Search in sources :

Example 1 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class TagUtil method addTagMetaData.

private static void addTagMetaData(PageContext pc, TagLib tl, TagLibTag tlt, String filename, boolean isWeb) {
    if (pc == null)
        return;
    try {
        ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
        PageSource ps = isWeb ? config.getTagMapping().getPageSource(filename) : config.getServerTagMapping().getPageSource(filename);
        // Page p = ps.loadPage(pc);
        ComponentImpl c = ComponentLoader.loadComponent(pc, ps, filename, true, true);
        ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, c);
        Struct meta = Caster.toStruct(cw.get(KeyConstants._metadata, null), null);
        // TODO handle all metadata here and make checking at runtime useless
        if (meta != null) {
            // parse body
            boolean rtexprvalue = Caster.toBooleanValue(meta.get(KeyConstants._parsebody, Boolean.FALSE), false);
            tlt.setParseBody(rtexprvalue);
            // hint
            String hint = Caster.toString(meta.get(KeyConstants._hint, null), null);
            if (!StringUtil.isEmpty(hint))
                tlt.setDescription(hint);
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) ComponentImpl(lucee.runtime.ComponentImpl) PageSource(lucee.runtime.PageSource) Struct(lucee.runtime.type.Struct)

Example 2 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class CFTagCore method createInitFile.

public static InitFile createInitFile(PageContext pageContext, boolean isweb, String filename) {
    ConfigWebImpl config = (ConfigWebImpl) pageContext.getConfig();
    Mapping mapping = isweb ? config.getTagMapping() : config.getServerTagMapping();
    return new InitFile(pageContext, mapping.getPageSource(filename), filename);
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) InitFile(lucee.runtime.customtag.InitFile) Mapping(lucee.runtime.Mapping)

Example 3 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class ChildThreadImpl method execute.

public PageException execute(Config config) {
    PageContext oldPc = ThreadLocalPageContext.get();
    Page p = page;
    PageContextImpl pc = null;
    try {
        // deamon
        if (this.pc != null) {
            pc = this.pc;
            ThreadLocalPageContext.register(pc);
        } else // task
        {
            ConfigWebImpl cwi;
            try {
                cwi = (ConfigWebImpl) config;
                DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
                pc = ThreadUtil.createPageContext(cwi, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
                pc.setRequestTimeout(requestTimeout);
                p = PageSourceImpl.loadPage(pc, cwi.getPageSources(oldPc == null ? pc : oldPc, null, template, false, false, true));
            // p=cwi.getPageSources(oldPc,null, template, false,false,true).loadPage(cwi);
            } catch (PageException e) {
                return e;
            }
            pc.addPageSource(p.getPageSource(), true);
        }
        threadScope = pc.getThreadScope(KeyConstants._cfthread, null);
        pc.setCurrentThreadScope(new ThreadsImpl(this));
        pc.setThread(Thread.currentThread());
        // String encodings = pc.getHttpServletRequest().getHeader("Accept-Encoding");
        Undefined undefined = pc.us();
        Argument newArgs = new ArgumentThreadImpl((Struct) Duplicator.duplicate(attrs, false));
        LocalImpl newLocal = pc.getScopeFactory().getLocalInstance();
        // Key[] keys = attrs.keys();
        Iterator<Entry<Key, Object>> it = attrs.entryIterator();
        Entry<Key, Object> e;
        while (it.hasNext()) {
            e = it.next();
            newArgs.setEL(e.getKey(), e.getValue());
        }
        newLocal.setEL(KEY_ATTRIBUTES, newArgs);
        Argument oldArgs = pc.argumentsScope();
        Local oldLocal = pc.localScope();
        int oldMode = undefined.setMode(Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
        pc.setFunctionScopes(newLocal, newArgs);
        try {
            p.threadCall(pc, threadIndex);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            if (!Abort.isSilentAbort(t)) {
                ConfigWeb c = pc.getConfig();
                if (c instanceof ConfigImpl) {
                    ConfigImpl ci = (ConfigImpl) c;
                    Log log = ci.getLog("thread");
                    if (log != null)
                        LogUtil.log(log, Log.LEVEL_ERROR, this.getName(), t);
                }
                PageException pe = Caster.toPageException(t);
                if (!serializable)
                    catchBlock = pe.getCatchBlock(pc.getConfig());
                return pe;
            }
        } finally {
            completed = true;
            pc.setFunctionScopes(oldLocal, oldArgs);
            undefined.setMode(oldMode);
            // pc.getScopeFactory().recycle(newArgs);
            pc.getScopeFactory().recycle(pc, newLocal);
            if (pc.getHttpServletResponse() instanceof HttpServletResponseDummy) {
                HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
                pc.flush();
                contentType = rsp.getContentType();
                Pair<String, Object>[] _headers = rsp.getHeaders();
                if (_headers != null)
                    for (int i = 0; i < _headers.length; i++) {
                        if (_headers[i].getName().equalsIgnoreCase("Content-Encoding"))
                            contentEncoding = Caster.toString(_headers[i].getValue(), null);
                    }
            }
        }
    } finally {
        pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
        pc = null;
        if (oldPc != null)
            ThreadLocalPageContext.register(oldPc);
    }
    return null;
}
Also used : Argument(lucee.runtime.type.scope.Argument) Page(lucee.runtime.Page) Entry(java.util.Map.Entry) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) LocalImpl(lucee.runtime.type.scope.LocalImpl) Pair(lucee.commons.lang.Pair) PageException(lucee.runtime.exp.PageException) Undefined(lucee.runtime.type.scope.Undefined) Log(lucee.commons.io.log.Log) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) DevNullOutputStream(lucee.commons.io.DevNullOutputStream) ArgumentThreadImpl(lucee.runtime.type.scope.ArgumentThreadImpl) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HttpServletResponseDummy(lucee.runtime.net.http.HttpServletResponseDummy) Key(lucee.runtime.type.Collection.Key) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 4 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class Admin method doStopThread.

private void doStopThread() throws PageException {
    String contextId = getString("admin", "stopThread", "contextId");
    String threadId = getString("admin", "stopThread", "threadId");
    String stopType = getString("stopType", "exception");
    if (!(config instanceof ConfigServer))
        throw new ApplicationException("invalid context for this action");
    ConfigServer cs = (ConfigServer) config;
    ConfigWeb[] webs = cs.getConfigWebs();
    boolean has = false;
    for (int i = 0; i < webs.length; i++) {
        ConfigWebImpl cw = (ConfigWebImpl) webs[i];
        if (!cw.getIdentification().getId().equals(contextId))
            continue;
        ((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
        has = true;
        break;
    }
    if (!has) {
        for (int i = 0; i < webs.length; i++) {
            ConfigWebImpl cw = (ConfigWebImpl) webs[i];
            if (!contextId.equals(cw.getLabel()))
                continue;
            ((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
            has = true;
            break;
        }
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) ApplicationException(lucee.runtime.exp.ApplicationException) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) ConfigServer(lucee.runtime.config.ConfigServer) ConfigWeb(lucee.runtime.config.ConfigWeb)

Example 5 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class WDDXConverter method _serializeQuery.

/**
 * serialize a Query
 *
 * @param query
 *            Query to serialize
 * @param done
 * @return serialized query
 * @throws ConverterException
 */
private String _serializeQuery(Query query, Set<Object> done) throws ConverterException {
    // fieldnames
    PageContext pc = ThreadLocalPageContext.get();
    boolean upperCase = false;
    if (pc != null)
        upperCase = pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML && !((ConfigWebImpl) pc.getConfig()).preserveCase();
    StringBuilder fn = new StringBuilder();
    Collection.Key[] keys = CollectionUtil.keys(query);
    for (int i = 0; i < keys.length; i++) {
        if (i > 0)
            fn.append(',');
        fn.append(XMLUtil.escapeXMLString(upperCase ? keys[i].getUpperString() : keys[i].getString()));
    }
    StringBuilder sb = new StringBuilder(goIn() + "<recordset rowCount=" + del + query.getRecordcount() + del + " fieldNames=" + del + fn + del + " type=" + del + "coldfusion.sql.QueryTable" + del + ">");
    deep++;
    int len = query.getRecordcount();
    for (int i = 0; i < keys.length; i++) {
        sb.append(goIn() + "<field name=" + del + XMLUtil.escapeXMLString(keys[i].getString()) + del + ">");
        for (int y = 1; y <= len; y++) {
            try {
                sb.append(_serialize(query.getAt(keys[i], y), done));
            } catch (PageException e) {
                sb.append(_serialize(e.getMessage(), done));
            }
        }
        sb.append(goIn() + "</field>");
    }
    deep--;
    sb.append(goIn() + "</recordset>");
    return sb.toString();
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) PageException(lucee.runtime.exp.PageException) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) Key(lucee.runtime.type.Collection.Key)

Aggregations

ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)42 Resource (lucee.commons.io.res.Resource)9 PageContextImpl (lucee.runtime.PageContextImpl)9 Struct (lucee.runtime.type.Struct)9 PageSource (lucee.runtime.PageSource)8 PageException (lucee.runtime.exp.PageException)8 Key (lucee.runtime.type.Collection.Key)8 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)7 Mapping (lucee.runtime.Mapping)7 ConfigServer (lucee.runtime.config.ConfigServer)6 ConfigWeb (lucee.runtime.config.ConfigWeb)5 ApplicationException (lucee.runtime.exp.ApplicationException)5 StructImpl (lucee.runtime.type.StructImpl)5 IOException (java.io.IOException)4 Entry (java.util.Map.Entry)4 ConfigImpl (lucee.runtime.config.ConfigImpl)4 HTTPResource (lucee.commons.io.res.type.http.HTTPResource)3 Page (lucee.runtime.Page)3 PageContext (lucee.runtime.PageContext)3 ExpressionException (lucee.runtime.exp.ExpressionException)3