Search in sources :

Example 6 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.

the class BodyBase method addPrintOut.

@Override
public void addPrintOut(Factory f, String str, Position start, Position end) {
    if (concatPrintouts(str))
        return;
    last = new PrintOut(f.createLitString(str, start, end), start, end);
    last.setParent(this);
    this.statements.add(last);
}
Also used : PrintOut(lucee.transformer.bytecode.statement.PrintOut)

Example 7 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.

the class BodyBase method addStatement.

/**
 * @see lucee.transformer.bytecode.Body#addStatement(lucee.transformer.bytecode.Statement)
 */
@Override
public void addStatement(Statement statement) {
    if (statement instanceof PrintOut) {
        Expression expr = ((PrintOut) statement).getExpr();
        if (expr instanceof LitString && concatPrintouts(((LitString) expr).getString()))
            return;
    }
    statement.setParent(this);
    this.statements.add(statement);
    last = statement;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression)

Example 8 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.

the class CFMLTransformer method literal.

/**
 * Liest Literale Zeichenketten ein die sich innerhalb und auserhalb von tgas befinden,
 * beim Einlesen wird unterschieden ob Expression geparsst werden muessen oder nicht,
 * dies ist abhaengig, von der Definition des Tag in dem man sich allenfalls befindet, innerhalb der TLD.
 * @param parent uebergeordnetes Element.
 * @param parseExpression Definiert on Expressions geparset werden sollen oder nicht.
 * @param transformer Expression Transfomer zum uebersetzen der Expressions innerhalb des Literals.
 * @throws TemplateException
 *
 * <br />
 * EBNF:<br />
 * <code>("<" | {?-"#"-"<"} "<" | {"#" expression "#"} "<" ) | ({?-"<"} "<")
 *			(* Welcher Teil der "oder" Bedingung ausgefuehrt wird, ist abhaengig ob die Tag-Lib vorgibt,
 *			 dass Expression geparst werden sollen oder nicht. *)</code>
 */
private void literal(TagData data, Body parent, boolean parseExpression, ExprTransformer transformer) throws TemplateException {
    // with expression
    if (parseExpression) {
        if (data.srcCode.isAfterLast())
            return;
        // data.cfml.getCurrent()
        StringBuffer text = new StringBuffer();
        int count = 0;
        while (data.srcCode.isValidIndex()) {
            count++;
            // #
            if (data.srcCode.isCurrent('#')) {
                data.srcCode.next();
                if (data.srcCode.isCurrent('#')) {
                    text.append('#');
                } else {
                    if (text.length() > 0) {
                        Position end = data.srcCode.getPosition();
                        Position start = data.srcCode.getPosition(end.pos - text.length());
                        parent.addPrintOut(data.factory, text.toString(), start, end);
                        start = end;
                        text = new StringBuffer();
                    }
                    Position end = data.srcCode.getPosition();
                    Position start = data.srcCode.getPosition(end.pos - text.length());
                    PrintOut po;
                    parent.addStatement(po = new PrintOut(transformer.transform(data.factory, data.root, data.ep, data.tlibs, data.flibs, data.scriptTags, data.srcCode, data.settings), start, end));
                    po.setEnd(data.srcCode.getPosition());
                    if (!data.srcCode.isCurrent('#'))
                        throw new TemplateException(data.srcCode, "missing terminating [#] for expression");
                }
            } else if (data.srcCode.isCurrent('<') && count > 1) {
                break;
            } else
                text.append(data.srcCode.getCurrent());
            data.srcCode.next();
        }
        if (text.length() > 0) {
            Position end = data.srcCode.getPosition();
            Position start = data.srcCode.getPosition(end.pos - text.length());
            parent.addPrintOut(data.factory, text.toString(), start, end);
        }
    } else // no expression
    {
        int start = data.srcCode.getPos();
        data.srcCode.next();
        int end = data.srcCode.indexOfNext('<');
        String text;
        if (end == -1) {
            text = data.srcCode.substring(start);
            data.srcCode.setPos(data.srcCode.length());
        } else {
            text = data.srcCode.substring(start, end - start);
            data.srcCode.setPos(end);
        }
        Position e = data.srcCode.getPosition();
        Position s = data.srcCode.getPosition(start);
        parent.addPrintOut(data.factory, text, s, e);
    }
}
Also used : PrintOut(lucee.transformer.bytecode.statement.PrintOut) Position(lucee.transformer.Position) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) LitString(lucee.transformer.expression.literal.LitString)

Example 9 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.

the class CFMLTransformer method transform.

/**
 * Startmethode zum transfomieren einer CFML Datei.
 * <br />
 * EBNF:<br />
 * <code>{body}</code>
 * @param config
 * @param ps CFML File
 * @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 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
 * @throws IOException
 */
public Page transform(Factory factory, ConfigImpl config, PageSource ps, TagLib[] tlibs, FunctionLib[] flibs, boolean returnValue, boolean ignoreScopes) throws TemplateException, IOException {
    Page p;
    SourceCode sc;
    boolean writeLog = config.getExecutionLogEnabled();
    Charset charset = config.getTemplateCharset();
    boolean dotUpper = ps.getDialect() == CFMLEngine.DIALECT_CFML && ((MappingImpl) ps.getMapping()).getDotNotationUpperCase();
    // parse regular
    while (true) {
        try {
            sc = new PageSourceCode(ps, charset, writeLog);
            p = transform(factory, config, sc, tlibs, flibs, ps.getResource().lastModified(), dotUpper, returnValue, ignoreScopes);
            break;
        } catch (ProcessingDirectiveException pde) {
            if (pde.getWriteLog() != null)
                writeLog = pde.getWriteLog().booleanValue();
            if (pde.getDotNotationUpperCase() != null)
                dotUpper = pde.getDotNotationUpperCase().booleanValue();
            if (!StringUtil.isEmpty(pde.getCharset()))
                charset = pde.getCharset();
        }
    }
    // could it be a component?
    boolean isCFML = ps.getDialect() == CFMLEngine.DIALECT_CFML;
    boolean isCFMLCompExt = isCFML && Constants.isCFMLComponentExtension(ResourceUtil.getExtension(ps.getResource(), ""));
    boolean possibleUndetectedComponent = false;
    // we don't have a component or interface
    if (p.isPage()) {
        if (isCFML)
            possibleUndetectedComponent = isCFMLCompExt;
        else if (Constants.isLuceeComponentExtension(ResourceUtil.getExtension(ps.getResource(), ""))) {
            Expression expr;
            Statement stat;
            PrintOut po;
            LitString ls;
            List<Statement> statements = p.getStatements();
            // check the root statements for component
            Iterator<Statement> it = statements.iterator();
            String str;
            while (it.hasNext()) {
                stat = it.next();
                if (stat instanceof PrintOut && (expr = ((PrintOut) stat).getExpr()) instanceof LitString) {
                    ls = (LitString) expr;
                    str = ls.getString();
                    if (str.indexOf(Constants.LUCEE_COMPONENT_TAG_NAME) != -1 || str.indexOf(Constants.LUCEE_INTERFACE_TAG_NAME) != -1 || // cfml name is supported as alias
                    str.indexOf(Constants.CFML_COMPONENT_TAG_NAME) != -1) {
                        possibleUndetectedComponent = true;
                        break;
                    }
                }
            }
        }
    }
    /*if(p.isPage() && (isCFML?
				Constants.isCFMLComponentExtension(ResourceUtil.getExtension(ps.getResource(),"")):
				Constants.isLuceeComponentExtension(ResourceUtil.getExtension(ps.getResource(),""))) &&
				isPossibleRawScript(sc,config.getIdentification())){*/
    if (possibleUndetectedComponent) {
        Page _p;
        TagLibTag scriptTag = CFMLTransformer.getTLT(sc, isCFML ? Constants.CFML_SCRIPT_TAG_NAME : Constants.LUCEE_SCRIPT_TAG_NAME, config.getIdentification());
        sc.setPos(0);
        SourceCode original = sc;
        // try inside a cfscript
        String text = "<" + scriptTag.getFullName() + ">" + original.getText() + "\n</" + scriptTag.getFullName() + ">";
        sc = new PageSourceCode(ps, text, charset, writeLog);
        try {
            while (true) {
                if (sc == null) {
                    sc = new PageSourceCode(ps, charset, writeLog);
                    text = "<" + scriptTag.getFullName() + ">" + sc.getText() + "\n</" + scriptTag.getFullName() + ">";
                    sc = new PageSourceCode(ps, text, charset, writeLog);
                }
                try {
                    _p = transform(factory, config, sc, tlibs, flibs, ps.getResource().lastModified(), dotUpper, returnValue, ignoreScopes);
                    break;
                } catch (ProcessingDirectiveException pde) {
                    if (pde.getWriteLog() != null)
                        writeLog = pde.getWriteLog().booleanValue();
                    if (pde.getDotNotationUpperCase() != null)
                        dotUpper = pde.getDotNotationUpperCase().booleanValue();
                    if (!StringUtil.isEmpty(pde.getCharset()))
                        charset = pde.getCharset();
                    sc = null;
                }
            }
        } catch (ComponentTemplateException e) {
            throw e.getTemplateException();
        }
        // we only use that result if it is a component now
        if (_p != null && !_p.isPage())
            return _p;
    }
    if (isCFMLCompExt && !p.isComponent() && !p.isInterface()) {
        String msg = "template [" + ps.getDisplayPath() + "] must contain a component or an interface.";
        if (sc != null)
            throw new TemplateException(sc, msg);
        throw new TemplateException(msg);
    }
    return p;
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) PageSourceCode(lucee.transformer.util.PageSourceCode) SourceCode(lucee.transformer.util.SourceCode) PageSourceCode(lucee.transformer.util.PageSourceCode) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) Statement(lucee.transformer.bytecode.Statement) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) Charset(java.nio.charset.Charset) Page(lucee.transformer.bytecode.Page) ProcessingDirectiveException(lucee.transformer.cfml.evaluator.impl.ProcessingDirectiveException) LitString(lucee.transformer.expression.literal.LitString) LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 10 with PrintOut

use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.

the class Query method translateChildren.

private void translateChildren(Iterator it) {
    Statement stat;
    while (it.hasNext()) {
        stat = (Statement) it.next();
        if (stat instanceof PrintOut) {
            PrintOut printOut = ((PrintOut) stat);
            Expression e = printOut.getExpr();
            if (!(e instanceof Literal)) {
                Expression expr = removeCastString(e);
                if (expr instanceof Variable) {
                    // do not preserve BIF PreserveSingleQuotes return value
                    Member member = ((Variable) expr).getFirstMember();
                    if (member instanceof BIF) {
                        BIF bif = (BIF) member;
                        if (bif.getClassDefinition().getClassName().equals(PreserveSingleQuotes.class.getName())) {
                            printOut.setExpr(bif.getArguments()[0].getValue());
                            continue;
                        } else if (bif.getClassDefinition().getClassName().equals(ListQualify.class.getName())) {
                            Argument[] args = bif.getArguments();
                            List<Argument> arr = new ArrayList<Argument>();
                            // first get existing arguments
                            arr.add(args[0]);
                            arr.add(args[1]);
                            if (args.length >= 3)
                                arr.add(args[2]);
                            else
                                arr.add(new Argument(expr.getFactory().createLitString(","), "string"));
                            if (args.length >= 4)
                                arr.add(args[3]);
                            else
                                arr.add(new Argument(expr.getFactory().createLitString("all"), "string"));
                            if (args.length >= 5)
                                arr.add(args[4]);
                            else
                                arr.add(new Argument(expr.getFactory().createLitBoolean(false), "boolean"));
                            // PSQ-BIF DO NOT REMOVE THIS COMMENT
                            arr.add(new Argument(expr.getFactory().createLitBoolean(true), "boolean"));
                            bif.setArguments(arr.toArray(new Argument[arr.size()]));
                            continue;
                        } else if (bif.getClassDefinition().getClassName().equals(QuotedValueList.class.getName()) || bif.getClassDefinition().getClassName().equals(ValueList.class.getName())) {
                            // printOut.setPreserveSingleQuote(false);
                            continue;
                        }
                    }
                    // do not preserve UDF return value
                    member = ((Variable) expr).getLastMember();
                    if (member instanceof UDF)
                        continue;
                }
                printOut.setCheckPSQ(true);
                if (e != expr)
                    printOut.setExpr(expr);
            }
        } else if (stat instanceof Tag) {
            Body b = ((Tag) stat).getBody();
            if (b != null)
                translateChildren(b.getStatements().iterator());
        } else if (stat instanceof Body) {
            translateChildren(((Body) stat).getStatements().iterator());
        }
    }
}
Also used : Variable(lucee.transformer.expression.var.Variable) Argument(lucee.transformer.bytecode.expression.var.Argument) Statement(lucee.transformer.bytecode.Statement) PreserveSingleQuotes(lucee.runtime.functions.other.PreserveSingleQuotes) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression) UDF(lucee.transformer.bytecode.expression.var.UDF) Literal(lucee.transformer.expression.literal.Literal) QuotedValueList(lucee.runtime.functions.other.QuotedValueList) ValueList(lucee.runtime.functions.query.ValueList) ArrayList(java.util.ArrayList) List(java.util.List) Tag(lucee.transformer.bytecode.statement.tag.Tag) Member(lucee.transformer.expression.var.Member) Body(lucee.transformer.bytecode.Body) BIF(lucee.transformer.bytecode.expression.var.BIF)

Aggregations

PrintOut (lucee.transformer.bytecode.statement.PrintOut)10 Statement (lucee.transformer.bytecode.Statement)6 Expression (lucee.transformer.expression.Expression)6 LitString (lucee.transformer.expression.literal.LitString)6 Body (lucee.transformer.bytecode.Body)5 Tag (lucee.transformer.bytecode.statement.tag.Tag)4 Literal (lucee.transformer.expression.literal.Literal)3 TagLibTag (lucee.transformer.library.tag.TagLibTag)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TemplateException (lucee.runtime.exp.TemplateException)2 BIF (lucee.transformer.bytecode.expression.var.BIF)2 ComponentTemplateException (lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException)2 Member (lucee.transformer.expression.var.Member)2 Variable (lucee.transformer.expression.var.Variable)2 Charset (java.nio.charset.Charset)1 Iterator (java.util.Iterator)1 lucee.aprint (lucee.aprint)1 RefBoolean (lucee.commons.lang.types.RefBoolean)1 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)1