Search in sources :

Example 66 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class PageExceptionImpl method getErrorBlock.

@Override
public Struct getErrorBlock(PageContext pc, ErrorPage ep) {
    Struct struct = new StructImpl();
    struct.setEL("browser", pc.cgiScope().get("HTTP_USER_AGENT", ""));
    struct.setEL("datetime", new DateTimeImpl(pc));
    struct.setEL("diagnostics", getMessage() + ' ' + getDetail() + "<br>The error occurred on line " + getLine(pc.getConfig()) + " in file " + getFile(pc.getConfig()) + ".");
    struct.setEL("GeneratedContent", getGeneratedContent(pc));
    struct.setEL("HTTPReferer", pc.cgiScope().get("HTTP_REFERER", ""));
    struct.setEL("mailto", ep.getMailto());
    struct.setEL(KeyConstants._message, getMessage());
    struct.setEL("QueryString", StringUtil.emptyIfNull(pc.getHttpServletRequest().getQueryString()));
    struct.setEL("RemoteAddress", pc.cgiScope().get("REMOTE_ADDR", ""));
    struct.setEL("RootCause", getCatchBlock(pc));
    struct.setEL("StackTrace", getStackTraceAsString());
    struct.setEL(KeyConstants._template, pc.getHttpServletRequest().getServletPath());
    struct.setEL(KeyConstants._Detail, getDetail());
    struct.setEL("ErrorCode", getErrorCode());
    struct.setEL("ExtendedInfo", getExtendedInfo());
    struct.setEL(KeyConstants._type, getTypeAsString());
    struct.setEL("TagContext", getTagContext(pc.getConfig()));
    struct.setEL("additional", additional);
    return struct;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) Struct(lucee.runtime.type.Struct)

Example 67 with StructImpl

use of lucee.runtime.type.StructImpl 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 68 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class CacheGetMetadata method call.

public static Struct call(PageContext pc, String id, String cacheName) throws PageException {
    try {
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        CacheEntry entry = cache.getCacheEntry(CacheUtil.key(id));
        Struct info = new StructImpl();
        info.set(CACHE_HITCOUNT, new Double(cache.hitCount()));
        info.set(CACHE_MISSCOUNT, new Double(cache.missCount()));
        info.set(CACHE_CUSTOM, cache.getCustomInfo());
        info.set(KeyConstants._custom, entry.getCustomInfo());
        info.set(CREATED_TIME, entry.created());
        info.set(KeyConstants._hitcount, new Double(entry.hitCount()));
        info.set(IDLE_TIME, new Double(entry.idleTimeSpan()));
        info.set(LAST_HIT, entry.lastHit());
        info.set(LAST_UPDATED, entry.lastModified());
        info.set(KeyConstants._size, new Double(entry.size()));
        info.set(KeyConstants._timespan, new Double(entry.liveTimeSpan()));
        return info;
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) IOException(java.io.IOException) CacheEntry(lucee.commons.io.cache.CacheEntry) Cache(lucee.commons.io.cache.Cache) Struct(lucee.runtime.type.Struct)

Example 69 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class ComponentImpl method writeExternal.

public void writeExternal(ObjectOutput out) throws IOException {
    ComponentSpecificAccess cw = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, this);
    Struct _this = new StructImpl();
    Struct _var = new StructImpl();
    // this scope (removing all UDFs)
    Object member;
    {
        Iterator<Entry<Key, Object>> it = cw.entryIterator();
        Entry<Key, Object> e;
        while (it.hasNext()) {
            e = it.next();
            member = e.getValue();
            if (member instanceof UDF)
                continue;
            _this.setEL(e.getKey(), member);
        }
    }
    // variables scope (removing all UDFs and key "this")
    {
        ComponentScope scope = getComponentScope();
        Iterator<Entry<Key, Object>> it = scope.entryIterator();
        Entry<Key, Object> e;
        Key k;
        while (it.hasNext()) {
            e = it.next();
            k = e.getKey();
            if (KeyConstants._THIS.equalsIgnoreCase(k))
                continue;
            member = e.getValue();
            if (member instanceof UDF)
                continue;
            _var.setEL(e.getKey(), member);
        }
    }
    out.writeUTF(getAbsName());
    out.writeUTF(ComponentUtil.md5(cw));
    out.writeObject(_this);
    out.writeObject(_var);
}
Also used : StructImpl(lucee.runtime.type.StructImpl) UDF(lucee.runtime.type.UDF) ComponentIterator(lucee.runtime.type.it.ComponentIterator) ComponentEntryIterator(lucee.runtime.type.cfc.ComponentEntryIterator) StringIterator(lucee.runtime.type.it.StringIterator) Iterator(java.util.Iterator) ComponentValueIterator(lucee.runtime.type.cfc.ComponentValueIterator) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey) Struct(lucee.runtime.type.Struct)

Example 70 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class ComponentScopeShadow method duplicate.

@Override
public Collection duplicate(boolean deepCopy) {
    StructImpl sct = new StructImpl();
    StructImpl.copy(this, sct, deepCopy);
    return sct;
// MUST muss deepCopy checken
// return new ComponentScopeShadow(component,shadow);//new ComponentScopeThis(component.cloneComponentImpl());
}
Also used : StructImpl(lucee.runtime.type.StructImpl)

Aggregations

StructImpl (lucee.runtime.type.StructImpl)251 Struct (lucee.runtime.type.Struct)216 PageException (lucee.runtime.exp.PageException)40 Entry (java.util.Map.Entry)34 Key (lucee.runtime.type.Collection.Key)28 Array (lucee.runtime.type.Array)25 ArrayImpl (lucee.runtime.type.ArrayImpl)24 ApplicationException (lucee.runtime.exp.ApplicationException)21 IOException (java.io.IOException)19 Map (java.util.Map)19 Resource (lucee.commons.io.res.Resource)18 Iterator (java.util.Iterator)17 PageContextImpl (lucee.runtime.PageContextImpl)14 QueryImpl (lucee.runtime.type.QueryImpl)13 Collection (lucee.runtime.type.Collection)11 Query (lucee.runtime.type.Query)11 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)11 HashMap (java.util.HashMap)9 PageSource (lucee.runtime.PageSource)8 Element (org.w3c.dom.Element)8