Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

1 participant

@bstansberry
Owner

No description provided.

@bstansberry
Owner

No objections in 3 years, so let's do it!

@bstansberry bstansberry merged commit 8df8c6a into jbossas:master
@bstansberry bstansberry deleted the bstansberry:STXM-12 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/main/java/org/jboss/staxmapper/FormattingXMLStreamWriter.java
View
14 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,7 +419,7 @@ 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();
@@ -420,6 +427,7 @@ public void writeCharacters(final String text) throws XMLStreamException {
}
}
state = CHARACTERS;
+ indentEndElement = true;
}
public void writeCharacters(final char[] text, final int start, final int len) throws XMLStreamException {
Something went wrong with that request. Please try again.