use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.
the class CFMLEngineImpl method getConfigDirectory.
/**
* loads Configuration File from System, from init Parameter from web.xml
*
* @param sg
* @param configServer
* @param countExistingContextes
* @return return path to directory
*/
private Resource getConfigDirectory(ServletConfig sg, ConfigServerImpl configServer, int countExistingContextes, RefBoolean isCustomSetting) throws PageServletException {
isCustomSetting.setValue(true);
ServletContext sc = sg.getServletContext();
String strConfig = sg.getInitParameter("configuration");
if (StringUtil.isEmpty(strConfig))
strConfig = sg.getInitParameter("lucee-web-directory");
if (StringUtil.isEmpty(strConfig))
strConfig = System.getProperty("lucee.web.dir");
if (StringUtil.isEmpty(strConfig)) {
isCustomSetting.setValue(false);
strConfig = "{web-root-directory}/WEB-INF/lucee/";
} else // only for backward compatibility
if (strConfig.startsWith("/WEB-INF/lucee/"))
strConfig = "{web-root-directory}" + strConfig;
strConfig = StringUtil.removeQuotes(strConfig, true);
// static path is not allowed
if (countExistingContextes > 1 && strConfig != null && strConfig.indexOf('{') == -1) {
String text = "static path [" + strConfig + "] for servlet init param [lucee-web-directory] is not allowed, path must use a web-context specific placeholder.";
System.err.println(text);
throw new PageServletException(new ApplicationException(text));
}
strConfig = SystemUtil.parsePlaceHolder(strConfig, sc, configServer.getLabels());
ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
Resource root = frp.getResource(ReqRspUtil.getRootPath(sc));
Resource res;
Resource configDir = ResourceUtil.createResource(res = root.getRealResource(strConfig), FileUtil.LEVEL_PARENT_FILE, FileUtil.TYPE_DIR);
if (configDir == null) {
configDir = ResourceUtil.createResource(res = frp.getResource(strConfig), FileUtil.LEVEL_GRAND_PARENT_FILE, FileUtil.TYPE_DIR);
}
if (configDir == null && !isCustomSetting.toBooleanValue()) {
try {
res.createDirectory(true);
configDir = res;
} catch (IOException e) {
throw new PageServletException(Caster.toPageException(e));
}
}
if (configDir == null) {
throw new PageServletException(new ApplicationException("path [" + strConfig + "] is invalid"));
}
if (!configDir.exists() || ResourceUtil.isEmptyDirectory(configDir, null)) {
Resource railoRoot;
// there is a railo directory
if (configDir.getName().equals("lucee") && (railoRoot = configDir.getParentResource().getRealResource("railo")).isDirectory()) {
try {
copyRecursiveAndRename(railoRoot, configDir);
} catch (IOException e) {
try {
configDir.createDirectory(true);
} catch (IOException ioe) {
}
return configDir;
}
// zip the railo-server di and delete it (optional)
try {
Resource p = railoRoot.getParentResource();
CompressUtil.compress(CompressUtil.FORMAT_ZIP, railoRoot, p.getRealResource("railo-web-context-old.zip"), false, -1);
ResourceUtil.removeEL(railoRoot, true);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
} else {
try {
configDir.createDirectory(true);
} catch (IOException e) {
}
}
}
return configDir;
}
use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.
the class GetVFSMetaData method call.
public static Struct call(PageContext pc, String scheme) {
ResourceProvider[] providers = pc.getConfig().getResourceProviders();
ResourceProvider provider;
scheme = scheme.trim();
Struct sct = new StructImpl();
for (int i = 0; i < providers.length; i++) {
provider = providers[i];
if (provider.getScheme().equalsIgnoreCase(scheme)) {
// MUST sct=provider.getMetaData();
sct.setEL("Scheme", provider.getScheme());
sct.setEL("Attributes", provider.isAttributesSupported());
sct.setEL("CaseSensitive", provider.isCaseSensitive());
sct.setEL("Mode", provider.isModeSupported());
sct.setEL("Enabled", Boolean.TRUE);
return sct;
}
}
sct.setEL("Enabled", Boolean.FALSE);
return sct;
}
use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.
the class MacAddressWrap method getRuningContextRoot.
/**
* @return return running context root
*/
public static Resource getRuningContextRoot() {
ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
try {
return frp.getResource(".").getCanonicalResource();
} catch (IOException e) {
}
URL url = InfoImpl.class.getClassLoader().getResource(".");
try {
return frp.getResource(FileUtil.URLToFile(url).getAbsolutePath());
} catch (MalformedURLException e) {
return null;
}
}
use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.
the class MacAddressWrap method getClassPathesFromClassLoader.
/**
* get class pathes from all url ClassLoaders
*
* @param ucl
* URL Class Loader
* @param pathes
* Hashmap with allpathes
*/
private static void getClassPathesFromClassLoader(URLClassLoader ucl, ArrayList<Resource> pathes) {
ClassLoader pcl = ucl.getParent();
// parent first
if (pcl instanceof URLClassLoader)
getClassPathesFromClassLoader((URLClassLoader) pcl, pathes);
ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
// get all pathes
URL[] urls = ucl.getURLs();
for (int i = 0; i < urls.length; i++) {
Resource file = frp.getResource(urls[i].getPath());
if (file.exists())
pathes.add(ResourceUtil.getCanonicalResourceEL(file));
}
}
use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.
the class MacAddressWrap method getHomeDirectory.
/**
* returns the Hoome Directory of the System
*
* @return home directory
*/
public static Resource getHomeDirectory() {
if (homeFile != null)
return homeFile;
ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
String homeStr = System.getProperty("user.home");
if (homeStr != null) {
homeFile = frp.getResource(homeStr);
homeFile = ResourceUtil.getCanonicalResourceEL(homeFile);
}
return homeFile;
}
Aggregations