use of lucee.runtime.listener.MixedAppListener 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