Java 类org.apache.log4j.xml.XMLLayout 实例源码

项目:Lucee    文件:Log4jUtil.java   
public static ClassDefinition<Layout> layoutClassDefintion(String className) {
    if("classic".equalsIgnoreCase(className))return new ClassDefinitionImpl( ClassicLayout.class);
    if("html".equalsIgnoreCase(className))return new ClassDefinitionImpl( HTMLLayout.class);
    if("xml".equalsIgnoreCase(className))return new ClassDefinitionImpl( XMLLayout.class);
    if("pattern".equalsIgnoreCase(className))return new ClassDefinitionImpl( PatternLayout.class);

    return new ClassDefinitionImpl( className);
}
项目:Lucee    文件:ApplicationContextSupport.java   
public static ClassDefinition toClassDefinition(Struct sct, ClassDefinition defaultValue, boolean isAppender, boolean isLayout) {
    if(sct==null) return defaultValue;

    // class
    String className=Caster.toString(sct.get("class",null),null);
    if(StringUtil.isEmpty(className)) return defaultValue;

    if(isAppender) {
        if("console".equalsIgnoreCase(className))   return new ClassDefinitionImpl( ConsoleAppender.class);
        if("resource".equalsIgnoreCase(className))  return new ClassDefinitionImpl( RollingResourceAppender.class);
        if("datasource".equalsIgnoreCase(className))return new ClassDefinitionImpl( DatasourceAppender.class);
    }
    else if(isLayout) {
        if("classic".equalsIgnoreCase(className))return new ClassDefinitionImpl( ClassicLayout.class);
        if("html".equalsIgnoreCase(className))return new ClassDefinitionImpl( HTMLLayout.class);
        if("xml".equalsIgnoreCase(className))return new ClassDefinitionImpl( XMLLayout.class);
        if("pattern".equalsIgnoreCase(className))return new ClassDefinitionImpl( PatternLayout.class);
    }

    // name
    String name=Caster.toString(sct.get("bundlename",null),null);
    if(StringUtil.isEmpty(name)) name=Caster.toString(sct.get("name",null),null);

    // version
    Version version=OSGiUtil.toVersion(Caster.toString(sct.get("bundleversion",null),null),null);
    if(version==null) version=OSGiUtil.toVersion(Caster.toString(sct.get("version",null),null),null);

    if(StringUtil.isEmpty(name)) return new ClassDefinitionImpl(className);

    return new ClassDefinitionImpl(null,className, name, version);
}
项目:Lucee4    文件:ConfigWebAdmin.java   
public void updateLogSettings(String name, Level level, String appenderClassName, Struct appenderArgs, String layoutClassName, Struct layoutArgs) throws PageException {
    checkWriteAccess();
    // TODO
    //boolean hasAccess=ConfigWebUtil.hasAccess(config,SecurityManagerImpl.TYPE_GATEWAY);
       // if(!hasAccess) throw new SecurityException("no access to update gateway entry");

       // check parameters
    name=name.trim();
    if(StringUtil.isEmpty(name))
           throw new ApplicationException("name can't be a empty value");

    if(StringUtil.isEmpty(appenderClassName))
        throw new ExpressionException("you must define appender class name");
    if(StringUtil.isEmpty(layoutClassName))
        throw new ExpressionException("you must define layout class name");

       try {
        ClassUtil.loadClass(appenderClassName);
        ClassUtil.loadClass(layoutClassName);

    }
       catch (ClassException e) {
           throw Caster.toPageException(e);
    }

       Element parent=_getRootElement("logging");

       // Update
       Element[] children = ConfigWebFactory.getChildren(parent,"logger");
       Element el=null;
        for(int i=0;i<children.length;i++) {
            String n=children[i].getAttribute("name");
            if(name.equalsIgnoreCase(n)) {
                el=children[i];
                break;
            }

        }
        // Insert
        if(el==null) {
        el=doc.createElement("logger");
        parent.appendChild(el);
        el.setAttribute("name",name);
        }

        // appender
        if(appenderClassName.equals(ConsoleAppender.class.getName())) appenderClassName="console";
        if(appenderClassName.equals(RollingResourceAppender.class.getName())) appenderClassName="resource";
        // layout
        if(layoutClassName.equals(PatternLayout.class.getName())) layoutClassName="pattern";
        if(layoutClassName.equals(ClassicLayout.class.getName())) layoutClassName="classic";
        if(layoutClassName.equals(HTMLLayout.class.getName())) layoutClassName="html";
        if(layoutClassName.equals(XMLLayout.class.getName())) layoutClassName="xml";

        el.setAttribute("level",level.toString());
        el.setAttribute("appender",appenderClassName);
        el.setAttribute("appender-arguments",toStringCSSStyle(appenderArgs));
    el.setAttribute("layout",layoutClassName);
    el.setAttribute("layout-arguments",toStringCSSStyle(layoutArgs));
}