Search in sources :

Example 11 with ParserString

use of lucee.commons.lang.ParserString in project Lucee by lucee.

the class VariableInterpreter method getVariableELAsCollection.

public static Object getVariableELAsCollection(PageContext pc, String var, Object defaultValue) {
    StringList list = parse(pc, new ParserString(var), false);
    if (list == null)
        return defaultValue;
    int scope = scopeString2Int(pc.ignoreScopes(), list.next());
    Object coll = null;
    if (scope == Scope.SCOPE_UNDEFINED) {
        try {
            coll = pc.undefinedScope().getCollection(list.current());
        } catch (PageException e) {
            coll = null;
        }
        if (coll == null)
            return defaultValue;
    } else {
        try {
            coll = VariableInterpreter.scope(pc, scope, list.hasNext());
        // coll=pc.scope(scope);
        } catch (PageException e) {
            return defaultValue;
        }
    }
    while (list.hasNext()) {
        coll = pc.getVariableUtil().getCollection(pc, coll, list.next(), null);
        if (coll == null)
            return defaultValue;
    }
    return coll;
}
Also used : PageException(lucee.runtime.exp.PageException) StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString)

Example 12 with ParserString

use of lucee.commons.lang.ParserString in project Lucee by lucee.

the class VariableInterpreter method getVariableEL.

/**
 * get a variable from page context
 * @param pc Page Context
 * @param var variable string to get value to
 * @param defaultValue value returnded if variable was not found
 * @return the value or default value if not found
 */
public static Object getVariableEL(PageContext pc, String var, Object defaultValue) {
    StringList list = parse(pc, new ParserString(var), false);
    if (list == null)
        return defaultValue;
    int scope = scopeString2Int(pc.ignoreScopes(), list.next());
    Object coll = null;
    if (scope == Scope.SCOPE_UNDEFINED) {
        coll = pc.undefinedScope().get(KeyImpl.init(list.current()), NullSupportHelper.NULL());
        if (coll == NullSupportHelper.NULL())
            return defaultValue;
    } else {
        try {
            coll = VariableInterpreter.scope(pc, scope, list.hasNext());
        // coll=pc.scope(scope);
        } catch (PageException e) {
            return defaultValue;
        }
    }
    while (list.hasNext()) {
        coll = pc.getVariableUtil().get(pc, coll, KeyImpl.init(list.next()), NullSupportHelper.NULL());
        if (coll == NullSupportHelper.NULL())
            return defaultValue;
    }
    return coll;
}
Also used : PageException(lucee.runtime.exp.PageException) StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString)

Example 13 with ParserString

use of lucee.commons.lang.ParserString in project Lucee by lucee.

the class SelectParser method identifier.

private String identifier(ParserString raw, RefBoolean hasBracked) throws SQLParserException {
    if (hasBracked != null && raw.forwardIfCurrent('[')) {
        hasBracked.setValue(true);
        return identifierBracked(raw);
    } else if (!(raw.isCurrentLetter() || raw.isCurrent('*') || raw.isCurrent('?') || raw.isCurrent('_')))
        return null;
    int start = raw.getPos();
    do {
        raw.next();
        if (!(raw.isCurrentLetter() || raw.isCurrentBetween('0', '9') || raw.isCurrent('*') || raw.isCurrent('?') || raw.isCurrent('_'))) {
            break;
        }
    } while (raw.isValidIndex());
    String str = raw.substring(start, raw.getPos() - start);
    raw.removeSpace();
    return str;
}
Also used : ParserString(lucee.commons.lang.ParserString) ValueString(lucee.runtime.sql.exp.value.ValueString)

Example 14 with ParserString

use of lucee.commons.lang.ParserString in project Lucee by lucee.

the class SelectParser method column.

private Expression column(ParserString raw) throws SQLParserException {
    RefBoolean hb = new RefBooleanImpl(false);
    String name = identifier(raw, hb);
    if (name == null)
        return null;
    if (!hb.toBooleanValue()) {
        if ("true".equalsIgnoreCase(name))
            return ValueBoolean.TRUE;
        if ("false".equalsIgnoreCase(name))
            return ValueBoolean.FALSE;
        if ("null".equalsIgnoreCase(name))
            return ValueNull.NULL;
    }
    ColumnExpression column = new ColumnExpression(name, name.equals("?") ? columnIndex++ : 0);
    raw.removeSpace();
    while (raw.forwardIfCurrent(".")) {
        raw.removeSpace();
        String sub = identifier(raw, hb);
        if (sub == null)
            throw new SQLParserException("invalid column definition");
        column.setSub(sub);
    }
    raw.removeSpace();
    if (raw.forwardIfCurrent('(')) {
        return new OperationN(column.getFullName(), readArguments(raw));
    }
    return column;
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) OperationN(lucee.runtime.sql.exp.op.OperationN) ParserString(lucee.commons.lang.ParserString) ValueString(lucee.runtime.sql.exp.value.ValueString) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Example 15 with ParserString

use of lucee.commons.lang.ParserString in project Lucee by lucee.

the class ClientScopeConverter method unserialize.

public static Struct unserialize(String str) {
    Struct sct = new StructImpl();
    ParserString ps = new ParserString(str);
    StringBuilder sb = new StringBuilder();
    String key = null;
    while (!ps.isAfterLast()) {
        if (ps.isCurrent('#')) {
            if (ps.isNext('=')) {
                ps.next();
                sb.append('=');
            } else if (ps.isNext('#')) {
                ps.next();
                sb.append('#');
            } else {
                sct.setEL(key, sb.toString());
                sb = new StringBuilder();
            }
        } else if (ps.isCurrent('=')) {
            key = sb.toString();
            sb = new StringBuilder();
        } else
            sb.append(ps.getCurrent());
        ps.next();
    }
    if (!StringUtil.isEmpty(key) && !StringUtil.isEmpty(sb)) {
        sct.setEL(key, sb.toString());
    }
    return sct;
/*
		int index=0,last=0;
		while((index=str.indexOf('#',last))!=-1) {
			outer:while(str.length()+1>index) {
				c=str.charAt(index+1);
				if(c=='#' || c=='=') {
					last=index+1;
					continue;
				}
			}
			_unserialize(str.substring(last,index));
			last=index+1;
		}
		_unserialize(str.substring(last));
		*/
}
Also used : StructImpl(lucee.runtime.type.StructImpl) ParserString(lucee.commons.lang.ParserString) ParserString(lucee.commons.lang.ParserString) Struct(lucee.runtime.type.Struct)

Aggregations

ParserString (lucee.commons.lang.ParserString)23 StringList (lucee.commons.lang.StringList)10 ValueString (lucee.runtime.sql.exp.value.ValueString)7 PageException (lucee.runtime.exp.PageException)5 RefBoolean (lucee.commons.lang.types.RefBoolean)3 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)3 ColumnExpression (lucee.runtime.sql.exp.ColumnExpression)3 Expression (lucee.runtime.sql.exp.Expression)2 ValueNumber (lucee.runtime.sql.exp.value.ValueNumber)2 DateFormat (lucee.runtime.format.DateFormat)1 TimeFormat (lucee.runtime.format.TimeFormat)1 Ref (lucee.runtime.interpreter.ref.Ref)1 Column (lucee.runtime.sql.exp.Column)1 OperationN (lucee.runtime.sql.exp.op.OperationN)1 Collection (lucee.runtime.type.Collection)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1 DateTime (lucee.runtime.type.dt.DateTime)1 VariableReference (lucee.runtime.type.ref.VariableReference)1 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)1