use of lucee.commons.lang.types.RefBooleanImpl in project Lucee by lucee.
the class SelectParser method tableList.
private void tableList(ParserString raw, Select select) throws SQLParserException {
Column column = null;
Expression exp = null;
do {
raw.removeSpace();
exp = column(raw);
if (!(exp instanceof Column))
throw new SQLParserException("invalid table definition");
column = (Column) exp;
raw.removeSpace();
if (raw.forwardIfCurrent("as ")) {
String alias = identifier(raw, new RefBooleanImpl(false));
if (alias == null)
throw new SQLParserException("missing alias in select part");
column.setAlias(alias);
} else {
int start = raw.getPos();
RefBoolean hasBracked = new RefBooleanImpl(false);
// TODO having usw
String alias = identifier(raw, hasBracked);
if (!hasBracked.toBooleanValue()) {
if ("where".equalsIgnoreCase(alias))
raw.setPos(start);
else if ("group".equalsIgnoreCase(alias))
raw.setPos(start);
else if ("having".equalsIgnoreCase(alias))
raw.setPos(start);
else if ("union".equalsIgnoreCase(alias))
raw.setPos(start);
else if ("order".equalsIgnoreCase(alias))
raw.setPos(start);
else if ("limit".equalsIgnoreCase(alias))
raw.setPos(start);
else if (alias != null)
column.setAlias(alias);
} else {
if (alias != null)
column.setAlias(alias);
}
}
select.addFromExpression(column);
raw.removeSpace();
} while (raw.forwardIfCurrent(','));
}
use of lucee.commons.lang.types.RefBooleanImpl in project Lucee by lucee.
the class SelectParser method selectExpressions.
// { (selectStatement) [AS] label | tableName [AS] label}
private void selectExpressions(ParserString raw, Select select) throws SQLParserException {
Expression exp = null;
do {
raw.removeSpace();
exp = expression(raw);
if (exp == null)
throw new SQLParserException("missing expression in select part of query");
raw.removeSpace();
if (raw.forwardIfCurrent("as ")) {
String alias = identifier(raw, new RefBooleanImpl(false));
if (alias == null)
throw new SQLParserException("missing alias in select part");
exp.setAlias(alias);
} else {
int start = raw.getPos();
RefBoolean hb = new RefBooleanImpl(false);
String alias = identifier(raw, hb);
if (!hb.toBooleanValue() && "from".equalsIgnoreCase(alias))
raw.setPos(start);
else if (alias != null)
exp.setAlias(alias);
}
select.addSelectExpression(exp);
raw.removeSpace();
} while (raw.forwardIfCurrent(','));
}
use of lucee.commons.lang.types.RefBooleanImpl in project Lucee by lucee.
the class TagFunction method _writeOut.
public void _writeOut(BytecodeContext bc, int type) throws TransformerException {
// private static final Expression EMPTY = LitString.toExprString("");
Body functionBody = new BodyBase(bc.getFactory());
RefBoolean isStatic = new RefBooleanImpl();
Function func = createFunction(bc.getPage(), functionBody, isStatic, bc.getOutput());
// ScriptBody sb=new ScriptBody(bc.getFactory());
func.setParent(getParent());
List<Statement> statements = getBody().getStatements();
Statement stat;
Tag tag;
// suppress WS between cffunction and the last cfargument
Tag last = null;
if (bc.getSupressWSbeforeArg()) {
// check if there is a cfargument at all
Iterator<Statement> it = statements.iterator();
while (it.hasNext()) {
stat = it.next();
if (stat instanceof Tag) {
tag = (Tag) stat;
if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Argument")) {
last = tag;
}
}
}
// check if there are only literal WS printouts
if (last != null) {
it = statements.iterator();
while (it.hasNext()) {
stat = it.next();
if (stat == last)
break;
if (stat instanceof PrintOut) {
PrintOut po = (PrintOut) stat;
Expression expr = po.getExpr();
if (!(expr instanceof LitString) || !StringUtil.isWhiteSpace(((LitString) expr).getString())) {
last = null;
break;
}
}
}
}
}
Iterator<Statement> it = statements.iterator();
boolean beforeLastArgument = last != null;
while (it.hasNext()) {
stat = it.next();
if (beforeLastArgument) {
if (stat == last) {
beforeLastArgument = false;
} else if (stat instanceof PrintOut) {
PrintOut po = (PrintOut) stat;
Expression expr = po.getExpr();
if (expr instanceof LitString) {
LitString ls = (LitString) expr;
if (StringUtil.isWhiteSpace(ls.getString()))
continue;
}
}
}
if (stat instanceof Tag) {
tag = (Tag) stat;
if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Argument")) {
addArgument(func, tag);
continue;
}
}
functionBody.addStatement(stat);
}
func._writeOut(bc, type);
}
use of lucee.commons.lang.types.RefBooleanImpl in project Lucee by lucee.
the class CFMLTransformer method attributes.
/**
* Liest die Attribute eines Tags ein, dies Abhaengig von der Definition innerhalb der Tag-Lib.
* Hierbei unterscheiden wir vier verschiedene Arten von Attributen:<br>
* <ul>
* <li>FIX: Definierte Attribute Fix, fuer jedes Attribut ist definiert ob es required ist oder nicht (gleich wie JSP). </li>
* <li>DYNAMIC: Die Attribute des Tag sind frei, keine Namen sind vorgegeben.
* Es kann aber definiert sein wieviele Attribute maximal und minimal verwendetet werden duerfen.</li>
* <li>FULLDYNAMIC: Gleich wie DYNAMIC, jedoch kann der Name des Attribut auch ein dynamischer Wert sein (wie bei cfset).</li>
* <li>NONAME: Ein Tag welches nur ein Attribut besitzt ohne Name, sondern einfach nur mit einem Attribut Wert</li>
* </ul>
* <br />
* EBNF:<br />
* <code>({spaces attribute} "/>" | {spaces attribute} ">") | attribute-value;(* Welcher Teil der "oder" Bedingung ausgefuehrt wird, ist abhaengig von der Tag Attribute Definition in der Tag Lib. *)</code>
* @param tag
* @param parent
* @throws TemplateException
*/
public static void attributes(TagData data, TagLibTag tag, Tag parent) throws TemplateException {
int type = tag.getAttributeType();
int start = data.srcCode.getPos();
// Tag with attribute names
if (type != TagLibTag.ATTRIBUTE_TYPE_NONAME) {
try {
int min = tag.getMin();
int max = tag.getMax();
int count = 0;
ArrayList<String> args = new ArrayList<String>();
RefBoolean allowDefaultValue = new RefBooleanImpl(tag.getDefaultAttribute() != null);
while (data.srcCode.isValidIndex()) {
data.srcCode.removeSpace();
// if no more attributes break
if (data.srcCode.isCurrent('/') || data.srcCode.isCurrent('>'))
break;
parent.addAttribute(attribute(data, tag, args, allowDefaultValue));
count++;
}
// set default values
if (tag.hasDefaultValue()) {
Map<String, TagLibTagAttr> hash = tag.getAttributes();
Iterator<Entry<String, TagLibTagAttr>> it = hash.entrySet().iterator();
Entry<String, TagLibTagAttr> e;
TagLibTagAttr att;
while (it.hasNext()) {
e = it.next();
att = e.getValue();
if (!parent.containsAttribute(att.getName()) && att.hasDefaultValue()) {
Attribute attr = new Attribute(tag.getAttributeType() == TagLibTag.ATTRIBUTE_TYPE_DYNAMIC, att.getName(), CastOther.toExpression(data.factory.createLitString(Caster.toString(att.getDefaultValue(), null)), att.getType()), att.getType());
attr.setDefaultAttribute(true);
parent.addAttribute(attr);
}
}
}
boolean hasAttributeCollection = args.contains("attributecollection");
// to less attributes
if (!hasAttributeCollection && min > count)
throw createTemplateException(data.srcCode, "the tag " + tag.getFullName() + " must have at least " + min + " attributes", tag);
// too much attributes
if (!hasAttributeCollection && max > 0 && max < count)
throw createTemplateException(data.srcCode, "the tag " + tag.getFullName() + " can have a maximum of " + max + " attributes", tag);
// not defined attributes
if (type == TagLibTag.ATTRIBUTE_TYPE_FIXED || type == TagLibTag.ATTRIBUTE_TYPE_MIXED) {
// Map<String, TagLibTagAttr> hash = tag.getAttributes();
Iterator<TagLibTagAttr> it = tag.getAttributes().values().iterator();
while (it.hasNext()) {
TagLibTagAttr att = it.next();
if (att.isRequired() && !contains(args, att) && att.getDefaultValue() == null) {
if (!hasAttributeCollection)
throw createTemplateException(data.srcCode, "attribute " + att.getName() + " is required for tag " + tag.getFullName(), tag);
parent.addMissingAttribute(att);
}
}
}
} catch (TemplateException te) {
data.srcCode.setPos(start);
// if the tag supports a non name attribute try this
TagLibTagAttr sa = tag.getSingleAttr();
if (sa != null)
attrNoName(parent, tag, data, sa);
else
throw te;
}
} else // tag without attributes name
{
attrNoName(parent, tag, data, null);
}
}
use of lucee.commons.lang.types.RefBooleanImpl 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);
}
Aggregations