private String getLiteral()

in velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java [185:234]


    private String getLiteral()
    {
        SpaceGobbling spaceGobbling = rsvc.getSpaceGobbling();
        ASTDirective directive = (ASTDirective)node;

        String morePrefix = directive.getMorePrefix();

        if (literal == null)
        {
            StringBuilder buffer = new StringBuilder();
            Token t = node.getFirstToken();

            /* avoid outputting twice the prefix and the 'MORE' prefix,
             * but still display the prefix in the cases where the ASTDirective would hide it */
            int pos = -1;
            while (t != null && t != node.getLastToken())
            {
                if (pos == -1) pos = t.image.lastIndexOf(rsvc.getParserConfiguration().getHashChar());
                if (pos != -1)
                {
                    buffer.append(t.image.substring(pos));
                    pos = 0;
                }
                else if (morePrefix.length() == 0 && spaceGobbling.compareTo(SpaceGobbling.LINES) >= 0)
                {
                    buffer.append(t.image);
                }
                t = t.next;
            }

            if (t != null)
            {
                if (pos == -1) pos = t.image.lastIndexOf(rsvc.getParserConfiguration().getHashChar());
                if (pos != -1)
                {
                    buffer.append(t.image.substring(pos));
                }
            }

            literal = buffer.toString();
            /* avoid outputting twice the postfix, but still display it in the cases
             * where the ASTDirective would hide it */
            String postfix = directive.getPostfix();
            if ((morePrefix.length() > 0 || spaceGobbling == SpaceGobbling.NONE) && literal.endsWith(postfix))
            {
                literal = literal.substring(0, literal.length() - postfix.length());
            }
        }
        return literal;
    }