Search in sources :

Example 1 with ModernAppListener

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

Example 2 with ModernAppListener

use of lucee.runtime.listener.ModernAppListener in project Lucee by lucee.

the class XMLConfigWebFactory method loadMappings.

/**
 * load mapings from XML Document
 *
 * @param configServer
 * @param config
 * @param doc
 * @throws IOException
 */
private static void loadMappings(ConfigServerImpl configServer, ConfigImpl config, Document doc, int mode) throws IOException {
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_MAPPING);
    Element el = getChildByName(doc.getDocumentElement(), "mappings");
    Element[] _mappings = getChildren(el, "mapping");
    Map<String, Mapping> mappings = MapFactory.<String, Mapping>getConcurrentMap();
    Mapping tmp;
    boolean finished = false;
    if (configServer != null && config instanceof ConfigWeb) {
        Mapping[] sm = configServer.getMappings();
        for (int i = 0; i < sm.length; i++) {
            if (!sm[i].isHidden()) {
                if ("/".equals(sm[i].getVirtual()))
                    finished = true;
                if (sm[i] instanceof MappingImpl) {
                    tmp = ((MappingImpl) sm[i]).cloneReadOnly(config);
                    mappings.put(tmp.getVirtualLowerCase(), tmp);
                } else {
                    tmp = sm[i];
                    mappings.put(tmp.getVirtualLowerCase(), tmp);
                }
            }
        }
    }
    if (hasAccess) {
        boolean hasServerContext = false;
        for (int i = 0; i < _mappings.length; i++) {
            el = _mappings[i];
            String physical = el.getAttribute("physical");
            String archive = el.getAttribute("archive");
            String virtual = getAttr(el, "virtual");
            String listType = getAttr(el, "listener-type");
            String listMode = getAttr(el, "listener-mode");
            boolean readonly = toBoolean(getAttr(el, "readonly"), false);
            boolean hidden = toBoolean(getAttr(el, "hidden"), false);
            boolean toplevel = toBoolean(getAttr(el, "toplevel"), true);
            if (config instanceof ConfigServer && (virtual.equalsIgnoreCase("/lucee-server/") || virtual.equalsIgnoreCase("/lucee-server-context/"))) {
                hasServerContext = true;
            }
            // lucee
            if (virtual.equalsIgnoreCase("/lucee/")) {
                if (StringUtil.isEmpty(listType, true))
                    listType = "modern";
                if (StringUtil.isEmpty(listMode, true))
                    listMode = "curr2root";
                toplevel = true;
            }
            int listenerMode = ConfigWebUtil.toListenerMode(listMode, -1);
            int listenerType = ConfigWebUtil.toListenerType(listType, -1);
            ApplicationListener listener = ConfigWebUtil.loadListener(listenerType, null);
            if (listener != null || listenerMode != -1) {
                // type
                if (mode == ConfigImpl.MODE_STRICT)
                    listener = new ModernAppListener();
                else if (listener == null)
                    listener = ConfigWebUtil.loadListener(ConfigWebUtil.toListenerType(config.getApplicationListener().getType(), -1), null);
                if (// this should never be true
                listener == null)
                    listener = new ModernAppListener();
                // mode
                if (listenerMode == -1) {
                    listenerMode = config.getApplicationListener().getMode();
                }
                listener.setMode(listenerMode);
            }
            // physical!=null &&
            if ((physical != null || archive != null)) {
                short insTemp = inspectTemplate(el);
                if ("/lucee/".equalsIgnoreCase(virtual) || "/lucee".equalsIgnoreCase(virtual) || "/lucee-server/".equalsIgnoreCase(virtual) || "/lucee-server-context".equalsIgnoreCase(virtual))
                    insTemp = ConfigImpl.INSPECT_ONCE;
                String primary = getAttr(el, "primary");
                boolean physicalFirst = primary == null || !primary.equalsIgnoreCase("archive");
                tmp = new MappingImpl(config, virtual, physical, archive, insTemp, physicalFirst, hidden, readonly, toplevel, false, false, listener, listenerMode, listenerType);
                mappings.put(tmp.getVirtualLowerCase(), tmp);
                if (virtual.equals("/")) {
                    finished = true;
                // break;
                }
            }
        }
        // set default lucee-server-context
        if (config instanceof ConfigServer && !hasServerContext) {
            ApplicationListener listener = ConfigWebUtil.loadListener(ApplicationListener.TYPE_MODERN, null);
            listener.setMode(ApplicationListener.MODE_CURRENT2ROOT);
            tmp = new MappingImpl(config, "/lucee-server", "{lucee-server}/context/", null, ConfigImpl.INSPECT_ONCE, true, false, true, true, false, false, listener, ApplicationListener.MODE_CURRENT2ROOT, ApplicationListener.TYPE_MODERN);
            mappings.put(tmp.getVirtualLowerCase(), tmp);
        }
    }
    if (!finished) {
        if ((config instanceof ConfigWebImpl) && ResourceUtil.isUNCPath(config.getRootDirectory().getPath())) {
            tmp = new MappingImpl(config, "/", config.getRootDirectory().getPath(), null, ConfigImpl.INSPECT_UNDEFINED, true, true, true, true, false, false, null, -1, -1);
        } else {
            tmp = new MappingImpl(config, "/", "/", null, ConfigImpl.INSPECT_UNDEFINED, true, true, true, true, false, false, null, -1, -1);
        }
        mappings.put("/", tmp);
    }
    Mapping[] arrMapping = new Mapping[mappings.size()];
    int index = 0;
    Iterator it = mappings.keySet().iterator();
    while (it.hasNext()) {
        arrMapping[index++] = mappings.get(it.next());
    }
    config.setMappings(arrMapping);
// config.setMappings((Mapping[]) mappings.toArray(new
// Mapping[mappings.size()]));
}
Also used : ModernAppListener(lucee.runtime.listener.ModernAppListener) Element(org.w3c.dom.Element) Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl) lucee.aprint(lucee.aprint) ApplicationListener(lucee.runtime.listener.ApplicationListener) Iterator(java.util.Iterator)

Aggregations

lucee.aprint (lucee.aprint)2 ApplicationListener (lucee.runtime.listener.ApplicationListener)2 ModernAppListener (lucee.runtime.listener.ModernAppListener)2 Element (org.w3c.dom.Element)2 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 Iterator (java.util.Iterator)1 Resource (lucee.commons.io.res.Resource)1 ClassException (lucee.commons.lang.ClassException)1 Mapping (lucee.runtime.Mapping)1 MappingImpl (lucee.runtime.MappingImpl)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