Search in sources :

Example 11 with FunctionException

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

the class FileMove method call.

public static String call(PageContext pc, Object oSrc, Object oDst) throws PageException {
    Resource src = Caster.toResource(pc, oSrc, false);
    if (!src.exists())
        throw new FunctionException(pc, "FileMove", 1, "source", "source file [" + src + "] does not exist");
    FileTag.actionMove(pc, pc.getConfig().getSecurityManager(), src, Caster.toString(oDst), FileUtil.NAMECONFLICT_UNDEFINED, null, null, -1, null);
    return null;
}
Also used : Resource(lucee.commons.io.res.Resource) FunctionException(lucee.runtime.exp.FunctionException)

Example 12 with FunctionException

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

the class FileSkipBytes method call.

public static String call(PageContext pc, Object fileObj, double len) throws PageException {
    if (!(fileObj instanceof FileStreamWrapper))
        throw new FunctionException(pc, "FileSkipBytes", 1, "fileObj", "invalid type [" + Caster.toTypeName(fileObj) + "], only File Object produced by FileOpen supported");
    FileStreamWrapper fs = (FileStreamWrapper) fileObj;
    fs.skip((int) len);
    return null;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException)

Example 13 with FunctionException

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

the class StructFindValue method call.

public static Array call(PageContext pc, Struct struct, String value, String scope) throws PageException {
    // Scope
    boolean all = false;
    if (scope.equalsIgnoreCase("one"))
        all = false;
    else if (scope.equalsIgnoreCase("all"))
        all = true;
    else
        throw new FunctionException(pc, "structFindValue", 3, "scope", "invalid scope definition [" + scope + "], valid scopes are [one, all]");
    Array array = new ArrayImpl();
    getValues(pc, array, struct, value, all, "");
    return array;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException)

Example 14 with FunctionException

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

the class BundleInfo method call.

public static Struct call(PageContext pc, Object obj) throws PageException {
    if (obj == null)
        throw new FunctionException(pc, "bundleInfo", 1, "object", "value is null");
    Class<?> clazz;
    if (obj instanceof JavaObject)
        clazz = ((JavaObject) obj).getClazz();
    else if (obj instanceof ObjectWrap)
        clazz = ((ObjectWrap) obj).getEmbededObject().getClass();
    else
        clazz = obj.getClass();
    ClassLoader cl = clazz.getClassLoader();
    if (cl instanceof BundleClassLoader) {
        BundleClassLoader bcl = (BundleClassLoader) cl;
        Bundle b = bcl.getBundle();
        Struct sct = new StructImpl();
        sct.setEL(KeyConstants._id, b.getBundleId());
        sct.setEL(KeyConstants._name, b.getSymbolicName());
        sct.setEL("location", b.getLocation());
        sct.setEL(KeyConstants._version, b.getVersion().toString());
        sct.setEL(KeyConstants._state, OSGiUtil.toState(b.getState(), null));
        try {
            sct.setEL("requiredBundles", toArray1(OSGiUtil.getRequiredBundles(b)));
            sct.setEL("requiredPackages", toArray2(OSGiUtil.getRequiredPackages(b)));
        } catch (BundleException be) {
            throw Caster.toPageException(be);
        }
        return sct;
    }
    throw new ApplicationException(obj + "given object is not from a OSGi bundle");
}
Also used : ObjectWrap(lucee.runtime.type.ObjectWrap) StructImpl(lucee.runtime.type.StructImpl) ApplicationException(lucee.runtime.exp.ApplicationException) JavaObject(lucee.runtime.java.JavaObject) BundleClassLoader(org.apache.felix.framework.BundleWiringImpl.BundleClassLoader) Bundle(org.osgi.framework.Bundle) FunctionException(lucee.runtime.exp.FunctionException) BundleClassLoader(org.apache.felix.framework.BundleWiringImpl.BundleClassLoader) BundleException(org.osgi.framework.BundleException) Struct(lucee.runtime.type.Struct)

Example 15 with FunctionException

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

the class Compress method call.

public static boolean call(PageContext pc, String strFormat, String strSource, String srcTarget, boolean includeBaseFolder, String strMode) throws PageException {
    int mode;
    try {
        mode = ModeUtil.toOctalMode(strMode);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    strFormat = strFormat.trim().toLowerCase();
    int format = CompressUtil.FORMAT_ZIP;
    if (strFormat.equals("bzip"))
        format = CompressUtil.FORMAT_BZIP;
    else if (strFormat.equals("bzip2"))
        format = CompressUtil.FORMAT_BZIP2;
    else if (strFormat.equals("gzip"))
        format = CompressUtil.FORMAT_GZIP;
    else if (strFormat.equals("tar"))
        format = CompressUtil.FORMAT_TAR;
    else if (strFormat.equals("tbz"))
        format = CompressUtil.FORMAT_TBZ;
    else if (strFormat.startsWith("tar.bz"))
        format = CompressUtil.FORMAT_TBZ;
    else if (strFormat.equals("tbz2"))
        format = CompressUtil.FORMAT_TBZ2;
    else if (strFormat.startsWith("tar.gz"))
        format = CompressUtil.FORMAT_TGZ;
    else if (strFormat.equals("tgz"))
        format = CompressUtil.FORMAT_TGZ;
    else if (strFormat.equals("zip"))
        format = CompressUtil.FORMAT_ZIP;
    else
        throw new FunctionException(pc, "compress", 1, "format", "invalid format definition [" + strFormat + "]," + " valid formats are [bzip,gzip,tar,tbz (tar bzip),tgz (tar gzip) and zip]");
    String[] arrSources = ListUtil.toStringArrayEL(ListUtil.listToArrayRemoveEmpty(strSource, ","));
    Resource[] sources = new Resource[arrSources.length];
    for (int i = 0; i < sources.length; i++) {
        sources[i] = ResourceUtil.toResourceExisting(pc, arrSources[i]);
        (pc.getConfig()).getSecurityManager().checkFileLocation(sources[i]);
    }
    Resource target = ResourceUtil.toResourceExistingParent(pc, srcTarget);
    (pc.getConfig()).getSecurityManager().checkFileLocation(target);
    try {
        if (sources.length == 1)
            CompressUtil.compress(format, sources[0], target, includeBaseFolder, mode);
        else
            CompressUtil.compress(format, sources, target, mode);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    return true;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException)

Aggregations

FunctionException (lucee.runtime.exp.FunctionException)189 BufferedImage (java.awt.image.BufferedImage)123 Image (lucee.runtime.img.Image)17 Struct (lucee.runtime.type.Struct)13 Array (lucee.runtime.type.Array)12 Resource (lucee.commons.io.res.Resource)10 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 Iterator (java.util.Iterator)6 Query (lucee.runtime.type.Query)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 Enumeration (java.util.Enumeration)5 List (java.util.List)5 ListIterator (java.util.ListIterator)5 ExecutorService (java.util.concurrent.ExecutorService)5 Future (java.util.concurrent.Future)5 Iteratorable (lucee.runtime.type.Iteratorable)5 StringListData (lucee.runtime.type.util.StringListData)5 ArrayImpl (lucee.runtime.type.ArrayImpl)4 StructImpl (lucee.runtime.type.StructImpl)4