use of lucee.transformer.bytecode.statement.tag.Tag 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.Tag 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.Tag in project Lucee by lucee.
the class Interface method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
super.evaluate(tag, libTag);
Body body = tag.getBody();
List<Statement> statments = body.getStatements();
Statement stat;
Iterator<Statement> it = statments.iterator();
Tag t;
while (it.hasNext()) {
stat = it.next();
if (stat instanceof PrintOut) {
// body.remove(stat);
} else if (stat instanceof Tag) {
t = (Tag) stat;
if (stat instanceof TagImport) {
// ignore
} else if (stat instanceof TagFunction) {
Function.throwIfNotEmpty(t);
Attribute attr = t.getAttribute("access");
if (attr != null) {
ExprString expr = t.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("the attribute access of the Tag function inside an interface must contain a constant value");
String access = ((LitString) expr).getString().trim();
if (!"public".equalsIgnoreCase(access))
throw new EvaluatorException("the attribute access of the tag function inside an interface definition can only have the value [public] not [" + access + "]");
} else
t.addAttribute(new Attribute(false, "access", stat.getFactory().createLitString("public"), "string"));
} else
throw new EvaluatorException("tag " + libTag.getFullName() + " can only contain function definitions.");
}
}
}
use of lucee.transformer.bytecode.statement.tag.Tag in project Lucee by lucee.
the class Output method addEncodeToChildren.
private void addEncodeToChildren(Iterator it, Expression encodeForValue, FunctionLibFunction encodeForBIF) {
Statement stat;
while (it.hasNext()) {
stat = (Statement) it.next();
if (stat instanceof PrintOut) {
PrintOut printOut = ((PrintOut) stat);
Expression e = removeCastString(printOut.getExpr());
if (!(e instanceof Literal)) {
if (e instanceof Variable) {
Member member = ((Variable) e).getFirstMember();
if (member instanceof BIF) {
BIF bif = (BIF) member;
String cn = bif.getClassDefinition().getClassName();
if (cn.startsWith(ENCODE_FOR) || cn.equals(ESAPIEncode.class.getName())) {
continue;
}
}
}
printOut.setEncodeFor(encodeForValue);
}
} else if (stat instanceof Tag) {
Body b = ((Tag) stat).getBody();
if (b != null)
addEncodeToChildren(b.getStatements().iterator(), encodeForValue, encodeForBIF);
} else if (stat instanceof Body) {
addEncodeToChildren(((Body) stat).getStatements().iterator(), encodeForValue, encodeForBIF);
}
}
}
use of lucee.transformer.bytecode.statement.tag.Tag in project Lucee by lucee.
the class ASMUtil method getAncestorTag.
/**
* Gibt ein uebergeordnetes Tag mit dem uebergebenen Full-Name (Namespace und Name) zurueck,
* falls ein solches existiert, andernfalls wird null zurueckgegeben.
* @param el Startelement, von wo aus gesucht werden soll.
* @param fullName Name des gesuchten Tags.
* @return uebergeornetes Element oder null.
*/
public static Tag getAncestorTag(Statement stat, String fullName) {
Statement parent = stat;
Tag tag;
while (true) {
parent = parent.getParent();
if (parent == null)
return null;
if (parent instanceof Tag) {
tag = (Tag) parent;
if (tag.getFullname().equalsIgnoreCase(fullName))
return tag;
}
}
}
Aggregations