Search in sources :

Example 1 with Tag

use of jodd.lagarto.Tag in project jodd by oblac.

the class PageRegionExtractorTest method testTag.

@Test(expected = DecoraException.class)
public final void testTag() {
    // setup
    Tag tag = mock(Tag.class);
    when(tag.getType()).thenReturn(TagType.END);
    regionMarkers.add(new RegionMarker("TEST"));
    setInternalState(pageRegionExtractor, "regionMarkers", regionMarkers);
    // when
    pageRegionExtractor.tag(tag);
    // then
    fail("A DecoraException must have occured because tag parameter not matches with any decoraTags.");
}
Also used : Tag(jodd.lagarto.Tag) RegionMarker(jodd.decora.parser.PageRegionExtractor.RegionMarker) Test(org.junit.Test)

Example 2 with Tag

use of jodd.lagarto.Tag 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

Tag (jodd.lagarto.Tag)2 RegionMarker (jodd.decora.parser.PageRegionExtractor.RegionMarker)1 EmptyTagVisitor (jodd.lagarto.EmptyTagVisitor)1 LagartoParser (jodd.lagarto.LagartoParser)1 MutableInteger (jodd.mutable.MutableInteger)1 Test (org.junit.Test)1