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;
}
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;
}
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;
}
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");
}
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;
}
Aggregations