Skip to content

Instantly share code, notes, and snippets.

@cluelessjoe
Created October 5, 2014 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cluelessjoe/5928925162fc4041c630 to your computer and use it in GitHub Desktop.
Save cluelessjoe/5928925162fc4041c630 to your computer and use it in GitHub Desktop.
@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