use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class ProcessingDirective method execute.
@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
// dot notation
Boolean dotNotationUpperCase = null;
if (tag.containsAttribute("preservecase")) {
Boolean preservecase = ASMUtil.getAttributeBoolean(tag, "preservecase", null);
if (preservecase == null)
throw new TemplateException(data.srcCode, "attribute [preserveCase] of the tag [processingdirective] must be a constant boolean value");
dotNotationUpperCase = preservecase.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
if (dotNotationUpperCase == data.settings.dotNotationUpper)
dotNotationUpperCase = null;
}
// page encoding
Charset cs = null;
if (tag.containsAttribute("pageencoding")) {
String str = ASMUtil.getAttributeString(tag, "pageencoding", null);
if (str == null)
throw new TemplateException(data.srcCode, "attribute [pageencoding] of the tag [processingdirective] must be a constant value");
cs = CharsetUtil.toCharset(str);
PageSourceCode psc = data.srcCode instanceof PageSourceCode ? (PageSourceCode) data.srcCode : null;
if (psc == null || cs.equals(psc.getCharset())) {
cs = null;
}
}
// execution log
Boolean exeLog = null;
if (tag.containsAttribute("executionlog")) {
String strExeLog = ASMUtil.getAttributeString(tag, "executionlog", null);
exeLog = Caster.toBoolean(strExeLog, null);
if (exeLog == null)
throw new TemplateException(data.srcCode, "attribute [executionlog] of the tag [processingdirective] must be a constant boolean value");
if (exeLog.booleanValue() == data.srcCode.getWriteLog())
exeLog = null;
}
if (cs != null || exeLog != null || dotNotationUpperCase != null) {
if (cs == null) {
if (data.srcCode instanceof PageSourceCode)
cs = ((PageSourceCode) data.srcCode).getCharset();
else
cs = CharsetUtil.UTF8;
}
if (exeLog == null)
exeLog = data.srcCode.getWriteLog() ? Boolean.TRUE : Boolean.FALSE;
if (dotNotationUpperCase == null)
dotNotationUpperCase = data.settings.dotNotationUpper;
throw new ProcessingDirectiveException(data.srcCode, cs, dotNotationUpperCase, exeLog);
}
return null;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLExprTransformer method assignOp.
/**
* Transfomiert Zuweisungs Operation.
* <br />
* EBNF:<br />
* <code>eqvOp ["=" spaces assignOp];</code>
* @return CFXD Element
* @throws TemplateException
*/
protected Expression assignOp(ExprData data) throws TemplateException {
Expression expr = conditionalOp(data);
if (data.srcCode.forwardIfCurrent('=')) {
comments(data);
if (data.mode == STATIC)
expr = new DynAssign(expr, assignOp(data));
else {
if (expr instanceof Variable) {
Expression value = assignOp(data);
expr = new Assign((Variable) expr, value, data.srcCode.getPosition());
} else if (expr instanceof Null) {
Variable var = ((Null) expr).toVariable();
Expression value = assignOp(data);
expr = new Assign(var, value, data.srcCode.getPosition());
} else
throw new TemplateException(data.srcCode, "invalid assignment left-hand side (" + expr.getClass().getName() + ")");
}
}
// patch for test()(); only works at the end of an expression!
comments(data);
while (data.srcCode.isCurrent('(')) {
comments(data);
Call call = new Call(expr);
getFunctionMemberAttrs(data, null, false, call, null);
call.setEnd(data.srcCode.getPosition());
comments(data);
expr = call;
}
return expr;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLExprTransformer method dynamic.
/**
* Liest den folgenden idetifier ein und prueft ob dieser ein boolscher Wert ist.
* Im Gegensatz zu CFMX wird auch "yes" und "no" als bolscher <wert akzeptiert,
* was bei CFMX nur beim Umwandeln einer Zeichenkette zu einem boolschen Wert der Fall ist.<br />
* Wenn es sich um keinen bolschen Wert handelt wird der folgende Wert eingelesen mit seiner ganzen Hirarchie.
* <br />
* EBNF:<br />
* <code>"true" | "false" | "yes" | "no" | startElement {("." identifier | "[" structElement "]" )[function] };</code>
* @return CFXD Element
* @throws TemplateException
*/
private Expression dynamic(ExprData data) throws TemplateException {
// Die Implementation weicht ein wenig von der Grammatik ab,
// aber nicht in der Logik sondern rein wie es umgesetzt wurde.
// get First Element of the Variable
Position line = data.srcCode.getPosition();
Identifier id = identifier(data, false, true);
if (id == null) {
if (!data.srcCode.forwardIfCurrent('('))
return null;
comments(data);
Expression expr = assignOp(data);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [)] not found");
comments(data);
// subDynamic(expr);
return expr;
}
Variable var;
comments(data);
// Boolean constant
if (id.getString().equalsIgnoreCase("TRUE")) {
// || name.equals("YES")) {
comments(data);
return id.getFactory().createLitBoolean(true, line, data.srcCode.getPosition());
} else if (id.getString().equalsIgnoreCase("FALSE")) {
// || name.equals("NO")) {
comments(data);
return id.getFactory().createLitBoolean(false, line, data.srcCode.getPosition());
} else if ((data.srcCode.getDialect() != CFMLEngine.DIALECT_CFML || data.config.getFullNullSupport()) && id.getString().equalsIgnoreCase("NULL")) {
comments(data);
return id.getFactory().createNull(line, data.srcCode.getPosition());
}
// Extract Scope from the Variable
var = startElement(data, id, line);
var.setStart(line);
var.setEnd(data.srcCode.getPosition());
return var;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class Function method addAttribute.
public final void addAttribute(Attribute attr) throws TemplateException {
String name = attr.getName().toLowerCase();
// name
if ("name".equals(name)) {
throw new TransformerException("name cannot be defined twice", getStart());
} else if ("returntype".equals(name)) {
this.returnType = toLitString(name, attr.getValue());
} else if ("access".equals(name)) {
LitString ls = toLitString(name, attr.getValue());
String strAccess = ls.getString();
int acc = ComponentUtil.toIntAccess(strAccess, -1);
if (acc == -1)
throw new TransformerException("invalid access type [" + strAccess + "], access types are remote, public, package, private", getStart());
access = acc;
} else if ("output".equals(name))
this.output = toLitBoolean(name, attr.getValue());
else if ("bufferoutput".equals(name))
this.bufferOutput = toLitBoolean(name, attr.getValue());
else if ("displayname".equals(name))
this.displayName = toLitString(name, attr.getValue());
else if ("hint".equals(name))
this.hint = toLitString(name, attr.getValue());
else if ("description".equals(name))
this.description = toLitString(name, attr.getValue());
else if ("returnformat".equals(name))
this.returnFormat = toLitString(name, attr.getValue());
else if ("securejson".equals(name))
this.secureJson = toLitBoolean(name, attr.getValue());
else if ("verifyclient".equals(name))
this.verifyClient = toLitBoolean(name, attr.getValue());
else if ("localmode".equals(name)) {
Expression v = attr.getValue();
if (v != null) {
String str = ASMUtil.toString(v, null);
if (!StringUtil.isEmpty(str)) {
int mode = AppListenerUtil.toLocalMode(str, -1);
if (mode != -1)
this.localMode = v.getFactory().createLitInteger(mode);
else
throw new TransformerException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)", getStart());
}
}
} else if ("cachedwithin".equals(name)) {
try {
// ASMUtil.timeSpanToLong(attr.getValue());
this.cachedWithin = ASMUtil.cachedWithinValue(attr.getValue());
} catch (EvaluatorException e) {
throw new TemplateException(e.getMessage());
}
} else if ("modifier".equals(name)) {
Expression val = attr.getValue();
if (val instanceof Literal) {
Literal l = (Literal) val;
String str = StringUtil.emptyIfNull(l.getString()).trim();
if ("abstract".equalsIgnoreCase(str))
modifier = Component.MODIFIER_ABSTRACT;
else if ("final".equalsIgnoreCase(str))
modifier = Component.MODIFIER_FINAL;
}
} else {
// needed for testing
toLitString(name, attr.getValue());
if (metadata == null)
metadata = new HashMap<String, Attribute>();
metadata.put(attr.getName(), attr);
}
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class CFMLTransformer method createTemplateException.
public static TemplateException createTemplateException(SourceCode cfml, String msg, TagLibTag tag) {
TemplateException te = new TemplateException(cfml, msg);
setAddional(te, tag);
return te;
}
Aggregations