use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.
the class XMLConfigWebFactory method loadListener.
private static void loadListener(ConfigServerImpl configServer, ConfigImpl config, Document doc) {
if (config instanceof ConfigServer) {
ConfigServer cs = (ConfigServer) config;
Element listener = getChildByName(doc.getDocumentElement(), "listener");
ClassDefinition cd = getClassDefinition(listener, "", config.getIdentification());
String strArguments = getAttr(listener, "arguments");
if (strArguments == null)
strArguments = "";
if (cd.hasClass()) {
try {
Object obj = ClassUtil.loadInstance(cd.getClazz(), new Object[] { strArguments }, null);
if (obj instanceof ConfigListener) {
ConfigListener cl = (ConfigListener) obj;
cs.setConfigListener(cl);
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
t.printStackTrace(config.getErrWriter());
}
}
} else if (configServer != null) {
ConfigListener listener = configServer.getConfigListener();
if (listener != null)
listener.onLoadWebContext(configServer, (ConfigWeb) config);
}
}
use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.
the class XMLConfigWebFactory method loadDumpWriter.
private static void loadDumpWriter(ConfigServerImpl configServer, ConfigImpl config, Document doc) throws ClassException {
boolean hasCS = configServer != null;
Element coll = getChildByName(doc.getDocumentElement(), "dump-writers");
Element[] writers = getChildren(coll, "dump-writer");
Struct sct = new StructImpl();
boolean hasPlain = false;
boolean hasRich = false;
if (hasCS) {
DumpWriterEntry[] entries = configServer.getDumpWritersEntries();
if (entries != null)
for (int i = 0; i < entries.length; i++) {
if (entries[i].getDefaultType() == HTMLDumpWriter.DEFAULT_PLAIN)
hasPlain = true;
if (entries[i].getDefaultType() == HTMLDumpWriter.DEFAULT_RICH)
hasRich = true;
sct.put(entries[i].getName(), entries[i]);
}
}
if (writers != null && writers.length > 0) {
ClassDefinition cd;
String strName;
String strDefault;
Class clazz;
int def = HTMLDumpWriter.DEFAULT_NONE;
for (int i = 0; i < writers.length; i++) {
cd = getClassDefinition(writers[i], "", config.getIdentification());
strName = getAttr(writers[i], "name");
strDefault = getAttr(writers[i], "default");
clazz = cd.getClazz(null);
if (clazz != null && !StringUtil.isEmpty(strName)) {
if (StringUtil.isEmpty(strDefault))
def = HTMLDumpWriter.DEFAULT_NONE;
else if ("browser".equalsIgnoreCase(strDefault))
def = HTMLDumpWriter.DEFAULT_RICH;
else if ("console".equalsIgnoreCase(strDefault))
def = HTMLDumpWriter.DEFAULT_PLAIN;
sct.put(strName, new DumpWriterEntry(def, strName, (DumpWriter) ClassUtil.loadInstance(clazz)));
}
}
} else {
// print.err("yep");
if (!hasRich)
sct.setEL(KeyConstants._html, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_RICH, "html", new HTMLDumpWriter()));
if (!hasPlain)
sct.setEL(KeyConstants._text, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_PLAIN, "text", new TextDumpWriter()));
sct.setEL(KeyConstants._classic, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_NONE, "classic", new ClassicHTMLDumpWriter()));
sct.setEL(KeyConstants._simple, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_NONE, "simple", new SimpleHTMLDumpWriter()));
}
Iterator<Object> it = sct.valueIterator();
java.util.List<DumpWriterEntry> entries = new ArrayList<DumpWriterEntry>();
while (it.hasNext()) {
entries.add((DumpWriterEntry) it.next());
}
config.setDumpWritersEntries(entries.toArray(new DumpWriterEntry[entries.size()]));
}
use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.
the class XMLConfigWebFactory method loadExeLog.
private static void loadExeLog(ConfigServerImpl configServer, ConfigImpl config, Document doc) {
boolean hasServer = configServer != null;
Element el = getChildByName(doc.getDocumentElement(), "execution-log");
// enabled
Boolean bEnabled = Caster.toBoolean(getAttr(el, "enabled"), null);
if (bEnabled == null) {
if (hasServer)
config.setExecutionLogEnabled(configServer.getExecutionLogEnabled());
} else
config.setExecutionLogEnabled(bEnabled.booleanValue());
boolean hasChanged = false;
String val = Caster.toString(config.getExecutionLogEnabled());
try {
Resource contextDir = config.getConfigDir();
Resource exeLog = contextDir.getRealResource("exe-log");
if (!exeLog.exists()) {
exeLog.createNewFile();
IOUtil.write(exeLog, val, SystemUtil.getCharset(), false);
hasChanged = true;
} else if (!IOUtil.toString(exeLog, SystemUtil.getCharset()).equals(val)) {
IOUtil.write(exeLog, val, SystemUtil.getCharset(), false);
hasChanged = true;
}
} catch (IOException e) {
e.printStackTrace(config.getErrWriter());
}
if (hasChanged) {
try {
if (config.getClassDirectory().exists())
config.getClassDirectory().remove(true);
} catch (IOException e) {
e.printStackTrace(config.getErrWriter());
}
}
// class
String strClass = getAttr(el, "class");
Class clazz;
if (!StringUtil.isEmpty(strClass)) {
try {
if ("console".equalsIgnoreCase(strClass))
clazz = ConsoleExecutionLog.class;
else {
ClassDefinition cd = getClassDefinition(el, "", config.getIdentification());
Class c = cd.getClazz();
if ((c.newInstance() instanceof ExecutionLog)) {
clazz = c;
} else {
clazz = ConsoleExecutionLog.class;
SystemOut.printDate(config.getErrWriter(), "class [" + strClass + "] must implement the interface " + ExecutionLog.class.getName());
}
}
} catch (Exception e) {
SystemOut.printDate(e);
clazz = ConsoleExecutionLog.class;
}
if (clazz != null)
SystemOut.printDate(config.getOutWriter(), "loaded ExecutionLog class " + clazz.getName());
// arguments
String strArgs = getAttr(el, "arguments");
if (StringUtil.isEmpty(strArgs))
strArgs = getAttr(el, "class-arguments");
Map<String, String> args = toArguments(strArgs, true);
config.setExecutionLogFactory(new ExecutionLogFactory(clazz, args));
} else {
if (hasServer)
config.setExecutionLogFactory(configServer.getExecutionLogFactory());
else
config.setExecutionLogFactory(new ExecutionLogFactory(ConsoleExecutionLog.class, new HashMap<String, String>()));
}
}
use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.
the class XMLConfigWebFactory method loadLoggers.
private static void loadLoggers(ConfigServerImpl configServer, ConfigImpl config, Document doc, boolean isReload) {
config.clearLoggers(Boolean.FALSE);
Element parent = getChildByName(doc.getDocumentElement(), "logging");
Element[] children = getChildren(parent, "logger");
Element child;
String name, appenderArgs, tmp, layoutArgs;
ClassDefinition cdAppender, cdLayout;
Level level = Level.ERROR;
boolean readOnly = false;
for (int i = 0; i < children.length; i++) {
child = children[i];
name = StringUtil.trim(getAttr(child, "name"), "");
// appender
cdAppender = getClassDefinition(child, "appender-", config.getIdentification());
if (!cdAppender.hasClass()) {
tmp = StringUtil.trim(getAttr(child, "appender"), "");
cdAppender = Log4jUtil.appenderClassDefintion(tmp);
}
appenderArgs = StringUtil.trim(getAttr(child, "appender-arguments"), "");
// layout
cdLayout = getClassDefinition(child, "layout-", config.getIdentification());
if (!cdLayout.hasClass()) {
tmp = StringUtil.trim(getAttr(child, "layout"), "");
cdLayout = Log4jUtil.layoutClassDefintion(tmp);
}
layoutArgs = StringUtil.trim(getAttr(child, "layout-arguments"), "");
String strLevel = getAttr(child, "level");
if (StringUtil.isEmpty(strLevel, true))
strLevel = getAttr(child, "log-level");
level = Log4jUtil.toLevel(StringUtil.trim(strLevel, ""), Level.ERROR);
readOnly = Caster.toBooleanValue(getAttr(child, "read-only"), false);
// ignore when no appender/name is defined
if (cdAppender.hasClass() && !StringUtil.isEmpty(name)) {
Map<String, String> appArgs = cssStringToMap(appenderArgs, true, true);
if (cdLayout.hasClass()) {
Map<String, String> layArgs = cssStringToMap(layoutArgs, true, true);
config.addLogger(name, level, cdAppender, appArgs, cdLayout, layArgs, readOnly, false);
} else
config.addLogger(name, level, cdAppender, appArgs, null, null, readOnly, false);
}
}
if (configServer != null) {
Iterator<Entry<String, LoggerAndSourceData>> it = configServer.getLoggers().entrySet().iterator();
Entry<String, LoggerAndSourceData> e;
LoggerAndSourceData data;
while (it.hasNext()) {
e = it.next();
// logger only exists in server context
if (config.getLog(e.getKey(), false) == null) {
data = e.getValue();
config.addLogger(e.getKey(), data.getLevel(), data.getAppenderClassDefinition(), data.getAppenderArgs(), data.getLayoutClassDefinition(), data.getLayoutArgs(), true, false);
}
}
}
}
use of lucee.runtime.db.ClassDefinition in project Lucee by lucee.
the class XMLConfigWebFactory method loadApplication.
/**
* @param configServer
* @param config
* @param doc
* @throws IOException
* @throws PageException
*/
private static void loadApplication(ConfigServerImpl configServer, ConfigImpl config, Document doc, int mode) throws IOException, PageException {
boolean hasCS = configServer != null;
boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_SETTING);
Element application = getChildByName(doc.getDocumentElement(), "application");
Element scope = getChildByName(doc.getDocumentElement(), "scope");
// Listener type
ApplicationListener listener;
if (mode == ConfigImpl.MODE_STRICT) {
listener = new ModernAppListener();
} else {
listener = ConfigWebUtil.loadListener(getAttr(application, "listener-type"), null);
if (listener == null) {
if (hasCS && configServer.getApplicationListener() != null)
listener = ConfigWebUtil.loadListener(configServer.getApplicationListener().getType(), null);
if (listener == null)
listener = new MixedAppListener();
}
}
String[] strTypes = new String[] { "function", "include", "query", "resource", "http", "file", "webservice" };
int[] types = new int[] { Config.CACHEDWITHIN_FUNCTION, Config.CACHEDWITHIN_INCLUDE, Config.CACHEDWITHIN_QUERY, Config.CACHEDWITHIN_RESOURCE, Config.CACHEDWITHIN_HTTP, Config.CACHEDWITHIN_FILE, Config.CACHEDWITHIN_WEBSERVICE };
// cachedwithin
for (int i = 0; i < types.length; i++) {
String cw = getAttr(application, "cached-within-" + strTypes[i]);
if (!StringUtil.isEmpty(cw, true))
config.setCachedWithin(types[i], cw);
else if (hasCS)
config.setCachedWithin(types[i], configServer.getCachedWithin(types[i]));
}
// Type Checking
Boolean typeChecking = Caster.toBoolean(getAttr(application, "type-checking"), null);
if (typeChecking != null)
config.setTypeChecking(typeChecking.booleanValue());
else if (hasCS)
config.setTypeChecking(configServer.getTypeChecking());
// Listener Mode
int listenerMode = ConfigWebUtil.toListenerMode(getAttr(application, "listener-mode"), -1);
if (listenerMode == -1) {
if (hasCS)
listenerMode = configServer.getApplicationListener() == null ? ApplicationListener.MODE_CURRENT2ROOT : configServer.getApplicationListener().getMode();
else
listenerMode = ApplicationListener.MODE_CURRENT2ROOT;
}
listener.setMode(listenerMode);
config.setApplicationListener(listener);
// Req Timeout URL
if (mode == ConfigImpl.MODE_STRICT) {
config.setAllowURLRequestTimeout(false);
} else {
String allowURLReqTimeout = getAttr(application, "allow-url-requesttimeout");
if (hasAccess && !StringUtil.isEmpty(allowURLReqTimeout)) {
config.setAllowURLRequestTimeout(Caster.toBooleanValue(allowURLReqTimeout, false));
} else if (hasCS)
config.setAllowURLRequestTimeout(configServer.isAllowURLRequestTimeout());
}
// Req Timeout
TimeSpan ts = null;
if (hasAccess) {
String reqTimeoutApplication = getAttr(application, "requesttimeout");
// deprecated
String reqTimeoutScope = getAttr(scope, "requesttimeout");
if (!StringUtil.isEmpty(reqTimeoutApplication))
ts = Caster.toTimespan(reqTimeoutApplication);
if (ts == null && !StringUtil.isEmpty(reqTimeoutScope))
ts = Caster.toTimespan(reqTimeoutScope);
}
if (ts != null && ts.getMillis() > 0)
config.setRequestTimeout(ts);
else if (hasCS)
config.setRequestTimeout(configServer.getRequestTimeout());
// script-protect
String strScriptProtect = getAttr(application, "script-protect");
if (hasAccess && !StringUtil.isEmpty(strScriptProtect)) {
// print.err("sp:"+strScriptProtect);
config.setScriptProtect(AppListenerUtil.translateScriptProtect(strScriptProtect));
} else if (hasCS)
config.setScriptProtect(configServer.getScriptProtect());
// classic-date-parsing
if (config instanceof ConfigServer) {
if (mode == ConfigImpl.MODE_STRICT) {
DateCaster.classicStyle = true;
} else {
String strClassicDateParsing = getAttr(application, "classic-date-parsing");
if (!StringUtil.isEmpty(strClassicDateParsing)) {
DateCaster.classicStyle = Caster.toBooleanValue(strClassicDateParsing, false);
}
}
}
// Cache
Resource configDir = config.getConfigDir();
String strCacheDirectory = application.getAttribute("cache-directory");
if (hasAccess && !StringUtil.isEmpty(strCacheDirectory)) {
strCacheDirectory = ConfigWebUtil.translateOldPath(strCacheDirectory);
Resource res = ConfigWebUtil.getFile(configDir, strCacheDirectory, "cache", configDir, FileUtil.TYPE_DIR, config);
config.setCacheDir(res);
} else {
config.setCacheDir(configDir.getRealResource("cache"));
}
String strMax = getAttr(application, "cache-directory-max-size");
if (hasAccess && !StringUtil.isEmpty(strMax)) {
config.setCacheDirSize(ByteSizeParser.parseByteSizeDefinition(strMax, config.getCacheDirSize()));
} else if (hasCS)
config.setCacheDirSize(configServer.getCacheDirSize());
// admin sync
ClassDefinition asc = getClassDefinition(application, "admin-sync-", config.getIdentification());
if (!asc.hasClass())
asc = getClassDefinition(application, "admin-synchronisation-", config.getIdentification());
if (hasAccess && asc.hasClass()) {
try {
Class clazz = asc.getClazz();
if (!Reflector.isInstaneOf(clazz, AdminSync.class))
throw new ApplicationException("class [" + clazz.getName() + "] does not implement interface [" + AdminSync.class.getName() + "]");
config.setAdminSyncClass(clazz);
} catch (Exception e) {
SystemOut.printDate(e);
}
} else if (hasCS)
config.setAdminSyncClass(configServer.getAdminSyncClass());
}
Aggregations