📄 stylemanager.java
字号:
/*
* Created on 2004-8-18
*
*/
package com.esimple.framework.web.style;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.esimple.framework.configuration.*;
import com.esimple.framework.web.util.CookieUtils;
/**
* @author steven
*
*/
public class StyleManager {
private Log log = LogFactory.getLog(this.getClass());
public static final String SESSION_NAME = "ESIMPLE_STYLE";
public static final String BEAN_NAME = "StyleManager";
public static final String FILE_STYLECONFIG = "/WEB-INF/styleConfig.xml";
public static final String CSS_FILE_NAME = "style.css";
public static final String DEFAULT_CSS_PATH = "/theme/style0/style.css";
public static final String DEFAULT_STYLE = "/theme/style0/";
private Configuration styleConfig;
private String root;
private String defaultStyle;
private HashMap styles = new HashMap();
private HashMap descs = new HashMap();
private boolean isInit = false;
public void setStyleConfig(Configuration styleConfig){
this.styleConfig = styleConfig;
}
public void init() throws Exception{
try{
root = styleConfig.getChild("root").getValue();
defaultStyle = styleConfig.getChild("default").getValue();
Configuration[] scs = styleConfig.getChild("styles").getChildren();
for(int i = 0;i < scs.length;i++){
String name = scs[i].getAttribute("name");
String path = scs[i].getAttribute("path");
String desc = scs[i].getValue();
styles.put(name,path);
descs.put(name,desc);
}
}catch(Exception e){
log.error("can not read style config:" + e);
log.debug( e.getMessage());
isInit = false;
}
isInit =true;
}
public String getStylePath( String styleName ){
String rt = null;
String stylePath = (String)styles.get(styleName);
if( !isInit || stylePath == null ) return DEFAULT_STYLE;
rt = root + "/" + stylePath +"/";
return rt;
}
public void setStyle( HttpServletRequest req,HttpServletResponse res,String styleName ){
CookieUtils.setValue(req,res,SESSION_NAME,styleName,CookieUtils.ONE_MONTH_AGE);
req.getSession().setAttribute(SESSION_NAME,styleName);
}
public String getStylePath(HttpServletRequest req){
String cs = (String) req.getSession().getAttribute( SESSION_NAME );
if( cs == null ){
cs = CookieUtils.getValue(req,SESSION_NAME);
if( cs == null ) cs = defaultStyle;
req.getSession().setAttribute(SESSION_NAME,cs);
}
return getStylePath(cs);
}
public String getImgPath(HttpServletRequest req){
return getStylePath(req) + "images/";
}
public String getCSSPath(HttpServletRequest req){
String cs = getStylePath( req );
return cs + CSS_FILE_NAME;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -