Permalink
Browse files

STXM-12 Don't indent end element if element content is all on one line

  • Loading branch information...
1 parent 8f05c65 commit 9193c4ae16c8e6382defe0ca2058e1f9b54dec5c @bstansberry bstansberry committed Jan 6, 2012
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/main/java/org/jboss/staxmapper/FormattingXMLStreamWriter.java
@@ -42,6 +42,7 @@
private final ArrayDeque<ArgRunnable> attrQueue = new ArrayDeque<ArgRunnable>();
private int level;
private int state = START_DOCUMENT;
+ private boolean indentEndElement = false;
private ArrayDeque<String> unspecifiedNamespaces = new ArrayDeque<String>();
@@ -106,6 +107,7 @@ public void run(int arg) throws XMLStreamException {
level++;
state = START_ELEMENT;
+ indentEndElement = false;
}
public void writeStartElement(final String namespaceURI, final String localName) throws XMLStreamException {
@@ -126,6 +128,7 @@ public void run(int arg) throws XMLStreamException {
});
level++;
state = START_ELEMENT;
+ indentEndElement = false;
}
public void writeStartElement(final String prefix, final String localName, final String namespaceURI) throws XMLStreamException {
@@ -146,6 +149,7 @@ public void run(int arg) throws XMLStreamException {
});
level++;
state = START_ELEMENT;
+ indentEndElement = false;
}
public void writeEmptyElement(final String namespaceURI, final String localName) throws XMLStreamException {
@@ -182,8 +186,11 @@ public void writeEndElement() throws XMLStreamException {
level--;
if (state != START_ELEMENT) {
runAttrQueue();
- nl();
- indent();
+ if (state != CHARACTERS || indentEndElement) {
+ nl();
+ indent();
+ indentEndElement = false;
+ }
delegate.writeEndElement();
} else {
// Change the start element to an empty element
@@ -412,14 +419,15 @@ public void writeCharacters(final String text) throws XMLStreamException {
}
final Iterator<String> iterator = Spliterator.over(text, '\n');
while (iterator.hasNext()) {
- final String t = (String) iterator.next();
+ final String t = iterator.next();
delegate.writeCharacters(t);
if (iterator.hasNext()) {
nl();
indent();
}
}
state = CHARACTERS;
+ indentEndElement = true;
}
public void writeCharacters(final char[] text, final int start, final int len) throws XMLStreamException {

0 comments on commit 9193c4a

Please sign in to comment.