use of lucee.commons.io.res.Resource 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.commons.io.res.Resource in project Lucee by lucee.
the class FileRead method call.
public static Object call(PageContext pc, Object obj, Object charsetOrSize) throws PageException {
if (charsetOrSize == null)
return call(pc, obj);
if (obj instanceof FileStreamWrapper) {
return _call((FileStreamWrapper) obj, Caster.toIntValue(charsetOrSize));
}
Resource res = Caster.toResource(pc, obj, true);
String charset = Caster.toString(charsetOrSize);
if (Decision.isInteger(charset)) {
charset = ((PageContextImpl) pc).getResourceCharset().name();
return _call(pc, res, charset, Caster.toIntValue(charset));
}
return _call(pc, res, charset);
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class FileReadBinary method call.
public static Object call(PageContext pc, Object oSrc) throws PageException {
Resource src = Caster.toResource(pc, oSrc, false);
pc.getConfig().getSecurityManager().checkFileLocation(src);
try {
return IOUtil.toBytes(src);
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class FileSetLastModified method call.
public static String call(PageContext pc, Object oSrc, DateTime date) throws PageException {
Resource src = Caster.toResource(pc, oSrc, false);
pc.getConfig().getSecurityManager().checkFileLocation(src);
if (!src.exists() || !src.isFile())
throw Caster.toPageException(new FileNotFoundException(src.getAbsolutePath()));
src.setLastModified(date.getTime());
return null;
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class ConfigImpl method toPageSource.
public PageSource toPageSource(Mapping[] mappings, Resource res, PageSource defaultValue) {
Mapping mapping;
String path;
// app mappings
if (mappings != null) {
for (int i = 0; i < mappings.length; i++) {
mapping = mappings[i];
// Physical
if (mapping.hasPhysical()) {
path = ResourceUtil.getPathToChild(res, mapping.getPhysical());
if (path != null) {
return mapping.getPageSource(path);
}
}
// Archive
if (mapping.hasArchive() && res.getResourceProvider() instanceof CompressResourceProvider) {
Resource archive = mapping.getArchive();
CompressResource cr = ((CompressResource) res);
if (archive.equals(cr.getCompressResource())) {
return mapping.getPageSource(cr.getCompressPath());
}
}
}
}
// config mappings
for (int i = 0; i < this.mappings.length; i++) {
mapping = this.mappings[i];
// Physical
if (mapping.hasPhysical()) {
path = ResourceUtil.getPathToChild(res, mapping.getPhysical());
if (path != null) {
return mapping.getPageSource(path);
}
}
// Archive
if (mapping.hasArchive() && res.getResourceProvider() instanceof CompressResourceProvider) {
Resource archive = mapping.getArchive();
CompressResource cr = ((CompressResource) res);
if (archive.equals(cr.getCompressResource())) {
return mapping.getPageSource(cr.getCompressPath());
}
}
}
// map resource to root mapping when same filesystem
Mapping rootMapping = this.mappings[this.mappings.length - 1];
Resource root;
if (rootMapping.hasPhysical() && res.getResourceProvider().getScheme().equals((root = rootMapping.getPhysical()).getResourceProvider().getScheme())) {
String realpath = "";
while (root != null && !ResourceUtil.isChildOf(res, root)) {
root = root.getParentResource();
realpath += "../";
}
String p2c = ResourceUtil.getPathToChild(res, root);
if (StringUtil.startsWith(p2c, '/') || StringUtil.startsWith(p2c, '\\'))
p2c = p2c.substring(1);
realpath += p2c;
return rootMapping.getPageSource(realpath);
}
// MUST better impl than this
if (this instanceof ConfigWebImpl) {
Resource parent = res.getParentResource();
if (parent != null && !parent.equals(res)) {
Mapping m = ((ConfigWebImpl) this).getApplicationMapping("application", "/", parent.getAbsolutePath(), null, true, false);
return m.getPageSource(res.getName());
}
}
// MUST check archive
return defaultValue;
}
Aggregations