Search in sources :

Example 11 with MutableInteger

use of jodd.mutable.MutableInteger in project jodd by oblac.

the class Jspp method process.

// ---------------------------------------------------------------- process
/**
	 * Processes input JSP content and replace macros.
	 */
public String process(final String input) {
    LagartoParser lagartoParser = new LagartoParser(input, true);
    final MutableInteger lastPosition = new MutableInteger(0);
    final StringBuilder sb = new StringBuilder();
    lagartoParser.parse(new EmptyTagVisitor() {

        @Override
        public void tag(Tag tag) {
            if (tag.getType() == TagType.SELF_CLOSING) {
                if (tag.matchTagNamePrefix(tagPrefix)) {
                    int tagStart = tag.getTagPosition();
                    sb.append(input.substring(lastPosition.get(), tagStart));
                    String tagName = tag.getName().toString();
                    tagName = tagName.substring(tagPrefix.length);
                    String macroBody = loadMacro(tagName);
                    int attrCount = tag.getAttributeCount();
                    for (int i = 0; i < attrCount; i++) {
                        String key = macroPrefix + tag.getAttributeName(i) + macroSuffix;
                        macroBody = StringUtil.replace(macroBody, key, tag.getAttributeValue(i).toString());
                    }
                    sb.append(macroBody);
                    lastPosition.set(tagStart + tag.getTagLength());
                }
            }
        }
    });
    sb.append(input.substring(lastPosition.get()));
    return sb.toString();
}
Also used : EmptyTagVisitor(jodd.lagarto.EmptyTagVisitor) MutableInteger(jodd.mutable.MutableInteger) Tag(jodd.lagarto.Tag) LagartoParser(jodd.lagarto.LagartoParser)

Aggregations

MutableInteger (jodd.mutable.MutableInteger)11 Test (org.junit.Test)6 MutableIntegerConverter (jodd.typeconverter.impl.MutableIntegerConverter)2 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 FileConsumer (jodd.io.findfile.FileConsumer)1 FindFile (jodd.io.findfile.FindFile)1 RegExpFindFile (jodd.io.findfile.RegExpFindFile)1 WildcardFindFile (jodd.io.findfile.WildcardFindFile)1 EmptyTagVisitor (jodd.lagarto.EmptyTagVisitor)1 LagartoParser (jodd.lagarto.LagartoParser)1 Tag (jodd.lagarto.Tag)1 MutableByte (jodd.mutable.MutableByte)1 MutableDouble (jodd.mutable.MutableDouble)1 MutableFloat (jodd.mutable.MutableFloat)1 MutableLong (jodd.mutable.MutableLong)1 MutableShort (jodd.mutable.MutableShort)1