use of lucee.runtime.Mapping in project Lucee by lucee.
the class Admin method doCompileMapping.
private Mapping doCompileMapping(short mappingType, String virtual, boolean stoponerror, Boolean ignoreScopes) throws PageException {
if (StringUtil.isEmpty(virtual))
return null;
if (!StringUtil.startsWith(virtual, '/'))
virtual = '/' + virtual;
if (!StringUtil.endsWith(virtual, '/'))
virtual += '/';
Mapping[] mappings = null;
if (mappingType == MAPPING_CFC)
mappings = config.getComponentMappings();
else if (mappingType == MAPPING_CT)
mappings = config.getCustomTagMappings();
else
mappings = config.getMappings();
for (int i = 0; i < mappings.length; i++) {
Mapping mapping = mappings[i];
if (mapping.getVirtualLowerCaseWithSlash().equals(virtual)) {
Map<String, String> errors = stoponerror ? null : MapFactory.<String, String>getConcurrentMap();
doCompileFile(mapping, mapping.getPhysical(), "", errors, ignoreScopes);
if (errors != null && errors.size() > 0) {
StringBuilder sb = new StringBuilder();
Iterator<String> it = errors.keySet().iterator();
Object key;
while (it.hasNext()) {
key = it.next();
if (sb.length() > 0)
sb.append("\n\n");
sb.append(errors.get(key));
}
throw new ApplicationException(sb.toString());
}
return mapping;
}
}
return null;
}
use of lucee.runtime.Mapping 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()]));
}
use of lucee.runtime.Mapping 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) });
}
}
use of lucee.runtime.Mapping 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)});
}
}
use of lucee.runtime.Mapping in project Lucee by lucee.
the class Controler method doCheckMappings.
private void doCheckMappings(ConfigWeb config) {
Mapping[] mappings = config.getMappings();
for (int i = 0; i < mappings.length; i++) {
Mapping mapping = mappings[i];
mapping.check();
}
}
Aggregations