use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class Component method evaluate.
@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
tagLibTag.setParseBody(false);
Attribute attr = tag.getAttribute("output");
if (attr != null) {
Expression expr = attr.getValue();
if (!(expr instanceof LitBoolean))
throw new AttributeEvaluatorException("Attribute output of the Tag Component, must be a static boolean value (true or false)");
if (((LitBoolean) expr).getBooleanValue())
tagLibTag.setParseBody(true);
}
return tagLibTag;
}
use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class Function method evaluate.
@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
tagLibTag.setParseBody(false);
Attribute attrOutput = tag.getAttribute("output");
if (attrOutput == null)
return tagLibTag;
Expression expr = CastBoolean.toExprBoolean(attrOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new AttributeEvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false)");
boolean output = ((LitBoolean) expr).getBooleanValue();
if (output)
tagLibTag.setParseBody(true);
return tagLibTag;
}
use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class Transaction method evaluate.
@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
Attribute action = tag.getAttribute("action");
if (action != null) {
Tag parent = ASMUtil.getAncestorTag(tag, tag.getFullname());
if (parent != null) {
tagLibTag = tagLibTag.duplicate(false);
tagLibTag.setBodyContent("empty");
}
}
return tagLibTag;
}
use of lucee.transformer.bytecode.statement.tag.Attribute 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.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class Argument method checkDefaultValue.
public static void checkDefaultValue(Tag tag) {
Attribute _type = tag.getAttribute("type");
if (_type != null) {
ExprString typeValue = tag.getFactory().toExprString(_type.getValue());
if (typeValue instanceof LitString) {
String strType = ((LitString) typeValue).getString();
Attribute _default = tag.getAttribute("default");
if (_default != null) {
Expression defaultValue = _default.getValue();
if (defaultValue instanceof LitString) {
String strDefault = ((LitString) defaultValue).getString();
// check for boolean
if ("boolean".equalsIgnoreCase(strType)) {
if ("true".equalsIgnoreCase(strDefault) || "yes".equalsIgnoreCase(strDefault))
tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().TRUE(), _default.getType()));
if ("false".equalsIgnoreCase(strDefault) || "no".equalsIgnoreCase(strDefault))
tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().FALSE(), _default.getType()));
}
// check for numbers
if ("number".equalsIgnoreCase(strType) || "numeric".equalsIgnoreCase(strType)) {
Double dbl = Caster.toDouble(strDefault, null);
if (dbl != null) {
tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().createLitDouble(dbl.doubleValue()), _default.getType()));
}
}
}
}
}
}
}
Aggregations