use of lucee.runtime.customtag.InitFile in project Lucee by lucee.
the class Module method initFile.
@Override
public void initFile() throws MissingIncludeException, ExpressionException {
ConfigWeb config = pageContext.getConfig();
// MUSTMUST cache like ct
// String[] filenames=getFileNames(config,getAppendix());// = appendix+'.'+config.getCFMLExtension();
Object objTemplate = attributesScope.get(KeyConstants._template, null);
Object objName = attributesScope.get(KeyConstants._name, null);
source = null;
if (objTemplate != null) {
attributesScope.removeEL(KeyConstants._template);
String template = objTemplate.toString();
if (StringUtil.startsWith(template, '/')) {
PageSource[] sources = ((PageContextImpl) pageContext).getPageSources(template);
PageSource ps = MappingImpl.isOK(sources);
if (ps == null)
throw new MissingIncludeException(sources[0], "could not find template [" + template + "], file [" + sources[0].getDisplayPath() + "] doesn't exist");
source = new InitFile(pageContext, ps, template);
} else {
source = new InitFile(pageContext, pageContext.getCurrentPageSource().getRealPage(template), template);
if (!MappingImpl.isOK(source.getPageSource())) {
throw new MissingIncludeException(source.getPageSource(), "could not find template [" + template + "], file [" + source.getPageSource().getDisplayPath() + "] doesn't exist");
}
}
// attributesScope.removeEL(TEMPLATE);
setAppendix(source.getPageSource());
} else if (objName != null) {
attributesScope.removeEL(KeyConstants._name);
String[] filenames = toRealPath(config, objName.toString());
boolean exist = false;
// appcontext mappings
Mapping[] ctms = pageContext.getApplicationContext().getCustomTagMappings();
if (ctms != null) {
outer: for (int f = 0; f < filenames.length; f++) {
for (int i = 0; i < ctms.length; i++) {
source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
if (MappingImpl.isOK(source.getPageSource())) {
exist = true;
break outer;
}
}
}
}
// config mappings
if (!exist) {
ctms = config.getCustomTagMappings();
outer: for (int f = 0; f < filenames.length; f++) {
for (int i = 0; i < ctms.length; i++) {
// TODO optimieren siehe CFTag
source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
if (MappingImpl.isOK(source.getPageSource())) {
exist = true;
break outer;
}
}
}
}
if (!exist)
throw new ExpressionException("custom tag (" + CustomTagUtil.getDisplayName(config, objName.toString()) + ") is not defined in custom tag directory [" + (ctms.length == 0 ? "no custom tag directory defined" : CustomTagUtil.toString(ctms)) + "]");
setAppendix(source.getPageSource());
} else {
throw new ExpressionException("you must define attribute template or name for tag module");
}
}
use of lucee.runtime.customtag.InitFile in project Lucee by lucee.
the class CFTagCore method createInitFile.
public static InitFile createInitFile(PageContext pageContext, boolean isweb, String filename) {
ConfigWebImpl config = (ConfigWebImpl) pageContext.getConfig();
Mapping mapping = isweb ? config.getTagMapping() : config.getServerTagMapping();
return new InitFile(pageContext, mapping.getPageSource(filename), filename);
}
use of lucee.runtime.customtag.InitFile in project Lucee by lucee.
the class ConfigImpl method listCTCache.
public Struct listCTCache() {
Struct sct = new StructImpl();
if (ctPatchCache == null)
return sct;
Iterator<Entry<String, InitFile>> it = ctPatchCache.entrySet().iterator();
Entry<String, InitFile> entry;
while (it.hasNext()) {
entry = it.next();
sct.setEL(entry.getKey(), entry.getValue().getPageSource().getDisplayPath());
}
return sct;
}
use of lucee.runtime.customtag.InitFile in project Lucee by lucee.
the class CFImportTag method initFile.
@Override
public void initFile() throws PageException {
ConfigWeb config = pageContext.getConfig();
// = appendix+'.'+config.getCFMLExtension();
String[] filenames = CustomTagUtil.getFileNames(config, getAppendix());
String strRealPathes = attributesScope.remove("__custom_tag_path").toString();
String[] realPathes = ListUtil.listToStringArray(strRealPathes, File.pathSeparatorChar);
for (int i = 0; i < realPathes.length; i++) {
if (!StringUtil.endsWith(realPathes[i], '/'))
realPathes[i] = realPathes[i] + "/";
}
// MUSTMUST use cache like regular ct
// page source
PageSource ps;
for (int rp = 0; rp < realPathes.length; rp++) {
for (int fn = 0; fn < filenames.length; fn++) {
ps = ((PageContextImpl) pageContext).getRelativePageSourceExisting(realPathes[rp] + filenames[fn]);
if (ps != null) {
source = new InitFile(pageContext, ps, filenames[fn]);
return;
}
}
}
// EXCEPTION
// message
StringBuffer msg = new StringBuffer("could not find template [");
msg.append(CustomTagUtil.getDisplayName(config, getAppendix()));
msg.append("] in the following directories [");
msg.append(strRealPathes.replace(File.pathSeparatorChar, ','));
msg.append(']');
throw new ExpressionException(msg.toString());
}
use of lucee.runtime.customtag.InitFile in project Lucee by lucee.
the class GetTagData method cfmlBasedTag.
private static Struct cfmlBasedTag(PageContext pc, TagLib tld, TagLibTag tag) throws PageException {
// Map attrs = tag.getAttributes();
TagLibTagAttr attrFilename = tag.getAttribute("__filename");
// TagLibTagAttr attrName = tag.getAttribute("__name");
TagLibTagAttr attrIsWeb = tag.getAttribute("__isweb");
String filename = Caster.toString(attrFilename.getDefaultValue());
String name = Caster.toString(attrFilename.getDefaultValue());
boolean isWeb = Caster.toBooleanValue(attrIsWeb.getDefaultValue());
InitFile source = CFTagCore.createInitFile(pc, isWeb, filename);
String callPath = ResourceUtil.removeExtension(source.getFilename(), source.getFilename());
Component cfc = ComponentLoader.loadComponent(pc, source.getPageSource(), callPath, false, true);
ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, cfc);
Struct metadata = Caster.toStruct(cw.get("metadata", null), null, false);
Struct sct = new StructImpl();
sct.set("nameSpaceSeperator", tld.getNameSpaceSeparator());
sct.set("nameSpace", tld.getNameSpace());
sct.set(KeyConstants._name, name.substring(0, name.lastIndexOf('.')));
sct.set("hasNameAppendix", Boolean.FALSE);
sct.set(KeyConstants._status, "implemeted");
sct.set(KeyConstants._type, "cfml");
sct.set("bodyType", getBodyType(tag));
sct.set("attrMin", Caster.toDouble(0));
sct.set("attrMax", Caster.toDouble(0));
sct.set("attributeCollection", getSupportAttributeCollection(tag));
// TODO add support for script for cfml tags
Struct scp = new StructImpl();
sct.set(KeyConstants._script, scp);
scp.set("rtexpr", Boolean.FALSE);
scp.set(KeyConstants._type, "none");
if (metadata != null) {
sct.set(KeyConstants._description, metadata.get("hint", ""));
sct.set("attributeType", metadata.get("attributeType", ""));
sct.set("parseBody", Caster.toBoolean(metadata.get("parseBody", Boolean.FALSE), Boolean.FALSE));
Struct _attrs = new StructImpl();
sct.set(KeyConstants._attributes, _attrs);
Struct srcAttrs = Caster.toStruct(metadata.get(KeyConstants._attributes, null), null, false);
Struct src;
if (srcAttrs != null) {
// Key[] keys = srcAttrs.keys();
Iterator<Entry<Key, Object>> it = srcAttrs.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
src = Caster.toStruct(e.getValue(), null, false);
if (Caster.toBooleanValue(src.get(KeyConstants._hidden, null), false))
continue;
Struct _attr = new StructImpl();
_attr.set(KeyConstants._status, "implemeted");
_attr.set(KeyConstants._description, src.get(KeyConstants._hint, ""));
_attr.set(KeyConstants._type, src.get(KeyConstants._type, "any"));
_attr.set(KeyConstants._required, Caster.toBoolean(src.get(KeyConstants._required, ""), null));
_attr.set("scriptSupport", "none");
_attrs.setEL(e.getKey().getLowerString(), _attr);
}
}
}
return sct;
}
Aggregations