package io.github.simonxianyu.util.spring.web;

import org.springframework.core.io.Resource;

import java.util.Map;

/**
 * Try to read css configurations.
 * Created by Simon Xianyu on 2015/11/22 0022.
 */
public class CssConfigSource {
  private Map<String, Resource> cssResources;

  public void init() {

  }

  public Map<String, Resource> getCssResources() {
    return cssResources;
  }

  public void setCssResources(Map<String, Resource> cssResources) {
    this.cssResources = cssResources;
  }
}

@@ -52,46 +52,294 @@
 ort 
-org.springframework.core.io.Resource;%0A
+io.github.simonxianyu.util.common.DwUtil;%0Aimport org.apache.logging.log4j.LogManager;%0Aimport org.apache.logging.log4j.Logger;%0Aimport org.springframework.beans.factory.InitializingBean;%0Aimport org.springframework.core.io.Resource;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStream;
 %0Aimp
@@ -356,12 +356,67 @@
 til.
+Hash
 Map;
+%0Aimport java.util.Map;%0Aimport java.util.Properties;
 %0A%0A/*
@@ -536,80 +536,1336 @@
 rce 
-%7B%0A  private Map%3CString, Resource%3E cssResources;%0A%0A  public void init() %7B%0A
+implements InitializingBean %7B%0A  private Logger log = LogManager.getLogger();%0A  private Map%3CString, Resource%3E cssResources;%0A%0A  private Map%3CString, Map%3CString, String%3E%3E cssMap = new HashMap%3C%3E();%0A%0A  @Override%0A  public void afterPropertiesSet() throws Exception %7B%0A    init();%0A  %7D%0A%0A  public void init() %7B%0A    if (null == cssResources) %7B%0A      throw new RuntimeException(%22CssResource should be declared.%22);%0A    %7D%0A    for(Map.Entry%3CString, Resource%3E e : cssResources.entrySet()) %7B%0A      if (cssMap.containsKey(e.getKey())) %7B%0A        throw new IllegalArgumentException(%22duplicated scope:%22+e.getKey());%0A      %7D%0A%0A      Properties prop = new Properties();%0A      InputStream in = null;%0A      try %7B%0A        in = e.getValue().getInputStream();%0A        prop.load( in );%0A        if (prop.size()%3E0) %7B%0A          Map%3CString, String%3E m = new HashMap%3C%3E();%0A          for(Map.Entry%3CObject, Object%3E e1 : prop.entrySet()) %7B%0A            m.put(e1.getKey().toString(), e1.getValue().toString());%0A          %7D%0A          cssMap.put(e.getKey(), m);%0A        %7D else %7B%0A          log.warn(%22scope %22+e.getKey() +%22 has no values%22);%0A        %7D%0A      %7D catch (IOException e1) %7B%0A//        e1.printStackTrace();%0A        log.error(%22Failed to read scope %22+e.getKey() +%22 resource %22+e.getValue().getFilename());%0A      %7D finally %7B%0A        DwUtil.closeQuietly(in);%0A      %7D%0A    %7D
 %0A  %7D
@@ -2057,10 +2057,12 @@
 es;%0A  %7D%0A
+%0A%0A
 %7D%0A

implement CssConfigSource