use of lucee.runtime.PageSource in project Lucee by lucee.
the class ResourceUtil method toResourceNotExisting.
public static Resource toResourceNotExisting(PageContext pc, String destination, boolean allowRealpath, boolean checkComponentMappings) {
destination = destination.replace('\\', '/');
Resource res = pc.getConfig().getResource(destination);
if (!allowRealpath || res.exists()) {
return res;
}
boolean isUNC;
if (!(isUNC = isUNCPath(destination)) && StringUtil.startsWith(destination, '/')) {
PageContextImpl pci = (PageContextImpl) pc;
ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), destination, false, pci.useSpecialMappings(), SystemUtil.isWindows(), checkComponentMappings);
if (!ArrayUtil.isEmpty(sources)) {
for (int i = 0; i < sources.length; i++) {
res = sources[i].getResource();
if (res != null)
return res;
}
}
// Resource res2 = pc.getPhysical(destination,SystemUtil.isWindows());
// if(res2!=null) return res2;
}
if (isUNC) {
res = pc.getConfig().getResource(destination.replace('/', '\\'));
} else if (!destination.startsWith(".."))
res = pc.getConfig().getResource(destination);
if (res != null && res.isAbsolute())
return res;
return getRealResource(pc, destination, res);
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class ResourceUtil method toResourceExistingParent.
public static Resource toResourceExistingParent(PageContext pc, String destination, boolean allowRealpath) throws ExpressionException {
destination = destination.replace('\\', '/');
Resource res = pc.getConfig().getResource(destination);
// not allow realpath
if (!allowRealpath) {
if (res.exists() || parentExists(res))
return res;
throw new ExpressionException("parent directory " + res.getParent() + " for file " + destination + " doesn't exist");
}
// allow realpath
if (res.isAbsolute() && (res.exists() || parentExists(res))) {
return res;
}
if (StringUtil.startsWith(destination, '/')) {
PageContextImpl pci = (PageContextImpl) pc;
ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), destination, false, pci.useSpecialMappings(), true);
// Resource[] reses = cwi.getPhysicalResourcesX(pc,pc.getApplicationContext().getMappings(),destination,false,pci.useSpecialMappings(),true);
if (!ArrayUtil.isEmpty(sources)) {
for (int i = 0; i < sources.length; i++) {
if (sources[i].exists() || parentExists(sources[i])) {
res = sources[i].getResource();
if (res != null)
return res;
}
}
}
}
res = getRealResource(pc, destination, res);
if (res != null && (res.exists() || parentExists(res)))
return res;
throw new ExpressionException("parent directory " + res.getParent() + " for file " + destination + " doesn't exist");
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class MappingUtil method searchMappingRecursive.
public static PageSource searchMappingRecursive(Mapping mapping, String name, boolean onlyCFC) {
if (name.indexOf('/') == -1) {
// TODO handle this as well?
Config config = mapping.getConfig();
ExtensionResourceFilter ext = null;
if (onlyCFC)
ext = new ExtensionResourceFilter(Constants.getComponentExtensions(), true, true);
else {
ext = new ExtensionResourceFilter(Constants.getExtensions(), true, true);
// ext.addExtension(config.getComponentExtension());
}
if (mapping.isPhysicalFirst()) {
PageSource ps = searchPhysical(mapping, name, ext);
if (ps != null)
return ps;
ps = searchArchive(mapping, name, onlyCFC);
if (ps != null)
return ps;
} else {
PageSource ps = searchArchive(mapping, name, onlyCFC);
if (ps != null)
return ps;
ps = searchPhysical(mapping, name, ext);
if (ps != null)
return ps;
}
}
return null;
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class MappingUtil method searchArchive.
private static PageSource searchArchive(Mapping mapping, String name, boolean onlyCFC) {
Resource archive = mapping.getArchive();
if (archive != null && archive.isFile()) {
ZipInputStream zis = null;
try {
zis = new ZipInputStream(archive.getInputStream());
ZipEntry entry;
Class<?> clazz;
while ((entry = zis.getNextEntry()) != null) {
if (entry.isDirectory() || !entry.getName().endsWith(".class"))
continue;
clazz = mapping.getArchiveClass(toClassName(entry.getName()), null);
if (clazz == null)
continue;
SourceInfo srcInf = ASMUtil.getSourceInfo(mapping.getConfig(), clazz, onlyCFC);
if (name.equalsIgnoreCase(srcInf.name)) {
PageSource ps = mapping.getPageSource(srcInf.relativePath);
return ps;
}
}
} catch (IOException ioe) {
SystemOut.printDate(ioe);
} finally {
IOUtil.closeEL(zis);
}
}
// TODO Auto-generated method stub
return null;
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class HTTPUtil method optimizeRealPath.
/*public static URL toURL(HttpMethod httpMethod) {
HostConfiguration config = httpMethod.getHostConfiguration();
try {
String qs = httpMethod.getQueryString();
if(StringUtil.isEmpty(qs))
return new URL(config.getProtocol().getScheme(),config.getHost(),config.getPort(),httpMethod.getPath());
return new URL(config.getProtocol().getScheme(),config.getHost(),config.getPort(),httpMethod.getPath()+"?"+qs);
} catch (MalformedURLException e) {
return null;
}
}*/
public static String optimizeRealPath(PageContext pc, String realPath) {
int index;
String requestURI = realPath, queryString = null;
if ((index = realPath.indexOf('?')) != -1) {
requestURI = realPath.substring(0, index);
queryString = realPath.substring(index + 1);
}
PageSource ps = PageSourceImpl.best(((PageContextImpl) pc).getRelativePageSources(requestURI));
requestURI = ps.getRealpathWithVirtual();
if (queryString != null)
return requestURI + "?" + queryString;
return requestURI;
}
Aggregations