Search in sources :

Example 31 with TemplateException

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

the class AbstrCFMLScriptTransformer method elseifStatement.

/**
 * Liest ein else if Statement ein.
 * <br />
 * EBNF:<br />
 * <code>spaces condition spaces ")" spaces block;</code>
 * @return else if Statement
 * @throws TemplateException
 */
private final boolean elseifStatement(ExprData data, Condition cont) throws TemplateException {
    int pos = data.srcCode.getPos();
    if (!data.srcCode.forwardIfCurrent("else"))
        return false;
    comments(data);
    if (!data.srcCode.forwardIfCurrent("if", '(')) {
        data.srcCode.setPos(pos);
        return false;
    }
    Position line = data.srcCode.getPosition();
    Body body = new BodyBase(data.factory);
    Pair pair = cont.addElseIf(condition(data), body, line, null);
    if (!data.srcCode.forwardIfCurrent(')'))
        throw new TemplateException(data.srcCode, "else if statement must end with a [)]");
    // ex block
    statement(data, body, CTX_ELSE_IF);
    pair.end = data.srcCode.getPosition();
    return true;
}
Also used : Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase) Pair(lucee.transformer.bytecode.statement.Condition.Pair)

Example 32 with TemplateException

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

the class CFMLTransformer method transform.

/**
 * Startmethode zum transfomieren einer CFMLString.
 * <br />
 * EBNF:<br />
 * <code>{body}</code>
 * @param config
 * @param sc CFMLString
 * @param tlibs Tag Library Deskriptoren, nach denen innerhalb der CFML Datei geprueft werden soll.
 * @param flibs Function Library Deskriptoren, nach denen innerhalb der Expressions der CFML Datei geprueft werden soll.
 * @param sourceLastModified
 * @param dotNotationUpperCase
 * @param returnValue if true the method returns the value of the last expression executed inside when you call the method "call"
 * @return uebersetztes CFXD Dokument Element.
 * @throws TemplateException
 */
public Page transform(Factory factory, ConfigImpl config, SourceCode sc, TagLib[] tlibs, FunctionLib[] flibs, long sourceLastModified, Boolean dotNotationUpperCase, boolean returnValue, boolean ignoreScope) throws TemplateException {
    boolean dnuc;
    if (dotNotationUpperCase == null) {
        if (sc instanceof PageSourceCode)
            dnuc = sc.getDialect() == CFMLEngine.DIALECT_CFML && ((MappingImpl) ((PageSourceCode) sc).getPageSource().getMapping()).getDotNotationUpperCase();
        else
            dnuc = sc.getDialect() == CFMLEngine.DIALECT_CFML && config.getDotNotationUpperCase();
    } else
        dnuc = dotNotationUpperCase;
    TagLib[][] _tlibs = new TagLib[][] { null, new TagLib[0] };
    _tlibs[TAG_LIB_GLOBAL] = tlibs;
    // reset page tlds
    if (_tlibs[TAG_LIB_PAGE].length > 0) {
        _tlibs[TAG_LIB_PAGE] = new TagLib[0];
    }
    Page page = new Page(factory, config, sc, null, ConfigWebUtil.getEngine(config).getInfo().getFullVersionInfo(), sourceLastModified, sc.getWriteLog(), sc.getDialect() == CFMLEngine.DIALECT_LUCEE || config.getSuppressWSBeforeArg(), config.getDefaultFunctionOutput(), returnValue, ignoreScope);
    TagData data = new TagData(factory, _tlibs, flibs, config.getCoreTagLib(sc.getDialect()).getScriptTags(), sc, page, dnuc, ignoreScope);
    // Body body=page;
    try {
        do {
            body(data, page, false, null);
            if (data.srcCode.isAfterLast())
                break;
            if (data.srcCode.forwardIfCurrent("</")) {
                int pos = data.srcCode.getPos();
                TagLib tagLib = nameSpace(data);
                if (tagLib == null) {
                    page.addPrintOut(data.factory, "</", null, null);
                } else {
                    String name = identifier(data.srcCode, true, true);
                    if (tagLib.getIgnoreUnknowTags()) {
                        TagLibTag tlt = tagLib.getTag(name);
                        if (tlt == null) {
                            data.srcCode.setPos(pos);
                            page.addPrintOut(data.factory, "</", null, null);
                        }
                    } else
                        throw new TemplateException(sc, "no matching start tag for end tag [" + tagLib.getNameSpaceAndSeparator() + name + "]");
                }
            } else
                throw new TemplateException(sc, "Error while transforming CFML File");
        } while (true);
        // call-back of evaluators
        data.ep.run();
        return page;
    } catch (TemplateException e) {
        data.ep.clear();
        throw e;
    }
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) PageSourceCode(lucee.transformer.util.PageSourceCode) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) TagLib(lucee.transformer.library.tag.TagLib) CustomTagLib(lucee.transformer.library.tag.CustomTagLib) Page(lucee.transformer.bytecode.Page) LitString(lucee.transformer.expression.literal.LitString)

Example 33 with TemplateException

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

the class Exit method doEndTag.

@Override
public int doEndTag() throws TemplateException {
    Scope variables = pageContext.variablesScope();
    Object thistagObj = variables.get("thistag", null);
    boolean insideCT = (thistagObj != null) && (thistagObj instanceof lucee.runtime.type.Collection);
    // Inside Custom Tag
    if (insideCT) {
        lucee.runtime.type.Collection thistag = (lucee.runtime.type.Collection) thistagObj;
        // executionmode
        Object exeModeObj = thistag.get("executionmode", null);
        boolean isEndMode = (exeModeObj != null) && (exeModeObj instanceof String) && exeModeObj.toString().equalsIgnoreCase("end");
        // Start
        if (!isEndMode) {
            if (method == MODE_LOOP) {
                throw new TemplateException("invalid context for the tag exit, method loop can only be used in the end tag of a custom tag");
            } else if (method == MODE_EXIT_TAG) {
                thistag.setEL("executebody", Boolean.FALSE);
                return SKIP_PAGE;
            }
        } else // End
        if (method == MODE_LOOP) {
            thistag.setEL("executebody", Boolean.TRUE);
            return SKIP_PAGE;
        }
        return SKIP_PAGE;
    }
    // OUTside Custom Tag
    if (method == MODE_LOOP)
        throw new TemplateException("invalid context for the tag exit, method loop can only be used inside a custom tag");
    return SKIP_PAGE;
}
Also used : Scope(lucee.runtime.type.scope.Scope) TemplateException(lucee.runtime.exp.TemplateException)

Example 34 with TemplateException

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

the class Header method doStartTag.

@Override
public int doStartTag() throws PageException {
    HttpServletResponse rsp = pageContext.getHttpServletResponse();
    if (rsp.isCommitted())
        throw new TemplateException("can't assign value to header, header is already committed");
    // set name value
    if (name != null) {
        if (charset == null && name.equalsIgnoreCase("content-disposition")) {
            charset = CharsetUtil.toCharSet(((PageContextImpl) pageContext).getWebCharset());
        }
        if (charset != null) {
            name = new String(name.getBytes(CharsetUtil.toCharset(charset)), CharsetUtil.ISO88591);
            value = new String(value.getBytes(CharsetUtil.toCharset(charset)), CharsetUtil.ISO88591);
        } else {
            name = new String(name.getBytes(), CharsetUtil.ISO88591);
            value = new String(value.getBytes(), CharsetUtil.ISO88591);
        }
        if (name.toLowerCase().equals("content-type") && value.length() > 0) {
            ReqRspUtil.setContentType(rsp, value);
        } else {
            rsp.addHeader(name, value);
        }
    }
    // set status
    if (hasStatucCode) {
        if (statustext != null) {
            // try {
            // /rsp.sendError(statuscode, statustext);
            rsp.setStatus(statuscode, statustext);
        /*} 
                catch (IOException e) {
    				throw new TemplateException("can't assign value to header, header is already committed",e.getMessage());
    			} */
        } else {
            rsp.setStatus(statuscode);
        }
    }
    return SKIP_BODY;
}
Also used : TemplateException(lucee.runtime.exp.TemplateException) HttpServletResponse(javax.servlet.http.HttpServletResponse) PageContextImpl(lucee.runtime.PageContextImpl)

Example 35 with TemplateException

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

the class FDSignal method createExceptionStack.

public static List createExceptionStack(PageException pe) {
    StackTraceElement[] traces = pe.getStackTrace();
    PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get();
    String template = "";
    StackTraceElement trace = null;
    List list = new ArrayList();
    Resource res;
    PageSource ps;
    FDStackFrameImpl frame;
    for (int i = traces.length - 1; i >= 0; i--) {
        trace = traces[i];
        ps = null;
        if (trace.getLineNumber() <= 0)
            continue;
        template = trace.getFileName();
        if (template == null || ResourceUtil.getExtension(template, "").equals("java"))
            continue;
        res = ResourceUtil.toResourceNotExisting(pc, template);
        ps = pc.toPageSource(res, null);
        frame = new FDStackFrameImpl(null, pc, trace, ps);
        if (ASMUtil.isOverfowMethod(trace.getMethodName()))
            list.set(0, frame);
        else
            list.add(0, frame);
    }
    if (pe instanceof TemplateException) {
        TemplateException te = (TemplateException) pe;
        if (te.getPageSource() != null)
            list.add(0, new FDStackFrameImpl(null, pc, te.getPageSource(), te.getLine()));
    }
    return list;
}
Also used : TemplateException(lucee.runtime.exp.TemplateException) ArrayList(java.util.ArrayList) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) List(java.util.List) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource)

Aggregations

TemplateException (lucee.runtime.exp.TemplateException)55 Position (lucee.transformer.Position)21 Expression (lucee.transformer.expression.Expression)18 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)15 LitString (lucee.transformer.expression.literal.LitString)14 ScriptBody (lucee.transformer.bytecode.ScriptBody)9 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)9 Body (lucee.transformer.bytecode.Body)8 BodyBase (lucee.transformer.bytecode.BodyBase)8 FunctionBody (lucee.transformer.bytecode.FunctionBody)8 ComponentTemplateException (lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException)8 Variable (lucee.transformer.expression.var.Variable)8 ExprString (lucee.transformer.expression.ExprString)7 TagLibTag (lucee.transformer.library.tag.TagLibTag)6 PageSourceCode (lucee.transformer.util.PageSourceCode)6 ArrayList (java.util.ArrayList)5 OpVariable (lucee.transformer.bytecode.op.OpVariable)5 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)5 Resource (lucee.commons.io.res.Resource)4 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)4