use of lucee.transformer.library.tag.TagLibTagAttr in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method attribute.
private final Attribute attribute(TagLibTag tlt, ExprData data, ArrayList<String> args, Expression defaultValue, Object oAllowExpression, boolean allowTwiceAttr, boolean allowColonSeparator) throws TemplateException {
StringBuffer sbType = new StringBuffer();
RefBoolean dynamic = new RefBooleanImpl(false);
// Name
String name = attributeName(data.srcCode, args, tlt, dynamic, sbType, allowTwiceAttr, !allowColonSeparator);
String nameLC = name == null ? null : name.toLowerCase();
boolean allowExpression = false;
if (oAllowExpression instanceof Boolean)
allowExpression = ((Boolean) oAllowExpression).booleanValue();
else if (oAllowExpression instanceof String)
allowExpression = ((String) oAllowExpression).equalsIgnoreCase(nameLC);
Expression value = null;
comments(data);
// value
boolean hasValue = data.srcCode.forwardIfCurrent('=') || (allowColonSeparator && data.srcCode.forwardIfCurrent(':'));
if (hasValue) {
comments(data);
value = attributeValue(data, allowExpression);
} else {
value = defaultValue;
}
comments(data);
// Type
TagLibTagAttr tlta = null;
if (tlt != null) {
tlta = tlt.getAttribute(nameLC, true);
if (tlta != null && tlta.getName() != null)
nameLC = tlta.getName();
}
return new Attribute(dynamic.toBooleanValue(), name, tlta != null ? CastOther.toExpression(value, tlta.getType()) : value, sbType.toString(), !hasValue);
}
use of lucee.transformer.library.tag.TagLibTagAttr in project Lucee by lucee.
the class CFMLTransformer method attributeName.
/**
* Liest den Namen eines Attribut ein, je nach Attribut-Definition innerhalb der Tag-Lib,
* wird der Name ueber den identifier oder den Expression Transformer eingelesen.
* <ul>
* <li>FIX und DYNAMIC --> identifier </li>
* <li>FULLDYNAMIC --> Expression Transformer </li>
* </ul>
* <br />
* EBNF:<br />
* <code>("expression"|'expression'|expression) | identifier;(* Ruft identifier oder den Expression Transformer auf je nach Attribute Definition in der Tag Lib. *)</code>
* @param dynamic
* @param args Container zum Speichern einzelner Attribute Namen zum nachtraeglichen Prufen gegen die Tag-Lib.
* @param tag Aktuelles tag aus der Tag-Lib
* @param sbType Die Methode speichert innerhalb von sbType den Typ des Tags, zur Interpretation in der attribute Methode.
* @param parseExpression Soll der Wert des Attributes geparst werden
* @return Attribute Name
* @throws TemplateException
*/
private static String attributeName(SourceCode cfml, RefBoolean dynamic, ArrayList<String> args, TagLibTag tag, StringBuffer sbType, boolean[] parseExpression, boolean allowDefaultValue) throws TemplateException {
String _id = identifier(cfml, !allowDefaultValue, true);
if (StringUtil.isEmpty(_id)) {
return null;
}
int typeDef = tag.getAttributeType();
String id = StringUtil.toLowerCase(_id);
if (args.contains(id))
throw createTemplateException(cfml, "you can't use the same tag attribute [" + id + "] twice", tag);
args.add(id);
if ("attributecollection".equals(id)) {
dynamic.setValue(tag.getAttribute(id, true) == null);
sbType.append("struct");
parseExpression[0] = true;
parseExpression[1] = true;
} else if (typeDef == TagLibTag.ATTRIBUTE_TYPE_FIXED || typeDef == TagLibTag.ATTRIBUTE_TYPE_MIXED) {
TagLibTagAttr attr = tag.getAttribute(id, true);
if (attr == null) {
if (typeDef == TagLibTag.ATTRIBUTE_TYPE_FIXED) {
String names = tag.getAttributeNames();
if (StringUtil.isEmpty(names))
throw createTemplateException(cfml, "Attribute " + id + " is not allowed for tag " + tag.getFullName(), tag);
try {
names = ListUtil.sort(names, "textnocase", null, null);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
throw createTemplateException(cfml, "Attribute " + id + " is not allowed for tag " + tag.getFullName(), "valid attribute names are [" + names + "]", tag);
}
dynamic.setValue(true);
} else {
id = attr.getName();
sbType.append(attr.getType());
parseExpression[0] = attr.getRtexpr();
}
} else if (typeDef == TagLibTag.ATTRIBUTE_TYPE_DYNAMIC) {
dynamic.setValue(true);
}
return id;
}
use of lucee.transformer.library.tag.TagLibTagAttr in project Lucee by lucee.
the class CFMLTransformer method setAddional.
private static void setAddional(PageExceptionImpl pe, TagLibTag tlt) {
Map<String, TagLibTagAttr> attrs = tlt.getAttributes();
Iterator<Entry<String, TagLibTagAttr>> it = attrs.entrySet().iterator();
Entry<String, TagLibTagAttr> entry;
TagLibTagAttr attr;
// Pattern
StringBuilder pattern = new StringBuilder("<");
pattern.append((tlt.getFullName()));
StringBuilder req = new StringBuilder();
StringBuilder opt = new StringBuilder();
StringBuilder tmp;
pattern.append(" ");
int c = 0;
while (it.hasNext()) {
entry = it.next();
attr = entry.getValue();
tmp = attr.isRequired() ? req : opt;
tmp.append(" ");
if (!attr.isRequired())
tmp.append("[");
if (c++ > 0)
pattern.append(" ");
tmp.append(attr.getName());
tmp.append("=\"");
tmp.append(attr.getType());
tmp.append("\"");
if (!attr.isRequired())
tmp.append("]");
}
if (req.length() > 0)
pattern.append(req);
if (opt.length() > 0)
pattern.append(opt);
if (tlt.getAttributeType() == TagLibTag.ATTRIBUTE_TYPE_MIXED || tlt.getAttributeType() == TagLibTag.ATTRIBUTE_TYPE_DYNAMIC)
pattern.append(" ...");
pattern.append(">");
if (tlt.getHasBody()) {
if (tlt.isBodyReq()) {
pattern.append("</");
pattern.append(tlt.getFullName());
pattern.append(">");
} else if (tlt.isBodyFree()) {
pattern.append("[</");
pattern.append(tlt.getFullName());
pattern.append(">]");
}
}
pe.setAdditional(KeyConstants._Pattern, pattern);
// Documentation
StringBuilder doc = new StringBuilder(tlt.getDescription());
req = new StringBuilder();
opt = new StringBuilder();
doc.append("\n");
it = attrs.entrySet().iterator();
while (it.hasNext()) {
entry = it.next();
attr = entry.getValue();
tmp = attr.isRequired() ? req : opt;
tmp.append("* ");
tmp.append(attr.getName());
tmp.append(" (");
tmp.append(attr.getType());
tmp.append("): ");
tmp.append(attr.getDescription());
tmp.append("\n");
}
if (req.length() > 0)
doc.append("\nRequired:\n").append(req);
if (opt.length() > 0)
doc.append("\nOptional:\n").append(opt);
pe.setAdditional(KeyImpl.init("Documentation"), doc);
}
use of lucee.transformer.library.tag.TagLibTagAttr in project Lucee by lucee.
the class CFTag method getAttributeRequirments.
private static TagLibTag getAttributeRequirments(Component cfc, boolean runtime) {
Struct meta = null;
Member mem = cfc != null ? cfc.getMember(Component.ACCESS_PRIVATE, KeyConstants._metadata, true, false) : null;
if (mem != null)
meta = Caster.toStruct(mem.getValue(), null, false);
if (meta == null)
return null;
TagLibTag tag = new TagLibTag(null);
// TAG
// type
String type = Caster.toString(meta.get(ATTRIBUTE_TYPE, "dynamic"), "dynamic");
if ("fixed".equalsIgnoreCase(type))
tag.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_FIXED);
else
// else if("mixed".equalsIgnoreCase(type))tag.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_MIXED);
// else if("noname".equalsIgnoreCase(type))tag.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_NONAME);
tag.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_DYNAMIC);
if (!runtime) {
// hint
String hint = Caster.toString(meta.get(KeyConstants._hint, null), null);
if (!StringUtil.isEmpty(hint))
tag.setDescription(hint);
}
// ATTRIBUTES
Struct attributes = Caster.toStruct(meta.get(KeyConstants._ATTRIBUTES, null), null, false);
if (attributes != null) {
Iterator<Entry<Key, Object>> it = attributes.entryIterator();
// Iterator it = attributes.entrySet().iterator();
Entry<Key, Object> entry;
TagLibTagAttr attr;
Struct sct;
String name;
Object defaultValue;
while (it.hasNext()) {
entry = it.next();
name = Caster.toString(entry.getKey(), null);
if (StringUtil.isEmpty(name))
continue;
attr = new TagLibTagAttr(tag);
attr.setName(name);
sct = Caster.toStruct(entry.getValue(), null, false);
if (sct != null) {
attr.setRequired(Caster.toBooleanValue(sct.get(KeyConstants._required, Boolean.FALSE), false));
attr.setType(Caster.toString(sct.get(KeyConstants._type, "any"), "any"));
defaultValue = sct.get(KeyConstants._default, null);
if (defaultValue != null)
attr.setDefaultValue(defaultValue);
if (!runtime) {
attr.setDescription(Caster.toString(sct.get(KeyConstants._hint, null), null));
attr.setRtexpr(Caster.toBooleanValue(sct.get(RT_EXPR_VALUE, Boolean.TRUE), true));
}
}
tag.setAttribute(attr);
}
}
return tag;
}
use of lucee.transformer.library.tag.TagLibTagAttr in project Lucee by lucee.
the class TagUtil method _addTagMetaData.
private static void _addTagMetaData(PageContext pc, ConfigWebImpl cw, int dialect) {
TagLibTagAttr attrFileName, attrIsWeb;
String filename;
Boolean isWeb;
TagLibTag tlt;
TagLib[] tlds = cw.getTLDs(dialect);
for (int i = 0; i < tlds.length; i++) {
Map<String, TagLibTag> tags = tlds[i].getTags();
Iterator<TagLibTag> it = tags.values().iterator();
while (it.hasNext()) {
tlt = it.next();
if (tlt.getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.CFTagCore")) {
attrFileName = tlt.getAttribute("__filename");
attrIsWeb = tlt.getAttribute("__isweb");
if (attrFileName != null && attrIsWeb != null) {
filename = Caster.toString(attrFileName.getDefaultValue(), null);
isWeb = Caster.toBoolean(attrIsWeb.getDefaultValue(), null);
if (filename != null && isWeb != null) {
addTagMetaData(pc, tlds[i], tlt, filename, isWeb.booleanValue());
}
}
}
}
}
}
Aggregations