Search in sources :

Example 1 with RefBoolean

use of lucee.commons.lang.types.RefBoolean 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(','));
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) Column(lucee.runtime.sql.exp.Column) ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) ParserString(lucee.commons.lang.ParserString) ValueString(lucee.runtime.sql.exp.value.ValueString) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Example 2 with RefBoolean

use of lucee.commons.lang.types.RefBoolean 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(','));
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) ParserString(lucee.commons.lang.ParserString) ValueString(lucee.runtime.sql.exp.value.ValueString) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Example 3 with RefBoolean

use of lucee.commons.lang.types.RefBoolean 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);
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) Statement(lucee.transformer.bytecode.Statement) Function(lucee.transformer.bytecode.statement.udf.Function) IFunction(lucee.transformer.bytecode.statement.IFunction) LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Body(lucee.transformer.bytecode.Body) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 4 with RefBoolean

use of lucee.commons.lang.types.RefBoolean 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);
    }
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) RefBoolean(lucee.commons.lang.types.RefBoolean) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) ArrayList(java.util.ArrayList) LitString(lucee.transformer.expression.literal.LitString) Entry(java.util.Map.Entry) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Example 5 with RefBoolean

use of lucee.commons.lang.types.RefBoolean 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);
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) RefBoolean(lucee.commons.lang.types.RefBoolean) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) RefBoolean(lucee.commons.lang.types.RefBoolean) ExprBoolean(lucee.transformer.expression.ExprBoolean) CastBoolean(lucee.transformer.bytecode.cast.CastBoolean) LitBoolean(lucee.transformer.expression.literal.LitBoolean)

Aggregations

RefBoolean (lucee.commons.lang.types.RefBoolean)16 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)16 IOException (java.io.IOException)3 ParserString (lucee.commons.lang.ParserString)3 PageException (lucee.runtime.exp.PageException)3 ColumnExpression (lucee.runtime.sql.exp.ColumnExpression)3 ValueString (lucee.runtime.sql.exp.value.ValueString)3 Entry (java.util.Map.Entry)2 Resource (lucee.commons.io.res.Resource)2 Component (lucee.runtime.Component)2 PageSource (lucee.runtime.PageSource)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)2 TemplateException (lucee.runtime.exp.TemplateException)2 Expression (lucee.runtime.sql.exp.Expression)2 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)2 Expression (lucee.transformer.expression.Expression)2 LitString (lucee.transformer.expression.literal.LitString)2 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)2 Instrumentation (java.lang.instrument.Instrumentation)1