Search in sources :

Example 1 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class HtmlBody method actionFlush.

@Override
public void actionFlush() throws IOException {
    PageContextImpl pci = (PageContextImpl) pageContext;
    pci.write(pci.getRootOut().getHTMLBody());
    pci.getRootOut().resetHTMLBody();
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl)

Example 2 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class HtmlHead method actionFlush.

@Override
public void actionFlush() throws IOException {
    PageContextImpl pci = (PageContextImpl) pageContext;
    pci.write(pci.getRootOut().getHTMLHead());
    pci.getRootOut().resetHTMLHead();
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl)

Example 3 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class Lock method doStartTag.

@Override
public int doStartTag() throws PageException {
    if (timeoutInMillis <= 0) {
        TimeSpan remaining = PageContextUtil.remainingTime(pageContext, true);
        this.timeoutInMillis = toInt(remaining.getMillis());
    }
    manager = pageContext.getConfig().getLockManager();
    // check attributes
    if (name != null && scope != SCOPE_NONE) {
        throw new LockException(LockException.OPERATION_CREATE, this.name, "invalid attribute combination", "attribute [name] and [scope] can't be used together");
    }
    if (name == null && scope == SCOPE_NONE) {
        name = "id-" + id;
    }
    String lockType = null;
    if (name == null) {
        String cid = pageContext.getConfig().getIdentification().getId();
        // Session
        if (scope == SCOPE_REQUEST) {
            lockType = "request";
            name = "__request_" + cid + "__" + ((RequestImpl) pageContext.requestScope())._getId();
        } else // Session
        if (scope == SCOPE_SESSION) {
            lockType = "session";
            name = "__session_" + cid + "__" + pageContext.sessionScope()._getId();
        } else // Application
        if (scope == SCOPE_APPLICATION) {
            lockType = "application";
            name = "__application_" + cid + "__" + ((ApplicationImpl) pageContext.applicationScope())._getId();
        } else // Server
        if (scope == SCOPE_SERVER) {
            lockType = "server";
            name = "__server_" + ((ServerImpl) pageContext.serverScope())._getId();
        }
    }
    Struct cflock = new StructImpl();
    cflock.set("succeeded", Boolean.TRUE);
    cflock.set("errortext", "");
    pageContext.setVariable(result, cflock);
    start = System.nanoTime();
    try {
        // this has to be first, otherwise LockTimeoutException has nothing to release
        ((PageContextImpl) pageContext).setActiveLock(new ActiveLock(type, name, timeoutInMillis));
        data = manager.lock(type, name, timeoutInMillis, pageContext.getId());
    } catch (LockTimeoutException e) {
        LockManagerImpl mi = (LockManagerImpl) manager;
        Boolean hasReadLock = mi.isReadLocked(name);
        Boolean hasWriteLock = mi.isWriteLocked(name);
        String msg = LockTimeoutExceptionImpl.createMessage(type, name, lockType, timeoutInMillis, hasReadLock, hasWriteLock);
        _release(pageContext, System.nanoTime() - start);
        name = null;
        cflock.set("succeeded", Boolean.FALSE);
        cflock.set("errortext", msg);
        if (throwontimeout)
            throw new LockException(LockException.OPERATION_TIMEOUT, this.name, msg);
        return SKIP_BODY;
    } catch (InterruptedException e) {
        _release(pageContext, System.nanoTime() - start);
        cflock.set("succeeded", Boolean.FALSE);
        cflock.set("errortext", e.getMessage());
        if (throwontimeout)
            throw Caster.toPageException(e);
        return SKIP_BODY;
    }
    return EVAL_BODY_INCLUDE;
}
Also used : ApplicationImpl(lucee.runtime.type.scope.ApplicationImpl) PageContextImpl(lucee.runtime.PageContextImpl) Struct(lucee.runtime.type.Struct) TimeSpan(lucee.runtime.type.dt.TimeSpan) StructImpl(lucee.runtime.type.StructImpl) ActiveLock(lucee.runtime.debug.ActiveLock) LockException(lucee.runtime.exp.LockException) LockManagerImpl(lucee.runtime.lock.LockManagerImpl) RequestImpl(lucee.runtime.type.scope.RequestImpl) LockTimeoutException(lucee.runtime.lock.LockTimeoutException)

Example 4 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class Log method doStartTag.

@Override
public int doStartTag() throws PageException {
    if (text == null && exception == null)
        throw new ApplicationException("Wrong Context, you must define one of the following attributes [text, exception]");
    PageContextImpl pci = (PageContextImpl) pageContext;
    ConfigImpl config = (ConfigImpl) pageContext.getConfig();
    lucee.commons.io.log.Log logger;
    if (file == null) {
        logger = pci.getLog(log.toLowerCase(), false);
        if (logger == null) {
            // for backward compatiblity
            if ("console".equalsIgnoreCase(log))
                logger = new LogAdapter(Log4jUtil.getConsoleLog(config, false, "cflog", Level.INFO));
            else {
                java.util.Collection<String> set = pci.getLogNames();
                Iterator<String> it = set.iterator();
                lucee.runtime.type.Collection.Key[] keys = new lucee.runtime.type.Collection.Key[set.size()];
                int index = 0;
                while (it.hasNext()) {
                    keys[index++] = KeyImpl.init(it.next());
                }
                throw new ApplicationException(ExceptionUtil.similarKeyMessage(keys, log, "attribute log", "log names", null, true));
            }
        }
    } else {
        logger = getFileLog(pageContext, file, charset, async);
    }
    String contextName = pageContext.getApplicationContext().getName();
    if (contextName == null || !application)
        contextName = "";
    if (exception != null) {
        if (StringUtil.isEmpty(text))
            LogUtil.log(logger, type, contextName, exception);
        else
            LogUtil.log(logger, type, contextName, text, exception);
    } else if (!StringUtil.isEmpty(text))
        logger.log(type, contextName, text);
    else
        throw new ApplicationException("you must define attribute text or attribute exception with the tag cflog");
    // logger.write(toStringType(type),contextName,text);
    return SKIP_BODY;
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl) ApplicationException(lucee.runtime.exp.ApplicationException) LogAdapter(lucee.commons.io.log.log4j.LogAdapter) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 5 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class Module method initFile.

@Override
public void initFile() throws MissingIncludeException, ExpressionException {
    ConfigWeb config = pageContext.getConfig();
    // MUSTMUST cache like ct
    // String[] filenames=getFileNames(config,getAppendix());// = appendix+'.'+config.getCFMLExtension();
    Object objTemplate = attributesScope.get(KeyConstants._template, null);
    Object objName = attributesScope.get(KeyConstants._name, null);
    source = null;
    if (objTemplate != null) {
        attributesScope.removeEL(KeyConstants._template);
        String template = objTemplate.toString();
        if (StringUtil.startsWith(template, '/')) {
            PageSource[] sources = ((PageContextImpl) pageContext).getPageSources(template);
            PageSource ps = MappingImpl.isOK(sources);
            if (ps == null)
                throw new MissingIncludeException(sources[0], "could not find template [" + template + "], file [" + sources[0].getDisplayPath() + "] doesn't exist");
            source = new InitFile(pageContext, ps, template);
        } else {
            source = new InitFile(pageContext, pageContext.getCurrentPageSource().getRealPage(template), template);
            if (!MappingImpl.isOK(source.getPageSource())) {
                throw new MissingIncludeException(source.getPageSource(), "could not find template [" + template + "], file [" + source.getPageSource().getDisplayPath() + "] doesn't exist");
            }
        }
        // attributesScope.removeEL(TEMPLATE);
        setAppendix(source.getPageSource());
    } else if (objName != null) {
        attributesScope.removeEL(KeyConstants._name);
        String[] filenames = toRealPath(config, objName.toString());
        boolean exist = false;
        // appcontext mappings
        Mapping[] ctms = pageContext.getApplicationContext().getCustomTagMappings();
        if (ctms != null) {
            outer: for (int f = 0; f < filenames.length; f++) {
                for (int i = 0; i < ctms.length; i++) {
                    source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
                    if (MappingImpl.isOK(source.getPageSource())) {
                        exist = true;
                        break outer;
                    }
                }
            }
        }
        // config mappings
        if (!exist) {
            ctms = config.getCustomTagMappings();
            outer: for (int f = 0; f < filenames.length; f++) {
                for (int i = 0; i < ctms.length; i++) {
                    // TODO optimieren siehe CFTag
                    source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
                    if (MappingImpl.isOK(source.getPageSource())) {
                        exist = true;
                        break outer;
                    }
                }
            }
        }
        if (!exist)
            throw new ExpressionException("custom tag (" + CustomTagUtil.getDisplayName(config, objName.toString()) + ") is not defined in custom tag directory [" + (ctms.length == 0 ? "no custom tag directory defined" : CustomTagUtil.toString(ctms)) + "]");
        setAppendix(source.getPageSource());
    } else {
        throw new ExpressionException("you must define attribute template or name for tag module");
    }
}
Also used : MissingIncludeException(lucee.runtime.exp.MissingIncludeException) InitFile(lucee.runtime.customtag.InitFile) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Aggregations

PageContextImpl (lucee.runtime.PageContextImpl)84 PageSource (lucee.runtime.PageSource)19 Resource (lucee.commons.io.res.Resource)17 Key (lucee.runtime.type.Collection.Key)15 Struct (lucee.runtime.type.Struct)15 StructImpl (lucee.runtime.type.StructImpl)14 IOException (java.io.IOException)12 ApplicationException (lucee.runtime.exp.ApplicationException)10 PageException (lucee.runtime.exp.PageException)10 Component (lucee.runtime.Component)9 ConfigWeb (lucee.runtime.config.ConfigWeb)9 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)9 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ArrayList (java.util.ArrayList)6 Mapping (lucee.runtime.Mapping)6 PageContext (lucee.runtime.PageContext)6 ConfigImpl (lucee.runtime.config.ConfigImpl)6 ExpressionException (lucee.runtime.exp.ExpressionException)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5