use of lucee.commons.io.log.log4j.layout.ClassicLayout 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();
}
Aggregations