use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class CFMLTransformer method attribute.
/**
* Liest ein einzelnes Atribut eines tag ein (nicht NONAME).
* <br />
* EBNF:<br />
* <code>attribute-name spaces "=" spaces attribute-value;</code>
* @param tag Definition des Tag das dieses Attribut enthaelt.
* @param args Container zum Speichern einzelner Attribute Namen zum nachtraeglichen Prufen gegen die Tag-Lib.
* @return Element Attribute Element.
* @throws TemplateException
*/
private static Attribute attribute(TagData data, TagLibTag tag, ArrayList<String> args, RefBoolean allowDefaultValue) throws TemplateException {
Expression value = null;
// Name
StringBuffer sbType = new StringBuffer();
RefBoolean dynamic = new RefBooleanImpl(false);
boolean isDefaultValue = false;
boolean[] parseExpression = new boolean[2];
parseExpression[0] = true;
parseExpression[1] = false;
String name = attributeName(data.srcCode, dynamic, args, tag, sbType, parseExpression, allowDefaultValue.toBooleanValue());
// mixed in a noname attribute
if (StringUtil.isEmpty(name)) {
allowDefaultValue.setValue(false);
TagLibTagAttr attr = tag.getDefaultAttribute();
if (attr == null)
throw new TemplateException(data.srcCode, "Invalid Identifier.");
name = attr.getName();
sbType.append(attr.getType());
isDefaultValue = true;
}
comment(data.srcCode, true);
if (isDefaultValue || data.srcCode.forwardIfCurrent('=')) {
comment(data.srcCode, true);
// Value
value = attributeValue(data, tag, sbType.toString(), parseExpression[0], false, data.factory.createLitString(""));
} else // default value boolean true
{
TagLibTagAttr attr = tag.getAttribute(name);
if (attr != null)
value = attr.getUndefinedValue(data.factory);
else
value = tag.getAttributeUndefinedValue(data.factory);
if (sbType.toString().length() > 0) {
value = CastOther.toExpression(value, sbType.toString());
}
}
comment(data.srcCode, true);
return new Attribute(dynamic.toBooleanValue(), name, value, sbType.toString());
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class PageEncoding method execute.
@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
// encoding
String str = ASMUtil.getAttributeString(tag, "charset", null);
if (str == null)
throw new TemplateException(data.srcCode, "attribute [pageencoding] of the tag [processingdirective] must be a constant value");
Charset cs = CharsetUtil.toCharset(str);
PageSourceCode psc = data.srcCode instanceof PageSourceCode ? (PageSourceCode) data.srcCode : null;
if (psc == null || cs.equals(psc.getCharset()) || CharsetUtil.UTF8.equals(psc.getCharset())) {
cs = null;
}
if (cs != null) {
throw new ProcessingDirectiveException(data.srcCode, cs, null, data.srcCode.getWriteLog());
}
return null;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLExprTransformer method conditionalOp.
private Expression conditionalOp(ExprData data) throws TemplateException {
Expression expr = impOp(data);
if (data.srcCode.forwardIfCurrent('?')) {
comments(data);
// Elvis
if (data.srcCode.forwardIfCurrent(':')) {
comments(data);
Expression right = assignOp(data);
if (expr instanceof ExprBoolean)
return expr;
if (!(expr instanceof Variable))
throw new TemplateException(data.srcCode, "left operand of the Elvis operator has to be a variable or a function call");
Variable left = (Variable) expr;
/*List<Member> members = left.getMembers();
Member last=null;
for(Member m:members) {
last=m;
m.setSafeNavigated(true);
}
if(last!=null) {
last.setSafeNavigatedValue(right);
}
return left;*/
return OpElvis.toExpr(left, right);
}
Expression left = assignOp(data);
comments(data);
if (!data.srcCode.forwardIfCurrent(':'))
throw new TemplateException(data.srcCode, "invalid conditional operator");
comments(data);
Expression right = assignOp(data);
expr = OpContional.toExpr(expr, left, right);
}
return expr;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLExprTransformer method checker.
/**
* Hier werden die verschiedenen Moeglichen Werte erkannt
* und jenachdem wird mit der passenden Methode weitergefahren
* <br />
* EBNF:<br />
* <code>string | number | dynamic | sharp;</code>
* @return CFXD Element
* @throws TemplateException
*/
private Expression checker(ExprData data) throws TemplateException {
Expression expr = null;
// String
if ((expr = string(data)) != null) {
expr = subDynamic(data, expr, false, false);
// (expr instanceof Literal)?STATIC:DYNAMIC;// STATIC
data.mode = STATIC;
return expr;
}
// Number
if ((expr = number(data)) != null) {
expr = subDynamic(data, expr, false, false);
// (expr instanceof Literal)?STATIC:DYNAMIC;// STATIC
data.mode = STATIC;
return expr;
}
// closure
if ((expr = closure(data)) != null) {
data.mode = DYNAMIC;
return expr;
}
// lambda
if ((expr = lambda(data)) != null) {
data.mode = DYNAMIC;
return expr;
}
// Dynamic
if ((expr = dynamic(data)) != null) {
expr = newOp(data, expr);
expr = subDynamic(data, expr, true, false);
data.mode = DYNAMIC;
return expr;
}
// Sharp
if ((expr = sharp(data)) != null) {
data.mode = DYNAMIC;
return expr;
}
// JSON
if ((expr = json(data, JSON_ARRAY, '[', ']')) != null) {
expr = subDynamic(data, expr, false, false);
data.mode = DYNAMIC;
return expr;
}
if ((expr = json(data, JSON_STRUCT, '{', '}')) != null) {
expr = subDynamic(data, expr, false, false);
data.mode = DYNAMIC;
return expr;
}
// else Error
throw new TemplateException(data.srcCode, "Syntax Error, Invalid Construct");
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLExprTransformer method subDynamic.
private Expression subDynamic(ExprData data, Expression expr, boolean tryStatic, boolean isStaticChild) throws TemplateException {
String name = null;
Invoker invoker = null;
// Loop over nested Variables
boolean safeNavigation;
while (data.srcCode.isValidIndex()) {
safeNavigation = false;
ExprString nameProp = null, namePropUC = null;
// []
if (data.srcCode.forwardIfCurrent('[')) {
isStaticChild = false;
// get Next Var
nameProp = structElement(data);
namePropUC = nameProp;
// Valid Syntax ???
if (!data.srcCode.forwardIfCurrent(']'))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing []] not found");
} else // .
if (isStaticChild || data.srcCode.forwardIfCurrent('.') || (safeNavigation = data.srcCode.forwardIfCurrent('?', '.'))) {
isStaticChild = false;
// Extract next Var String
comments(data);
Position line = data.srcCode.getPosition();
name = identifier(data, true);
if (name == null)
throw new TemplateException(data.srcCode, "Invalid identifier");
comments(data);
nameProp = Identifier.toIdentifier(data.factory, name, line, data.srcCode.getPosition());
namePropUC = Identifier.toIdentifier(data.factory, name, data.settings.dotNotationUpper ? Identifier.CASE_UPPER : Identifier.CASE_ORIGNAL, line, data.srcCode.getPosition());
} else // finish
{
break;
}
comments(data);
if (expr instanceof Invoker) {
invoker = (Invoker) expr;
} else {
invoker = new ExpressionInvoker(expr);
expr = invoker;
}
// safe navigation
Member member;
if (safeNavigation) {
List<Member> members = invoker.getMembers();
if (members.size() > 0) {
member = members.get(members.size() - 1);
member.setSafeNavigated(true);
}
}
// Method
if (data.srcCode.isCurrent('(')) {
// properly this is never used
if (nameProp == null && name != null)
nameProp = Identifier.toIdentifier(data.factory, name, Identifier.CASE_ORIGNAL, null, null);
invoker.addMember(member = getFunctionMember(data, nameProp, false));
} else
// property
invoker.addMember(member = data.factory.createDataMember(namePropUC));
if (safeNavigation) {
member.setSafeNavigated(true);
}
}
// STATIC SCOPE CALL
if (tryStatic) {
comments(data);
Expression staticCall = staticScope(data, expr);
if (staticCall != null)
return staticCall;
}
return expr;
}
Aggregations