Search in sources :

Example 11 with CFMLEngine

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);
    }
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) OutputStream(java.io.OutputStream) CFMLEngine(lucee.loader.engine.CFMLEngine) IOException(java.io.IOException)

Example 12 with CFMLEngine

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");
}
Also used : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Resource(lucee.commons.io.res.Resource) StringReader(java.io.StringReader) Reader(java.io.Reader) XMLReader(org.xml.sax.XMLReader) StringReader(java.io.StringReader) CFMLEngine(lucee.loader.engine.CFMLEngine) File(java.io.File)

Example 13 with CFMLEngine

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;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CFMLEngine(lucee.loader.engine.CFMLEngine) File(java.io.File) HashSet(java.util.HashSet) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Example 14 with CFMLEngine

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();
    }
}
Also used : Bundle(org.osgi.framework.Bundle) CFMLEngine(lucee.loader.engine.CFMLEngine) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Example 15 with CFMLEngine

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;
}
Also used : CFMLEngine(lucee.loader.engine.CFMLEngine) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Aggregations

CFMLEngine (lucee.loader.engine.CFMLEngine)31 File (java.io.File)10 IOException (java.io.IOException)9 CFMLEngineFactory (lucee.loader.engine.CFMLEngineFactory)9 Bundle (org.osgi.framework.Bundle)9 Resource (lucee.commons.io.res.Resource)6 BundleFile (lucee.runtime.osgi.BundleFile)5 BundleException (org.osgi.framework.BundleException)5 ServletException (javax.servlet.ServletException)4 BundleContext (org.osgi.framework.BundleContext)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Reader (java.io.Reader)3 BundleCollection (lucee.loader.osgi.BundleCollection)3 PageContext (lucee.runtime.PageContext)3 Struct (lucee.runtime.type.Struct)3 OutputStream (java.io.OutputStream)2 StringReader (java.io.StringReader)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2