use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class XMLConfigAdmin method _updateConfigs.
private static void _updateConfigs(Config config, InputStream is, String realpath, boolean closeStream, List<Resource> filesDeployed, boolean store) throws PageException, IOException, SAXException, BundleException {
// MUST get that dynamically
Resource configs = config.getConfigDir();
Resource trg = configs.getRealResource(realpath);
if (trg.exists())
trg.remove(true);
Resource p = trg.getParentResource();
if (!p.isDirectory())
p.createDirectory(true);
IOUtil.copy(is, trg.getOutputStream(false), closeStream, true);
filesDeployed.add(trg);
if (store)
_storeAndReload((ConfigImpl) config);
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class XMLConfigAdmin method _removeWebContexts.
private boolean _removeWebContexts(Config config, String realpath, boolean _store) throws PageException, IOException, SAXException, BundleException {
if (config instanceof ConfigServer) {
ConfigServer cs = ((ConfigServer) config);
// remove files from deploy folder
Resource deploy = cs.getConfigDir().getRealResource("web-context-deployment");
Resource trg = deploy.getRealResource(realpath);
if (trg.exists()) {
trg.remove(true);
ResourceUtil.removeEmptyFolders(deploy, null);
}
// remove files from lucee web context
boolean store = false;
ConfigWeb[] webs = cs.getConfigWebs();
for (int i = 0; i < webs.length; i++) {
if (_removeContext(webs[i], realpath, _store)) {
store = true;
}
}
return store;
}
return false;
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class XMLConfigAdmin method updateArchive.
public void updateArchive(Config config, Resource archive) throws PageException {
Log logger = ((ConfigImpl) config).getLog("deploy");
String type = null, virtual = null, name = null;
boolean readOnly, topLevel, hidden, physicalFirst;
short inspect;
int listMode, listType;
InputStream is = null;
ZipFile file = null;
try {
file = new ZipFile(FileWrapper.toFile(archive));
ZipEntry entry = file.getEntry("META-INF/MANIFEST.MF");
// no manifest
if (entry == null) {
DeployHandler.moveToFailedFolder(config.getDeployDirectory(), archive);
throw new ApplicationException("cannot deploy " + Constants.NAME + " Archive [" + archive + "], file is to old, the file does not have a MANIFEST.");
}
is = file.getInputStream(entry);
Manifest manifest = new Manifest(is);
Attributes attr = manifest.getMainAttributes();
// id = unwrap(attr.getValue("mapping-id"));
type = StringUtil.unwrap(attr.getValue("mapping-type"));
virtual = StringUtil.unwrap(attr.getValue("mapping-virtual-path"));
name = ListUtil.trim(virtual, "/");
readOnly = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-readonly")), false);
topLevel = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-top-level")), false);
listMode = ConfigWebUtil.toListenerMode(StringUtil.unwrap(attr.getValue("mapping-listener-mode")), -1);
listType = ConfigWebUtil.toListenerType(StringUtil.unwrap(attr.getValue("mapping-listener-type")), -1);
inspect = ConfigWebUtil.inspectTemplate(StringUtil.unwrap(attr.getValue("mapping-inspect")), Config.INSPECT_UNDEFINED);
if (inspect == Config.INSPECT_UNDEFINED) {
Boolean trusted = Caster.toBoolean(StringUtil.unwrap(attr.getValue("mapping-trusted")), null);
if (trusted != null) {
if (trusted.booleanValue())
inspect = Config.INSPECT_NEVER;
else
inspect = Config.INSPECT_ALWAYS;
}
}
hidden = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-hidden")), false);
physicalFirst = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-physical-first")), false);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
DeployHandler.moveToFailedFolder(config.getDeployDirectory(), archive);
throw Caster.toPageException(t);
} finally {
IOUtil.closeEL(is);
ZipUtil.close(file);
}
try {
Resource trgDir = config.getConfigDir().getRealResource("archives").getRealResource(type).getRealResource(name);
Resource trgFile = trgDir.getRealResource(archive.getName());
trgDir.mkdirs();
// delete existing files
ResourceUtil.deleteContent(trgDir, null);
ResourceUtil.moveTo(archive, trgFile, true);
logger.log(Log.LEVEL_INFO, "archive", "add " + type + " mapping [" + virtual + "] with archive [" + trgFile.getAbsolutePath() + "]");
if ("regular".equalsIgnoreCase(type))
_updateMapping(virtual, null, trgFile.getAbsolutePath(), "archive", inspect, topLevel, listMode, listType, readOnly);
else if ("cfc".equalsIgnoreCase(type))
_updateComponentMapping(virtual, null, trgFile.getAbsolutePath(), "archive", inspect);
else if ("ct".equalsIgnoreCase(type))
_updateCustomTag(virtual, null, trgFile.getAbsolutePath(), "archive", inspect);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
DeployHandler.moveToFailedFolder(config.getDeployDirectory(), archive);
throw Caster.toPageException(t);
}
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class XMLConfigAdmin method deployFilesFromStream.
private static void deployFilesFromStream(Config config, Resource root, InputStream is, String realpath, boolean closeStream, List<Resource> filesDeployed) throws PageException, IOException, SAXException {
// MUST this makes no sense at this point
if (config instanceof ConfigServer) {
ConfigWeb[] webs = ((ConfigServer) config).getConfigWebs();
if (webs.length == 0)
return;
if (webs.length == 1) {
deployFilesFromStream(webs[0], root, is, realpath, closeStream, filesDeployed);
return;
}
try {
byte[] barr = IOUtil.toBytes(is);
for (int i = 0; i < webs.length; i++) {
deployFilesFromStream(webs[i], root, new ByteArrayInputStream(barr), realpath, true, filesDeployed);
}
} finally {
if (closeStream)
IOUtil.closeEL(is);
}
return;
}
// ConfigWeb
Resource trg = root.getRealResource(realpath);
if (trg.exists())
trg.remove(true);
Resource p = trg.getParentResource();
if (!p.isDirectory())
p.createDirectory(true);
IOUtil.copy(is, trg.getOutputStream(false), closeStream, true);
filesDeployed.add(trg);
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class XMLConfigAdmin method installBundle.
public static Object installBundle(Config config, InputStream is, String name, String extensionVersion, boolean closeStream, boolean convert2bundle) throws IOException, BundleException {
Resource tmp = SystemUtil.getTempDirectory().getRealResource(name);
try {
IOUtil.copy(is, tmp, closeStream);
BundleFile bf = installBundle(config, tmp, extensionVersion, convert2bundle);
if (bf != null)
return bf;
return tmp;
} finally {
tmp.delete();
}
}
Aggregations