Search in sources :

Example 11 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadComponent.

/**
 * @param configServer
 * @param config
 * @param doc
 * @throws IOException
 */
private static void loadComponent(ConfigServer configServer, ConfigImpl config, Document doc, int mode) {
    Element component = getChildByName(doc.getDocumentElement(), "component");
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_SETTING);
    boolean hasSet = false;
    boolean hasCS = configServer != null;
    if (component != null && hasAccess) {
        // component-default-import
        String strCDI = getAttr(component, "component-default-import");
        if (StringUtil.isEmpty(strCDI, true) && configServer != null) {
            strCDI = ((ConfigServerImpl) configServer).getComponentDefaultImport().toString();
        }
        if (!StringUtil.isEmpty(strCDI, true))
            config.setComponentDefaultImport(strCDI);
        // Base CFML
        String strBase = getAttr(component, "base-cfml");
        if (StringUtil.isEmpty(strBase, true))
            strBase = getAttr(component, "base");
        if (StringUtil.isEmpty(strBase, true) && configServer != null) {
            strBase = configServer.getBaseComponentTemplate(CFMLEngine.DIALECT_CFML);
        }
        config.setBaseComponentTemplate(CFMLEngine.DIALECT_CFML, strBase);
        // Base Lucee
        strBase = getAttr(component, "base-lucee");
        if (StringUtil.isEmpty(strBase, true)) {
            if (configServer != null)
                strBase = configServer.getBaseComponentTemplate(CFMLEngine.DIALECT_LUCEE);
            else
                strBase = "/lucee/Component.lucee";
        }
        config.setBaseComponentTemplate(CFMLEngine.DIALECT_LUCEE, strBase);
        // deep search
        if (mode == ConfigImpl.MODE_STRICT) {
            config.setDoComponentDeepSearch(false);
        } else {
            String strDeepSearch = getAttr(component, "deep-search");
            if (!StringUtil.isEmpty(strDeepSearch)) {
                config.setDoComponentDeepSearch(Caster.toBooleanValue(strDeepSearch.trim(), false));
            } else if (hasCS) {
                config.setDoComponentDeepSearch(((ConfigServerImpl) configServer).doComponentDeepSearch());
            }
        }
        // Dump-Template
        String strDumpRemplate = component.getAttribute("dump-template");
        if ((strDumpRemplate == null || strDumpRemplate.trim().length() == 0) && configServer != null) {
            strDumpRemplate = configServer.getComponentDumpTemplate();
        }
        config.setComponentDumpTemplate(strDumpRemplate);
        // data-member-default-access
        if (mode == ConfigImpl.MODE_STRICT) {
            config.setComponentDataMemberDefaultAccess(Component.ACCESS_PRIVATE);
        } else {
            String strDmda = getAttr(component, "data-member-default-access");
            if (strDmda != null && strDmda.trim().length() > 0) {
                strDmda = strDmda.toLowerCase().trim();
                if (strDmda.equals("remote"))
                    config.setComponentDataMemberDefaultAccess(Component.ACCESS_REMOTE);
                else if (strDmda.equals("public"))
                    config.setComponentDataMemberDefaultAccess(Component.ACCESS_PUBLIC);
                else if (strDmda.equals("package"))
                    config.setComponentDataMemberDefaultAccess(Component.ACCESS_PACKAGE);
                else if (strDmda.equals("private"))
                    config.setComponentDataMemberDefaultAccess(Component.ACCESS_PRIVATE);
            } else if (configServer != null) {
                config.setComponentDataMemberDefaultAccess(configServer.getComponentDataMemberDefaultAccess());
            }
        }
        // trigger-properties
        if (mode == ConfigImpl.MODE_STRICT) {
            config.setTriggerComponentDataMember(true);
        } else {
            Boolean tp = Caster.toBoolean(getAttr(component, "trigger-data-member"), null);
            if (tp != null)
                config.setTriggerComponentDataMember(tp.booleanValue());
            else if (configServer != null) {
                config.setTriggerComponentDataMember(configServer.getTriggerComponentDataMember());
            }
        }
        // local search
        if (mode == ConfigImpl.MODE_STRICT) {
            config.setComponentLocalSearch(false);
        } else {
            Boolean ls = Caster.toBoolean(getAttr(component, "local-search"), null);
            if (ls != null)
                config.setComponentLocalSearch(ls.booleanValue());
            else if (configServer != null) {
                config.setComponentLocalSearch(((ConfigServerImpl) configServer).getComponentLocalSearch());
            }
        }
        // use cache path
        Boolean ucp = Caster.toBoolean(getAttr(component, "use-cache-path"), null);
        if (ucp != null)
            config.setUseComponentPathCache(ucp.booleanValue());
        else if (configServer != null) {
            config.setUseComponentPathCache(((ConfigServerImpl) configServer).useComponentPathCache());
        }
        // use component shadow
        if (mode == ConfigImpl.MODE_STRICT) {
            config.setUseComponentShadow(false);
        } else {
            Boolean ucs = Caster.toBoolean(getAttr(component, "use-shadow"), null);
            if (ucs != null)
                config.setUseComponentShadow(ucs.booleanValue());
            else if (configServer != null) {
                config.setUseComponentShadow(configServer.useComponentShadow());
            }
        }
    } else if (configServer != null) {
        config.setBaseComponentTemplate(CFMLEngine.DIALECT_CFML, configServer.getBaseComponentTemplate(CFMLEngine.DIALECT_CFML));
        config.setBaseComponentTemplate(CFMLEngine.DIALECT_LUCEE, configServer.getBaseComponentTemplate(CFMLEngine.DIALECT_LUCEE));
        config.setComponentDumpTemplate(configServer.getComponentDumpTemplate());
        if (mode == ConfigImpl.MODE_STRICT) {
            config.setComponentDataMemberDefaultAccess(Component.ACCESS_PRIVATE);
            config.setTriggerComponentDataMember(true);
        } else {
            config.setComponentDataMemberDefaultAccess(configServer.getComponentDataMemberDefaultAccess());
            config.setTriggerComponentDataMember(configServer.getTriggerComponentDataMember());
        }
    }
    if (mode == ConfigImpl.MODE_STRICT) {
        config.setDoComponentDeepSearch(false);
        config.setComponentDataMemberDefaultAccess(Component.ACCESS_PRIVATE);
        config.setTriggerComponentDataMember(true);
        config.setComponentLocalSearch(false);
        config.setUseComponentShadow(false);
    }
    // Web Mapping
    Element[] cMappings = getChildren(component, "mapping");
    hasSet = false;
    Mapping[] mappings = null;
    if (hasAccess && cMappings.length > 0) {
        mappings = new Mapping[cMappings.length];
        for (int i = 0; i < cMappings.length; i++) {
            Element cMapping = cMappings[i];
            String physical = cMapping.getAttribute("physical");
            String archive = cMapping.getAttribute("archive");
            boolean readonly = toBoolean(getAttr(cMapping, "readonly"), false);
            boolean hidden = toBoolean(getAttr(cMapping, "hidden"), false);
            int listMode = ConfigWebUtil.toListenerMode(getAttr(cMapping, "listener-mode"), -1);
            int listType = ConfigWebUtil.toListenerType(getAttr(cMapping, "listener-type"), -1);
            short inspTemp = inspectTemplate(cMapping);
            String virtual = XMLConfigAdmin.createVirtual(cMapping);
            String primary = getAttr(cMapping, "primary");
            boolean physicalFirst = archive == null || !primary.equalsIgnoreCase("archive");
            hasSet = true;
            mappings[i] = new MappingImpl(config, virtual, physical, archive, inspTemp, physicalFirst, hidden, readonly, true, false, true, null, listMode, listType);
        }
        config.setComponentMappings(mappings);
    }
    // Server Mapping
    if (hasCS) {
        Mapping[] originals = ((ConfigServerImpl) configServer).getComponentMappings();
        Mapping[] clones = new Mapping[originals.length];
        LinkedHashMap map = new LinkedHashMap();
        Mapping m;
        for (int i = 0; i < clones.length; i++) {
            m = ((MappingImpl) originals[i]).cloneReadOnly(config);
            map.put(toKey(m), m);
        // clones[i]=((MappingImpl)m[i]).cloneReadOnly(config);
        }
        if (mappings != null) {
            for (int i = 0; i < mappings.length; i++) {
                m = mappings[i];
                map.put(toKey(m), m);
            }
        }
        if (originals.length > 0) {
            clones = new Mapping[map.size()];
            Iterator it = map.entrySet().iterator();
            Map.Entry entry;
            int index = 0;
            while (it.hasNext()) {
                entry = (Entry) it.next();
                clones[index++] = (Mapping) entry.getValue();
            // print.out("c:"+clones[index-1]);
            }
            hasSet = true;
            // print.err("set:"+clones.length);
            config.setComponentMappings(clones);
        }
    }
    if (!hasSet) {
        MappingImpl m = new MappingImpl(config, "/default", "{lucee-web}/components/", null, ConfigImpl.INSPECT_UNDEFINED, true, false, false, true, false, true, null, -1, -1);
        config.setComponentMappings(new Mapping[] { m.cloneReadOnly(config) });
    }
}
Also used : Entry(java.util.Map.Entry) Element(org.w3c.dom.Element) Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl) lucee.aprint(lucee.aprint) LinkedHashMap(java.util.LinkedHashMap) Iterator(java.util.Iterator) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 12 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadCustomTagsMappings.

/*private static void setDatasourceEL(ConfigImpl config, Map<String, DataSource> datasources, String datasourceName, ClassDefinition cd, String server, String databasename,
			int port, String dsn, String user, String pass, int connectionLimit, int connectionTimeout, long metaCacheTimeout, boolean blob, boolean clob, int allow,
			boolean validate, boolean storage, String timezone, Struct custom, String dbdriver) {
		try {
			setDatasource(config, datasources, datasourceName, cd, server, databasename, port, dsn, user, pass, connectionLimit, connectionTimeout, metaCacheTimeout, blob,
					clob, allow, validate, storage, timezone, custom, dbdriver);
		}
		catch(Throwable t) {ExceptionUtil.rethrowIfNecessary(t);}
	}*/
/**
 * @param configServer
 * @param config
 * @param doc
 * @throws IOException
 */
private static void loadCustomTagsMappings(ConfigServerImpl configServer, ConfigImpl config, Document doc, int mode) {
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_CUSTOM_TAG);
    boolean hasCS = configServer != null;
    Element customTag = getChildByName(doc.getDocumentElement(), "custom-tag");
    Element[] ctMappings = getChildren(customTag, "mapping");
    // String virtualx="/custom-tag/";
    // do patch cache
    String strDoPathcache = getAttr(customTag, "use-cache-path");
    if (hasAccess && !StringUtil.isEmpty(strDoPathcache, true)) {
        config.setUseCTPathCache(Caster.toBooleanValue(strDoPathcache.trim(), true));
    } else if (hasCS) {
        config.setUseCTPathCache(configServer.useCTPathCache());
    }
    // do custom tag local search
    if (mode == ConfigImpl.MODE_STRICT) {
        config.setDoLocalCustomTag(false);
    } else {
        String strDoCTLocalSearch = getAttr(customTag, "custom-tag-local-search");
        if (hasAccess && !StringUtil.isEmpty(strDoCTLocalSearch)) {
            config.setDoLocalCustomTag(Caster.toBooleanValue(strDoCTLocalSearch.trim(), true));
        } else if (hasCS) {
            config.setDoLocalCustomTag(configServer.doLocalCustomTag());
        }
    }
    // do custom tag deep search
    if (mode == ConfigImpl.MODE_STRICT) {
        config.setDoCustomTagDeepSearch(false);
    } else {
        String strDoCTDeepSearch = getAttr(customTag, "custom-tag-deep-search");
        if (hasAccess && !StringUtil.isEmpty(strDoCTDeepSearch)) {
            config.setDoCustomTagDeepSearch(Caster.toBooleanValue(strDoCTDeepSearch.trim(), false));
        } else if (hasCS) {
            config.setDoCustomTagDeepSearch(configServer.doCustomTagDeepSearch());
        }
    }
    // extensions
    if (mode == ConfigImpl.MODE_STRICT) {
        config.setCustomTagExtensions(Constants.getComponentExtensions());
    } else {
        String strExtensions = getAttr(customTag, "extensions");
        if (hasAccess && !StringUtil.isEmpty(strExtensions)) {
            try {
                String[] arr = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(strExtensions, ","));
                config.setCustomTagExtensions(ListUtil.trimItems(arr));
            } catch (PageException e) {
            }
        } else if (hasCS) {
            config.setCustomTagExtensions(configServer.getCustomTagExtensions());
        }
    }
    // Web Mapping
    boolean hasSet = false;
    Mapping[] mappings = null;
    if (hasAccess && ctMappings.length > 0) {
        mappings = new Mapping[ctMappings.length];
        for (int i = 0; i < ctMappings.length; i++) {
            Element ctMapping = ctMappings[i];
            String physical = ctMapping.getAttribute("physical");
            String archive = ctMapping.getAttribute("archive");
            boolean readonly = toBoolean(getAttr(ctMapping, "readonly"), false);
            boolean hidden = toBoolean(getAttr(ctMapping, "hidden"), false);
            // boolean trusted = toBoolean(getAttr(ctMapping,"trusted"), false);
            short inspTemp = inspectTemplate(ctMapping);
            // int clMaxEl = toInt(getAttr(ctMapping,"classloader-max-elements"), 100);
            String primary = getAttr(ctMapping, "primary");
            boolean physicalFirst = archive == null || !primary.equalsIgnoreCase("archive");
            hasSet = true;
            mappings[i] = new MappingImpl(config, XMLConfigAdmin.createVirtual(ctMapping), physical, archive, inspTemp, physicalFirst, hidden, readonly, true, false, true, null, -1, -1);
        // print.out(mappings[i].isPhysicalFirst());
        }
        config.setCustomTagMappings(mappings);
    }
    // Server Mapping
    if (hasCS) {
        Mapping[] originals = configServer.getCustomTagMappings();
        Mapping[] clones = new Mapping[originals.length];
        LinkedHashMap map = new LinkedHashMap();
        Mapping m;
        for (int i = 0; i < clones.length; i++) {
            m = ((MappingImpl) originals[i]).cloneReadOnly(config);
            map.put(toKey(m), m);
        // clones[i]=((MappingImpl)m[i]).cloneReadOnly(config);
        }
        if (mappings != null) {
            for (int i = 0; i < mappings.length; i++) {
                m = mappings[i];
                map.put(toKey(m), m);
            }
        }
        if (originals.length > 0) {
            clones = new Mapping[map.size()];
            Iterator it = map.entrySet().iterator();
            Map.Entry entry;
            int index = 0;
            while (it.hasNext()) {
                entry = (Entry) it.next();
                clones[index++] = (Mapping) entry.getValue();
            // print.out("c:"+clones[index-1]);
            }
            hasSet = true;
            // print.err("set:"+clones.length);
            config.setCustomTagMappings(clones);
        }
    }
    if (!hasSet) {
    // MappingImpl m=new
    // MappingImpl(config,"/default-customtags/","{lucee-web}/customtags/",null,false,true,false,false,true,false,true);
    // config.setCustomTagMappings(new
    // Mapping[]{m.cloneReadOnly(config)});
    }
}
Also used : Entry(java.util.Map.Entry) PageException(lucee.runtime.exp.PageException) Element(org.w3c.dom.Element) Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl) lucee.aprint(lucee.aprint) LinkedHashMap(java.util.LinkedHashMap) Iterator(java.util.Iterator) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 13 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class Surveillance method infoMapping.

private static void infoMapping(Struct map, Mapping[] mappings, boolean isCustomTagMapping) throws PageException {
    if (mappings == null)
        return;
    DoubleStruct sct = new DoubleStruct();
    long size;
    MappingImpl mapping;
    for (int i = 0; i < mappings.length; i++) {
        mapping = (MappingImpl) mappings[i];
        // archive classloader
        size = mapping.getArchive() != null ? mapping.getArchive().length() : 0;
        sct.set("archiveClassLoader", Caster.toDouble(size));
        // physical classloader
        size = mapping.getPhysical() != null ? mapping.getPhysical().length() : 0;
        sct.set("physicalClassLoader", Caster.toDouble(size));
        // pagepool
        size = SizeOf.size(mapping.getPageSourcePool());
        sct.set(PAGE_POOL, Caster.toDouble(size));
        map.set(!isCustomTagMapping ? mapping.getVirtual() : mapping.getStrPhysical(), sct);
    }
}
Also used : DoubleStruct(lucee.runtime.type.DoubleStruct) MappingImpl(lucee.runtime.MappingImpl)

Example 14 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class ConfigImpl method setTagDirectory.

protected void setTagDirectory(Resource tagDirectory) {
    // this.tagDirectory=tagDirectory;
    this.tagMapping = new MappingImpl(this, "/mapping-tag/", tagDirectory.getAbsolutePath(), null, ConfigImpl.INSPECT_NEVER, true, true, true, true, false, true, null, -1, -1);
    TagLib tlc = getCoreTagLib(CFMLEngine.DIALECT_CFML);
    TagLib tll = getCoreTagLib(CFMLEngine.DIALECT_LUCEE);
    // now overwrite with new data
    if (tagDirectory.isDirectory()) {
        String[] files = tagDirectory.list(new ExtensionResourceFilter(getMode() == ConfigImpl.MODE_STRICT ? Constants.getComponentExtensions() : Constants.getExtensions()));
        for (int i = 0; i < files.length; i++) {
            if (tlc != null)
                createTag(tlc, files[i]);
            if (tll != null)
                createTag(tll, files[i]);
        }
    }
}
Also used : TagLib(lucee.transformer.library.tag.TagLib) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) MappingImpl(lucee.runtime.MappingImpl)

Example 15 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class ConfigWebImpl method getApplicationMapping.

public Mapping getApplicationMapping(String type, String virtual, String physical, String archive, boolean physicalFirst, boolean ignoreVirtual) {
    String key = type + ":" + virtual.toLowerCase() + ":" + (physical == null ? "" : physical.toLowerCase()) + ":" + (archive == null ? "" : archive.toLowerCase()) + ":" + physicalFirst;
    key = Long.toString(HashUtil.create64BitHash(key), Character.MAX_RADIX);
    Mapping m = applicationMappings.get(key);
    if (m == null) {
        m = new MappingImpl(this, virtual, physical, archive, Config.INSPECT_UNDEFINED, physicalFirst, false, false, false, true, ignoreVirtual, null, -1, -1);
        applicationMappings.put(key, m);
    }
    return m;
}
Also used : Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl)

Aggregations

MappingImpl (lucee.runtime.MappingImpl)18 Mapping (lucee.runtime.Mapping)11 Iterator (java.util.Iterator)4 Resource (lucee.commons.io.res.Resource)4 Entry (java.util.Map.Entry)3 lucee.aprint (lucee.aprint)3 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)3 Query (lucee.runtime.type.Query)3 QueryImpl (lucee.runtime.type.QueryImpl)3 Element (org.w3c.dom.Element)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 DirectoryResourceFilter (lucee.commons.io.res.filter.DirectoryResourceFilter)2 OrResourceFilter (lucee.commons.io.res.filter.OrResourceFilter)2 ResourceFilter (lucee.commons.io.res.filter.ResourceFilter)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 Struct (lucee.runtime.type.Struct)2 IOException (java.io.IOException)1