use of lucee.transformer.library.tag.TagLibTag in project Lucee by lucee.
the class CFTag method validateAttributes.
private static void validateAttributes(Component cfc, StructImpl attributesScope, String tagName) throws ApplicationException, ExpressionException {
TagLibTag tag = getAttributeRequirments(cfc, false);
if (tag == null)
return;
if (tag.getAttributeType() == TagLibTag.ATTRIBUTE_TYPE_FIXED || tag.getAttributeType() == TagLibTag.ATTRIBUTE_TYPE_MIXED) {
Iterator<Entry<String, TagLibTagAttr>> it = tag.getAttributes().entrySet().iterator();
int count = 0;
Collection.Key key;
TagLibTagAttr attr;
Object value;
Entry<String, TagLibTagAttr> entry;
// check existing attributes
while (it.hasNext()) {
entry = it.next();
count++;
key = KeyImpl.toKey(entry.getKey(), null);
attr = entry.getValue();
value = attributesScope.get(key, null);
// check alias
if (value == null) {
String[] alias = attr.getAlias();
if (!ArrayUtil.isEmpty(alias))
for (int i = 0; i < alias.length; i++) {
value = attributesScope.get(KeyImpl.toKey(alias[i], null), null);
if (value != null)
break;
}
}
if (value == null) {
if (attr.getDefaultValue() != null) {
value = attr.getDefaultValue();
attributesScope.setEL(key, value);
} else if (attr.isRequired())
throw new ApplicationException("attribute [" + key.getString() + "] is required for tag [" + tagName + "]");
}
if (value != null) {
if (!Decision.isCastableTo(attr.getType(), value, true, true, -1))
throw new CasterException(createMessage(attr.getType(), value));
}
}
// check if there are attributes not supported
if (tag.getAttributeType() == TagLibTag.ATTRIBUTE_TYPE_FIXED && count < attributesScope.size()) {
Collection.Key[] keys = attributesScope.keys();
for (int i = 0; i < keys.length; i++) {
if (tag.getAttribute(keys[i].getLowerString(), true) == null)
throw new ApplicationException("attribute [" + keys[i].getString() + "] is not supported for tag [" + tagName + "]");
}
// Attribute susi is not allowed for tag cfmail
}
}
}
use of lucee.transformer.library.tag.TagLibTag in project Lucee by lucee.
the class ConfigImpl method addTag.
protected void addTag(String nameSpace, String nameSpaceSeperator, String name, int dialect, ClassDefinition cd) {
if (dialect == CFMLEngine.DIALECT_BOTH) {
addTag(nameSpace, nameSpaceSeperator, name, CFMLEngine.DIALECT_CFML, cd);
addTag(nameSpace, nameSpaceSeperator, name, CFMLEngine.DIALECT_LUCEE, cd);
return;
}
TagLib[] tlds = dialect == CFMLEngine.DIALECT_CFML ? cfmlTlds : luceeTlds;
for (int i = 0; i < tlds.length; i++) {
if (tlds[i].getNameSpaceAndSeparator().equalsIgnoreCase(nameSpace + nameSpaceSeperator)) {
TagLibTag tlt = new TagLibTag(tlds[i]);
tlt.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_DYNAMIC);
tlt.setBodyContent("free");
tlt.setTagClassDefinition(cd);
tlt.setName(name);
tlds[i].setTag(tlt);
}
}
}
use of lucee.transformer.library.tag.TagLibTag 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.library.tag.TagLibTag 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.library.tag.TagLibTag 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.");
}
}
}
Aggregations