Created
October 5, 2014 21:10
-
-
Save cluelessjoe/5928925162fc4041c630 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { | |
String m = method.getName(); | |
if (log.isDebugEnabled()) { | |
log.debug("XML event: " + m); | |
} | |
// Needs to be BEFORE the actual event, so that for instance the | |
// sequence writeStartElem, writeAttr, writeStartElem, writeEndElem, | |
// writeEndElem | |
// is correctly handled | |
if ("writeStartElement".equals(m)) { | |
// update state of parent node | |
if (depth > 0) { | |
hasChildElement.put(depth - 1, true); | |
} | |
// reset state of current node | |
hasChildElement.put(depth, false); | |
// indent for current depth | |
if (firstLine == false) { | |
target.writeCharacters(LINEFEED_CHAR); | |
target.writeCharacters(repeat(depth, indent)); | |
} | |
depth++; | |
} else if ("writeEndElement".equals(m)) { | |
depth--; | |
if (hasChildElement.get(depth) == true) { | |
target.writeCharacters(LINEFEED_CHAR); | |
target.writeCharacters(repeat(depth, indent)); | |
} | |
} else if ("writeEmptyElement".equals(m)) { | |
// update state of parent node | |
if (depth > 0) { | |
hasChildElement.put(depth - 1, true); | |
} | |
// indent for current depth | |
target.writeCharacters(LINEFEED_CHAR); | |
target.writeCharacters(repeat(depth, indent)); | |
} | |
method.invoke(target, args); | |
firstLine = false; | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment