Search in sources :

Example 1 with MixedAppListener

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());
}
Also used : ModernAppListener(lucee.runtime.listener.ModernAppListener) Element(org.w3c.dom.Element) Resource(lucee.commons.io.res.Resource) ClassDefinition(lucee.runtime.db.ClassDefinition) lucee.aprint(lucee.aprint) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) ClassException(lucee.commons.lang.ClassException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) TimeSpan(lucee.runtime.type.dt.TimeSpan) ApplicationException(lucee.runtime.exp.ApplicationException) ApplicationListener(lucee.runtime.listener.ApplicationListener) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) MixedAppListener(lucee.runtime.listener.MixedAppListener)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SQLException (java.sql.SQLException)1 lucee.aprint (lucee.aprint)1 Resource (lucee.commons.io.res.Resource)1 ClassException (lucee.commons.lang.ClassException)1 CFXTagClass (lucee.runtime.cfx.customtag.CFXTagClass)1 CPPCFXTagClass (lucee.runtime.cfx.customtag.CPPCFXTagClass)1 JavaCFXTagClass (lucee.runtime.cfx.customtag.JavaCFXTagClass)1 ClassDefinition (lucee.runtime.db.ClassDefinition)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 PageException (lucee.runtime.exp.PageException)1 SecurityException (lucee.runtime.exp.SecurityException)1 ApplicationListener (lucee.runtime.listener.ApplicationListener)1 MixedAppListener (lucee.runtime.listener.MixedAppListener)1 ModernAppListener (lucee.runtime.listener.ModernAppListener)1 TimeSpan (lucee.runtime.type.dt.TimeSpan)1