use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.
the class XMLUtilImpl method writeTo.
@Override
public void writeTo(Node node, Resource file) throws PageException {
OutputStream os = null;
CFMLEngine e = CFMLEngineFactory.getInstance();
IO io = e.getIOUtil();
try {
os = io.toBufferedOutputStream(file.getOutputStream());
writeTo(node, new StreamResult(os), false, false, null, null, null);
} catch (IOException ioe) {
throw e.getCastUtil().toPageException(ioe);
} finally {
e.getIOUtil().closeSilent(os);
}
}
use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.
the class XMLUtilImpl method toInputSource.
@Override
public InputSource toInputSource(Object value) throws IOException, PageException {
if (value instanceof InputSource) {
return (InputSource) value;
}
if (value instanceof String) {
return toInputSource(CFMLEngineFactory.getInstance().getThreadPageContext(), (String) value, true);
}
if (value instanceof StringBuffer) {
return toInputSource(CFMLEngineFactory.getInstance().getThreadPageContext(), value.toString(), true);
}
if (value instanceof Resource) {
IO io = CFMLEngineFactory.getInstance().getIOUtil();
String str = io.toString(((Resource) value), (Charset) null);
return new InputSource(new StringReader(str));
}
if (value instanceof File) {
CFMLEngine e = CFMLEngineFactory.getInstance();
String str = e.getIOUtil().toString(e.getCastUtil().toResource(value), (Charset) null);
return new InputSource(new StringReader(str));
}
if (value instanceof InputStream) {
InputStream is = (InputStream) value;
IO io = CFMLEngineFactory.getInstance().getIOUtil();
try {
String str = io.toString(is, (Charset) null);
return new InputSource(new StringReader(str));
} finally {
io.closeSilent(is);
}
}
if (value instanceof Reader) {
Reader reader = (Reader) value;
IO io = CFMLEngineFactory.getInstance().getIOUtil();
try {
String str = io.toString(reader);
return new InputSource(new StringReader(str));
} finally {
io.closeSilent(reader);
}
}
if (value instanceof byte[]) {
return new InputSource(new ByteArrayInputStream((byte[]) value));
}
throw CFMLEngineFactory.getInstance().getExceptionUtil().createExpressionException("cat cast object of type [" + value + "] to a Input for xml parser");
}
use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.
the class OSGiUtil method getBundleDefinitions.
public static List<BundleDefinition> getBundleDefinitions(BundleContext bc) {
Set<String> set = new HashSet<>();
List<BundleDefinition> list = new ArrayList<>();
Bundle[] bundles = bc.getBundles();
for (Bundle b : bundles) {
list.add(new BundleDefinition(b));
set.add(b.getSymbolicName() + ":" + b.getVersion());
}
// is it in jar directory but not loaded
CFMLEngine engine = ConfigWebUtil.getEngine(ThreadLocalPageContext.getConfig());
CFMLEngineFactory factory = engine.getCFMLEngineFactory();
try {
File[] children = factory.getBundleDirectory().listFiles(JAR_EXT_FILTER);
BundleFile bf;
for (int i = 0; i < children.length; i++) {
try {
bf = new BundleFile(children[i]);
if (bf.isBundle() && !set.contains(bf.getSymbolicName() + ":" + bf.getVersion()))
list.add(new BundleDefinition(bf.getSymbolicName(), bf.getVersion()));
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
} catch (IOException ioe) {
}
return list;
}
use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.
the class OSGiUtil method removeLocalBundle.
/**
* get local bundle, but does not download from update provider!
* @param name
* @param version
* @return
* @throws BundleException
*/
public static void removeLocalBundle(String name, Version version, boolean removePhysical, boolean doubleTap) throws BundleException {
name = name.trim();
CFMLEngine engine = CFMLEngineFactory.getInstance();
CFMLEngineFactory factory = engine.getCFMLEngineFactory();
BundleFile bf = _getBundleFile(factory, name, version, null);
if (bf != null) {
BundleDefinition bd = bf.toBundleDefinition();
if (bd != null) {
Bundle b = bd.getLocalBundle();
if (b != null) {
stopIfNecessary(b);
b.uninstall();
}
}
}
if (!removePhysical)
return;
// remove file
if (bf != null) {
if (!bf.getFile().delete() && doubleTap)
bf.getFile().deleteOnExit();
}
}
use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.
the class OSGiUtil method getBundleFile.
public static BundleFile getBundleFile(String name, Version version, Identification id, boolean downloadIfNecessary, BundleFile defaultValue) {
name = name.trim();
CFMLEngine engine = CFMLEngineFactory.getInstance();
CFMLEngineFactory factory = engine.getCFMLEngineFactory();
StringBuilder versionsFound = new StringBuilder();
// is it in jar directory but not loaded
BundleFile bf = _getBundleFile(factory, name, version, versionsFound);
if (bf != null)
return bf;
// if not found try to download
if (downloadIfNecessary && version != null) {
try {
bf = new BundleFile(factory.downloadBundle(name, version.toString(), id));
if (bf.isBundle())
return bf;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
return defaultValue;
}
Aggregations