Search in sources :

Example 1 with XMLLayout

use of org.apache.log4j.xml.XMLLayout in project Lucee by lucee.

the class Log4jUtil method getLayout.

public static final Layout getLayout(ClassDefinition cd, Map<String, String> layoutArgs) {
    if (layoutArgs == null)
        layoutArgs = new HashMap<String, String>();
    // Layout
    Layout layout = null;
    if (cd != null && cd.hasClass()) {
        // Classic Layout
        if (ClassicLayout.class.getName().equalsIgnoreCase(cd.getClassName()))
            layout = new ClassicLayout();
        else // HTML Layout
        if (HTMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            HTMLLayout html = new HTMLLayout();
            layout = html;
            // Location Info
            Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
            if (locInfo != null)
                html.setLocationInfo(locInfo.booleanValue());
            else
                locInfo = Boolean.FALSE;
            layoutArgs.put("locationinfo", locInfo.toString());
            // Title
            String title = Caster.toString(layoutArgs.get("title"), "");
            if (!StringUtil.isEmpty(title, true))
                html.setTitle(title);
            layoutArgs.put("title", title);
        } else // XML Layout
        if (XMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            XMLLayout xml = new XMLLayout();
            layout = xml;
            // Location Info
            Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
            if (locInfo != null)
                xml.setLocationInfo(locInfo.booleanValue());
            else
                locInfo = Boolean.FALSE;
            layoutArgs.put("locationinfo", locInfo.toString());
            // Properties
            Boolean props = Caster.toBoolean(layoutArgs.get("properties"), null);
            if (props != null)
                xml.setProperties(props.booleanValue());
            else
                props = Boolean.FALSE;
            layoutArgs.put("properties", props.toString());
        } else // Pattern Layout
        if (PatternLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            PatternLayout patt = new PatternLayout();
            layout = patt;
            // pattern
            String pattern = Caster.toString(layoutArgs.get("pattern"), null);
            if (!StringUtil.isEmpty(pattern, true))
                patt.setConversionPattern(pattern);
            else {
                patt.setConversionPattern(DEFAULT_PATTERN);
                layoutArgs.put("pattern", DEFAULT_PATTERN);
            }
        } else // class defintion
        {
            Object obj = ClassUtil.loadInstance(cd.getClazz(null), null, null);
            if (obj instanceof Layout) {
                layout = (Layout) obj;
                Iterator<Entry<String, String>> it = layoutArgs.entrySet().iterator();
                Entry<String, String> e;
                while (it.hasNext()) {
                    e = it.next();
                    try {
                        Reflector.callSetter(obj, e.getKey(), e.getValue());
                    } catch (PageException e1) {
                        // TODO log
                        SystemOut.printDate(e1);
                    }
                }
            }
        }
    }
    if (layout != null)
        return layout;
    return new ClassicLayout();
}
Also used : PageException(lucee.runtime.exp.PageException) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) HTMLLayout(org.apache.log4j.HTMLLayout) ClassicLayout(lucee.commons.io.log.log4j.layout.ClassicLayout) XMLLayout(org.apache.log4j.xml.XMLLayout) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) HTMLLayout(org.apache.log4j.HTMLLayout) PatternLayout(org.apache.log4j.PatternLayout) ClassicLayout(lucee.commons.io.log.log4j.layout.ClassicLayout) Iterator(java.util.Iterator) XMLLayout(org.apache.log4j.xml.XMLLayout)

Aggregations

HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 ClassicLayout (lucee.commons.io.log.log4j.layout.ClassicLayout)1 PageException (lucee.runtime.exp.PageException)1 HTMLLayout (org.apache.log4j.HTMLLayout)1 Layout (org.apache.log4j.Layout)1 PatternLayout (org.apache.log4j.PatternLayout)1 XMLLayout (org.apache.log4j.xml.XMLLayout)1