* 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.getValue(), 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.setValue(tagStart + tag.getTagLength());
}
}
}
});
sb.append(input.substring(lastPosition.getValue()));
return sb.toString();
}