Search in sources :

Example 81 with PageException

use of lucee.runtime.exp.PageException 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 82 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class JavaObject method get.

public Object get(PageContext pc, String propertyName, Object defaultValue) {
    if (isInit) {
        return variableUtil.get(pc, object, propertyName, defaultValue);
    }
    // Field
    Field[] fields = Reflector.getFieldsIgnoreCase(clazz, propertyName, null);
    if (!ArrayUtil.isEmpty(fields) && Modifier.isStatic(fields[0].getModifiers())) {
        try {
            return fields[0].get(null);
        } catch (Exception e) {
        }
    }
    // Getter
    MethodInstance mi = Reflector.getGetterEL(clazz, propertyName);
    if (mi != null) {
        if (Modifier.isStatic(mi.getMethod().getModifiers())) {
            try {
                return mi.invoke(null);
            } catch (Exception e) {
            }
        }
    }
    try {
        return variableUtil.get(pc, init(), propertyName, defaultValue);
    } catch (PageException e1) {
        return defaultValue;
    }
}
Also used : Field(java.lang.reflect.Field) PageException(lucee.runtime.exp.PageException) MethodInstance(lucee.runtime.reflection.pairs.MethodInstance) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 83 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class ScriptEngineImpl method put.

@Override
public void put(String key, Object value) {
    PageContext oldPC = ThreadLocalPageContext.get();
    PageContext pc = getPageContext(getContext());
    try {
        pc.undefinedScope().set(KeyImpl.init(key), value);
    } catch (PageException e) {
    // ignored
    } finally {
        releasePageContext(pc, oldPC);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext)

Example 84 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class ModernApplicationContext method initJava.

private void initJava() {
    if (!initJavaSettings) {
        Object o = get(component, JAVA_SETTING, null);
        if (o != null && Decision.isStruct(o)) {
            Struct sct = Caster.toStruct(o, null);
            // loadPaths
            Object obj = sct.get(KeyImpl.init("loadPaths"), null);
            List<Resource> paths;
            if (obj != null) {
                paths = loadPaths(ThreadLocalPageContext.get(), obj);
            } else
                paths = new ArrayList<Resource>();
            // loadCFMLClassPath
            Boolean loadCFMLClassPath = Caster.toBoolean(sct.get(KeyImpl.init("loadCFMLClassPath"), null), null);
            if (loadCFMLClassPath == null)
                loadCFMLClassPath = Caster.toBoolean(sct.get(KeyImpl.init("loadColdFusionClassPath"), null), null);
            if (loadCFMLClassPath == null)
                loadCFMLClassPath = javaSettings.loadCFMLClassPath();
            // reloadOnChange
            boolean reloadOnChange = Caster.toBooleanValue(sct.get(KeyImpl.init("reloadOnChange"), null), javaSettings.reloadOnChange());
            // watchInterval
            int watchInterval = Caster.toIntValue(sct.get(KeyImpl.init("watchInterval"), null), javaSettings.watchInterval());
            // watchExtensions
            obj = sct.get(KeyImpl.init("watchExtensions"), null);
            List<String> extensions = new ArrayList<String>();
            if (obj != null) {
                Array arr;
                if (Decision.isArray(obj)) {
                    try {
                        arr = Caster.toArray(obj);
                    } catch (PageException e) {
                        arr = new ArrayImpl();
                    }
                } else {
                    arr = lucee.runtime.type.util.ListUtil.listToArrayRemoveEmpty(Caster.toString(obj, ""), ',');
                }
                Iterator<Object> it = arr.valueIterator();
                String ext;
                while (it.hasNext()) {
                    ext = Caster.toString(it.next(), null);
                    if (StringUtil.isEmpty(ext))
                        continue;
                    ext = ext.trim();
                    if (ext.startsWith("."))
                        ext = ext.substring(1);
                    if (ext.startsWith("*."))
                        ext = ext.substring(2);
                    extensions.add(ext);
                }
            }
            javaSettings = new JavaSettingsImpl(paths.toArray(new Resource[paths.size()]), loadCFMLClassPath, reloadOnChange, watchInterval, extensions.toArray(new String[extensions.size()]));
        }
        initJavaSettings = true;
    }
}
Also used : PageException(lucee.runtime.exp.PageException) ArrayImpl(lucee.runtime.type.ArrayImpl) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) RefBoolean(lucee.commons.lang.types.RefBoolean)

Example 85 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class ObjectLoad method call.

public static Object call(PageContext pc, Object input) throws PageException {
    InputStream is;
    boolean closeStream = true;
    if (Decision.isBinary(input)) {
        is = new ByteArrayInputStream(Caster.toBinary(input));
    } else if (input instanceof InputStream) {
        is = (InputStream) input;
        closeStream = false;
    } else {
        Resource res = ResourceUtil.toResourceExisting(pc, Caster.toString(input));
        pc.getConfig().getSecurityManager().checkFileLocation(res);
        try {
            is = res.getInputStream();
        } catch (IOException e) {
            throw Caster.toPageException(e);
        }
    }
    try {
        return JavaConverter.deserialize(is);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    } finally {
        if (closeStream)
            IOUtil.closeEL(is);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) IOException(java.io.IOException) PageException(lucee.runtime.exp.PageException)

Aggregations

PageException (lucee.runtime.exp.PageException)200 ApplicationException (lucee.runtime.exp.ApplicationException)56 IOException (java.io.IOException)54 Struct (lucee.runtime.type.Struct)49 StructImpl (lucee.runtime.type.StructImpl)37 ExpressionException (lucee.runtime.exp.ExpressionException)32 Resource (lucee.commons.io.res.Resource)30 SecurityException (lucee.runtime.exp.SecurityException)26 BundleException (org.osgi.framework.BundleException)26 MalformedURLException (java.net.MalformedURLException)25 Array (lucee.runtime.type.Array)21 Key (lucee.runtime.type.Collection.Key)17 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)15 SAXException (org.xml.sax.SAXException)15 Entry (java.util.Map.Entry)14 ClassException (lucee.commons.lang.ClassException)14 DeprecatedException (lucee.runtime.exp.DeprecatedException)14 SMTPException (lucee.runtime.net.mail.SMTPException)13 ArrayImpl (lucee.runtime.type.ArrayImpl)13 Query (lucee.runtime.type.Query)13