Search in sources :

Example 1 with Abort

use of lucee.runtime.exp.Abort in project Lucee by lucee.

the class Location method doStartTag.

@Override
public int doStartTag() throws PageException {
    try {
        pageContext.getOut().clear();
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    HttpServletResponse rsp = pageContext.getHttpServletResponse();
    url = HTTPUtil.encode(url);
    // add token
    if (addtoken && needId()) {
        String[] arr = url.split("\\?");
        // only string_name
        if (arr.length == 1) {
            url += "?" + pageContext.getURLToken();
        } else // script_name and query_string
        if (arr.length > 1) {
            url = arr[0] + "?" + pageContext.getURLToken();
            for (int i = 1; i < arr.length; i++) url += "&" + arr[i];
        }
        url = ReqRspUtil.encodeRedirectURLEL(rsp, url);
    }
    // IE unter IIS6, Win2K3 und Resin
    rsp.setHeader("Connection", "close");
    rsp.setStatus(statuscode);
    rsp.setHeader("location", url);
    try {
        pageContext.forceWrite("<html>\n<head>\n\t<title>Document Moved</title>\n");
        // pageContext.forceWrite("\t<script>window.location='"+JSStringFormat.invoke(url)+"';</script>\n");
        pageContext.forceWrite("</head>\n<body>\n\t<h1>Object Moved</h1>\n\t		 <a HREF=\"" + url + "\">here</a>\n");
        pageContext.forceWrite("</body>\n</html>");
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    if (pageContext.getConfig().debug())
        pageContext.getDebugger().setOutput(false);
    throw new Abort(Abort.SCOPE_REQUEST);
}
Also used : Abort(lucee.runtime.exp.Abort) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException)

Example 2 with Abort

use of lucee.runtime.exp.Abort in project Lucee by lucee.

the class Trace method _doEndTag.

public void _doEndTag() throws IOException, PageException {
    PageSource ps = pageContext.getCurrentTemplatePageSource();
    // var
    String varValue = null;
    Object value = null, traceValue = null;
    if (!StringUtil.isEmpty(var)) {
        try {
            if (caller instanceof Scope)
                value = VariableInterpreter.getVariable(pageContext, var, (Scope) caller);
            else
                value = pageContext.getVariable(var);
        } catch (PageException e) {
            varValue = "(undefined)";
            follow = false;
        }
        if (follow) {
            // print.o(1);
            if (StringUtil.isEmpty(text, true))
                text = var;
            // print.o(2);
            traceValue = TraceObjectSupport.toTraceObject(pageContext.getDebugger(), value, type, category, text);
            if (caller instanceof Scope)
                VariableInterpreter.setVariable(pageContext, var, traceValue, (Scope) caller);
            else
                pageContext.setVariable(var, traceValue);
        }
        try {
            varValue = new ScriptConverter().serialize(value);
        } catch (ConverterException e) {
            if (value != null)
                varValue = "(" + Caster.toTypeName(value) + ")";
        }
    }
    DebugTrace trace = ((DebuggerImpl) pageContext.getDebugger()).addTrace(type, category, text, ps, var, varValue);
    DebugTrace[] traces = pageContext.getDebugger().getTraces(pageContext);
    String total = "(1st trace)";
    if (traces.length > 1) {
        long t = 0;
        for (int i = 0; i < traces.length; i++) {
            t += traces[i].getTime();
        }
        total = "(" + t + ")";
    }
    boolean hasCat = !StringUtil.isEmpty(trace.getCategory());
    boolean hasText = !StringUtil.isEmpty(trace.getText());
    boolean hasVar = !StringUtil.isEmpty(var);
    // inline
    if (inline) {
        lucee.runtime.format.TimeFormat tf = new lucee.runtime.format.TimeFormat(pageContext.getConfig().getLocale());
        StringBuffer sb = new StringBuffer();
        sb.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"white\">");
        sb.append("<tr>");
        // sb.append("<td><img src=\"/CFIDE/debug/images/Error_16x16.gif\" alt=\"Error type\">");
        sb.append("<td>");
        sb.append("<font color=\"orange\">");
        sb.append("<b>");
        sb.append(DebugTraceImpl.toType(trace.getType(), "INFO") + " - ");
        sb.append("[CFTRACE " + tf.format(new DateTimeImpl(pageContext.getConfig()), "hh:mm:ss:l") + "]");
        sb.append("[" + trace.getTime() + " ms " + total + "]");
        sb.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
        if (hasCat || hasText)
            sb.append(" -");
        if (hasCat)
            sb.append("  [" + trace.getCategory() + "]");
        if (hasText)
            sb.append(" <i>" + trace.getText() + "&nbsp;</i>");
        sb.append("</b>");
        sb.append("</font>");
        sb.append("</td>");
        sb.append("</tr>");
        sb.append("</table>");
        pageContext.forceWrite(sb.toString());
        if (hasVar)
            Dump.call(pageContext, value, var);
    }
    // log
    Log log = ((ConfigImpl) pageContext.getConfig()).getLog("trace");
    StringBuffer msg = new StringBuffer();
    msg.append("[" + trace.getTime() + " ms " + total + "] ");
    msg.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
    if (hasCat || hasText || hasVar)
        msg.append("- ");
    if (hasCat)
        msg.append("[" + trace.getCategory() + "] ");
    if (hasVar)
        msg.append("[" + var + "=" + varValue + "] ");
    if (hasText)
        msg.append(" " + trace.getText() + " ");
    log.log(trace.getType(), "cftrace", msg.toString());
    // abort
    if (abort)
        throw new Abort(Abort.SCOPE_REQUEST);
}
Also used : PageException(lucee.runtime.exp.PageException) ConverterException(lucee.runtime.converter.ConverterException) Log(lucee.commons.io.log.Log) DebuggerImpl(lucee.runtime.debug.DebuggerImpl) PageSource(lucee.runtime.PageSource) Abort(lucee.runtime.exp.Abort) Scope(lucee.runtime.type.scope.Scope) DebugTrace(lucee.runtime.debug.DebugTrace) ScriptConverter(lucee.runtime.converter.ScriptConverter) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 3 with Abort

use of lucee.runtime.exp.Abort in project Lucee by lucee.

the class Cache method doServerCache.

private void doServerCache() throws IOException, PageException {
    if (hasBody)
        hasBody = !StringUtil.isEmpty(body);
    // call via cfcache disable debugger output
    if (pageContext.getConfig().debug())
        pageContext.getDebugger().setOutput(false);
    HttpServletResponse rsp = pageContext.getHttpServletResponse();
    // generate cache resource matching request object
    CacheItem ci = generateCacheResource(null, false);
    // use cached resource
    if (ci.isValid(timespan)) {
        // if(isOK(cacheResource)){
        if (pageContext.getHttpServletResponse().isCommitted())
            return;
        OutputStream os = null;
        try {
            ci.writeTo(os = getOutputStream(), ReqRspUtil.getCharacterEncoding(pageContext, rsp).name());
        // IOUtil.copy(is=cacheResource.getInputStream(),os=getOutputStream(),false,false);
        } finally {
            IOUtil.flushEL(os);
            IOUtil.closeEL(os);
            ((PageContextImpl) pageContext).getRootOut().setClosed(true);
        }
        throw new Abort(Abort.SCOPE_REQUEST);
    }
    // call page again and
    // MetaData.getInstance(getDirectory()).add(ci.getName(), ci.getRaw());
    PageContextImpl pci = (PageContextImpl) pageContext;
    pci.getRootOut().doCache(ci);
}
Also used : Abort(lucee.runtime.exp.Abort) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) CacheItem(lucee.runtime.cache.legacy.CacheItem) PageContextImpl(lucee.runtime.PageContextImpl)

Aggregations

Abort (lucee.runtime.exp.Abort)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Log (lucee.commons.io.log.Log)1 PageContextImpl (lucee.runtime.PageContextImpl)1 PageSource (lucee.runtime.PageSource)1 CacheItem (lucee.runtime.cache.legacy.CacheItem)1 ConfigImpl (lucee.runtime.config.ConfigImpl)1 ConverterException (lucee.runtime.converter.ConverterException)1 ScriptConverter (lucee.runtime.converter.ScriptConverter)1 DebugTrace (lucee.runtime.debug.DebugTrace)1 DebuggerImpl (lucee.runtime.debug.DebuggerImpl)1 PageException (lucee.runtime.exp.PageException)1 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)1 Scope (lucee.runtime.type.scope.Scope)1