use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.
the class Argument method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
String ns = libTag.getTagLib().getNameSpaceAndSeparator();
String functionName = ns + "function";
ASMUtil.isLiteralAttribute(tag, "type", ASMUtil.TYPE_STRING, false, true);
ASMUtil.isLiteralAttribute(tag, "name", ASMUtil.TYPE_STRING, false, true);
// ASMUtil.isLiteralAttribute(tag,"hint",ASMUtil.TYPE_STRING,false,true);
// ASMUtil.isLiteralAttribute(tag,"displayname",ASMUtil.TYPE_STRING,false,true);
// check if default can be converted to a literal value that match the type declration.
checkDefaultValue(tag);
// check attribute passby
Attribute attrPassBy = tag.getAttribute("passby");
if (attrPassBy != null) {
ExprString expr = tag.getFactory().toExprString(attrPassBy.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute passby of the Tag Argument, must be a literal string");
LitString lit = (LitString) expr;
String passBy = lit.getString().toLowerCase().trim();
if (!"value".equals(passBy) && !"ref".equals(passBy) && !"reference".equals(passBy))
throw new EvaluatorException("Attribute passby of the Tag Argument has an invalid value [" + passBy + "], valid values are [reference,value]");
}
// check if tag is direct inside function
if (!ASMUtil.isParentTag(tag, functionName)) {
Tag parent = ASMUtil.getParentTag(tag);
String addText = (parent != null) ? "but tag " + libTag.getFullName() + " is inside tag " + parent.getFullname() + "" : "but tag " + libTag.getFullName() + " has no parent";
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be direct inside a " + functionName + " tag, " + addText);
}
// TODO check if there is a tag other than argument and text before
}
use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.
the class Break method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
String ns = libTag.getTagLib().getNameSpaceAndSeparator();
String loopName = ns + "loop";
String whileName = ns + "while";
// label
String label = null;
Attribute attrLabel = tag.getAttribute("label");
if (attrLabel != null) {
TagBreak tb = (TagBreak) tag;
label = variableToString(tag, attrLabel, null);
if (label != null) {
tb.setLabel(label = label.trim());
tag.removeAttribute("label");
} else if (ASMUtil.isLiteralAttribute(tag, attrLabel, ASMUtil.TYPE_STRING, false, true)) {
LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
label = ls.getString();
if (!StringUtil.isEmpty(label, true)) {
tb.setLabel(label = label.trim());
tag.removeAttribute("label");
} else
label = null;
}
}
// no base tag found
if (!ASMUtil.hasAncestorBreakFCStatement(tag, label)) {
if (tag.isScriptBase()) {
if (StringUtil.isEmpty(label))
throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a looping statement or tag");
throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a looping statement or tag with the label [" + label + "]");
}
if (StringUtil.isEmpty(label))
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag");
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag with the label [" + label + "]");
}
}
use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.
the class Else method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
String ns = libTag.getTagLib().getNameSpaceAndSeparator();
String ifName = ns + "if";
// check if tag is direct inside if
if (!ASMUtil.isParentTag(tag, TagIf.class)) {
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be direct inside a " + ifName + " tag");
}
// check if is there a elseif tag after this tag
if (ASMUtil.hasSisterTagAfter(tag, "elseif"))
throw new EvaluatorException("Wrong Context, tag cfelseif can't be after tag else");
// check if tag else is unique
if (ASMUtil.hasSisterTagWithSameName(tag))
throw new EvaluatorException("Wrong Context, tag else must be once inside the tag if");
}
use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.
the class ElseIf method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
String ns = libTag.getTagLib().getNameSpaceAndSeparator();
String ifName = ns + "if";
// check if tag is direct inside if
if (!ASMUtil.isParentTag(tag, TagIf.class))
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be direct inside a " + ifName + " tag");
}
use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.
the class Function method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws EvaluatorException {
// Body p=(Body) tag.getParent();
// Statement pp = p.getParent();
boolean isCI = true;
try {
isCI = ASMUtil.getAncestorPage(tag).isComponent() || ASMUtil.getAncestorPage(tag).isInterface();
} catch (TransformerException e) {
}
Attribute attrName = tag.getAttribute("name");
if (attrName != null) {
Expression expr = attrName.getValue();
PageSource ps = null;
if (expr instanceof LitString && !isCI) {
Page p = ASMUtil.getAncestorPage(tag, null);
if (p != null) {
SourceCode sc = p.getSourceCode();
if (sc instanceof PageSourceCode) {
PageSourceCode psc = (PageSourceCode) sc;
ps = psc.getPageSource();
}
}
checkFunctionName(((LitString) expr).getString(), flibs, ps);
}
}
// attribute modifier
boolean isStatic = false;
{
Attribute attrModifier = tag.getAttribute("modifier");
if (attrModifier != null) {
ExprString expr = tag.getFactory().toExprString(attrModifier.getValue());
if (!(expr instanceof Literal))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
String modifier = StringUtil.emptyIfNull(((Literal) expr).getString()).trim();
if (!StringUtil.isEmpty(modifier) && !"abstract".equalsIgnoreCase(modifier) && !"final".equalsIgnoreCase(modifier) && !"static".equalsIgnoreCase(modifier))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
isStatic = "static".equalsIgnoreCase(modifier);
boolean abstr = "abstract".equalsIgnoreCase(modifier);
if (abstr)
throwIfNotEmpty(tag);
}
}
// cachedWithin
{
Attribute attrCachedWithin = tag.getAttribute("cachedwithin");
if (attrCachedWithin != null) {
Expression val = attrCachedWithin.getValue();
tag.addAttribute(new Attribute(attrCachedWithin.isDynamicType(), attrCachedWithin.getName(), ASMUtil.cachedWithinValue(val), attrCachedWithin.getType()));
}
}
// Attribute localMode
{
Attribute attrLocalMode = tag.getAttribute("localmode");
if (attrLocalMode != null) {
Expression expr = attrLocalMode.getValue();
String str = ASMUtil.toString(expr, null);
if (!StringUtil.isEmpty(str) && AppListenerUtil.toLocalMode(str, -1) == -1)
throw new EvaluatorException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)");
// boolean output = ((LitBoolean)expr).getBooleanValue();
// if(!output) ASMUtil.removeLiterlChildren(tag, true);
}
}
// Attribute Output
{
Attribute attrOutput = tag.getAttribute("output");
if (attrOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// Buffer output
{
Attribute attrBufferOutput = tag.getAttribute("bufferoutput");
if (attrBufferOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrBufferOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute bufferOutput of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// check attribute values
Map<String, Attribute> attrs = tag.getAttributes();
Iterator<Attribute> it = attrs.values().iterator();
while (it.hasNext()) {
checkAttributeValue(tag, it.next());
}
// add to static scope
if (isStatic) {
// remove that tag from parent
ASMUtil.remove(tag);
Body body = (Body) tag.getParent();
StaticBody sb = Static.getStaticBody(body);
sb.addStatement(tag);
}
}
Aggregations