Search in sources :

Example 16 with StringList

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

the class VariableInterpreter method getVariable.

/**
 * get a variable from page context
 * @param pc Page Context
 * @param var variable string to get value to
 * @return the value
 * @throws PageException
 */
public static Object getVariable(PageContext pc, String var) throws PageException {
    StringList list = parse(pc, new ParserString(var), false);
    if (list == null)
        throw new InterpreterException("invalid variable declaration [" + var + "]");
    int scope = scopeString2Int(pc.ignoreScopes(), list.next());
    Object coll = null;
    if (scope == Scope.SCOPE_UNDEFINED) {
        coll = pc.undefinedScope().get(list.current());
    } else {
        coll = VariableInterpreter.scope(pc, scope, list.hasNext());
    }
    while (list.hasNext()) {
        coll = pc.getVariableUtil().get(pc, coll, list.next());
    }
    return coll;
}
Also used : StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString)

Example 17 with StringList

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

the class VariableInterpreter method getVariableAsCollection.

public static Object getVariableAsCollection(PageContext pc, String var) throws PageException {
    StringList list = parse(pc, new ParserString(var), false);
    if (list == null)
        throw new InterpreterException("invalid variable declaration [" + var + "]");
    int scope = scopeString2Int(pc.ignoreScopes(), list.next());
    Object coll = null;
    if (scope == Scope.SCOPE_UNDEFINED) {
        coll = pc.undefinedScope().getCollection(list.current());
    } else {
        coll = VariableInterpreter.scope(pc, scope, list.hasNext());
    }
    while (list.hasNext()) {
        coll = pc.getVariableUtil().getCollection(pc, coll, list.next());
    }
    return coll;
}
Also used : StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString)

Example 18 with StringList

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

the class VariableInterpreter method removeVariable.

/**
 * removes a variable eith matching name from page context
 * @param pc
 * @param var
 * @return has removed or not
 * @throws PageException
 */
public static Object removeVariable(PageContext pc, String var) throws PageException {
    // print.ln("var:"+var);
    StringList list = parse(pc, new ParserString(var), false);
    if (list == null)
        throw new InterpreterException("invalid variable declaration [" + var + "]");
    if (list.size() == 1) {
        return pc.undefinedScope().remove(KeyImpl.init(list.next()));
    }
    int scope = scopeString2Int(pc.ignoreScopes(), list.next());
    Object coll;
    if (scope == Scope.SCOPE_UNDEFINED) {
        coll = pc.undefinedScope().get(list.current());
    } else {
        coll = VariableInterpreter.scope(pc, scope, true);
    // coll=pc.scope(scope);
    }
    while (list.hasNextNext()) {
        coll = pc.get(coll, list.next());
    }
    return Caster.toCollection(coll).remove(KeyImpl.init(list.next()));
}
Also used : StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString)

Example 19 with StringList

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

the class VariableInterpreter method getVariableReference.

/**
 * return a variable reference by string syntax ("scopename.key.key" -> "url.name")
 * a variable reference, references to variable, to modifed it, with global effect.
 * @param pc
 * @param var variable name to get
 * @return variable as Reference
 * @throws PageException
 */
public static VariableReference getVariableReference(PageContext pc, String var) throws PageException {
    StringList list = parse(pc, new ParserString(var), false);
    if (list == null)
        throw new InterpreterException("invalid variable declaration [" + var + "]");
    if (list.size() == 1) {
        return new VariableReference(pc.undefinedScope(), list.next());
    }
    int scope = scopeString2Int(pc.ignoreScopes(), list.next());
    Object coll;
    if (scope == Scope.SCOPE_UNDEFINED) {
        coll = pc.touch(pc.undefinedScope(), KeyImpl.init(list.current()));
    } else {
        coll = VariableInterpreter.scope(pc, scope, list.hasNext());
    // coll=pc.scope(scope);
    }
    while (list.hasNextNext()) {
        coll = pc.touch(coll, KeyImpl.init(list.next()));
    }
    if (!(coll instanceof Collection))
        throw new InterpreterException("invalid variable [" + var + "]");
    return new VariableReference((Collection) coll, list.next());
}
Also used : VariableReference(lucee.runtime.type.ref.VariableReference) StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString) Collection(lucee.runtime.type.Collection)

Example 20 with StringList

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

the class VariableInterpreter method setVariable.

/**
 * sets a variable to page Context
 * @param pc pagecontext of the new variable
 * @param var String of variable definition
 * @param value value to set to variable
 * @return value setted
 * @throws PageException
 */
public static Object setVariable(PageContext pc, String var, Object value) throws PageException {
    StringList list = parse(pc, new ParserString(var), false);
    if (list == null)
        throw new InterpreterException("invalid variable name declaration [" + var + "]");
    if (list.size() == 1) {
        return pc.undefinedScope().set(list.next(), value);
    }
    // min 2 elements
    int scope = scopeString2Int(pc.ignoreScopes(), list.next());
    Object coll;
    if (scope == Scope.SCOPE_UNDEFINED) {
        coll = pc.touch(pc.undefinedScope(), KeyImpl.init(list.current()));
    } else {
        coll = VariableInterpreter.scope(pc, scope, true);
    // coll=pc.scope(scope);
    }
    while (list.hasNextNext()) {
        coll = pc.touch(coll, KeyImpl.init(list.next()));
    }
    return pc.set(coll, KeyImpl.init(list.next()), value);
}
Also used : StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString)

Aggregations

StringList (lucee.commons.lang.StringList)22 ParserString (lucee.commons.lang.ParserString)10 PageException (lucee.runtime.exp.PageException)4 Collection (lucee.runtime.type.Collection)2 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 CastableStruct (lucee.runtime.type.CastableStruct)1 Struct (lucee.runtime.type.Struct)1 VariableReference (lucee.runtime.type.ref.VariableReference)1 CollectionKey (lucee.transformer.bytecode.expression.type.CollectionKey)1 CollectionKeyArray (lucee.transformer.bytecode.expression.type.CollectionKeyArray)1 Argument (lucee.transformer.bytecode.expression.var.Argument)1 Expression (lucee.transformer.expression.Expression)1 LitString (lucee.transformer.expression.literal.LitString)1 Version (org.osgi.framework.Version)1