use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class EvaluatorPool method run.
/**
* Die Methode run wird aufgerufen sobald, der CFML Transformer den uebersetzungsprozess angeschlossen hat.
* Die metode run rauft darauf alle Evaluatoren auf die intern gespeicher wurden und loescht den internen Speicher.
* @throws TemplateException
*/
public void run() throws TemplateException {
{
// tags
Iterator<TagData> it = tags.iterator();
while (it.hasNext()) {
TagData td = it.next();
SourceCode cfml = td.cfml;
cfml.setPos(td.pos);
try {
if (td.libTag.getEvaluator() != null)
td.libTag.getEvaluator().evaluate(td.tag, td.libTag, td.flibs);
} catch (EvaluatorException e) {
// print.printST(e);
clear();
throw new TemplateException(cfml, e);
} catch (Throwable e) {
ExceptionUtil.rethrowIfNecessary(e);
clear();
throw new TemplateException(cfml, e);
}
}
tags.clear();
}
// functions
Iterator<FunctionData> it = functions.iterator();
while (it.hasNext()) {
FunctionData td = it.next();
SourceCode cfml = td.cfml;
cfml.setPos(td.pos);
try {
if (td.flf.getEvaluator() != null)
td.flf.getEvaluator().evaluate(td.bif, td.flf);
} catch (EvaluatorException e) {
// print.printST(e);
clear();
throw new TemplateException(cfml, e);
} catch (Throwable e) {
ExceptionUtil.rethrowIfNecessary(e);
clear();
throw new TemplateException(cfml, e);
}
}
functions.clear();
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class Import method _executeTLD.
/**
* @param fileTagLib
* @return
* @throws EvaluatorException
*/
private TagLib _executeTLD(Config config, Resource fileTagLib, String nameSpace, String nameSpaceSeparator, SourceCode cfml) throws TemplateException {
// change extesnion
String ext = ResourceUtil.getExtension(fileTagLib, null);
if ("jar".equalsIgnoreCase(ext)) {
// check anchestor file
Resource newFileTagLib = ResourceUtil.changeExtension(fileTagLib, "tld");
if (newFileTagLib.exists())
fileTagLib = newFileTagLib;
else // check inside jar
{
Resource tmp = getTLDFromJarAsFile(config, fileTagLib);
if (tmp != null)
fileTagLib = tmp;
}
}
try {
TagLib taglib = TagLibFactory.loadFromFile(fileTagLib, config.getIdentification());
taglib.setNameSpace(nameSpace);
taglib.setNameSpaceSeperator(nameSpaceSeparator);
return taglib;
} catch (TagLibException e) {
throw new TemplateException(cfml, e.getMessage());
}
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class Import method execute.
@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
TagImport ti = (TagImport) tag;
Attribute p = tag.getAttribute("prefix");
Attribute t = tag.getAttribute("taglib");
Attribute path = tag.getAttribute("path");
if (p != null || t != null) {
if (p == null)
throw new TemplateException(data.srcCode, "Wrong Context, missing attribute [prefix] for tag " + tag.getFullname());
if (t == null)
throw new TemplateException(data.srcCode, "Wrong Context, missing attribute [taglib] for tag " + tag.getFullname());
if (path != null)
throw new TemplateException(data.srcCode, "Wrong context, you have an invalid attributes constellation for the tag " + tag.getFullname() + ", " + "you cannot mix attribute [path] with attributes [taglib] and [prefix]");
return executePT(config, tag, libTag, flibs, data.srcCode);
}
if (path == null)
throw new TemplateException(data.srcCode, "Wrong context, you have an invalid attributes constellation for the tag " + tag.getFullname() + ", " + "you need to define the attributes [prefix] and [taglib], the attribute [path] or simply define a attribute value");
String strPath = ASMUtil.getAttributeString(tag, "path", null);
if (strPath == null)
throw new TemplateException(data.srcCode, "attribute [path] must be a constant value");
ti.setPath(strPath);
return null;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class Import method executePT.
private TagLib executePT(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, SourceCode sc) throws TemplateException {
// Attribute prefix
String nameSpace = ASMUtil.getAttributeString(tag, "prefix", null);
if (nameSpace == null)
throw new TemplateException(sc, "attribute [prefix] must be a constant value");
nameSpace = nameSpace.trim();
String nameSpaceSeparator = StringUtil.isEmpty(nameSpace) ? "" : ":";
// Attribute taglib
String textTagLib = ASMUtil.getAttributeString(tag, "taglib", null);
if (textTagLib == null)
throw new TemplateException(sc, "attribute [taglib] must be a constant value");
textTagLib = textTagLib.replace('\\', '/');
textTagLib = ConfigWebUtil.replacePlaceholder(textTagLib, config);
// File TagLib
String ext = ResourceUtil.getExtension(textTagLib, null);
boolean hasTldExtension = "tld".equalsIgnoreCase(ext) || "tldx".equalsIgnoreCase(ext);
Resource absFile = config.getResource(textTagLib);
// TLD
if (absFile.isFile())
return _executeTLD(config, absFile, nameSpace, nameSpaceSeparator, sc);
// Second Change
if (textTagLib.startsWith("/")) {
// config.getPhysical(textTagLib);
PageSource ps = ((ConfigImpl) config).getPageSourceExisting(null, null, textTagLib, false, false, true, false);
// config.getConfigDir()
if (ps != null) {
if (ps.physcalExists()) {
Resource file = ps.getPhyscalFile();
// TLD
if (file.isFile())
return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
}
// CTD
if (!hasTldExtension)
return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
}
} else {
PageSource ps = sc instanceof PageSourceCode ? ((PageSourceCode) sc).getPageSource() : null;
Resource sourceFile = ps == null ? null : ps.getPhyscalFile();
if (sourceFile != null) {
Resource file = sourceFile.getParentResource().getRealResource(textTagLib);
// TLD
if (file.isFile())
return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
// CTD
if (!hasTldExtension)
return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
}
}
throw new TemplateException(sc, "invalid definition of the attribute taglib [" + textTagLib + "]");
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class Loop method execute.
@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
TagLoop loop = (TagLoop) tag;
// label
try {
if (ASMUtil.isLiteralAttribute(tag, "label", ASMUtil.TYPE_STRING, false, true)) {
LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
String l = ls.getString();
if (!StringUtil.isEmpty(l, true)) {
loop.setLabel(l.trim());
tag.removeAttribute("label");
}
}
} catch (EvaluatorException e) {
throw new TemplateException(null, e);
}
return null;
}
Aggregations