Search in sources :

Example 61 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class ResourceExecutionLog method getTemp.

private static Resource getTemp(PageContext pc) {
    Resource tmp = pc.getConfig().getConfigDir();
    Resource dir = tmp.getRealResource("execution-log");
    if (!dir.exists())
        dir.mkdirs();
    return dir;
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 62 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class PageExceptionImpl method toString.

public static String toString(PageContext pc, StackTraceElement trace) {
    String path = null;
    if (trace.getFileName() == null || trace.getFileName().endsWith(".java"))
        return trace.toString();
    Config config = ThreadLocalPageContext.getConfig(pc);
    if (config != null) {
        Resource res = pc.getConfig().getResource(trace.getFileName());
        if (res.exists())
            path = trace.getFileName();
        // get path from source
        if (path == null) {
            SourceInfo si = MappingUtil.getMatch(pc, trace);
            if (si != null) {
                if (si.absolutePath(pc) != null) {
                    res = pc.getConfig().getResource(si.absolutePath(pc));
                    if (res.exists())
                        path = si.absolutePath(pc);
                }
                if (path == null && si.relativePath != null)
                    path = si.relativePath;
            }
            if (path == null)
                path = trace.getFileName();
        }
    }
    return trace.getClassName() + "." + trace.getMethodName() + (trace.isNativeMethod() ? "(Native Method)" : (path != null && trace.getLineNumber() >= 0 ? "(" + path + ":" + trace.getLineNumber() + ")" : (path != null ? "(" + path + ")" : "(Unknown Source)")));
}
Also used : SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) Config(lucee.runtime.config.Config) Resource(lucee.commons.io.res.Resource)

Example 63 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class PageExceptionImpl method _getTagContext.

private static void _getTagContext(Config config, Array tagContext, StackTraceElement[] traces, LinkedList<PageSource> sources) {
    // StackTraceElement[] traces = getStackTraceElements(t);
    int line = 0;
    String template = "", tlast;
    Struct item;
    StackTraceElement trace = null;
    int index = -1;
    PageSource ps;
    PageContextImpl pc = null;
    if (config instanceof ConfigWeb)
        pc = (PageContextImpl) ThreadLocalPageContext.get();
    for (int i = 0; i < traces.length; i++) {
        trace = traces[i];
        tlast = template;
        template = trace.getFileName();
        if (trace.getLineNumber() <= 0 || template == null || ResourceUtil.getExtension(template, "").equals("java"))
            continue;
        // content
        if (!StringUtil.emptyIfNull(tlast).equals(template))
            index++;
        String[] content = null;
        String dspPath = template;
        try {
            Resource res = config.getResource(template);
            if (!res.exists()) {
                PageSource _ps = pc == null ? null : pc.getPageSource(template);
                res = _ps == null ? null : _ps.getPhyscalFile();
                if (res == null || !res.exists()) {
                    res = config.getResource(_ps.getDisplayPath());
                    if (res != null && res.exists())
                        dspPath = res.getAbsolutePath();
                } else
                    dspPath = res.getAbsolutePath();
            } else
                dspPath = res.getAbsolutePath();
            // class was not build on the local filesystem
            if (!res.exists()) {
                SourceInfo si = pc != null ? MappingUtil.getMatch(pc, trace) : MappingUtil.getMatch(config, trace);
                if (si != null && si.relativePath != null) {
                    dspPath = si.relativePath;
                    res = ResourceUtil.toResourceNotExisting(ThreadLocalPageContext.get(), si.relativePath, true, true);
                    if (!res.exists()) {
                        PageSource _ps = PageSourceImpl.best(config.getPageSources(ThreadLocalPageContext.get(), null, si.relativePath, false, false, true));
                        if (_ps != null && _ps.exists()) {
                            res = _ps.getResource();
                            if (res != null && res.exists())
                                dspPath = res.getAbsolutePath();
                        } else
                            dspPath = res.getAbsolutePath();
                    } else
                        dspPath = res.getAbsolutePath();
                }
            }
            if (res.exists()) {
                InputStream is = res.getInputStream();
                if (ClassUtil.isBytecode(is)) {
                    // empty code array to show ??
                    content = new String[] {};
                } else
                    content = IOUtil.toStringArray(IOUtil.getReader(res, config.getTemplateCharset()));
                IOUtil.closeEL(is);
            } else {
                if (sources.size() > index)
                    ps = sources.get(index);
                else
                    ps = null;
                if (ps != null && trace.getClassName().equals(ps.getClassName())) {
                    if (ps.physcalExists())
                        content = IOUtil.toStringArray(IOUtil.getReader(ps.getPhyscalFile(), config.getTemplateCharset()));
                    template = ps.getDisplayPath();
                }
            }
        } catch (Throwable th) {
        }
        // check last
        if (tagContext.size() > 0) {
            try {
                Struct last = (Struct) tagContext.getE(tagContext.size());
                if (last.get(KeyConstants._Raw_Trace).equals(trace.toString()))
                    continue;
            } catch (Exception e) {
            }
        }
        item = new StructImpl();
        line = trace.getLineNumber();
        item.setEL(KeyConstants._template, dspPath);
        item.setEL(KeyConstants._line, new Double(line));
        item.setEL(KeyConstants._id, "??");
        item.setEL(KeyConstants._Raw_Trace, trace.toString());
        item.setEL(KeyConstants._type, "cfml");
        item.setEL(KeyConstants._column, new Double(0));
        if (content != null) {
            if (content.length > 0) {
                item.setEL(KeyConstants._codePrintHTML, getCodePrint(content, line, true));
                item.setEL(KeyConstants._codePrintPlain, getCodePrint(content, line, false));
            } else {
                item.setEL(KeyConstants._codePrintHTML, "??");
                item.setEL(KeyConstants._codePrintPlain, "??");
            }
        } else {
            item.setEL(KeyConstants._codePrintHTML, "");
            item.setEL(KeyConstants._codePrintPlain, "");
        }
        // FUTURE id
        tagContext.appendEL(item);
    }
}
Also used : SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) InputStream(java.io.InputStream) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource) StructImpl(lucee.runtime.type.StructImpl)

Example 64 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class RHExtension method deployBundles.

public void deployBundles(Config config) throws IOException, BundleException {
    // no we read the content of the zip
    ZipInputStream zis = new ZipInputStream(IOUtil.toBufferedInputStream(extensionFile.getInputStream()));
    ZipEntry entry;
    String path;
    String fileName;
    try {
        while ((entry = zis.getNextEntry()) != null) {
            path = entry.getName();
            fileName = fileName(entry);
            // jars
            if (!entry.isDirectory() && (startsWith(path, type, "jars") || startsWith(path, type, "jar") || startsWith(path, type, "bundles") || startsWith(path, type, "bundle") || startsWith(path, type, "lib") || startsWith(path, type, "libs")) && StringUtil.endsWithIgnoreCase(path, ".jar")) {
                Object obj = XMLConfigAdmin.installBundle(config, zis, fileName, version, false, false);
                // jar is not a bundle, only a regular jar
                if (!(obj instanceof BundleFile)) {
                    Resource tmp = (Resource) obj;
                    Resource tmpJar = tmp.getParentResource().getRealResource(ListUtil.last(path, "\\/"));
                    tmp.moveTo(tmpJar);
                    XMLConfigAdmin.updateJar(config, tmpJar, false);
                }
            }
            zis.closeEntry();
        }
    } finally {
        IOUtil.closeEL(zis);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) Resource(lucee.commons.io.res.Resource) BundleFile(lucee.runtime.osgi.BundleFile)

Example 65 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class RHExtension method toBundleDefinition.

private static BundleDefinition toBundleDefinition(InputStream is, String name, String extensionVersion, boolean closeStream) throws IOException, BundleException, ApplicationException {
    Resource tmp = SystemUtil.getTempDirectory().getRealResource(name);
    try {
        IOUtil.copy(is, tmp, closeStream);
        BundleFile bf = new BundleFile(tmp);
        if (bf.isBundle())
            throw new ApplicationException("Jar [" + name + "] is not a valid OSGi Bundle");
        return new BundleDefinition(bf.getSymbolicName(), bf.getVersion());
    } finally {
        tmp.delete();
    }
}
Also used : BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) ApplicationException(lucee.runtime.exp.ApplicationException) Resource(lucee.commons.io.res.Resource) BundleFile(lucee.runtime.osgi.BundleFile)

Aggregations

Resource (lucee.commons.io.res.Resource)309 IOException (java.io.IOException)100 ApplicationException (lucee.runtime.exp.ApplicationException)54 PageException (lucee.runtime.exp.PageException)40 ArrayList (java.util.ArrayList)31 Struct (lucee.runtime.type.Struct)28 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 ExpressionException (lucee.runtime.exp.ExpressionException)19 StructImpl (lucee.runtime.type.StructImpl)18 MalformedURLException (java.net.MalformedURLException)17 PageContextImpl (lucee.runtime.PageContextImpl)17 PageSource (lucee.runtime.PageSource)16 FileResource (lucee.commons.io.res.type.file.FileResource)15 SecurityException (lucee.runtime.exp.SecurityException)15 BundleException (org.osgi.framework.BundleException)15 ZipEntry (java.util.zip.ZipEntry)13 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)13 Array (lucee.runtime.type.Array)13 File (java.io.File)12