From 17787e5ff7dea8acf347fd3f92bd855e110d6dfe Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 22 May 2023 15:35:24 +0200 Subject: [PATCH] Reformat using spotless --- pom.xml | 8 +- .../plexus/util/xml/CompactXMLWriter.java | 17 +- .../plexus/util/xml/PrettyPrintXMLWriter.java | 285 +- .../plexus/util/xml/SerializerXMLWriter.java | 95 +- .../codehaus/plexus/util/xml/StringUtils.java | 116 +- .../codehaus/plexus/util/xml/XMLWriter.java | 12 +- .../codehaus/plexus/util/xml/XmlReader.java | 571 ++- .../plexus/util/xml/XmlReaderException.java | 36 +- .../plexus/util/xml/XmlStreamReader.java | 78 +- .../util/xml/XmlStreamReaderException.java | 16 +- .../plexus/util/xml/XmlStreamWriter.java | 109 +- .../org/codehaus/plexus/util/xml/XmlUtil.java | 231 +- .../plexus/util/xml/XmlWriterUtil.java | 189 +- .../org/codehaus/plexus/util/xml/Xpp3Dom.java | 245 +- .../plexus/util/xml/Xpp3DomBuilder.java | 82 +- .../plexus/util/xml/Xpp3DomUtils.java | 33 +- .../plexus/util/xml/Xpp3DomWriter.java | 48 +- .../util/xml/pull/EntityReplacementMap.java | 358 +- .../plexus/util/xml/pull/MXParser.java | 3356 +++++++---------- .../plexus/util/xml/pull/MXSerializer.java | 1116 ++---- .../plexus/util/xml/pull/XmlPullParser.java | 118 +- .../util/xml/pull/XmlPullParserException.java | 48 +- .../plexus/util/xml/pull/XmlSerializer.java | 75 +- .../util/xml/PrettyPrintXMLWriterTest.java | 209 +- .../plexus/util/xml/XmlStreamReaderTest.java | 182 +- .../plexus/util/xml/XmlStreamWriterTest.java | 109 +- .../codehaus/plexus/util/xml/XmlUtilTest.java | 118 +- .../plexus/util/xml/XmlWriterUtilTest.java | 399 +- .../plexus/util/xml/Xpp3DomBuilderTest.java | 268 +- .../plexus/util/xml/Xpp3DomPerfTest.java | 35 +- .../codehaus/plexus/util/xml/Xpp3DomTest.java | 506 ++- .../plexus/util/xml/Xpp3DomWriterTest.java | 120 +- ...onformanceTestSuite_Production24_Test.java | 397 +- ...ConformanceTestSuite_Production2_Test.java | 643 ++-- ...onformanceTestSuite_Production32_Test.java | 425 +-- ...onformanceTestSuite_Production66_Test.java | 707 ++-- ...onformanceTestSuite_Production80_Test.java | 287 +- .../util/xml/pull/MXParserPerfTest.java | 29 +- .../plexus/util/xml/pull/MXParserTest.java | 1579 ++++---- ..._BjoernHoehrmannviaHST2013_09_18_Test.java | 181 +- 40 files changed, 5616 insertions(+), 7820 deletions(-) diff --git a/pom.xml b/pom.xml index 65be8e56..6e8d2a50 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,4 @@ - - 4.0.0 @@ -143,15 +141,17 @@ limitations under the License. org.apache.maven.plugins maven-scm-publish-plugin - ${project.reporting.outputDirectory} + ${project.reporting.outputDirectory} + scm-publish - site-deploy + publish-scm + site-deploy diff --git a/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java b/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java index 85835210..d7ceaa05 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java @@ -22,23 +22,18 @@ /** * */ -public class CompactXMLWriter - extends PrettyPrintXMLWriter -{ +public class CompactXMLWriter extends PrettyPrintXMLWriter { - public CompactXMLWriter( PrintWriter writer ) - { - super( writer ); + public CompactXMLWriter(PrintWriter writer) { + super(writer); } - public CompactXMLWriter( Writer writer ) - { - super( writer ); + public CompactXMLWriter(Writer writer) { + super(writer); } @Override - protected void endOfLine() - { + protected void endOfLine() { // override parent: don't write anything at end of line } } diff --git a/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java b/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java index c01109c9..e089c5c1 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java @@ -20,7 +20,6 @@ import java.io.Writer; import java.util.ArrayDeque; import java.util.Deque; -import java.util.LinkedList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -29,11 +28,9 @@ * * */ -public class PrettyPrintXMLWriter - implements XMLWriter -{ +public class PrettyPrintXMLWriter implements XMLWriter { /** Line separator ("\n" on UNIX) */ - protected static final String LS = System.getProperty( "line.separator" ); + protected static final String LS = System.getProperty("line.separator"); private PrintWriter writer; @@ -59,34 +56,30 @@ public class PrettyPrintXMLWriter * @param writer not null * @param lineIndenter could be null, but the normal way is some spaces. */ - public PrettyPrintXMLWriter( PrintWriter writer, String lineIndenter ) - { - this( writer, lineIndenter, null, null ); + public PrettyPrintXMLWriter(PrintWriter writer, String lineIndenter) { + this(writer, lineIndenter, null, null); } /** * @param writer not null * @param lineIndenter could be null, but the normal way is some spaces. */ - public PrettyPrintXMLWriter( Writer writer, String lineIndenter ) - { - this( new PrintWriter( writer ), lineIndenter ); + public PrettyPrintXMLWriter(Writer writer, String lineIndenter) { + this(new PrintWriter(writer), lineIndenter); } /** * @param writer not null */ - public PrettyPrintXMLWriter( PrintWriter writer ) - { - this( writer, null, null ); + public PrettyPrintXMLWriter(PrintWriter writer) { + this(writer, null, null); } /** * @param writer not null */ - public PrettyPrintXMLWriter( Writer writer ) - { - this( new PrintWriter( writer ) ); + public PrettyPrintXMLWriter(Writer writer) { + this(new PrintWriter(writer)); } /** @@ -95,9 +88,8 @@ public PrettyPrintXMLWriter( Writer writer ) * @param encoding could be null or invalid. * @param doctype could be null. */ - public PrettyPrintXMLWriter( PrintWriter writer, String lineIndenter, String encoding, String doctype ) - { - this( writer, lineIndenter, LS, encoding, doctype ); + public PrettyPrintXMLWriter(PrintWriter writer, String lineIndenter, String encoding, String doctype) { + this(writer, lineIndenter, LS, encoding, doctype); } /** @@ -106,9 +98,8 @@ public PrettyPrintXMLWriter( PrintWriter writer, String lineIndenter, String enc * @param encoding could be null or invalid. * @param doctype could be null. */ - public PrettyPrintXMLWriter( Writer writer, String lineIndenter, String encoding, String doctype ) - { - this( new PrintWriter( writer ), lineIndenter, encoding, doctype ); + public PrettyPrintXMLWriter(Writer writer, String lineIndenter, String encoding, String doctype) { + this(new PrintWriter(writer), lineIndenter, encoding, doctype); } /** @@ -116,9 +107,8 @@ public PrettyPrintXMLWriter( Writer writer, String lineIndenter, String encoding * @param encoding could be null or invalid. * @param doctype could be null. */ - public PrettyPrintXMLWriter( PrintWriter writer, String encoding, String doctype ) - { - this( writer, " ", encoding, doctype ); + public PrettyPrintXMLWriter(PrintWriter writer, String encoding, String doctype) { + this(writer, " ", encoding, doctype); } /** @@ -126,9 +116,8 @@ public PrettyPrintXMLWriter( PrintWriter writer, String encoding, String doctype * @param encoding could be null or invalid. * @param doctype could be null. */ - public PrettyPrintXMLWriter( Writer writer, String encoding, String doctype ) - { - this( new PrintWriter( writer ), encoding, doctype ); + public PrettyPrintXMLWriter(Writer writer, String encoding, String doctype) { + this(new PrintWriter(writer), encoding, doctype); } /** @@ -138,42 +127,39 @@ public PrettyPrintXMLWriter( Writer writer, String encoding, String doctype ) * @param encoding could be null or invalid. * @param doctype could be null. */ - public PrettyPrintXMLWriter( PrintWriter writer, String lineIndenter, String lineSeparator, String encoding, - String doctype ) - { - setWriter( writer ); + public PrettyPrintXMLWriter( + PrintWriter writer, String lineIndenter, String lineSeparator, String encoding, String doctype) { + setWriter(writer); - setLineIndenter( lineIndenter ); + setLineIndenter(lineIndenter); - setLineSeparator( lineSeparator ); + setLineSeparator(lineSeparator); - setEncoding( encoding ); + setEncoding(encoding); - setDocType( doctype ); + setDocType(doctype); - if ( doctype != null || encoding != null ) - { + if (doctype != null || encoding != null) { writeDocumentHeaders(); } } /** {@inheritDoc} */ @Override - public void startElement( String name ) - { + public void startElement(String name) { tagIsEmpty = false; finishTag(); - write( "<" ); + write("<"); - write( name ); + write(name); - elementStack.addLast( name ); + elementStack.addLast(name); tagInProgress = true; - setDepth( getDepth() + 1 ); + setDepth(getDepth() + 1); readyForNewLine = true; @@ -182,65 +168,55 @@ public void startElement( String name ) /** {@inheritDoc} */ @Override - public void writeText( String text ) - { - writeText( text, true ); + public void writeText(String text) { + writeText(text, true); } /** {@inheritDoc} */ @Override - public void writeMarkup( String text ) - { - writeText( text, false ); + public void writeMarkup(String text) { + writeText(text, false); } - private void writeText( String text, boolean escapeXml ) - { + private void writeText(String text, boolean escapeXml) { readyForNewLine = false; tagIsEmpty = false; finishTag(); - if ( escapeXml ) - { - text = escapeXml( text ); + if (escapeXml) { + text = escapeXml(text); } - write( StringUtils.unifyLineSeparators( text, lineSeparator ) ); + write(StringUtils.unifyLineSeparators(text, lineSeparator)); } - private static final Pattern amp = Pattern.compile( "&" ); + private static final Pattern amp = Pattern.compile("&"); - private static final Pattern lt = Pattern.compile( "<" ); + private static final Pattern lt = Pattern.compile("<"); - private static final Pattern gt = Pattern.compile( ">" ); + private static final Pattern gt = Pattern.compile(">"); - private static final Pattern dqoute = Pattern.compile( "\"" ); + private static final Pattern dqoute = Pattern.compile("\""); - private static final Pattern sqoute = Pattern.compile( "\'" ); + private static final Pattern sqoute = Pattern.compile("\'"); - private static String escapeXml( String text ) - { - if ( text.indexOf( '&' ) >= 0 ) - { - text = amp.matcher( text ).replaceAll( "&" ); + private static String escapeXml(String text) { + if (text.indexOf('&') >= 0) { + text = amp.matcher(text).replaceAll("&"); } - if ( text.indexOf( '<' ) >= 0 ) - { - text = lt.matcher( text ).replaceAll( "<" ); + if (text.indexOf('<') >= 0) { + text = lt.matcher(text).replaceAll("<"); } - if ( text.indexOf( '>' ) >= 0 ) - { - text = gt.matcher( text ).replaceAll( ">" ); + if (text.indexOf('>') >= 0) { + text = gt.matcher(text).replaceAll(">"); } - if ( text.indexOf( '"' ) >= 0 ) - { - text = dqoute.matcher( text ).replaceAll( """ ); + if (text.indexOf('"') >= 0) { + text = dqoute.matcher(text).replaceAll("""); } - if ( text.indexOf( '\'' ) >= 0 ) - { - text = sqoute.matcher( text ).replaceAll( "'" ); + if (text.indexOf('\'') >= 0) { + text = sqoute.matcher(text).replaceAll("'"); } return text; @@ -248,70 +224,62 @@ private static String escapeXml( String text ) private static final String crlf_str = "\r\n"; - private static final Pattern crlf = Pattern.compile( crlf_str ); + private static final Pattern crlf = Pattern.compile(crlf_str); - private static final Pattern lowers = Pattern.compile( "([\000-\037])" ); + private static final Pattern lowers = Pattern.compile("([\000-\037])"); - private static String escapeXmlAttribute( String text ) - { - text = escapeXml( text ); + private static String escapeXmlAttribute(String text) { + text = escapeXml(text); // Windows - Matcher crlfmatcher = crlf.matcher( text ); - if ( text.contains( crlf_str ) ) - { - text = crlfmatcher.replaceAll( " " ); + Matcher crlfmatcher = crlf.matcher(text); + if (text.contains(crlf_str)) { + text = crlfmatcher.replaceAll(" "); } - Matcher m = lowers.matcher( text ); + Matcher m = lowers.matcher(text); StringBuffer b = new StringBuffer(); - while ( m.find() ) - { - m = m.appendReplacement( b, "&#" + Integer.toString( m.group( 1 ).charAt( 0 ) ) + ";" ); + while (m.find()) { + m = m.appendReplacement(b, "&#" + Integer.toString(m.group(1).charAt(0)) + ";"); } - m.appendTail( b ); + m.appendTail(b); return b.toString(); } /** {@inheritDoc} */ @Override - public void addAttribute( String key, String value ) - { - write( " " ); + public void addAttribute(String key, String value) { + write(" "); - write( key ); + write(key); - write( "=\"" ); + write("=\""); - write( escapeXmlAttribute( value ) ); + write(escapeXmlAttribute(value)); - write( "\"" ); + write("\""); } /** {@inheritDoc} */ @Override - public void endElement() - { - setDepth( getDepth() - 1 ); + public void endElement() { + setDepth(getDepth() - 1); - if ( tagIsEmpty ) - { - write( "/" ); + if (tagIsEmpty) { + write("/"); readyForNewLine = false; finishTag(); elementStack.removeLast(); - } - else - { + } else { finishTag(); - write( "" ); + write(""); } readyForNewLine = true; @@ -319,25 +287,21 @@ public void endElement() /** * Write a string to the underlying writer - * + * * @param str */ - private void write( String str ) - { - getWriter().write( str ); + private void write(String str) { + getWriter().write(str); } - private void finishTag() - { - if ( tagInProgress ) - { - write( ">" ); + private void finishTag() { + if (tagInProgress) { + write(">"); } tagInProgress = false; - if ( readyForNewLine ) - { + if (readyForNewLine) { endOfLine(); } readyForNewLine = false; @@ -350,8 +314,7 @@ private void finishTag() * * @return the line indenter */ - protected String getLineIndenter() - { + protected String getLineIndenter() { return lineIndenter; } @@ -360,8 +323,7 @@ protected String getLineIndenter() * * @param lineIndenter new line indenter, could be null, but the normal way is some spaces. */ - protected void setLineIndenter( String lineIndenter ) - { + protected void setLineIndenter(String lineIndenter) { this.lineIndenter = lineIndenter; } @@ -371,8 +333,7 @@ protected void setLineIndenter( String lineIndenter ) * @return the line separator * @see #LS */ - protected String getLineSeparator() - { + protected String getLineSeparator() { return lineSeparator; } @@ -381,8 +342,7 @@ protected String getLineSeparator() * * @param lineSeparator new line separator, could be null but the normal way is valid line separator ("\n" on UNIX). */ - protected void setLineSeparator( String lineSeparator ) - { + protected void setLineSeparator(String lineSeparator) { this.lineSeparator = lineSeparator; } @@ -392,36 +352,31 @@ protected void setLineSeparator( String lineSeparator ) * @see #getLineIndenter() * @see #getLineSeparator() */ - protected void endOfLine() - { - write( getLineSeparator() ); + protected void endOfLine() { + write(getLineSeparator()); - for ( int i = 0; i < getDepth(); i++ ) - { - write( getLineIndenter() ); + for (int i = 0; i < getDepth(); i++) { + write(getLineIndenter()); } } - private void writeDocumentHeaders() - { - write( "" ); + write("?>"); endOfLine(); - if ( getDocType() != null ) - { - write( "" ); + write(">"); endOfLine(); } @@ -432,11 +387,9 @@ private void writeDocumentHeaders() * * @param writer not null writer */ - protected void setWriter( PrintWriter writer ) - { - if ( writer == null ) - { - throw new IllegalArgumentException( "writer could not be null" ); + protected void setWriter(PrintWriter writer) { + if (writer == null) { + throw new IllegalArgumentException("writer could not be null"); } this.writer = writer; @@ -447,8 +400,7 @@ protected void setWriter( PrintWriter writer ) * * @return the underlying writer */ - protected PrintWriter getWriter() - { + protected PrintWriter getWriter() { return writer; } @@ -457,8 +409,7 @@ protected PrintWriter getWriter() * * @param depth new depth */ - protected void setDepth( int depth ) - { + protected void setDepth(int depth) { this.depth = depth; } @@ -467,8 +418,7 @@ protected void setDepth( int depth ) * * @return the current depth */ - protected int getDepth() - { + protected int getDepth() { return depth; } @@ -477,8 +427,7 @@ protected int getDepth() * * @param encoding new encoding */ - protected void setEncoding( String encoding ) - { + protected void setEncoding(String encoding) { this.encoding = encoding; } @@ -487,8 +436,7 @@ protected void setEncoding( String encoding ) * * @return the current encoding */ - protected String getEncoding() - { + protected String getEncoding() { return encoding; } @@ -497,8 +445,7 @@ protected String getEncoding() * * @param docType new docType */ - protected void setDocType( String docType ) - { + protected void setDocType(String docType) { this.docType = docType; } @@ -507,16 +454,14 @@ protected void setDocType( String docType ) * * @return the current docType */ - protected String getDocType() - { + protected String getDocType() { return docType; } /** * @return the current elementStack; */ - protected Deque getElementStack() - { + protected Deque getElementStack() { return elementStack; } } diff --git a/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java b/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java index 488103d4..6309b165 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java @@ -16,23 +16,21 @@ * limitations under the License. */ -import org.codehaus.plexus.util.xml.pull.XmlSerializer; - import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Stack; +import org.codehaus.plexus.util.xml.pull.XmlSerializer; + /** * Write to an MXSerializer. * * @author Brett Porter * */ -public class SerializerXMLWriter - implements XMLWriter -{ +public class SerializerXMLWriter implements XMLWriter { private final XmlSerializer serializer; private final String namespace; @@ -41,93 +39,68 @@ public class SerializerXMLWriter private List exceptions; - public SerializerXMLWriter( String namespace, XmlSerializer serializer ) - { + public SerializerXMLWriter(String namespace, XmlSerializer serializer) { this.serializer = serializer; this.namespace = namespace; } @Override - public void startElement( String name ) - { - try - { - serializer.startTag( namespace, name ); - elements.push( name ); - } - catch ( IOException e ) - { - storeException( e ); + public void startElement(String name) { + try { + serializer.startTag(namespace, name); + elements.push(name); + } catch (IOException e) { + storeException(e); } } @Override - public void addAttribute( String key, String value ) - { - try - { - serializer.attribute( namespace, key, value ); - } - catch ( IOException e ) - { - storeException( e ); + public void addAttribute(String key, String value) { + try { + serializer.attribute(namespace, key, value); + } catch (IOException e) { + storeException(e); } } @Override - public void writeText( String text ) - { - try - { - serializer.text( text ); - } - catch ( IOException e ) - { - storeException( e ); + public void writeText(String text) { + try { + serializer.text(text); + } catch (IOException e) { + storeException(e); } } @Override - public void writeMarkup( String text ) - { - try - { - serializer.cdsect( text ); - } - catch ( IOException e ) - { - storeException( e ); + public void writeMarkup(String text) { + try { + serializer.cdsect(text); + } catch (IOException e) { + storeException(e); } } @Override - public void endElement() - { - try - { - serializer.endTag( namespace, elements.pop() ); - } - catch ( IOException e ) - { - storeException( e ); + public void endElement() { + try { + serializer.endTag(namespace, elements.pop()); + } catch (IOException e) { + storeException(e); } } /** * @todo Maybe the interface should allow IOExceptions on each? */ - private void storeException( IOException e ) - { - if ( exceptions == null ) - { + private void storeException(IOException e) { + if (exceptions == null) { exceptions = new ArrayList(); } - exceptions.add( e ); + exceptions.add(e); } - public List getExceptions() - { + public List getExceptions() { return exceptions == null ? Collections.emptyList() : exceptions; } - } diff --git a/src/main/java/org/codehaus/plexus/util/xml/StringUtils.java b/src/main/java/org/codehaus/plexus/util/xml/StringUtils.java index 8a4f1944..0e851f27 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/StringUtils.java +++ b/src/main/java/org/codehaus/plexus/util/xml/StringUtils.java @@ -77,8 +77,7 @@ * @since 1.0 * */ -class StringUtils -{ +class StringUtils { /** *

* StringUtils instances should NOT be constructed in standard programming. Instead, the class should @@ -88,9 +87,7 @@ class StringUtils * This constructor is public to permit tools that require a JavaBean manager to operate. *

*/ - private StringUtils() - { - } + private StringUtils() {} /** * Checks if a String is null or empty. @@ -102,9 +99,8 @@ private StringUtils() * @param str the String to check * @return true if the String is null, or length zero */ - public static boolean isEmpty( String str ) - { - return ( ( str == null ) || ( str.isEmpty() ) ); + public static boolean isEmpty(String str) { + return ((str == null) || (str.isEmpty())); } // Splitting @@ -115,9 +111,8 @@ public static boolean isEmpty( String str ) * @param separator Characters used as the delimiters. If null, splits on whitespace. * @return an array of parsed Strings */ - public static String[] split( String text, String separator ) - { - return split( text, separator, -1 ); + public static String[] split(String text, String separator) { + return split(text, separator, -1); } /** @@ -138,23 +133,18 @@ public static String[] split( String text, String separator ) * @param max The maximum number of elements to include in the array. A zero or negative value implies no limit. * @return an array of parsed Strings */ - private static String[] split( String str, String separator, int max ) - { + private static String[] split(String str, String separator, int max) { StringTokenizer tok; - if ( separator == null ) - { + if (separator == null) { // Null separator means we're using StringTokenizer's default // delimiter, which comprises all whitespace characters. - tok = new StringTokenizer( str ); - } - else - { - tok = new StringTokenizer( str, separator ); + tok = new StringTokenizer(str); + } else { + tok = new StringTokenizer(str, separator); } int listSize = tok.countTokens(); - if ( ( max > 0 ) && ( listSize > max ) ) - { + if ((max > 0) && (listSize > max)) { listSize = max; } @@ -162,22 +152,18 @@ private static String[] split( String str, String separator, int max ) int i = 0; int lastTokenBegin; int lastTokenEnd = 0; - while ( tok.hasMoreTokens() ) - { - if ( ( max > 0 ) && ( i == listSize - 1 ) ) - { + while (tok.hasMoreTokens()) { + if ((max > 0) && (i == listSize - 1)) { // In the situation where we hit the max yet have // tokens left over in our input, the last list // element gets all remaining text. String endToken = tok.nextToken(); - lastTokenBegin = str.indexOf( endToken, lastTokenEnd ); - list[i] = str.substring( lastTokenBegin ); + lastTokenBegin = str.indexOf(endToken, lastTokenEnd); + list[i] = str.substring(lastTokenBegin); break; - } - else - { + } else { list[i] = tok.nextToken(); - lastTokenBegin = str.indexOf( list[i], lastTokenEnd ); + lastTokenBegin = str.indexOf(list[i], lastTokenEnd); lastTokenEnd = lastTokenBegin + list[i].length(); } i++; @@ -196,12 +182,10 @@ private static String[] split( String str, String separator, int max ) * @throws NegativeArraySizeException if repeat < 0 * @throws NullPointerException if str is null */ - public static String repeat( String str, int repeat ) - { - StringBuilder buffer = new StringBuilder( repeat * str.length() ); - for ( int i = 0; i < repeat; i++ ) - { - buffer.append( str ); + public static String repeat(String str, int repeat) { + StringBuilder buffer = new StringBuilder(repeat * str.length()); + for (int i = 0; i < repeat; i++) { + buffer.append(str); } return buffer.toString(); } @@ -213,18 +197,15 @@ public static String repeat( String str, int repeat ) * @return a string with unique whitespace. * @since 1.5.7 */ - public static String removeDuplicateWhitespace( String s ) - { + public static String removeDuplicateWhitespace(String s) { StringBuilder result = new StringBuilder(); int length = s.length(); boolean isPreviousWhiteSpace = false; - for ( int i = 0; i < length; i++ ) - { - char c = s.charAt( i ); - boolean thisCharWhiteSpace = Character.isWhitespace( c ); - if ( !( isPreviousWhiteSpace && thisCharWhiteSpace ) ) - { - result.append( c ); + for (int i = 0; i < length; i++) { + char c = s.charAt(i); + boolean thisCharWhiteSpace = Character.isWhitespace(c); + if (!(isPreviousWhiteSpace && thisCharWhiteSpace)) { + result.append(c); } isPreviousWhiteSpace = thisCharWhiteSpace; } @@ -240,44 +221,33 @@ public static String removeDuplicateWhitespace( String s ) * @throws IllegalArgumentException if ls is not '\n', '\r' and '\r\n' characters. * @since 1.5.7 */ - public static String unifyLineSeparators( String s, String ls ) - { - if ( s == null ) - { + public static String unifyLineSeparators(String s, String ls) { + if (s == null) { return null; } - if ( ls == null ) - { - ls = System.getProperty( "line.separator" ); + if (ls == null) { + ls = System.getProperty("line.separator"); } - if ( !( ls.equals( "\n" ) || ls.equals( "\r" ) || ls.equals( "\r\n" ) ) ) - { - throw new IllegalArgumentException( "Requested line separator is invalid." ); + if (!(ls.equals("\n") || ls.equals("\r") || ls.equals("\r\n"))) { + throw new IllegalArgumentException("Requested line separator is invalid."); } int length = s.length(); - StringBuilder buffer = new StringBuilder( length ); - for ( int i = 0; i < length; i++ ) - { - if ( s.charAt( i ) == '\r' ) - { - if ( ( i + 1 ) < length && s.charAt( i + 1 ) == '\n' ) - { + StringBuilder buffer = new StringBuilder(length); + for (int i = 0; i < length; i++) { + if (s.charAt(i) == '\r') { + if ((i + 1) < length && s.charAt(i + 1) == '\n') { i++; } - buffer.append( ls ); - } - else if ( s.charAt( i ) == '\n' ) - { - buffer.append( ls ); - } - else - { - buffer.append( s.charAt( i ) ); + buffer.append(ls); + } else if (s.charAt(i) == '\n') { + buffer.append(ls); + } else { + buffer.append(s.charAt(i)); } } diff --git a/src/main/java/org/codehaus/plexus/util/xml/XMLWriter.java b/src/main/java/org/codehaus/plexus/util/xml/XMLWriter.java index 364849ba..c8bcbc2b 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XMLWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XMLWriter.java @@ -19,16 +19,14 @@ /** * */ -public interface XMLWriter -{ - void startElement( String name ); +public interface XMLWriter { + void startElement(String name); - void addAttribute( String key, String value ); + void addAttribute(String key, String value); - void writeText( String text ); + void writeText(String text); - void writeMarkup( String text ); + void writeMarkup(String text); void endElement(); - } diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java b/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java index 8ac13cab..f2a03161 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java @@ -24,29 +24,29 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; +import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; -import java.net.HttpURLConnection; import java.nio.file.Path; +import java.text.MessageFormat; import java.util.Locale; -import java.util.regex.Pattern; import java.util.regex.Matcher; -import java.text.MessageFormat; +import java.util.regex.Pattern; /** *

Character stream that handles (or at least attempts to) all the necessary Voodo to figure out the charset encoding of * the XML document within the stream.

- * + * *

IMPORTANT: This class is not related in any way to the org.xml.sax.XMLReader. This one IS a character stream.

- * + * *

All this has to be done without consuming characters from the stream, if not the XML parser will not recognized the * document as a valid XML. This is not 100% true, but it's close enough (UTF-8 BOM is not handled by all parsers right * now, XmlReader handles it and things work in all parsers).

- * + * *

The XmlReader class handles the charset encoding of XML documents in Files, raw streams and HTTP streams by offering * a wide set of constructors.

- * + * *

By default the charset encoding detection is lenient, the constructor with the lenient flag can be used for an script * (following HTTP MIME and XML specifications). All this is nicely explained by Mark Pilgrim in his blog, * Determining the character encoding of a @@ -59,9 +59,7 @@ * @since 1.4.3 */ @Deprecated -public class XmlReader - extends Reader -{ +public class XmlReader extends Reader { private static final int BUFFER_SIZE = 4096; private static final String UTF_8 = "UTF-8"; @@ -87,28 +85,26 @@ public class XmlReader /** *

Sets the default encoding to use if none is set in HTTP content-type, XML prolog and the rules based on * content-type are not adequate.

- * + * *

If it is set to NULL the content-type based rules are used.

- * + * *

By default it is NULL.

* * @param encoding charset encoding to default to. */ - public static void setDefaultEncoding( String encoding ) - { + public static void setDefaultEncoding(String encoding) { _staticDefaultEncoding = encoding; } /** *

Returns the default encoding to use if none is set in HTTP content-type, XML prolog and the rules based on * content-type are not adequate.

- * + * *

If it is NULL the content-type based rules are used.

* * @return the default encoding to use. */ - public static String getDefaultEncoding() - { + public static String getDefaultEncoding() { return _staticDefaultEncoding; } @@ -124,10 +120,8 @@ public static String getDefaultEncoding() * @param path Path to create a Reader from. * @throws IOException thrown if there is a problem reading the file. */ - public XmlReader( Path path ) - throws IOException - { - this( Files.newInputStream( path ) ); + public XmlReader(Path path) throws IOException { + this(Files.newInputStream(path)); } /** @@ -142,10 +136,8 @@ public XmlReader( Path path ) * @param file File to create a Reader from. * @throws IOException thrown if there is a problem reading the file. */ - public XmlReader( File file ) - throws IOException - { - this( file.toPath() ); + public XmlReader(File file) throws IOException { + this(file.toPath()); } /** @@ -159,10 +151,8 @@ public XmlReader( File file ) * @param is InputStream to create a Reader from. * @throws IOException thrown if there is a problem reading the stream. */ - public XmlReader( InputStream is ) - throws IOException - { - this( is, true ); + public XmlReader(InputStream is) throws IOException { + this(is, true); } /** @@ -189,23 +179,15 @@ public XmlReader( InputStream is ) * @throws IOException thrown if there is a problem reading the stream. * @throws XmlStreamReaderException thrown if the charset encoding could not be determined according to the specs. */ - public XmlReader( InputStream is, boolean lenient ) - throws IOException, XmlStreamReaderException - { + public XmlReader(InputStream is, boolean lenient) throws IOException, XmlStreamReaderException { _defaultEncoding = _staticDefaultEncoding; - try - { - doRawStream( is, lenient ); - } - catch ( XmlStreamReaderException ex ) - { - if ( !lenient ) - { + try { + doRawStream(is, lenient); + } catch (XmlStreamReaderException ex) { + if (!lenient) { throw ex; - } - else - { - doLenientDetection( null, ex ); + } else { + doLenientDetection(null, ex); } } } @@ -225,10 +207,8 @@ public XmlReader( InputStream is, boolean lenient ) * @param url URL to create a Reader from. * @throws IOException thrown if there is a problem reading the stream of the URL. */ - public XmlReader( URL url ) - throws IOException - { - this( url.openConnection() ); + public XmlReader(URL url) throws IOException { + this(url.openConnection()); } /** @@ -246,42 +226,26 @@ public XmlReader( URL url ) * @param conn URLConnection to create a Reader from. * @throws IOException thrown if there is a problem reading the stream of the URLConnection. */ - public XmlReader( URLConnection conn ) - throws IOException - { + public XmlReader(URLConnection conn) throws IOException { _defaultEncoding = _staticDefaultEncoding; boolean lenient = true; - if ( conn instanceof HttpURLConnection ) - { - try - { - doHttpStream( conn.getInputStream(), conn.getContentType(), lenient ); - } - catch ( XmlStreamReaderException ex ) - { - doLenientDetection( conn.getContentType(), ex ); + if (conn instanceof HttpURLConnection) { + try { + doHttpStream(conn.getInputStream(), conn.getContentType(), lenient); + } catch (XmlStreamReaderException ex) { + doLenientDetection(conn.getContentType(), ex); } - } - else if ( conn.getContentType() != null ) - { - try - { - doHttpStream( conn.getInputStream(), conn.getContentType(), lenient ); + } else if (conn.getContentType() != null) { + try { + doHttpStream(conn.getInputStream(), conn.getContentType(), lenient); + } catch (XmlStreamReaderException ex) { + doLenientDetection(conn.getContentType(), ex); } - catch ( XmlStreamReaderException ex ) - { - doLenientDetection( conn.getContentType(), ex ); - } - } - else - { - try - { - doRawStream( conn.getInputStream(), lenient ); - } - catch ( XmlStreamReaderException ex ) - { - doLenientDetection( null, ex ); + } else { + try { + doRawStream(conn.getInputStream(), lenient); + } catch (XmlStreamReaderException ex) { + doLenientDetection(null, ex); } } } @@ -300,10 +264,8 @@ else if ( conn.getContentType() != null ) * @param httpContentType content-type header to use for the resolution of the charset encoding. * @throws IOException thrown if there is a problem reading the file. */ - public XmlReader( InputStream is, String httpContentType ) - throws IOException - { - this( is, httpContentType, true ); + public XmlReader(InputStream is, String httpContentType) throws IOException { + this(is, httpContentType, true); } /** @@ -335,23 +297,16 @@ public XmlReader( InputStream is, String httpContentType ) * @throws IOException thrown if there is a problem reading the file. * @throws XmlStreamReaderException thrown if the charset encoding could not be determined according to the specs. */ - public XmlReader( InputStream is, String httpContentType, boolean lenient, String defaultEncoding ) - throws IOException, XmlStreamReaderException - { - _defaultEncoding = ( defaultEncoding == null ) ? _staticDefaultEncoding : defaultEncoding; - try - { - doHttpStream( is, httpContentType, lenient ); - } - catch ( XmlStreamReaderException ex ) - { - if ( !lenient ) - { + public XmlReader(InputStream is, String httpContentType, boolean lenient, String defaultEncoding) + throws IOException, XmlStreamReaderException { + _defaultEncoding = (defaultEncoding == null) ? _staticDefaultEncoding : defaultEncoding; + try { + doHttpStream(is, httpContentType, lenient); + } catch (XmlStreamReaderException ex) { + if (!lenient) { throw ex; - } - else - { - doLenientDetection( httpContentType, ex ); + } else { + doLenientDetection(httpContentType, ex); } } } @@ -384,44 +339,33 @@ public XmlReader( InputStream is, String httpContentType, boolean lenient, Strin * @throws IOException thrown if there is a problem reading the file. * @throws XmlStreamReaderException thrown if the charset encoding could not be determined according to the specs. */ - public XmlReader( InputStream is, String httpContentType, boolean lenient ) - throws IOException, XmlStreamReaderException - { - this( is, httpContentType, lenient, null ); + public XmlReader(InputStream is, String httpContentType, boolean lenient) + throws IOException, XmlStreamReaderException { + this(is, httpContentType, lenient, null); } - private void doLenientDetection( String httpContentType, XmlStreamReaderException ex ) - throws IOException - { - if ( httpContentType != null ) - { - if ( httpContentType.startsWith( "text/html" ) ) - { - httpContentType = httpContentType.substring( "text/html".length() ); + private void doLenientDetection(String httpContentType, XmlStreamReaderException ex) throws IOException { + if (httpContentType != null) { + if (httpContentType.startsWith("text/html")) { + httpContentType = httpContentType.substring("text/html".length()); httpContentType = "text/xml" + httpContentType; - try - { - doHttpStream( ex.getInputStream(), httpContentType, true ); + try { + doHttpStream(ex.getInputStream(), httpContentType, true); ex = null; - } - catch ( XmlStreamReaderException ex2 ) - { + } catch (XmlStreamReaderException ex2) { ex = ex2; } } } - if ( ex != null ) - { + if (ex != null) { String encoding = ex.getXmlEncoding(); - if ( encoding == null ) - { + if (encoding == null) { encoding = ex.getContentTypeEncoding(); } - if ( encoding == null ) - { - encoding = ( _defaultEncoding == null ) ? UTF_8 : _defaultEncoding; + if (encoding == null) { + encoding = (_defaultEncoding == null) ? UTF_8 : _defaultEncoding; } - prepareReader( ex.getInputStream(), encoding ); + prepareReader(ex.getInputStream(), encoding); } } @@ -431,16 +375,13 @@ private void doLenientDetection( String httpContentType, XmlStreamReaderExceptio * * @return charset encoding. */ - public String getEncoding() - { + public String getEncoding() { return _encoding; } @Override - public int read( char[] buf, int offset, int len ) - throws IOException - { - return _reader.read( buf, offset, len ); + public int read(char[] buf, int offset, int len) throws IOException { + return _reader.read(buf, offset, len); } /** @@ -450,180 +391,155 @@ public int read( char[] buf, int offset, int len ) * @throws IOException thrown if there was a problem closing the stream. */ @Override - public void close() - throws IOException - { + public void close() throws IOException { _reader.close(); } - private void doRawStream( InputStream is, boolean lenient ) - throws IOException - { - BufferedInputStream pis = new BufferedInputStream( is, BUFFER_SIZE ); - String bomEnc = getBOMEncoding( pis ); - String xmlGuessEnc = getXMLGuessEncoding( pis ); - String xmlEnc = getXmlProlog( pis, xmlGuessEnc ); - String encoding = calculateRawEncoding( bomEnc, xmlGuessEnc, xmlEnc, pis ); - prepareReader( pis, encoding ); + private void doRawStream(InputStream is, boolean lenient) throws IOException { + BufferedInputStream pis = new BufferedInputStream(is, BUFFER_SIZE); + String bomEnc = getBOMEncoding(pis); + String xmlGuessEnc = getXMLGuessEncoding(pis); + String xmlEnc = getXmlProlog(pis, xmlGuessEnc); + String encoding = calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, pis); + prepareReader(pis, encoding); } - private void doHttpStream( InputStream is, String httpContentType, boolean lenient ) - throws IOException - { - BufferedInputStream pis = new BufferedInputStream( is, BUFFER_SIZE ); - String cTMime = getContentTypeMime( httpContentType ); - String cTEnc = getContentTypeEncoding( httpContentType ); - String bomEnc = getBOMEncoding( pis ); - String xmlGuessEnc = getXMLGuessEncoding( pis ); - String xmlEnc = getXmlProlog( pis, xmlGuessEnc ); - String encoding = calculateHttpEncoding( cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, pis, lenient ); - prepareReader( pis, encoding ); + private void doHttpStream(InputStream is, String httpContentType, boolean lenient) throws IOException { + BufferedInputStream pis = new BufferedInputStream(is, BUFFER_SIZE); + String cTMime = getContentTypeMime(httpContentType); + String cTEnc = getContentTypeEncoding(httpContentType); + String bomEnc = getBOMEncoding(pis); + String xmlGuessEnc = getXMLGuessEncoding(pis); + String xmlEnc = getXmlProlog(pis, xmlGuessEnc); + String encoding = calculateHttpEncoding(cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, pis, lenient); + prepareReader(pis, encoding); } - private void prepareReader( InputStream is, String encoding ) - throws IOException - { - _reader = new InputStreamReader( is, encoding ); + private void prepareReader(InputStream is, String encoding) throws IOException { + _reader = new InputStreamReader(is, encoding); _encoding = encoding; } // InputStream is passed for XmlStreamReaderException creation only - private String calculateRawEncoding( String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) - throws IOException - { + private String calculateRawEncoding(String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is) + throws IOException { String encoding; - if ( bomEnc == null ) - { - if ( xmlGuessEnc == null || xmlEnc == null ) - { - encoding = ( _defaultEncoding == null ) ? UTF_8 : _defaultEncoding; - } - else if ( xmlEnc.equals( UTF_16 ) && ( xmlGuessEnc.equals( UTF_16BE ) || xmlGuessEnc.equals( UTF_16LE ) ) ) - { + if (bomEnc == null) { + if (xmlGuessEnc == null || xmlEnc == null) { + encoding = (_defaultEncoding == null) ? UTF_8 : _defaultEncoding; + } else if (xmlEnc.equals(UTF_16) && (xmlGuessEnc.equals(UTF_16BE) || xmlGuessEnc.equals(UTF_16LE))) { encoding = xmlGuessEnc; - } - else - { + } else { encoding = xmlEnc; } - } - else if ( bomEnc.equals( UTF_8 ) ) - { - if ( xmlGuessEnc != null && !xmlGuessEnc.equals( UTF_8 ) ) - { - throw new XmlStreamReaderException( RAW_EX_1.format( new Object[] { bomEnc, xmlGuessEnc, xmlEnc } ), - bomEnc, xmlGuessEnc, xmlEnc, is ); + } else if (bomEnc.equals(UTF_8)) { + if (xmlGuessEnc != null && !xmlGuessEnc.equals(UTF_8)) { + throw new XmlStreamReaderException( + RAW_EX_1.format(new Object[] {bomEnc, xmlGuessEnc, xmlEnc}), bomEnc, xmlGuessEnc, xmlEnc, is); } - if ( xmlEnc != null && !xmlEnc.equals( UTF_8 ) ) - { - throw new XmlStreamReaderException( RAW_EX_1.format( new Object[] { bomEnc, xmlGuessEnc, xmlEnc } ), - bomEnc, xmlGuessEnc, xmlEnc, is ); + if (xmlEnc != null && !xmlEnc.equals(UTF_8)) { + throw new XmlStreamReaderException( + RAW_EX_1.format(new Object[] {bomEnc, xmlGuessEnc, xmlEnc}), bomEnc, xmlGuessEnc, xmlEnc, is); } encoding = UTF_8; - } - else if ( bomEnc.equals( UTF_16BE ) || bomEnc.equals( UTF_16LE ) ) - { - if ( xmlGuessEnc != null && !xmlGuessEnc.equals( bomEnc ) - || xmlEnc != null && !xmlEnc.equals( UTF_16 ) && !xmlEnc.equals( bomEnc ) ) - { - throw new XmlStreamReaderException( RAW_EX_1.format( new Object[] { bomEnc, xmlGuessEnc, xmlEnc } ), - bomEnc, xmlGuessEnc, xmlEnc, is ); + } else if (bomEnc.equals(UTF_16BE) || bomEnc.equals(UTF_16LE)) { + if (xmlGuessEnc != null && !xmlGuessEnc.equals(bomEnc) + || xmlEnc != null && !xmlEnc.equals(UTF_16) && !xmlEnc.equals(bomEnc)) { + throw new XmlStreamReaderException( + RAW_EX_1.format(new Object[] {bomEnc, xmlGuessEnc, xmlEnc}), bomEnc, xmlGuessEnc, xmlEnc, is); } encoding = bomEnc; - } - else - { - throw new XmlStreamReaderException( RAW_EX_2.format( new Object[] { bomEnc, xmlGuessEnc, xmlEnc } ), bomEnc, - xmlGuessEnc, xmlEnc, is ); + } else { + throw new XmlStreamReaderException( + RAW_EX_2.format(new Object[] {bomEnc, xmlGuessEnc, xmlEnc}), bomEnc, xmlGuessEnc, xmlEnc, is); } return encoding; } // InputStream is passed for XmlStreamReaderException creation only - private String calculateHttpEncoding( String cTMime, String cTEnc, String bomEnc, String xmlGuessEnc, String xmlEnc, - InputStream is, boolean lenient ) - throws IOException - { + private String calculateHttpEncoding( + String cTMime, + String cTEnc, + String bomEnc, + String xmlGuessEnc, + String xmlEnc, + InputStream is, + boolean lenient) + throws IOException { String encoding; - if ( lenient & xmlEnc != null ) - { + if (lenient & xmlEnc != null) { encoding = xmlEnc; - } - else - { - boolean appXml = isAppXml( cTMime ); - boolean textXml = isTextXml( cTMime ); - if ( appXml || textXml ) - { - if ( cTEnc == null ) - { - if ( appXml ) - { - encoding = calculateRawEncoding( bomEnc, xmlGuessEnc, xmlEnc, is ); - } - else - { - encoding = ( _defaultEncoding == null ) ? US_ASCII : _defaultEncoding; + } else { + boolean appXml = isAppXml(cTMime); + boolean textXml = isTextXml(cTMime); + if (appXml || textXml) { + if (cTEnc == null) { + if (appXml) { + encoding = calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, is); + } else { + encoding = (_defaultEncoding == null) ? US_ASCII : _defaultEncoding; } - } - else if ( bomEnc != null && ( cTEnc.equals( UTF_16BE ) || cTEnc.equals( UTF_16LE ) ) ) - { - throw new XmlStreamReaderException( HTTP_EX_1.format( new Object[] { cTMime, cTEnc, bomEnc, - xmlGuessEnc, xmlEnc } ), cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, is ); - } - else if ( cTEnc.equals( UTF_16 ) ) - { - if ( bomEnc != null && bomEnc.startsWith( UTF_16 ) ) - { + } else if (bomEnc != null && (cTEnc.equals(UTF_16BE) || cTEnc.equals(UTF_16LE))) { + throw new XmlStreamReaderException( + HTTP_EX_1.format(new Object[] {cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc}), + cTMime, + cTEnc, + bomEnc, + xmlGuessEnc, + xmlEnc, + is); + } else if (cTEnc.equals(UTF_16)) { + if (bomEnc != null && bomEnc.startsWith(UTF_16)) { encoding = bomEnc; + } else { + throw new XmlStreamReaderException( + HTTP_EX_2.format(new Object[] {cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc}), + cTMime, + cTEnc, + bomEnc, + xmlGuessEnc, + xmlEnc, + is); } - else - { - throw new XmlStreamReaderException( HTTP_EX_2.format( new Object[] { cTMime, cTEnc, bomEnc, - xmlGuessEnc, xmlEnc } ), cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, is ); - } - } - else - { + } else { encoding = cTEnc; } - } - else - { - throw new XmlStreamReaderException( HTTP_EX_3.format( new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, - xmlEnc } ), cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, is ); + } else { + throw new XmlStreamReaderException( + HTTP_EX_3.format(new Object[] {cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc}), + cTMime, + cTEnc, + bomEnc, + xmlGuessEnc, + xmlEnc, + is); } } return encoding; } // returns MIME type or NULL if httpContentType is NULL - private static String getContentTypeMime( String httpContentType ) - { + private static String getContentTypeMime(String httpContentType) { String mime = null; - if ( httpContentType != null ) - { - int i = httpContentType.indexOf( ";" ); - mime = ( ( i == -1 ) ? httpContentType : httpContentType.substring( 0, i ) ).trim(); + if (httpContentType != null) { + int i = httpContentType.indexOf(";"); + mime = ((i == -1) ? httpContentType : httpContentType.substring(0, i)).trim(); } return mime; } - private static final Pattern CHARSET_PATTERN = Pattern.compile( "charset=([.[^; ]]*)" ); + private static final Pattern CHARSET_PATTERN = Pattern.compile("charset=([.[^; ]]*)"); // returns charset parameter value, NULL if not present, NULL if httpContentType is NULL - private static String getContentTypeEncoding( String httpContentType ) - { + private static String getContentTypeEncoding(String httpContentType) { String encoding = null; - if ( httpContentType != null ) - { - int i = httpContentType.indexOf( ";" ); - if ( i > -1 ) - { - String postMime = httpContentType.substring( i + 1 ); - Matcher m = CHARSET_PATTERN.matcher( postMime ); - encoding = ( m.find() ) ? m.group( 1 ) : null; - encoding = ( encoding != null ) ? encoding.toUpperCase( Locale.ENGLISH ) : null; + if (httpContentType != null) { + int i = httpContentType.indexOf(";"); + if (i > -1) { + String postMime = httpContentType.substring(i + 1); + Matcher m = CHARSET_PATTERN.matcher(postMime); + encoding = (m.find()) ? m.group(1) : null; + encoding = (encoding != null) ? encoding.toUpperCase(Locale.ENGLISH) : null; } } return encoding; @@ -631,127 +547,97 @@ private static String getContentTypeEncoding( String httpContentType ) // returns the BOM in the stream, NULL if not present, // if there was BOM the in the stream it is consumed - private static String getBOMEncoding( BufferedInputStream is ) - throws IOException - { + private static String getBOMEncoding(BufferedInputStream is) throws IOException { String encoding = null; int[] bytes = new int[3]; - is.mark( 3 ); + is.mark(3); bytes[0] = is.read(); bytes[1] = is.read(); bytes[2] = is.read(); - if ( bytes[0] == 0xFE && bytes[1] == 0xFF ) - { + if (bytes[0] == 0xFE && bytes[1] == 0xFF) { encoding = UTF_16BE; is.reset(); is.read(); is.read(); - } - else if ( bytes[0] == 0xFF && bytes[1] == 0xFE ) - { + } else if (bytes[0] == 0xFF && bytes[1] == 0xFE) { encoding = UTF_16LE; is.reset(); is.read(); is.read(); - } - else if ( bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF ) - { + } else if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) { encoding = UTF_8; - } - else - { + } else { is.reset(); } return encoding; } // returns the best guess for the encoding by looking the first bytes of the stream, ', NULL if none - private static String getXmlProlog( BufferedInputStream is, String guessedEnc ) - throws IOException - { + private static String getXmlProlog(BufferedInputStream is, String guessedEnc) throws IOException { String encoding = null; - if ( guessedEnc != null ) - { + if (guessedEnc != null) { byte[] bytes = new byte[BUFFER_SIZE]; - is.mark( BUFFER_SIZE ); + is.mark(BUFFER_SIZE); int offset = 0; int max = BUFFER_SIZE; - int c = is.read( bytes, offset, max ); + int c = is.read(bytes, offset, max); int firstGT = -1; String xmlProlog = null; - while ( c != -1 && firstGT == -1 && offset < BUFFER_SIZE ) - { + while (c != -1 && firstGT == -1 && offset < BUFFER_SIZE) { offset += c; max -= c; - c = is.read( bytes, offset, max ); - xmlProlog = new String( bytes, 0, offset, guessedEnc ); - firstGT = xmlProlog.indexOf( '>' ); + c = is.read(bytes, offset, max); + xmlProlog = new String(bytes, 0, offset, guessedEnc); + firstGT = xmlProlog.indexOf('>'); } - if ( firstGT == -1 ) - { - if ( c == -1 ) - { - throw new IOException( "Unexpected end of XML stream" ); - } - else - { - throw new IOException( "XML prolog or ROOT element not found on first " + offset + " bytes" ); + if (firstGT == -1) { + if (c == -1) { + throw new IOException("Unexpected end of XML stream"); + } else { + throw new IOException("XML prolog or ROOT element not found on first " + offset + " bytes"); } } int bytesRead = offset; - if ( bytesRead > 0 ) - { + if (bytesRead > 0) { is.reset(); - BufferedReader bReader = - new BufferedReader( new StringReader( xmlProlog.substring( 0, firstGT + 1 ) ) ); + BufferedReader bReader = new BufferedReader(new StringReader(xmlProlog.substring(0, firstGT + 1))); StringBuilder prolog = new StringBuilder(); String line = bReader.readLine(); - while ( line != null ) - { - prolog.append( line ); + while (line != null) { + prolog.append(line); line = bReader.readLine(); } - Matcher m = ENCODING_PATTERN.matcher( prolog ); - if ( m.find() ) - { - encoding = m.group( 1 ).toUpperCase( Locale.ENGLISH ); - encoding = encoding.substring( 1, encoding.length() - 1 ); + Matcher m = ENCODING_PATTERN.matcher(prolog); + if (m.find()) { + encoding = m.group(1).toUpperCase(Locale.ENGLISH); + encoding = encoding.substring(1, encoding.length() - 1); } } } @@ -759,33 +645,34 @@ private static String getXmlProlog( BufferedInputStream is, String guessedEnc ) } // indicates if the MIME type belongs to the APPLICATION XML family - private static boolean isAppXml( String mime ) - { - return mime != null && ( mime.equals( "application/xml" ) || mime.equals( "application/xml-dtd" ) - || mime.equals( "application/xml-external-parsed-entity" ) - || ( mime.startsWith( "application/" ) && mime.endsWith( "+xml" ) ) ); + private static boolean isAppXml(String mime) { + return mime != null + && (mime.equals("application/xml") + || mime.equals("application/xml-dtd") + || mime.equals("application/xml-external-parsed-entity") + || (mime.startsWith("application/") && mime.endsWith("+xml"))); } // indicates if the MIME type belongs to the TEXT XML family - private static boolean isTextXml( String mime ) - { - return mime != null && ( mime.equals( "text/xml" ) || mime.equals( "text/xml-external-parsed-entity" ) - || ( mime.startsWith( "text/" ) && mime.endsWith( "+xml" ) ) ); + private static boolean isTextXml(String mime) { + return mime != null + && (mime.equals("text/xml") + || mime.equals("text/xml-external-parsed-entity") + || (mime.startsWith("text/") && mime.endsWith("+xml"))); } private static final MessageFormat RAW_EX_1 = - new MessageFormat( "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch" ); + new MessageFormat("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch"); private static final MessageFormat RAW_EX_2 = - new MessageFormat( "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM" ); - - private static final MessageFormat HTTP_EX_1 = - new MessageFormat( "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL" ); + new MessageFormat("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM"); - private static final MessageFormat HTTP_EX_2 = - new MessageFormat( "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch" ); + private static final MessageFormat HTTP_EX_1 = new MessageFormat( + "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL"); - private static final MessageFormat HTTP_EX_3 = - new MessageFormat( "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], Invalid MIME" ); + private static final MessageFormat HTTP_EX_2 = new MessageFormat( + "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch"); + private static final MessageFormat HTTP_EX_3 = new MessageFormat( + "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], Invalid MIME"); } diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlReaderException.java b/src/main/java/org/codehaus/plexus/util/xml/XmlReaderException.java index 1e015506..5fb2dcab 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlReaderException.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlReaderException.java @@ -16,8 +16,8 @@ */ package org.codehaus.plexus.util.xml; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; /** * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding can not be determined @@ -31,9 +31,7 @@ * @version revision 1.1 taken on 26/06/2007 from Rome (see * https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java) */ -public class XmlReaderException - extends IOException -{ +public class XmlReaderException extends IOException { private String _bomEncoding; private String _xmlGuessEncoding; @@ -58,9 +56,8 @@ public class XmlReaderException * @param xmlEnc XML prolog encoding. * @param is the unconsumed InputStream. */ - public XmlReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) - { - this( msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is ); + public XmlReaderException(String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is) { + this(msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is); } /** @@ -77,10 +74,9 @@ public XmlReaderException( String msg, String bomEnc, String xmlGuessEnc, String * @param xmlEnc XML prolog encoding. * @param is the unconsumed InputStream. */ - public XmlReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, - String xmlEnc, InputStream is ) - { - super( msg ); + public XmlReaderException( + String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is) { + super(msg); _contentTypeMime = ctMime; _contentTypeEncoding = ctEnc; _bomEncoding = bomEnc; @@ -95,8 +91,7 @@ public XmlReaderException( String msg, String ctMime, String ctEnc, String bomEn * * @return the BOM encoding, null if none. */ - public String getBomEncoding() - { + public String getBomEncoding() { return _bomEncoding; } @@ -106,8 +101,7 @@ public String getBomEncoding() * * @return the encoding guess, null if it couldn't be guessed. */ - public String getXmlGuessEncoding() - { + public String getXmlGuessEncoding() { return _xmlGuessEncoding; } @@ -117,8 +111,7 @@ public String getXmlGuessEncoding() * * @return the encoding of the XML prolog, null if none. */ - public String getXmlEncoding() - { + public String getXmlEncoding() { return _xmlEncoding; } @@ -129,8 +122,7 @@ public String getXmlEncoding() * @return the MIME type in the content-type, null if there was not content-type or the encoding detection did not * involve HTTP. */ - public String getContentTypeMime() - { + public String getContentTypeMime() { return _contentTypeMime; } @@ -141,8 +133,7 @@ public String getContentTypeMime() * @return the encoding in the content-type, null if there was not content-type, no encoding in it or the encoding * detection did not involve HTTP. */ - public String getContentTypeEncoding() - { + public String getContentTypeEncoding() { return _contentTypeEncoding; } @@ -153,8 +144,7 @@ public String getContentTypeEncoding() * * @return the unconsumed InputStream. */ - public InputStream getInputStream() - { + public InputStream getInputStream() { return _is; } } diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java index 20eb1211..c81c64d3 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java @@ -41,15 +41,13 @@ *
Determining the character encoding of a * feed. *

- * + * * @author Alejandro Abdelnur * @version revision 1.17 taken on 26/06/2007 from Rome (see * https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReader.java) * @since 1.4.4 */ -public class XmlStreamReader - extends XmlReader -{ +public class XmlStreamReader extends XmlReader { /** * Creates a Reader for a Path. *

@@ -62,10 +60,8 @@ public class XmlStreamReader * @param path Path to create a Reader from. * @throws IOException thrown if there is a problem reading the file. */ - public XmlStreamReader( Path path ) - throws IOException - { - super( path ); + public XmlStreamReader(Path path) throws IOException { + super(path); } /** @@ -76,14 +72,12 @@ public XmlStreamReader( Path path ) *

* It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. *

- * + * * @param file File to create a Reader from. * @throws IOException thrown if there is a problem reading the file. */ - public XmlStreamReader( File file ) - throws IOException - { - this( file.toPath() ); + public XmlStreamReader(File file) throws IOException { + this(file.toPath()); } /** @@ -93,14 +87,12 @@ public XmlStreamReader( File file ) *

* It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. *

- * + * * @param is InputStream to create a Reader from. * @throws IOException thrown if there is a problem reading the stream. */ - public XmlStreamReader( InputStream is ) - throws IOException - { - super( is ); + public XmlStreamReader(InputStream is) throws IOException { + super(is); } /** @@ -121,16 +113,14 @@ public XmlStreamReader( InputStream is ) *

* If lenient detection is indicated an XmlStreamReaderException is never thrown. *

- * + * * @param is InputStream to create a Reader from. * @param lenient indicates if the charset encoding detection should be relaxed. * @throws IOException thrown if there is a problem reading the stream. * @throws XmlStreamReaderException thrown if the charset encoding could not be determined according to the specs. */ - public XmlStreamReader( InputStream is, boolean lenient ) - throws IOException, XmlStreamReaderException - { - super( is, lenient ); + public XmlStreamReader(InputStream is, boolean lenient) throws IOException, XmlStreamReaderException { + super(is, lenient); } /** @@ -144,14 +134,12 @@ public XmlStreamReader( InputStream is, boolean lenient ) *

* It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. *

- * + * * @param url URL to create a Reader from. * @throws IOException thrown if there is a problem reading the stream of the URL. */ - public XmlStreamReader( URL url ) - throws IOException - { - super( url ); + public XmlStreamReader(URL url) throws IOException { + super(url); } /** @@ -165,14 +153,12 @@ public XmlStreamReader( URL url ) *

* It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. *

- * + * * @param conn URLConnection to create a Reader from. * @throws IOException thrown if there is a problem reading the stream of the URLConnection. */ - public XmlStreamReader( URLConnection conn ) - throws IOException - { - super( conn ); + public XmlStreamReader(URLConnection conn) throws IOException { + super(conn); } /** @@ -184,15 +170,13 @@ public XmlStreamReader( URLConnection conn ) *

* It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. *

- * + * * @param is InputStream to create the reader from. * @param httpContentType content-type header to use for the resolution of the charset encoding. * @throws IOException thrown if there is a problem reading the file. */ - public XmlStreamReader( InputStream is, String httpContentType ) - throws IOException - { - super( is, httpContentType ); + public XmlStreamReader(InputStream is, String httpContentType) throws IOException { + super(is, httpContentType); } /** @@ -216,7 +200,7 @@ public XmlStreamReader( InputStream is, String httpContentType ) *

* If lenient detection is indicated an XmlStreamReaderException is never thrown. *

- * + * * @param is InputStream to create the reader from. * @param httpContentType content-type header to use for the resolution of the charset encoding. * @param lenient indicates if the charset encoding detection should be relaxed. @@ -224,10 +208,9 @@ public XmlStreamReader( InputStream is, String httpContentType ) * @throws IOException thrown if there is a problem reading the file. * @throws XmlStreamReaderException thrown if the charset encoding could not be determined according to the specs. */ - public XmlStreamReader( InputStream is, String httpContentType, boolean lenient, String defaultEncoding ) - throws IOException, XmlStreamReaderException - { - super( is, httpContentType, lenient, defaultEncoding ); + public XmlStreamReader(InputStream is, String httpContentType, boolean lenient, String defaultEncoding) + throws IOException, XmlStreamReaderException { + super(is, httpContentType, lenient, defaultEncoding); } /** @@ -251,16 +234,15 @@ public XmlStreamReader( InputStream is, String httpContentType, boolean lenient, *

* If lenient detection is indicated an XmlStreamReaderException is never thrown. *

- * + * * @param is InputStream to create the reader from. * @param httpContentType content-type header to use for the resolution of the charset encoding. * @param lenient indicates if the charset encoding detection should be relaxed. * @throws IOException thrown if there is a problem reading the file. * @throws XmlStreamReaderException thrown if the charset encoding could not be determined according to the specs. */ - public XmlStreamReader( InputStream is, String httpContentType, boolean lenient ) - throws IOException, XmlStreamReaderException - { - super( is, httpContentType, lenient ); + public XmlStreamReader(InputStream is, String httpContentType, boolean lenient) + throws IOException, XmlStreamReaderException { + super(is, httpContentType, lenient); } } diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReaderException.java b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReaderException.java index dc919981..1901c40c 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReaderException.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReaderException.java @@ -31,9 +31,7 @@ * @version revision 1.1 taken on 26/06/2007 from Rome (see * https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java) */ -public class XmlStreamReaderException - extends XmlReaderException -{ +public class XmlStreamReaderException extends XmlReaderException { /** * Creates an exception instance if the charset encoding could not be determined. *

@@ -46,9 +44,8 @@ public class XmlStreamReaderException * @param xmlEnc XML prolog encoding. * @param is the unconsumed InputStream. */ - public XmlStreamReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) - { - super( msg, bomEnc, xmlGuessEnc, xmlEnc, is ); + public XmlStreamReaderException(String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is) { + super(msg, bomEnc, xmlGuessEnc, xmlEnc, is); } /** @@ -65,9 +62,8 @@ public XmlStreamReaderException( String msg, String bomEnc, String xmlGuessEnc, * @param xmlEnc XML prolog encoding. * @param is the unconsumed InputStream. */ - public XmlStreamReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, - String xmlEnc, InputStream is ) - { - super( msg, ctMime, ctEnc, bomEnc, xmlGuessEnc, xmlEnc, is ); + public XmlStreamReaderException( + String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is) { + super(msg, ctMime, ctEnc, bomEnc, xmlGuessEnc, xmlEnc, is); } } diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java index 9b5f0a92..aec451aa 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java @@ -30,17 +30,15 @@ /** * Character stream that handles (or at least attempts to) all the necessary Voodo to figure out the charset encoding of * the XML document written to the stream. - * + * * @author Herve Boutemy * * @since 1.4.4 */ -public class XmlStreamWriter - extends Writer -{ +public class XmlStreamWriter extends Writer { private static final int BUFFER_SIZE = 4096; - private StringWriter xmlPrologWriter = new StringWriter( BUFFER_SIZE ); + private StringWriter xmlPrologWriter = new StringWriter(BUFFER_SIZE); private OutputStream out; @@ -48,117 +46,86 @@ public class XmlStreamWriter private String encoding; - public XmlStreamWriter( OutputStream out ) - { + public XmlStreamWriter(OutputStream out) { this.out = out; } - public XmlStreamWriter( File file ) - throws IOException - { - this( Files.newOutputStream( file.toPath() ) ); + public XmlStreamWriter(File file) throws IOException { + this(Files.newOutputStream(file.toPath())); } - public String getEncoding() - { + public String getEncoding() { return encoding; } @Override - public void close() - throws IOException - { - if ( writer == null ) - { + public void close() throws IOException { + if (writer == null) { encoding = "UTF-8"; - writer = new OutputStreamWriter( out, encoding ); - writer.write( xmlPrologWriter.toString() ); + writer = new OutputStreamWriter(out, encoding); + writer.write(xmlPrologWriter.toString()); } writer.close(); } @Override - public void flush() - throws IOException - { - if ( writer != null ) - { + public void flush() throws IOException { + if (writer != null) { writer.flush(); } } - private void detectEncoding( char[] cbuf, int off, int len ) - throws IOException - { + private void detectEncoding(char[] cbuf, int off, int len) throws IOException { int size = len; StringBuffer xmlProlog = xmlPrologWriter.getBuffer(); - if ( xmlProlog.length() + len > BUFFER_SIZE ) - { + if (xmlProlog.length() + len > BUFFER_SIZE) { size = BUFFER_SIZE - xmlProlog.length(); } - xmlPrologWriter.write( cbuf, off, size ); + xmlPrologWriter.write(cbuf, off, size); // try to determine encoding - if ( xmlProlog.length() >= 5 ) - { - if ( xmlProlog.substring( 0, 5 ).equals( "= 5) { + if (xmlProlog.substring(0, 5).equals("" ); - if ( xmlPrologEnd > 0 ) - { + int xmlPrologEnd = xmlProlog.indexOf("?>"); + if (xmlPrologEnd > 0) { // ok, full XML prolog written: let's extract encoding - Matcher m = ENCODING_PATTERN.matcher( xmlProlog.substring( 0, xmlPrologEnd ) ); - if ( m.find() ) - { - encoding = m.group( 1 ).toUpperCase( Locale.ENGLISH ); - encoding = encoding.substring( 1, encoding.length() - 1 ); - } - else - { + Matcher m = ENCODING_PATTERN.matcher(xmlProlog.substring(0, xmlPrologEnd)); + if (m.find()) { + encoding = m.group(1).toUpperCase(Locale.ENGLISH); + encoding = encoding.substring(1, encoding.length() - 1); + } else { // no encoding found in XML prolog: using default encoding encoding = "UTF-8"; } - } - else - { - if ( xmlProlog.length() >= BUFFER_SIZE ) - { + } else { + if (xmlProlog.length() >= BUFFER_SIZE) { // no encoding found in first characters: using default encoding encoding = "UTF-8"; } } - } - else - { + } else { // no XML prolog: using default encoding encoding = "UTF-8"; } - if ( encoding != null ) - { + if (encoding != null) { // encoding has been chosen: let's do it xmlPrologWriter = null; - writer = new OutputStreamWriter( out, encoding ); - writer.write( xmlProlog.toString() ); - if ( len > size ) - { - writer.write( cbuf, off + size, len - size ); + writer = new OutputStreamWriter(out, encoding); + writer.write(xmlProlog.toString()); + if (len > size) { + writer.write(cbuf, off + size, len - size); } } } } @Override - public void write( char[] cbuf, int off, int len ) - throws IOException - { - if ( xmlPrologWriter != null ) - { - detectEncoding( cbuf, off, len ); - } - else - { - writer.write( cbuf, off, len ); + public void write(char[] cbuf, int off, int len) throws IOException { + if (xmlPrologWriter != null) { + detectEncoding(cbuf, off, len); + } else { + writer.write(cbuf, off, len); } } diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java b/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java index 213bd0c0..deb41d2e 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java @@ -35,13 +35,12 @@ * * @since 1.5.7 */ -public class XmlUtil -{ +public class XmlUtil { /** The default line indenter size i.e. 2. */ public static final int DEFAULT_INDENTATION_SIZE = 2; /** The default line separator ("\n" on UNIX) */ - public static final String DEFAULT_LINE_SEPARATOR = System.getProperty( "line.separator" ); + public static final String DEFAULT_LINE_SEPARATOR = System.getProperty("line.separator"); /** * Determines if a given File shall be handled as XML. @@ -49,40 +48,34 @@ public class XmlUtil * @param f not null file * @return true if the given file has XML content, false otherwise. */ - public static boolean isXml( File f ) - { - if ( f == null ) - { - throw new IllegalArgumentException( "f could not be null." ); + public static boolean isXml(File f) { + if (f == null) { + throw new IllegalArgumentException("f could not be null."); } - if ( !f.isFile() ) - { - throw new IllegalArgumentException( "The file '" + f.getAbsolutePath() + "' is not a file." ); + if (!f.isFile()) { + throw new IllegalArgumentException("The file '" + f.getAbsolutePath() + "' is not a file."); } - try ( Reader reader = new XmlStreamReader( f ) ) - { + try (Reader reader = new XmlStreamReader(f)) { XmlPullParser parser = new MXParser(); - parser.setInput( reader ); + parser.setInput(reader); parser.nextToken(); return true; - } - catch ( Exception e ) - { + } catch (Exception e) { return false; } } /** * Pretty format the input reader. For instance, the following input: - * + * *

      * <div><b>content</b></div>
      * 
- * + * * becomes - * + * *
      * <div>
      *   <b>content</b>
@@ -94,21 +87,19 @@ public static boolean isXml( File f )
      * @throws IOException if any or invalid xml content
      * @see #prettyFormat(Reader, Writer, int, String)
      */
-    public static void prettyFormat( Reader reader, Writer writer )
-        throws IOException
-    {
-        prettyFormat( reader, writer, DEFAULT_INDENTATION_SIZE, DEFAULT_LINE_SEPARATOR );
+    public static void prettyFormat(Reader reader, Writer writer) throws IOException {
+        prettyFormat(reader, writer, DEFAULT_INDENTATION_SIZE, DEFAULT_LINE_SEPARATOR);
     }
 
     /**
      * Pretty format the input reader. For instance, the following input:
-     * 
+     *
      * 
      * <div><b>content</b></div>
      * 
- * + * * becomes - * + * *
      * <div>
      *   <b>content</b>
@@ -121,48 +112,41 @@ public static void prettyFormat( Reader reader, Writer writer )
      * @param lineSeparator the wanted line separator
      * @throws IOException if any or invalid xml content
      */
-    public static void prettyFormat( Reader reader, Writer writer, int indentSize, String lineSeparator )
-        throws IOException
-    {
-        if ( reader == null )
-        {
-            throw new IllegalArgumentException( "The reader is null" );
+    public static void prettyFormat(Reader reader, Writer writer, int indentSize, String lineSeparator)
+            throws IOException {
+        if (reader == null) {
+            throw new IllegalArgumentException("The reader is null");
         }
-        if ( writer == null )
-        {
-            throw new IllegalArgumentException( "The writer is null" );
+        if (writer == null) {
+            throw new IllegalArgumentException("The writer is null");
         }
-        if ( indentSize < 0 )
-        {
+        if (indentSize < 0) {
             indentSize = 0;
         }
 
-        PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter( writer );
-        xmlWriter.setLineIndenter( StringUtils.repeat( " ", indentSize ) );
-        xmlWriter.setLineSeparator( lineSeparator );
+        PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter(writer);
+        xmlWriter.setLineIndenter(StringUtils.repeat(" ", indentSize));
+        xmlWriter.setLineSeparator(lineSeparator);
 
         XmlPullParser parser = new MXParser();
-        try
-        {
-            parser.setInput( reader );
+        try {
+            parser.setInput(reader);
 
-            prettyFormatInternal( parser, xmlWriter );
-        }
-        catch ( XmlPullParserException e )
-        {
-            throw new IOException( "Unable to parse the XML: " + e.getMessage() );
+            prettyFormatInternal(parser, xmlWriter);
+        } catch (XmlPullParserException e) {
+            throw new IOException("Unable to parse the XML: " + e.getMessage());
         }
     }
 
     /**
      * Pretty format the input stream. For instance, the following input:
-     * 
+     *
      * 
      * <div><b>content</b></div>
      * 
- * + * * becomes - * + * *
      * <div>
      *   <b>content</b>
@@ -174,21 +158,19 @@ public static void prettyFormat( Reader reader, Writer writer, int indentSize, S
      * @throws IOException if any or invalid xml content
      * @see #prettyFormat(InputStream, OutputStream, int, String)
      */
-    public static void prettyFormat( InputStream is, OutputStream os )
-        throws IOException
-    {
-        prettyFormat( is, os, DEFAULT_INDENTATION_SIZE, DEFAULT_LINE_SEPARATOR );
+    public static void prettyFormat(InputStream is, OutputStream os) throws IOException {
+        prettyFormat(is, os, DEFAULT_INDENTATION_SIZE, DEFAULT_LINE_SEPARATOR);
     }
 
     /**
      * Pretty format the input stream. For instance, the following input:
-     * 
+     *
      * 
      * <div><b>content</b></div>
      * 
- * + * * becomes - * + * *
      * <div>
      *   <b>content</b>
@@ -201,37 +183,30 @@ public static void prettyFormat( InputStream is, OutputStream os )
      * @param lineSeparator the wanted line separator
      * @throws IOException if any or invalid xml content
      */
-    public static void prettyFormat( InputStream is, OutputStream os, int indentSize, String lineSeparator )
-        throws IOException
-    {
-        if ( is == null )
-        {
-            throw new IllegalArgumentException( "The is is null" );
+    public static void prettyFormat(InputStream is, OutputStream os, int indentSize, String lineSeparator)
+            throws IOException {
+        if (is == null) {
+            throw new IllegalArgumentException("The is is null");
         }
-        if ( os == null )
-        {
-            throw new IllegalArgumentException( "The os is null" );
+        if (os == null) {
+            throw new IllegalArgumentException("The os is null");
         }
-        if ( indentSize < 0 )
-        {
+        if (indentSize < 0) {
             indentSize = 0;
         }
 
-        try ( InputStream input = is;
-              Writer writer = new OutputStreamWriter( os ) )
-        {
-            final PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter( writer );
-            xmlWriter.setLineIndenter( StringUtils.repeat( " ", indentSize ) );
-            xmlWriter.setLineSeparator( lineSeparator );
+        try (InputStream input = is;
+                Writer writer = new OutputStreamWriter(os)) {
+            final PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter(writer);
+            xmlWriter.setLineIndenter(StringUtils.repeat(" ", indentSize));
+            xmlWriter.setLineSeparator(lineSeparator);
 
             final XmlPullParser parser = new MXParser();
-            parser.setInput( input, null );
+            parser.setInput(input, null);
 
-            prettyFormatInternal( parser, xmlWriter );
-        }
-        catch ( XmlPullParserException e )
-        {
-            throw new IOException( "Unable to parse the XML: " + e.getMessage() );
+            prettyFormatInternal(parser, xmlWriter);
+        } catch (XmlPullParserException e) {
+            throw new IOException("Unable to parse the XML: " + e.getMessage());
         }
     }
 
@@ -241,82 +216,58 @@ public static void prettyFormat( InputStream is, OutputStream os, int indentSize
      * @throws XmlPullParserException if any
      * @throws IOException if any
      */
-    private static void prettyFormatInternal( XmlPullParser parser, PrettyPrintXMLWriter writer )
-        throws XmlPullParserException, IOException
-    {
+    private static void prettyFormatInternal(XmlPullParser parser, PrettyPrintXMLWriter writer)
+            throws XmlPullParserException, IOException {
         boolean hasTag = false;
         boolean hasComment = false;
         int eventType = parser.getEventType();
-        while ( eventType != XmlPullParser.END_DOCUMENT )
-        {
-            if ( eventType == XmlPullParser.START_TAG )
-            {
+        while (eventType != XmlPullParser.END_DOCUMENT) {
+            if (eventType == XmlPullParser.START_TAG) {
                 hasTag = true;
-                if ( hasComment )
-                {
-                    writer.writeText( writer.getLineIndenter() );
+                if (hasComment) {
+                    writer.writeText(writer.getLineIndenter());
                     hasComment = false;
                 }
-                writer.startElement( parser.getName() );
-                for ( int i = 0; i < parser.getAttributeCount(); i++ )
-                {
-                    String key = parser.getAttributeName( i );
-                    String value = parser.getAttributeValue( i );
-                    writer.addAttribute( key, value );
+                writer.startElement(parser.getName());
+                for (int i = 0; i < parser.getAttributeCount(); i++) {
+                    String key = parser.getAttributeName(i);
+                    String value = parser.getAttributeValue(i);
+                    writer.addAttribute(key, value);
                 }
-            }
-            else if ( eventType == XmlPullParser.TEXT )
-            {
+            } else if (eventType == XmlPullParser.TEXT) {
                 String text = parser.getText();
-                if ( !text.trim().equals( "" ) )
-                {
-                    text = StringUtils.removeDuplicateWhitespace( text );
-                    writer.writeText( text );
+                if (!text.trim().equals("")) {
+                    text = StringUtils.removeDuplicateWhitespace(text);
+                    writer.writeText(text);
                 }
-            }
-            else if ( eventType == XmlPullParser.END_TAG )
-            {
+            } else if (eventType == XmlPullParser.END_TAG) {
                 hasTag = false;
                 writer.endElement();
-            }
-            else if ( eventType == XmlPullParser.COMMENT )
-            {
+            } else if (eventType == XmlPullParser.COMMENT) {
                 hasComment = true;
-                if ( !hasTag )
-                {
-                    writer.writeMarkup( writer.getLineSeparator() );
-                    for ( int i = 0; i < writer.getDepth(); i++ )
-                    {
-                        writer.writeMarkup( writer.getLineIndenter() );
+                if (!hasTag) {
+                    writer.writeMarkup(writer.getLineSeparator());
+                    for (int i = 0; i < writer.getDepth(); i++) {
+                        writer.writeMarkup(writer.getLineIndenter());
                     }
                 }
-                writer.writeMarkup( "" );
-                if ( !hasTag )
-                {
-                    writer.writeMarkup( writer.getLineSeparator() );
-                    for ( int i = 0; i < writer.getDepth() - 1; i++ )
-                    {
-                        writer.writeMarkup( writer.getLineIndenter() );
+                writer.writeMarkup("");
+                if (!hasTag) {
+                    writer.writeMarkup(writer.getLineSeparator());
+                    for (int i = 0; i < writer.getDepth() - 1; i++) {
+                        writer.writeMarkup(writer.getLineIndenter());
                     }
                 }
-            }
-            else if ( eventType == XmlPullParser.DOCDECL )
-            {
-                writer.writeMarkup( "" );
+            } else if (eventType == XmlPullParser.DOCDECL) {
+                writer.writeMarkup("");
                 writer.endOfLine();
-            }
-            else if ( eventType == XmlPullParser.PROCESSING_INSTRUCTION )
-            {
-                writer.writeMarkup( "" );
+            } else if (eventType == XmlPullParser.PROCESSING_INSTRUCTION) {
+                writer.writeMarkup("");
                 writer.endOfLine();
-            }
-            else if ( eventType == XmlPullParser.CDSECT )
-            {
-                writer.writeMarkup( "" );
-            }
-            else if ( eventType == XmlPullParser.ENTITY_REF )
-            {
-                writer.writeMarkup( "&" + parser.getName() + ";" );
+            } else if (eventType == XmlPullParser.CDSECT) {
+                writer.writeMarkup("");
+            } else if (eventType == XmlPullParser.ENTITY_REF) {
+                writer.writeMarkup("&" + parser.getName() + ";");
             }
 
             eventType = parser.nextToken();
diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java b/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
index 515ff75e..01870e51 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
@@ -22,10 +22,9 @@
  * @author Vincent Siveton
  *
  */
-public class XmlWriterUtil
-{
+public class XmlWriterUtil {
     /** The vm line separator */
-    public static final String LS = System.getProperty( "line.separator" );
+    public static final String LS = System.getProperty("line.separator");
 
     /** The default line indenter size i.e. 2. */
     public static final int DEFAULT_INDENTATION_SIZE = 2;
@@ -38,9 +37,8 @@ public class XmlWriterUtil
      *
      * @param writer not null writer
      */
-    public static void writeLineBreak( XMLWriter writer )
-    {
-        writeLineBreak( writer, 1 );
+    public static void writeLineBreak(XMLWriter writer) {
+        writeLineBreak(writer, 1);
     }
 
     /**
@@ -49,11 +47,9 @@ public static void writeLineBreak( XMLWriter writer )
      * @param writer not null
      * @param repeat positive number
      */
-    public static void writeLineBreak( XMLWriter writer, int repeat )
-    {
-        for ( int i = 0; i < repeat; i++ )
-        {
-            writer.writeMarkup( LS );
+    public static void writeLineBreak(XMLWriter writer, int repeat) {
+        for (int i = 0; i < repeat; i++) {
+            writer.writeMarkup(LS);
         }
     }
 
@@ -66,9 +62,8 @@ public static void writeLineBreak( XMLWriter writer, int repeat )
      * @see #DEFAULT_INDENTATION_SIZE
      * @see #writeLineBreak(XMLWriter, int, int, int)
      */
-    public static void writeLineBreak( XMLWriter writer, int repeat, int indent )
-    {
-        writeLineBreak( writer, repeat, indent, DEFAULT_INDENTATION_SIZE );
+    public static void writeLineBreak(XMLWriter writer, int repeat, int indent) {
+        writeLineBreak(writer, repeat, indent, DEFAULT_INDENTATION_SIZE);
     }
 
     /**
@@ -79,21 +74,18 @@ public static void writeLineBreak( XMLWriter writer, int repeat, int indent )
      * @param indent positive number
      * @param indentSize positive number
      */
-    public static void writeLineBreak( XMLWriter writer, int repeat, int indent, int indentSize )
-    {
-        writeLineBreak( writer, repeat );
+    public static void writeLineBreak(XMLWriter writer, int repeat, int indent, int indentSize) {
+        writeLineBreak(writer, repeat);
 
-        if ( indent < 0 )
-        {
+        if (indent < 0) {
             indent = 0;
         }
 
-        if ( indentSize < 0 )
-        {
+        if (indentSize < 0) {
             indentSize = 0;
         }
 
-        writer.writeText( StringUtils.repeat( " ", indent * indentSize ) );
+        writer.writeText(StringUtils.repeat(" ", indent * indentSize));
     }
 
     /**
@@ -103,9 +95,8 @@ public static void writeLineBreak( XMLWriter writer, int repeat, int indent, int
      * @see #DEFAULT_COLUMN_LINE
      * @see #writeCommentLineBreak(XMLWriter, int)
      */
-    public static void writeCommentLineBreak( XMLWriter writer )
-    {
-        writeCommentLineBreak( writer, DEFAULT_COLUMN_LINE );
+    public static void writeCommentLineBreak(XMLWriter writer) {
+        writeCommentLineBreak(writer, DEFAULT_COLUMN_LINE);
     }
 
     /**
@@ -114,14 +105,12 @@ public static void writeCommentLineBreak( XMLWriter writer )
      * @param writer not null
      * @param columnSize positive number
      */
-    public static void writeCommentLineBreak( XMLWriter writer, int columnSize )
-    {
-        if ( columnSize < 10 )
-        {
+    public static void writeCommentLineBreak(XMLWriter writer, int columnSize) {
+        if (columnSize < 10) {
             columnSize = DEFAULT_COLUMN_LINE;
         }
 
-        writer.writeMarkup( "" + LS );
+        writer.writeMarkup("" + LS);
     }
 
     /**
@@ -133,9 +122,8 @@ public static void writeCommentLineBreak( XMLWriter writer, int columnSize )
      * @see #DEFAULT_INDENTATION_SIZE
      * @see #writeComment(XMLWriter, String, int, int)
      */
-    public static void writeComment( XMLWriter writer, String comment )
-    {
-        writeComment( writer, comment, 0, DEFAULT_INDENTATION_SIZE );
+    public static void writeComment(XMLWriter writer, String comment) {
+        writeComment(writer, comment, 0, DEFAULT_INDENTATION_SIZE);
     }
 
     /**
@@ -148,9 +136,8 @@ public static void writeComment( XMLWriter writer, String comment )
      * @see #DEFAULT_INDENTATION_SIZE
      * @see #writeComment(XMLWriter, String, int, int)
      */
-    public static void writeComment( XMLWriter writer, String comment, int indent )
-    {
-        writeComment( writer, comment, indent, DEFAULT_INDENTATION_SIZE );
+    public static void writeComment(XMLWriter writer, String comment, int indent) {
+        writeComment(writer, comment, indent, DEFAULT_INDENTATION_SIZE);
     }
 
     /**
@@ -164,9 +151,8 @@ public static void writeComment( XMLWriter writer, String comment, int indent )
      * @see #DEFAULT_COLUMN_LINE
      * @see #writeComment(XMLWriter, String, int, int, int)
      */
-    public static void writeComment( XMLWriter writer, String comment, int indent, int indentSize )
-    {
-        writeComment( writer, comment, indent, indentSize, DEFAULT_COLUMN_LINE );
+    public static void writeComment(XMLWriter writer, String comment, int indent, int indentSize) {
+        writeComment(writer, comment, indent, indentSize, DEFAULT_COLUMN_LINE);
     }
 
     /**
@@ -179,85 +165,69 @@ public static void writeComment( XMLWriter writer, String comment, int indent, i
      * @param indentSize positive number
      * @param columnSize positive number
      */
-    public static void writeComment( XMLWriter writer, String comment, int indent, int indentSize, int columnSize )
-    {
-        if ( comment == null )
-        {
+    public static void writeComment(XMLWriter writer, String comment, int indent, int indentSize, int columnSize) {
+        if (comment == null) {
             comment = "null";
         }
 
-        while ( comment.contains( "" ) )
-        {
-            comment = comment.replace( "-->", "" );
+        while (comment.contains("-->")) {
+            comment = comment.replace("-->", "");
         }
 
-        if ( indent < 0 )
-        {
+        if (indent < 0) {
             indent = 0;
         }
 
-        if ( indentSize < 0 )
-        {
+        if (indentSize < 0) {
             indentSize = 0;
         }
 
-        if ( columnSize < 0 )
-        {
+        if (columnSize < 0) {
             columnSize = DEFAULT_COLUMN_LINE;
         }
 
-        String indentation = StringUtils.repeat( " ", indent * indentSize );
+        String indentation = StringUtils.repeat(" ", indent * indentSize);
         int magicNumber = indentation.length() + columnSize - "-->".length() - 1;
-        String[] sentences = StringUtils.split( comment, LS );
-
-        StringBuffer line = new StringBuffer( indentation + "" ).append( LS );
-                        writer.writeMarkup( line.toString() );
+                        line.append("-->").append(LS);
+                        writer.writeMarkup(line.toString());
                     }
-                    line = new StringBuffer( indentation + "" ).append( LS );
+        line.append("-->").append(LS);
 
-        writer.writeMarkup( line.toString() );
+        writer.writeMarkup(line.toString());
     }
 
     /**
@@ -268,9 +238,8 @@ public static void writeComment( XMLWriter writer, String comment, int indent, i
      * @see #DEFAULT_INDENTATION_SIZE
      * @see #writeCommentText(XMLWriter, String, int, int)
      */
-    public static void writeCommentText( XMLWriter writer, String comment )
-    {
-        writeCommentText( writer, comment, 0, DEFAULT_INDENTATION_SIZE );
+    public static void writeCommentText(XMLWriter writer, String comment) {
+        writeCommentText(writer, comment, 0, DEFAULT_INDENTATION_SIZE);
     }
 
     /**
@@ -283,9 +252,8 @@ public static void writeCommentText( XMLWriter writer, String comment )
      * @see #DEFAULT_INDENTATION_SIZE
      * @see #writeCommentText(XMLWriter, String, int, int)
      */
-    public static void writeCommentText( XMLWriter writer, String comment, int indent )
-    {
-        writeCommentText( writer, comment, indent, DEFAULT_INDENTATION_SIZE );
+    public static void writeCommentText(XMLWriter writer, String comment, int indent) {
+        writeCommentText(writer, comment, indent, DEFAULT_INDENTATION_SIZE);
     }
 
     /**
@@ -299,9 +267,8 @@ public static void writeCommentText( XMLWriter writer, String comment, int inden
      * @see #DEFAULT_COLUMN_LINE
      * @see #writeCommentText(XMLWriter, String, int, int, int)
      */
-    public static void writeCommentText( XMLWriter writer, String comment, int indent, int indentSize )
-    {
-        writeCommentText( writer, comment, indent, indentSize, DEFAULT_COLUMN_LINE );
+    public static void writeCommentText(XMLWriter writer, String comment, int indent, int indentSize) {
+        writeCommentText(writer, comment, indent, indentSize, DEFAULT_COLUMN_LINE);
     }
 
     /**
@@ -314,33 +281,29 @@ public static void writeCommentText( XMLWriter writer, String comment, int inden
      * @param indentSize positive number
      * @param columnSize positive number
      */
-    public static void writeCommentText( XMLWriter writer, String comment, int indent, int indentSize, int columnSize )
-    {
-        if ( indent < 0 )
-        {
+    public static void writeCommentText(XMLWriter writer, String comment, int indent, int indentSize, int columnSize) {
+        if (indent < 0) {
             indent = 0;
         }
 
-        if ( indentSize < 0 )
-        {
+        if (indentSize < 0) {
             indentSize = 0;
         }
 
-        if ( columnSize < 0 )
-        {
+        if (columnSize < 0) {
             columnSize = DEFAULT_COLUMN_LINE;
         }
 
-        writeLineBreak( writer, 1 );
+        writeLineBreak(writer, 1);
 
-        writer.writeMarkup( StringUtils.repeat( " ", indent * indentSize ) );
-        writeCommentLineBreak( writer, columnSize );
+        writer.writeMarkup(StringUtils.repeat(" ", indent * indentSize));
+        writeCommentLineBreak(writer, columnSize);
 
-        writeComment( writer, comment, indent, indentSize, columnSize );
+        writeComment(writer, comment, indent, indentSize, columnSize);
 
-        writer.writeMarkup( StringUtils.repeat( " ", indent * indentSize ) );
-        writeCommentLineBreak( writer, columnSize );
+        writer.writeMarkup(StringUtils.repeat(" ", indent * indentSize));
+        writeCommentLineBreak(writer, columnSize);
 
-        writeLineBreak( writer, 1, indent, indentSize );
+        writeLineBreak(writer, 1, indent, indentSize);
     }
 }
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
index 2046da3f..0e8ddfe9 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
@@ -16,10 +16,6 @@
  * limitations under the License.
  */
 
-import org.apache.maven.api.xml.XmlNode;
-import org.apache.maven.internal.xml.XmlNodeImpl;
-import org.codehaus.plexus.util.xml.pull.XmlSerializer;
-
 import java.io.IOException;
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -27,12 +23,14 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.maven.api.xml.XmlNode;
+import org.apache.maven.internal.xml.XmlNodeImpl;
+import org.codehaus.plexus.util.xml.pull.XmlSerializer;
+
 /**
  *  NOTE: remove all the util code in here when separated, this class should be pure data.
  */
-public class Xpp3Dom
-    implements Serializable
-{
+public class Xpp3Dom implements Serializable {
     private static final String[] EMPTY_STRING_ARRAY = new String[0];
 
     public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = XmlNode.CHILDREN_COMBINATION_MODE_ATTRIBUTE;
@@ -71,9 +69,8 @@ public class Xpp3Dom
     private ChildrenTracking childrenTracking;
     private XmlNode dom;
 
-    public Xpp3Dom( String name )
-    {
-        this.dom = new XmlNodeImpl( name );
+    public Xpp3Dom(String name) {
+        this.dom = new XmlNodeImpl(name);
     }
 
     /**
@@ -81,18 +78,16 @@ public Xpp3Dom( String name )
      * @param inputLocation The input location.
      * @param name The name of the Dom.
      */
-    public Xpp3Dom( String name, Object inputLocation )
-    {
-        this.dom = new XmlNodeImpl( name, null, null, null, inputLocation );
+    public Xpp3Dom(String name, Object inputLocation) {
+        this.dom = new XmlNodeImpl(name, null, null, null, inputLocation);
     }
 
     /**
      * Copy constructor.
      * @param src The source Dom.
      */
-    public Xpp3Dom( Xpp3Dom src )
-    {
-        this( src, src.getName() );
+    public Xpp3Dom(Xpp3Dom src) {
+        this(src, src.getName());
     }
 
     /**
@@ -100,30 +95,25 @@ public Xpp3Dom( Xpp3Dom src )
      * @param src The source Dom.
      * @param name The name of the Dom.
      */
-    public Xpp3Dom( Xpp3Dom src, String name )
-    {
-        this.dom = new XmlNodeImpl( src.dom, name );
+    public Xpp3Dom(Xpp3Dom src, String name) {
+        this.dom = new XmlNodeImpl(src.dom, name);
     }
 
-    public Xpp3Dom( XmlNode dom )
-    {
+    public Xpp3Dom(XmlNode dom) {
         this.dom = dom;
     }
 
-    public Xpp3Dom( XmlNode dom, Xpp3Dom parent )
-    {
+    public Xpp3Dom(XmlNode dom, Xpp3Dom parent) {
         this.dom = dom;
         this.childrenTracking = parent::replace;
     }
 
-    public Xpp3Dom( XmlNode dom, ChildrenTracking childrenTracking )
-    {
+    public Xpp3Dom(XmlNode dom, ChildrenTracking childrenTracking) {
         this.dom = dom;
         this.childrenTracking = childrenTracking;
     }
 
-    public XmlNode getDom()
-    {
+    public XmlNode getDom() {
         return dom;
     }
 
@@ -131,8 +121,7 @@ public XmlNode getDom()
     // Name handling
     // ----------------------------------------------------------------------
 
-    public String getName()
-    {
+    public String getName() {
         return dom.getName();
     }
 
@@ -140,28 +129,24 @@ public String getName()
     // Value handling
     // ----------------------------------------------------------------------
 
-    public String getValue()
-    {
+    public String getValue() {
         return dom.getValue();
     }
 
-    public void setValue( String value )
-    {
-        update( new XmlNodeImpl( dom.getName(), value, dom.getAttributes(), dom.getChildren(), dom.getInputLocation() ) );
+    public void setValue(String value) {
+        update(new XmlNodeImpl(dom.getName(), value, dom.getAttributes(), dom.getChildren(), dom.getInputLocation()));
     }
 
     // ----------------------------------------------------------------------
     // Attribute handling
     // ----------------------------------------------------------------------
 
-    public String[] getAttributeNames()
-    {
-        return dom.getAttributes().keySet().toArray( EMPTY_STRING_ARRAY );
+    public String[] getAttributeNames() {
+        return dom.getAttributes().keySet().toArray(EMPTY_STRING_ARRAY);
     }
 
-    public String getAttribute( String name )
-    {
-        return dom.getAttribute( name );
+    public String getAttribute(String name) {
+        return dom.getAttribute(name);
     }
 
     /**
@@ -170,10 +155,8 @@ public String getAttribute( String name )
      * @return true if the attribute has been removed
      * @since 3.4.0
      */
-    public boolean removeAttribute( String name )
-    {
-        if ( name != null && !name.isEmpty() )
-        {
+    public boolean removeAttribute(String name) {
+        if (name != null && !name.isEmpty()) {
             Map attrs = new HashMap<>(dom.getAttributes());
             boolean ret = attrs.remove(name) != null;
             if (ret) {
@@ -187,18 +170,15 @@ public boolean removeAttribute( String name )
 
     /**
      * Set the attribute value
-     * 
+     *
      * @param name String not null
      * @param value String not null
      */
-    public void setAttribute( String name, String value )
-    {
-        if ( null == value )
-        {
-            throw new NullPointerException( "Attribute value can not be null" );
+    public void setAttribute(String name, String value) {
+        if (null == value) {
+            throw new NullPointerException("Attribute value can not be null");
         }
-        if ( null == name )
-        {
+        if (null == name) {
             throw new NullPointerException("Attribute name can not be null");
         }
         Map attrs = new HashMap<>(dom.getAttributes());
@@ -210,69 +190,58 @@ public void setAttribute( String name, String value )
     // Child handling
     // ----------------------------------------------------------------------
 
-    public Xpp3Dom getChild( int i )
-    {
-        return new Xpp3Dom( dom.getChildren().get(i), this );
+    public Xpp3Dom getChild(int i) {
+        return new Xpp3Dom(dom.getChildren().get(i), this);
     }
 
-    public Xpp3Dom getChild( String name )
-    {
-        XmlNode child = dom.getChild( name );
-        return child != null ? new Xpp3Dom( child, this ) : null;
+    public Xpp3Dom getChild(String name) {
+        XmlNode child = dom.getChild(name);
+        return child != null ? new Xpp3Dom(child, this) : null;
     }
 
-    public void addChild( Xpp3Dom xpp3Dom )
-    {
-        List children = new ArrayList<>( dom.getChildren() );
-        children.add( xpp3Dom.dom );
+    public void addChild(Xpp3Dom xpp3Dom) {
+        List children = new ArrayList<>(dom.getChildren());
+        children.add(xpp3Dom.dom);
         xpp3Dom.childrenTracking = this::replace;
-        update( new XmlNodeImpl( dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation() ) );
+        update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation()));
     }
 
-    public Xpp3Dom[] getChildren()
-    {
+    public Xpp3Dom[] getChildren() {
         return dom.getChildren().stream().map(d -> new Xpp3Dom(d, this)).toArray(Xpp3Dom[]::new);
     }
 
-    public Xpp3Dom[] getChildren( String name )
-    {
+    public Xpp3Dom[] getChildren(String name) {
         return dom.getChildren().stream()
-                .filter( c -> c.getName().equals( name ) )
-                .map( d -> new Xpp3Dom( d, this ) )
-                .toArray( Xpp3Dom[]::new );
+                .filter(c -> c.getName().equals(name))
+                .map(d -> new Xpp3Dom(d, this))
+                .toArray(Xpp3Dom[]::new);
     }
 
-    public int getChildCount()
-    {
+    public int getChildCount() {
         return dom.getChildren().size();
     }
 
-    public void removeChild( int i )
-    {
-        List children = new ArrayList<>( dom.getChildren() );
-        children.remove( i );
-        update( new XmlNodeImpl( dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation() ) );
+    public void removeChild(int i) {
+        List children = new ArrayList<>(dom.getChildren());
+        children.remove(i);
+        update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation()));
     }
 
-    public void removeChild( Xpp3Dom child )
-    {
-        List children = new ArrayList<>( dom.getChildren() );
-        children.remove( child.dom );
-        update( new XmlNodeImpl( dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation() ) );
+    public void removeChild(Xpp3Dom child) {
+        List children = new ArrayList<>(dom.getChildren());
+        children.remove(child.dom);
+        update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation()));
     }
 
     // ----------------------------------------------------------------------
     // Parent handling
     // ----------------------------------------------------------------------
 
-    public Xpp3Dom getParent()
-    {
+    public Xpp3Dom getParent() {
         throw new UnsupportedOperationException();
     }
 
-    public void setParent( Xpp3Dom parent )
-    {
-    }
+    public void setParent(Xpp3Dom parent) {}
 
     // ----------------------------------------------------------------------
     // Input location handling
@@ -282,8 +251,7 @@ public void setParent( Xpp3Dom parent )
      * @since 3.2.0
      * @return input location
      */
-    public Object getInputLocation()
-    {
+    public Object getInputLocation() {
         return dom.getInputLocation();
     }
 
@@ -291,24 +259,21 @@ public Object getInputLocation()
      * @since 3.2.0
      * @param inputLocation input location to set
      */
-    public void setInputLocation( Object inputLocation )
-    {
-        update( new XmlNodeImpl( dom.getName(), dom.getValue(), dom.getAttributes(), dom.getChildren(), inputLocation ) );
+    public void setInputLocation(Object inputLocation) {
+        update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), dom.getChildren(), inputLocation));
     }
 
     // ----------------------------------------------------------------------
     // Helpers
     // ----------------------------------------------------------------------
 
-    public void writeToSerializer( String namespace, XmlSerializer serializer ) throws IOException
-    {
+    public void writeToSerializer(String namespace, XmlSerializer serializer) throws IOException {
         // TODO: WARNING! Later versions of plexus-utils psit out an  header due to thinking this is a new
         // document - not the desired behaviour!
-        SerializerXMLWriter xmlWriter = new SerializerXMLWriter( namespace, serializer );
-        Xpp3DomWriter.write( xmlWriter, this );
-        if ( xmlWriter.getExceptions().size() > 0 )
-        {
-            throw (IOException) xmlWriter.getExceptions().get( 0 );
+        SerializerXMLWriter xmlWriter = new SerializerXMLWriter(namespace, serializer);
+        Xpp3DomWriter.write(xmlWriter, this);
+        if (xmlWriter.getExceptions().size() > 0) {
+            throw (IOException) xmlWriter.getExceptions().get(0);
         }
     }
 
@@ -349,14 +314,12 @@ public void writeToSerializer( String namespace, XmlSerializer serializer ) thro
      *   
      * 
      */
-    private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride )
-    {
+    private static void mergeIntoXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) {
         // TODO: share this as some sort of assembler, implement a walk interface?
-        if ( recessive == null )
-        {
+        if (recessive == null) {
             return;
         }
-        dominant.dom = dominant.dom.merge( recessive.dom, childMergeOverride );
+        dominant.dom = dominant.dom.merge(recessive.dom, childMergeOverride);
     }
 
     /**
@@ -370,11 +333,9 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
      *            dominant DOM
      * @return merged DOM
      */
-    public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride )
-    {
-        if ( dominant != null )
-        {
-            mergeIntoXpp3Dom( dominant, recessive, childMergeOverride );
+    public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) {
+        if (dominant != null) {
+            mergeIntoXpp3Dom(dominant, recessive, childMergeOverride);
             return dominant;
         }
         return recessive;
@@ -390,11 +351,9 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean
      * @param recessive The recessive DOM, which will be merged into the dominant DOM
      * @return merged DOM
      */
-    public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
-    {
-        if ( dominant != null )
-        {
-            mergeIntoXpp3Dom( dominant, recessive, null );
+    public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive) {
+        if (dominant != null) {
+            mergeIntoXpp3Dom(dominant, recessive, null);
             return dominant;
         }
         return recessive;
@@ -405,73 +364,61 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
     // ----------------------------------------------------------------------
 
     @Override
-    public boolean equals( Object obj )
-    {
+    public boolean equals(Object obj) {
         if (obj == this) {
             return true;
         }
 
-        if ( !( obj instanceof Xpp3Dom ) )
-        {
+        if (!(obj instanceof Xpp3Dom)) {
             return false;
         }
 
-        Xpp3Dom dom = ( Xpp3Dom ) obj;
-        return this.dom.equals( dom.dom );
+        Xpp3Dom dom = (Xpp3Dom) obj;
+        return this.dom.equals(dom.dom);
     }
 
     @Override
-    public int hashCode()
-    {
+    public int hashCode() {
         return dom.hashCode();
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return dom.toString();
     }
 
-    public String toUnescapedString()
-    {
-        return ( ( Xpp3Dom ) dom ).toUnescapedString();
+    public String toUnescapedString() {
+        return ((Xpp3Dom) dom).toUnescapedString();
     }
 
-    public static boolean isNotEmpty( String str )
-    {
-        return ( ( str != null ) && ( str.length() > 0 ) );
+    public static boolean isNotEmpty(String str) {
+        return ((str != null) && (str.length() > 0));
     }
 
-    public static boolean isEmpty( String str )
-    {
-        return ( ( str == null ) || ( str.trim().length() == 0 ) );
+    public static boolean isEmpty(String str) {
+        return ((str == null) || (str.trim().length() == 0));
     }
 
-    private void update(XmlNode dom)
-    {
-        if ( childrenTracking != null )
-        {
-            childrenTracking.replace( this.dom, dom );
+    private void update(XmlNode dom) {
+        if (childrenTracking != null) {
+            childrenTracking.replace(this.dom, dom);
         }
         this.dom = dom;
     }
 
-    private boolean replace(Object prevChild, Object newChild)
-    {
-        List children = new ArrayList<>( dom.getChildren() );
-        children.replaceAll( d -> d == prevChild ? (XmlNode) newChild : d );
-        update( new XmlNodeImpl( dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation() ) );
+    private boolean replace(Object prevChild, Object newChild) {
+        List children = new ArrayList<>(dom.getChildren());
+        children.replaceAll(d -> d == prevChild ? (XmlNode) newChild : d);
+        update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation()));
         return true;
     }
 
-    public void setChildrenTracking( ChildrenTracking childrenTracking )
-    {
+    public void setChildrenTracking(ChildrenTracking childrenTracking) {
         this.childrenTracking = childrenTracking;
     }
 
     @FunctionalInterface
-    public interface ChildrenTracking
-    {
-        boolean replace( Object oldDelegate, Object newDelegate );
+    public interface ChildrenTracking {
+        boolean replace(Object oldDelegate, Object newDelegate);
     }
 }
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
index cc10df39..b75e681f 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
@@ -16,90 +16,73 @@
  * limitations under the License.
  */
 
-import org.apache.maven.internal.xml.XmlNodeBuilder;
-import org.codehaus.plexus.util.xml.pull.XmlPullParser;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
 
+import org.apache.maven.internal.xml.XmlNodeBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
 /**
  *
  */
-public class Xpp3DomBuilder
-{
+public class Xpp3DomBuilder {
     private static final boolean DEFAULT_TRIM = true;
 
-    public static Xpp3Dom build( Reader reader )
-        throws XmlPullParserException, IOException
-    {
-        return build( reader, null );
+    public static Xpp3Dom build(Reader reader) throws XmlPullParserException, IOException {
+        return build(reader, null);
     }
 
     /**
      * @since 3.2.0
      */
-    public static Xpp3Dom build( Reader reader, InputLocationBuilder locationBuilder )
-        throws XmlPullParserException, IOException
-    {
-        return build( reader, DEFAULT_TRIM, locationBuilder );
+    public static Xpp3Dom build(Reader reader, InputLocationBuilder locationBuilder)
+            throws XmlPullParserException, IOException {
+        return build(reader, DEFAULT_TRIM, locationBuilder);
     }
 
-    public static Xpp3Dom build( InputStream is, String encoding )
-        throws XmlPullParserException, IOException
-    {
-        return build( is, encoding, DEFAULT_TRIM );
+    public static Xpp3Dom build(InputStream is, String encoding) throws XmlPullParserException, IOException {
+        return build(is, encoding, DEFAULT_TRIM);
     }
 
-    public static Xpp3Dom build( InputStream is, String encoding, boolean trim )
-        throws XmlPullParserException, IOException
-    {
-        try ( InputStream closeMe = is )
-        {
-            return new Xpp3Dom( XmlNodeBuilder.build( is, encoding, trim ) );
+    public static Xpp3Dom build(InputStream is, String encoding, boolean trim)
+            throws XmlPullParserException, IOException {
+        try (InputStream closeMe = is) {
+            return new Xpp3Dom(XmlNodeBuilder.build(is, encoding, trim));
         }
     }
 
-    public static Xpp3Dom build( Reader reader, boolean trim )
-        throws XmlPullParserException, IOException
-    {
-        return build( reader, trim, null );
+    public static Xpp3Dom build(Reader reader, boolean trim) throws XmlPullParserException, IOException {
+        return build(reader, trim, null);
     }
 
     /**
      * @since 3.2.0
      */
-    public static Xpp3Dom build( Reader reader, boolean trim, InputLocationBuilder locationBuilder )
-        throws XmlPullParserException, IOException
-    {
-        try ( Reader closeMe = reader )
-        {
-            return new Xpp3Dom( XmlNodeBuilder.build(
-                    reader, trim, locationBuilder != null ? locationBuilder::toInputLocation : null ) );
+    public static Xpp3Dom build(Reader reader, boolean trim, InputLocationBuilder locationBuilder)
+            throws XmlPullParserException, IOException {
+        try (Reader closeMe = reader) {
+            return new Xpp3Dom(XmlNodeBuilder.build(
+                    reader, trim, locationBuilder != null ? locationBuilder::toInputLocation : null));
         }
     }
 
-    public static Xpp3Dom build( XmlPullParser parser )
-        throws XmlPullParserException, IOException
-    {
-        return build( parser, DEFAULT_TRIM );
+    public static Xpp3Dom build(XmlPullParser parser) throws XmlPullParserException, IOException {
+        return build(parser, DEFAULT_TRIM);
     }
 
-    public static Xpp3Dom build( XmlPullParser parser, boolean trim )
-        throws XmlPullParserException, IOException
-    {
-        return build( parser, trim, null );
+    public static Xpp3Dom build(XmlPullParser parser, boolean trim) throws XmlPullParserException, IOException {
+        return build(parser, trim, null);
     }
 
     /**
      * @since 3.2.0
      */
-    public static Xpp3Dom build( XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder )
-        throws XmlPullParserException, IOException
-    {
+    public static Xpp3Dom build(XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder)
+            throws XmlPullParserException, IOException {
         return new Xpp3Dom(
-                XmlNodeBuilder.build( parser, trim, locationBuilder != null ? locationBuilder::toInputLocation : null ) );
+                XmlNodeBuilder.build(parser, trim, locationBuilder != null ? locationBuilder::toInputLocation : null));
     }
 
     /**
@@ -107,8 +90,7 @@ public static Xpp3Dom build( XmlPullParser parser, boolean trim, InputLocationBu
      *
      * @since 3.2.0
      */
-    public interface InputLocationBuilder
-    {
-        Object toInputLocation( XmlPullParser parser );
+    public interface InputLocationBuilder {
+        Object toInputLocation(XmlPullParser parser);
     }
 }
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
index 8195d496..b4475f61 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
@@ -16,14 +16,13 @@
  * limitations under the License.
  */
 
-import org.codehaus.plexus.util.xml.pull.XmlSerializer;
-
 import java.io.IOException;
 
+import org.codehaus.plexus.util.xml.pull.XmlSerializer;
+
 /** @author Jason van Zyl */
 @Deprecated
-public class Xpp3DomUtils
-{
+public class Xpp3DomUtils {
     /**
      * @deprecated use {@link Xpp3Dom#CHILDREN_COMBINATION_MODE_ATTRIBUTE}
      */
@@ -88,10 +87,8 @@ public class Xpp3DomUtils
      * @deprecated use {@link Xpp3Dom#writeToSerializer(String, XmlSerializer)}
      */
     @Deprecated
-    public void writeToSerializer( String namespace, XmlSerializer serializer, Xpp3Dom dom )
-        throws IOException
-    {
-        dom.writeToSerializer( namespace, serializer );
+    public void writeToSerializer(String namespace, XmlSerializer serializer, Xpp3Dom dom) throws IOException {
+        dom.writeToSerializer(namespace, serializer);
     }
 
     /**
@@ -107,9 +104,8 @@ public void writeToSerializer( String namespace, XmlSerializer serializer, Xpp3D
      * @deprecated use {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom, Boolean)}
      */
     @Deprecated
-    public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride )
-    {
-        return Xpp3Dom.mergeXpp3Dom( dominant, recessive, childMergeOverride );
+    public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) {
+        return Xpp3Dom.mergeXpp3Dom(dominant, recessive, childMergeOverride);
     }
 
     /**
@@ -124,26 +120,23 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean
      * @deprecated use {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom)}
      */
     @Deprecated
-    public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
-    {
-        return Xpp3Dom.mergeXpp3Dom( dominant, recessive );
+    public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive) {
+        return Xpp3Dom.mergeXpp3Dom(dominant, recessive);
     }
 
     /**
      * @deprecated Use {@link org.codehaus.plexus.util.StringUtils#isNotEmpty(String)} instead
      */
     @Deprecated
-    public static boolean isNotEmpty( String str )
-    {
-        return ( str != null && str.length() > 0 );
+    public static boolean isNotEmpty(String str) {
+        return (str != null && str.length() > 0);
     }
 
     /**
      * @deprecated Use {@link org.codehaus.plexus.util.StringUtils#isEmpty(String)} instead
      */
     @Deprecated
-    public static boolean isEmpty( String str )
-    {
-        return ( str == null || str.length() == 0 );
+    public static boolean isEmpty(String str) {
+        return (str == null || str.length() == 0);
     }
 }
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomWriter.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomWriter.java
index 91770cab..35ecec33 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomWriter.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomWriter.java
@@ -22,52 +22,40 @@
 /**
  *
  */
-public class Xpp3DomWriter
-{
-    public static void write( Writer writer, Xpp3Dom dom )
-    {
-        write( new PrettyPrintXMLWriter( writer ), dom );
+public class Xpp3DomWriter {
+    public static void write(Writer writer, Xpp3Dom dom) {
+        write(new PrettyPrintXMLWriter(writer), dom);
     }
 
-    public static void write( PrintWriter writer, Xpp3Dom dom )
-    {
-        write( new PrettyPrintXMLWriter( writer ), dom );
+    public static void write(PrintWriter writer, Xpp3Dom dom) {
+        write(new PrettyPrintXMLWriter(writer), dom);
     }
 
-    public static void write( XMLWriter xmlWriter, Xpp3Dom dom )
-    {
-        write( xmlWriter, dom, true );
+    public static void write(XMLWriter xmlWriter, Xpp3Dom dom) {
+        write(xmlWriter, dom, true);
     }
 
-    public static void write( XMLWriter xmlWriter, Xpp3Dom dom, boolean escape )
-    {
+    public static void write(XMLWriter xmlWriter, Xpp3Dom dom, boolean escape) {
         // TODO: move to XMLWriter?
-        xmlWriter.startElement( dom.getName() );
+        xmlWriter.startElement(dom.getName());
         String[] attributeNames = dom.getAttributeNames();
-        for ( String attributeName : attributeNames )
-        {
-            xmlWriter.addAttribute( attributeName, dom.getAttribute( attributeName ) );
+        for (String attributeName : attributeNames) {
+            xmlWriter.addAttribute(attributeName, dom.getAttribute(attributeName));
         }
         Xpp3Dom[] children = dom.getChildren();
-        for ( Xpp3Dom aChildren : children )
-        {
-            write( xmlWriter, aChildren, escape );
+        for (Xpp3Dom aChildren : children) {
+            write(xmlWriter, aChildren, escape);
         }
 
         String value = dom.getValue();
-        if ( value != null )
-        {
-            if ( escape )
-            {
-                xmlWriter.writeText( value );
-            }
-            else
-            {
-                xmlWriter.writeMarkup( value );
+        if (value != null) {
+            if (escape) {
+                xmlWriter.writeText(value);
+            } else {
+                xmlWriter.writeMarkup(value);
             }
         }
 
         xmlWriter.endElement();
     }
-
 }
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/EntityReplacementMap.java b/src/main/java/org/codehaus/plexus/util/xml/pull/EntityReplacementMap.java
index 476cb774..8af68d3a 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/EntityReplacementMap.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/EntityReplacementMap.java
@@ -15,8 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-public class EntityReplacementMap
-{
+public class EntityReplacementMap {
     final String entityName[];
 
     final char[] entityNameBuf[];
@@ -29,8 +28,7 @@ public class EntityReplacementMap
 
     final int entityNameHash[];
 
-    public EntityReplacementMap( String[][] replacements )
-    {
+    public EntityReplacementMap(String[][] replacements) {
         int length = replacements.length;
         entityName = new String[length];
         entityNameBuf = new char[length][];
@@ -38,21 +36,16 @@ public EntityReplacementMap( String[][] replacements )
         entityReplacementBuf = new char[length][];
         entityNameHash = new int[length];
 
-        for ( String[] replacement : replacements )
-        {
-            defineEntityReplacementText( replacement[0], replacement[1] );
+        for (String[] replacement : replacements) {
+            defineEntityReplacementText(replacement[0], replacement[1]);
         }
     }
 
-    private void defineEntityReplacementText( String entityName, String replacementText )
-    {
-        if ( !replacementText.startsWith( "&#" ) && this.entityName != null && replacementText.length() > 1 )
-        {
-            String tmp = replacementText.substring( 1, replacementText.length() - 1 );
-            for ( int i = 0; i < this.entityName.length; i++ )
-            {
-                if ( this.entityName[i] != null && this.entityName[i].equals( tmp ) )
-                {
+    private void defineEntityReplacementText(String entityName, String replacementText) {
+        if (!replacementText.startsWith("&#") && this.entityName != null && replacementText.length() > 1) {
+            String tmp = replacementText.substring(1, replacementText.length() - 1);
+            for (int i = 0; i < this.entityName.length; i++) {
+                if (this.entityName[i] != null && this.entityName[i].equals(tmp)) {
                     replacementText = this.entityReplacement[i];
                 }
             }
@@ -61,116 +54,301 @@ private void defineEntityReplacementText( String entityName, String replacementT
         // this is to make sure that if interning works we will take advantage of it ...
         char[] entityNameCharData = entityName.toCharArray();
         // noinspection ConstantConditions
-        this.entityName[entityEnd] = newString( entityNameCharData, 0, entityName.length() );
+        this.entityName[entityEnd] = newString(entityNameCharData, 0, entityName.length());
         entityNameBuf[entityEnd] = entityNameCharData;
 
         entityReplacement[entityEnd] = replacementText;
         entityReplacementBuf[entityEnd] = replacementText.toCharArray();
-        entityNameHash[entityEnd] = fastHash( entityNameBuf[entityEnd], 0, entityNameBuf[entityEnd].length );
+        entityNameHash[entityEnd] = fastHash(entityNameBuf[entityEnd], 0, entityNameBuf[entityEnd].length);
         ++entityEnd;
         // TODO disallow < or & in entity replacement text (or ]]>???)
         // TODO keepEntityNormalizedForAttributeValue cached as well ...
     }
 
-    private String newString( char[] cbuf, int off, int len )
-    {
-        return new String( cbuf, off, len );
+    private String newString(char[] cbuf, int off, int len) {
+        return new String(cbuf, off, len);
     }
 
     /**
      * simplistic implementation of hash function that has constant time to compute - so it also means
      * diminishing hash quality for long strings but for XML parsing it should be good enough ...
      */
-    private static int fastHash( char ch[], int off, int len )
-    {
-        if ( len == 0 )
-            return 0;
+    private static int fastHash(char ch[], int off, int len) {
+        if (len == 0) return 0;
         // assert len >0
         int hash = ch[off]; // hash at beginning
         // try {
-        hash = ( hash << 7 ) + ch[off + len - 1]; // hash at the end
+        hash = (hash << 7) + ch[off + len - 1]; // hash at the end
         // } catch(ArrayIndexOutOfBoundsException aie) {
         // aie.printStackTrace(); //should never happen ...
         // throw new RuntimeException("this is violation of pre-condition");
         // }
-        if ( len > 16 )
-            hash = ( hash << 7 ) + ch[off + ( len / 4 )]; // 1/4 from beginning
-        if ( len > 8 )
-            hash = ( hash << 7 ) + ch[off + ( len / 2 )]; // 1/2 of string size ...
+        if (len > 16) hash = (hash << 7) + ch[off + (len / 4)]; // 1/4 from beginning
+        if (len > 8) hash = (hash << 7) + ch[off + (len / 2)]; // 1/2 of string size ...
         // notice that hash is at most done 3 times <<7 so shifted by 21 bits 8 bit value
         // so max result == 29 bits so it is quite just below 31 bits for long (2^32) ...
         // assert hash >= 0;
         return hash;
     }
 
-    public static final EntityReplacementMap defaultEntityReplacementMap = new EntityReplacementMap( new String[][] {
-        { "nbsp", "\u00a0" }, { "iexcl", "\u00a1" }, { "cent", "\u00a2" }, { "pound", "\u00a3" },
-        { "curren", "\u00a4" }, { "yen", "\u00a5" }, { "brvbar", "\u00a6" }, { "sect", "\u00a7" }, { "uml", "\u00a8" },
-        { "copy", "\u00a9" }, { "ordf", "\u00aa" }, { "laquo", "\u00ab" }, { "not", "\u00ac" }, { "shy", "\u00ad" },
-        { "reg", "\u00ae" }, { "macr", "\u00af" }, { "deg", "\u00b0" }, { "plusmn", "\u00b1" }, { "sup2", "\u00b2" },
-        { "sup3", "\u00b3" }, { "acute", "\u00b4" }, { "micro", "\u00b5" }, { "para", "\u00b6" },
-        { "middot", "\u00b7" }, { "cedil", "\u00b8" }, { "sup1", "\u00b9" }, { "ordm", "\u00ba" },
-        { "raquo", "\u00bb" }, { "frac14", "\u00bc" }, { "frac12", "\u00bd" }, { "frac34", "\u00be" },
-        { "iquest", "\u00bf" }, { "Agrave", "\u00c0" }, { "Aacute", "\u00c1" }, { "Acirc", "\u00c2" },
-        { "Atilde", "\u00c3" }, { "Auml", "\u00c4" }, { "Aring", "\u00c5" }, { "AElig", "\u00c6" },
-        { "Ccedil", "\u00c7" }, { "Egrave", "\u00c8" }, { "Eacute", "\u00c9" }, { "Ecirc", "\u00ca" },
-        { "Euml", "\u00cb" }, { "Igrave", "\u00cc" }, { "Iacute", "\u00cd" }, { "Icirc", "\u00ce" },
-        { "Iuml", "\u00cf" }, { "ETH", "\u00d0" }, { "Ntilde", "\u00d1" }, { "Ograve", "\u00d2" },
-        { "Oacute", "\u00d3" }, { "Ocirc", "\u00d4" }, { "Otilde", "\u00d5" }, { "Ouml", "\u00d6" },
-        { "times", "\u00d7" }, { "Oslash", "\u00d8" }, { "Ugrave", "\u00d9" }, { "Uacute", "\u00da" },
-        { "Ucirc", "\u00db" }, { "Uuml", "\u00dc" }, { "Yacute", "\u00dd" }, { "THORN", "\u00de" },
-        { "szlig", "\u00df" }, { "agrave", "\u00e0" }, { "aacute", "\u00e1" }, { "acirc", "\u00e2" },
-        { "atilde", "\u00e3" }, { "auml", "\u00e4" }, { "aring", "\u00e5" }, { "aelig", "\u00e6" },
-        { "ccedil", "\u00e7" }, { "egrave", "\u00e8" }, { "eacute", "\u00e9" }, { "ecirc", "\u00ea" },
-        { "euml", "\u00eb" }, { "igrave", "\u00ec" }, { "iacute", "\u00ed" }, { "icirc", "\u00ee" },
-        { "iuml", "\u00ef" }, { "eth", "\u00f0" }, { "ntilde", "\u00f1" }, { "ograve", "\u00f2" },
-        { "oacute", "\u00f3" }, { "ocirc", "\u00f4" }, { "otilde", "\u00f5" }, { "ouml", "\u00f6" },
-        { "divide", "\u00f7" }, { "oslash", "\u00f8" }, { "ugrave", "\u00f9" }, { "uacute", "\u00fa" },
-        { "ucirc", "\u00fb" }, { "uuml", "\u00fc" }, { "yacute", "\u00fd" }, { "thorn", "\u00fe" },
-        { "yuml", "\u00ff" },
+    public static final EntityReplacementMap defaultEntityReplacementMap = new EntityReplacementMap(new String[][] {
+        {"nbsp", "\u00a0"},
+        {"iexcl", "\u00a1"},
+        {"cent", "\u00a2"},
+        {"pound", "\u00a3"},
+        {"curren", "\u00a4"},
+        {"yen", "\u00a5"},
+        {"brvbar", "\u00a6"},
+        {"sect", "\u00a7"},
+        {"uml", "\u00a8"},
+        {"copy", "\u00a9"},
+        {"ordf", "\u00aa"},
+        {"laquo", "\u00ab"},
+        {"not", "\u00ac"},
+        {"shy", "\u00ad"},
+        {"reg", "\u00ae"},
+        {"macr", "\u00af"},
+        {"deg", "\u00b0"},
+        {"plusmn", "\u00b1"},
+        {"sup2", "\u00b2"},
+        {"sup3", "\u00b3"},
+        {"acute", "\u00b4"},
+        {"micro", "\u00b5"},
+        {"para", "\u00b6"},
+        {"middot", "\u00b7"},
+        {"cedil", "\u00b8"},
+        {"sup1", "\u00b9"},
+        {"ordm", "\u00ba"},
+        {"raquo", "\u00bb"},
+        {"frac14", "\u00bc"},
+        {"frac12", "\u00bd"},
+        {"frac34", "\u00be"},
+        {"iquest", "\u00bf"},
+        {"Agrave", "\u00c0"},
+        {"Aacute", "\u00c1"},
+        {"Acirc", "\u00c2"},
+        {"Atilde", "\u00c3"},
+        {"Auml", "\u00c4"},
+        {"Aring", "\u00c5"},
+        {"AElig", "\u00c6"},
+        {"Ccedil", "\u00c7"},
+        {"Egrave", "\u00c8"},
+        {"Eacute", "\u00c9"},
+        {"Ecirc", "\u00ca"},
+        {"Euml", "\u00cb"},
+        {"Igrave", "\u00cc"},
+        {"Iacute", "\u00cd"},
+        {"Icirc", "\u00ce"},
+        {"Iuml", "\u00cf"},
+        {"ETH", "\u00d0"},
+        {"Ntilde", "\u00d1"},
+        {"Ograve", "\u00d2"},
+        {"Oacute", "\u00d3"},
+        {"Ocirc", "\u00d4"},
+        {"Otilde", "\u00d5"},
+        {"Ouml", "\u00d6"},
+        {"times", "\u00d7"},
+        {"Oslash", "\u00d8"},
+        {"Ugrave", "\u00d9"},
+        {"Uacute", "\u00da"},
+        {"Ucirc", "\u00db"},
+        {"Uuml", "\u00dc"},
+        {"Yacute", "\u00dd"},
+        {"THORN", "\u00de"},
+        {"szlig", "\u00df"},
+        {"agrave", "\u00e0"},
+        {"aacute", "\u00e1"},
+        {"acirc", "\u00e2"},
+        {"atilde", "\u00e3"},
+        {"auml", "\u00e4"},
+        {"aring", "\u00e5"},
+        {"aelig", "\u00e6"},
+        {"ccedil", "\u00e7"},
+        {"egrave", "\u00e8"},
+        {"eacute", "\u00e9"},
+        {"ecirc", "\u00ea"},
+        {"euml", "\u00eb"},
+        {"igrave", "\u00ec"},
+        {"iacute", "\u00ed"},
+        {"icirc", "\u00ee"},
+        {"iuml", "\u00ef"},
+        {"eth", "\u00f0"},
+        {"ntilde", "\u00f1"},
+        {"ograve", "\u00f2"},
+        {"oacute", "\u00f3"},
+        {"ocirc", "\u00f4"},
+        {"otilde", "\u00f5"},
+        {"ouml", "\u00f6"},
+        {"divide", "\u00f7"},
+        {"oslash", "\u00f8"},
+        {"ugrave", "\u00f9"},
+        {"uacute", "\u00fa"},
+        {"ucirc", "\u00fb"},
+        {"uuml", "\u00fc"},
+        {"yacute", "\u00fd"},
+        {"thorn", "\u00fe"},
+        {"yuml", "\u00ff"},
 
         // ----------------------------------------------------------------------
         // Special entities
         // ----------------------------------------------------------------------
 
-        { "OElig", "\u0152" }, { "oelig", "\u0153" }, { "Scaron", "\u0160" }, { "scaron", "\u0161" },
-        { "Yuml", "\u0178" }, { "circ", "\u02c6" }, { "tilde", "\u02dc" }, { "ensp", "\u2002" }, { "emsp", "\u2003" },
-        { "thinsp", "\u2009" }, { "zwnj", "\u200c" }, { "zwj", "\u200d" }, { "lrm", "\u200e" }, { "rlm", "\u200f" },
-        { "ndash", "\u2013" }, { "mdash", "\u2014" }, { "lsquo", "\u2018" }, { "rsquo", "\u2019" },
-        { "sbquo", "\u201a" }, { "ldquo", "\u201c" }, { "rdquo", "\u201d" }, { "bdquo", "\u201e" },
-        { "dagger", "\u2020" }, { "Dagger", "\u2021" }, { "permil", "\u2030" }, { "lsaquo", "\u2039" },
-        { "rsaquo", "\u203a" }, { "euro", "\u20ac" },
+        {"OElig", "\u0152"},
+        {"oelig", "\u0153"},
+        {"Scaron", "\u0160"},
+        {"scaron", "\u0161"},
+        {"Yuml", "\u0178"},
+        {"circ", "\u02c6"},
+        {"tilde", "\u02dc"},
+        {"ensp", "\u2002"},
+        {"emsp", "\u2003"},
+        {"thinsp", "\u2009"},
+        {"zwnj", "\u200c"},
+        {"zwj", "\u200d"},
+        {"lrm", "\u200e"},
+        {"rlm", "\u200f"},
+        {"ndash", "\u2013"},
+        {"mdash", "\u2014"},
+        {"lsquo", "\u2018"},
+        {"rsquo", "\u2019"},
+        {"sbquo", "\u201a"},
+        {"ldquo", "\u201c"},
+        {"rdquo", "\u201d"},
+        {"bdquo", "\u201e"},
+        {"dagger", "\u2020"},
+        {"Dagger", "\u2021"},
+        {"permil", "\u2030"},
+        {"lsaquo", "\u2039"},
+        {"rsaquo", "\u203a"},
+        {"euro", "\u20ac"},
 
         // ----------------------------------------------------------------------
         // Symbol entities
         // ----------------------------------------------------------------------
 
-        { "fnof", "\u0192" }, { "Alpha", "\u0391" }, { "Beta", "\u0392" }, { "Gamma", "\u0393" }, { "Delta", "\u0394" },
-        { "Epsilon", "\u0395" }, { "Zeta", "\u0396" }, { "Eta", "\u0397" }, { "Theta", "\u0398" }, { "Iota", "\u0399" },
-        { "Kappa", "\u039a" }, { "Lambda", "\u039b" }, { "Mu", "\u039c" }, { "Nu", "\u039d" }, { "Xi", "\u039e" },
-        { "Omicron", "\u039f" }, { "Pi", "\u03a0" }, { "Rho", "\u03a1" }, { "Sigma", "\u03a3" }, { "Tau", "\u03a4" },
-        { "Upsilon", "\u03a5" }, { "Phi", "\u03a6" }, { "Chi", "\u03a7" }, { "Psi", "\u03a8" }, { "Omega", "\u03a9" },
-        { "alpha", "\u03b1" }, { "beta", "\u03b2" }, { "gamma", "\u03b3" }, { "delta", "\u03b4" },
-        { "epsilon", "\u03b5" }, { "zeta", "\u03b6" }, { "eta", "\u03b7" }, { "theta", "\u03b8" }, { "iota", "\u03b9" },
-        { "kappa", "\u03ba" }, { "lambda", "\u03bb" }, { "mu", "\u03bc" }, { "nu", "\u03bd" }, { "xi", "\u03be" },
-        { "omicron", "\u03bf" }, { "pi", "\u03c0" }, { "rho", "\u03c1" }, { "sigmaf", "\u03c2" }, { "sigma", "\u03c3" },
-        { "tau", "\u03c4" }, { "upsilon", "\u03c5" }, { "phi", "\u03c6" }, { "chi", "\u03c7" }, { "psi", "\u03c8" },
-        { "omega", "\u03c9" }, { "thetasym", "\u03d1" }, { "upsih", "\u03d2" }, { "piv", "\u03d6" },
-        { "bull", "\u2022" }, { "hellip", "\u2026" }, { "prime", "\u2032" }, { "Prime", "\u2033" },
-        { "oline", "\u203e" }, { "frasl", "\u2044" }, { "weierp", "\u2118" }, { "image", "\u2111" },
-        { "real", "\u211c" }, { "trade", "\u2122" }, { "alefsym", "\u2135" }, { "larr", "\u2190" },
-        { "uarr", "\u2191" }, { "rarr", "\u2192" }, { "darr", "\u2193" }, { "harr", "\u2194" }, { "crarr", "\u21b5" },
-        { "lArr", "\u21d0" }, { "uArr", "\u21d1" }, { "rArr", "\u21d2" }, { "dArr", "\u21d3" }, { "hArr", "\u21d4" },
-        { "forall", "\u2200" }, { "part", "\u2202" }, { "exist", "\u2203" }, { "empty", "\u2205" },
-        { "nabla", "\u2207" }, { "isin", "\u2208" }, { "notin", "\u2209" }, { "ni", "\u220b" }, { "prod", "\u220f" },
-        { "sum", "\u2211" }, { "minus", "\u2212" }, { "lowast", "\u2217" }, { "radic", "\u221a" }, { "prop", "\u221d" },
-        { "infin", "\u221e" }, { "ang", "\u2220" }, { "and", "\u2227" }, { "or", "\u2228" }, { "cap", "\u2229" },
-        { "cup", "\u222a" }, { "int", "\u222b" }, { "there4", "\u2234" }, { "sim", "\u223c" }, { "cong", "\u2245" },
-        { "asymp", "\u2248" }, { "ne", "\u2260" }, { "equiv", "\u2261" }, { "le", "\u2264" }, { "ge", "\u2265" },
-        { "sub", "\u2282" }, { "sup", "\u2283" }, { "nsub", "\u2284" }, { "sube", "\u2286" }, { "supe", "\u2287" },
-        { "oplus", "\u2295" }, { "otimes", "\u2297" }, { "perp", "\u22a5" }, { "sdot", "\u22c5" },
-        { "lceil", "\u2308" }, { "rceil", "\u2309" }, { "lfloor", "\u230a" }, { "rfloor", "\u230b" },
-        { "lang", "\u2329" }, { "rang", "\u232a" }, { "loz", "\u25ca" }, { "spades", "\u2660" }, { "clubs", "\u2663" },
-        { "hearts", "\u2665" }, { "diams", "\u2666" } } );
-
+        {"fnof", "\u0192"},
+        {"Alpha", "\u0391"},
+        {"Beta", "\u0392"},
+        {"Gamma", "\u0393"},
+        {"Delta", "\u0394"},
+        {"Epsilon", "\u0395"},
+        {"Zeta", "\u0396"},
+        {"Eta", "\u0397"},
+        {"Theta", "\u0398"},
+        {"Iota", "\u0399"},
+        {"Kappa", "\u039a"},
+        {"Lambda", "\u039b"},
+        {"Mu", "\u039c"},
+        {"Nu", "\u039d"},
+        {"Xi", "\u039e"},
+        {"Omicron", "\u039f"},
+        {"Pi", "\u03a0"},
+        {"Rho", "\u03a1"},
+        {"Sigma", "\u03a3"},
+        {"Tau", "\u03a4"},
+        {"Upsilon", "\u03a5"},
+        {"Phi", "\u03a6"},
+        {"Chi", "\u03a7"},
+        {"Psi", "\u03a8"},
+        {"Omega", "\u03a9"},
+        {"alpha", "\u03b1"},
+        {"beta", "\u03b2"},
+        {"gamma", "\u03b3"},
+        {"delta", "\u03b4"},
+        {"epsilon", "\u03b5"},
+        {"zeta", "\u03b6"},
+        {"eta", "\u03b7"},
+        {"theta", "\u03b8"},
+        {"iota", "\u03b9"},
+        {"kappa", "\u03ba"},
+        {"lambda", "\u03bb"},
+        {"mu", "\u03bc"},
+        {"nu", "\u03bd"},
+        {"xi", "\u03be"},
+        {"omicron", "\u03bf"},
+        {"pi", "\u03c0"},
+        {"rho", "\u03c1"},
+        {"sigmaf", "\u03c2"},
+        {"sigma", "\u03c3"},
+        {"tau", "\u03c4"},
+        {"upsilon", "\u03c5"},
+        {"phi", "\u03c6"},
+        {"chi", "\u03c7"},
+        {"psi", "\u03c8"},
+        {"omega", "\u03c9"},
+        {"thetasym", "\u03d1"},
+        {"upsih", "\u03d2"},
+        {"piv", "\u03d6"},
+        {"bull", "\u2022"},
+        {"hellip", "\u2026"},
+        {"prime", "\u2032"},
+        {"Prime", "\u2033"},
+        {"oline", "\u203e"},
+        {"frasl", "\u2044"},
+        {"weierp", "\u2118"},
+        {"image", "\u2111"},
+        {"real", "\u211c"},
+        {"trade", "\u2122"},
+        {"alefsym", "\u2135"},
+        {"larr", "\u2190"},
+        {"uarr", "\u2191"},
+        {"rarr", "\u2192"},
+        {"darr", "\u2193"},
+        {"harr", "\u2194"},
+        {"crarr", "\u21b5"},
+        {"lArr", "\u21d0"},
+        {"uArr", "\u21d1"},
+        {"rArr", "\u21d2"},
+        {"dArr", "\u21d3"},
+        {"hArr", "\u21d4"},
+        {"forall", "\u2200"},
+        {"part", "\u2202"},
+        {"exist", "\u2203"},
+        {"empty", "\u2205"},
+        {"nabla", "\u2207"},
+        {"isin", "\u2208"},
+        {"notin", "\u2209"},
+        {"ni", "\u220b"},
+        {"prod", "\u220f"},
+        {"sum", "\u2211"},
+        {"minus", "\u2212"},
+        {"lowast", "\u2217"},
+        {"radic", "\u221a"},
+        {"prop", "\u221d"},
+        {"infin", "\u221e"},
+        {"ang", "\u2220"},
+        {"and", "\u2227"},
+        {"or", "\u2228"},
+        {"cap", "\u2229"},
+        {"cup", "\u222a"},
+        {"int", "\u222b"},
+        {"there4", "\u2234"},
+        {"sim", "\u223c"},
+        {"cong", "\u2245"},
+        {"asymp", "\u2248"},
+        {"ne", "\u2260"},
+        {"equiv", "\u2261"},
+        {"le", "\u2264"},
+        {"ge", "\u2265"},
+        {"sub", "\u2282"},
+        {"sup", "\u2283"},
+        {"nsub", "\u2284"},
+        {"sube", "\u2286"},
+        {"supe", "\u2287"},
+        {"oplus", "\u2295"},
+        {"otimes", "\u2297"},
+        {"perp", "\u22a5"},
+        {"sdot", "\u22c5"},
+        {"lceil", "\u2308"},
+        {"rceil", "\u2309"},
+        {"lfloor", "\u230a"},
+        {"rfloor", "\u230b"},
+        {"lang", "\u2329"},
+        {"rang", "\u232a"},
+        {"loz", "\u25ca"},
+        {"spades", "\u2660"},
+        {"clubs", "\u2663"},
+        {"hearts", "\u2665"},
+        {"diams", "\u2666"}
+    });
 }
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
index ca7c33cc..9f4396bc 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
@@ -18,13 +18,12 @@
 import org.codehaus.plexus.util.xml.XmlStreamReader;
 import org.codehaus.plexus.util.xml.XmlStreamReaderException;
 
-
-//TODO best handling of interning issues
+// TODO best handling of interning issues
 //   have isAllNewStringInterned ???
 
-//TODO handling surrogate pairs: http://www.unicode.org/unicode/faq/utf_bom.html#6
+// TODO handling surrogate pairs: http://www.unicode.org/unicode/faq/utf_bom.html#6
 
-//TODO review code for use of bufAbsoluteStart when keeping pos between next()/fillBuf()
+// TODO review code for use of bufAbsoluteStart when keeping pos between next()/fillBuf()
 
 /**
  * Absolutely minimal implementation of XMLPULL V1 API. Encoding handling done with XmlReader
@@ -32,31 +31,26 @@
  * @see org.codehaus.plexus.util.xml.XmlReader
  * @author Aleksander Slominski
  */
-
-public class MXParser
-    implements XmlPullParser
-{
+public class MXParser implements XmlPullParser {
     // NOTE: no interning of those strings --> by Java leng spec they MUST be already interned
-    private final static String XML_URI = "http://www.w3.org/XML/1998/namespace";
+    private static final String XML_URI = "http://www.w3.org/XML/1998/namespace";
 
-    private final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
+    private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
 
-    private final static String FEATURE_XML_ROUNDTRIP =
-        // "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
-        "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
+    private static final String FEATURE_XML_ROUNDTRIP =
+            // "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
+            "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
 
-    private final static String FEATURE_NAMES_INTERNED = "http://xmlpull.org/v1/doc/features.html#names-interned";
+    private static final String FEATURE_NAMES_INTERNED = "http://xmlpull.org/v1/doc/features.html#names-interned";
 
-    private final static String PROPERTY_XMLDECL_VERSION =
-        "http://xmlpull.org/v1/doc/properties.html#xmldecl-version";
+    private static final String PROPERTY_XMLDECL_VERSION = "http://xmlpull.org/v1/doc/properties.html#xmldecl-version";
 
-    private final static String PROPERTY_XMLDECL_STANDALONE =
-        "http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone";
+    private static final String PROPERTY_XMLDECL_STANDALONE =
+            "http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone";
 
-    private final static String PROPERTY_XMLDECL_CONTENT =
-        "http://xmlpull.org/v1/doc/properties.html#xmldecl-content";
+    private static final String PROPERTY_XMLDECL_CONTENT = "http://xmlpull.org/v1/doc/properties.html#xmldecl-content";
 
-    private final static String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location";
+    private static final String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location";
 
     /**
      * Implementation notice: the is instance variable that controls if newString() is interning.
@@ -68,19 +62,16 @@ public class MXParser
      */
     private boolean allStringsInterned;
 
-    private void resetStringCache()
-    {
+    private void resetStringCache() {
         // System.out.println("resetStringCache() minimum called");
     }
 
-    private String newString( char[] cbuf, int off, int len )
-    {
-        return new String( cbuf, off, len );
+    private String newString(char[] cbuf, int off, int len) {
+        return new String(cbuf, off, len);
     }
 
-    private String newStringIntern( char[] cbuf, int off, int len )
-    {
-        return ( new String( cbuf, off, len ) ).intern();
+    private String newStringIntern(char[] cbuf, int off, int len) {
+        return (new String(cbuf, off, len)).intern();
     }
 
     private static final boolean TRACE_SIZING = false;
@@ -129,40 +120,31 @@ private String newStringIntern( char[] cbuf, int off, int len )
      * Make sure that we have enough space to keep element stack if passed size. It will always create one additional
      * slot then current depth
      */
-    private void ensureElementsCapacity()
-    {
+    private void ensureElementsCapacity() {
         final int elStackSize = elName != null ? elName.length : 0;
-        if ( ( depth + 1 ) >= elStackSize )
-        {
+        if ((depth + 1) >= elStackSize) {
             // we add at least one extra slot ...
-            final int newSize = ( depth >= 7 ? 2 * depth : 8 ) + 2; // = lucky 7 + 1 //25
-            if ( TRACE_SIZING )
-            {
-                System.err.println( "TRACE_SIZING elStackSize " + elStackSize + " ==> " + newSize );
+            final int newSize = (depth >= 7 ? 2 * depth : 8) + 2; // = lucky 7 + 1 //25
+            if (TRACE_SIZING) {
+                System.err.println("TRACE_SIZING elStackSize " + elStackSize + " ==> " + newSize);
             }
             final boolean needsCopying = elStackSize > 0;
             String[] arr = null;
             // resue arr local variable slot
             arr = new String[newSize];
-            if ( needsCopying )
-                System.arraycopy( elName, 0, arr, 0, elStackSize );
+            if (needsCopying) System.arraycopy(elName, 0, arr, 0, elStackSize);
             elName = arr;
             arr = new String[newSize];
-            if ( needsCopying )
-                System.arraycopy( elPrefix, 0, arr, 0, elStackSize );
+            if (needsCopying) System.arraycopy(elPrefix, 0, arr, 0, elStackSize);
             elPrefix = arr;
             arr = new String[newSize];
-            if ( needsCopying )
-                System.arraycopy( elUri, 0, arr, 0, elStackSize );
+            if (needsCopying) System.arraycopy(elUri, 0, arr, 0, elStackSize);
             elUri = arr;
 
             int[] iarr = new int[newSize];
-            if ( needsCopying )
-            {
-                System.arraycopy( elNamespaceCount, 0, iarr, 0, elStackSize );
-            }
-            else
-            {
+            if (needsCopying) {
+                System.arraycopy(elNamespaceCount, 0, iarr, 0, elStackSize);
+            } else {
                 // special initialization
                 iarr[0] = 0;
             }
@@ -170,23 +152,20 @@ private void ensureElementsCapacity()
 
             // TODO: avoid using element raw name ...
             iarr = new int[newSize];
-            if ( needsCopying )
-            {
-                System.arraycopy( elRawNameEnd, 0, iarr, 0, elStackSize );
+            if (needsCopying) {
+                System.arraycopy(elRawNameEnd, 0, iarr, 0, elStackSize);
             }
             elRawNameEnd = iarr;
 
             iarr = new int[newSize];
-            if ( needsCopying )
-            {
-                System.arraycopy( elRawNameLine, 0, iarr, 0, elStackSize );
+            if (needsCopying) {
+                System.arraycopy(elRawNameLine, 0, iarr, 0, elStackSize);
             }
             elRawNameLine = iarr;
 
             final char[][] carr = new char[newSize][];
-            if ( needsCopying )
-            {
-                System.arraycopy( elRawName, 0, carr, 0, elStackSize );
+            if (needsCopying) {
+                System.arraycopy(elRawName, 0, carr, 0, elStackSize);
             }
             elRawName = carr;
             // arr = new String[newSize];
@@ -224,44 +203,35 @@ private void ensureElementsCapacity()
     // private int attributeValueEnd[];
 
     // Make sure that in attributes temporary array is enough space.
-    private void ensureAttributesCapacity( int size )
-    {
+    private void ensureAttributesCapacity(int size) {
         final int attrPosSize = attributeName != null ? attributeName.length : 0;
-        if ( size >= attrPosSize )
-        {
+        if (size >= attrPosSize) {
             final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25
-            if ( TRACE_SIZING )
-            {
-                System.err.println( "TRACE_SIZING attrPosSize " + attrPosSize + " ==> " + newSize );
+            if (TRACE_SIZING) {
+                System.err.println("TRACE_SIZING attrPosSize " + attrPosSize + " ==> " + newSize);
             }
             final boolean needsCopying = attrPosSize > 0;
             String[] arr = null;
 
             arr = new String[newSize];
-            if ( needsCopying )
-                System.arraycopy( attributeName, 0, arr, 0, attrPosSize );
+            if (needsCopying) System.arraycopy(attributeName, 0, arr, 0, attrPosSize);
             attributeName = arr;
 
             arr = new String[newSize];
-            if ( needsCopying )
-                System.arraycopy( attributePrefix, 0, arr, 0, attrPosSize );
+            if (needsCopying) System.arraycopy(attributePrefix, 0, arr, 0, attrPosSize);
             attributePrefix = arr;
 
             arr = new String[newSize];
-            if ( needsCopying )
-                System.arraycopy( attributeUri, 0, arr, 0, attrPosSize );
+            if (needsCopying) System.arraycopy(attributeUri, 0, arr, 0, attrPosSize);
             attributeUri = arr;
 
             arr = new String[newSize];
-            if ( needsCopying )
-                System.arraycopy( attributeValue, 0, arr, 0, attrPosSize );
+            if (needsCopying) System.arraycopy(attributeValue, 0, arr, 0, attrPosSize);
             attributeValue = arr;
 
-            if ( !allStringsInterned )
-            {
+            if (!allStringsInterned) {
                 final int[] iarr = new int[newSize];
-                if ( needsCopying )
-                    System.arraycopy( attributeNameHash, 0, iarr, 0, attrPosSize );
+                if (needsCopying) System.arraycopy(attributeNameHash, 0, iarr, 0, attrPosSize);
                 attributeNameHash = iarr;
             }
 
@@ -279,32 +249,26 @@ private void ensureAttributesCapacity( int size )
 
     private String namespaceUri[];
 
-    private void ensureNamespacesCapacity( int size )
-    {
+    private void ensureNamespacesCapacity(int size) {
         final int namespaceSize = namespacePrefix != null ? namespacePrefix.length : 0;
-        if ( size >= namespaceSize )
-        {
+        if (size >= namespaceSize) {
             final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25
-            if ( TRACE_SIZING )
-            {
-                System.err.println( "TRACE_SIZING namespaceSize " + namespaceSize + " ==> " + newSize );
+            if (TRACE_SIZING) {
+                System.err.println("TRACE_SIZING namespaceSize " + namespaceSize + " ==> " + newSize);
             }
             final String[] newNamespacePrefix = new String[newSize];
             final String[] newNamespaceUri = new String[newSize];
-            if ( namespacePrefix != null )
-            {
-                System.arraycopy( namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd );
-                System.arraycopy( namespaceUri, 0, newNamespaceUri, 0, namespaceEnd );
+            if (namespacePrefix != null) {
+                System.arraycopy(namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd);
+                System.arraycopy(namespaceUri, 0, newNamespaceUri, 0, namespaceEnd);
             }
             namespacePrefix = newNamespacePrefix;
             namespaceUri = newNamespaceUri;
 
-            if ( !allStringsInterned )
-            {
+            if (!allStringsInterned) {
                 final int[] newNamespacePrefixHash = new int[newSize];
-                if ( namespacePrefixHash != null )
-                {
-                    System.arraycopy( namespacePrefixHash, 0, newNamespacePrefixHash, 0, namespaceEnd );
+                if (namespacePrefixHash != null) {
+                    System.arraycopy(namespacePrefixHash, 0, newNamespacePrefixHash, 0, namespaceEnd);
                 }
                 namespacePrefixHash = newNamespacePrefixHash;
             }
@@ -313,26 +277,21 @@ private void ensureNamespacesCapacity( int size )
         }
     }
 
+    // simplistic implementation of hash function that has constant time to compute - so it also means
+    // diminishing hash quality for long strings but for XML parsing it should be good enough ...
 
-     // simplistic implementation of hash function that has constant time to compute - so it also means
-     // diminishing hash quality for long strings but for XML parsing it should be good enough ...
-
-    private static final int fastHash( char ch[], int off, int len )
-    {
-        if ( len == 0 )
-            return 0;
+    private static final int fastHash(char ch[], int off, int len) {
+        if (len == 0) return 0;
         // assert len >0
         int hash = ch[off]; // hash at beginning
         // try {
-        hash = ( hash << 7 ) + ch[off + len - 1]; // hash at the end
+        hash = (hash << 7) + ch[off + len - 1]; // hash at the end
         // } catch(ArrayIndexOutOfBoundsException aie) {
         // aie.printStackTrace(); //should never happen ...
         // throw new RuntimeException("this is violation of pre-condition");
         // }
-        if ( len > 16 )
-            hash = ( hash << 7 ) + ch[off + ( len / 4 )]; // 1/4 from beginning
-        if ( len > 8 )
-            hash = ( hash << 7 ) + ch[off + ( len / 2 )]; // 1/2 of string size ...
+        if (len > 16) hash = (hash << 7) + ch[off + (len / 4)]; // 1/4 from beginning
+        if (len > 8) hash = (hash << 7) + ch[off + (len / 2)]; // 1/2 of string size ...
         // notice that hash is at most done 3 times <<7 so shifted by 21 bits 8 bit value
         // so max result == 29 bits so it is quite just below 31 bits for long (2^32) ...
         // assert hash >= 0;
@@ -354,38 +313,32 @@ private static final int fastHash( char ch[], int off, int len )
 
     private final EntityReplacementMap replacementMapTemplate;
 
-    private void ensureEntityCapacity()
-    {
+    private void ensureEntityCapacity() {
         final int entitySize = entityReplacementBuf != null ? entityReplacementBuf.length : 0;
-        if ( entityEnd >= entitySize )
-        {
+        if (entityEnd >= entitySize) {
             final int newSize = entityEnd > 7 ? 2 * entityEnd : 8; // = lucky 7 + 1 //25
-            if ( TRACE_SIZING )
-            {
-                System.err.println( "TRACE_SIZING entitySize " + entitySize + " ==> " + newSize );
+            if (TRACE_SIZING) {
+                System.err.println("TRACE_SIZING entitySize " + entitySize + " ==> " + newSize);
             }
             final String[] newEntityName = new String[newSize];
             final char[] newEntityNameBuf[] = new char[newSize][];
             final String[] newEntityReplacement = new String[newSize];
             final char[] newEntityReplacementBuf[] = new char[newSize][];
-            if ( entityName != null )
-            {
-                System.arraycopy( entityName, 0, newEntityName, 0, entityEnd );
-                System.arraycopy( entityNameBuf, 0, newEntityNameBuf, 0, entityEnd );
-                System.arraycopy( entityReplacement, 0, newEntityReplacement, 0, entityEnd );
-                System.arraycopy( entityReplacementBuf, 0, newEntityReplacementBuf, 0, entityEnd );
+            if (entityName != null) {
+                System.arraycopy(entityName, 0, newEntityName, 0, entityEnd);
+                System.arraycopy(entityNameBuf, 0, newEntityNameBuf, 0, entityEnd);
+                System.arraycopy(entityReplacement, 0, newEntityReplacement, 0, entityEnd);
+                System.arraycopy(entityReplacementBuf, 0, newEntityReplacementBuf, 0, entityEnd);
             }
             entityName = newEntityName;
             entityNameBuf = newEntityNameBuf;
             entityReplacement = newEntityReplacement;
             entityReplacementBuf = newEntityReplacementBuf;
 
-            if ( !allStringsInterned )
-            {
+            if (!allStringsInterned) {
                 final int[] newEntityNameHash = new int[newSize];
-                if ( entityNameHash != null )
-                {
-                    System.arraycopy( entityNameHash, 0, newEntityNameHash, 0, entityEnd );
+                if (entityNameHash != null) {
+                    System.arraycopy(entityNameHash, 0, newEntityNameHash, 0, entityEnd);
                 }
                 entityNameHash = newEntityNameHash;
             }
@@ -404,9 +357,9 @@ private void ensureEntityCapacity()
 
     private float bufferLoadFactor = bufLoadFactor / 100f;
 
-	private char buf[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256];
+    private char buf[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256];
 
-	private int bufSoftLimit = (int) ( bufferLoadFactor * buf.length ); // desirable size of buffer
+    private int bufSoftLimit = (int) (bufferLoadFactor * buf.length); // desirable size of buffer
 
     private boolean preventBufferCompaction;
 
@@ -458,8 +411,7 @@ private void ensureEntityCapacity()
 
     private String xmlDeclContent;
 
-    private void reset()
-    {
+    private void reset() {
         // System.out.println("reset() called");
         location = null;
         lineNumber = 1;
@@ -504,20 +456,16 @@ private void reset()
         resetStringCache();
     }
 
-    public MXParser()
-    {
+    public MXParser() {
         replacementMapTemplate = null;
     }
 
-    public MXParser( EntityReplacementMap entityReplacementMap )
-    {
+    public MXParser(EntityReplacementMap entityReplacementMap) {
         this.replacementMapTemplate = entityReplacementMap;
     }
 
-    public void setupFromTemplate()
-    {
-        if ( replacementMapTemplate != null )
-        {
+    public void setupFromTemplate() {
+        if (replacementMapTemplate != null) {
             int length = replacementMapTemplate.entityEnd;
 
             // This is a bit cheeky, since the EntityReplacementMap contains exact-sized arrays,
@@ -540,49 +488,35 @@ public void setupFromTemplate()
      * @throws XmlPullParserException issue
      */
     @Override
-    public void setFeature( String name, boolean state )
-        throws XmlPullParserException
-    {
-        if ( name == null )
-            throw new IllegalArgumentException( "feature name should not be null" );
-        if ( FEATURE_PROCESS_NAMESPACES.equals( name ) )
-        {
-            if ( eventType != START_DOCUMENT )
-                throw new XmlPullParserException( "namespace processing feature can only be changed before parsing",
-                                                  this, null );
+    public void setFeature(String name, boolean state) throws XmlPullParserException {
+        if (name == null) throw new IllegalArgumentException("feature name should not be null");
+        if (FEATURE_PROCESS_NAMESPACES.equals(name)) {
+            if (eventType != START_DOCUMENT)
+                throw new XmlPullParserException(
+                        "namespace processing feature can only be changed before parsing", this, null);
             processNamespaces = state;
             // } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) {
             // if(type != START_DOCUMENT) throw new XmlPullParserException(
             // "namespace reporting feature can only be changed before parsing", this, null);
             // reportNsAttribs = state;
-        }
-        else if ( FEATURE_NAMES_INTERNED.equals( name ) )
-        {
-            if ( state != false )
-            {
-                throw new XmlPullParserException( "interning names in this implementation is not supported" );
+        } else if (FEATURE_NAMES_INTERNED.equals(name)) {
+            if (state != false) {
+                throw new XmlPullParserException("interning names in this implementation is not supported");
             }
-        }
-        else if ( FEATURE_PROCESS_DOCDECL.equals( name ) )
-        {
-            if ( state != false )
-            {
-                throw new XmlPullParserException( "processing DOCDECL is not supported" );
+        } else if (FEATURE_PROCESS_DOCDECL.equals(name)) {
+            if (state != false) {
+                throw new XmlPullParserException("processing DOCDECL is not supported");
             }
             // } else if(REPORT_DOCDECL.equals(name)) {
             // paramNotifyDoctype = state;
-        }
-        else if ( FEATURE_XML_ROUNDTRIP.equals( name ) )
-        {
+        } else if (FEATURE_XML_ROUNDTRIP.equals(name)) {
             // if(state == false) {
             // throw new XmlPullParserException(
             // "roundtrip feature can not be switched off");
             // }
             roundtripSupported = state;
-        }
-        else
-        {
-            throw new XmlPullParserException( "unsupported feature " + name );
+        } else {
+            throw new XmlPullParserException("unsupported feature " + name);
         }
     }
 
@@ -590,28 +524,19 @@ else if ( FEATURE_XML_ROUNDTRIP.equals( name ) )
      * Unknown properties are always returned as false
      */
     @Override
-    public boolean getFeature( String name )
-    {
-        if ( name == null )
-            throw new IllegalArgumentException( "feature name should not be null" );
-        if ( FEATURE_PROCESS_NAMESPACES.equals( name ) )
-        {
+    public boolean getFeature(String name) {
+        if (name == null) throw new IllegalArgumentException("feature name should not be null");
+        if (FEATURE_PROCESS_NAMESPACES.equals(name)) {
             return processNamespaces;
             // } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) {
             // return reportNsAttribs;
-        }
-        else if ( FEATURE_NAMES_INTERNED.equals( name ) )
-        {
+        } else if (FEATURE_NAMES_INTERNED.equals(name)) {
             return false;
-        }
-        else if ( FEATURE_PROCESS_DOCDECL.equals( name ) )
-        {
+        } else if (FEATURE_PROCESS_DOCDECL.equals(name)) {
             return false;
             // } else if(REPORT_DOCDECL.equals(name)) {
             // return paramNotifyDoctype;
-        }
-        else if ( FEATURE_XML_ROUNDTRIP.equals( name ) )
-        {
+        } else if (FEATURE_XML_ROUNDTRIP.equals(name)) {
             // return true;
             return roundtripSupported;
         }
@@ -619,116 +544,81 @@ else if ( FEATURE_XML_ROUNDTRIP.equals( name ) )
     }
 
     @Override
-    public void setProperty( String name, Object value )
-        throws XmlPullParserException
-    {
-        if ( PROPERTY_LOCATION.equals( name ) )
-        {
+    public void setProperty(String name, Object value) throws XmlPullParserException {
+        if (PROPERTY_LOCATION.equals(name)) {
             location = (String) value;
-        }
-        else
-        {
-            throw new XmlPullParserException( "unsupported property: '" + name + "'" );
+        } else {
+            throw new XmlPullParserException("unsupported property: '" + name + "'");
         }
     }
 
     @Override
-    public Object getProperty( String name )
-    {
-        if ( name == null )
-            throw new IllegalArgumentException( "property name should not be null" );
-        if ( PROPERTY_XMLDECL_VERSION.equals( name ) )
-        {
+    public Object getProperty(String name) {
+        if (name == null) throw new IllegalArgumentException("property name should not be null");
+        if (PROPERTY_XMLDECL_VERSION.equals(name)) {
             return xmlDeclVersion;
-        }
-        else if ( PROPERTY_XMLDECL_STANDALONE.equals( name ) )
-        {
+        } else if (PROPERTY_XMLDECL_STANDALONE.equals(name)) {
             return xmlDeclStandalone;
-        }
-        else if ( PROPERTY_XMLDECL_CONTENT.equals( name ) )
-        {
+        } else if (PROPERTY_XMLDECL_CONTENT.equals(name)) {
             return xmlDeclContent;
-        }
-        else if ( PROPERTY_LOCATION.equals( name ) )
-        {
+        } else if (PROPERTY_LOCATION.equals(name)) {
             return location;
         }
         return null;
     }
 
     @Override
-    public void setInput( Reader in )
-        throws XmlPullParserException
-    {
+    public void setInput(Reader in) throws XmlPullParserException {
         reset();
         reader = in;
     }
 
     @Override
-    public void setInput( java.io.InputStream inputStream, String inputEncoding )
-        throws XmlPullParserException
-    {
-        if ( inputStream == null )
-        {
-            throw new IllegalArgumentException( "input stream can not be null" );
+    public void setInput(java.io.InputStream inputStream, String inputEncoding) throws XmlPullParserException {
+        if (inputStream == null) {
+            throw new IllegalArgumentException("input stream can not be null");
         }
         Reader reader;
-        try
-        {
-            if ( inputEncoding != null )
-            {
-                reader = new InputStreamReader( inputStream, inputEncoding );
-            }
-            else
-            {
-                reader = new XmlStreamReader( inputStream, false );
-            }
-        }
-        catch ( UnsupportedEncodingException une )
-        {
-            throw new XmlPullParserException( "could not create reader for encoding " + inputEncoding + " : " + une,
-                                              this, une );
-        }
-        catch ( XmlStreamReaderException e )
-        {
-            if ( "UTF-8".equals( e.getBomEncoding() ) )
-            {
-                throw new XmlPullParserException( "UTF-8 BOM plus xml decl of " + e.getXmlEncoding() + " is incompatible", this, e );
-            }
-            if ( e.getBomEncoding() != null && e.getBomEncoding().startsWith( "UTF-16" ) )
-            {
-                throw new XmlPullParserException( "UTF-16 BOM in a " + e.getXmlEncoding() + " encoded file is incompatible", this, e );
-            }
-            throw new XmlPullParserException( "could not create reader : " + e, this, e );
-        }
-        catch ( IOException e )
-        {
-            throw new XmlPullParserException( "could not create reader : " + e, this, e );
-        }
-        setInput( reader );
+        try {
+            if (inputEncoding != null) {
+                reader = new InputStreamReader(inputStream, inputEncoding);
+            } else {
+                reader = new XmlStreamReader(inputStream, false);
+            }
+        } catch (UnsupportedEncodingException une) {
+            throw new XmlPullParserException(
+                    "could not create reader for encoding " + inputEncoding + " : " + une, this, une);
+        } catch (XmlStreamReaderException e) {
+            if ("UTF-8".equals(e.getBomEncoding())) {
+                throw new XmlPullParserException(
+                        "UTF-8 BOM plus xml decl of " + e.getXmlEncoding() + " is incompatible", this, e);
+            }
+            if (e.getBomEncoding() != null && e.getBomEncoding().startsWith("UTF-16")) {
+                throw new XmlPullParserException(
+                        "UTF-16 BOM in a " + e.getXmlEncoding() + " encoded file is incompatible", this, e);
+            }
+            throw new XmlPullParserException("could not create reader : " + e, this, e);
+        } catch (IOException e) {
+            throw new XmlPullParserException("could not create reader : " + e, this, e);
+        }
+        setInput(reader);
         // must be here as reset() was called in setInput() and has set this.inputEncoding to null ...
         this.inputEncoding = inputEncoding;
     }
 
     @Override
-    public String getInputEncoding()
-    {
+    public String getInputEncoding() {
         return inputEncoding;
     }
 
     @Override
-    public void defineEntityReplacementText( String entityName, String replacementText )
-        throws XmlPullParserException
-    {
+    public void defineEntityReplacementText(String entityName, String replacementText) throws XmlPullParserException {
         // throw new XmlPullParserException("not allowed");
 
-        if ( !replacementText.startsWith( "&#" ) && this.entityName != null && replacementText.length() > 1 )
-        {
-            String tmp = replacementText.substring( 1, replacementText.length() - 1 );
-            for ( int i = 0; i < this.entityName.length; i++ )
-            {
-                if ( this.entityName[i] != null && this.entityName[i].equals( tmp ) )
-                {
+        if (!replacementText.startsWith("&#") && this.entityName != null && replacementText.length() > 1) {
+            String tmp = replacementText.substring(1, replacementText.length() - 1);
+            for (int i = 0; i < this.entityName.length; i++) {
+                if (this.entityName[i] != null && this.entityName[i].equals(tmp)) {
                     replacementText = this.entityReplacement[i];
                 }
             }
@@ -739,14 +629,13 @@ public void defineEntityReplacementText( String entityName, String replacementTe
 
         // this is to make sure that if interning works we will take advantage of it ...
         char[] entityNameCharData = entityName.toCharArray();
-        this.entityName[entityEnd] = newString( entityNameCharData, 0, entityName.length() );
+        this.entityName[entityEnd] = newString(entityNameCharData, 0, entityName.length());
         entityNameBuf[entityEnd] = entityNameCharData;
 
         entityReplacement[entityEnd] = replacementText;
         entityReplacementBuf[entityEnd] = replacementText.toCharArray();
-        if ( !allStringsInterned )
-        {
-            entityNameHash[entityEnd] = fastHash( entityNameBuf[entityEnd], 0, entityNameBuf[entityEnd].length );
+        if (!allStringsInterned) {
+            entityNameHash[entityEnd] = fastHash(entityNameBuf[entityEnd], 0, entityNameBuf[entityEnd].length);
         }
         ++entityEnd;
         // TODO disallow < or & in entity replacement text (or ]]>???)
@@ -754,121 +643,89 @@ public void defineEntityReplacementText( String entityName, String replacementTe
     }
 
     @Override
-    public int getNamespaceCount( int depth )
-        throws XmlPullParserException
-    {
-        if ( !processNamespaces || depth == 0 )
-        {
+    public int getNamespaceCount(int depth) throws XmlPullParserException {
+        if (!processNamespaces || depth == 0) {
             return 0;
         }
         // int maxDepth = eventType == END_TAG ? this.depth + 1 : this.depth;
         // if(depth < 0 || depth > maxDepth) throw new IllegalArgumentException(
-        if ( depth < 0 || depth > this.depth )
-            throw new IllegalArgumentException( "namespace count may be for depth 0.." + this.depth + " not " + depth );
+        if (depth < 0 || depth > this.depth)
+            throw new IllegalArgumentException("namespace count may be for depth 0.." + this.depth + " not " + depth);
         return elNamespaceCount[depth];
     }
 
     @Override
-    public String getNamespacePrefix( int pos )
-        throws XmlPullParserException
-    {
+    public String getNamespacePrefix(int pos) throws XmlPullParserException {
 
         // int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd;
         // if(pos < end) {
-        if ( pos < namespaceEnd )
-        {
+        if (pos < namespaceEnd) {
             return namespacePrefix[pos];
-        }
-        else
-        {
-            throw new XmlPullParserException( "position " + pos + " exceeded number of available namespaces "
-                + namespaceEnd );
+        } else {
+            throw new XmlPullParserException(
+                    "position " + pos + " exceeded number of available namespaces " + namespaceEnd);
         }
     }
 
     @Override
-    public String getNamespaceUri( int pos )
-        throws XmlPullParserException
-    {
+    public String getNamespaceUri(int pos) throws XmlPullParserException {
         // int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd;
         // if(pos < end) {
-        if ( pos < namespaceEnd )
-        {
+        if (pos < namespaceEnd) {
             return namespaceUri[pos];
-        }
-        else
-        {
-            throw new XmlPullParserException( "position " + pos + " exceeded number of available namespaces "
-                + namespaceEnd );
+        } else {
+            throw new XmlPullParserException(
+                    "position " + pos + " exceeded number of available namespaces " + namespaceEnd);
         }
     }
 
     @Override
-    public String getNamespace( String prefix )
-    // throws XmlPullParserException
-    {
-        // int count = namespaceCount[ depth ];
-        if ( prefix != null )
-        {
-            for ( int i = namespaceEnd - 1; i >= 0; i-- )
+    public String getNamespace(String prefix)
+                // throws XmlPullParserException
             {
-                if ( prefix.equals( namespacePrefix[i] ) )
-                {
+        // int count = namespaceCount[ depth ];
+        if (prefix != null) {
+            for (int i = namespaceEnd - 1; i >= 0; i--) {
+                if (prefix.equals(namespacePrefix[i])) {
                     return namespaceUri[i];
                 }
             }
-            if ( "xml".equals( prefix ) )
-            {
+            if ("xml".equals(prefix)) {
                 return XML_URI;
-            }
-            else if ( "xmlns".equals( prefix ) )
-            {
+            } else if ("xmlns".equals(prefix)) {
                 return XMLNS_URI;
             }
-        }
-        else
-        {
-            for ( int i = namespaceEnd - 1; i >= 0; i-- )
-            {
-                if ( namespacePrefix[i] == null )
-                { // "") { //null ) { //TODO check FIXME Alek
+        } else {
+            for (int i = namespaceEnd - 1; i >= 0; i--) {
+                if (namespacePrefix[i] == null) { // "") { //null ) { //TODO check FIXME Alek
                     return namespaceUri[i];
                 }
             }
-
         }
         return null;
     }
 
     @Override
-    public int getDepth()
-    {
+    public int getDepth() {
         return depth;
     }
 
-    private static int findFragment( int bufMinPos, char[] b, int start, int end )
-    {
+    private static int findFragment(int bufMinPos, char[] b, int start, int end) {
         // System.err.println("bufStart="+bufStart+" b="+printable(new String(b, start, end - start))+" start="+start+"
         // end="+end);
-        if ( start < bufMinPos )
-        {
+        if (start < bufMinPos) {
             start = bufMinPos;
-            if ( start > end )
-                start = end;
+            if (start > end) start = end;
             return start;
         }
-        if ( end - start > 65 )
-        {
+        if (end - start > 65) {
             start = end - 10; // try to find good location
         }
         int i = start + 1;
-        while ( --i > bufMinPos )
-        {
-            if ( ( end - i ) > 65 )
-                break;
+        while (--i > bufMinPos) {
+            if ((end - i) > 65) break;
             final char c = b[i];
-            if ( c == '<' && ( start - i ) > 10 )
-                break;
+            if (c == '<' && (start - i) > 10) break;
         }
         return i;
     }
@@ -877,137 +734,104 @@ private static int findFragment( int bufMinPos, char[] b, int start, int end )
      * Return string describing current position of parsers as text 'STATE [seen %s...] @line:column'.
      */
     @Override
-    public String getPositionDescription()
-    {
+    public String getPositionDescription() {
         String fragment = null;
-        if ( posStart <= pos )
-        {
-            final int start = findFragment( 0, buf, posStart, pos );
+        if (posStart <= pos) {
+            final int start = findFragment(0, buf, posStart, pos);
             // System.err.println("start="+start);
-            if ( start < pos )
-            {
-                fragment = new String( buf, start, pos - start );
+            if (start < pos) {
+                fragment = new String(buf, start, pos - start);
             }
-            if ( bufAbsoluteStart > 0 || start > 0 )
-                fragment = "..." + fragment;
+            if (bufAbsoluteStart > 0 || start > 0) fragment = "..." + fragment;
         }
         // return " at line "+tokenizerPosRow
         // +" and column "+(tokenizerPosCol-1)
         // +(fragment != null ? " seen "+printable(fragment)+"..." : "");
-        return " " + TYPES[eventType] + ( fragment != null ? " seen " + printable( fragment ) + "..." : "" ) + " "
-            + ( location != null ? location : "" ) + "@" + getLineNumber() + ":" + getColumnNumber();
+        return " " + TYPES[eventType] + (fragment != null ? " seen " + printable(fragment) + "..." : "") + " "
+                + (location != null ? location : "") + "@" + getLineNumber() + ":" + getColumnNumber();
     }
 
     @Override
-    public int getLineNumber()
-    {
+    public int getLineNumber() {
         return lineNumber;
     }
 
     @Override
-    public int getColumnNumber()
-    {
+    public int getColumnNumber() {
         return columnNumber;
     }
 
     @Override
-    public boolean isWhitespace()
-        throws XmlPullParserException
-    {
-        if ( eventType == TEXT || eventType == CDSECT )
-        {
-            if ( usePC )
-            {
-                for ( int i = pcStart; i < pcEnd; i++ )
-                {
-                    if ( !isS( pc[i] ) )
-                        return false;
+    public boolean isWhitespace() throws XmlPullParserException {
+        if (eventType == TEXT || eventType == CDSECT) {
+            if (usePC) {
+                for (int i = pcStart; i < pcEnd; i++) {
+                    if (!isS(pc[i])) return false;
                 }
                 return true;
-            }
-            else
-            {
-                for ( int i = posStart; i < posEnd; i++ )
-                {
-                    if ( !isS( buf[i] ) )
-                        return false;
+            } else {
+                for (int i = posStart; i < posEnd; i++) {
+                    if (!isS(buf[i])) return false;
                 }
                 return true;
             }
-        }
-        else if ( eventType == IGNORABLE_WHITESPACE )
-        {
+        } else if (eventType == IGNORABLE_WHITESPACE) {
             return true;
         }
-        throw new XmlPullParserException( "no content available to check for whitespaces" );
+        throw new XmlPullParserException("no content available to check for whitespaces");
     }
 
     @Override
-    public String getText()
-    {
-        if ( eventType == START_DOCUMENT || eventType == END_DOCUMENT )
-        {
+    public String getText() {
+        if (eventType == START_DOCUMENT || eventType == END_DOCUMENT) {
             // throw new XmlPullParserException("no content available to read");
             // if(roundtripSupported) {
             // text = new String(buf, posStart, posEnd - posStart);
             // } else {
             return null;
             // }
-        }
-        else if ( eventType == ENTITY_REF )
-        {
+        } else if (eventType == ENTITY_REF) {
             return text;
         }
-        if ( text == null )
-        {
-            if ( !usePC || eventType == START_TAG || eventType == END_TAG )
-            {
-                text = new String( buf, posStart, posEnd - posStart );
-            }
-            else
-            {
-                text = new String( pc, pcStart, pcEnd - pcStart );
+        if (text == null) {
+            if (!usePC || eventType == START_TAG || eventType == END_TAG) {
+                text = new String(buf, posStart, posEnd - posStart);
+            } else {
+                text = new String(pc, pcStart, pcEnd - pcStart);
             }
         }
         return text;
     }
 
     @Override
-    public char[] getTextCharacters( int[] holderForStartAndLength )
-    {
-        if ( eventType == TEXT )
-        {
-            if ( usePC )
-            {
+    public char[] getTextCharacters(int[] holderForStartAndLength) {
+        if (eventType == TEXT) {
+            if (usePC) {
                 holderForStartAndLength[0] = pcStart;
                 holderForStartAndLength[1] = pcEnd - pcStart;
                 return pc;
-            }
-            else
-            {
+            } else {
                 holderForStartAndLength[0] = posStart;
                 holderForStartAndLength[1] = posEnd - posStart;
                 return buf;
-
             }
-        }
-        else if ( eventType == START_TAG || eventType == END_TAG || eventType == CDSECT || eventType == COMMENT
-            || eventType == ENTITY_REF || eventType == PROCESSING_INSTRUCTION || eventType == IGNORABLE_WHITESPACE
-            || eventType == DOCDECL )
-        {
+        } else if (eventType == START_TAG
+                || eventType == END_TAG
+                || eventType == CDSECT
+                || eventType == COMMENT
+                || eventType == ENTITY_REF
+                || eventType == PROCESSING_INSTRUCTION
+                || eventType == IGNORABLE_WHITESPACE
+                || eventType == DOCDECL) {
             holderForStartAndLength[0] = posStart;
             holderForStartAndLength[1] = posEnd - posStart;
             return buf;
-        }
-        else if ( eventType == START_DOCUMENT || eventType == END_DOCUMENT )
-        {
+        } else if (eventType == START_DOCUMENT || eventType == END_DOCUMENT) {
             // throw new XmlPullParserException("no content available to read");
             holderForStartAndLength[0] = holderForStartAndLength[1] = -1;
             return null;
-        }
-        else
-        {
-            throw new IllegalArgumentException( "unknown text eventType: " + eventType );
+        } else {
+            throw new IllegalArgumentException("unknown text eventType: " + eventType);
         }
         // String s = getText();
         // char[] cb = null;
@@ -1021,15 +845,11 @@ else if ( eventType == START_DOCUMENT || eventType == END_DOCUMENT )
     }
 
     @Override
-    public String getNamespace()
-    {
-        if ( eventType == START_TAG )
-        {
+    public String getNamespace() {
+        if (eventType == START_TAG) {
             // return processNamespaces ? elUri[ depth - 1 ] : NO_NAMESPACE;
             return processNamespaces ? elUri[depth] : NO_NAMESPACE;
-        }
-        else if ( eventType == END_TAG )
-        {
+        } else if (eventType == END_TAG) {
             return processNamespaces ? elUri[depth] : NO_NAMESPACE;
         }
         return null;
@@ -1052,41 +872,28 @@ else if ( eventType == END_TAG )
     }
 
     @Override
-    public String getName()
-    {
-        if ( eventType == START_TAG )
-        {
+    public String getName() {
+        if (eventType == START_TAG) {
             // return elName[ depth - 1 ] ;
             return elName[depth];
-        }
-        else if ( eventType == END_TAG )
-        {
+        } else if (eventType == END_TAG) {
             return elName[depth];
-        }
-        else if ( eventType == ENTITY_REF )
-        {
-            if ( entityRefName == null )
-            {
-                entityRefName = newString( buf, posStart, posEnd - posStart );
+        } else if (eventType == ENTITY_REF) {
+            if (entityRefName == null) {
+                entityRefName = newString(buf, posStart, posEnd - posStart);
             }
             return entityRefName;
-        }
-        else
-        {
+        } else {
             return null;
         }
     }
 
     @Override
-    public String getPrefix()
-    {
-        if ( eventType == START_TAG )
-        {
+    public String getPrefix() {
+        if (eventType == START_TAG) {
             // return elPrefix[ depth - 1 ] ;
             return elPrefix[depth];
-        }
-        else if ( eventType == END_TAG )
-        {
+        } else if (eventType == END_TAG) {
             return elPrefix[depth];
         }
         return null;
@@ -1096,132 +903,104 @@ else if ( eventType == END_TAG )
     }
 
     @Override
-    public boolean isEmptyElementTag()
-        throws XmlPullParserException
-    {
-        if ( eventType != START_TAG )
-            throw new XmlPullParserException( "parser must be on START_TAG to check for empty element", this, null );
+    public boolean isEmptyElementTag() throws XmlPullParserException {
+        if (eventType != START_TAG)
+            throw new XmlPullParserException("parser must be on START_TAG to check for empty element", this, null);
         return emptyElementTag;
     }
 
     @Override
-    public int getAttributeCount()
-    {
-        if ( eventType != START_TAG )
-            return -1;
+    public int getAttributeCount() {
+        if (eventType != START_TAG) return -1;
         return attributeCount;
     }
 
     @Override
-    public String getAttributeNamespace( int index )
-    {
-        if ( eventType != START_TAG )
-            throw new IndexOutOfBoundsException( "only START_TAG can have attributes" );
-        if ( !processNamespaces )
-            return NO_NAMESPACE;
-        if ( index < 0 || index >= attributeCount )
-            throw new IndexOutOfBoundsException( "attribute position must be 0.." + ( attributeCount - 1 ) + " and not "
-                + index );
+    public String getAttributeNamespace(int index) {
+        if (eventType != START_TAG) throw new IndexOutOfBoundsException("only START_TAG can have attributes");
+        if (!processNamespaces) return NO_NAMESPACE;
+        if (index < 0 || index >= attributeCount)
+            throw new IndexOutOfBoundsException(
+                    "attribute position must be 0.." + (attributeCount - 1) + " and not " + index);
         return attributeUri[index];
     }
 
     @Override
-    public String getAttributeName( int index )
-    {
-        if ( eventType != START_TAG )
-            throw new IndexOutOfBoundsException( "only START_TAG can have attributes" );
-        if ( index < 0 || index >= attributeCount )
-            throw new IndexOutOfBoundsException( "attribute position must be 0.." + ( attributeCount - 1 ) + " and not "
-                + index );
+    public String getAttributeName(int index) {
+        if (eventType != START_TAG) throw new IndexOutOfBoundsException("only START_TAG can have attributes");
+        if (index < 0 || index >= attributeCount)
+            throw new IndexOutOfBoundsException(
+                    "attribute position must be 0.." + (attributeCount - 1) + " and not " + index);
         return attributeName[index];
     }
 
     @Override
-    public String getAttributePrefix( int index )
-    {
-        if ( eventType != START_TAG )
-            throw new IndexOutOfBoundsException( "only START_TAG can have attributes" );
-        if ( !processNamespaces )
-            return null;
-        if ( index < 0 || index >= attributeCount )
-            throw new IndexOutOfBoundsException( "attribute position must be 0.." + ( attributeCount - 1 ) + " and not "
-                + index );
+    public String getAttributePrefix(int index) {
+        if (eventType != START_TAG) throw new IndexOutOfBoundsException("only START_TAG can have attributes");
+        if (!processNamespaces) return null;
+        if (index < 0 || index >= attributeCount)
+            throw new IndexOutOfBoundsException(
+                    "attribute position must be 0.." + (attributeCount - 1) + " and not " + index);
         return attributePrefix[index];
     }
 
     @Override
-    public String getAttributeType( int index )
-    {
-        if ( eventType != START_TAG )
-            throw new IndexOutOfBoundsException( "only START_TAG can have attributes" );
-        if ( index < 0 || index >= attributeCount )
-            throw new IndexOutOfBoundsException( "attribute position must be 0.." + ( attributeCount - 1 ) + " and not "
-                + index );
+    public String getAttributeType(int index) {
+        if (eventType != START_TAG) throw new IndexOutOfBoundsException("only START_TAG can have attributes");
+        if (index < 0 || index >= attributeCount)
+            throw new IndexOutOfBoundsException(
+                    "attribute position must be 0.." + (attributeCount - 1) + " and not " + index);
         return "CDATA";
     }
 
     @Override
-    public boolean isAttributeDefault( int index )
-    {
-        if ( eventType != START_TAG )
-            throw new IndexOutOfBoundsException( "only START_TAG can have attributes" );
-        if ( index < 0 || index >= attributeCount )
-            throw new IndexOutOfBoundsException( "attribute position must be 0.." + ( attributeCount - 1 ) + " and not "
-                + index );
+    public boolean isAttributeDefault(int index) {
+        if (eventType != START_TAG) throw new IndexOutOfBoundsException("only START_TAG can have attributes");
+        if (index < 0 || index >= attributeCount)
+            throw new IndexOutOfBoundsException(
+                    "attribute position must be 0.." + (attributeCount - 1) + " and not " + index);
         return false;
     }
 
     @Override
-    public String getAttributeValue( int index )
-    {
-        if ( eventType != START_TAG )
-            throw new IndexOutOfBoundsException( "only START_TAG can have attributes" );
-        if ( index < 0 || index >= attributeCount )
-            throw new IndexOutOfBoundsException( "attribute position must be 0.." + ( attributeCount - 1 ) + " and not "
-                + index );
+    public String getAttributeValue(int index) {
+        if (eventType != START_TAG) throw new IndexOutOfBoundsException("only START_TAG can have attributes");
+        if (index < 0 || index >= attributeCount)
+            throw new IndexOutOfBoundsException(
+                    "attribute position must be 0.." + (attributeCount - 1) + " and not " + index);
         return attributeValue[index];
     }
 
     @Override
-    public String getAttributeValue( String namespace, String name )
-    {
-        if ( eventType != START_TAG )
-            throw new IndexOutOfBoundsException( "only START_TAG can have attributes" + getPositionDescription() );
-        if ( name == null )
-        {
-            throw new IllegalArgumentException( "attribute name can not be null" );
+    public String getAttributeValue(String namespace, String name) {
+        if (eventType != START_TAG)
+            throw new IndexOutOfBoundsException("only START_TAG can have attributes" + getPositionDescription());
+        if (name == null) {
+            throw new IllegalArgumentException("attribute name can not be null");
         }
         // TODO make check if namespace is interned!!! etc. for names!!!
-        if ( processNamespaces )
-        {
-            if ( namespace == null )
-            {
+        if (processNamespaces) {
+            if (namespace == null) {
                 namespace = "";
             }
 
-            for ( int i = 0; i < attributeCount; ++i )
-            {
-                if ( ( namespace == attributeUri[i] || namespace.equals( attributeUri[i] ) )
-                    // (namespace != null && namespace.equals(attributeUri[ i ]))
-                    // taking advantage of String.intern()
-                    && name.equals( attributeName[i] ) )
-                {
+            for (int i = 0; i < attributeCount; ++i) {
+                if ((namespace == attributeUri[i] || namespace.equals(attributeUri[i]))
+                        // (namespace != null && namespace.equals(attributeUri[ i ]))
+                        // taking advantage of String.intern()
+                        && name.equals(attributeName[i])) {
                     return attributeValue[i];
                 }
             }
-        }
-        else
-        {
-            if ( namespace != null && namespace.length() == 0 )
-            {
+        } else {
+            if (namespace != null && namespace.length() == 0) {
                 namespace = null;
             }
-            if ( namespace != null )
-                throw new IllegalArgumentException( "when namespaces processing is disabled attribute namespace must be null" );
-            for ( int i = 0; i < attributeCount; ++i )
-            {
-                if ( name.equals( attributeName[i] ) )
-                {
+            if (namespace != null)
+                throw new IllegalArgumentException(
+                        "when namespaces processing is disabled attribute namespace must be null");
+            for (int i = 0; i < attributeCount; ++i) {
+                if (name.equals(attributeName[i])) {
                     return attributeValue[i];
                 }
             }
@@ -1230,37 +1009,38 @@ public String getAttributeValue( String namespace, String name )
     }
 
     @Override
-    public int getEventType()
-        throws XmlPullParserException
-    {
+    public int getEventType() throws XmlPullParserException {
         return eventType;
     }
 
     @Override
-    public void require( int type, String namespace, String name )
-        throws XmlPullParserException, IOException
-    {
-        if ( !processNamespaces && namespace != null )
-        {
-            throw new XmlPullParserException( "processing namespaces must be enabled on parser (or factory)"
-                + " to have possible namespaces declared on elements" + ( " (position:" + getPositionDescription() )
-                + ")" );
-        }
-        if ( type != getEventType() || ( namespace != null && !namespace.equals( getNamespace() ) )
-            || ( name != null && !name.equals( getName() ) ) )
-        {
-            throw new XmlPullParserException( "expected event " + TYPES[type]
-                + ( name != null ? " with name '" + name + "'" : "" )
-                + ( namespace != null && name != null ? " and" : "" )
-                + ( namespace != null ? " with namespace '" + namespace + "'" : "" ) + " but got"
-                + ( type != getEventType() ? " " + TYPES[getEventType()] : "" )
-                + ( name != null && getName() != null && !name.equals( getName() ) ? " name '" + getName() + "'" : "" )
-                + ( namespace != null && name != null && getName() != null && !name.equals( getName() )
-                    && getNamespace() != null && !namespace.equals( getNamespace() ) ? " and" : "" )
-                + ( namespace != null && getNamespace() != null && !namespace.equals( getNamespace() )
-                                ? " namespace '" + getNamespace() + "'"
-                                : "" )
-                + ( " (position:" + getPositionDescription() ) + ")" );
+    public void require(int type, String namespace, String name) throws XmlPullParserException, IOException {
+        if (!processNamespaces && namespace != null) {
+            throw new XmlPullParserException("processing namespaces must be enabled on parser (or factory)"
+                    + " to have possible namespaces declared on elements" + (" (position:" + getPositionDescription())
+                    + ")");
+        }
+        if (type != getEventType()
+                || (namespace != null && !namespace.equals(getNamespace()))
+                || (name != null && !name.equals(getName()))) {
+            throw new XmlPullParserException("expected event " + TYPES[type]
+                    + (name != null ? " with name '" + name + "'" : "")
+                    + (namespace != null && name != null ? " and" : "")
+                    + (namespace != null ? " with namespace '" + namespace + "'" : "") + " but got"
+                    + (type != getEventType() ? " " + TYPES[getEventType()] : "")
+                    + (name != null && getName() != null && !name.equals(getName()) ? " name '" + getName() + "'" : "")
+                    + (namespace != null
+                                    && name != null
+                                    && getName() != null
+                                    && !name.equals(getName())
+                                    && getNamespace() != null
+                                    && !namespace.equals(getNamespace())
+                            ? " and"
+                            : "")
+                    + (namespace != null && getNamespace() != null && !namespace.equals(getNamespace())
+                            ? " namespace '" + getNamespace() + "'"
+                            : "")
+                    + (" (position:" + getPositionDescription()) + ")");
         }
     }
 
@@ -1270,20 +1050,14 @@ && getNamespace() != null && !namespace.equals( getNamespace() ) ? " and" : "" )
      * @throws XmlPullParserException issue
      * @throws IOException io
      */
-    public void skipSubTree()
-        throws XmlPullParserException, IOException
-    {
-        require( START_TAG, null, null );
+    public void skipSubTree() throws XmlPullParserException, IOException {
+        require(START_TAG, null, null);
         int level = 1;
-        while ( level > 0 )
-        {
+        while (level > 0) {
             int eventType = next();
-            if ( eventType == END_TAG )
-            {
+            if (eventType == END_TAG) {
                 --level;
-            }
-            else if ( eventType == START_TAG )
-            {
+            } else if (eventType == START_TAG) {
                 ++level;
             }
         }
@@ -1298,9 +1072,7 @@ else if ( eventType == START_TAG )
     // }
 
     @Override
-    public String nextText()
-        throws XmlPullParserException, IOException
-    {
+    public String nextText() throws XmlPullParserException, IOException {
         // String result = null;
         // boolean onStartTag = false;
         // if(eventType == START_TAG) {
@@ -1321,96 +1093,73 @@ public String nextText()
         // "event TEXT it must be immediately followed by END_TAG", this, null);
         // }
         // return result;
-        if ( getEventType() != START_TAG )
-        {
-            throw new XmlPullParserException( "parser must be on START_TAG to read next text", this, null );
+        if (getEventType() != START_TAG) {
+            throw new XmlPullParserException("parser must be on START_TAG to read next text", this, null);
         }
         int eventType = next();
-        if ( eventType == TEXT )
-        {
+        if (eventType == TEXT) {
             final String result = getText();
             eventType = next();
-            if ( eventType != END_TAG )
-            {
-                throw new XmlPullParserException( "TEXT must be immediately followed by END_TAG and not "
-                    + TYPES[getEventType()], this, null );
+            if (eventType != END_TAG) {
+                throw new XmlPullParserException(
+                        "TEXT must be immediately followed by END_TAG and not " + TYPES[getEventType()], this, null);
             }
             return result;
-        }
-        else if ( eventType == END_TAG )
-        {
+        } else if (eventType == END_TAG) {
             return "";
-        }
-        else
-        {
-            throw new XmlPullParserException( "parser must be on START_TAG or TEXT to read text", this, null );
+        } else {
+            throw new XmlPullParserException("parser must be on START_TAG or TEXT to read text", this, null);
         }
     }
 
     @Override
-    public int nextTag()
-        throws XmlPullParserException, IOException
-    {
+    public int nextTag() throws XmlPullParserException, IOException {
         next();
-        if ( eventType == TEXT && isWhitespace() )
-        { // skip whitespace
+        if (eventType == TEXT && isWhitespace()) { // skip whitespace
             next();
         }
-        if ( eventType != START_TAG && eventType != END_TAG )
-        {
-            throw new XmlPullParserException( "expected START_TAG or END_TAG not " + TYPES[getEventType()], this,
-                                              null );
+        if (eventType != START_TAG && eventType != END_TAG) {
+            throw new XmlPullParserException("expected START_TAG or END_TAG not " + TYPES[getEventType()], this, null);
         }
         return eventType;
     }
 
     @Override
-    public int next()
-        throws XmlPullParserException, IOException
-    {
+    public int next() throws XmlPullParserException, IOException {
         tokenize = false;
         return nextImpl();
     }
 
     @Override
-    public int nextToken()
-        throws XmlPullParserException, IOException
-    {
+    public int nextToken() throws XmlPullParserException, IOException {
         tokenize = true;
         return nextImpl();
     }
 
-    private int nextImpl()
-        throws XmlPullParserException, IOException
-    {
+    private int nextImpl() throws XmlPullParserException, IOException {
         text = null;
         pcEnd = pcStart = 0;
         usePC = false;
         bufStart = posEnd;
-        if ( pastEndTag )
-        {
+        if (pastEndTag) {
             pastEndTag = false;
             --depth;
             namespaceEnd = elNamespaceCount[depth]; // less namespaces available
         }
-        if ( emptyElementTag )
-        {
+        if (emptyElementTag) {
             emptyElementTag = false;
             pastEndTag = true;
             return eventType = END_TAG;
         }
 
         // [1] document ::= prolog element Misc*
-        if ( depth > 0 )
-        {
+        if (depth > 0) {
 
-            if ( seenStartTag )
-            {
+            if (seenStartTag) {
                 seenStartTag = false;
                 return eventType = parseStartTag();
             }
-            if ( seenEndTag )
-            {
+            if (seenEndTag) {
                 seenEndTag = false;
                 return eventType = parseEndTag();
             }
@@ -1418,18 +1167,13 @@ private int nextImpl()
             // ASSUMPTION: we are _on_ first character of content or markup!!!!
             // [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*
             char ch;
-            if ( seenMarkup )
-            { // we have read ahead ...
+            if (seenMarkup) { // we have read ahead ...
                 seenMarkup = false;
                 ch = '<';
-            }
-            else if ( seenAmpersand )
-            {
+            } else if (seenAmpersand) {
                 seenAmpersand = false;
                 ch = '&';
-            }
-            else
-            {
+            } else {
                 ch = more();
             }
             posStart = pos - 1; // VERY IMPORTANT: this is correct start of event!!!
@@ -1440,67 +1184,50 @@ else if ( seenAmpersand )
             // when true TEXT data is not continuous (like ) and requires PC merging
             boolean needsMerging = false;
 
-            MAIN_LOOP: while ( true )
-            {
+            MAIN_LOOP:
+            while (true) {
                 // work on MARKUP
-                if ( ch == '<' )
-                {
-                    if ( hadCharData )
-                    {
+                if (ch == '<') {
+                    if (hadCharData) {
                         // posEnd = pos - 1;
-                        if ( tokenize )
-                        {
+                        if (tokenize) {
                             seenMarkup = true;
                             return eventType = TEXT;
                         }
                     }
                     ch = more();
-                    if ( ch == '/' )
-                    {
-                        if ( !tokenize && hadCharData )
-                        {
+                    if (ch == '/') {
+                        if (!tokenize && hadCharData) {
                             seenEndTag = true;
                             // posEnd = pos - 2;
                             return eventType = TEXT;
                         }
                         return eventType = parseEndTag();
-                    }
-                    else if ( ch == '!' )
-                    {
+                    } else if (ch == '!') {
                         ch = more();
-                        if ( ch == '-' )
-                        {
+                        if (ch == '-') {
                             // note: if(tokenize == false) posStart/End is NOT changed!!!!
                             parseComment();
-                            if ( tokenize )
-                                return eventType = COMMENT;
-                            if ( !usePC && hadCharData )
-                            {
+                            if (tokenize) return eventType = COMMENT;
+                            if (!usePC && hadCharData) {
                                 needsMerging = true;
-                            }
-                            else
-                            {
+                            } else {
                                 posStart = pos; // completely ignore comment
                             }
-                        }
-                        else if ( ch == '[' )
-                        {
+                        } else if (ch == '[') {
                             // posEnd = pos - 3;
                             // must remember previous posStart/End as it merges with content of CDATA
                             // int oldStart = posStart + bufAbsoluteStart;
                             // int oldEnd = posEnd + bufAbsoluteStart;
-                            parseCDSect( hadCharData );
-                            if ( tokenize )
-                                return eventType = CDSECT;
+                            parseCDSect(hadCharData);
+                            if (tokenize) return eventType = CDSECT;
                             final int cdStart = posStart;
                             final int cdEnd = posEnd;
                             final int cdLen = cdEnd - cdStart;
 
-                            if ( cdLen > 0 )
-                            { // was there anything inside CDATA section?
+                            if (cdLen > 0) { // was there anything inside CDATA section?
                                 hadCharData = true;
-                                if ( !usePC )
-                                {
+                                if (!usePC) {
                                     needsMerging = true;
                                 }
                             }
@@ -1542,106 +1269,76 @@ else if ( ch == '[' )
                             // needsMerging = true;
                             // }
                             // }
+                        } else {
+                            throw new XmlPullParserException(
+                                    "unexpected character in markup " + printable(ch), this, null);
                         }
-                        else
-                        {
-                            throw new XmlPullParserException( "unexpected character in markup " + printable( ch ), this,
-                                                              null );
-                        }
-                    }
-                    else if ( ch == '?' )
-                    {
+                    } else if (ch == '?') {
                         parsePI();
-                        if ( tokenize )
-                            return eventType = PROCESSING_INSTRUCTION;
-                        if ( !usePC && hadCharData )
-                        {
+                        if (tokenize) return eventType = PROCESSING_INSTRUCTION;
+                        if (!usePC && hadCharData) {
                             needsMerging = true;
-                        }
-                        else
-                        {
+                        } else {
                             posStart = pos; // completely ignore PI
                         }
 
-                    }
-                    else if ( isNameStartChar( ch ) )
-                    {
-                        if ( !tokenize && hadCharData )
-                        {
+                    } else if (isNameStartChar(ch)) {
+                        if (!tokenize && hadCharData) {
                             seenStartTag = true;
                             // posEnd = pos - 2;
                             return eventType = TEXT;
                         }
                         return eventType = parseStartTag();
-                    }
-                    else
-                    {
-                        throw new XmlPullParserException( "unexpected character in markup " + printable( ch ), this,
-                                                          null );
+                    } else {
+                        throw new XmlPullParserException("unexpected character in markup " + printable(ch), this, null);
                     }
                     // do content compaction if it makes sense!!!!
 
-                }
-                else if ( ch == '&' )
-                {
+                } else if (ch == '&') {
                     // work on ENTITY
                     // posEnd = pos - 1;
-                    if ( tokenize && hadCharData )
-                    {
+                    if (tokenize && hadCharData) {
                         seenAmpersand = true;
                         return eventType = TEXT;
                     }
                     final int oldStart = posStart + bufAbsoluteStart;
                     final int oldEnd = posEnd + bufAbsoluteStart;
                     parseEntityRef();
-                    if ( tokenize )
-                        return eventType = ENTITY_REF;
+                    if (tokenize) return eventType = ENTITY_REF;
                     // check if replacement text can be resolved !!!
-                    if ( resolvedEntityRefCharBuf == BUF_NOT_RESOLVED )
-                    {
-                        if ( entityRefName == null )
-                        {
-                            entityRefName = newString( buf, posStart, posEnd - posStart );
+                    if (resolvedEntityRefCharBuf == BUF_NOT_RESOLVED) {
+                        if (entityRefName == null) {
+                            entityRefName = newString(buf, posStart, posEnd - posStart);
                         }
-                        throw new XmlPullParserException( "could not resolve entity named '"
-                            + printable( entityRefName ) + "'", this, null );
+                        throw new XmlPullParserException(
+                                "could not resolve entity named '" + printable(entityRefName) + "'", this, null);
                     }
                     // int entStart = posStart;
                     // int entEnd = posEnd;
                     posStart = oldStart - bufAbsoluteStart;
                     posEnd = oldEnd - bufAbsoluteStart;
-                    if ( !usePC )
-                    {
-                        if ( hadCharData )
-                        {
+                    if (!usePC) {
+                        if (hadCharData) {
                             joinPC(); // posEnd is already set correctly!!!
                             needsMerging = false;
-                        }
-                        else
-                        {
+                        } else {
                             usePC = true;
                             pcStart = pcEnd = 0;
                         }
                     }
                     // assert usePC == true;
                     // write into PC replacement text - do merge for replacement text!!!!
-                    for ( char aResolvedEntity : resolvedEntityRefCharBuf )
-                    {
-                        if ( pcEnd >= pc.length )
-                        {
-                            ensurePC( pcEnd );
+                    for (char aResolvedEntity : resolvedEntityRefCharBuf) {
+                        if (pcEnd >= pc.length) {
+                            ensurePC(pcEnd);
                         }
                         pc[pcEnd++] = aResolvedEntity;
-
                     }
                     hadCharData = true;
                     // assert needsMerging == false;
-                }
-                else
-                {
+                } else {
 
-                    if ( needsMerging )
-                    {
+                    if (needsMerging) {
                         // assert usePC == false;
                         joinPC(); // posEnd is already set correctly!!!
                         // posStart = pos - 1;
@@ -1659,75 +1356,50 @@ else if ( ch == '&' )
                     // use loop locality here!!!!
                     boolean seenBracket = false;
                     boolean seenBracketBracket = false;
-                    do
-                    {
+                    do {
 
                         // check that ]]> does not show in
-                        if ( ch == ']' )
-                        {
-                            if ( seenBracket )
-                            {
+                        if (ch == ']') {
+                            if (seenBracket) {
                                 seenBracketBracket = true;
-                            }
-                            else
-                            {
+                            } else {
                                 seenBracket = true;
                             }
-                        }
-                        else if ( seenBracketBracket && ch == '>' )
-                        {
-                            throw new XmlPullParserException( "characters ]]> are not allowed in content", this, null );
-                        }
-                        else
-                        {
-                            if ( seenBracket )
-                            {
+                        } else if (seenBracketBracket && ch == '>') {
+                            throw new XmlPullParserException("characters ]]> are not allowed in content", this, null);
+                        } else {
+                            if (seenBracket) {
                                 seenBracketBracket = seenBracket = false;
                             }
                             // assert seenTwoBrackets == seenBracket == false;
                         }
-                        if ( normalizeInput )
-                        {
+                        if (normalizeInput) {
                             // deal with normalization issues ...
-                            if ( ch == '\r' )
-                            {
+                            if (ch == '\r') {
                                 normalizedCR = true;
                                 posEnd = pos - 1;
                                 // posEnd is already set
-                                if ( !usePC )
-                                {
-                                    if ( posEnd > posStart )
-                                    {
+                                if (!usePC) {
+                                    if (posEnd > posStart) {
                                         joinPC();
-                                    }
-                                    else
-                                    {
+                                    } else {
                                         usePC = true;
                                         pcStart = pcEnd = 0;
                                     }
                                 }
                                 // assert usePC == true;
-                                if ( pcEnd >= pc.length )
-                                    ensurePC( pcEnd );
+                                if (pcEnd >= pc.length) ensurePC(pcEnd);
                                 pc[pcEnd++] = '\n';
-                            }
-                            else if ( ch == '\n' )
-                            {
+                            } else if (ch == '\n') {
                                 // if(!usePC) { joinPC(); } else { if(pcEnd >= pc.length) ensurePC(); }
-                                if ( !normalizedCR && usePC )
-                                {
-                                    if ( pcEnd >= pc.length )
-                                        ensurePC( pcEnd );
+                                if (!normalizedCR && usePC) {
+                                    if (pcEnd >= pc.length) ensurePC(pcEnd);
                                     pc[pcEnd++] = '\n';
                                 }
                                 normalizedCR = false;
-                            }
-                            else
-                            {
-                                if ( usePC )
-                                {
-                                    if ( pcEnd >= pc.length )
-                                        ensurePC( pcEnd );
+                            } else {
+                                if (usePC) {
+                                    if (pcEnd >= pc.length) ensurePC(pcEnd);
                                     pc[pcEnd++] = ch;
                                 }
                                 normalizedCR = false;
@@ -1735,66 +1407,50 @@ else if ( ch == '\n' )
                         }
 
                         ch = more();
-                    }
-                    while ( ch != '<' && ch != '&' );
+                    } while (ch != '<' && ch != '&');
                     posEnd = pos - 1;
                     continue MAIN_LOOP; // skip ch = more() from below - we are already ahead ...
                 }
                 ch = more();
             } // endless while(true)
-        }
-        else
-        {
-            if ( seenRoot )
-            {
+        } else {
+            if (seenRoot) {
                 return parseEpilog();
-            }
-            else
-            {
+            } else {
                 return parseProlog();
             }
         }
     }
 
-    private int parseProlog()
-        throws XmlPullParserException, IOException
-    {
+    private int parseProlog() throws XmlPullParserException, IOException {
         // [2] prolog: ::= XMLDecl? Misc* (doctypedecl Misc*)? and look for [39] element
 
         char ch;
-        if ( seenMarkup )
-        {
+        if (seenMarkup) {
             ch = buf[pos - 1];
-        }
-        else
-        {
+        } else {
             ch = more();
         }
 
-        if ( eventType == START_DOCUMENT )
-        {
+        if (eventType == START_DOCUMENT) {
             // bootstrap parsing with getting first character input!
             // deal with BOM
             // detect BOM and crop it (Unicode int Order Mark)
-            if ( ch == '\uFFFE' )
-            {
-                throw new XmlPullParserException( "first character in input was UNICODE noncharacter (0xFFFE)"
-                    + "- input requires int swapping", this, null );
+            if (ch == '\uFFFE') {
+                throw new XmlPullParserException(
+                        "first character in input was UNICODE noncharacter (0xFFFE)" + "- input requires int swapping",
+                        this,
+                        null);
             }
-            if ( ch == '\uFEFF' )
-            {
+            if (ch == '\uFEFF') {
                 // skipping UNICODE int Order Mark (so called BOM)
                 ch = more();
-            }
-            else if ( ch == '\uFFFD' )
-            {
+            } else if (ch == '\uFFFD') {
                 // UTF-16 BOM in an UTF-8 encoded file?
                 // This is a hack...not the best way to check for BOM in UTF-16
                 ch = more();
-                if ( ch == '\uFFFD' )
-                {
-                    throw new XmlPullParserException( "UTF-16 BOM in a UTF-8 encoded file is incompatible", this,
-                                                      null );
+                if (ch == '\uFFFD') {
+                    throw new XmlPullParserException("UTF-16 BOM in a UTF-8 encoded file is incompatible", this, null);
                 }
             }
         }
@@ -1803,327 +1459,224 @@ else if ( ch == '\uFFFD' )
         posStart = pos - 1;
         final boolean normalizeIgnorableWS = tokenize && !roundtripSupported;
         boolean normalizedCR = false;
-        while ( true )
-        {
+        while (true) {
             // deal with Misc
             // [27] Misc ::= Comment | PI | S
             // deal with docdecl --> mark it!
             // else parseStartTag seen <[^/]
-            if ( ch == '<' )
-            {
-                if ( gotS && tokenize )
-                {
+            if (ch == '<') {
+                if (gotS && tokenize) {
                     posEnd = pos - 1;
                     seenMarkup = true;
                     return eventType = IGNORABLE_WHITESPACE;
                 }
                 ch = more();
-                if ( ch == '?' )
-                {
+                if (ch == '?') {
                     // check if it is 'xml'
                     // deal with XMLDecl
                     parsePI();
-                    if ( tokenize )
-                    {
+                    if (tokenize) {
                         return eventType = PROCESSING_INSTRUCTION;
                     }
-                }
-                else if ( ch == '!' )
-                {
+                } else if (ch == '!') {
                     ch = more();
-                    if ( ch == 'D' )
-                    {
-                        if ( seenDocdecl )
-                        {
-                            throw new XmlPullParserException( "only one docdecl allowed in XML document", this, null );
+                    if (ch == 'D') {
+                        if (seenDocdecl) {
+                            throw new XmlPullParserException("only one docdecl allowed in XML document", this, null);
                         }
                         seenDocdecl = true;
                         parseDocdecl();
-                        if ( tokenize )
-                            return eventType = DOCDECL;
-                    }
-                    else if ( ch == '-' )
-                    {
+                        if (tokenize) return eventType = DOCDECL;
+                    } else if (ch == '-') {
                         parseComment();
-                        if ( tokenize )
-                            return eventType = COMMENT;
+                        if (tokenize) return eventType = COMMENT;
+                    } else {
+                        throw new XmlPullParserException("unexpected markup  posStart )
-                            {
+                            if (posEnd > posStart) {
                                 joinPC();
-                            }
-                            else
-                            {
+                            } else {
                                 usePC = true;
                                 pcStart = pcEnd = 0;
                             }
                         }
                         // assert usePC == true;
-                        if ( pcEnd >= pc.length )
-                            ensurePC( pcEnd );
+                        if (pcEnd >= pc.length) ensurePC(pcEnd);
                         pc[pcEnd++] = '\n';
-                    }
-                    else if ( ch == '\n' )
-                    {
-                        if ( !normalizedCR && usePC )
-                        {
-                            if ( pcEnd >= pc.length )
-                                ensurePC( pcEnd );
+                    } else if (ch == '\n') {
+                        if (!normalizedCR && usePC) {
+                            if (pcEnd >= pc.length) ensurePC(pcEnd);
                             pc[pcEnd++] = '\n';
                         }
                         normalizedCR = false;
-                    }
-                    else
-                    {
-                        if ( usePC )
-                        {
-                            if ( pcEnd >= pc.length )
-                                ensurePC( pcEnd );
+                    } else {
+                        if (usePC) {
+                            if (pcEnd >= pc.length) ensurePC(pcEnd);
                             pc[pcEnd++] = ch;
                         }
                         normalizedCR = false;
                     }
                 }
-            }
-            else
-            {
-                throw new XmlPullParserException( "only whitespace content allowed before start tag and not "
-                    + printable( ch ), this, null );
+            } else {
+                throw new XmlPullParserException(
+                        "only whitespace content allowed before start tag and not " + printable(ch), this, null);
             }
             ch = more();
         }
     }
 
-    private int parseEpilog()
-        throws XmlPullParserException, IOException
-    {
-        if ( eventType == END_DOCUMENT )
-        {
-            throw new XmlPullParserException( "already reached end of XML input", this, null );
+    private int parseEpilog() throws XmlPullParserException, IOException {
+        if (eventType == END_DOCUMENT) {
+            throw new XmlPullParserException("already reached end of XML input", this, null);
         }
-        if ( reachedEnd )
-        {
+        if (reachedEnd) {
             return eventType = END_DOCUMENT;
         }
         boolean gotS = false;
         final boolean normalizeIgnorableWS = tokenize && !roundtripSupported;
         boolean normalizedCR = false;
-        try
-        {
+        try {
             // epilog: Misc*
             char ch;
-            if ( seenMarkup )
-            {
+            if (seenMarkup) {
                 ch = buf[pos - 1];
-            }
-            else
-            {
+            } else {
                 ch = more();
             }
             seenMarkup = false;
             posStart = pos - 1;
-            if ( !reachedEnd )
-            {
-                while ( true )
-                {
+            if (!reachedEnd) {
+                while (true) {
                     // deal with Misc
                     // [27] Misc ::= Comment | PI | S
-                    if ( ch == '<' )
-                    {
-                        if ( gotS && tokenize )
-                        {
+                    if (ch == '<') {
+                        if (gotS && tokenize) {
                             posEnd = pos - 1;
                             seenMarkup = true;
                             return eventType = IGNORABLE_WHITESPACE;
                         }
                         ch = more();
-                        if ( reachedEnd )
-                        {
+                        if (reachedEnd) {
                             break;
                         }
-                        if ( ch == '?' )
-                        {
+                        if (ch == '?') {
                             // check if it is 'xml'
                             // deal with XMLDecl
                             parsePI();
-                            if ( tokenize )
-                                return eventType = PROCESSING_INSTRUCTION;
+                            if (tokenize) return eventType = PROCESSING_INSTRUCTION;
 
-                        }
-                        else if ( ch == '!' )
-                        {
+                        } else if (ch == '!') {
                             ch = more();
-                            if ( reachedEnd )
-                            {
+                            if (reachedEnd) {
                                 break;
                             }
-                            if ( ch == 'D' )
-                            {
+                            if (ch == 'D') {
                                 parseDocdecl(); // FIXME
-                                if ( tokenize )
-                                    return eventType = DOCDECL;
-                            }
-                            else if ( ch == '-' )
-                            {
+                                if (tokenize) return eventType = DOCDECL;
+                            } else if (ch == '-') {
                                 parseComment();
-                                if ( tokenize )
-                                    return eventType = COMMENT;
-                            }
-                            else
-                            {
-                                throw new XmlPullParserException( "unexpected markup  posStart )
-                                    {
+                                    if (posEnd > posStart) {
                                         joinPC();
-                                    }
-                                    else
-                                    {
+                                    } else {
                                         usePC = true;
                                         pcStart = pcEnd = 0;
                                     }
                                 }
                                 // assert usePC == true;
-                                if ( pcEnd >= pc.length )
-                                    ensurePC( pcEnd );
+                                if (pcEnd >= pc.length) ensurePC(pcEnd);
                                 pc[pcEnd++] = '\n';
-                            }
-                            else if ( ch == '\n' )
-                            {
-                                if ( !normalizedCR && usePC )
-                                {
-                                    if ( pcEnd >= pc.length )
-                                        ensurePC( pcEnd );
+                            } else if (ch == '\n') {
+                                if (!normalizedCR && usePC) {
+                                    if (pcEnd >= pc.length) ensurePC(pcEnd);
                                     pc[pcEnd++] = '\n';
                                 }
                                 normalizedCR = false;
-                            }
-                            else
-                            {
-                                if ( usePC )
-                                {
-                                    if ( pcEnd >= pc.length )
-                                        ensurePC( pcEnd );
+                            } else {
+                                if (usePC) {
+                                    if (pcEnd >= pc.length) ensurePC(pcEnd);
                                     pc[pcEnd++] = ch;
                                 }
                                 normalizedCR = false;
                             }
                         }
-                    }
-                    else
-                    {
-                        throw new XmlPullParserException( "in epilog non whitespace content is not allowed but got "
-                            + printable( ch ), this, null );
+                    } else {
+                        throw new XmlPullParserException(
+                                "in epilog non whitespace content is not allowed but got " + printable(ch), this, null);
                     }
                     ch = more();
-                    if ( reachedEnd )
-                    {
+                    if (reachedEnd) {
                         break;
                     }
-
                 }
             }
 
             // throw Exception("unexpected content in epilog
             // catch EOFException return END_DOCUMENT
             // try {
-        }
-        catch ( EOFException ex )
-        {
+        } catch (EOFException ex) {
             reachedEnd = true;
         }
-        if ( tokenize && gotS )
-        {
+        if (tokenize && gotS) {
             posEnd = pos; // well - this is LAST available character pos
             return eventType = IGNORABLE_WHITESPACE;
         }
         return eventType = END_DOCUMENT;
     }
 
-    public int parseEndTag()
-        throws XmlPullParserException, IOException
-    {
+    public int parseEndTag() throws XmlPullParserException, IOException {
         // ASSUMPTION ch is past "'
         char ch = more();
-        if ( !isNameStartChar( ch ) )
-        {
-            throw new XmlPullParserException( "expected name start and not " + printable( ch ), this, null );
+        if (!isNameStartChar(ch)) {
+            throw new XmlPullParserException("expected name start and not " + printable(ch), this, null);
         }
         posStart = pos - 3;
         final int nameStart = pos - 1 + bufAbsoluteStart;
-        do
-        {
+        do {
             ch = more();
-        }
-        while ( isNameChar( ch ) );
+        } while (isNameChar(ch));
 
         // now we go one level down -- do checks
         // --depth; //FIXME
@@ -2134,36 +1687,39 @@ public int parseEndTag()
         // int last = pos - 1;
         int off = nameStart - bufAbsoluteStart;
         // final int len = last - off;
-        final int len = ( pos - 1 ) - off;
+        final int len = (pos - 1) - off;
         final char[] cbuf = elRawName[depth];
-        if ( elRawNameEnd[depth] != len )
-        {
+        if (elRawNameEnd[depth] != len) {
             // construct strings for exception
-            final String startname = new String( cbuf, 0, elRawNameEnd[depth] );
-            final String endname = new String( buf, off, len );
-            throw new XmlPullParserException( "end tag name  must match start tag name <" + startname
-                + ">" + " from line " + elRawNameLine[depth], this, null );
-        }
-        for ( int i = 0; i < len; i++ )
-        {
-            if ( buf[off++] != cbuf[i] )
-            {
+            final String startname = new String(cbuf, 0, elRawNameEnd[depth]);
+            final String endname = new String(buf, off, len);
+            throw new XmlPullParserException(
+                    "end tag name  must match start tag name <" + startname + ">" + " from line "
+                            + elRawNameLine[depth],
+                    this,
+                    null);
+        }
+        for (int i = 0; i < len; i++) {
+            if (buf[off++] != cbuf[i]) {
                 // construct strings for exception
-                final String startname = new String( cbuf, 0, len );
-                final String endname = new String( buf, off - i - 1, len );
-                throw new XmlPullParserException( "end tag name  must be the same as start tag <"
-                    + startname + ">" + " from line " + elRawNameLine[depth], this, null );
+                final String startname = new String(cbuf, 0, len);
+                final String endname = new String(buf, off - i - 1, len);
+                throw new XmlPullParserException(
+                        "end tag name  must be the same as start tag <" + startname + ">"
+                                + " from line " + elRawNameLine[depth],
+                        this,
+                        null);
             }
         }
 
-        while ( isS( ch ) )
-        {
+        while (isS(ch)) {
             ch = more();
         } // skip additional white spaces
-        if ( ch != '>' )
-        {
-            throw new XmlPullParserException( "expected > to finsh end tag not " + printable( ch ) + " from line "
-                + elRawNameLine[depth], this, null );
+        if (ch != '>') {
+            throw new XmlPullParserException(
+                    "expected > to finsh end tag not " + printable(ch) + " from line " + elRawNameLine[depth],
+                    this,
+                    null);
         }
 
         // namespaceEnd = elNamespaceCount[ depth ]; //FIXME
@@ -2173,9 +1729,7 @@ public int parseEndTag()
         return eventType = END_TAG;
     }
 
-    public int parseStartTag()
-        throws XmlPullParserException, IOException
-    {
+    public int parseStartTag() throws XmlPullParserException, IOException {
         // ASSUMPTION ch is past '
         // [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
@@ -2189,19 +1743,16 @@ public int parseStartTag()
         final int nameStart = pos - 1 + bufAbsoluteStart;
         int colonPos = -1;
         char ch = buf[pos - 1];
-        if ( ch == ':' && processNamespaces )
-            throw new XmlPullParserException( "when namespaces processing enabled colon can not be at element name start",
-                                              this, null );
-        while ( true )
-        {
+        if (ch == ':' && processNamespaces)
+            throw new XmlPullParserException(
+                    "when namespaces processing enabled colon can not be at element name start", this, null);
+        while (true) {
             ch = more();
-            if ( !isNameChar( ch ) )
-                break;
-            if ( ch == ':' && processNamespaces )
-            {
-                if ( colonPos != -1 )
-                    throw new XmlPullParserException( "only one colon is allowed in name of element when namespaces are enabled",
-                                                      this, null );
+            if (!isNameChar(ch)) break;
+            if (ch == ':' && processNamespaces) {
+                if (colonPos != -1)
+                    throw new XmlPullParserException(
+                            "only one colon is allowed in name of element when namespaces are enabled", this, null);
                 colonPos = pos - 1 + bufAbsoluteStart;
             }
         }
@@ -2211,12 +1762,11 @@ public int parseStartTag()
 
         // TODO check for efficient interning and then use elRawNameInterned!!!!
 
-        int elLen = ( pos - 1 ) - ( nameStart - bufAbsoluteStart );
-        if ( elRawName[depth] == null || elRawName[depth].length < elLen )
-        {
+        int elLen = (pos - 1) - (nameStart - bufAbsoluteStart);
+        if (elRawName[depth] == null || elRawName[depth].length < elLen) {
             elRawName[depth] = new char[2 * elLen];
         }
-        System.arraycopy( buf, nameStart - bufAbsoluteStart, elRawName[depth], 0, elLen );
+        System.arraycopy(buf, nameStart - bufAbsoluteStart, elRawName[depth], 0, elLen);
         elRawNameEnd[depth] = elLen;
         elRawNameLine[depth] = lineNumber;
 
@@ -2224,79 +1774,57 @@ public int parseStartTag()
 
         // work on prefixes and namespace URI
         String prefix = null;
-        if ( processNamespaces )
-        {
-            if ( colonPos != -1 )
-            {
-                prefix = elPrefix[depth] = newString( buf, nameStart - bufAbsoluteStart, colonPos - nameStart );
-                name = elName[depth] = newString( buf, colonPos + 1 - bufAbsoluteStart,
-                                                  // (pos -1) - (colonPos + 1));
-                                                  pos - 2 - ( colonPos - bufAbsoluteStart ) );
-            }
-            else
-            {
+        if (processNamespaces) {
+            if (colonPos != -1) {
+                prefix = elPrefix[depth] = newString(buf, nameStart - bufAbsoluteStart, colonPos - nameStart);
+                name = elName[depth] = newString(
+                        buf,
+                        colonPos + 1 - bufAbsoluteStart,
+                        // (pos -1) - (colonPos + 1));
+                        pos - 2 - (colonPos - bufAbsoluteStart));
+            } else {
                 prefix = elPrefix[depth] = null;
-                name = elName[depth] = newString( buf, nameStart - bufAbsoluteStart, elLen );
+                name = elName[depth] = newString(buf, nameStart - bufAbsoluteStart, elLen);
             }
-        }
-        else
-        {
-
-            name = elName[depth] = newString( buf, nameStart - bufAbsoluteStart, elLen );
+        } else {
 
+            name = elName[depth] = newString(buf, nameStart - bufAbsoluteStart, elLen);
         }
 
-        while ( true )
-        {
+        while (true) {
 
-            while ( isS( ch ) )
-            {
+            while (isS(ch)) {
                 ch = more();
             } // skip additional white spaces
 
-            if ( ch == '>' )
-            {
+            if (ch == '>') {
                 break;
-            }
-            else if ( ch == '/' )
-            {
-                if ( emptyElementTag )
-                    throw new XmlPullParserException( "repeated / in tag declaration", this, null );
+            } else if (ch == '/') {
+                if (emptyElementTag) throw new XmlPullParserException("repeated / in tag declaration", this, null);
                 emptyElementTag = true;
                 ch = more();
-                if ( ch != '>' )
-                    throw new XmlPullParserException( "expected > to end empty tag not " + printable( ch ), this,
-                                                      null );
+                if (ch != '>')
+                    throw new XmlPullParserException("expected > to end empty tag not " + printable(ch), this, null);
                 break;
-            }
-            else if ( isNameStartChar( ch ) )
-            {
+            } else if (isNameStartChar(ch)) {
                 ch = parseAttribute();
                 ch = more();
-            }
-            else
-            {
-                throw new XmlPullParserException( "start tag unexpected character " + printable( ch ), this, null );
+            } else {
+                throw new XmlPullParserException("start tag unexpected character " + printable(ch), this, null);
             }
             // ch = more(); // skip space
         }
 
         // now when namespaces were declared we can resolve them
-        if ( processNamespaces )
-        {
-            String uri = getNamespace( prefix );
-            if ( uri == null )
-            {
-                if ( prefix == null )
-                { // no prefix and no uri => use default namespace
+        if (processNamespaces) {
+            String uri = getNamespace(prefix);
+            if (uri == null) {
+                if (prefix == null) { // no prefix and no uri => use default namespace
                     uri = NO_NAMESPACE;
+                } else {
+                    throw new XmlPullParserException(
+                            "could not determine namespace bound to element prefix " + prefix, this, null);
                 }
-                else
-                {
-                    throw new XmlPullParserException( "could not determine namespace bound to element prefix " + prefix,
-                                                      this, null );
-                }
-
             }
             elUri[depth] = uri;
 
@@ -2305,22 +1833,16 @@ else if ( isNameStartChar( ch ) )
             // uri = "";
             // }
             // resolve attribute namespaces
-            for ( int i = 0; i < attributeCount; i++ )
-            {
+            for (int i = 0; i < attributeCount; i++) {
                 final String attrPrefix = attributePrefix[i];
-                if ( attrPrefix != null )
-                {
-                    final String attrUri = getNamespace( attrPrefix );
-                    if ( attrUri == null )
-                    {
-                        throw new XmlPullParserException( "could not determine namespace bound to attribute prefix "
-                            + attrPrefix, this, null );
-
+                if (attrPrefix != null) {
+                    final String attrUri = getNamespace(attrPrefix);
+                    if (attrUri == null) {
+                        throw new XmlPullParserException(
+                                "could not determine namespace bound to attribute prefix " + attrPrefix, this, null);
                     }
                     attributeUri[i] = attrUri;
-                }
-                else
-                {
+                } else {
                     attributeUri[i] = NO_NAMESPACE;
                 }
             }
@@ -2329,51 +1851,41 @@ else if ( isNameStartChar( ch ) )
             // [ WFC: Unique Att Spec ]
             // check namespaced attribute uniqueness constraint!!!
 
-            for ( int i = 1; i < attributeCount; i++ )
-            {
-                for ( int j = 0; j < i; j++ )
-                {
-                    if ( attributeUri[j] == attributeUri[i]
-                        && ( allStringsInterned && attributeName[j].equals( attributeName[i] )
-                            || ( !allStringsInterned && attributeNameHash[j] == attributeNameHash[i]
-                                && attributeName[j].equals( attributeName[i] ) ) )
-
-                    )
-                    {
+            for (int i = 1; i < attributeCount; i++) {
+                for (int j = 0; j < i; j++) {
+                    if (attributeUri[j] == attributeUri[i]
+                            && (allStringsInterned && attributeName[j].equals(attributeName[i])
+                                    || (!allStringsInterned
+                                            && attributeNameHash[j] == attributeNameHash[i]
+                                            && attributeName[j].equals(attributeName[i])))) {
+
                         // prepare data for nice error message?
                         String attr1 = attributeName[j];
-                        if ( attributeUri[j] != null )
-                            attr1 = attributeUri[j] + ":" + attr1;
+                        if (attributeUri[j] != null) attr1 = attributeUri[j] + ":" + attr1;
                         String attr2 = attributeName[i];
-                        if ( attributeUri[i] != null )
-                            attr2 = attributeUri[i] + ":" + attr2;
-                        throw new XmlPullParserException( "duplicated attributes " + attr1 + " and " + attr2, this,
-                                                          null );
+                        if (attributeUri[i] != null) attr2 = attributeUri[i] + ":" + attr2;
+                        throw new XmlPullParserException(
+                                "duplicated attributes " + attr1 + " and " + attr2, this, null);
                     }
                 }
             }
 
-        }
-        else
-        { // ! processNamespaces
+        } else { // ! processNamespaces
 
             // [ WFC: Unique Att Spec ]
             // check raw attribute uniqueness constraint!!!
-            for ( int i = 1; i < attributeCount; i++ )
-            {
-                for ( int j = 0; j < i; j++ )
-                {
-                    if ( ( allStringsInterned && attributeName[j].equals( attributeName[i] )
-                        || ( !allStringsInterned && attributeNameHash[j] == attributeNameHash[i]
-                            && attributeName[j].equals( attributeName[i] ) ) )
-
-                    )
-                    {
+            for (int i = 1; i < attributeCount; i++) {
+                for (int j = 0; j < i; j++) {
+                    if ((allStringsInterned && attributeName[j].equals(attributeName[i])
+                            || (!allStringsInterned
+                                    && attributeNameHash[j] == attributeNameHash[i]
+                                    && attributeName[j].equals(attributeName[i])))) {
+
                         // prepare data for nice error message?
                         final String attr1 = attributeName[j];
                         final String attr2 = attributeName[i];
-                        throw new XmlPullParserException( "duplicated attributes " + attr1 + " and " + attr2, this,
-                                                          null );
+                        throw new XmlPullParserException(
+                                "duplicated attributes " + attr1 + " and " + attr2, this, null);
                     }
                 }
             }
@@ -2384,9 +1896,7 @@ else if ( isNameStartChar( ch ) )
         return eventType = START_TAG;
     }
 
-    private char parseAttribute()
-        throws XmlPullParserException, IOException
-    {
+    private char parseAttribute() throws XmlPullParserException, IOException {
         // parse attribute
         // [41] Attribute ::= Name Eq AttValue
         // [WFC: No External Entity References]
@@ -2395,144 +1905,115 @@ private char parseAttribute()
         final int nameStart = pos - 1 + bufAbsoluteStart;
         int colonPos = -1;
         char ch = buf[pos - 1];
-        if ( ch == ':' && processNamespaces )
-            throw new XmlPullParserException( "when namespaces processing enabled colon can not be at attribute name start",
-                                              this, null );
+        if (ch == ':' && processNamespaces)
+            throw new XmlPullParserException(
+                    "when namespaces processing enabled colon can not be at attribute name start", this, null);
 
         boolean startsWithXmlns = processNamespaces && ch == 'x';
         int xmlnsPos = 0;
 
         ch = more();
-        while ( isNameChar( ch ) )
-        {
-            if ( processNamespaces )
-            {
-                if ( startsWithXmlns && xmlnsPos < 5 )
-                {
+        while (isNameChar(ch)) {
+            if (processNamespaces) {
+                if (startsWithXmlns && xmlnsPos < 5) {
                     ++xmlnsPos;
-                    if ( xmlnsPos == 1 )
-                    {
-                        if ( ch != 'm' )
-                            startsWithXmlns = false;
-                    }
-                    else if ( xmlnsPos == 2 )
-                    {
-                        if ( ch != 'l' )
-                            startsWithXmlns = false;
-                    }
-                    else if ( xmlnsPos == 3 )
-                    {
-                        if ( ch != 'n' )
-                            startsWithXmlns = false;
-                    }
-                    else if ( xmlnsPos == 4 )
-                    {
-                        if ( ch != 's' )
-                            startsWithXmlns = false;
-                    }
-                    else if ( xmlnsPos == 5 )
-                    {
-                        if ( ch != ':' )
-                            throw new XmlPullParserException( "after xmlns in attribute name must be colon"
-                                + "when namespaces are enabled", this, null );
+                    if (xmlnsPos == 1) {
+                        if (ch != 'm') startsWithXmlns = false;
+                    } else if (xmlnsPos == 2) {
+                        if (ch != 'l') startsWithXmlns = false;
+                    } else if (xmlnsPos == 3) {
+                        if (ch != 'n') startsWithXmlns = false;
+                    } else if (xmlnsPos == 4) {
+                        if (ch != 's') startsWithXmlns = false;
+                    } else if (xmlnsPos == 5) {
+                        if (ch != ':')
+                            throw new XmlPullParserException(
+                                    "after xmlns in attribute name must be colon" + "when namespaces are enabled",
+                                    this,
+                                    null);
                         // colonPos = pos - 1 + bufAbsoluteStart;
                     }
                 }
-                if ( ch == ':' )
-                {
-                    if ( colonPos != -1 )
-                        throw new XmlPullParserException( "only one colon is allowed in attribute name"
-                            + " when namespaces are enabled", this, null );
+                if (ch == ':') {
+                    if (colonPos != -1)
+                        throw new XmlPullParserException(
+                                "only one colon is allowed in attribute name" + " when namespaces are enabled",
+                                this,
+                                null);
                     colonPos = pos - 1 + bufAbsoluteStart;
                 }
             }
             ch = more();
         }
 
-        ensureAttributesCapacity( attributeCount );
+        ensureAttributesCapacity(attributeCount);
 
         // --- start processing attributes
         String name = null;
         String prefix = null;
         // work on prefixes and namespace URI
-        if ( processNamespaces )
-        {
-            if ( xmlnsPos < 4 )
-                startsWithXmlns = false;
-            if ( startsWithXmlns )
-            {
-                if ( colonPos != -1 )
-                {
+        if (processNamespaces) {
+            if (xmlnsPos < 4) startsWithXmlns = false;
+            if (startsWithXmlns) {
+                if (colonPos != -1) {
                     // prefix = attributePrefix[ attributeCount ] = null;
-                    final int nameLen = pos - 2 - ( colonPos - bufAbsoluteStart );
-                    if ( nameLen == 0 )
-                    {
-                        throw new XmlPullParserException( "namespace prefix is required after xmlns: "
-                            + " when namespaces are enabled", this, null );
+                    final int nameLen = pos - 2 - (colonPos - bufAbsoluteStart);
+                    if (nameLen == 0) {
+                        throw new XmlPullParserException(
+                                "namespace prefix is required after xmlns: " + " when namespaces are enabled",
+                                this,
+                                null);
                     }
                     name = // attributeName[ attributeCount ] =
-                        newString( buf, colonPos - bufAbsoluteStart + 1, nameLen );
+                            newString(buf, colonPos - bufAbsoluteStart + 1, nameLen);
                     // pos - 1 - (colonPos + 1 - bufAbsoluteStart)
                 }
-            }
-            else
-            {
-                if ( colonPos != -1 )
-                {
+            } else {
+                if (colonPos != -1) {
                     int prefixLen = colonPos - nameStart;
-                    prefix =
-                        attributePrefix[attributeCount] = newString( buf, nameStart - bufAbsoluteStart, prefixLen );
+                    prefix = attributePrefix[attributeCount] = newString(buf, nameStart - bufAbsoluteStart, prefixLen);
                     // colonPos - (nameStart - bufAbsoluteStart));
-                    int nameLen = pos - 2 - ( colonPos - bufAbsoluteStart );
-                    name = attributeName[attributeCount] = newString( buf, colonPos - bufAbsoluteStart + 1, nameLen );
+                    int nameLen = pos - 2 - (colonPos - bufAbsoluteStart);
+                    name = attributeName[attributeCount] = newString(buf, colonPos - bufAbsoluteStart + 1, nameLen);
                     // pos - 1 - (colonPos + 1 - bufAbsoluteStart));
 
                     // name.substring(0, colonPos-nameStart);
-                }
-                else
-                {
+                } else {
                     prefix = attributePrefix[attributeCount] = null;
                     name = attributeName[attributeCount] =
-                        newString( buf, nameStart - bufAbsoluteStart, pos - 1 - ( nameStart - bufAbsoluteStart ) );
+                            newString(buf, nameStart - bufAbsoluteStart, pos - 1 - (nameStart - bufAbsoluteStart));
                 }
-                if ( !allStringsInterned )
-                {
+                if (!allStringsInterned) {
                     attributeNameHash[attributeCount] = name.hashCode();
                 }
             }
 
-        }
-        else
-        {
+        } else {
             // retrieve name
             name = attributeName[attributeCount] =
-                newString( buf, nameStart - bufAbsoluteStart, pos - 1 - ( nameStart - bufAbsoluteStart ) );
+                    newString(buf, nameStart - bufAbsoluteStart, pos - 1 - (nameStart - bufAbsoluteStart));
             //// assert name != null;
-            if ( !allStringsInterned )
-            {
+            if (!allStringsInterned) {
                 attributeNameHash[attributeCount] = name.hashCode();
             }
         }
 
         // [25] Eq ::= S? '=' S?
-        while ( isS( ch ) )
-        {
+        while (isS(ch)) {
             ch = more();
         } // skip additional spaces
-        if ( ch != '=' )
-            throw new XmlPullParserException( "expected = after attribute name", this, null );
+        if (ch != '=') throw new XmlPullParserException("expected = after attribute name", this, null);
         ch = more();
-        while ( isS( ch ) )
-        {
+        while (isS(ch)) {
             ch = more();
         } // skip additional spaces
 
         // [10] AttValue ::= '"' ([^<&"] | Reference)* '"'
         // | "'" ([^<&'] | Reference)* "'"
         final char delimit = ch;
-        if ( delimit != '"' && delimit != '\'' )
-            throw new XmlPullParserException( "attribute value must start with quotation or apostrophe not "
-                + printable( delimit ), this, null );
+        if (delimit != '"' && delimit != '\'')
+            throw new XmlPullParserException(
+                    "attribute value must start with quotation or apostrophe not " + printable(delimit), this, null);
         // parse until delimit or < and resolve Reference
         // [67] Reference ::= EntityRef | CharRef
         // int valueStart = pos + bufAbsoluteStart;
@@ -2542,95 +2023,68 @@ else if ( xmlnsPos == 5 )
         pcStart = pcEnd;
         posStart = pos;
 
-        while ( true )
-        {
+        while (true) {
             ch = more();
-            if ( ch == delimit )
-            {
+            if (ch == delimit) {
                 break;
             }
-            if ( ch == '<' )
-            {
-                throw new XmlPullParserException( "markup not allowed inside attribute value - illegal < ", this,
-                                                  null );
+            if (ch == '<') {
+                throw new XmlPullParserException("markup not allowed inside attribute value - illegal < ", this, null);
             }
-            if ( ch == '&' )
-            {
+            if (ch == '&') {
                 extractEntityRef();
-            }
-            else if ( ch == '\t' || ch == '\n' || ch == '\r' )
-            {
+            } else if (ch == '\t' || ch == '\n' || ch == '\r') {
                 // do attribute value normalization
                 // as described in http://www.w3.org/TR/REC-xml#AVNormalize
                 // TODO add test for it form spec ...
                 // handle EOL normalization ...
-                if ( !usePC )
-                {
+                if (!usePC) {
                     posEnd = pos - 1;
-                    if ( posEnd > posStart )
-                    {
+                    if (posEnd > posStart) {
                         joinPC();
-                    }
-                    else
-                    {
+                    } else {
                         usePC = true;
                         pcEnd = pcStart = 0;
                     }
                 }
                 // assert usePC == true;
-                if ( pcEnd >= pc.length )
-                    ensurePC( pcEnd );
-                if ( ch != '\n' || !normalizedCR )
-                {
+                if (pcEnd >= pc.length) ensurePC(pcEnd);
+                if (ch != '\n' || !normalizedCR) {
                     pc[pcEnd++] = ' '; // '\n';
                 }
 
-            }
-            else
-            {
-                if ( usePC )
-                {
-                    if ( pcEnd >= pc.length )
-                        ensurePC( pcEnd );
+            } else {
+                if (usePC) {
+                    if (pcEnd >= pc.length) ensurePC(pcEnd);
                     pc[pcEnd++] = ch;
                 }
             }
             normalizedCR = ch == '\r';
         }
 
-        if ( processNamespaces && startsWithXmlns )
-        {
+        if (processNamespaces && startsWithXmlns) {
             String ns = null;
-            if ( !usePC )
-            {
-                ns = newStringIntern( buf, posStart, pos - 1 - posStart );
+            if (!usePC) {
+                ns = newStringIntern(buf, posStart, pos - 1 - posStart);
+            } else {
+                ns = newStringIntern(pc, pcStart, pcEnd - pcStart);
             }
-            else
-            {
-                ns = newStringIntern( pc, pcStart, pcEnd - pcStart );
-            }
-            ensureNamespacesCapacity( namespaceEnd );
+            ensureNamespacesCapacity(namespaceEnd);
             int prefixHash = -1;
-            if ( colonPos != -1 )
-            {
-                if ( ns.length() == 0 )
-                {
-                    throw new XmlPullParserException( "non-default namespace can not be declared to be empty string",
-                                                      this, null );
+            if (colonPos != -1) {
+                if (ns.length() == 0) {
+                    throw new XmlPullParserException(
+                            "non-default namespace can not be declared to be empty string", this, null);
                 }
                 // declare new namespace
                 namespacePrefix[namespaceEnd] = name;
-                if ( !allStringsInterned )
-                {
+                if (!allStringsInterned) {
                     prefixHash = namespacePrefixHash[namespaceEnd] = name.hashCode();
                 }
-            }
-            else
-            {
+            } else {
                 // declare new default namespace...
                 namespacePrefix[namespaceEnd] = null; // ""; //null; //TODO check FIXME Alek
-                if ( !allStringsInterned )
-                {
+                if (!allStringsInterned) {
                     prefixHash = namespacePrefixHash[namespaceEnd] = -1;
                 }
             }
@@ -2638,29 +2092,25 @@ else if ( ch == '\t' || ch == '\n' || ch == '\r' )
 
             // detect duplicate namespace declarations!!!
             final int startNs = elNamespaceCount[depth - 1];
-            for ( int i = namespaceEnd - 1; i >= startNs; --i )
-            {
-                if ( ( ( allStringsInterned || name == null ) && namespacePrefix[i] == name ) || ( !allStringsInterned
-                    && name != null && namespacePrefixHash[i] == prefixHash && name.equals( namespacePrefix[i] ) ) )
-                {
+            for (int i = namespaceEnd - 1; i >= startNs; --i) {
+                if (((allStringsInterned || name == null) && namespacePrefix[i] == name)
+                        || (!allStringsInterned
+                                && name != null
+                                && namespacePrefixHash[i] == prefixHash
+                                && name.equals(namespacePrefix[i]))) {
                     final String s = name == null ? "default" : "'" + name + "'";
-                    throw new XmlPullParserException( "duplicated namespace declaration for " + s + " prefix", this,
-                                                      null );
+                    throw new XmlPullParserException(
+                            "duplicated namespace declaration for " + s + " prefix", this, null);
                 }
             }
 
             ++namespaceEnd;
 
-        }
-        else
-        {
-            if ( !usePC )
-            {
-                attributeValue[attributeCount] = new String( buf, posStart, pos - 1 - posStart );
-            }
-            else
-            {
-                attributeValue[attributeCount] = new String( pc, pcStart, pcEnd - pcStart );
+        } else {
+            if (!usePC) {
+                attributeValue[attributeCount] = new String(buf, posStart, pos - 1 - posStart);
+            } else {
+                attributeValue[attributeCount] = new String(pc, pcStart, pcEnd - pcStart);
             }
             ++attributeCount;
         }
@@ -2672,11 +2122,11 @@ else if ( ch == '\t' || ch == '\n' || ch == '\r' )
     private static final char[] BUF_NOT_RESOLVED = new char[0];
 
     // predefined entity refs
-    private static final char[] BUF_LT = new char[] { '<' };
-    private static final char[] BUF_AMP = new char[] { '&' };
-    private static final char[] BUF_GT = new char[] { '>' };
-    private static final char[] BUF_APO = new char[] { '\'' };
-    private static final char[] BUF_QUOT = new char[] { '"' };
+    private static final char[] BUF_LT = new char[] {'<'};
+    private static final char[] BUF_AMP = new char[] {'&'};
+    private static final char[] BUF_GT = new char[] {'>'};
+    private static final char[] BUF_APO = new char[] {'\''};
+    private static final char[] BUF_QUOT = new char[] {'"'};
 
     private char[] resolvedEntityRefCharBuf = BUF_NOT_RESOLVED;
 
@@ -2689,9 +2139,7 @@ else if ( ch == '\t' || ch == '\n' || ch == '\r' )
      * @throws XmlPullParserException if invalid XML is detected.
      * @throws IOException if an I/O error is found.
      */
-    private int parseCharOrPredefinedEntityRef()
-        throws XmlPullParserException, IOException
-    {
+    private int parseCharOrPredefinedEntityRef() throws XmlPullParserException, IOException {
         // entity reference http://www.w3.org/TR/2000/REC-xml-20001006#NT-Reference
         // [67] Reference ::= EntityRef | CharRef
 
@@ -2701,125 +2149,96 @@ private int parseCharOrPredefinedEntityRef()
         int len = 0;
         resolvedEntityRefCharBuf = BUF_NOT_RESOLVED;
         char ch = more();
-        if ( ch == '#' )
-        {
+        if (ch == '#') {
             // parse character reference
 
             char charRef = 0;
             ch = more();
             StringBuilder sb = new StringBuilder();
-            boolean isHex = ( ch == 'x' );
+            boolean isHex = (ch == 'x');
 
-            if ( isHex )
-            {
+            if (isHex) {
                 // encoded in hex
-                while ( true )
-                {
+                while (true) {
                     ch = more();
-                    if ( ch >= '0' && ch <= '9' )
-                    {
-                        charRef = (char) ( charRef * 16 + ( ch - '0' ) );
-                        sb.append( ch );
-                    }
-                    else if ( ch >= 'a' && ch <= 'f' )
-                    {
-                        charRef = (char) ( charRef * 16 + ( ch - ( 'a' - 10 ) ) );
-                        sb.append( ch );
-                    }
-                    else if ( ch >= 'A' && ch <= 'F' )
-                    {
-                        charRef = (char) ( charRef * 16 + ( ch - ( 'A' - 10 ) ) );
-                        sb.append( ch );
-                    }
-                    else if ( ch == ';' )
-                    {
+                    if (ch >= '0' && ch <= '9') {
+                        charRef = (char) (charRef * 16 + (ch - '0'));
+                        sb.append(ch);
+                    } else if (ch >= 'a' && ch <= 'f') {
+                        charRef = (char) (charRef * 16 + (ch - ('a' - 10)));
+                        sb.append(ch);
+                    } else if (ch >= 'A' && ch <= 'F') {
+                        charRef = (char) (charRef * 16 + (ch - ('A' - 10)));
+                        sb.append(ch);
+                    } else if (ch == ';') {
                         break;
-                    }
-                    else
-                    {
-                        throw new XmlPullParserException( "character reference (with hex value) may not contain "
-                            + printable( ch ), this, null );
+                    } else {
+                        throw new XmlPullParserException(
+                                "character reference (with hex value) may not contain " + printable(ch), this, null);
                     }
                 }
-            }
-            else
-            {
+            } else {
                 // encoded in decimal
-                while ( true )
-                {
-                    if ( ch >= '0' && ch <= '9' )
-                    {
-                        charRef = (char) ( charRef * 10 + ( ch - '0' ) );
-                        sb.append( ch );
-                    }
-                    else if ( ch == ';' )
-                    {
+                while (true) {
+                    if (ch >= '0' && ch <= '9') {
+                        charRef = (char) (charRef * 10 + (ch - '0'));
+                        sb.append(ch);
+                    } else if (ch == ';') {
                         break;
-                    }
-                    else
-                    {
-                        throw new XmlPullParserException( "character reference (with decimal value) may not contain "
-                            + printable( ch ), this, null );
+                    } else {
+                        throw new XmlPullParserException(
+                                "character reference (with decimal value) may not contain " + printable(ch),
+                                this,
+                                null);
                     }
                     ch = more();
                 }
             }
 
             boolean isValidCodePoint = true;
-            try
-            {
-                int codePoint = Integer.parseInt( sb.toString(), isHex ? 16 : 10 );
-                isValidCodePoint = isValidCodePoint( codePoint );
-                if ( isValidCodePoint )
-                {
-                    resolvedEntityRefCharBuf = Character.toChars( codePoint );
+            try {
+                int codePoint = Integer.parseInt(sb.toString(), isHex ? 16 : 10);
+                isValidCodePoint = isValidCodePoint(codePoint);
+                if (isValidCodePoint) {
+                    resolvedEntityRefCharBuf = Character.toChars(codePoint);
                 }
-            }
-            catch ( IllegalArgumentException e )
-            {
+            } catch (IllegalArgumentException e) {
                 isValidCodePoint = false;
             }
 
-            if ( !isValidCodePoint )
-            {
-                throw new XmlPullParserException( "character reference (with " + ( isHex ? "hex" : "decimal" )
-                    + " value " + sb.toString() + ") is invalid", this, null );
+            if (!isValidCodePoint) {
+                throw new XmlPullParserException(
+                        "character reference (with " + (isHex ? "hex" : "decimal") + " value " + sb.toString()
+                                + ") is invalid",
+                        this,
+                        null);
             }
 
-            if ( tokenize )
-            {
-                text = newString( resolvedEntityRefCharBuf, 0, resolvedEntityRefCharBuf.length );
+            if (tokenize) {
+                text = newString(resolvedEntityRefCharBuf, 0, resolvedEntityRefCharBuf.length);
             }
             len = resolvedEntityRefCharBuf.length;
-        }
-        else
-        {
+        } else {
             // [68] EntityRef ::= '&' Name ';'
             // scan name until ;
-            if ( !isNameStartChar( ch ) )
-            {
-                throw new XmlPullParserException( "entity reference names can not start with character '"
-                    + printable( ch ) + "'", this, null );
+            if (!isNameStartChar(ch)) {
+                throw new XmlPullParserException(
+                        "entity reference names can not start with character '" + printable(ch) + "'", this, null);
             }
-            while ( true )
-            {
+            while (true) {
                 ch = more();
-                if ( ch == ';' )
-                {
+                if (ch == ';') {
                     break;
                 }
-                if ( !isNameChar( ch ) )
-                {
-                    throw new XmlPullParserException( "entity reference name can not contain character "
-                        + printable( ch ) + "'", this, null );
+                if (!isNameChar(ch)) {
+                    throw new XmlPullParserException(
+                            "entity reference name can not contain character " + printable(ch) + "'", this, null);
                 }
             }
             // determine what name maps to
-            len = ( pos - 1 ) - posStart;
-            if ( len == 2 && buf[posStart] == 'l' && buf[posStart + 1] == 't' )
-            {
-                if ( tokenize )
-                {
+            len = (pos - 1) - posStart;
+            if (len == 2 && buf[posStart] == 'l' && buf[posStart + 1] == 't') {
+                if (tokenize) {
                     text = "<";
                 }
                 resolvedEntityRefCharBuf = BUF_LT;
@@ -2827,37 +2246,31 @@ else if ( ch >= 'A' && ch <= 'F' )
                 // if(pcEnd >= pc.length) ensurePC();
                 // pc[pcEnd++] = '<';
                 // }
-            }
-            else if ( len == 3 && buf[posStart] == 'a' && buf[posStart + 1] == 'm' && buf[posStart + 2] == 'p' )
-            {
-                if ( tokenize )
-                {
+            } else if (len == 3 && buf[posStart] == 'a' && buf[posStart + 1] == 'm' && buf[posStart + 2] == 'p') {
+                if (tokenize) {
                     text = "&";
                 }
                 resolvedEntityRefCharBuf = BUF_AMP;
-            }
-            else if ( len == 2 && buf[posStart] == 'g' && buf[posStart + 1] == 't' )
-            {
-                if ( tokenize )
-                {
+            } else if (len == 2 && buf[posStart] == 'g' && buf[posStart + 1] == 't') {
+                if (tokenize) {
                     text = ">";
                 }
                 resolvedEntityRefCharBuf = BUF_GT;
-            }
-            else if ( len == 4 && buf[posStart] == 'a' && buf[posStart + 1] == 'p' && buf[posStart + 2] == 'o'
-                && buf[posStart + 3] == 's' )
-            {
-                if ( tokenize )
-                {
+            } else if (len == 4
+                    && buf[posStart] == 'a'
+                    && buf[posStart + 1] == 'p'
+                    && buf[posStart + 2] == 'o'
+                    && buf[posStart + 3] == 's') {
+                if (tokenize) {
                     text = "'";
                 }
                 resolvedEntityRefCharBuf = BUF_APO;
-            }
-            else if ( len == 4 && buf[posStart] == 'q' && buf[posStart + 1] == 'u' && buf[posStart + 2] == 'o'
-                && buf[posStart + 3] == 't' )
-            {
-                if ( tokenize )
-                {
+            } else if (len == 4
+                    && buf[posStart] == 'q'
+                    && buf[posStart + 1] == 'u'
+                    && buf[posStart + 2] == 'o'
+                    && buf[posStart + 3] == 't') {
+                if (tokenize) {
                     text = "\"";
                 }
                 resolvedEntityRefCharBuf = BUF_QUOT;
@@ -2875,19 +2288,15 @@ else if ( len == 4 && buf[posStart] == 'q' && buf[posStart + 1] == 'u' && buf[po
      * @throws XmlPullParserException if invalid XML is detected.
      * @throws IOException if an I/O error is found.
      */
-    private void parseEntityRefInDocDecl()
-        throws XmlPullParserException, IOException
-    {
+    private void parseEntityRefInDocDecl() throws XmlPullParserException, IOException {
         parseCharOrPredefinedEntityRef();
         if (usePC) {
             posStart--; // include in PC the starting '&' of the entity
             joinPC();
         }
 
-        if ( resolvedEntityRefCharBuf != BUF_NOT_RESOLVED )
-            return;
-        if ( tokenize )
-            text = null;
+        if (resolvedEntityRefCharBuf != BUF_NOT_RESOLVED) return;
+        if (tokenize) text = null;
     }
 
     /**
@@ -2896,24 +2305,20 @@ private void parseEntityRefInDocDecl()
      * @throws XmlPullParserException if invalid XML is detected.
      * @throws IOException if an I/O error is found.
      */
-    private void parseEntityRef()
-        throws XmlPullParserException, IOException
-    {
+    private void parseEntityRef() throws XmlPullParserException, IOException {
         final int len = parseCharOrPredefinedEntityRef();
 
         posEnd--; // don't involve the final ';' from the entity in the search
 
-        if ( resolvedEntityRefCharBuf != BUF_NOT_RESOLVED ) {
+        if (resolvedEntityRefCharBuf != BUF_NOT_RESOLVED) {
             return;
         }
 
-        resolvedEntityRefCharBuf = lookuEntityReplacement( len );
-        if ( resolvedEntityRefCharBuf != BUF_NOT_RESOLVED )
-        {
+        resolvedEntityRefCharBuf = lookuEntityReplacement(len);
+        if (resolvedEntityRefCharBuf != BUF_NOT_RESOLVED) {
             return;
         }
-        if ( tokenize )
-            text = null;
+        if (tokenize) text = null;
     }
 
     /**
@@ -2923,44 +2328,36 @@ private void parseEntityRef()
      * @param codePoint the numeric value to check
      * @return true if it is a valid numeric character reference. False otherwise.
      */
-    private static boolean isValidCodePoint( int codePoint )
-    {
+    private static boolean isValidCodePoint(int codePoint) {
         // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
-        return codePoint == 0x9 || codePoint == 0xA || codePoint == 0xD || ( 0x20 <= codePoint && codePoint <= 0xD7FF )
-            || ( 0xE000 <= codePoint && codePoint <= 0xFFFD ) || ( 0x10000 <= codePoint && codePoint <= 0x10FFFF );
-    }
-
-    private char[] lookuEntityReplacement( int entityNameLen )
-    {
-        if ( !allStringsInterned )
-        {
-            final int hash = fastHash( buf, posStart, posEnd - posStart );
-            LOOP: for ( int i = entityEnd - 1; i >= 0; --i )
-            {
-                if ( hash == entityNameHash[i] && entityNameLen == entityNameBuf[i].length )
-                {
+        return codePoint == 0x9
+                || codePoint == 0xA
+                || codePoint == 0xD
+                || (0x20 <= codePoint && codePoint <= 0xD7FF)
+                || (0xE000 <= codePoint && codePoint <= 0xFFFD)
+                || (0x10000 <= codePoint && codePoint <= 0x10FFFF);
+    }
+
+    private char[] lookuEntityReplacement(int entityNameLen) {
+        if (!allStringsInterned) {
+            final int hash = fastHash(buf, posStart, posEnd - posStart);
+            LOOP:
+            for (int i = entityEnd - 1; i >= 0; --i) {
+                if (hash == entityNameHash[i] && entityNameLen == entityNameBuf[i].length) {
                     final char[] entityBuf = entityNameBuf[i];
-                    for ( int j = 0; j < entityNameLen; j++ )
-                    {
-                        if ( buf[posStart + j] != entityBuf[j] )
-                            continue LOOP;
+                    for (int j = 0; j < entityNameLen; j++) {
+                        if (buf[posStart + j] != entityBuf[j]) continue LOOP;
                     }
-                    if ( tokenize )
-                        text = entityReplacement[i];
+                    if (tokenize) text = entityReplacement[i];
                     return entityReplacementBuf[i];
                 }
             }
-        }
-        else
-        {
-            entityRefName = newString( buf, posStart, posEnd - posStart );
-            for ( int i = entityEnd - 1; i >= 0; --i )
-            {
+        } else {
+            entityRefName = newString(buf, posStart, posEnd - posStart);
+            for (int i = entityEnd - 1; i >= 0; --i) {
                 // take advantage that interning for newString is enforced
-                if ( entityRefName == entityName[i] )
-                {
-                    if ( tokenize )
-                        text = entityReplacement[i];
+                if (entityRefName == entityName[i]) {
+                    if (tokenize) text = entityReplacement[i];
                     return entityReplacementBuf[i];
                 }
             }
@@ -2968,120 +2365,86 @@ private char[] lookuEntityReplacement( int entityNameLen )
         return BUF_NOT_RESOLVED;
     }
 
-    private void parseComment()
-        throws XmlPullParserException, IOException
-    {
+    private void parseComment() throws XmlPullParserException, IOException {
         // implements XML 1.0 Section 2.5 Comments
 
         // ASSUMPTION: seen 
                 cch = more();
                 int ch;
                 char cch2;
-                if ( Character.isHighSurrogate( cch ) )
-                {
+                if (Character.isHighSurrogate(cch)) {
                     cch2 = more();
-                    ch = Character.toCodePoint( cch, cch2 );
-                }
-                else
-                {
+                    ch = Character.toCodePoint(cch, cch2);
+                } else {
                     cch2 = 0;
                     ch = cch;
                 }
-                if ( seenDashDash && ch != '>' )
-                {
-                    throw new XmlPullParserException( "in comment after two dashes (--) next character must be >"
-                        + " not " + printable( ch ), this, null );
+                if (seenDashDash && ch != '>') {
+                    throw new XmlPullParserException(
+                            "in comment after two dashes (--) next character must be >" + " not " + printable(ch),
+                            this,
+                            null);
                 }
-                if ( ch == '-' )
-                {
-                    if ( !seenDash )
-                    {
+                if (ch == '-') {
+                    if (!seenDash) {
                         seenDash = true;
-                    }
-                    else
-                    {
+                    } else {
                         seenDashDash = true;
                     }
-                }
-                else if ( ch == '>' )
-                {
-                    if ( seenDashDash )
-                    {
+                } else if (ch == '>') {
+                    if (seenDashDash) {
                         break; // found end sequence!!!!
                     }
                     seenDash = false;
-                }
-                else if (isValidCodePoint( ch ))
-                {
+                } else if (isValidCodePoint(ch)) {
                     seenDash = false;
+                } else {
+                    throw new XmlPullParserException(
+                            "Illegal character 0x" + Integer.toHexString(ch) + " found in comment", this, null);
                 }
-                else
-                {
-                    throw new XmlPullParserException( "Illegal character 0x" + Integer.toHexString(ch) + " found in comment", this, null );
-                }
-                if ( normalizeIgnorableWS )
-                {
-                    if ( ch == '\r' )
-                    {
+                if (normalizeIgnorableWS) {
+                    if (ch == '\r') {
                         normalizedCR = true;
                         // posEnd = pos -1;
                         // joinPC();
                         // posEnd is alreadys set
-                        if ( !usePC )
-                        {
+                        if (!usePC) {
                             posEnd = pos - 1;
-                            if ( posEnd > posStart )
-                            {
+                            if (posEnd > posStart) {
                                 joinPC();
-                            }
-                            else
-                            {
+                            } else {
                                 usePC = true;
                                 pcStart = pcEnd = 0;
                             }
                         }
                         // assert usePC == true;
-                        if ( pcEnd >= pc.length )
-                            ensurePC( pcEnd );
+                        if (pcEnd >= pc.length) ensurePC(pcEnd);
                         pc[pcEnd++] = '\n';
-                    }
-                    else if ( ch == '\n' )
-                    {
-                        if ( !normalizedCR && usePC )
-                        {
-                            if ( pcEnd >= pc.length )
-                                ensurePC( pcEnd );
+                    } else if (ch == '\n') {
+                        if (!normalizedCR && usePC) {
+                            if (pcEnd >= pc.length) ensurePC(pcEnd);
                             pc[pcEnd++] = '\n';
                         }
                         normalizedCR = false;
-                    }
-                    else
-                    {
-                        if ( usePC )
-                        {
-                            if ( pcEnd >= pc.length )
-                                ensurePC( pcEnd );
+                    } else {
+                        if (usePC) {
+                            if (pcEnd >= pc.length) ensurePC(pcEnd);
                             pc[pcEnd++] = cch;
-                            if ( cch2 != 0 )
-                            {
+                            if (cch2 != 0) {
                                 pc[pcEnd++] = cch2;
                             }
                         }
@@ -3090,33 +2453,26 @@ else if ( ch == '\n' )
                 }
             }
 
-        }
-        catch ( EOFException ex )
-        {
+        } catch (EOFException ex) {
             // detect EOF and create meaningful error ...
-            throw new XmlPullParserException( "comment started on line " + curLine + " and column " + curColumn
-                + " was not closed", this, ex );
+            throw new XmlPullParserException(
+                    "comment started on line " + curLine + " and column " + curColumn + " was not closed", this, ex);
         }
-        if ( tokenize )
-        {
+        if (tokenize) {
             posEnd = pos - 3;
-            if ( usePC )
-            {
+            if (usePC) {
                 pcEnd -= 2;
             }
         }
     }
 
-    private void parsePI()
-        throws XmlPullParserException, IOException
-    {
+    private void parsePI() throws XmlPullParserException, IOException {
         // implements XML 1.0 Section 2.6 Processing Instructions
 
         // [16] PI ::= '' Char*)))? '?>'
         // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
         // ASSUMPTION: seen 
                 // ch = more();
 
-                if ( ch == '?' )
-                {
-                    if ( !seenPITarget )
-                    {
-                        throw new XmlPullParserException( "processing instruction PITarget name not found", this,
-                                                          null );
+                if (ch == '?') {
+                    if (!seenPITarget) {
+                        throw new XmlPullParserException("processing instruction PITarget name not found", this, null);
                     }
                     seenQ = true;
-                }
-                else if ( ch == '>' )
-                {
-                    if ( seenQ )
-                    {
+                } else if (ch == '>') {
+                    if (seenQ) {
                         break; // found end sequence!!!!
                     }
 
-                    if ( !seenPITarget )
-                    {
-                        throw new XmlPullParserException( "processing instruction PITarget name not found", this,
-                                                          null );
-                    }
-                    else if ( !seenInnerTag )
-                    {
+                    if (!seenPITarget) {
+                        throw new XmlPullParserException("processing instruction PITarget name not found", this, null);
+                    } else if (!seenInnerTag) {
                         // seenPITarget && !seenQ
-                        throw new XmlPullParserException( "processing instruction started on line " + curLine
-                            + " and column " + curColumn + " was not closed", this, null );
-                    }
-                    else
-                    {
+                        throw new XmlPullParserException(
+                                "processing instruction started on line " + curLine + " and column " + curColumn
+                                        + " was not closed",
+                                this,
+                                null);
+                    } else {
                         seenInnerTag = false;
                     }
-                }
-                else if ( ch == '<' )
-                {
+                } else if (ch == '<') {
                     seenInnerTag = true;
-                }
-                else
-                {
-                    if ( piTargetEnd == -1 && isS( ch ) )
-                    {
+                } else {
+                    if (piTargetEnd == -1 && isS(ch)) {
                         piTargetEnd = pos - 1;
 
                         // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
-                        if ( ( piTargetEnd - piTargetStart ) >= 3 )
-                        {
-                            if ( ( buf[piTargetStart] == 'x' || buf[piTargetStart] == 'X' )
-                                && ( buf[piTargetStart + 1] == 'm' || buf[piTargetStart + 1] == 'M' )
-                                && ( buf[piTargetStart + 2] == 'l' || buf[piTargetStart + 2] == 'L' ) )
-                            {
-                                if ( piTargetStart > 3 )
-                                { // = 3) {
+                            if ((buf[piTargetStart] == 'x' || buf[piTargetStart] == 'X')
+                                    && (buf[piTargetStart + 1] == 'm' || buf[piTargetStart + 1] == 'M')
+                                    && (buf[piTargetStart + 2] == 'l' || buf[piTargetStart + 2] == 'L')) {
+                                if (piTargetStart > 3) { //  posStart )
-                            {
+                            if (posEnd > posStart) {
                                 joinPC();
-                            }
-                            else
-                            {
+                            } else {
                                 usePC = true;
                                 pcStart = pcEnd = 0;
                             }
                         }
                         // assert usePC == true;
-                        if ( pcEnd >= pc.length )
-                            ensurePC( pcEnd );
+                        if (pcEnd >= pc.length) ensurePC(pcEnd);
                         pc[pcEnd++] = '\n';
-                    }
-                    else if ( ch == '\n' )
-                    {
-                        if ( !normalizedCR && usePC )
-                        {
-                            if ( pcEnd >= pc.length )
-                                ensurePC( pcEnd );
+                    } else if (ch == '\n') {
+                        if (!normalizedCR && usePC) {
+                            if (pcEnd >= pc.length) ensurePC(pcEnd);
                             pc[pcEnd++] = '\n';
                         }
                         normalizedCR = false;
-                    }
-                    else
-                    {
-                        if ( usePC )
-                        {
-                            if ( pcEnd >= pc.length )
-                                ensurePC( pcEnd );
+                    } else {
+                        if (usePC) {
+                            if (pcEnd >= pc.length) ensurePC(pcEnd);
                             pc[pcEnd++] = ch;
                         }
                         normalizedCR = false;
@@ -3266,24 +2588,22 @@ else if ( ch == '\n' )
                 seenPITarget = true;
                 ch = more();
             }
-        }
-        catch ( EOFException ex )
-        {
+        } catch (EOFException ex) {
             // detect EOF and create meaningful error ...
-            throw new XmlPullParserException( "processing instruction started on line " + curLine + " and column "
-                + curColumn + " was not closed", this, ex );
+            throw new XmlPullParserException(
+                    "processing instruction started on line " + curLine + " and column " + curColumn
+                            + " was not closed",
+                    this,
+                    ex);
         }
-        if ( piTargetEnd == -1 )
-        {
+        if (piTargetEnd == -1) {
             piTargetEnd = pos - 2 + bufAbsoluteStart;
             // throw new XmlPullParserException(
             // "processing instruction must have PITarget name", this, null);
         }
-        if ( tokenize )
-        {
+        if (tokenize) {
             posEnd = pos - 2;
-            if ( normalizeIgnorableWS )
-            {
+            if (normalizeIgnorableWS) {
                 --pcEnd;
             }
         }
@@ -3295,19 +2615,17 @@ else if ( ch == '\n' )
     // protected final static char[] YES = {'y','e','s'};
     // protected final static char[] NO = {'n','o'};
 
-    private final static char[] VERSION = "version".toCharArray();
+    private static final char[] VERSION = "version".toCharArray();
 
-    private final static char[] NCODING = "ncoding".toCharArray();
+    private static final char[] NCODING = "ncoding".toCharArray();
 
-    private final static char[] TANDALONE = "tandalone".toCharArray();
+    private static final char[] TANDALONE = "tandalone".toCharArray();
 
-    private final static char[] YES = "yes".toCharArray();
+    private static final char[] YES = "yes".toCharArray();
 
-    private final static char[] NO = "no".toCharArray();
+    private static final char[] NO = "no".toCharArray();
 
-    private void parseXmlDecl( char ch )
-        throws XmlPullParserException, IOException
-    {
+    private void parseXmlDecl(char ch) throws XmlPullParserException, IOException {
         // [23] XMLDecl ::= ''
 
         // first make sure that relative positions will stay OK
@@ -3318,207 +2636,195 @@ private void parseXmlDecl( char ch )
 
         // [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
         // parse is positioned just on first S past  'z' ) && ( ch < 'A' || ch > 'Z' ) && ( ch < '0' || ch > '9' ) && ch != '_'
-                && ch != '.' && ch != ':' && ch != '-' )
-            {
-                throw new XmlPullParserException( " 'z')
+                    && (ch < 'A' || ch > 'Z')
+                    && (ch < '0' || ch > '9')
+                    && ch != '_'
+                    && ch != '.'
+                    && ch != ':'
+                    && ch != '-') {
+                throw new XmlPullParserException(
+                        "' )
-        {
-            throw new XmlPullParserException( "unexpected character " + printable( ch ), this, null );
+        if (ch != 'e' && ch != 's' && ch != '?' && ch != '>') {
+            throw new XmlPullParserException("unexpected character " + printable(ch), this, null);
         }
 
-        if ( ch == 'e' )
-        {
-            if ( !isS( prevCh ) )
-            {
-                throw new XmlPullParserException( "expected a space after " + lastParsedAttr + " and not "
-                    + printable( ch ), this, null );
+        if (ch == 'e') {
+            if (!isS(prevCh)) {
+                throw new XmlPullParserException(
+                        "expected a space after " + lastParsedAttr + " and not " + printable(ch), this, null);
             }
             ch = more();
-            ch = requireInput( ch, NCODING );
-            ch = skipS( ch );
-            if ( ch != '=' )
-            {
-                throw new XmlPullParserException( "expected equals sign (=) after encoding and not " + printable( ch ),
-                                                  this, null );
+            ch = requireInput(ch, NCODING);
+            ch = skipS(ch);
+            if (ch != '=') {
+                throw new XmlPullParserException(
+                        "expected equals sign (=) after encoding and not " + printable(ch), this, null);
             }
             ch = more();
-            ch = skipS( ch );
-            if ( ch != '\'' && ch != '"' )
-            {
-                throw new XmlPullParserException( "expected apostrophe (') or quotation mark (\") after encoding and not "
-                    + printable( ch ), this, null );
+            ch = skipS(ch);
+            if (ch != '\'' && ch != '"') {
+                throw new XmlPullParserException(
+                        "expected apostrophe (') or quotation mark (\") after encoding and not " + printable(ch),
+                        this,
+                        null);
             }
             final char quotChar = ch;
             final int encodingStart = pos;
             ch = more();
             // [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
-            if ( ( ch < 'a' || ch > 'z' ) && ( ch < 'A' || ch > 'Z' ) )
-            {
-                throw new XmlPullParserException( " 'z') && (ch < 'A' || ch > 'Z')) {
+                throw new XmlPullParserException(
+                        " 'z' ) && ( ch < 'A' || ch > 'Z' ) && ( ch < '0' || ch > '9' ) && ch != '.'
-                    && ch != '_' && ch != '-' )
-                {
-                    throw new XmlPullParserException( " 'z')
+                        && (ch < 'A' || ch > 'Z')
+                        && (ch < '0' || ch > '9')
+                        && ch != '.'
+                        && ch != '_'
+                        && ch != '-') {
+                    throw new XmlPullParserException(
+                            " as last part of  as last part of ' )
-        {
-            throw new XmlPullParserException( "expected ?> as last part of ') {
+            throw new XmlPullParserException("expected ?> as last part of ' && bracketLevel == 0 )
-                break;
-            else if ( ch == '&' )
-            {
+            if (ch == '[') ++bracketLevel;
+            else if (ch == ']') --bracketLevel;
+            else if (ch == '>' && bracketLevel == 0) break;
+            else if (ch == '&') {
                 extractEntityRefInDocDecl();
                 continue;
             }
-            if ( normalizeIgnorableWS )
-            {
-                if ( ch == '\r' )
-                {
+            if (normalizeIgnorableWS) {
+                if (ch == '\r') {
                     normalizedCR = true;
                     // posEnd = pos -1;
                     // joinPC();
                     // posEnd is alreadys set
-                    if ( !usePC )
-                    {
+                    if (!usePC) {
                         posEnd = pos - 1;
-                        if ( posEnd > posStart )
-                        {
+                        if (posEnd > posStart) {
                             joinPC();
-                        }
-                        else
-                        {
+                        } else {
                             usePC = true;
                             pcStart = pcEnd = 0;
                         }
                     }
                     // assert usePC == true;
-                    if ( pcEnd >= pc.length )
-                        ensurePC( pcEnd );
+                    if (pcEnd >= pc.length) ensurePC(pcEnd);
                     pc[pcEnd++] = '\n';
-                }
-                else if ( ch == '\n' )
-                {
-                    if ( !normalizedCR && usePC )
-                    {
-                        if ( pcEnd >= pc.length )
-                            ensurePC( pcEnd );
+                } else if (ch == '\n') {
+                    if (!normalizedCR && usePC) {
+                        if (pcEnd >= pc.length) ensurePC(pcEnd);
                         pc[pcEnd++] = '\n';
                     }
                     normalizedCR = false;
-                }
-                else
-                {
-                    if ( usePC )
-                    {
-                        if ( pcEnd >= pc.length )
-                            ensurePC( pcEnd );
+                } else {
+                    if (usePC) {
+                        if (pcEnd >= pc.length) ensurePC(pcEnd);
                         pc[pcEnd++] = ch;
                     }
                     normalizedCR = false;
                 }
             }
-
         }
         posEnd = pos - 1;
         text = null;
     }
 
-    private void extractEntityRefInDocDecl()
-        throws XmlPullParserException, IOException
-    {
+    private void extractEntityRefInDocDecl() throws XmlPullParserException, IOException {
         // extractEntityRef
         posEnd = pos - 1;
 
@@ -3606,21 +2889,15 @@ private void extractEntityRefInDocDecl()
         posStart = prevPosStart;
     }
 
-    private void extractEntityRef()
-        throws XmlPullParserException, IOException
-    {
+    private void extractEntityRef() throws XmlPullParserException, IOException {
         // extractEntityRef
         posEnd = pos - 1;
-        if ( !usePC )
-        {
+        if (!usePC) {
             final boolean hadCharData = posEnd > posStart;
-            if ( hadCharData )
-            {
+            if (hadCharData) {
                 // posEnd is already set correctly!!!
                 joinPC();
-            }
-            else
-            {
+            } else {
                 usePC = true;
                 pcStart = pcEnd = 0;
             }
@@ -3629,29 +2906,23 @@ private void extractEntityRef()
 
         parseEntityRef();
         // check if replacement text can be resolved !!!
-        if ( resolvedEntityRefCharBuf == BUF_NOT_RESOLVED )
-        {
-            if ( entityRefName == null )
-            {
-                entityRefName = newString( buf, posStart, posEnd - posStart );
+        if (resolvedEntityRefCharBuf == BUF_NOT_RESOLVED) {
+            if (entityRefName == null) {
+                entityRefName = newString(buf, posStart, posEnd - posStart);
             }
-            throw new XmlPullParserException( "could not resolve entity named '" + printable( entityRefName )
-                + "'", this, null );
+            throw new XmlPullParserException(
+                    "could not resolve entity named '" + printable(entityRefName) + "'", this, null);
         }
         // write into PC replacement text - do merge for replacement text!!!!
-        for ( char aResolvedEntity : resolvedEntityRefCharBuf )
-        {
-            if ( pcEnd >= pc.length )
-            {
-                ensurePC( pcEnd );
+        for (char aResolvedEntity : resolvedEntityRefCharBuf) {
+            if (pcEnd >= pc.length) {
+                ensurePC(pcEnd);
             }
             pc[pcEnd++] = aResolvedEntity;
         }
     }
 
-    private void parseCDSect( boolean hadCharData )
-        throws XmlPullParserException, IOException
-    {
+    private void parseCDSect(boolean hadCharData) throws XmlPullParserException, IOException {
         // implements XML 1.0 Section 2.7 CDATA Sections
 
         // [18] CDSect ::= CDStart CData CDEnd
@@ -3661,44 +2932,31 @@ private void parseCDSect( boolean hadCharData )
 
         // ASSUMPTION: seen  posStart )
-                        {
+                        if (posEnd > posStart) {
                             joinPC();
-                        }
-                        else
-                        {
+                        } else {
                             usePC = true;
                             pcStart = pcEnd = 0;
                         }
@@ -3708,99 +2966,69 @@ private void parseCDSect( boolean hadCharData )
             boolean seenBracket = false;
             boolean seenBracketBracket = false;
             boolean normalizedCR = false;
-            while ( true )
-            {
+            while (true) {
                 // scan until it hits "]]>"
                 ch = more();
-                if ( ch == ']' )
-                {
-                    if ( !seenBracket )
-                    {
+                if (ch == ']') {
+                    if (!seenBracket) {
                         seenBracket = true;
-                    }
-                    else
-                    {
+                    } else {
                         seenBracketBracket = true;
                         // seenBracket = false;
                     }
-                }
-                else if ( ch == '>' )
-                {
-                    if ( seenBracket && seenBracketBracket )
-                    {
+                } else if (ch == '>') {
+                    if (seenBracket && seenBracketBracket) {
                         break; // found end sequence!!!!
-                    }
-                    else
-                    {
+                    } else {
                         seenBracketBracket = false;
                     }
                     seenBracket = false;
-                }
-                else
-                {
-                    if ( seenBracket )
-                    {
+                } else {
+                    if (seenBracket) {
                         seenBracket = false;
                     }
                 }
-                if ( normalizeInput )
-                {
+                if (normalizeInput) {
                     // deal with normalization issues ...
-                    if ( ch == '\r' )
-                    {
+                    if (ch == '\r') {
                         normalizedCR = true;
                         posStart = cdStart - bufAbsoluteStart;
                         posEnd = pos - 1; // posEnd is alreadys set
-                        if ( !usePC )
-                        {
-                            if ( posEnd > posStart )
-                            {
+                        if (!usePC) {
+                            if (posEnd > posStart) {
                                 joinPC();
-                            }
-                            else
-                            {
+                            } else {
                                 usePC = true;
                                 pcStart = pcEnd = 0;
                             }
                         }
                         // assert usePC == true;
-                        if ( pcEnd >= pc.length )
-                            ensurePC( pcEnd );
+                        if (pcEnd >= pc.length) ensurePC(pcEnd);
                         pc[pcEnd++] = '\n';
-                    }
-                    else if ( ch == '\n' )
-                    {
-                        if ( !normalizedCR && usePC )
-                        {
-                            if ( pcEnd >= pc.length )
-                                ensurePC( pcEnd );
+                    } else if (ch == '\n') {
+                        if (!normalizedCR && usePC) {
+                            if (pcEnd >= pc.length) ensurePC(pcEnd);
                             pc[pcEnd++] = '\n';
                         }
                         normalizedCR = false;
-                    }
-                    else
-                    {
-                        if ( usePC )
-                        {
-                            if ( pcEnd >= pc.length )
-                                ensurePC( pcEnd );
+                    } else {
+                        if (usePC) {
+                            if (pcEnd >= pc.length) ensurePC(pcEnd);
                             pc[pcEnd++] = ch;
                         }
                         normalizedCR = false;
                     }
                 }
             }
-        }
-        catch ( EOFException ex )
-        {
+        } catch (EOFException ex) {
             // detect EOF and create meaningful error ...
-            throw new XmlPullParserException( "CDATA section started on line " + curLine + " and column " + curColumn
-                + " was not closed", this, ex );
+            throw new XmlPullParserException(
+                    "CDATA section started on line " + curLine + " and column " + curColumn + " was not closed",
+                    this,
+                    ex);
         }
-        if ( normalizeInput )
-        {
-            if ( usePC )
-            {
+        if (normalizeInput) {
+            if (usePC) {
                 pcEnd = pcEnd - 2;
             }
         }
@@ -3808,46 +3036,36 @@ else if ( ch == '\n' )
         posEnd = pos - 3;
     }
 
-    private void fillBuf()
-        throws IOException, XmlPullParserException
-    {
-        if ( reader == null )
-            throw new XmlPullParserException( "reader must be set before parsing is started" );
+    private void fillBuf() throws IOException, XmlPullParserException {
+        if (reader == null) throw new XmlPullParserException("reader must be set before parsing is started");
 
         // see if we are in compaction area
-        if ( bufEnd > bufSoftLimit )
-        {
+        if (bufEnd > bufSoftLimit) {
 
             // check if we need to compact or expand the buffer
-            boolean compact = !preventBufferCompaction
-                    && ( bufStart > bufSoftLimit || bufStart >= buf.length / 2 );
+            boolean compact = !preventBufferCompaction && (bufStart > bufSoftLimit || bufStart >= buf.length / 2);
 
             // if buffer almost full then compact it
-            if ( compact )
-            {
+            if (compact) {
                 // TODO: look on trashing
                 // //assert bufStart > 0
-                System.arraycopy( buf, bufStart, buf, 0, bufEnd - bufStart );
-                if ( TRACE_SIZING )
-                    System.out.println( "TRACE_SIZING fillBuf() compacting " + bufStart + " bufEnd=" + bufEnd + " pos="
-                        + pos + " posStart=" + posStart + " posEnd=" + posEnd + " buf first 100 chars:"
-                        + new String( buf, bufStart, Math.min(bufEnd - bufStart, 100)) );
+                System.arraycopy(buf, bufStart, buf, 0, bufEnd - bufStart);
+                if (TRACE_SIZING)
+                    System.out.println("TRACE_SIZING fillBuf() compacting " + bufStart + " bufEnd=" + bufEnd + " pos="
+                            + pos + " posStart=" + posStart + " posEnd=" + posEnd + " buf first 100 chars:"
+                            + new String(buf, bufStart, Math.min(bufEnd - bufStart, 100)));
 
-            }
-            else
-            {
+            } else {
                 final int newSize = 2 * buf.length;
                 final char[] newBuf = new char[newSize];
-                if ( TRACE_SIZING )
-                    System.out.println( "TRACE_SIZING fillBuf() " + buf.length + " => " + newSize );
-                System.arraycopy( buf, bufStart, newBuf, 0, bufEnd - bufStart );
+                if (TRACE_SIZING) System.out.println("TRACE_SIZING fillBuf() " + buf.length + " => " + newSize);
+                System.arraycopy(buf, bufStart, newBuf, 0, bufEnd - bufStart);
                 buf = newBuf;
-                if ( bufLoadFactor > 0 )
-                {
-                    // Include a fix for https://web.archive.org/web/20070831191548/http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=228
-					bufSoftLimit = (int) ( bufferLoadFactor * buf.length );
+                if (bufLoadFactor > 0) {
+                    // Include a fix for
+                    // https://web.archive.org/web/20070831191548/http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=228
+                    bufSoftLimit = (int) (bufferLoadFactor * buf.length);
                 }
-
             }
             bufEnd -= bufStart;
             pos -= bufStart;
@@ -3855,123 +3073,107 @@ private void fillBuf()
             posEnd -= bufStart;
             bufAbsoluteStart += bufStart;
             bufStart = 0;
-            if ( TRACE_SIZING )
-                System.out.println( "TRACE_SIZING fillBuf() after bufEnd=" + bufEnd + " pos=" + pos + " posStart="
-                    + posStart + " posEnd=" + posEnd + " buf first 100 chars:"
-                    + new String( buf, 0, Math.min(bufEnd, 100)) );
+            if (TRACE_SIZING)
+                System.out.println("TRACE_SIZING fillBuf() after bufEnd=" + bufEnd + " pos=" + pos + " posStart="
+                        + posStart + " posEnd=" + posEnd + " buf first 100 chars:"
+                        + new String(buf, 0, Math.min(bufEnd, 100)));
         }
         // at least one character must be read or error
         final int len = Math.min(buf.length - bufEnd, READ_CHUNK_SIZE);
-        final int ret = reader.read( buf, bufEnd, len );
-        if ( ret > 0 )
-        {
+        final int ret = reader.read(buf, bufEnd, len);
+        if (ret > 0) {
             bufEnd += ret;
-            if ( TRACE_SIZING )
-                System.out.println( "TRACE_SIZING fillBuf() after filling in buffer" + " buf first 100 chars:"
-                    + new String( buf, 0, Math.min(bufEnd, 100)) );
+            if (TRACE_SIZING)
+                System.out.println("TRACE_SIZING fillBuf() after filling in buffer" + " buf first 100 chars:"
+                        + new String(buf, 0, Math.min(bufEnd, 100)));
 
             return;
         }
-        if ( ret == -1 )
-        {
-            if ( bufAbsoluteStart == 0 && pos == 0 )
-            {
-                throw new EOFException( "input contained no data" );
-            }
-            else
-            {
-                if ( seenRoot && depth == 0 )
-                { // inside parsing epilog!!!
+        if (ret == -1) {
+            if (bufAbsoluteStart == 0 && pos == 0) {
+                throw new EOFException("input contained no data");
+            } else {
+                if (seenRoot && depth == 0) { // inside parsing epilog!!!
                     reachedEnd = true;
                     return;
-                }
-                else
-                {
+                } else {
                     StringBuilder expectedTagStack = new StringBuilder();
-                    if ( depth > 0 )
-                    {
-                        if ( elRawName == null || elRawName[depth] == null )
-                        {
-                            String tagName = new String( buf, posStart + 1, pos - posStart - 1 );
-                            expectedTagStack.append( " - expected the opening tag <" ).append( tagName ).append( "...>" );
-                        }
-                        else
-                        {
+                    if (depth > 0) {
+                        if (elRawName == null || elRawName[depth] == null) {
+                            String tagName = new String(buf, posStart + 1, pos - posStart - 1);
+                            expectedTagStack
+                                    .append(" - expected the opening tag <")
+                                    .append(tagName)
+                                    .append("...>");
+                        } else {
                             // final char[] cbuf = elRawName[depth];
                             // final String startname = new String(cbuf, 0, elRawNameEnd[depth]);
-                            expectedTagStack.append( " - expected end tag" );
-                            if ( depth > 1 )
-                            {
-                                expectedTagStack.append( "s" ); // more than one end tag
+                            expectedTagStack.append(" - expected end tag");
+                            if (depth > 1) {
+                                expectedTagStack.append("s"); // more than one end tag
                             }
-                            expectedTagStack.append( " " );
-
-                            for ( int i = depth; i > 0; i-- )
-                            {
-                                if ( elRawName == null || elRawName[i] == null )
-                                {
-                                    String tagName = new String( buf, posStart + 1, pos - posStart - 1 );
-                                    expectedTagStack.append( " - expected the opening tag <" ).append( tagName ).append( "...>" );
-                                }
-                                else
-                                {
-                                    String tagName = new String( elRawName[i], 0, elRawNameEnd[i] );
-                                    expectedTagStack.append( "' );
+                            expectedTagStack.append(" ");
+
+                            for (int i = depth; i > 0; i--) {
+                                if (elRawName == null || elRawName[i] == null) {
+                                    String tagName = new String(buf, posStart + 1, pos - posStart - 1);
+                                    expectedTagStack
+                                            .append(" - expected the opening tag <")
+                                            .append(tagName)
+                                            .append("...>");
+                                } else {
+                                    String tagName = new String(elRawName[i], 0, elRawNameEnd[i]);
+                                    expectedTagStack
+                                            .append("');
                                 }
                             }
-                            expectedTagStack.append( " to close" );
-                            for ( int i = depth; i > 0; i-- )
-                            {
-                                if ( i != depth )
-                                {
-                                    expectedTagStack.append( " and" ); // more than one end tag
-                                }
-                                if ( elRawName == null || elRawName[i] == null )
-                                {
-                                    String tagName = new String( buf, posStart + 1, pos - posStart - 1 );
-                                    expectedTagStack.append( " start tag <" ).append( tagName ).append( ">" );
-                                    expectedTagStack.append( " from line " ).append( elRawNameLine[i] );
+                            expectedTagStack.append(" to close");
+                            for (int i = depth; i > 0; i--) {
+                                if (i != depth) {
+                                    expectedTagStack.append(" and"); // more than one end tag
                                 }
-                                else
-                                {
-                                String tagName = new String( elRawName[i], 0, elRawNameEnd[i] );
-                                expectedTagStack.append( " start tag <" ).append( tagName ).append( ">" );
-                                expectedTagStack.append( " from line " ).append( elRawNameLine[i] );
+                                if (elRawName == null || elRawName[i] == null) {
+                                    String tagName = new String(buf, posStart + 1, pos - posStart - 1);
+                                    expectedTagStack
+                                            .append(" start tag <")
+                                            .append(tagName)
+                                            .append(">");
+                                    expectedTagStack.append(" from line ").append(elRawNameLine[i]);
+                                } else {
+                                    String tagName = new String(elRawName[i], 0, elRawNameEnd[i]);
+                                    expectedTagStack
+                                            .append(" start tag <")
+                                            .append(tagName)
+                                            .append(">");
+                                    expectedTagStack.append(" from line ").append(elRawNameLine[i]);
                                 }
                             }
-                            expectedTagStack.append( ", parser stopped on" );
+                            expectedTagStack.append(", parser stopped on");
                         }
                     }
-                    throw new EOFException( "no more data available" + expectedTagStack.toString()
-                        + getPositionDescription() );
+                    throw new EOFException(
+                            "no more data available" + expectedTagStack.toString() + getPositionDescription());
                 }
             }
-        }
-        else
-        {
-            throw new IOException( "error reading input, returned " + ret );
+        } else {
+            throw new IOException("error reading input, returned " + ret);
         }
     }
 
-    private char more()
-        throws IOException, XmlPullParserException
-    {
-        if ( pos >= bufEnd )
-        {
+    private char more() throws IOException, XmlPullParserException {
+        if (pos >= bufEnd) {
             fillBuf();
             // this return value should be ignored as it is used in epilog parsing ...
-            if ( reachedEnd )
-                throw new EOFException( "no more data available" + getPositionDescription() );
+            if (reachedEnd) throw new EOFException("no more data available" + getPositionDescription());
         }
         final char ch = buf[pos++];
         // line/columnNumber
-        if ( ch == '\n' )
-        {
+        if (ch == '\n') {
             ++lineNumber;
             columnNumber = 1;
-        }
-        else
-        {
+        } else {
             ++columnNumber;
         }
         // System.out.print(ch);
@@ -3988,53 +3190,44 @@ private char more()
     // return pos + bufAbsoluteStart;
     // }
 
-    private void ensurePC( int end )
-    {
+    private void ensurePC(int end) {
         // assert end >= pc.length;
         final int newSize = end > READ_CHUNK_SIZE ? 2 * end : 2 * READ_CHUNK_SIZE;
         final char[] newPC = new char[newSize];
-        if ( TRACE_SIZING )
-            System.out.println( "TRACE_SIZING ensurePC() " + pc.length + " ==> " + newSize + " end=" + end );
-        System.arraycopy( pc, 0, newPC, 0, pcEnd );
+        if (TRACE_SIZING)
+            System.out.println("TRACE_SIZING ensurePC() " + pc.length + " ==> " + newSize + " end=" + end);
+        System.arraycopy(pc, 0, newPC, 0, pcEnd);
         pc = newPC;
         // assert end < pc.length;
     }
 
-    private void joinPC()
-    {
+    private void joinPC() {
         // assert usePC == false;
         // assert posEnd > posStart;
         final int len = posEnd - posStart;
         final int newEnd = pcEnd + len + 1;
-        if ( newEnd >= pc.length )
-            ensurePC( newEnd ); // add 1 for extra space for one char
+        if (newEnd >= pc.length) ensurePC(newEnd); // add 1 for extra space for one char
         // assert newEnd < pc.length;
-        System.arraycopy( buf, posStart, pc, pcEnd, len );
+        System.arraycopy(buf, posStart, pc, pcEnd, len);
         pcEnd += len;
         usePC = true;
-
     }
 
-    private char requireInput( char ch, char[] input )
-        throws XmlPullParserException, IOException
-    {
-        for ( char anInput : input )
-        {
-            if ( ch != anInput )
-            {
-                throw new XmlPullParserException( "expected " + printable( anInput ) + " in " + new String( input )
-                    + " and not " + printable( ch ), this, null );
+    private char requireInput(char ch, char[] input) throws XmlPullParserException, IOException {
+        for (char anInput : input) {
+            if (ch != anInput) {
+                throw new XmlPullParserException(
+                        "expected " + printable(anInput) + " in " + new String(input) + " and not " + printable(ch),
+                        this,
+                        null);
             }
             ch = more();
         }
         return ch;
     }
 
-    private char skipS( char ch )
-        throws XmlPullParserException, IOException
-    {
-        while ( isS( ch ) )
-        {
+    private char skipS(char ch) throws XmlPullParserException, IOException {
+        while (isS(ch)) {
             ch = more();
         } // skip additional spaces
         return ch;
@@ -4051,48 +3244,40 @@ private char skipS( char ch )
 
     private static final boolean[] lookupNameChar = new boolean[LOOKUP_MAX];
 
-    private static void setName( char ch )
-    // { lookupNameChar[ (int)ch / 32 ] |= (1 << (ch % 32)); }
-    {
+    private static void setName(char ch)
+                // { lookupNameChar[ (int)ch / 32 ] |= (1 << (ch % 32)); }
+            {
         lookupNameChar[ch] = true;
     }
 
-    private static void setNameStart( char ch )
-    // { lookupNameStartChar[ (int)ch / 32 ] |= (1 << (ch % 32)); setName(ch); }
-    {
+    private static void setNameStart(char ch)
+                // { lookupNameStartChar[ (int)ch / 32 ] |= (1 << (ch % 32)); setName(ch); }
+            {
         lookupNameStartChar[ch] = true;
-        setName( ch );
+        setName(ch);
     }
 
-    static
-    {
-        setNameStart( ':' );
-        for ( char ch = 'A'; ch <= 'Z'; ++ch )
-            setNameStart( ch );
-        setNameStart( '_' );
-        for ( char ch = 'a'; ch <= 'z'; ++ch )
-            setNameStart( ch );
-        for ( char ch = '\u00c0'; ch <= '\u02FF'; ++ch )
-            setNameStart( ch );
-        for ( char ch = '\u0370'; ch <= '\u037d'; ++ch )
-            setNameStart( ch );
-        for ( char ch = '\u037f'; ch < '\u0400'; ++ch )
-            setNameStart( ch );
-
-        setName( '-' );
-        setName( '.' );
-        for ( char ch = '0'; ch <= '9'; ++ch )
-            setName( ch );
-        setName( '\u00b7' );
-        for ( char ch = '\u0300'; ch <= '\u036f'; ++ch )
-            setName( ch );
+    static {
+        setNameStart(':');
+        for (char ch = 'A'; ch <= 'Z'; ++ch) setNameStart(ch);
+        setNameStart('_');
+        for (char ch = 'a'; ch <= 'z'; ++ch) setNameStart(ch);
+        for (char ch = '\u00c0'; ch <= '\u02FF'; ++ch) setNameStart(ch);
+        for (char ch = '\u0370'; ch <= '\u037d'; ++ch) setNameStart(ch);
+        for (char ch = '\u037f'; ch < '\u0400'; ++ch) setNameStart(ch);
+
+        setName('-');
+        setName('.');
+        for (char ch = '0'; ch <= '9'; ++ch) setName(ch);
+        setName('\u00b7');
+        for (char ch = '\u0300'; ch <= '\u036f'; ++ch) setName(ch);
     }
 
     // protected boolean isNameStartChar( char ch )
-    private static boolean isNameStartChar( char ch )
-    {
-        return ch < LOOKUP_MAX_CHAR ? lookupNameStartChar[ch] : ( ch <= '\u2027' )
-            || ( ch >= '\u202A' && ch <= '\u218F' ) || ( ch >= '\u2800' && ch <= '\uFFEF' );
+    private static boolean isNameStartChar(char ch) {
+        return ch < LOOKUP_MAX_CHAR
+                ? lookupNameStartChar[ch]
+                : (ch <= '\u2027') || (ch >= '\u202A' && ch <= '\u218F') || (ch >= '\u2800' && ch <= '\uFFEF');
 
         // if(ch < LOOKUP_MAX_CHAR) return lookupNameStartChar[ ch ];
         // else return ch <= '\u2027'
@@ -4116,14 +3301,14 @@ private static boolean isNameStartChar( char ch )
     }
 
     // protected boolean isNameChar( char ch )
-    private static boolean isNameChar( char ch )
-    {
+    private static boolean isNameChar(char ch) {
         // return isNameStartChar(ch);
 
         // if(ch < LOOKUP_MAX_CHAR) return (lookupNameChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0;
 
-        return ch < LOOKUP_MAX_CHAR ? lookupNameChar[ch] : ( ch <= '\u2027' )
-            || ( ch >= '\u202A' && ch <= '\u218F' ) || ( ch >= '\u2800' && ch <= '\uFFEF' );
+        return ch < LOOKUP_MAX_CHAR
+                ? lookupNameChar[ch]
+                : (ch <= '\u2027') || (ch >= '\u202A' && ch <= '\u218F') || (ch >= '\u2800' && ch <= '\uFFEF');
         // return false;
         // return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':'
         // || (ch >= '0' && ch <= '9');
@@ -4140,9 +3325,8 @@ private static boolean isNameChar( char ch )
         // else return false;
     }
 
-    private static boolean isS( char ch )
-    {
-        return ( ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' );
+    private static boolean isS(char ch) {
+        return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t');
         // || (supportXml11 && (ch == '\u0085' || ch == '\u2028');
     }
 
@@ -4150,52 +3334,36 @@ private static boolean isS( char ch )
     // ch != '\u0000' ch < '\uFFFE'
 
     // private char printable(char ch) { return ch; }
-    private static String printable( int ch )
-    {
-        if ( ch == '\n' )
-        {
+    private static String printable(int ch) {
+        if (ch == '\n') {
             return "\\n";
-        }
-        else if ( ch == '\r' )
-        {
+        } else if (ch == '\r') {
             return "\\r";
-        }
-        else if ( ch == '\t' )
-        {
+        } else if (ch == '\t') {
             return "\\t";
-        }
-        else if ( ch == '\'' )
-        {
+        } else if (ch == '\'') {
             return "\\'";
         }
-        if ( ch > 127 || ch < 32 )
-        {
-            return "\\u" + Integer.toHexString( ch );
-        }
-        if ( Character.isBmpCodePoint( ch ) )
-        {
-            return Character.toString( ( char ) ch );
+        if (ch > 127 || ch < 32) {
+            return "\\u" + Integer.toHexString(ch);
         }
-        else
-        {
-            return new String( new char[] { Character.highSurrogate( ch ), Character.lowSurrogate( ch ) } );
+        if (Character.isBmpCodePoint(ch)) {
+            return Character.toString((char) ch);
+        } else {
+            return new String(new char[] {Character.highSurrogate(ch), Character.lowSurrogate(ch)});
         }
     }
 
-    private static String printable( String s )
-    {
-        if ( s == null )
-            return null;
+    private static String printable(String s) {
+        if (s == null) return null;
         final int sLen = s.codePointCount(0, s.length());
-        StringBuilder buf = new StringBuilder( sLen + 10 );
-        for ( int i = 0; i < sLen; ++i )
-        {
-            buf.append( printable( s.codePointAt( i ) ) );
+        StringBuilder buf = new StringBuilder(sLen + 10);
+        for (int i = 0; i < sLen; ++i) {
+            buf.append(printable(s.codePointAt(i)));
         }
         s = buf.toString();
         return s;
     }
-
 }
 
 /*
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java b/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java
index c69db3f4..e69d28f8 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java
@@ -25,27 +25,25 @@
  * 
  • PROPERTY_SERIALIZER_LINE_SEPARATOR * */ -public class MXSerializer - implements XmlSerializer -{ - protected final static String XML_URI = "http://www.w3.org/XML/1998/namespace"; +public class MXSerializer implements XmlSerializer { + protected static final String XML_URI = "http://www.w3.org/XML/1998/namespace"; - protected final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; + protected static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; private static final boolean TRACE_SIZING = false; protected final String FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE = - "http://xmlpull.org/v1/doc/features.html#serializer-attvalue-use-apostrophe"; + "http://xmlpull.org/v1/doc/features.html#serializer-attvalue-use-apostrophe"; protected final String FEATURE_NAMES_INTERNED = "http://xmlpull.org/v1/doc/features.html#names-interned"; protected final String PROPERTY_SERIALIZER_INDENTATION = - "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"; + "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"; protected final String PROPERTY_SERIALIZER_LINE_SEPARATOR = - "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator"; + "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator"; - protected final static String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location"; + protected static final String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location"; // properties/features protected boolean namesInterned; @@ -101,36 +99,30 @@ public class MXSerializer protected static final String precomputedPrefixes[]; - static - { + static { precomputedPrefixes = new String[32]; // arbitrary number ... - for ( int i = 0; i < precomputedPrefixes.length; i++ ) - { - precomputedPrefixes[i] = ( "n" + i ).intern(); + for (int i = 0; i < precomputedPrefixes.length; i++) { + precomputedPrefixes[i] = ("n" + i).intern(); } } private boolean checkNamesInterned = false; - private void checkInterning( String name ) - { - if ( namesInterned && name != name.intern() ) - { - throw new IllegalArgumentException( "all names passed as arguments must be interned" - + "when NAMES INTERNED feature is enabled" ); + private void checkInterning(String name) { + if (namesInterned && name != name.intern()) { + throw new IllegalArgumentException( + "all names passed as arguments must be interned" + "when NAMES INTERNED feature is enabled"); } } - protected void reset() - { + protected void reset() { location = null; out = null; autoDeclaredPrefixes = 0; depth = 0; // nullify references on all levels to allow it to be GCed - for ( int i = 0; i < elNamespaceCount.length; i++ ) - { + for (int i = 0; i < elNamespaceCount.length; i++) { elName[i] = null; elNamespace[i] = null; elNamespaceCount[i] = 2; @@ -165,59 +157,49 @@ protected void reset() seenBracketBracket = false; } - protected void ensureElementsCapacity() - { + protected void ensureElementsCapacity() { final int elStackSize = elName.length; // assert (depth + 1) >= elName.length; // we add at least one extra slot ... - final int newSize = ( depth >= 7 ? 2 * depth : 8 ) + 2; // = lucky 7 + 1 //25 - if ( TRACE_SIZING ) - { - System.err.println( getClass().getName() + " elStackSize " + elStackSize + " ==> " + newSize ); + final int newSize = (depth >= 7 ? 2 * depth : 8) + 2; // = lucky 7 + 1 //25 + if (TRACE_SIZING) { + System.err.println(getClass().getName() + " elStackSize " + elStackSize + " ==> " + newSize); } final boolean needsCopying = elStackSize > 0; String[] arr = null; // reuse arr local variable slot arr = new String[newSize]; - if ( needsCopying ) - System.arraycopy( elName, 0, arr, 0, elStackSize ); + if (needsCopying) System.arraycopy(elName, 0, arr, 0, elStackSize); elName = arr; arr = new String[newSize]; - if ( needsCopying ) - System.arraycopy( elNamespace, 0, arr, 0, elStackSize ); + if (needsCopying) System.arraycopy(elNamespace, 0, arr, 0, elStackSize); elNamespace = arr; final int[] iarr = new int[newSize]; - if ( needsCopying ) - { - System.arraycopy( elNamespaceCount, 0, iarr, 0, elStackSize ); - } - else - { + if (needsCopying) { + System.arraycopy(elNamespaceCount, 0, iarr, 0, elStackSize); + } else { // special initialization iarr[0] = 0; } elNamespaceCount = iarr; } - protected void ensureNamespacesCapacity() - { // int size) { + protected void ensureNamespacesCapacity() { // int size) { // int namespaceSize = namespacePrefix != null ? namespacePrefix.length : 0; // assert (namespaceEnd >= namespacePrefix.length); // if(size >= namespaceSize) { // int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25 final int newSize = namespaceEnd > 7 ? 2 * namespaceEnd : 8; - if ( TRACE_SIZING ) - { - System.err.println( getClass().getName() + " namespaceSize " + namespacePrefix.length + " ==> " + newSize ); + if (TRACE_SIZING) { + System.err.println(getClass().getName() + " namespaceSize " + namespacePrefix.length + " ==> " + newSize); } final String[] newNamespacePrefix = new String[newSize]; final String[] newNamespaceUri = new String[newSize]; - if ( namespacePrefix != null ) - { - System.arraycopy( namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd ); - System.arraycopy( namespaceUri, 0, newNamespaceUri, 0, namespaceEnd ); + if (namespacePrefix != null) { + System.arraycopy(namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd); + System.arraycopy(namespaceUri, 0, newNamespaceUri, 0, namespaceEnd); } namespacePrefix = newNamespacePrefix; namespaceUri = newNamespaceUri; @@ -237,45 +219,29 @@ protected void ensureNamespacesCapacity() } @Override - public void setFeature( String name, boolean state ) - throws IllegalArgumentException, IllegalStateException - { - if ( name == null ) - { - throw new IllegalArgumentException( "feature name can not be null" ); + public void setFeature(String name, boolean state) throws IllegalArgumentException, IllegalStateException { + if (name == null) { + throw new IllegalArgumentException("feature name can not be null"); } - if ( FEATURE_NAMES_INTERNED.equals( name ) ) - { + if (FEATURE_NAMES_INTERNED.equals(name)) { namesInterned = state; - } - else if ( FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals( name ) ) - { + } else if (FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals(name)) { attributeUseApostrophe = state; - } - else - { - throw new IllegalStateException( "unsupported feature " + name ); + } else { + throw new IllegalStateException("unsupported feature " + name); } } @Override - public boolean getFeature( String name ) - throws IllegalArgumentException - { - if ( name == null ) - { - throw new IllegalArgumentException( "feature name can not be null" ); + public boolean getFeature(String name) throws IllegalArgumentException { + if (name == null) { + throw new IllegalArgumentException("feature name can not be null"); } - if ( FEATURE_NAMES_INTERNED.equals( name ) ) - { + if (FEATURE_NAMES_INTERNED.equals(name)) { return namesInterned; - } - else if ( FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals( name ) ) - { + } else if (FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals(name)) { return attributeUseApostrophe; - } - else - { + } else { return false; } } @@ -297,86 +263,64 @@ else if ( FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals( name ) ) * For maximum efficiency when writing indents the required output is pre-computed This is internal function that * recomputes buffer after user requested changes. */ - protected void rebuildIndentationBuf() - { - if ( doIndent == false ) - return; + protected void rebuildIndentationBuf() { + if (doIndent == false) return; final int maxIndent = 65; // hardcoded maximum indentation size in characters int bufSize = 0; offsetNewLine = 0; - if ( writeLineSeparator ) - { + if (writeLineSeparator) { offsetNewLine = lineSeparator.length(); bufSize += offsetNewLine; } maxIndentLevel = 0; - if ( writeIndentation ) - { + if (writeIndentation) { indentationJump = indentationString.length(); maxIndentLevel = maxIndent / indentationJump; bufSize += maxIndentLevel * indentationJump; } - if ( indentationBuf == null || indentationBuf.length < bufSize ) - { + if (indentationBuf == null || indentationBuf.length < bufSize) { indentationBuf = new char[bufSize + 8]; } int bufPos = 0; - if ( writeLineSeparator ) - { - for ( int i = 0; i < lineSeparator.length(); i++ ) - { - indentationBuf[bufPos++] = lineSeparator.charAt( i ); + if (writeLineSeparator) { + for (int i = 0; i < lineSeparator.length(); i++) { + indentationBuf[bufPos++] = lineSeparator.charAt(i); } } - if ( writeIndentation ) - { - for ( int i = 0; i < maxIndentLevel; i++ ) - { - for ( int j = 0; j < indentationString.length(); j++ ) - { - indentationBuf[bufPos++] = indentationString.charAt( j ); + if (writeIndentation) { + for (int i = 0; i < maxIndentLevel; i++) { + for (int j = 0; j < indentationString.length(); j++) { + indentationBuf[bufPos++] = indentationString.charAt(j); } } } } // if(doIndent) writeIndent(); - protected void writeIndent() - throws IOException - { + protected void writeIndent() throws IOException { final int start = writeLineSeparator ? 0 : offsetNewLine; - final int level = ( depth > maxIndentLevel ) ? maxIndentLevel : depth; - out.write( indentationBuf, start, ( level * indentationJump ) + offsetNewLine ); + final int level = (depth > maxIndentLevel) ? maxIndentLevel : depth; + out.write(indentationBuf, start, (level * indentationJump) + offsetNewLine); } @Override - public void setProperty( String name, Object value ) - throws IllegalArgumentException, IllegalStateException - { - if ( name == null ) - { - throw new IllegalArgumentException( "property name can not be null" ); + public void setProperty(String name, Object value) throws IllegalArgumentException, IllegalStateException { + if (name == null) { + throw new IllegalArgumentException("property name can not be null"); } - if ( PROPERTY_SERIALIZER_INDENTATION.equals( name ) ) - { + if (PROPERTY_SERIALIZER_INDENTATION.equals(name)) { indentationString = (String) value; - } - else if ( PROPERTY_SERIALIZER_LINE_SEPARATOR.equals( name ) ) - { + } else if (PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) { lineSeparator = (String) value; - } - else if ( PROPERTY_LOCATION.equals( name ) ) - { + } else if (PROPERTY_LOCATION.equals(name)) { location = (String) value; - } - else - { - throw new IllegalStateException( "unsupported property " + name ); + } else { + throw new IllegalStateException("unsupported property " + name); } writeLineSeparator = lineSeparator != null && lineSeparator.length() > 0; writeIndentation = indentationString != null && indentationString.length() > 0; // optimize - do not write when nothing to write ... - doIndent = indentationString != null && ( writeLineSeparator || writeIndentation ); + doIndent = indentationString != null && (writeLineSeparator || writeIndentation); // NOTE: when indentationString == null there is no indentation // (even though writeLineSeparator may be true ...) rebuildIndentationBuf(); @@ -384,125 +328,91 @@ else if ( PROPERTY_LOCATION.equals( name ) ) } @Override - public Object getProperty( String name ) - throws IllegalArgumentException - { - if ( name == null ) - { - throw new IllegalArgumentException( "property name can not be null" ); + public Object getProperty(String name) throws IllegalArgumentException { + if (name == null) { + throw new IllegalArgumentException("property name can not be null"); } - if ( PROPERTY_SERIALIZER_INDENTATION.equals( name ) ) - { + if (PROPERTY_SERIALIZER_INDENTATION.equals(name)) { return indentationString; - } - else if ( PROPERTY_SERIALIZER_LINE_SEPARATOR.equals( name ) ) - { + } else if (PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) { return lineSeparator; - } - else if ( PROPERTY_LOCATION.equals( name ) ) - { + } else if (PROPERTY_LOCATION.equals(name)) { return location; - } - else - { + } else { return null; } } - private String getLocation() - { + private String getLocation() { return location != null ? " @" + location : ""; } // this is special method that can be accessed directly to retrieve Writer serializer is using - public Writer getWriter() - { + public Writer getWriter() { return out; } @Override - public void setOutput( Writer writer ) - { + public void setOutput(Writer writer) { reset(); out = writer; } @Override - public void setOutput( OutputStream os, String encoding ) - throws IOException - { - if ( os == null ) - throw new IllegalArgumentException( "output stream can not be null" ); + public void setOutput(OutputStream os, String encoding) throws IOException { + if (os == null) throw new IllegalArgumentException("output stream can not be null"); reset(); - if ( encoding != null ) - { - out = new OutputStreamWriter( os, encoding ); - } - else - { - out = new OutputStreamWriter( os ); + if (encoding != null) { + out = new OutputStreamWriter(os, encoding); + } else { + out = new OutputStreamWriter(os); } } @Override - public void startDocument( String encoding, Boolean standalone ) - throws IOException - { + public void startDocument(String encoding, Boolean standalone) throws IOException { char apos = attributeUseApostrophe ? '\'' : '"'; - if ( attributeUseApostrophe ) - { - out.write( "" ); - if ( writeLineSeparator ) - { - out.write( lineSeparator ); + out.write("?>"); + if (writeLineSeparator) { + out.write(lineSeparator); } } @Override - public void endDocument() - throws IOException - { + public void endDocument() throws IOException { // close all unclosed tag; - while ( depth > 0 ) - { - endTag( elNamespace[depth], elName[depth] ); + while (depth > 0) { + endTag(elNamespace[depth], elName[depth]); } - if ( writeLineSeparator ) - { - out.write( lineSeparator ); + if (writeLineSeparator) { + out.write(lineSeparator); } // assert depth == 0; // assert startTagIncomplete == false; @@ -511,54 +421,37 @@ public void endDocument() } @Override - public void setPrefix( String prefix, String namespace ) - throws IOException - { - if ( startTagIncomplete ) - closeStartTag(); + public void setPrefix(String prefix, String namespace) throws IOException { + if (startTagIncomplete) closeStartTag(); // assert prefix != null; // assert namespace != null; - if ( prefix == null ) - { + if (prefix == null) { prefix = ""; } - if ( !namesInterned ) - { + if (!namesInterned) { prefix = prefix.intern(); // will throw NPE if prefix==null - } - else if ( checkNamesInterned ) - { - checkInterning( prefix ); - } - else if ( prefix == null ) - { - throw new IllegalArgumentException( "prefix must be not null" + getLocation() ); + } else if (checkNamesInterned) { + checkInterning(prefix); + } else if (prefix == null) { + throw new IllegalArgumentException("prefix must be not null" + getLocation()); } // check that prefix is not duplicated ... - for ( int i = elNamespaceCount[depth]; i < namespaceEnd; i++ ) - { - if ( prefix == namespacePrefix[i] ) - { - throw new IllegalStateException( "duplicated prefix " + printable( prefix ) + getLocation() ); + for (int i = elNamespaceCount[depth]; i < namespaceEnd; i++) { + if (prefix == namespacePrefix[i]) { + throw new IllegalStateException("duplicated prefix " + printable(prefix) + getLocation()); } } - if ( !namesInterned ) - { + if (!namesInterned) { namespace = namespace.intern(); - } - else if ( checkNamesInterned ) - { - checkInterning( namespace ); - } - else if ( namespace == null ) - { - throw new IllegalArgumentException( "namespace must be not null" + getLocation() ); + } else if (checkNamesInterned) { + checkInterning(namespace); + } else if (namespace == null) { + throw new IllegalArgumentException("namespace must be not null" + getLocation()); } - if ( namespaceEnd >= namespacePrefix.length ) - { + if (namespaceEnd >= namespacePrefix.length) { ensureNamespacesCapacity(); } namespacePrefix[namespaceEnd] = prefix; @@ -567,44 +460,33 @@ else if ( namespace == null ) setPrefixCalled = true; } - protected String lookupOrDeclarePrefix( String namespace ) - { - return getPrefix( namespace, true ); + protected String lookupOrDeclarePrefix(String namespace) { + return getPrefix(namespace, true); } @Override - public String getPrefix( String namespace, boolean generatePrefix ) - { + public String getPrefix(String namespace, boolean generatePrefix) { // assert namespace != null; - if ( !namesInterned ) - { + if (!namesInterned) { // when String is interned we can do much faster namespace stack lookups ... namespace = namespace.intern(); - } - else if ( checkNamesInterned ) - { - checkInterning( namespace ); + } else if (checkNamesInterned) { + checkInterning(namespace); // assert namespace != namespace.intern(); } - if ( namespace == null ) - { - throw new IllegalArgumentException( "namespace must be not null" + getLocation() ); - } - else if ( namespace.length() == 0 ) - { - throw new IllegalArgumentException( "default namespace cannot have prefix" + getLocation() ); + if (namespace == null) { + throw new IllegalArgumentException("namespace must be not null" + getLocation()); + } else if (namespace.length() == 0) { + throw new IllegalArgumentException("default namespace cannot have prefix" + getLocation()); } // first check if namespace is already in scope - for ( int i = namespaceEnd - 1; i >= 0; --i ) - { - if ( namespace == namespaceUri[i] ) - { + for (int i = namespaceEnd - 1; i >= 0; --i) { + if (namespace == namespaceUri[i]) { final String prefix = namespacePrefix[i]; // now check that prefix is still in scope - for ( int p = namespaceEnd - 1; p > i; --p ) - { - if ( prefix == namespacePrefix[p] ) + for (int p = namespaceEnd - 1; p > i; --p) { + if (prefix == namespacePrefix[p]) continue; // too bad - prefix is redeclared with different namespace } return prefix; @@ -612,35 +494,29 @@ else if ( namespace.length() == 0 ) } // so not found it ... - if ( !generatePrefix ) - { + if (!generatePrefix) { return null; } - return generatePrefix( namespace ); + return generatePrefix(namespace); } - private String generatePrefix( String namespace ) - { + private String generatePrefix(String namespace) { // assert namespace == namespace.intern(); - while ( true ) - { + while (true) { ++autoDeclaredPrefixes; // fast lookup uses table that was pre-initialized in static{} .... - final String prefix = - autoDeclaredPrefixes < precomputedPrefixes.length ? precomputedPrefixes[autoDeclaredPrefixes] - : ( "n" + autoDeclaredPrefixes ).intern(); + final String prefix = autoDeclaredPrefixes < precomputedPrefixes.length + ? precomputedPrefixes[autoDeclaredPrefixes] + : ("n" + autoDeclaredPrefixes).intern(); // make sure this prefix is not declared in any scope (avoid hiding in-scope prefixes)! - for ( int i = namespaceEnd - 1; i >= 0; --i ) - { - if ( prefix == namespacePrefix[i] ) - { + for (int i = namespaceEnd - 1; i >= 0; --i) { + if (prefix == namespacePrefix[i]) { continue; // prefix is already declared - generate new and try again } } // declare prefix - if ( namespaceEnd >= namespacePrefix.length ) - { + if (namespaceEnd >= namespacePrefix.length) { ensureNamespacesCapacity(); } namespacePrefix[namespaceEnd] = prefix; @@ -652,84 +528,66 @@ private String generatePrefix( String namespace ) } @Override - public int getDepth() - { + public int getDepth() { return depth; } @Override - public String getNamespace() - { + public String getNamespace() { return elNamespace[depth]; } @Override - public String getName() - { + public String getName() { return elName[depth]; } @Override - public XmlSerializer startTag( String namespace, String name ) - throws IOException - { + public XmlSerializer startTag(String namespace, String name) throws IOException { - if ( startTagIncomplete ) - { + if (startTagIncomplete) { closeStartTag(); } seenBracket = seenBracketBracket = false; - if ( doIndent && depth > 0 && seenTag ) - { + if (doIndent && depth > 0 && seenTag) { writeIndent(); } seenTag = true; setPrefixCalled = false; startTagIncomplete = true; ++depth; - if ( ( depth + 1 ) >= elName.length ) - { + if ((depth + 1) >= elName.length) { ensureElementsCapacity(); } //// assert namespace != null; - if ( checkNamesInterned && namesInterned ) - checkInterning( namespace ); - elNamespace[depth] = ( namesInterned || namespace == null ) ? namespace : namespace.intern(); + if (checkNamesInterned && namesInterned) checkInterning(namespace); + elNamespace[depth] = (namesInterned || namespace == null) ? namespace : namespace.intern(); // assert name != null; // elName[ depth ] = name; - if ( checkNamesInterned && namesInterned ) - checkInterning( name ); - elName[depth] = ( namesInterned || name == null ) ? name : name.intern(); - if ( out == null ) - { - throw new IllegalStateException( "setOutput() must called set before serialization can start" ); + if (checkNamesInterned && namesInterned) checkInterning(name); + elName[depth] = (namesInterned || name == null) ? name : name.intern(); + if (out == null) { + throw new IllegalStateException("setOutput() must called set before serialization can start"); } - out.write( '<' ); - if ( namespace != null ) - { + out.write('<'); + if (namespace != null) { - if ( namespace.length() > 0 ) - { + if (namespace.length() > 0) { // ALEK: in future make it as feature on serializer String prefix = null; - if ( depth > 0 && ( namespaceEnd - elNamespaceCount[depth - 1] ) == 1 ) - { + if (depth > 0 && (namespaceEnd - elNamespaceCount[depth - 1]) == 1) { // if only one prefix was declared un-declare it if prefix is already declared on parent el with the // same URI String uri = namespaceUri[namespaceEnd - 1]; - if ( uri == namespace || uri.equals( namespace ) ) - { + if (uri == namespace || uri.equals(namespace)) { String elPfx = namespacePrefix[namespaceEnd - 1]; // 2 == to skip predefined namespaces (xml and xmlns ...) - for ( int pos = elNamespaceCount[depth - 1] - 1; pos >= 2; --pos ) - { + for (int pos = elNamespaceCount[depth - 1] - 1; pos >= 2; --pos) { String pf = namespacePrefix[pos]; - if ( pf == elPfx || pf.equals( elPfx ) ) - { + if (pf == elPfx || pf.equals(elPfx)) { String n = namespaceUri[pos]; - if ( n == uri || n.equals( uri ) ) - { + if (n == uri || n.equals(uri)) { --namespaceEnd; // un-declare namespace prefix = elPfx; } @@ -738,224 +596,175 @@ public XmlSerializer startTag( String namespace, String name ) } } } - if ( prefix == null ) - { - prefix = lookupOrDeclarePrefix( namespace ); + if (prefix == null) { + prefix = lookupOrDeclarePrefix(namespace); } // assert prefix != null; // make sure that default ("") namespace to not print ":" - if ( prefix.length() > 0 ) - { - out.write( prefix ); - out.write( ':' ); + if (prefix.length() > 0) { + out.write(prefix); + out.write(':'); } - } - else - { + } else { // make sure that default namespace can be declared - for ( int i = namespaceEnd - 1; i >= 0; --i ) - { - if ( namespacePrefix[i] == "" ) - { + for (int i = namespaceEnd - 1; i >= 0; --i) { + if (namespacePrefix[i] == "") { final String uri = namespaceUri[i]; - if ( uri == null ) - { + if (uri == null) { // declare default namespace - setPrefix( "", "" ); - } - else if ( uri.length() > 0 ) - { - throw new IllegalStateException( "start tag can not be written in empty default namespace " - + "as default namespace is currently bound to '" + uri + "'" + getLocation() ); + setPrefix("", ""); + } else if (uri.length() > 0) { + throw new IllegalStateException("start tag can not be written in empty default namespace " + + "as default namespace is currently bound to '" + uri + "'" + getLocation()); } break; } } } - } - out.write( name ); + out.write(name); return this; } @Override - public XmlSerializer attribute( String namespace, String name, String value ) - throws IOException - { - if ( !startTagIncomplete ) - { - throw new IllegalArgumentException( "startTag() must be called before attribute()" + getLocation() ); + public XmlSerializer attribute(String namespace, String name, String value) throws IOException { + if (!startTagIncomplete) { + throw new IllegalArgumentException("startTag() must be called before attribute()" + getLocation()); } // assert setPrefixCalled == false; - out.write( ' ' ); + out.write(' '); //// assert namespace != null; - if ( namespace != null && namespace.length() > 0 ) - { + if (namespace != null && namespace.length() > 0) { // namespace = namespace.intern(); - if ( !namesInterned ) - { + if (!namesInterned) { namespace = namespace.intern(); + } else if (checkNamesInterned) { + checkInterning(namespace); } - else if ( checkNamesInterned ) - { - checkInterning( namespace ); - } - String prefix = lookupOrDeclarePrefix( namespace ); + String prefix = lookupOrDeclarePrefix(namespace); // assert( prefix != null); - if ( prefix.length() == 0 ) - { + if (prefix.length() == 0) { // needs to declare prefix to hold default namespace // NOTE: attributes such as a='b' are in NO namespace - prefix = generatePrefix( namespace ); + prefix = generatePrefix(namespace); } - out.write( prefix ); - out.write( ':' ); + out.write(prefix); + out.write(':'); // if(prefix.length() > 0) { // out.write(prefix); // out.write(':'); // } } // assert name != null; - out.write( name ); - out.write( '=' ); + out.write(name); + out.write('='); // assert value != null; - out.write( attributeUseApostrophe ? '\'' : '"' ); - writeAttributeValue( value, out ); - out.write( attributeUseApostrophe ? '\'' : '"' ); + out.write(attributeUseApostrophe ? '\'' : '"'); + writeAttributeValue(value, out); + out.write(attributeUseApostrophe ? '\'' : '"'); return this; } - protected void closeStartTag() - throws IOException - { - if ( finished ) - { - throw new IllegalArgumentException( "trying to write past already finished output" + getLocation() ); + protected void closeStartTag() throws IOException { + if (finished) { + throw new IllegalArgumentException("trying to write past already finished output" + getLocation()); } - if ( seenBracket ) - { + if (seenBracket) { seenBracket = seenBracketBracket = false; } - if ( startTagIncomplete || setPrefixCalled ) - { - if ( setPrefixCalled ) - { - throw new IllegalArgumentException( "startTag() must be called immediately after setPrefix()" - + getLocation() ); + if (startTagIncomplete || setPrefixCalled) { + if (setPrefixCalled) { + throw new IllegalArgumentException( + "startTag() must be called immediately after setPrefix()" + getLocation()); } - if ( !startTagIncomplete ) - { - throw new IllegalArgumentException( "trying to close start tag that is not opened" + getLocation() ); + if (!startTagIncomplete) { + throw new IllegalArgumentException("trying to close start tag that is not opened" + getLocation()); } // write all namespace declarations! writeNamespaceDeclarations(); - out.write( '>' ); + out.write('>'); elNamespaceCount[depth] = namespaceEnd; startTagIncomplete = false; } } - private void writeNamespaceDeclarations() - throws IOException - { + private void writeNamespaceDeclarations() throws IOException { // int start = elNamespaceCount[ depth - 1 ]; - for ( int i = elNamespaceCount[depth - 1]; i < namespaceEnd; i++ ) - { - if ( doIndent && namespaceUri[i].length() > 40 ) - { + for (int i = elNamespaceCount[depth - 1]; i < namespaceEnd; i++) { + if (doIndent && namespaceUri[i].length() > 40) { writeIndent(); - out.write( " " ); + out.write(" "); } - if ( namespacePrefix[i] != "" ) - { - out.write( " xmlns:" ); - out.write( namespacePrefix[i] ); - out.write( '=' ); + if (namespacePrefix[i] != "") { + out.write(" xmlns:"); + out.write(namespacePrefix[i]); + out.write('='); + } else { + out.write(" xmlns="); } - else - { - out.write( " xmlns=" ); - } - out.write( attributeUseApostrophe ? '\'' : '"' ); + out.write(attributeUseApostrophe ? '\'' : '"'); // NOTE: escaping of namespace value the same way as attributes!!!! - writeAttributeValue( namespaceUri[i], out ); + writeAttributeValue(namespaceUri[i], out); - out.write( attributeUseApostrophe ? '\'' : '"' ); + out.write(attributeUseApostrophe ? '\'' : '"'); } } @Override - public XmlSerializer endTag( String namespace, String name ) - throws IOException - { + public XmlSerializer endTag(String namespace, String name) throws IOException { // check that level is valid //// assert namespace != null; // if(namespace != null) { // namespace = namespace.intern(); // } seenBracket = seenBracketBracket = false; - if ( namespace != null ) - { - if ( !namesInterned ) - { + if (namespace != null) { + if (!namesInterned) { namespace = namespace.intern(); - } - else if ( checkNamesInterned ) - { - checkInterning( namespace ); + } else if (checkNamesInterned) { + checkInterning(namespace); } } - if ( namespace != elNamespace[depth] ) - { - throw new IllegalArgumentException( "expected namespace " + printable( elNamespace[depth] ) + " and not " - + printable( namespace ) + getLocation() ); + if (namespace != elNamespace[depth]) { + throw new IllegalArgumentException("expected namespace " + printable(elNamespace[depth]) + " and not " + + printable(namespace) + getLocation()); } - if ( name == null ) - { - throw new IllegalArgumentException( "end tag name can not be null" + getLocation() ); + if (name == null) { + throw new IllegalArgumentException("end tag name can not be null" + getLocation()); } - if ( checkNamesInterned && namesInterned ) - { - checkInterning( name ); + if (checkNamesInterned && namesInterned) { + checkInterning(name); } - if ( ( !namesInterned && !name.equals( elName[depth] ) ) || ( namesInterned && name != elName[depth] ) ) - { - throw new IllegalArgumentException( "expected element name " + printable( elName[depth] ) + " and not " - + printable( name ) + getLocation() ); + if ((!namesInterned && !name.equals(elName[depth])) || (namesInterned && name != elName[depth])) { + throw new IllegalArgumentException("expected element name " + printable(elName[depth]) + " and not " + + printable(name) + getLocation()); } - if ( startTagIncomplete ) - { + if (startTagIncomplete) { writeNamespaceDeclarations(); - out.write( " />" ); // space is added to make it easier to work in XHTML!!! + out.write(" />"); // space is added to make it easier to work in XHTML!!! --depth; - } - else - { + } else { --depth; // assert startTagIncomplete == false; - if ( doIndent && seenTag ) - { + if (doIndent && seenTag) { writeIndent(); } - out.write( " 0 ) - { + out.write(" 0) { // TODO prefix should be already known from matching start tag ... - final String prefix = lookupOrDeclarePrefix( namespace ); + final String prefix = lookupOrDeclarePrefix(namespace); // assert( prefix != null); - if ( prefix.length() > 0 ) - { - out.write( prefix ); - out.write( ':' ); + if (prefix.length() > 0) { + out.write(prefix); + out.write(':'); } } - out.write( name ); - out.write( '>' ); - + out.write(name); + out.write('>'); } namespaceEnd = elNamespaceCount[depth]; startTagIncomplete = false; @@ -964,171 +773,118 @@ else if ( checkNamesInterned ) } @Override - public XmlSerializer text( String text ) - throws IOException - { + public XmlSerializer text(String text) throws IOException { // assert text != null; - if ( startTagIncomplete || setPrefixCalled ) - closeStartTag(); - if ( doIndent && seenTag ) - seenTag = false; - writeElementContent( text, out ); + if (startTagIncomplete || setPrefixCalled) closeStartTag(); + if (doIndent && seenTag) seenTag = false; + writeElementContent(text, out); return this; } @Override - public XmlSerializer text( char[] buf, int start, int len ) - throws IOException - { - if ( startTagIncomplete || setPrefixCalled ) - closeStartTag(); - if ( doIndent && seenTag ) - seenTag = false; - writeElementContent( buf, start, len, out ); + public XmlSerializer text(char[] buf, int start, int len) throws IOException { + if (startTagIncomplete || setPrefixCalled) closeStartTag(); + if (doIndent && seenTag) seenTag = false; + writeElementContent(buf, start, len, out); return this; } @Override - public void cdsect( String text ) - throws IOException - { - if ( startTagIncomplete || setPrefixCalled || seenBracket ) - closeStartTag(); - if ( doIndent && seenTag ) - seenTag = false; - out.write( "" ); + public void cdsect(String text) throws IOException { + if (startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); + if (doIndent && seenTag) seenTag = false; + out.write(""); } @Override - public void entityRef( String text ) - throws IOException - { - if ( startTagIncomplete || setPrefixCalled || seenBracket ) - closeStartTag(); - if ( doIndent && seenTag ) - seenTag = false; - out.write( '&' ); - out.write( text ); // escape? - out.write( ';' ); + public void entityRef(String text) throws IOException { + if (startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); + if (doIndent && seenTag) seenTag = false; + out.write('&'); + out.write(text); // escape? + out.write(';'); } @Override - public void processingInstruction( String text ) - throws IOException - { - if ( startTagIncomplete || setPrefixCalled || seenBracket ) - closeStartTag(); - if ( doIndent && seenTag ) - seenTag = false; - out.write( "" ); + public void processingInstruction(String text) throws IOException { + if (startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); + if (doIndent && seenTag) seenTag = false; + out.write(""); } @Override - public void comment( String text ) - throws IOException - { - if ( startTagIncomplete || setPrefixCalled || seenBracket ) - closeStartTag(); - if ( doIndent && seenTag ) - seenTag = false; - out.write( "" ); + public void comment(String text) throws IOException { + if (startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); + if (doIndent && seenTag) seenTag = false; + out.write(""); } @Override - public void docdecl( String text ) - throws IOException - { - if ( startTagIncomplete || setPrefixCalled || seenBracket ) - closeStartTag(); - if ( doIndent && seenTag ) - seenTag = false; - out.write( "" ); + public void docdecl(String text) throws IOException { + if (startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); + if (doIndent && seenTag) seenTag = false; + out.write(""); } @Override - public void ignorableWhitespace( String text ) - throws IOException - { - if ( startTagIncomplete || setPrefixCalled || seenBracket ) - closeStartTag(); - if ( doIndent && seenTag ) - seenTag = false; - if ( text.length() == 0 ) - { - throw new IllegalArgumentException( "empty string is not allowed for ignorable whitespace" - + getLocation() ); + public void ignorableWhitespace(String text) throws IOException { + if (startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); + if (doIndent && seenTag) seenTag = false; + if (text.length() == 0) { + throw new IllegalArgumentException("empty string is not allowed for ignorable whitespace" + getLocation()); } - out.write( text ); // no escape? + out.write(text); // no escape? } @Override - public void flush() - throws IOException - { - if ( !finished && startTagIncomplete ) - closeStartTag(); + public void flush() throws IOException { + if (!finished && startTagIncomplete) closeStartTag(); out.flush(); } // --- utility methods - protected void writeAttributeValue( String value, Writer out ) - throws IOException - { + protected void writeAttributeValue(String value, Writer out) throws IOException { // .[apostrophe and <, & escaped], final char quot = attributeUseApostrophe ? '\'' : '"'; final String quotEntity = attributeUseApostrophe ? "'" : """; int pos = 0; - for ( int i = 0; i < value.length(); i++ ) - { - char ch = value.charAt( i ); - if ( ch == '&' ) - { - if ( i > pos ) - out.write( value.substring( pos, i ) ); - out.write( "&" ); + for (int i = 0; i < value.length(); i++) { + char ch = value.charAt(i); + if (ch == '&') { + if (i > pos) out.write(value.substring(pos, i)); + out.write("&"); pos = i + 1; } - if ( ch == '<' ) - { - if ( i > pos ) - out.write( value.substring( pos, i ) ); - out.write( "<" ); + if (ch == '<') { + if (i > pos) out.write(value.substring(pos, i)); + out.write("<"); pos = i + 1; - } - else if ( ch == quot ) - { - if ( i > pos ) - out.write( value.substring( pos, i ) ); - out.write( quotEntity ); + } else if (ch == quot) { + if (i > pos) out.write(value.substring(pos, i)); + out.write(quotEntity); pos = i + 1; - } - else if ( ch < 32 ) - { + } else if (ch < 32) { // in XML 1.0 only legal character are #x9 | #xA | #xD // and they must be escaped otherwise in attribute value they are normalized to spaces - if ( ch == 13 || ch == 10 || ch == 9 ) - { - if ( i > pos ) - out.write( value.substring( pos, i ) ); - out.write( "&#" ); - out.write( Integer.toString( ch ) ); - out.write( ';' ); + if (ch == 13 || ch == 10 || ch == 9) { + if (i > pos) out.write(value.substring(pos, i)); + out.write("&#"); + out.write(Integer.toString(ch)); + out.write(';'); pos = i + 1; - } - else - { - throw new IllegalStateException( "character " + Integer.toString( ch ) + " is not allowed in output" - + getLocation() ); + } else { + throw new IllegalStateException( + "character " + Integer.toString(ch) + " is not allowed in output" + getLocation()); // in XML 1.1 legal are [#x1-#xD7FF] // if(ch > 0) { // if(i > pos) out.write(text.substring(pos, i)); @@ -1143,65 +899,41 @@ else if ( ch < 32 ) } } } - if ( pos > 0 ) - { - out.write( value.substring( pos ) ); - } - else - { - out.write( value ); // this is shortcut to the most common case + if (pos > 0) { + out.write(value.substring(pos)); + } else { + out.write(value); // this is shortcut to the most common case } - } - protected void writeElementContent( String text, Writer out ) - throws IOException - { + protected void writeElementContent(String text, Writer out) throws IOException { // escape '<', '&', ']]>', <32 if necessary int pos = 0; - for ( int i = 0; i < text.length(); i++ ) - { + for (int i = 0; i < text.length(); i++) { // TODO: check if doing char[] text.getChars() would be faster than getCharAt(i) ... - char ch = text.charAt( i ); - if ( ch == ']' ) - { - if ( seenBracket ) - { + char ch = text.charAt(i); + if (ch == ']') { + if (seenBracket) { seenBracketBracket = true; - } - else - { + } else { seenBracket = true; } - } - else - { - if ( ch == '&' ) - { - if ( i > pos ) - out.write( text.substring( pos, i ) ); - out.write( "&" ); + } else { + if (ch == '&') { + if (i > pos) out.write(text.substring(pos, i)); + out.write("&"); pos = i + 1; - } - else if ( ch == '<' ) - { - if ( i > pos ) - out.write( text.substring( pos, i ) ); - out.write( "<" ); + } else if (ch == '<') { + if (i > pos) out.write(text.substring(pos, i)); + out.write("<"); pos = i + 1; - } - else if ( seenBracketBracket && ch == '>' ) - { - if ( i > pos ) - out.write( text.substring( pos, i ) ); - out.write( ">" ); + } else if (seenBracketBracket && ch == '>') { + if (i > pos) out.write(text.substring(pos, i)); + out.write(">"); pos = i + 1; - } - else if ( ch < 32 ) - { + } else if (ch < 32) { // in XML 1.0 only legal character are #x9 | #xA | #xD - if ( ch == 9 || ch == 10 || ch == 13 ) - { + if (ch == 9 || ch == 10 || ch == 13) { // pass through // } else if(ch == 13) { //escape @@ -1210,11 +942,9 @@ else if ( ch < 32 ) // out.write(Integer.toString(ch)); // out.write(';'); // pos = i + 1; - } - else - { - throw new IllegalStateException( "character " + Integer.toString( ch ) - + " is not allowed in output" + getLocation() ); + } else { + throw new IllegalStateException( + "character " + Integer.toString(ch) + " is not allowed in output" + getLocation()); // in XML 1.1 legal are [#x1-#xD7FF] // if(ch > 0) { // if(i > pos) out.write(text.substring(pos, i)); @@ -1228,79 +958,53 @@ else if ( ch < 32 ) // } } } - if ( seenBracket ) - { + if (seenBracket) { seenBracketBracket = seenBracket = false; } - } } - if ( pos > 0 ) - { - out.write( text.substring( pos ) ); - } - else - { - out.write( text ); // this is shortcut to the most common case + if (pos > 0) { + out.write(text.substring(pos)); + } else { + out.write(text); // this is shortcut to the most common case } - } - protected void writeElementContent( char[] buf, int off, int len, Writer out ) - throws IOException - { + protected void writeElementContent(char[] buf, int off, int len, Writer out) throws IOException { // escape '<', '&', ']]>' final int end = off + len; int pos = off; - for ( int i = off; i < end; i++ ) - { + for (int i = off; i < end; i++) { final char ch = buf[i]; - if ( ch == ']' ) - { - if ( seenBracket ) - { + if (ch == ']') { + if (seenBracket) { seenBracketBracket = true; - } - else - { + } else { seenBracket = true; } - } - else - { - if ( ch == '&' ) - { - if ( i > pos ) - { - out.write( buf, pos, i - pos ); + } else { + if (ch == '&') { + if (i > pos) { + out.write(buf, pos, i - pos); } - out.write( "&" ); + out.write("&"); pos = i + 1; - } - else if ( ch == '<' ) - { - if ( i > pos ) - { - out.write( buf, pos, i - pos ); + } else if (ch == '<') { + if (i > pos) { + out.write(buf, pos, i - pos); } - out.write( "<" ); + out.write("<"); pos = i + 1; - } - else if ( seenBracketBracket && ch == '>' ) - { - if ( i > pos ) - { - out.write( buf, pos, i - pos ); + } else if (seenBracketBracket && ch == '>') { + if (i > pos) { + out.write(buf, pos, i - pos); } - out.write( ">" ); + out.write(">"); pos = i + 1; - } - else if ( ch < 32 ) - { + } else if (ch < 32) { // in XML 1.0 only legal character are #x9 | #xA | #xD - if ( ch == 9 || ch == 10 || ch == 13 ) - { + if (ch == 9 || ch == 10 || ch == 13) { // pass through // } else if(ch == 13 ) { //if(ch == '\r') { @@ -1311,11 +1015,9 @@ else if ( ch < 32 ) // out.write(Integer.toString(ch)); // out.write(';'); // pos = i + 1; - } - else - { - throw new IllegalStateException( "character " + Integer.toString( ch ) - + " is not allowed in output" + getLocation() ); + } else { + throw new IllegalStateException( + "character " + Integer.toString(ch) + " is not allowed in output" + getLocation()); // in XML 1.1 legal are [#x1-#xD7FF] // if(ch > 0) { // if(i > pos) out.write(text.substring(pos, i)); @@ -1329,81 +1031,69 @@ else if ( ch < 32 ) // } } } - if ( seenBracket ) - { + if (seenBracket) { seenBracketBracket = seenBracket = false; } // assert seenBracketBracket == seenBracket == false; } } - if ( end > pos ) - { - out.write( buf, pos, end - pos ); + if (end > pos) { + out.write(buf, pos, end - pos); } } // simple utility method -- good for debugging - protected static final String printable( String s ) - { - if ( s == null ) - return "null"; - StringBuilder retval = new StringBuilder( s.length() + 16 ); - retval.append( "'" ); + protected static final String printable(String s) { + if (s == null) return "null"; + StringBuilder retval = new StringBuilder(s.length() + 16); + retval.append("'"); char ch; - for ( int i = 0; i < s.length(); i++ ) - { - addPrintable( retval, s.charAt( i ) ); + for (int i = 0; i < s.length(); i++) { + addPrintable(retval, s.charAt(i)); } - retval.append( "'" ); + retval.append("'"); return retval.toString(); } - protected static final String printable( char ch ) - { + protected static final String printable(char ch) { StringBuilder retval = new StringBuilder(); - addPrintable( retval, ch ); + addPrintable(retval, ch); return retval.toString(); } - private static void addPrintable( StringBuilder retval, char ch ) - { - switch ( ch ) - { + private static void addPrintable(StringBuilder retval, char ch) { + switch (ch) { case '\b': - retval.append( "\\b" ); + retval.append("\\b"); break; case '\t': - retval.append( "\\t" ); + retval.append("\\t"); break; case '\n': - retval.append( "\\n" ); + retval.append("\\n"); break; case '\f': - retval.append( "\\f" ); + retval.append("\\f"); break; case '\r': - retval.append( "\\r" ); + retval.append("\\r"); break; case '\"': - retval.append( "\\\"" ); + retval.append("\\\""); break; case '\'': - retval.append( "\\\'" ); + retval.append("\\\'"); break; case '\\': - retval.append( "\\\\" ); + retval.append("\\\\"); break; default: - if ( ch < 0x20 || ch > 0x7e ) - { - final String ss = "0000" + Integer.toString( ch, 16 ); - retval.append( "\\u" ).append( ss, ss.length() - 4, ss.length() ); - } - else - { - retval.append( ch ); + if (ch < 0x20 || ch > 0x7e) { + final String ss = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append(ss, ss.length() - 4, ss.length()); + } else { + retval.append(ch); } } } - } diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java index a5f06c14..1e574485 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java +++ b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java @@ -3,8 +3,8 @@ package org.codehaus.plexus.util.xml.pull; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.io.Reader; /** @@ -60,7 +60,7 @@ * and it was not declared in XMLDecl * * A minimal example for using this API may look as follows: - * + * *
      * import java.io.IOException;
      * import java.io.StringReader;
    @@ -100,14 +100,14 @@
      * 
    *

    * The above example will generate the following output: - * + * *

      * Start document
      * Start tag foo
      * Text Hello World!
      * End tag foo
      * 
    - * + * * For more details on API usage, please refer to the quick Introduction available at * http://www.xmlpull.org * @@ -128,9 +128,7 @@ * @author Stefan Haustein * @author Aleksander Slominski */ - -public interface XmlPullParser -{ +public interface XmlPullParser { /** This constant represents the default namespace (empty string "") */ String NO_NAMESPACE = ""; @@ -252,7 +250,7 @@ public interface XmlPullParser * An XML processing instruction declaration was just read. This event type is available only via * nextToken(). getText() will return text that is inside the processing instruction. * Calls to next() will skip processing instructions automatically. - * + * * @see #nextToken * @see #getText */ @@ -284,8 +282,19 @@ public interface XmlPullParser * only. Relying on the contents of the array may be dangerous since malicious applications may alter the array, * although it is final, due to limitations of the Java language. */ - String[] TYPES = { "START_DOCUMENT", "END_DOCUMENT", "START_TAG", "END_TAG", "TEXT", "CDSECT", "ENTITY_REF", - "IGNORABLE_WHITESPACE", "PROCESSING_INSTRUCTION", "COMMENT", "DOCDECL" }; + String[] TYPES = { + "START_DOCUMENT", + "END_DOCUMENT", + "START_TAG", + "END_TAG", + "TEXT", + "CDSECT", + "ENTITY_REF", + "IGNORABLE_WHITESPACE", + "PROCESSING_INSTRUCTION", + "COMMENT", + "DOCDECL" + }; // ---------------------------------------------------------------------------- // namespace related features @@ -348,8 +357,7 @@ public interface XmlPullParser * @exception XmlPullParserException If the feature is not supported or can not be set * @exception IllegalArgumentException If string with the feature name is null */ - void setFeature( String name, boolean state ) - throws XmlPullParserException; + void setFeature(String name, boolean state) throws XmlPullParserException; /** * Returns the current value of the given feature. @@ -360,7 +368,7 @@ void setFeature( String name, boolean state ) * @return The value of the feature. * @exception IllegalArgumentException if string the feature name is null */ - boolean getFeature( String name ); + boolean getFeature(String name); /** * Set the value of a property. The property name is any fully-qualified URI. @@ -370,8 +378,7 @@ void setFeature( String name, boolean state ) * @exception IllegalArgumentException If string with the property name is null * @throws XmlPullParserException parsing issue */ - void setProperty( String name, Object value ) - throws XmlPullParserException; + void setProperty(String name, Object value) throws XmlPullParserException; /** * Look up the value of a property. The property name is any fully-qualified URI. @@ -381,7 +388,7 @@ void setProperty( String name, Object value ) * @param name The name of property to be retrieved. * @return The value of named property. */ - Object getProperty( String name ); + Object getProperty(String name); /** * Set the input source for parser to the given reader and resets the parser. The event type is set to the initial @@ -390,8 +397,7 @@ void setProperty( String name, Object value ) * @param in the Reader * @throws XmlPullParserException parsing issue */ - void setInput( Reader in ) - throws XmlPullParserException; + void setInput(Reader in) throws XmlPullParserException; /** * Sets the input stream the parser is going to process. This call resets the parser state and sets the event type @@ -407,8 +413,7 @@ void setInput( Reader in ) * @param inputEncoding if not null it MUST be used as encoding for inputStream * @throws XmlPullParserException parsing issue */ - void setInput( InputStream inputStream, String inputEncoding ) - throws XmlPullParserException; + void setInput(InputStream inputStream, String inputEncoding) throws XmlPullParserException; /** * @return the input encoding if known, null otherwise. If setInput(InputStream, inputEncoding) was called with an @@ -448,8 +453,7 @@ void setInput( InputStream inputStream, String inputEncoding ) * @see #FEATURE_VALIDATION * @throws XmlPullParserException parsing issue */ - void defineEntityReplacementText( String entityName, String replacementText ) - throws XmlPullParserException; + void defineEntityReplacementText(String entityName, String replacementText) throws XmlPullParserException; /** * @return the numbers of elements in the namespace stack for the given depth. If namespaces are not enabled, 0 is @@ -459,7 +463,7 @@ void defineEntityReplacementText( String entityName, String replacementText ) * retrieve position of namespace prefixes and URIs that were declared on corresponding START_TAG. *

    * NOTE: to retrieve lsit of namespaces declared in current element: - * + * *

          *       XmlPullParser pp = ...
          *       int nsStart = pp.getNamespaceCount(pp.getDepth()-1);
    @@ -478,8 +482,7 @@ void defineEntityReplacementText( String entityName, String replacementText )
          * @param depth depth
          * @throws XmlPullParserException parsing issue
          */
    -    int getNamespaceCount( int depth )
    -        throws XmlPullParserException;
    +    int getNamespaceCount(int depth) throws XmlPullParserException;
     
         /**
          * @return Returns the namespace prefix for the given position in the namespace stack. Default namespace declaration
    @@ -491,8 +494,7 @@ int getNamespaceCount( int depth )
          * @param pos namespace stack position
          * @throws XmlPullParserException parsing issue
          */
    -    String getNamespacePrefix( int pos )
    -        throws XmlPullParserException;
    +    String getNamespacePrefix(int pos) throws XmlPullParserException;
     
         /**
          * @return Returns the namespace URI for the given position in the namespace stack If the position is out of range, an
    @@ -503,8 +505,7 @@ String getNamespacePrefix( int pos )
          * @throws XmlPullParserException parsing issue
          * @param pos namespace stack position
          */
    -    String getNamespaceUri( int pos )
    -        throws XmlPullParserException;
    +    String getNamespaceUri(int pos) throws XmlPullParserException;
     
         /**
          * @return the URI corresponding to the given prefix, depending on current state of the parser.
    @@ -534,7 +535,7 @@ String getNamespaceUri( int pos )
          * @see #getNamespacePrefix
          * @see #getNamespaceUri
          */
    -    String getNamespace( String prefix );
    +    String getNamespace(String prefix);
     
         // --------------------------------------------------------------------------
         // miscellaneous reporting methods
    @@ -591,8 +592,7 @@ String getNamespaceUri( int pos )
          * exposed via nextToken only.
          * @throws XmlPullParserException parsing issue
          */
    -    boolean isWhitespace()
    -        throws XmlPullParserException;
    +    boolean isWhitespace() throws XmlPullParserException;
     
         /**
          * @return  the text content of the current event as String. The value returned depends on current event type, for
    @@ -626,7 +626,7 @@ boolean isWhitespace()
          * @return char buffer that contains the text of the current event (null if the current event has no text
          *         associated).
          */
    -    char[] getTextCharacters( int[] holderForStartAndLength );
    +    char[] getTextCharacters(int[] holderForStartAndLength);
     
         // --------------------------------------------------------------------------
         // START_TAG / END_TAG shared methods
    @@ -660,8 +660,7 @@ boolean isWhitespace()
          * NOTE: if the parser is not on START_TAG, an exception will be thrown.
          * @throws XmlPullParserException parsing issue
          */
    -    boolean isEmptyElementTag()
    -        throws XmlPullParserException;
    +    boolean isEmptyElementTag() throws XmlPullParserException;
     
         // --------------------------------------------------------------------------
         // START_TAG Attributes retrieval methods
    @@ -693,7 +692,7 @@ boolean isEmptyElementTag()
          * @return attribute namespace, empty string ("") is returned if namespaces processing is not enabled or namespaces
          *         processing is enabled but attribute has no namespace (it has no prefix).
          */
    -    String getAttributeNamespace( int index );
    +    String getAttributeNamespace(int index);
     
         /**
          * Returns the local name of the specified attribute if namespaces are enabled or just attribute name if namespaces
    @@ -703,7 +702,7 @@ boolean isEmptyElementTag()
          * @param index zero based index of attribute
          * @return attribute name (null is never returned)
          */
    -    String getAttributeName( int index );
    +    String getAttributeName(int index);
     
         /**
          * Returns the prefix of the specified attribute Returns null if the element has no prefix. If namespaces are
    @@ -713,7 +712,7 @@ boolean isEmptyElementTag()
          * @param index zero based index of attribute
          * @return attribute prefix or null if namespaces processing is not enabled.
          */
    -    String getAttributePrefix( int index );
    +    String getAttributePrefix(int index);
     
         /**
          * Returns the type of the specified attribute If parser is non-validating it MUST return CDATA.
    @@ -721,7 +720,7 @@ boolean isEmptyElementTag()
          * @param index zero based index of attribute
          * @return attribute type (null is never returned)
          */
    -    String getAttributeType( int index );
    +    String getAttributeType(int index);
     
         /**
          * Returns if the specified attribute was not in input was declared in XML. If parser is non-validating it MUST
    @@ -730,7 +729,7 @@ boolean isEmptyElementTag()
          * @param index zero based index of attribute
          * @return false if attribute was in input
          */
    -    boolean isAttributeDefault( int index );
    +    boolean isAttributeDefault(int index);
     
         /**
          * Returns the given attributes value. Throws an IndexOutOfBoundsException if the index is out of range or current
    @@ -744,7 +743,7 @@ boolean isEmptyElementTag()
          * @param index zero based index of attribute
          * @return value of attribute (null is never returned)
          */
    -    String getAttributeValue( int index );
    +    String getAttributeValue(int index);
     
         /**
          * Returns the attributes value identified by namespace URI and namespace localName. If namespaces are disabled
    @@ -759,7 +758,7 @@ boolean isEmptyElementTag()
          * @param name If namespaces enabled local name of attribute otherwise just attribute name
          * @return value of attribute or null if attribute with given name does not exist
          */
    -    String getAttributeValue( String namespace, String name );
    +    String getAttributeValue(String namespace, String name);
     
         // --------------------------------------------------------------------------
         // actual parsing methods
    @@ -771,8 +770,7 @@ boolean isEmptyElementTag()
          * @see #nextToken()
          * @throws XmlPullParserException parsing issue
          */
    -    int getEventType()
    -        throws XmlPullParserException;
    +    int getEventType() throws XmlPullParserException;
     
         /**
          * @return Get next parsing event - element content wil be coalesced and only one TEXT event must be returned for whole
    @@ -791,8 +789,7 @@ int getEventType()
          * @throws XmlPullParserException parsing issue
          * @throws IOException io issue
          */
    -    int next()
    -        throws XmlPullParserException, IOException;
    +    int next() throws XmlPullParserException, IOException;
     
         /**
          * This method works similarly to next() but will expose additional event types (COMMENT, CDSECT, DOCDECL,
    @@ -846,19 +843,19 @@ int next()
          * 
    DOCDECL *
    if FEATURE_XML_ROUNDTRIP is true or PROCESS_DOCDECL is false then return what is inside of DOCDECL for * example it returns: - * + * *
          * " titlepage SYSTEM "http://www.foo.bar/dtds/typo.dtd"
          * [<!ENTITY % active.links "INCLUDE">]"
          * 
    *

    * for input document that contained: - * + * *

          * <!DOCTYPE titlepage SYSTEM "http://www.foo.bar/dtds/typo.dtd"
          * [<!ENTITY % active.links "INCLUDE">]>
          * 
    - * + * * otherwise if FEATURE_XML_ROUNDTRIP is false and PROCESS_DOCDECL is true then what is returned is undefined (it * may be even null)
    * @@ -885,8 +882,7 @@ int next() * @see #ENTITY_REF * @see #IGNORABLE_WHITESPACE */ - int nextToken() - throws XmlPullParserException, IOException; + int nextToken() throws XmlPullParserException, IOException; // ----------------------------------------------------------------------------- // utility methods to mak XML parsing easier ... @@ -897,7 +893,7 @@ int nextToken() * parser position, the expected event and the current event that is not meeting the requirement. *

    * Essentially it does this - * + * *

          * if ( type != getEventType() || ( namespace != null && !namespace.equals( getNamespace() ) )
          *     || ( name != null && !name.equals( getName() ) ) )
    @@ -909,8 +905,7 @@ int nextToken()
          * @throws XmlPullParserException parsing issue
          * @throws IOException io issue
          */
    -    void require( int type, String namespace, String name )
    -        throws XmlPullParserException, IOException;
    +    void require(int type, String namespace, String name) throws XmlPullParserException, IOException;
     
         /**
          * If current event is START_TAG then if next element is TEXT then element content is returned or if next event is
    @@ -922,18 +917,18 @@ void require( int type, String namespace, String name )
          * 
      *
    1. <tag>foo</tag> *
    2. <tag></tag> (which is equivalent to <tag/> both input can be parsed with the same code: - * + * *
            *   p.nextTag()
            *   p.requireEvent(p.START_TAG, "", "tag");
            *   String content = p.nextText();
            *   p.requireEvent(p.END_TAG, "", "tag");
            * 
    - * + * * This function together with nextTag make it very easy to parse XML that has no mixed content. *

    * Essentially it does this - * + * *

          * if ( getEventType() != START_TAG )
          * {
    @@ -963,15 +958,14 @@ void require( int type, String namespace, String name )
          * @throws XmlPullParserException parsing issue
          * @throws IOException io issue
          */
    -    String nextText()
    -        throws XmlPullParserException, IOException;
    +    String nextText() throws XmlPullParserException, IOException;
     
         /**
          * Call next() and return event if it is START_TAG or END_TAG otherwise throw an exception. It will skip whitespace
          * TEXT before actual tag if any.
          * 

    * essentially it does this - * + * *

          * int eventType = next();
          * if ( eventType == TEXT && isWhitespace() )
    @@ -989,7 +983,5 @@ String nextText()
          * @throws
          * IOException io issue
          */
    -    int nextTag()
    -        throws XmlPullParserException, IOException;
    -
    +    int nextTag() throws XmlPullParserException, IOException;
     }
    diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java
    index ff23754f..198977c5 100644
    --- a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java
    +++ b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java
    @@ -8,9 +8,7 @@
      *
      * @author Aleksander Slominski
      */
    -public class XmlPullParserException
    -    extends Exception
    -{
    +public class XmlPullParserException extends Exception {
         /**
          * @deprecated use generic getCause() method
          */
    @@ -25,9 +23,8 @@ public class XmlPullParserException
          * public XmlPullParserException() { }
          */
     
    -    public XmlPullParserException( String s )
    -    {
    -        super( s );
    +    public XmlPullParserException(String s) {
    +        super(s);
         }
     
         /*
    @@ -35,14 +32,14 @@ public XmlPullParserException( String s )
          * XmlPullParserException(String s, int row, int column) { super(s); this.row = row; this.column = column; }
          */
     
    -    public XmlPullParserException( String msg, XmlPullParser parser, Throwable chain )
    -    {
    -        super( ( msg == null ? "" : msg + " " )
    -            + ( parser == null ? "" : "(position:" + parser.getPositionDescription() + ") " )
    -            + ( chain == null ? "" : "caused by: " + chain ), chain );
    +    public XmlPullParserException(String msg, XmlPullParser parser, Throwable chain) {
    +        super(
    +                (msg == null ? "" : msg + " ")
    +                        + (parser == null ? "" : "(position:" + parser.getPositionDescription() + ") ")
    +                        + (chain == null ? "" : "caused by: " + chain),
    +                chain);
     
    -        if ( parser != null )
    -        {
    +        if (parser != null) {
                 this.row = parser.getLineNumber();
                 this.column = parser.getColumnNumber();
             }
    @@ -54,19 +51,16 @@ public XmlPullParserException( String msg, XmlPullParser parser, Throwable chain
          * @return the cause
          */
         @Deprecated
    -    public Throwable getDetail()
    -    {
    +    public Throwable getDetail() {
             return getCause();
         }
     
         // public void setDetail(Throwable cause) { this.detail = cause; }
    -    public int getLineNumber()
    -    {
    +    public int getLineNumber() {
             return row;
         }
     
    -    public int getColumnNumber()
    -    {
    +    public int getColumnNumber() {
             return column;
         }
     
    @@ -77,20 +71,14 @@ public int getColumnNumber()
     
         // NOTE: code that prints this and detail is difficult in J2ME
         @Override
    -    public void printStackTrace()
    -    {
    -        if ( getCause() == null )
    -        {
    +    public void printStackTrace() {
    +        if (getCause() == null) {
                 super.printStackTrace();
    -        }
    -        else
    -        {
    -            synchronized ( System.err )
    -            {
    -                System.err.println( super.getMessage() + "; nested exception is:" );
    +        } else {
    +            synchronized (System.err) {
    +                System.err.println(super.getMessage() + "; nested exception is:");
                     getCause().printStackTrace();
                 }
             }
         }
    -
     }
    diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java
    index 46ef492f..6d5ec139 100644
    --- a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java
    +++ b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java
    @@ -28,9 +28,7 @@
      * be thrown and it is recommended to use an optional feature to signal that implementation is not supporting this kind
      * of output.
      */
    -
    -public interface XmlSerializer
    -{
    +public interface XmlSerializer {
     
         /**
          * Set feature identified by name (recommended to be URI for uniqueness). Some well known optional features are
    @@ -41,8 +39,7 @@ public interface XmlSerializer
          * @param state feature state
          * @exception IllegalStateException If the feature is not supported or can not be set
          */
    -    void setFeature( String name, boolean state )
    -        throws IllegalArgumentException, IllegalStateException;
    +    void setFeature(String name, boolean state) throws IllegalArgumentException, IllegalStateException;
     
         /**
          * Return the current value of the feature with given name.
    @@ -53,7 +50,7 @@ void setFeature( String name, boolean state )
          * @return The value of named feature.
          * @exception IllegalArgumentException if feature string is null
          */
    -    boolean getFeature( String name );
    +    boolean getFeature(String name);
     
         /**
          * Set the value of a property. (the property name is recommended to be URI for uniqueness). Some well known
    @@ -64,8 +61,7 @@ void setFeature( String name, boolean state )
          * @param value property value
          * @exception IllegalStateException if the property is not supported or can not be set
          */
    -    void setProperty( String name, Object value )
    -        throws IllegalArgumentException, IllegalStateException;
    +    void setProperty(String name, Object value) throws IllegalArgumentException, IllegalStateException;
     
         /**
          * Look up the value of a property. The property name is any fully-qualified URI. I
    @@ -75,7 +71,7 @@ void setProperty( String name, Object value )
          * @param name The name of property to be retrieved.
          * @return The value of named property.
          */
    -    Object getProperty( String name );
    +    Object getProperty(String name);
     
         /**
          * Set to use binary output stream with given encoding.
    @@ -85,8 +81,8 @@ void setProperty( String name, Object value )
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    void setOutput( OutputStream os, String encoding )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void setOutput(OutputStream os, String encoding)
    +            throws IOException, IllegalArgumentException, IllegalStateException;
     
         /**
          * @param writer Set the output to the given writer.
    @@ -96,8 +92,7 @@ void setOutput( OutputStream os, String encoding )
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    void setOutput( Writer writer )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void setOutput(Writer writer) throws IOException, IllegalArgumentException, IllegalStateException;
     
         /**
          * Write <?xml declaration with encoding (if encoding not null) and standalone flag (if standalone not null)
    @@ -108,8 +103,8 @@ void setOutput( Writer writer )
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    void startDocument( String encoding, Boolean standalone )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void startDocument(String encoding, Boolean standalone)
    +            throws IOException, IllegalArgumentException, IllegalStateException;
     
         /**
          * Finish writing. All unclosed start tags will be closed and output will be flushed. After calling this method no
    @@ -118,8 +113,7 @@ void startDocument( String encoding, Boolean standalone )
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    void endDocument()
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void endDocument() throws IOException, IllegalArgumentException, IllegalStateException;
     
         /**
          * Binds the given prefix to the given namespace. This call is valid for the next element including child elements.
    @@ -141,8 +135,7 @@ void endDocument()
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    void setPrefix( String prefix, String namespace )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void setPrefix(String prefix, String namespace) throws IOException, IllegalArgumentException, IllegalStateException;
     
         /**
          * @return namespace that corresponds to given prefix If there is no prefix bound to this namespace return null but
    @@ -157,8 +150,7 @@ void setPrefix( String prefix, String namespace )
          * @param generatePrefix to generate the missing prefix
          * @throws IllegalArgumentException if null
          */
    -    String getPrefix( String namespace, boolean generatePrefix )
    -        throws IllegalArgumentException;
    +    String getPrefix(String namespace, boolean generatePrefix) throws IllegalArgumentException;
     
         /**
          * @return the current depth of the element. Outside the root element, the depth is 0. The depth is incremented by 1
    @@ -210,8 +202,8 @@ String getPrefix( String namespace, boolean generatePrefix )
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    XmlSerializer startTag( String namespace, String name )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    XmlSerializer startTag(String namespace, String name)
    +            throws IOException, IllegalArgumentException, IllegalStateException;
     
         /**
          * Write an attribute. Calls to attribute() MUST follow a call to startTag() immediately. If there is no prefix
    @@ -225,8 +217,8 @@ XmlSerializer startTag( String namespace, String name )
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    XmlSerializer attribute( String namespace, String name, String value )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    XmlSerializer attribute(String namespace, String name, String value)
    +            throws IOException, IllegalArgumentException, IllegalStateException;
     
         /**
          * Write end tag. Repetition of namespace and name is just for avoiding errors.
    @@ -240,8 +232,8 @@ XmlSerializer attribute( String namespace, String name, String value )
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    XmlSerializer endTag( String namespace, String name )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    XmlSerializer endTag(String namespace, String name)
    +            throws IOException, IllegalArgumentException, IllegalStateException;
     
         // /**
         // * Writes a start tag with the given namespace and name.
    @@ -303,8 +295,7 @@ XmlSerializer endTag( String namespace, String name )
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    XmlSerializer text( String text )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    XmlSerializer text(String text) throws IOException, IllegalArgumentException, IllegalStateException;
     
         /**
          * Writes text, where special XML chars are escaped automatically
    @@ -316,26 +307,20 @@ XmlSerializer text( String text )
          * @throws IllegalArgumentException if null
          * @throws IllegalStateException illegal use
          */
    -    XmlSerializer text( char[] buf, int start, int len )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    XmlSerializer text(char[] buf, int start, int len)
    +            throws IOException, IllegalArgumentException, IllegalStateException;
     
    -    void cdsect( String text )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void cdsect(String text) throws IOException, IllegalArgumentException, IllegalStateException;
     
    -    void entityRef( String text )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void entityRef(String text) throws IOException, IllegalArgumentException, IllegalStateException;
     
    -    void processingInstruction( String text )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void processingInstruction(String text) throws IOException, IllegalArgumentException, IllegalStateException;
     
    -    void comment( String text )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void comment(String text) throws IOException, IllegalArgumentException, IllegalStateException;
     
    -    void docdecl( String text )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void docdecl(String text) throws IOException, IllegalArgumentException, IllegalStateException;
     
    -    void ignorableWhitespace( String text )
    -        throws IOException, IllegalArgumentException, IllegalStateException;
    +    void ignorableWhitespace(String text) throws IOException, IllegalArgumentException, IllegalStateException;
     
         /**
          * Write all pending output to the stream. If method startTag() or attribute() was called then start tag is closed
    @@ -345,7 +330,5 @@ void ignorableWhitespace( String text )
          * output call method text() with empty string (text("")).
          * @throws IOException io
          */
    -    void flush()
    -        throws IOException;
    -
    +    void flush() throws IOException;
     }
    diff --git a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java
    index bb004c73..9e23c420 100644
    --- a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java
    +++ b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java
    @@ -16,6 +16,8 @@
      * limitations under the License.
      */
     
    +import javax.swing.text.html.HTML.Tag;
    +
     import java.io.File;
     import java.io.IOException;
     import java.io.StringWriter;
    @@ -24,8 +26,6 @@
     import java.nio.file.Files;
     import java.util.NoSuchElementException;
     
    -import javax.swing.text.html.HTML.Tag;
    -
     import org.codehaus.plexus.util.StringUtils;
     import org.junit.jupiter.api.AfterEach;
     import org.junit.jupiter.api.BeforeEach;
    @@ -45,8 +45,7 @@
      * @version $Id: $Id
      * @since 3.4.0
      */
    -public class PrettyPrintXMLWriterTest
    -{
    +public class PrettyPrintXMLWriterTest {
         StringWriter w;
     
         PrettyPrintXMLWriter writer;
    @@ -55,8 +54,7 @@ public class PrettyPrintXMLWriterTest
          * 

    setUp.

    */ @BeforeEach - public void setUp() - { + public void setUp() { initWriter(); } @@ -64,109 +62,102 @@ public void setUp() *

    tearDown.

    */ @AfterEach - public void tearDown() - { + public void tearDown() { writer = null; w = null; } - private void initWriter() - { + private void initWriter() { w = new StringWriter(); - writer = new PrettyPrintXMLWriter( w ); + writer = new PrettyPrintXMLWriter(w); } /** *

    testDefaultPrettyPrintXMLWriter.

    */ @Test - public void testDefaultPrettyPrintXMLWriter() - { - writer.startElement( Tag.HTML.toString() ); + public void testDefaultPrettyPrintXMLWriter() { + writer.startElement(Tag.HTML.toString()); - writeXhtmlHead( writer ); + writeXhtmlHead(writer); - writeXhtmlBody( writer ); + writeXhtmlBody(writer); writer.endElement(); // Tag.HTML - assertEquals( expectedResult( PrettyPrintXMLWriter.LS ), w.toString() ); + assertEquals(expectedResult(PrettyPrintXMLWriter.LS), w.toString()); } /** *

    testPrettyPrintXMLWriterWithGivenLineSeparator.

    */ @Test - public void testPrettyPrintXMLWriterWithGivenLineSeparator() - { - writer.setLineSeparator( "\n" ); + public void testPrettyPrintXMLWriterWithGivenLineSeparator() { + writer.setLineSeparator("\n"); - writer.startElement( Tag.HTML.toString() ); + writer.startElement(Tag.HTML.toString()); - writeXhtmlHead( writer ); + writeXhtmlHead(writer); - writeXhtmlBody( writer ); + writeXhtmlBody(writer); writer.endElement(); // Tag.HTML - assertEquals( expectedResult( "\n" ), w.toString() ); + assertEquals(expectedResult("\n"), w.toString()); } /** *

    testPrettyPrintXMLWriterWithGivenLineIndenter.

    */ @Test - public void testPrettyPrintXMLWriterWithGivenLineIndenter() - { - writer.setLineIndenter( " " ); + public void testPrettyPrintXMLWriterWithGivenLineIndenter() { + writer.setLineIndenter(" "); - writer.startElement( Tag.HTML.toString() ); + writer.startElement(Tag.HTML.toString()); - writeXhtmlHead( writer ); + writeXhtmlHead(writer); - writeXhtmlBody( writer ); + writeXhtmlBody(writer); writer.endElement(); // Tag.HTML - assertEquals( expectedResult( " ", PrettyPrintXMLWriter.LS ), w.toString() ); + assertEquals(expectedResult(" ", PrettyPrintXMLWriter.LS), w.toString()); } /** *

    testEscapeXmlAttribute.

    */ @Test - public void testEscapeXmlAttribute() - { + public void testEscapeXmlAttribute() { // Windows - writer.startElement( Tag.DIV.toString() ); - writer.addAttribute( "class", "sect\r\nion" ); + writer.startElement(Tag.DIV.toString()); + writer.addAttribute("class", "sect\r\nion"); writer.endElement(); // Tag.DIV - assertEquals( "
    ", w.toString() ); + assertEquals("
    ", w.toString()); // Mac initWriter(); - writer.startElement( Tag.DIV.toString() ); - writer.addAttribute( "class", "sect\rion" ); + writer.startElement(Tag.DIV.toString()); + writer.addAttribute("class", "sect\rion"); writer.endElement(); // Tag.DIV - assertEquals( "
    ", w.toString() ); + assertEquals("
    ", w.toString()); // Unix initWriter(); - writer.startElement( Tag.DIV.toString() ); - writer.addAttribute( "class", "sect\nion" ); + writer.startElement(Tag.DIV.toString()); + writer.addAttribute("class", "sect\nion"); writer.endElement(); // Tag.DIV - assertEquals( "
    ", w.toString() ); + assertEquals("
    ", w.toString()); } /** *

    testendElementAlreadyClosed.

    */ @Test - public void testendElementAlreadyClosed() - { + public void testendElementAlreadyClosed() { assertThrows(NoSuchElementException.class, () -> { - writer.startElement( Tag.DIV.toString() ); - writer.addAttribute( "class", "someattribute" ); + writer.startElement(Tag.DIV.toString()); + writer.addAttribute("class", "someattribute"); writer.endElement(); // Tag.DIV closed writer.endElement(); // Tag.DIV already closed, and there is no other outer tag! }); @@ -180,99 +171,93 @@ public void testendElementAlreadyClosed() * * @throws java.io.IOException if an I/O error occurs */ - @Disabled( "This test is only relevant on JDK 1.7, which is not supported anymore" ) + @Disabled("This test is only relevant on JDK 1.7, which is not supported anymore") @Test - public void testIssue51DetectJava7ConcatenationBug() - throws IOException - { - File dir = new File( "target/test-xml" ); - if ( !dir.exists() ) - { - assertTrue( dir.mkdir(), "cannot create directory test-xml" ); + public void testIssue51DetectJava7ConcatenationBug() throws IOException { + File dir = new File("target/test-xml"); + if (!dir.exists()) { + assertTrue(dir.mkdir(), "cannot create directory test-xml"); } - File xmlFile = new File( dir, "test-issue-51.xml" ); + File xmlFile = new File(dir, "test-issue-51.xml"); int iterations = 20000; - try ( Writer osw = Files.newBufferedWriter( xmlFile.toPath(), StandardCharsets.UTF_8 ) ) - { - writer = new PrettyPrintXMLWriter( osw ); - for ( int i = 0; i < iterations; ++i ) - { - writer.startElement( Tag.DIV.toString() + i ); - writer.addAttribute( "class", "someattribute" ); + try (Writer osw = Files.newBufferedWriter(xmlFile.toPath(), StandardCharsets.UTF_8)) { + writer = new PrettyPrintXMLWriter(osw); + for (int i = 0; i < iterations; ++i) { + writer.startElement(Tag.DIV.toString() + i); + writer.addAttribute("class", "someattribute"); } - for ( int i = 0; i < iterations; ++i ) - { + for (int i = 0; i < iterations; ++i) { writer.endElement(); // closes Tag.DIV + i } - } - catch ( NoSuchElementException e ) - { - fail( "Should not throw a NoSuchElementException" ); + } catch (NoSuchElementException e) { + fail("Should not throw a NoSuchElementException"); } } - private void writeXhtmlHead( XMLWriter writer ) - { - writer.startElement( Tag.HEAD.toString() ); - writer.startElement( Tag.TITLE.toString() ); - writer.writeText( "title" ); + private void writeXhtmlHead(XMLWriter writer) { + writer.startElement(Tag.HEAD.toString()); + writer.startElement(Tag.TITLE.toString()); + writer.writeText("title"); writer.endElement(); // Tag.TITLE - writer.startElement( Tag.META.toString() ); - writer.addAttribute( "name", "author" ); - writer.addAttribute( "content", "Author" ); + writer.startElement(Tag.META.toString()); + writer.addAttribute("name", "author"); + writer.addAttribute("content", "Author"); writer.endElement(); // Tag.META - writer.startElement( Tag.META.toString() ); - writer.addAttribute( "name", "date" ); - writer.addAttribute( "content", "Date" ); + writer.startElement(Tag.META.toString()); + writer.addAttribute("name", "date"); + writer.addAttribute("content", "Date"); writer.endElement(); // Tag.META writer.endElement(); // Tag.HEAD } - private void writeXhtmlBody( XMLWriter writer ) - { - writer.startElement( Tag.BODY.toString() ); - writer.startElement( Tag.P.toString() ); - writer.writeText( "Paragraph 1, line 1. Paragraph 1, line 2." ); + private void writeXhtmlBody(XMLWriter writer) { + writer.startElement(Tag.BODY.toString()); + writer.startElement(Tag.P.toString()); + writer.writeText("Paragraph 1, line 1. Paragraph 1, line 2."); writer.endElement(); // Tag.P - writer.startElement( Tag.DIV.toString() ); - writer.addAttribute( "class", "section" ); - writer.startElement( Tag.H2.toString() ); - writer.writeText( "Section title" ); + writer.startElement(Tag.DIV.toString()); + writer.addAttribute("class", "section"); + writer.startElement(Tag.H2.toString()); + writer.writeText("Section title"); writer.endElement(); // Tag.H2 writer.endElement(); // Tag.DIV writer.endElement(); // Tag.BODY } - private String expectedResult( String lineSeparator ) - { - return expectedResult( " ", lineSeparator ); + private String expectedResult(String lineSeparator) { + return expectedResult(" ", lineSeparator); } - private String expectedResult( String lineIndenter, String lineSeparator ) - { + private String expectedResult(String lineIndenter, String lineSeparator) { StringBuilder expected = new StringBuilder(); - expected.append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, - 2 ) ).append( "title" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, - 2 ) ).append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, - 2 ) ).append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, - 2 ) ).append( "

    Paragraph 1, line 1. Paragraph 1, line 2.

    " ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, - 2 ) ).append( "
    " ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, - 3 ) ).append( "

    Section title

    " ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 2 ) ).append( "
    " ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator ); - expected.append( "" ); + expected.append("").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("title") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("

    Paragraph 1, line 1. Paragraph 1, line 2.

    ") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("
    ") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 3)) + .append("

    Section title

    ") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)).append("
    ").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); + expected.append(""); return expected.toString(); } diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java index 3fe0b515..4ffe7a9c 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java @@ -22,13 +22,11 @@ import java.io.SequenceInputStream; import org.codehaus.plexus.util.IOUtil; - import org.junit.jupiter.api.Test; import org.opentest4j.AssertionFailedError; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.fail; /** *

    XmlStreamReaderTest class.

    @@ -37,8 +35,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class XmlStreamReaderTest -{ +public class XmlStreamReaderTest { /** french */ private static final String TEXT_LATIN1 = "eacute: \u00E9"; @@ -53,76 +50,63 @@ public class XmlStreamReaderTest /** Unicode: support everything */ private static final String TEXT_UNICODE = - TEXT_LATIN1 + ", " + TEXT_LATIN7 + ", " + TEXT_LATIN15 + ", " + TEXT_EUC_JP; + TEXT_LATIN1 + ", " + TEXT_LATIN7 + ", " + TEXT_LATIN15 + ", " + TEXT_EUC_JP; /** see http://unicode.org/faq/utf_bom.html#BOM */ - private static final byte[] BOM_UTF8 = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF }; + private static final byte[] BOM_UTF8 = {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF}; - private static final byte[] BOM_UTF16BE = { (byte) 0xFE, (byte) 0xFF }; + private static final byte[] BOM_UTF16BE = {(byte) 0xFE, (byte) 0xFF}; - private static final byte[] BOM_UTF16LE = { (byte) 0xFF, (byte) 0xFE }; + private static final byte[] BOM_UTF16LE = {(byte) 0xFF, (byte) 0xFE}; - private static final byte[] BOM_UTF32BE = { (byte) 0x00, (byte) 0x00, (byte) 0xFF, (byte) 0xFE }; + private static final byte[] BOM_UTF32BE = {(byte) 0x00, (byte) 0x00, (byte) 0xFF, (byte) 0xFE}; - private static final byte[] BOM_UTF32LE = { (byte) 0xFF, (byte) 0xFE, (byte) 0x00, (byte) 0x00 }; + private static final byte[] BOM_UTF32LE = {(byte) 0xFF, (byte) 0xFE, (byte) 0x00, (byte) 0x00}; - private static String createXmlContent( String text, String encoding ) - { + private static String createXmlContent(String text, String encoding) { String xmlDecl = ""; - if ( encoding != null ) - { + if (encoding != null) { xmlDecl = ""; } String xml = xmlDecl + "\n" + text + ""; return xml; } - private static void checkXmlContent( String xml, String encoding ) - throws IOException - { - checkXmlContent( xml, encoding, null ); + private static void checkXmlContent(String xml, String encoding) throws IOException { + checkXmlContent(xml, encoding, null); } - private static void checkXmlContent( String xml, String encoding, byte... bom ) - throws IOException - { - byte[] xmlContent = xml.getBytes( encoding ); - InputStream in = new ByteArrayInputStream( xmlContent ); + private static void checkXmlContent(String xml, String encoding, byte... bom) throws IOException { + byte[] xmlContent = xml.getBytes(encoding); + InputStream in = new ByteArrayInputStream(xmlContent); - if ( bom != null ) - { - in = new SequenceInputStream( new ByteArrayInputStream( bom ), in ); + if (bom != null) { + in = new SequenceInputStream(new ByteArrayInputStream(bom), in); } - XmlStreamReader reader = new XmlStreamReader( in ); - assertEquals( encoding, reader.getEncoding() ); - String result = IOUtil.toString( reader ); - assertEquals( xml, result ); + XmlStreamReader reader = new XmlStreamReader(in); + assertEquals(encoding, reader.getEncoding()); + String result = IOUtil.toString(reader); + assertEquals(xml, result); } - private static void checkXmlStreamReader( String text, String encoding, String effectiveEncoding ) - throws IOException - { - checkXmlStreamReader( text, encoding, effectiveEncoding, null ); + private static void checkXmlStreamReader(String text, String encoding, String effectiveEncoding) + throws IOException { + checkXmlStreamReader(text, encoding, effectiveEncoding, null); } - private static void checkXmlStreamReader( String text, String encoding ) - throws IOException - { - checkXmlStreamReader( text, encoding, encoding, null ); + private static void checkXmlStreamReader(String text, String encoding) throws IOException { + checkXmlStreamReader(text, encoding, encoding, null); } - private static void checkXmlStreamReader( String text, String encoding, byte... bom ) - throws IOException - { - checkXmlStreamReader( text, encoding, encoding, bom ); + private static void checkXmlStreamReader(String text, String encoding, byte... bom) throws IOException { + checkXmlStreamReader(text, encoding, encoding, bom); } - private static void checkXmlStreamReader( String text, String encoding, String effectiveEncoding, byte... bom ) - throws IOException - { - String xml = createXmlContent( text, encoding ); - checkXmlContent( xml, effectiveEncoding, bom ); + private static void checkXmlStreamReader(String text, String encoding, String effectiveEncoding, byte... bom) + throws IOException { + String xml = createXmlContent(text, encoding); + checkXmlContent(xml, effectiveEncoding, bom); } /** @@ -131,12 +115,10 @@ private static void checkXmlStreamReader( String text, String encoding, String e * @throws java.io.IOException if any. */ @Test - public void testNoXmlHeader() - throws IOException - { + public void testNoXmlHeader() throws IOException { String xml = "text with no XML header"; - checkXmlContent( xml, "UTF-8" ); - checkXmlContent( xml, "UTF-8", BOM_UTF8 ); + checkXmlContent(xml, "UTF-8"); + checkXmlContent(xml, "UTF-8", BOM_UTF8); } /** @@ -145,11 +127,9 @@ public void testNoXmlHeader() * @throws java.io.IOException if any. */ @Test - public void testDefaultEncoding() - throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, null, "UTF-8" ); - checkXmlStreamReader( TEXT_UNICODE, null, "UTF-8", BOM_UTF8 ); + public void testDefaultEncoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8"); + checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8", BOM_UTF8); } /** @@ -158,11 +138,9 @@ public void testDefaultEncoding() * @throws java.io.IOException if any. */ @Test - public void testUTF8Encoding() - throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, "UTF-8" ); - checkXmlStreamReader( TEXT_UNICODE, "UTF-8", BOM_UTF8 ); + public void testUTF8Encoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, "UTF-8"); + checkXmlStreamReader(TEXT_UNICODE, "UTF-8", BOM_UTF8); } /** @@ -171,12 +149,10 @@ public void testUTF8Encoding() * @throws java.io.IOException if any. */ @Test - public void testUTF16Encoding() - throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16BE", null ); - checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE ); - checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16BE", BOM_UTF16BE ); + public void testUTF16Encoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", null); + checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE); + checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", BOM_UTF16BE); } /** @@ -185,10 +161,8 @@ public void testUTF16Encoding() * @throws java.io.IOException if any. */ @Test - public void testUTF16BEEncoding() - throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, "UTF-16BE" ); + public void testUTF16BEEncoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, "UTF-16BE"); } /** @@ -197,10 +171,8 @@ public void testUTF16BEEncoding() * @throws java.io.IOException if any. */ @Test - public void testUTF16LEEncoding() - throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, "UTF-16LE" ); + public void testUTF16LEEncoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, "UTF-16LE"); } /** @@ -209,10 +181,8 @@ public void testUTF16LEEncoding() * @throws java.io.IOException if any. */ @Test - public void testLatin1Encoding() - throws IOException - { - checkXmlStreamReader( TEXT_LATIN1, "ISO-8859-1" ); + public void testLatin1Encoding() throws IOException { + checkXmlStreamReader(TEXT_LATIN1, "ISO-8859-1"); } /** @@ -221,10 +191,8 @@ public void testLatin1Encoding() * @throws java.io.IOException if any. */ @Test - public void testLatin7Encoding() - throws IOException - { - checkXmlStreamReader( TEXT_LATIN7, "ISO-8859-7" ); + public void testLatin7Encoding() throws IOException { + checkXmlStreamReader(TEXT_LATIN7, "ISO-8859-7"); } /** @@ -233,10 +201,8 @@ public void testLatin7Encoding() * @throws java.io.IOException if any. */ @Test - public void testLatin15Encoding() - throws IOException - { - checkXmlStreamReader( TEXT_LATIN15, "ISO-8859-15" ); + public void testLatin15Encoding() throws IOException { + checkXmlStreamReader(TEXT_LATIN15, "ISO-8859-15"); } /** @@ -245,10 +211,8 @@ public void testLatin15Encoding() * @throws java.io.IOException if any. */ @Test - public void testEUC_JPEncoding() - throws IOException - { - checkXmlStreamReader( TEXT_EUC_JP, "EUC-JP" ); + public void testEUC_JPEncoding() throws IOException { + checkXmlStreamReader(TEXT_EUC_JP, "EUC-JP"); } /** @@ -257,10 +221,8 @@ public void testEUC_JPEncoding() * @throws java.io.IOException if any. */ @Test - public void testEBCDICEncoding() - throws IOException - { - checkXmlStreamReader( "simple text in EBCDIC", "CP1047" ); + public void testEBCDICEncoding() throws IOException { + checkXmlStreamReader("simple text in EBCDIC", "CP1047"); } /** @@ -269,14 +231,12 @@ public void testEBCDICEncoding() * @throws java.io.IOException if any. */ @Test - public void testInappropriateEncoding() - throws IOException - { + public void testInappropriateEncoding() throws IOException { // expected failure, since the encoding does not contain some characters - assertThrows(AssertionFailedError.class, () -> - checkXmlStreamReader( TEXT_UNICODE, "ISO-8859-2" ), - "Check should have failed, since some characters are not available in the specified encoding" - ); + assertThrows( + AssertionFailedError.class, + () -> checkXmlStreamReader(TEXT_UNICODE, "ISO-8859-2"), + "Check should have failed, since some characters are not available in the specified encoding"); } /** @@ -285,25 +245,23 @@ public void testInappropriateEncoding() * @throws java.io.IOException if any. */ @Test - public void testEncodingAttribute() - throws IOException - { + public void testEncodingAttribute() throws IOException { String xml = ""; - checkXmlContent( xml, "US-ASCII" ); + checkXmlContent(xml, "US-ASCII"); xml = ""; - checkXmlContent( xml, "US-ASCII" ); + checkXmlContent(xml, "US-ASCII"); xml = ""; - checkXmlContent( xml, "UTF-8" ); + checkXmlContent(xml, "UTF-8"); xml = "\n"; - checkXmlContent( xml, "US-ASCII" ); + checkXmlContent(xml, "US-ASCII"); xml = "\n"; - checkXmlContent( xml, "UTF-8" ); + checkXmlContent(xml, "UTF-8"); xml = ""; - checkXmlContent( xml, "UTF-8" ); + checkXmlContent(xml, "UTF-8"); } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java index b699f732..c2803b59 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java @@ -30,8 +30,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class XmlStreamWriterTest -{ +public class XmlStreamWriterTest { /** french */ private static final String TEXT_LATIN1 = "eacute: \u00E9"; @@ -46,37 +45,31 @@ public class XmlStreamWriterTest /** Unicode: support everything */ private static final String TEXT_UNICODE = - TEXT_LATIN1 + ", " + TEXT_LATIN7 + ", " + TEXT_LATIN15 + ", " + TEXT_EUC_JP; + TEXT_LATIN1 + ", " + TEXT_LATIN7 + ", " + TEXT_LATIN15 + ", " + TEXT_EUC_JP; - private static String createXmlContent( String text, String encoding ) - { + private static String createXmlContent(String text, String encoding) { String xmlDecl = ""; - if ( encoding != null ) - { + if (encoding != null) { xmlDecl = ""; } String xml = xmlDecl + "\n" + text + ""; return xml; } - private static void checkXmlContent( String xml, String encoding ) - throws IOException - { + private static void checkXmlContent(String xml, String encoding) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); - XmlStreamWriter writer = new XmlStreamWriter( out ); - writer.write( xml ); + XmlStreamWriter writer = new XmlStreamWriter(out); + writer.write(xml); writer.close(); byte[] xmlContent = out.toByteArray(); - String result = new String( xmlContent, encoding ); - assertEquals( xml, result ); + String result = new String(xmlContent, encoding); + assertEquals(xml, result); } - private static void checkXmlWriter( String text, String encoding ) - throws IOException - { - String xml = createXmlContent( text, encoding ); - String effectiveEncoding = ( encoding == null ) ? "UTF-8" : encoding; - checkXmlContent( xml, effectiveEncoding ); + private static void checkXmlWriter(String text, String encoding) throws IOException { + String xml = createXmlContent(text, encoding); + String effectiveEncoding = (encoding == null) ? "UTF-8" : encoding; + checkXmlContent(xml, effectiveEncoding); } /** @@ -85,11 +78,9 @@ private static void checkXmlWriter( String text, String encoding ) * @throws java.io.IOException if any. */ @Test - public void testNoXmlHeader() - throws IOException - { + public void testNoXmlHeader() throws IOException { String xml = "text with no XML header"; - checkXmlContent( xml, "UTF-8" ); + checkXmlContent(xml, "UTF-8"); } /** @@ -98,15 +89,13 @@ public void testNoXmlHeader() * @throws java.io.IOException if any. */ @Test - public void testEmpty() - throws IOException - { + public void testEmpty() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); - XmlStreamWriter writer = new XmlStreamWriter( out ); + XmlStreamWriter writer = new XmlStreamWriter(out); writer.flush(); - writer.write( "" ); + writer.write(""); writer.flush(); - writer.write( "." ); + writer.write("."); writer.flush(); writer.close(); } @@ -117,10 +106,8 @@ public void testEmpty() * @throws java.io.IOException if any. */ @Test - public void testDefaultEncoding() - throws IOException - { - checkXmlWriter( TEXT_UNICODE, null ); + public void testDefaultEncoding() throws IOException { + checkXmlWriter(TEXT_UNICODE, null); } /** @@ -129,10 +116,8 @@ public void testDefaultEncoding() * @throws java.io.IOException if any. */ @Test - public void testUTF8Encoding() - throws IOException - { - checkXmlWriter( TEXT_UNICODE, "UTF-8" ); + public void testUTF8Encoding() throws IOException { + checkXmlWriter(TEXT_UNICODE, "UTF-8"); } /** @@ -141,10 +126,8 @@ public void testUTF8Encoding() * @throws java.io.IOException if any. */ @Test - public void testUTF16Encoding() - throws IOException - { - checkXmlWriter( TEXT_UNICODE, "UTF-16" ); + public void testUTF16Encoding() throws IOException { + checkXmlWriter(TEXT_UNICODE, "UTF-16"); } /** @@ -153,10 +136,8 @@ public void testUTF16Encoding() * @throws java.io.IOException if any. */ @Test - public void testUTF16BEEncoding() - throws IOException - { - checkXmlWriter( TEXT_UNICODE, "UTF-16BE" ); + public void testUTF16BEEncoding() throws IOException { + checkXmlWriter(TEXT_UNICODE, "UTF-16BE"); } /** @@ -165,10 +146,8 @@ public void testUTF16BEEncoding() * @throws java.io.IOException if any. */ @Test - public void testUTF16LEEncoding() - throws IOException - { - checkXmlWriter( TEXT_UNICODE, "UTF-16LE" ); + public void testUTF16LEEncoding() throws IOException { + checkXmlWriter(TEXT_UNICODE, "UTF-16LE"); } /** @@ -177,10 +156,8 @@ public void testUTF16LEEncoding() * @throws java.io.IOException if any. */ @Test - public void testLatin1Encoding() - throws IOException - { - checkXmlWriter( TEXT_LATIN1, "ISO-8859-1" ); + public void testLatin1Encoding() throws IOException { + checkXmlWriter(TEXT_LATIN1, "ISO-8859-1"); } /** @@ -189,10 +166,8 @@ public void testLatin1Encoding() * @throws java.io.IOException if any. */ @Test - public void testLatin7Encoding() - throws IOException - { - checkXmlWriter( TEXT_LATIN7, "ISO-8859-7" ); + public void testLatin7Encoding() throws IOException { + checkXmlWriter(TEXT_LATIN7, "ISO-8859-7"); } /** @@ -201,10 +176,8 @@ public void testLatin7Encoding() * @throws java.io.IOException if any. */ @Test - public void testLatin15Encoding() - throws IOException - { - checkXmlWriter( TEXT_LATIN15, "ISO-8859-15" ); + public void testLatin15Encoding() throws IOException { + checkXmlWriter(TEXT_LATIN15, "ISO-8859-15"); } /** @@ -213,10 +186,8 @@ public void testLatin15Encoding() * @throws java.io.IOException if any. */ @Test - public void testEUC_JPEncoding() - throws IOException - { - checkXmlWriter( TEXT_EUC_JP, "EUC-JP" ); + public void testEUC_JPEncoding() throws IOException { + checkXmlWriter(TEXT_EUC_JP, "EUC-JP"); } /** @@ -225,9 +196,7 @@ public void testEUC_JPEncoding() * @throws java.io.IOException if any. */ @Test - public void testEBCDICEncoding() - throws IOException - { - checkXmlWriter( "simple text in EBCDIC", "CP1047" ); + public void testEBCDICEncoding() throws IOException { + checkXmlWriter("simple text in EBCDIC", "CP1047"); } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java index 3b54f16f..eb6db5eb 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java @@ -38,8 +38,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class XmlUtilTest -{ +public class XmlUtilTest { private String basedir; /** @@ -47,23 +46,18 @@ public class XmlUtilTest * * @return a {@link java.lang.String} object. */ - public final String getBasedir() - { - if ( null == basedir ) - { - basedir = System.getProperty( "basedir", new File( "" ).getAbsolutePath() ); + public final String getBasedir() { + if (null == basedir) { + basedir = System.getProperty("basedir", new File("").getAbsolutePath()); } return basedir; } - private File getTestOutputFile( String relPath ) - throws IOException - { - final File file = new File( getBasedir(), relPath ); + private File getTestOutputFile(String relPath) throws IOException { + final File file = new File(getBasedir(), relPath); final File parentFile = file.getParentFile(); - if ( !parentFile.isDirectory() && !parentFile.mkdirs() ) - { - throw new IOException( "Could not create test directory " + parentFile ); + if (!parentFile.isDirectory() && !parentFile.mkdirs()) { + throw new IOException("Could not create test directory " + parentFile); } return file; } @@ -74,19 +68,18 @@ private File getTestOutputFile( String relPath ) * @throws java.lang.Exception if any. */ @Test - public void testPrettyFormatInputStreamOutputStream() - throws Exception - { - File testDocument = new File( getBasedir(), "src/test/resources/testDocument.xhtml" ); - assertTrue( testDocument.exists() ); - - try ( InputStream is = Files.newInputStream( testDocument.toPath() ); - OutputStream os = Files.newOutputStream( getTestOutputFile( "target/test/prettyFormatTestDocumentOutputStream.xml" ).toPath() ) ) - { - assertNotNull( is ); - assertNotNull( os ); - - XmlUtil.prettyFormat( is, os ); + public void testPrettyFormatInputStreamOutputStream() throws Exception { + File testDocument = new File(getBasedir(), "src/test/resources/testDocument.xhtml"); + assertTrue(testDocument.exists()); + + try (InputStream is = Files.newInputStream(testDocument.toPath()); + OutputStream os = + Files.newOutputStream(getTestOutputFile("target/test/prettyFormatTestDocumentOutputStream.xml") + .toPath())) { + assertNotNull(is); + assertNotNull(os); + + XmlUtil.prettyFormat(is, os); } } @@ -96,19 +89,17 @@ public void testPrettyFormatInputStreamOutputStream() * @throws java.lang.Exception if any. */ @Test - public void testPrettyFormatReaderWriter() - throws Exception - { - File testDocument = new File( getBasedir(), "src/test/resources/testDocument.xhtml" ); - assertTrue( testDocument.exists() ); - - try ( Reader reader = new XmlStreamReader( testDocument ); - Writer writer = new XmlStreamWriter( getTestOutputFile( "target/test/prettyFormatTestDocumentWriter.xml" ) ) ) - { - assertNotNull( reader ); - assertNotNull( writer ); - - XmlUtil.prettyFormat( reader, writer ); + public void testPrettyFormatReaderWriter() throws Exception { + File testDocument = new File(getBasedir(), "src/test/resources/testDocument.xhtml"); + assertTrue(testDocument.exists()); + + try (Reader reader = new XmlStreamReader(testDocument); + Writer writer = + new XmlStreamWriter(getTestOutputFile("target/test/prettyFormatTestDocumentWriter.xml"))) { + assertNotNull(reader); + assertNotNull(writer); + + XmlUtil.prettyFormat(reader, writer); } } @@ -118,28 +109,24 @@ public void testPrettyFormatReaderWriter() * @throws java.lang.Exception if any. */ @Test - public void testPrettyFormatString() - throws Exception - { - File testDocument = new File( getBasedir(), "src/test/resources/testDocument.xhtml" ); - assertTrue( testDocument.exists() ); + public void testPrettyFormatString() throws Exception { + File testDocument = new File(getBasedir(), "src/test/resources/testDocument.xhtml"); + assertTrue(testDocument.exists()); String content; - try ( Reader reader = new XmlStreamReader( testDocument ) ) - { - content = IOUtil.toString( reader ); + try (Reader reader = new XmlStreamReader(testDocument)) { + content = IOUtil.toString(reader); } Writer writer = new StringWriter(); - try ( Reader reader = new XmlStreamReader( testDocument ) ) - { - XmlUtil.prettyFormat( reader, writer ); + try (Reader reader = new XmlStreamReader(testDocument)) { + XmlUtil.prettyFormat(reader, writer); } - assertNotNull( content ); + assertNotNull(content); - int countEOL = StringUtils.countMatches( content, XmlUtil.DEFAULT_LINE_SEPARATOR ); - assertTrue( countEOL < StringUtils.countMatches( writer.toString(), XmlUtil.DEFAULT_LINE_SEPARATOR ) ); + int countEOL = StringUtils.countMatches(content, XmlUtil.DEFAULT_LINE_SEPARATOR); + assertTrue(countEOL < StringUtils.countMatches(writer.toString(), XmlUtil.DEFAULT_LINE_SEPARATOR)); } /** @@ -148,19 +135,16 @@ public void testPrettyFormatString() * @throws java.lang.Exception if any. */ @Test - public void testPrettyFormatReaderWriter2() - throws Exception - { - File testDocument = new File( getBasedir(), "src/test/resources/test.xdoc.xhtml" ); - assertTrue( testDocument.exists() ); - - try ( Reader reader = new XmlStreamReader( testDocument ); - Writer writer = new XmlStreamWriter( getTestOutputFile( "target/test/prettyFormatTestXdocWriter.xml" ) ) ) - { - assertNotNull( reader ); - assertNotNull( writer ); - - XmlUtil.prettyFormat( reader, writer ); + public void testPrettyFormatReaderWriter2() throws Exception { + File testDocument = new File(getBasedir(), "src/test/resources/test.xdoc.xhtml"); + assertTrue(testDocument.exists()); + + try (Reader reader = new XmlStreamReader(testDocument); + Writer writer = new XmlStreamWriter(getTestOutputFile("target/test/prettyFormatTestXdocWriter.xml"))) { + assertNotNull(reader); + assertNotNull(writer); + + XmlUtil.prettyFormat(reader, writer); } } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java index eb8041f7..35ca0a25 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java @@ -34,8 +34,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class XmlWriterUtilTest -{ +public class XmlWriterUtilTest { private OutputStream output; private Writer writer; @@ -48,12 +47,10 @@ public class XmlWriterUtilTest * @throws java.lang.Exception if any. */ @BeforeEach - public void setUp() - throws Exception - { + public void setUp() throws Exception { output = new ByteArrayOutputStream(); - writer = new XmlStreamWriter( output ); - xmlWriter = new PrettyPrintXMLWriter( writer ); + writer = new XmlStreamWriter(output); + xmlWriter = new PrettyPrintXMLWriter(writer); } /** @@ -62,9 +59,7 @@ public void setUp() * @throws java.lang.Exception if any. */ @AfterEach - public void tearDown() - throws Exception - { + public void tearDown() throws Exception { xmlWriter = null; writer = null; output = null; @@ -77,12 +72,10 @@ public void tearDown() * @throws java.lang.Exception if any */ @Test - public void testWriteLineBreakXMLWriter() - throws Exception - { - XmlWriterUtil.writeLineBreak( xmlWriter ); + public void testWriteLineBreakXMLWriter() throws Exception { + XmlWriterUtil.writeLineBreak(xmlWriter); writer.close(); - assertTrue( StringUtils.countMatches( output.toString(), XmlWriterUtil.LS ) == 1 ); + assertTrue(StringUtils.countMatches(output.toString(), XmlWriterUtil.LS) == 1); } /** @@ -92,12 +85,10 @@ public void testWriteLineBreakXMLWriter() * @throws java.lang.Exception if any */ @Test - public void testWriteLineBreakXMLWriterInt() - throws Exception - { - XmlWriterUtil.writeLineBreak( xmlWriter, 10 ); + public void testWriteLineBreakXMLWriterInt() throws Exception { + XmlWriterUtil.writeLineBreak(xmlWriter, 10); writer.close(); - assertTrue( StringUtils.countMatches( output.toString(), XmlWriterUtil.LS ) == 10 ); + assertTrue(StringUtils.countMatches(output.toString(), XmlWriterUtil.LS) == 10); } /** @@ -107,15 +98,13 @@ public void testWriteLineBreakXMLWriterInt() * @throws java.lang.Exception if any */ @Test - public void testWriteLineBreakXMLWriterIntInt() - throws Exception - { - XmlWriterUtil.writeLineBreak( xmlWriter, 10, 2 ); + public void testWriteLineBreakXMLWriterIntInt() throws Exception { + XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2); writer.close(); - assertTrue( StringUtils.countMatches( output.toString(), XmlWriterUtil.LS ) == 10 ); - assertTrue( StringUtils.countMatches( output.toString(), - StringUtils.repeat( " ", - 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE ) ) == 1 ); + assertTrue(StringUtils.countMatches(output.toString(), XmlWriterUtil.LS) == 10); + assertTrue(StringUtils.countMatches( + output.toString(), StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE)) + == 1); } /** @@ -125,13 +114,11 @@ public void testWriteLineBreakXMLWriterIntInt() * @throws java.lang.Exception if any */ @Test - public void testWriteLineBreakXMLWriterIntIntInt() - throws Exception - { - XmlWriterUtil.writeLineBreak( xmlWriter, 10, 2, 4 ); + public void testWriteLineBreakXMLWriterIntIntInt() throws Exception { + XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2, 4); writer.close(); - assertTrue( StringUtils.countMatches( output.toString(), XmlWriterUtil.LS ) == 10 ); - assertTrue( StringUtils.countMatches( output.toString(), StringUtils.repeat( " ", 2 * 4 ) ) == 1 ); + assertTrue(StringUtils.countMatches(output.toString(), XmlWriterUtil.LS) == 10); + assertTrue(StringUtils.countMatches(output.toString(), StringUtils.repeat(" ", 2 * 4)) == 1); } /** @@ -141,15 +128,14 @@ public void testWriteLineBreakXMLWriterIntIntInt() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentLineBreakXMLWriter() - throws Exception - { - XmlWriterUtil.writeCommentLineBreak( xmlWriter ); + public void testWriteCommentLineBreakXMLWriter() throws Exception { + XmlWriterUtil.writeCommentLineBreak(xmlWriter); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() ); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()); } /** @@ -159,19 +145,17 @@ public void testWriteCommentLineBreakXMLWriter() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentLineBreakXMLWriterInt() - throws Exception - { - XmlWriterUtil.writeCommentLineBreak( xmlWriter, 20 ); + public void testWriteCommentLineBreakXMLWriterInt() throws Exception { + XmlWriterUtil.writeCommentLineBreak(xmlWriter, 20); writer.close(); - assertEquals( output.toString(), "" + XmlWriterUtil.LS ); + assertEquals(output.toString(), "" + XmlWriterUtil.LS); tearDown(); setUp(); - XmlWriterUtil.writeCommentLineBreak( xmlWriter, 10 ); + XmlWriterUtil.writeCommentLineBreak(xmlWriter, 10); writer.close(); - assertEquals( output.toString(), output.toString(), "" + XmlWriterUtil.LS ); + assertEquals(output.toString(), output.toString(), "" + XmlWriterUtil.LS); } /** @@ -181,38 +165,40 @@ public void testWriteCommentLineBreakXMLWriterInt() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentXMLWriterString() - throws Exception - { - XmlWriterUtil.writeComment( xmlWriter, "hello" ); + public void testWriteCommentXMLWriterString() throws Exception { + XmlWriterUtil.writeComment(xmlWriter, "hello"); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() ); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()); tearDown(); setUp(); - XmlWriterUtil.writeComment( xmlWriter, - "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" ); + XmlWriterUtil.writeComment( + xmlWriter, "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"); writer.close(); sb = new StringBuffer(); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() >= XmlWriterUtil.DEFAULT_COLUMN_LINE ); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() >= XmlWriterUtil.DEFAULT_COLUMN_LINE); tearDown(); setUp(); - XmlWriterUtil.writeComment( xmlWriter, "hello\nworld" ); + XmlWriterUtil.writeComment(xmlWriter, "hello\nworld"); writer.close(); sb = new StringBuffer(); - sb.append( "" ).append( XmlWriterUtil.LS ); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == 2 - * ( XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() ) ); + sb.append("") + .append(XmlWriterUtil.LS); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue( + output.toString().length() == 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length())); } /** @@ -222,33 +208,37 @@ public void testWriteCommentXMLWriterString() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentXMLWriterStringInt() - throws Exception - { - String indent = StringUtils.repeat( " ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE ); + public void testWriteCommentXMLWriterStringInt() throws Exception { + String indent = StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE); - XmlWriterUtil.writeComment( xmlWriter, "hello", 2 ); + XmlWriterUtil.writeComment(xmlWriter, "hello", 2); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( indent ); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() - + 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE ); + sb.append(indent); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() + == XmlWriterUtil.DEFAULT_COLUMN_LINE + - 1 + + XmlWriterUtil.LS.length() + + 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE); tearDown(); setUp(); - XmlWriterUtil.writeComment( xmlWriter, "hello\nworld", 2 ); + XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2); writer.close(); sb = new StringBuffer(); - sb.append( indent ); - sb.append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == 2 - * ( XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() ) + 2 * indent.length() ); + sb.append(indent); + sb.append("") + .append(XmlWriterUtil.LS); + sb.append(indent); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() + == 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()) + 2 * indent.length()); } /** @@ -258,33 +248,34 @@ public void testWriteCommentXMLWriterStringInt() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentXMLWriterStringIntInt() - throws Exception - { - String repeat = StringUtils.repeat( " ", 2 * 4 ); + public void testWriteCommentXMLWriterStringIntInt() throws Exception { + String repeat = StringUtils.repeat(" ", 2 * 4); - XmlWriterUtil.writeComment( xmlWriter, "hello", 2, 4 ); + XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( repeat ); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() - + 2 * 4 ); + sb.append(repeat); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() + == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() + 2 * 4); tearDown(); setUp(); - XmlWriterUtil.writeComment( xmlWriter, "hello\nworld", 2, 4 ); + XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2, 4); writer.close(); sb = new StringBuffer(); - sb.append( repeat ); - sb.append( "" ).append( XmlWriterUtil.LS ); - sb.append( repeat ); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == 2 - * ( XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() ) + 2 * repeat.length() ); + sb.append(repeat); + sb.append("") + .append(XmlWriterUtil.LS); + sb.append(repeat); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() + == 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()) + 2 * repeat.length()); } /** @@ -294,29 +285,27 @@ public void testWriteCommentXMLWriterStringIntInt() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentXMLWriterStringIntIntInt() - throws Exception - { - String indent = StringUtils.repeat( " ", 2 * 4 ); + public void testWriteCommentXMLWriterStringIntIntInt() throws Exception { + String indent = StringUtils.repeat(" ", 2 * 4); - XmlWriterUtil.writeComment( xmlWriter, "hello", 2, 4, 50 ); + XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 50); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( indent ); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == 50 - 1 + XmlWriterUtil.LS.length() + 2 * 4 ); + sb.append(indent); + sb.append("").append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() == 50 - 1 + XmlWriterUtil.LS.length() + 2 * 4); tearDown(); setUp(); - XmlWriterUtil.writeComment( xmlWriter, "hello", 2, 4, 10 ); + XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 10); writer.close(); sb = new StringBuffer(); - sb.append( indent ); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() >= 10 + 2 * 4 ); + sb.append(indent); + sb.append("").append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() >= 10 + 2 * 4); } /** @@ -326,40 +315,56 @@ public void testWriteCommentXMLWriterStringIntIntInt() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentTextXMLWriterStringInt() - throws Exception - { - XmlWriterUtil.writeCommentText( xmlWriter, "hello", 0 ); + public void testWriteCommentTextXMLWriterStringInt() throws Exception { + XmlWriterUtil.writeCommentText(xmlWriter, "hello", 0); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( XmlWriterUtil.LS ); - sb.append( "" ).append( XmlWriterUtil.LS ); - sb.append( "" ).append( XmlWriterUtil.LS ); - sb.append( "" ).append( XmlWriterUtil.LS ); - sb.append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == 3 * ( 80 - 1 + XmlWriterUtil.LS.length() ) - + 2 * XmlWriterUtil.LS.length() ); + sb.append(XmlWriterUtil.LS); + sb.append("") + .append(XmlWriterUtil.LS); + sb.append("") + .append(XmlWriterUtil.LS); + sb.append("") + .append(XmlWriterUtil.LS); + sb.append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); + assertTrue( + output.toString().length() == 3 * (80 - 1 + XmlWriterUtil.LS.length()) + 2 * XmlWriterUtil.LS.length()); tearDown(); setUp(); - String indent = StringUtils.repeat( " ", 2 * 2 ); + String indent = StringUtils.repeat(" ", 2 * 2); - XmlWriterUtil.writeCommentText( xmlWriter, "hello world with end of line\n and " - + "loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong line", 2 ); + XmlWriterUtil.writeCommentText( + xmlWriter, + "hello world with end of line\n and " + + "loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong line", + 2); writer.close(); sb = new StringBuffer(); - sb.append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( XmlWriterUtil.LS ); - sb.append( indent ); - assertEquals( output.toString(), sb.toString() ); + sb.append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(XmlWriterUtil.LS); + sb.append(indent); + assertEquals(output.toString(), sb.toString()); } /** @@ -369,23 +374,27 @@ public void testWriteCommentTextXMLWriterStringInt() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentTextXMLWriterStringIntInt() - throws Exception - { - String indent = StringUtils.repeat( " ", 2 * 4 ); + public void testWriteCommentTextXMLWriterStringIntInt() throws Exception { + String indent = StringUtils.repeat(" ", 2 * 4); - XmlWriterUtil.writeCommentText( xmlWriter, "hello", 2, 4 ); + XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( XmlWriterUtil.LS ); - sb.append( indent ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == 3 * ( 80 - 1 + XmlWriterUtil.LS.length() ) + 4 * 2 * 4 - + 2 * XmlWriterUtil.LS.length() ); + sb.append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(XmlWriterUtil.LS); + sb.append(indent); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() + == 3 * (80 - 1 + XmlWriterUtil.LS.length()) + 4 * 2 * 4 + 2 * XmlWriterUtil.LS.length()); } /** @@ -395,23 +404,27 @@ public void testWriteCommentTextXMLWriterStringIntInt() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentTextXMLWriterStringIntIntInt() - throws Exception - { - String indent = StringUtils.repeat( " ", 2 * 4 ); + public void testWriteCommentTextXMLWriterStringIntIntInt() throws Exception { + String indent = StringUtils.repeat(" ", 2 * 4); - XmlWriterUtil.writeCommentText( xmlWriter, "hello", 2, 4, 50 ); + XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4, 50); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( indent ).append( "" ).append( XmlWriterUtil.LS ); - sb.append( XmlWriterUtil.LS ); - sb.append( indent ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == 3 * ( 50 - 1 + XmlWriterUtil.LS.length() ) + 4 * 2 * 4 - + 2 * XmlWriterUtil.LS.length() ); + sb.append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(indent) + .append("") + .append(XmlWriterUtil.LS); + sb.append(XmlWriterUtil.LS); + sb.append(indent); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() + == 3 * (50 - 1 + XmlWriterUtil.LS.length()) + 4 * 2 * 4 + 2 * XmlWriterUtil.LS.length()); } /** @@ -421,14 +434,13 @@ public void testWriteCommentTextXMLWriterStringIntIntInt() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentNull() - throws Exception - { - XmlWriterUtil.writeComment( xmlWriter, null ); + public void testWriteCommentNull() throws Exception { + XmlWriterUtil.writeComment(xmlWriter, null); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); } /** @@ -438,14 +450,13 @@ public void testWriteCommentNull() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentShort() - throws Exception - { - XmlWriterUtil.writeComment( xmlWriter, "This is a short text" ); + public void testWriteCommentShort() throws Exception { + XmlWriterUtil.writeComment(xmlWriter, "This is a short text"); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); } /** @@ -455,18 +466,22 @@ public void testWriteCommentShort() * @throws java.lang.Exception if any */ @Test - public void testWriteCommentLong() - throws Exception - { - XmlWriterUtil.writeComment( xmlWriter, "Maven is a software project management and comprehension tool. " - + "Based on the concept of a project object model (POM), Maven can manage a project's build, reporting " - + "and documentation from a central piece of information." ); + public void testWriteCommentLong() throws Exception { + XmlWriterUtil.writeComment( + xmlWriter, + "Maven is a software project management and comprehension tool. " + + "Based on the concept of a project object model (POM), Maven can manage a project's build, reporting " + + "and documentation from a central piece of information."); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "" ).append( XmlWriterUtil.LS ); - sb.append( "" ).append( XmlWriterUtil.LS ); - sb.append( "" ).append( XmlWriterUtil.LS ); - sb.append( "" ).append( XmlWriterUtil.LS ); - assertEquals( output.toString(), sb.toString() ); + sb.append("") + .append(XmlWriterUtil.LS); + sb.append("") + .append(XmlWriterUtil.LS); + sb.append("") + .append(XmlWriterUtil.LS); + sb.append("") + .append(XmlWriterUtil.LS); + assertEquals(output.toString(), sb.toString()); } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java index bd696d62..c8db71b5 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java @@ -34,8 +34,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class Xpp3DomBuilderTest -{ +public class Xpp3DomBuilderTest { private static final String LS = System.lineSeparator(); /** @@ -44,16 +43,14 @@ public class Xpp3DomBuilderTest * @throws java.lang.Exception if any. */ @Test - public void testBuildFromReader() - throws Exception - { + public void testBuildFromReader() throws Exception { String domString = createDomString(); - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( domString ) ); + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString)); Xpp3Dom expectedDom = createExpectedDom(); - assertEquals( expectedDom, dom, "check DOMs match" ); + assertEquals(expectedDom, dom, "check DOMs match"); } /** @@ -62,18 +59,16 @@ public void testBuildFromReader() * @throws java.lang.Exception if any. */ @Test - public void testBuildTrimming() - throws Exception - { + public void testBuildTrimming() throws Exception { String domString = createDomString(); - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( domString ), true ); + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true); - assertEquals( "element1", dom.getChild( "el1" ).getValue(), "test with trimming on" ); + assertEquals("element1", dom.getChild("el1").getValue(), "test with trimming on"); - dom = Xpp3DomBuilder.build( new StringReader( domString ), false ); + dom = Xpp3DomBuilder.build(new StringReader(domString), false); - assertEquals( " element1\n ", dom.getChild( "el1" ).getValue(), "test with trimming off" ); + assertEquals(" element1\n ", dom.getChild("el1").getValue(), "test with trimming off"); } /** @@ -82,16 +77,14 @@ public void testBuildTrimming() * @throws java.lang.Exception if any. */ @Test - public void testBuildFromXpp3Dom() - throws Exception - { + public void testBuildFromXpp3Dom() throws Exception { Xpp3Dom expectedDom = createExpectedDom(); Xpp3Dom dom = null; XmlPullParser parser = new MXParser(); String domString = "" + createDomString() + ""; - parser.setInput( new StringReader( domString ) ); + parser.setInput(new StringReader(domString)); int eventType = parser.getEventType(); @@ -99,63 +92,47 @@ public void testBuildFromXpp3Dom() boolean newRootClosed = false; boolean rootClosed = false; - while ( eventType != XmlPullParser.END_DOCUMENT ) - { - if ( eventType == XmlPullParser.START_TAG ) - { + while (eventType != XmlPullParser.END_DOCUMENT) { + if (eventType == XmlPullParser.START_TAG) { String rawName = parser.getName(); - if ( "root".equals( rawName ) ) - { - dom = Xpp3DomBuilder.build( parser ); + if ("root".equals(rawName)) { + dom = Xpp3DomBuilder.build(parser); } - } - else if ( eventType == XmlPullParser.END_TAG ) - { + } else if (eventType == XmlPullParser.END_TAG) { String rawName = parser.getName(); - if ( "configuration".equals( rawName ) ) - { + if ("configuration".equals(rawName)) { configurationClosed = true; - } - else if ( "newRoot".equals( rawName ) ) - { + } else if ("newRoot".equals(rawName)) { newRootClosed = true; - } - else if ( "root".equals( rawName ) ) - { + } else if ("root".equals(rawName)) { rootClosed = true; } } eventType = parser.next(); } - assertEquals( expectedDom, dom, "Check DOM matches" ); - assertFalse( rootClosed, "Check closing root was consumed" ); - assertTrue( configurationClosed, "Check continued to parse configuration" ); - assertTrue( newRootClosed, "Check continued to parse newRoot" ); + assertEquals(expectedDom, dom, "Check DOM matches"); + assertFalse(rootClosed, "Check closing root was consumed"); + assertTrue(configurationClosed, "Check continued to parse configuration"); + assertTrue(newRootClosed, "Check continued to parse newRoot"); } /** * Test we get an error from the parser, and don't hit the IllegalStateException. */ @Test - public void testUnclosedXml() - { + public void testUnclosedXml() { String domString = "" + createDomString(); - try - { - Xpp3DomBuilder.build( new StringReader( domString ) ); - } - catch ( XmlPullParserException expected ) - { + try { + Xpp3DomBuilder.build(new StringReader(domString)); + } catch (XmlPullParserException expected) { // correct - assertTrue( true ); - } - catch ( IOException expected ) - { + assertTrue(true); + } catch (IOException expected) { // this will do too - assertTrue( true ); + assertTrue(true); } } @@ -166,18 +143,16 @@ public void testUnclosedXml() * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Test - public void testEscapingInContent() - throws IOException, XmlPullParserException - { - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( getEncodedString() ) ); + public void testEscapingInContent() throws IOException, XmlPullParserException { + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(getEncodedString())); - assertEquals( "\"text\"", dom.getChild( "el" ).getValue(), "Check content value" ); - assertEquals( "\"text\"", dom.getChild( "ela" ).getValue(), "Check content value" ); - assertEquals( "\"text\"", dom.getChild( "elb" ).getValue(), "Check content value" ); + assertEquals("\"text\"", dom.getChild("el").getValue(), "Check content value"); + assertEquals("\"text\"", dom.getChild("ela").getValue(), "Check content value"); + assertEquals("\"text\"", dom.getChild("elb").getValue(), "Check content value"); StringWriter w = new StringWriter(); - Xpp3DomWriter.write( w, dom ); - assertEquals( getExpectedString(), w.toString(), "Compare stringified DOMs" ); + Xpp3DomWriter.write(w, dom); + assertEquals(getExpectedString(), w.toString(), "Compare stringified DOMs"); } /** @@ -187,18 +162,16 @@ public void testEscapingInContent() * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Test - public void testEscapingInAttributes() - throws IOException, XmlPullParserException - { + public void testEscapingInAttributes() throws IOException, XmlPullParserException { String s = getAttributeEncodedString(); - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( s ) ); + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(s)); - assertEquals( "", dom.getChild( "el" ).getAttribute( "att" ), "Check attribute value" ); + assertEquals("", dom.getChild("el").getAttribute("att"), "Check attribute value"); StringWriter w = new StringWriter(); - Xpp3DomWriter.write( w, dom ); + Xpp3DomWriter.write(w, dom); String newString = w.toString(); - assertEquals( newString, s, "Compare stringified DOMs" ); + assertEquals(newString, s, "Compare stringified DOMs"); } /** @@ -208,70 +181,61 @@ public void testEscapingInAttributes() * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Test - public void testInputLocationTracking() - throws IOException, XmlPullParserException - { + public void testInputLocationTracking() throws IOException, XmlPullParserException { Xpp3DomBuilder.InputLocationBuilder ilb = new Xpp3DomBuilder.InputLocationBuilder() { - public Object toInputLocation( XmlPullParser parser ) - { + public Object toInputLocation(XmlPullParser parser) { return parser.getLineNumber(); // store only line number as a simple Integer } - }; - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( createDomString() ), true, ilb ); + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(createDomString()), true, ilb); Xpp3Dom expectedDom = createExpectedDom(); - assertEquals( expectedDom.getInputLocation(), dom.getInputLocation(), "root input location" ); - for( int i = 0; i < dom.getChildCount(); i++ ) - { - Xpp3Dom elt = dom.getChild( i ); - Xpp3Dom expectedElt = expectedDom.getChild( i ); - assertEquals( expectedElt.getInputLocation(), elt.getInputLocation(), elt.getName() + " input location" ); - - if ( "el2".equals( elt.getName() ) ) - { - Xpp3Dom el3 = elt.getChild( 0 ); - Xpp3Dom expectedEl3 = expectedElt.getChild( 0 ); - assertEquals( expectedEl3.getInputLocation(), el3.getInputLocation(), el3.getName() + " input location" ); + assertEquals(expectedDom.getInputLocation(), dom.getInputLocation(), "root input location"); + for (int i = 0; i < dom.getChildCount(); i++) { + Xpp3Dom elt = dom.getChild(i); + Xpp3Dom expectedElt = expectedDom.getChild(i); + assertEquals(expectedElt.getInputLocation(), elt.getInputLocation(), elt.getName() + " input location"); + + if ("el2".equals(elt.getName())) { + Xpp3Dom el3 = elt.getChild(0); + Xpp3Dom expectedEl3 = expectedElt.getChild(0); + assertEquals(expectedEl3.getInputLocation(), el3.getInputLocation(), el3.getName() + " input location"); } } } - private static String getAttributeEncodedString() - { + private static String getAttributeEncodedString() { StringBuilder domString = new StringBuilder(); - domString.append( "" ); - domString.append( LS ); - domString.append( " bar" ); - domString.append( LS ); - domString.append( "" ); + domString.append(""); + domString.append(LS); + domString.append(" bar"); + domString.append(LS); + domString.append(""); return domString.toString(); } - private static String getEncodedString() - { + private static String getEncodedString() { StringBuilder domString = new StringBuilder(); - domString.append( "\n" ); - domString.append( " \"text\"\n" ); - domString.append( " \"text\"]]>\n" ); - domString.append( " <b>"text"</b>\n" ); - domString.append( "" ); + domString.append("\n"); + domString.append(" \"text\"\n"); + domString.append(" \"text\"]]>\n"); + domString.append(" <b>"text"</b>\n"); + domString.append(""); return domString.toString(); } - private static String getExpectedString() - { + private static String getExpectedString() { StringBuilder domString = new StringBuilder(); - domString.append( "" ); - domString.append( LS ); - domString.append( " "text"" ); - domString.append( LS ); - domString.append( " <b>"text"</b>" ); - domString.append( LS ); - domString.append( " <b>"text"</b>" ); - domString.append( LS ); - domString.append( "" ); + domString.append(""); + domString.append(LS); + domString.append(" "text""); + domString.append(LS); + domString.append(" <b>"text"</b>"); + domString.append(LS); + domString.append(" <b>"text"</b>"); + domString.append(LS); + domString.append(""); return domString.toString(); } @@ -280,54 +244,52 @@ private static String getExpectedString() // HELPER METHODS // - private static String createDomString() - { + private static String createDomString() { StringBuilder buf = new StringBuilder(); - buf.append( "\n" ); - buf.append( " element1\n \n" ); - buf.append( " \n" ); - buf.append( " element3\n" ); - buf.append( " \n" ); - buf.append( " \n" ); - buf.append( " \n" ); - buf.append( " do not trim \n" ); - buf.append( "\n" ); + buf.append("\n"); + buf.append(" element1\n \n"); + buf.append(" \n"); + buf.append(" element3\n"); + buf.append(" \n"); + buf.append(" \n"); + buf.append(" \n"); + buf.append(" do not trim \n"); + buf.append("\n"); return buf.toString(); } - private static Xpp3Dom createExpectedDom() - { + private static Xpp3Dom createExpectedDom() { int line = 1; - Xpp3Dom expectedDom = new Xpp3Dom( "root" ); - expectedDom.setInputLocation( line ); - Xpp3Dom el1 = new Xpp3Dom( "el1" ); - el1.setInputLocation( ++line ); - el1.setValue( "element1" ); - expectedDom.addChild( el1 ); + Xpp3Dom expectedDom = new Xpp3Dom("root"); + expectedDom.setInputLocation(line); + Xpp3Dom el1 = new Xpp3Dom("el1"); + el1.setInputLocation(++line); + el1.setValue("element1"); + expectedDom.addChild(el1); ++line; // newline trimmed in Xpp3Dom but not in source - Xpp3Dom el2 = new Xpp3Dom( "el2" ); - el2.setInputLocation( ++line ); - el2.setAttribute( "att2", "attribute2\nnextline" ); - expectedDom.addChild( el2 ); - Xpp3Dom el3 = new Xpp3Dom( "el3" ); - el3.setInputLocation( ++line ); - el3.setAttribute( "att3", "attribute3" ); - el3.setValue( "element3" ); - el2.addChild( el3 ); + Xpp3Dom el2 = new Xpp3Dom("el2"); + el2.setInputLocation(++line); + el2.setAttribute("att2", "attribute2\nnextline"); + expectedDom.addChild(el2); + Xpp3Dom el3 = new Xpp3Dom("el3"); + el3.setInputLocation(++line); + el3.setAttribute("att3", "attribute3"); + el3.setValue("element3"); + el2.addChild(el3); ++line; - Xpp3Dom el4 = new Xpp3Dom( "el4" ); - el4.setInputLocation( ++line ); - el4.setValue( "" ); - expectedDom.addChild( el4 ); - Xpp3Dom el5 = new Xpp3Dom( "el5" ); - el5.setInputLocation( ++line ); - expectedDom.addChild( el5 ); - Xpp3Dom el6 = new Xpp3Dom( "el6" ); - el6.setInputLocation( ++line ); - el6.setAttribute( "xml:space", "preserve" ); - el6.setValue( " do not trim " ); - expectedDom.addChild( el6 ); + Xpp3Dom el4 = new Xpp3Dom("el4"); + el4.setInputLocation(++line); + el4.setValue(""); + expectedDom.addChild(el4); + Xpp3Dom el5 = new Xpp3Dom("el5"); + el5.setInputLocation(++line); + expectedDom.addChild(el5); + Xpp3Dom el6 = new Xpp3Dom("el6"); + el6.setInputLocation(++line); + el6.setAttribute("xml:space", "preserve"); + el6.setValue(" do not trim "); + expectedDom.addChild(el6); return expectedDom; } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomPerfTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomPerfTest.java index 22bba428..31636955 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomPerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomPerfTest.java @@ -46,22 +46,21 @@ @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) @Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS) -public class Xpp3DomPerfTest -{ +public class Xpp3DomPerfTest { @State(Scope.Benchmark) - static public class AdditionState { + public static class AdditionState { Xpp3Dom dom1; Xpp3Dom dom2; @Setup(Level.Iteration) public void setUp() throws IOException, XmlPullParserException { - String testDom = "onetwo"; - dom1 = Xpp3DomBuilder.build( new StringReader( testDom ) ); - dom2 = new Xpp3Dom( dom1 ); + String testDom = + "onetwo"; + dom1 = Xpp3DomBuilder.build(new StringReader(testDom)); + dom2 = new Xpp3Dom(dom1); } } - /** *

    benchmarkClone.

    * @@ -69,9 +68,8 @@ public void setUp() throws IOException, XmlPullParserException { * @return a {@link org.codehaus.plexus.util.xml.Xpp3Dom} object. */ @Benchmark - public Xpp3Dom benchmarkClone(AdditionState state) - { - return new Xpp3Dom( state.dom1 ); + public Xpp3Dom benchmarkClone(AdditionState state) { + return new Xpp3Dom(state.dom1); } /** @@ -80,9 +78,8 @@ public Xpp3Dom benchmarkClone(AdditionState state) * @param state a {@link org.codehaus.plexus.util.xml.Xpp3DomPerfTest.AdditionState} object. */ @Benchmark - public void benchmarkMerge(AdditionState state) - { - Xpp3Dom.mergeXpp3Dom( state.dom1, state.dom2 ); + public void benchmarkMerge(AdditionState state) { + Xpp3Dom.mergeXpp3Dom(state.dom1, state.dom2); } /** @@ -91,14 +88,12 @@ public void benchmarkMerge(AdditionState state) * @param args a {@link java.lang.String} object. * @throws org.openjdk.jmh.runner.RunnerException if any. */ - public static void main( String... args ) - throws RunnerException - { + public static void main(String... args) throws RunnerException { Options opts = new OptionsBuilder() - .measurementIterations( 3 ) - .measurementTime( TimeValue.milliseconds( 3000 ) ) - .forks( 1 ) + .measurementIterations(3) + .measurementTime(TimeValue.milliseconds(3000)) + .forks(1) .build(); - new Runner( opts ).run(); + new Runner(opts).run(); } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java index 469bb3f8..dccdde34 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java @@ -38,185 +38,172 @@ * @version $Id: $Id * @since 3.4.0 */ -public class Xpp3DomTest -{ +public class Xpp3DomTest { /** *

    testShouldPerformAppendAtFirstSubElementLevel.

    */ @Test - public void testShouldPerformAppendAtFirstSubElementLevel() - { + public void testShouldPerformAppendAtFirstSubElementLevel() { // create the dominant DOM - Xpp3Dom t1 = new Xpp3Dom( "top" ); - t1.setAttribute( Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND ); - t1.setInputLocation( "t1top" ); + Xpp3Dom t1 = new Xpp3Dom("top"); + t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND); + t1.setInputLocation("t1top"); - Xpp3Dom t1s1 = new Xpp3Dom( "topsub1" ); - t1s1.setValue( "t1s1Value" ); - t1s1.setInputLocation( "t1s1" ); + Xpp3Dom t1s1 = new Xpp3Dom("topsub1"); + t1s1.setValue("t1s1Value"); + t1s1.setInputLocation("t1s1"); - t1.addChild( t1s1 ); + t1.addChild(t1s1); // create the recessive DOM - Xpp3Dom t2 = new Xpp3Dom( "top" ); - t2.setInputLocation( "t2top" ); + Xpp3Dom t2 = new Xpp3Dom("top"); + t2.setInputLocation("t2top"); - Xpp3Dom t2s1 = new Xpp3Dom( "topsub1" ); - t2s1.setValue( "t2s1Value" ); - t2s1.setInputLocation( "t2s1" ); + Xpp3Dom t2s1 = new Xpp3Dom("topsub1"); + t2s1.setValue("t2s1Value"); + t2s1.setInputLocation("t2s1"); - t2.addChild( t2s1 ); + t2.addChild(t2s1); // merge and check results. - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( t1, t2 ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(t1, t2); - assertEquals( 2, result.getChildren( "topsub1" ).length ); - assertEquals( "t2s1Value", result.getChildren( "topsub1" )[0].getValue() ); - assertEquals( "t1s1Value", result.getChildren( "topsub1" )[1].getValue() ); + assertEquals(2, result.getChildren("topsub1").length); + assertEquals("t2s1Value", result.getChildren("topsub1")[0].getValue()); + assertEquals("t1s1Value", result.getChildren("topsub1")[1].getValue()); - assertEquals( "t1top", result.getInputLocation() ); - assertEquals( "t2s1", result.getChildren( "topsub1" )[0].getInputLocation() ); - assertEquals( "t1s1", result.getChildren( "topsub1" )[1].getInputLocation() ); + assertEquals("t1top", result.getInputLocation()); + assertEquals("t2s1", result.getChildren("topsub1")[0].getInputLocation()); + assertEquals("t1s1", result.getChildren("topsub1")[1].getInputLocation()); } /** *

    testShouldOverrideAppendAndDeepMerge.

    */ @Test - public void testShouldOverrideAppendAndDeepMerge() - { + public void testShouldOverrideAppendAndDeepMerge() { // create the dominant DOM - Xpp3Dom t1 = new Xpp3Dom( "top" ); - t1.setAttribute( Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND ); - t1.setInputLocation( "t1top" ); + Xpp3Dom t1 = new Xpp3Dom("top"); + t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND); + t1.setInputLocation("t1top"); - Xpp3Dom t1s1 = new Xpp3Dom( "topsub1" ); - t1s1.setValue( "t1s1Value" ); - t1s1.setInputLocation( "t1s1" ); + Xpp3Dom t1s1 = new Xpp3Dom("topsub1"); + t1s1.setValue("t1s1Value"); + t1s1.setInputLocation("t1s1"); - t1.addChild( t1s1 ); + t1.addChild(t1s1); // create the recessive DOM - Xpp3Dom t2 = new Xpp3Dom( "top" ); - t2.setInputLocation( "t2top" ); + Xpp3Dom t2 = new Xpp3Dom("top"); + t2.setInputLocation("t2top"); - Xpp3Dom t2s1 = new Xpp3Dom( "topsub1" ); - t2s1.setValue( "t2s1Value" ); - t2s1.setInputLocation( "t2s1" ); + Xpp3Dom t2s1 = new Xpp3Dom("topsub1"); + t2s1.setValue("t2s1Value"); + t2s1.setInputLocation("t2s1"); - t2.addChild( t2s1 ); + t2.addChild(t2s1); // merge and check results. - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( t1, t2, Boolean.TRUE ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(t1, t2, Boolean.TRUE); - assertEquals( 1, result.getChildren( "topsub1" ).length ); - assertEquals( "t1s1Value", result.getChildren( "topsub1" )[0].getValue() ); + assertEquals(1, result.getChildren("topsub1").length); + assertEquals("t1s1Value", result.getChildren("topsub1")[0].getValue()); - assertEquals( "t1top", result.getInputLocation() ); - assertEquals( "t1s1", result.getChildren( "topsub1" )[0].getInputLocation() ); + assertEquals("t1top", result.getInputLocation()); + assertEquals("t1s1", result.getChildren("topsub1")[0].getInputLocation()); } /** *

    testShouldPerformSelfOverrideAtTopLevel.

    */ @Test - public void testShouldPerformSelfOverrideAtTopLevel() - { + public void testShouldPerformSelfOverrideAtTopLevel() { // create the dominant DOM - Xpp3Dom t1 = new Xpp3Dom( "top" ); - t1.setAttribute( "attr", "value" ); - t1.setInputLocation( "t1top" ); + Xpp3Dom t1 = new Xpp3Dom("top"); + t1.setAttribute("attr", "value"); + t1.setInputLocation("t1top"); - t1.setAttribute( Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_OVERRIDE ); + t1.setAttribute(Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_OVERRIDE); // create the recessive DOM - Xpp3Dom t2 = new Xpp3Dom( "top" ); - t2.setAttribute( "attr2", "value2" ); - t2.setValue( "t2Value" ); - t2.setInputLocation( "t2top" ); + Xpp3Dom t2 = new Xpp3Dom("top"); + t2.setAttribute("attr2", "value2"); + t2.setValue("t2Value"); + t2.setInputLocation("t2top"); // merge and check results. - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( t1, t2 ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(t1, t2); - assertEquals( 2, result.getAttributeNames().length ); - assertNull( result.getValue() ); - assertEquals( "t1top", result.getInputLocation() ); + assertEquals(2, result.getAttributeNames().length); + assertNull(result.getValue()); + assertEquals("t1top", result.getInputLocation()); } /** *

    testShouldMergeValuesAtTopLevelByDefault.

    */ @Test - public void testShouldNotMergeValuesAtTopLevelByDefault() - { + public void testShouldNotMergeValuesAtTopLevelByDefault() { // create the dominant DOM - Xpp3Dom t1 = new Xpp3Dom( "top" ); - t1.setAttribute( "attr", "value" ); - t1.setInputLocation( "t1top" ); + Xpp3Dom t1 = new Xpp3Dom("top"); + t1.setAttribute("attr", "value"); + t1.setInputLocation("t1top"); // create the recessive DOM - Xpp3Dom t2 = new Xpp3Dom( "top" ); - t2.setAttribute( "attr2", "value2" ); - t2.setValue( "t2Value" ); - t2.setInputLocation( "t2top" ); + Xpp3Dom t2 = new Xpp3Dom("top"); + t2.setAttribute("attr2", "value2"); + t2.setValue("t2Value"); + t2.setInputLocation("t2top"); // merge and check results. - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( t1, t2 ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(t1, t2); // this is still 2, since we're not using the merge-control attribute. - assertEquals( 2, result.getAttributeNames().length ); + assertEquals(2, result.getAttributeNames().length); - assertEquals( result.getValue(), t1.getValue() ); - assertEquals( "t1top", result.getInputLocation() ); + assertEquals(result.getValue(), t1.getValue()); + assertEquals("t1top", result.getInputLocation()); } /** *

    testShouldMergeValuesAtTopLevel.

    */ @Test - public void testShouldNotMergeValues() - { + public void testShouldNotMergeValues() { // create the dominant DOM - Xpp3Dom t1 = new Xpp3Dom( "top" ); - t1.setAttribute( "attr", "value" ); + Xpp3Dom t1 = new Xpp3Dom("top"); + t1.setAttribute("attr", "value"); - t1.setAttribute( Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_MERGE ); + t1.setAttribute(Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_MERGE); // create the recessive DOM - Xpp3Dom t2 = new Xpp3Dom( "top" ); - t2.setAttribute( "attr2", "value2" ); - t2.setValue( "t2Value" ); + Xpp3Dom t2 = new Xpp3Dom("top"); + t2.setAttribute("attr2", "value2"); + t2.setValue("t2Value"); // merge and check results. - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( t1, t2 ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(t1, t2); - assertEquals( 3, result.getAttributeNames().length ); - assertNull( result.getValue(), t1.getValue() ); + assertEquals(3, result.getAttributeNames().length); + assertNull(result.getValue(), t1.getValue()); } /** *

    testNullAttributeNameOrValue.

    */ @Test - public void testNullAttributeNameOrValue() - { - Xpp3Dom t1 = new Xpp3Dom( "top" ); - try - { - t1.setAttribute( "attr", null ); - fail( "null attribute values shouldn't be allowed" ); - } - catch ( NullPointerException e ) - { + public void testNullAttributeNameOrValue() { + Xpp3Dom t1 = new Xpp3Dom("top"); + try { + t1.setAttribute("attr", null); + fail("null attribute values shouldn't be allowed"); + } catch (NullPointerException e) { } t1.toString(); - try - { - t1.setAttribute( null, "value" ); - fail( "null attribute names shouldn't be allowed" ); - } - catch ( NullPointerException e ) - { + try { + t1.setAttribute(null, "value"); + fail("null attribute names shouldn't be allowed"); + } catch (NullPointerException e) { } t1.toString(); } @@ -225,13 +212,12 @@ public void testNullAttributeNameOrValue() *

    testEquals.

    */ @Test - public void testEquals() - { - Xpp3Dom dom = new Xpp3Dom( "top" ); + public void testEquals() { + Xpp3Dom dom = new Xpp3Dom("top"); - assertEquals( dom, dom ); - assertFalse( dom.equals( null ) ); - assertFalse( dom.equals( new Xpp3Dom( "" ) ) ); + assertEquals(dom, dom); + assertFalse(dom.equals(null)); + assertFalse(dom.equals(new Xpp3Dom(""))); } /** @@ -241,21 +227,19 @@ public void testEquals() * @throws java.io.IOException if any. */ @Test - public void testEqualsIsNullSafe() - throws XmlPullParserException, IOException - { + public void testEqualsIsNullSafe() throws XmlPullParserException, IOException { String testDom = "onetwo"; - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( testDom ) ); + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(testDom)); Map attributes = new HashMap<>(); - attributes.put( "nullValue", null ); - attributes.put( null, "nullKey" ); + attributes.put("nullValue", null); + attributes.put(null, "nullKey"); List childList = new ArrayList<>(); - childList.add( null ); - Xpp3Dom dom2 = new Xpp3Dom( new XmlNodeImpl( dom.getName(), null, attributes, childList, null ) ); + childList.add(null); + Xpp3Dom dom2 = new Xpp3Dom(new XmlNodeImpl(dom.getName(), null, attributes, childList, null)); - assertNotEquals( dom, dom2 ); - assertNotEquals( dom2, dom ); + assertNotEquals(dom, dom2); + assertNotEquals(dom2, dom); } /** @@ -265,25 +249,23 @@ public void testEqualsIsNullSafe() * @throws java.io.IOException if any. */ @Test - public void testShouldOverwritePluginConfigurationSubItemsByDefault() - throws XmlPullParserException, IOException - { + public void testShouldOverwritePluginConfigurationSubItemsByDefault() throws XmlPullParserException, IOException { String parentConfigStr = "onetwo"; Xpp3Dom parentConfig = - Xpp3DomBuilder.build( new StringReader( parentConfigStr ), new FixedInputLocationBuilder( "parent" ) ); + Xpp3DomBuilder.build(new StringReader(parentConfigStr), new FixedInputLocationBuilder("parent")); String childConfigStr = "three"; Xpp3Dom childConfig = - Xpp3DomBuilder.build( new StringReader( childConfigStr ), new FixedInputLocationBuilder( "child" ) ); + Xpp3DomBuilder.build(new StringReader(childConfigStr), new FixedInputLocationBuilder("child")); - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( childConfig, parentConfig ); - Xpp3Dom items = result.getChild( "items" ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(childConfig, parentConfig); + Xpp3Dom items = result.getChild("items"); - assertEquals( 1, items.getChildCount() ); + assertEquals(1, items.getChildCount()); - Xpp3Dom item = items.getChild( 0 ); - assertEquals( "three", item.getValue() ); - assertEquals( "child", item.getInputLocation() ); + Xpp3Dom item = items.getChild(0); + assertEquals("three", item.getValue()); + assertEquals("child", item.getInputLocation()); } /** @@ -294,30 +276,29 @@ public void testShouldOverwritePluginConfigurationSubItemsByDefault() */ @Test public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() - throws XmlPullParserException, IOException - { + throws XmlPullParserException, IOException { String parentConfigStr = "onetwo"; Xpp3Dom parentConfig = - Xpp3DomBuilder.build( new StringReader( parentConfigStr ), new FixedInputLocationBuilder( "parent" ) ); + Xpp3DomBuilder.build(new StringReader(parentConfigStr), new FixedInputLocationBuilder("parent")); String childConfigStr = - "three"; + "three"; Xpp3Dom childConfig = - Xpp3DomBuilder.build( new StringReader( childConfigStr ), new FixedInputLocationBuilder( "child" ) ); + Xpp3DomBuilder.build(new StringReader(childConfigStr), new FixedInputLocationBuilder("child")); - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( childConfig, parentConfig ); - Xpp3Dom items = result.getChild( "items" ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(childConfig, parentConfig); + Xpp3Dom items = result.getChild("items"); - assertEquals( 3, items.getChildCount() ); + assertEquals(3, items.getChildCount()); Xpp3Dom[] item = items.getChildren(); - assertEquals( "one", item[0].getValue() ); - assertEquals( "parent", item[0].getInputLocation() ); - assertEquals( "two", item[1].getValue() ); - assertEquals( "parent", item[1].getInputLocation() ); - assertEquals( "three", item[2].getValue() ); - assertEquals( "child", item[2].getInputLocation() ); + assertEquals("one", item[0].getValue()); + assertEquals("parent", item[0].getInputLocation()); + assertEquals("two", item[1].getValue()); + assertEquals("parent", item[1].getInputLocation()); + assertEquals("three", item[2].getValue()); + assertEquals("child", item[2].getInputLocation()); } /** @@ -326,21 +307,19 @@ public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() * @throws java.lang.Exception if any. */ @Test - public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty() - throws Exception - { + public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty() throws Exception { String configStr = "test"; - Xpp3Dom dominantConfig = Xpp3DomBuilder.build( new StringReader( configStr ) ); - Xpp3Dom recessiveConfig = Xpp3DomBuilder.build( new StringReader( configStr ) ); + Xpp3Dom dominantConfig = Xpp3DomBuilder.build(new StringReader(configStr)); + Xpp3Dom recessiveConfig = Xpp3DomBuilder.build(new StringReader(configStr)); - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( dominantConfig, recessiveConfig ); - Xpp3Dom items = result.getChild( "items" ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(dominantConfig, recessiveConfig); + Xpp3Dom items = result.getChild("items"); - assertEquals( 3, items.getChildCount() ); + assertEquals(3, items.getChildCount()); - assertEquals( null, items.getChild( 0 ).getValue() ); - assertEquals( "test", items.getChild( 1 ).getValue() ); - assertEquals( null, items.getChild( 2 ).getValue() ); + assertEquals(null, items.getChild(0).getValue()); + assertEquals("test", items.getChild(1).getValue()); + assertEquals(null, items.getChild(2).getValue()); } /** @@ -349,21 +328,19 @@ public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty( * @throws java.lang.Exception if any. */ @Test - public void testShouldCopyRecessiveChildrenNotPresentInTarget() - throws Exception - { + public void testShouldCopyRecessiveChildrenNotPresentInTarget() throws Exception { String dominantStr = "x"; String recessiveStr = "y"; - Xpp3Dom dominantConfig = Xpp3DomBuilder.build( new StringReader( dominantStr ) ); - Xpp3Dom recessiveConfig = Xpp3DomBuilder.build( new StringReader( recessiveStr ) ); + Xpp3Dom dominantConfig = Xpp3DomBuilder.build(new StringReader(dominantStr)); + Xpp3Dom recessiveConfig = Xpp3DomBuilder.build(new StringReader(recessiveStr)); - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( dominantConfig, recessiveConfig ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(dominantConfig, recessiveConfig); - assertEquals( 2, result.getChildCount() ); + assertEquals(2, result.getChildCount()); - assertEquals( "x", result.getChild( "foo" ).getValue() ); - assertEquals( "y", result.getChild( "bar" ).getValue() ); - assertNotSame( result.getChild( "bar" ), recessiveConfig.getChild( "bar" ) ); + assertEquals("x", result.getChild("foo").getValue()); + assertEquals("y", result.getChild("bar").getValue()); + assertNotSame(result.getChild("bar"), recessiveConfig.getChild("bar")); } /** @@ -373,13 +350,11 @@ public void testShouldCopyRecessiveChildrenNotPresentInTarget() * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Test - public void testDupeChildren() - throws IOException, XmlPullParserException - { + public void testDupeChildren() throws IOException, XmlPullParserException { String dupes = "xy"; - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( dupes ) ); - assertNotNull( dom ); - assertEquals( "y", dom.getChild( "foo" ).getValue() ); + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(dupes)); + assertNotNull(dom); + assertEquals("y", dom.getChild("foo").getValue()); } /** @@ -388,18 +363,16 @@ public void testDupeChildren() * @throws java.lang.Exception if any. */ @Test - public void testShouldRemoveEntireElementWithAttributesAndChildren() - throws Exception - { + public void testShouldRemoveEntireElementWithAttributesAndChildren() throws Exception { String dominantStr = ""; String recessiveStr = "parameter"; - Xpp3Dom dominantConfig = Xpp3DomBuilder.build( new StringReader( dominantStr ) ); - Xpp3Dom recessiveConfig = Xpp3DomBuilder.build( new StringReader( recessiveStr ) ); + Xpp3Dom dominantConfig = Xpp3DomBuilder.build(new StringReader(dominantStr)); + Xpp3Dom recessiveConfig = Xpp3DomBuilder.build(new StringReader(recessiveStr)); - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( dominantConfig, recessiveConfig ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(dominantConfig, recessiveConfig); - assertEquals( 0, result.getChildCount() ); - assertEquals( "config", result.getName() ); + assertEquals(0, result.getChildCount()); + assertEquals("config", result.getName()); } /** @@ -408,18 +381,16 @@ public void testShouldRemoveEntireElementWithAttributesAndChildren() * @throws java.lang.Exception if any. */ @Test - public void testShouldRemoveDoNotRemoveTagWhenSwappedInputDOMs() - throws Exception - { + public void testShouldRemoveDoNotRemoveTagWhenSwappedInputDOMs() throws Exception { String dominantStr = ""; String recessiveStr = "parameter"; - Xpp3Dom dominantConfig = Xpp3DomBuilder.build( new StringReader( dominantStr ) ); - Xpp3Dom recessiveConfig = Xpp3DomBuilder.build( new StringReader( recessiveStr ) ); + Xpp3Dom dominantConfig = Xpp3DomBuilder.build(new StringReader(dominantStr)); + Xpp3Dom recessiveConfig = Xpp3DomBuilder.build(new StringReader(recessiveStr)); // same DOMs as testShouldRemoveEntireElementWithAttributesAndChildren(), swapping dominant <--> recessive - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( recessiveConfig, dominantConfig ); + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(recessiveConfig, dominantConfig); - assertEquals( recessiveConfig.toString(), result.toString() ); + assertEquals(recessiveConfig.toString(), result.toString()); } /** @@ -428,38 +399,46 @@ public void testShouldRemoveDoNotRemoveTagWhenSwappedInputDOMs() * @throws java.lang.Exception if any. */ @Test - public void testCombineId() - throws Exception - { + public void testCombineId() throws Exception { String lhs = "" + "LHS-ONLYLHS" - + "TOOVERWRITELHS" + ""; + + "TOOVERWRITELHS" + + ""; String rhs = "" + "RHS-ONLYRHS" - + "TOOVERWRITERHS" + ""; - - Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new Xpp3DomTest.FixedInputLocationBuilder( "left" ) ); - Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ), new Xpp3DomTest.FixedInputLocationBuilder( "right" ) ); - - Xpp3Dom mergeResult = Xpp3Dom.mergeXpp3Dom( leftDom, rightDom, true ); - assertEquals( 3, mergeResult.getChildren( "property" ).length ); - - Xpp3Dom p0 = mergeResult.getChildren( "property" )[0]; - assertEquals( "LHS-ONLY", p0.getChild( "name" ).getValue() ); - assertEquals( "left", p0.getChild( "name" ).getInputLocation() ); - assertEquals( "LHS", p0.getChild( "value" ).getValue() ); - assertEquals( "left", p0.getChild( "value" ).getInputLocation() ); - - Xpp3Dom p1 = mergeResult.getChildren( "property" )[1]; - assertEquals( "TOOVERWRITE", mergeResult.getChildren( "property" )[1].getChild( "name" ).getValue() ); - assertEquals( "left", p1.getChild( "name" ).getInputLocation() ); - assertEquals( "LHS", mergeResult.getChildren( "property" )[1].getChild( "value" ).getValue() ); - assertEquals( "left", p1.getChild( "value" ).getInputLocation() ); - - Xpp3Dom p2 = mergeResult.getChildren( "property" )[2]; - assertEquals( "RHS-ONLY", mergeResult.getChildren( "property" )[2].getChild( "name" ).getValue() ); - assertEquals( "right", p2.getChild( "name" ).getInputLocation() ); - assertEquals( "RHS", mergeResult.getChildren( "property" )[2].getChild( "value" ).getValue() ); - assertEquals( "right", p2.getChild( "value" ).getInputLocation() ); + + "TOOVERWRITERHS" + + ""; + + Xpp3Dom leftDom = + Xpp3DomBuilder.build(new StringReader(lhs), new Xpp3DomTest.FixedInputLocationBuilder("left")); + Xpp3Dom rightDom = + Xpp3DomBuilder.build(new StringReader(rhs), new Xpp3DomTest.FixedInputLocationBuilder("right")); + + Xpp3Dom mergeResult = Xpp3Dom.mergeXpp3Dom(leftDom, rightDom, true); + assertEquals(3, mergeResult.getChildren("property").length); + + Xpp3Dom p0 = mergeResult.getChildren("property")[0]; + assertEquals("LHS-ONLY", p0.getChild("name").getValue()); + assertEquals("left", p0.getChild("name").getInputLocation()); + assertEquals("LHS", p0.getChild("value").getValue()); + assertEquals("left", p0.getChild("value").getInputLocation()); + + Xpp3Dom p1 = mergeResult.getChildren("property")[1]; + assertEquals( + "TOOVERWRITE", + mergeResult.getChildren("property")[1].getChild("name").getValue()); + assertEquals("left", p1.getChild("name").getInputLocation()); + assertEquals( + "LHS", mergeResult.getChildren("property")[1].getChild("value").getValue()); + assertEquals("left", p1.getChild("value").getInputLocation()); + + Xpp3Dom p2 = mergeResult.getChildren("property")[2]; + assertEquals( + "RHS-ONLY", + mergeResult.getChildren("property")[2].getChild("name").getValue()); + assertEquals("right", p2.getChild("name").getInputLocation()); + assertEquals( + "RHS", mergeResult.getChildren("property")[2].getChild("value").getValue()); + assertEquals("right", p2.getChild("value").getInputLocation()); } /** @@ -468,38 +447,46 @@ public void testCombineId() * @throws java.lang.Exception if any. */ @Test - public void testCombineKeys() - throws Exception - { - String lhs = "" + "LHS-ONLYLHS" - + "TOOVERWRITELHS" + ""; - - String rhs = "" + "RHS-ONLYRHS" - + "TOOVERWRITERHS" + ""; - - Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new Xpp3DomTest.FixedInputLocationBuilder( "left" ) ); - Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ), new Xpp3DomTest.FixedInputLocationBuilder( "right" ) ); - - Xpp3Dom mergeResult = Xpp3Dom.mergeXpp3Dom( leftDom, rightDom, true ); - assertEquals( 3, mergeResult.getChildren( "property" ).length ); - - Xpp3Dom p0 = mergeResult.getChildren( "property" )[0]; - assertEquals( "LHS-ONLY", p0.getChild( "name" ).getValue() ); - assertEquals( "left", p0.getChild( "name" ).getInputLocation() ); - assertEquals( "LHS", p0.getChild( "value" ).getValue() ); - assertEquals( "left", p0.getChild( "value" ).getInputLocation() ); - - Xpp3Dom p1 = mergeResult.getChildren( "property" )[1]; - assertEquals( "TOOVERWRITE", mergeResult.getChildren( "property" )[1].getChild( "name" ).getValue() ); - assertEquals( "left", p1.getChild( "name" ).getInputLocation() ); - assertEquals( "LHS", mergeResult.getChildren( "property" )[1].getChild( "value" ).getValue() ); - assertEquals( "left", p1.getChild( "value" ).getInputLocation() ); - - Xpp3Dom p2 = mergeResult.getChildren( "property" )[2]; - assertEquals( "RHS-ONLY", mergeResult.getChildren( "property" )[2].getChild( "name" ).getValue() ); - assertEquals( "right", p2.getChild( "name" ).getInputLocation() ); - assertEquals( "RHS", mergeResult.getChildren( "property" )[2].getChild( "value" ).getValue() ); - assertEquals( "right", p2.getChild( "value" ).getInputLocation() ); + public void testCombineKeys() throws Exception { + String lhs = "" + + "LHS-ONLYLHS" + + "TOOVERWRITELHS" + ""; + + String rhs = "" + + "RHS-ONLYRHS" + + "TOOVERWRITERHS" + ""; + + Xpp3Dom leftDom = + Xpp3DomBuilder.build(new StringReader(lhs), new Xpp3DomTest.FixedInputLocationBuilder("left")); + Xpp3Dom rightDom = + Xpp3DomBuilder.build(new StringReader(rhs), new Xpp3DomTest.FixedInputLocationBuilder("right")); + + Xpp3Dom mergeResult = Xpp3Dom.mergeXpp3Dom(leftDom, rightDom, true); + assertEquals(3, mergeResult.getChildren("property").length); + + Xpp3Dom p0 = mergeResult.getChildren("property")[0]; + assertEquals("LHS-ONLY", p0.getChild("name").getValue()); + assertEquals("left", p0.getChild("name").getInputLocation()); + assertEquals("LHS", p0.getChild("value").getValue()); + assertEquals("left", p0.getChild("value").getInputLocation()); + + Xpp3Dom p1 = mergeResult.getChildren("property")[1]; + assertEquals( + "TOOVERWRITE", + mergeResult.getChildren("property")[1].getChild("name").getValue()); + assertEquals("left", p1.getChild("name").getInputLocation()); + assertEquals( + "LHS", mergeResult.getChildren("property")[1].getChild("value").getValue()); + assertEquals("left", p1.getChild("value").getInputLocation()); + + Xpp3Dom p2 = mergeResult.getChildren("property")[2]; + assertEquals( + "RHS-ONLY", + mergeResult.getChildren("property")[2].getChild("name").getValue()); + assertEquals("right", p2.getChild("name").getInputLocation()); + assertEquals( + "RHS", mergeResult.getChildren("property")[2].getChild("value").getValue()); + assertEquals("right", p2.getChild("value").getInputLocation()); } @Test @@ -508,39 +495,38 @@ public void testPreserveDominantBlankValue() throws XmlPullParserException, IOEx String rhs = "recessive"; - Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new Xpp3DomTest.FixedInputLocationBuilder( "left" ) ); - Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ), new Xpp3DomTest.FixedInputLocationBuilder( "right" ) ); + Xpp3Dom leftDom = + Xpp3DomBuilder.build(new StringReader(lhs), new Xpp3DomTest.FixedInputLocationBuilder("left")); + Xpp3Dom rightDom = + Xpp3DomBuilder.build(new StringReader(rhs), new Xpp3DomTest.FixedInputLocationBuilder("right")); - Xpp3Dom mergeResult = Xpp3Dom.mergeXpp3Dom( leftDom, rightDom, true ); - assertEquals( " ", mergeResult.getValue() ); + Xpp3Dom mergeResult = Xpp3Dom.mergeXpp3Dom(leftDom, rightDom, true); + assertEquals(" ", mergeResult.getValue()); } @Test - public void testPreserveDominantEmptyNode() throws XmlPullParserException, IOException - { + public void testPreserveDominantEmptyNode() throws XmlPullParserException, IOException { String lhs = ""; String rhs = "recessive"; - Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new Xpp3DomTest.FixedInputLocationBuilder( "left" ) ); - Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ), new Xpp3DomTest.FixedInputLocationBuilder( "right" ) ); + Xpp3Dom leftDom = + Xpp3DomBuilder.build(new StringReader(lhs), new Xpp3DomTest.FixedInputLocationBuilder("left")); + Xpp3Dom rightDom = + Xpp3DomBuilder.build(new StringReader(rhs), new Xpp3DomTest.FixedInputLocationBuilder("right")); - Xpp3Dom mergeResult = Xpp3Dom.mergeXpp3Dom( leftDom, rightDom, true ); - assertEquals( "", mergeResult.getValue() ); + Xpp3Dom mergeResult = Xpp3Dom.mergeXpp3Dom(leftDom, rightDom, true); + assertEquals("", mergeResult.getValue()); } - private static class FixedInputLocationBuilder - implements Xpp3DomBuilder.InputLocationBuilder - { + private static class FixedInputLocationBuilder implements Xpp3DomBuilder.InputLocationBuilder { private final Object location; - public FixedInputLocationBuilder( Object location ) - { + public FixedInputLocationBuilder(Object location) { this.location = location; } - public Object toInputLocation( XmlPullParser parser ) - { + public Object toInputLocation(XmlPullParser parser) { return location; } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java index 8076b37f..7f7f3219 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java @@ -29,103 +29,95 @@ * @version $Id: $Id * @since 3.4.0 */ -public class Xpp3DomWriterTest -{ - private static final String LS = System.getProperty( "line.separator" ); +public class Xpp3DomWriterTest { + private static final String LS = System.getProperty("line.separator"); /** *

    testWriter.

    */ @Test - public void testWriter() - { + public void testWriter() { StringWriter writer = new StringWriter(); - Xpp3DomWriter.write( writer, createXpp3Dom() ); + Xpp3DomWriter.write(writer, createXpp3Dom()); - assertEquals( createExpectedXML( true ), writer.toString(), "Check if output matches" ); + assertEquals(createExpectedXML(true), writer.toString(), "Check if output matches"); } /** *

    testWriterNoEscape.

    */ @Test - public void testWriterNoEscape() - { + public void testWriterNoEscape() { StringWriter writer = new StringWriter(); - Xpp3DomWriter.write( new PrettyPrintXMLWriter( writer ), createXpp3Dom(), false ); + Xpp3DomWriter.write(new PrettyPrintXMLWriter(writer), createXpp3Dom(), false); - assertEquals( createExpectedXML( false ), writer.toString(), "Check if output matches" ); + assertEquals(createExpectedXML(false), writer.toString(), "Check if output matches"); } - private String createExpectedXML( boolean escape ) - { + private String createExpectedXML(boolean escape) { StringBuilder buf = new StringBuilder(); - buf.append( "" ); - buf.append( LS ); - buf.append( " element1" ); - buf.append( LS ); - buf.append( " " ); - buf.append( LS ); - buf.append( " element3" ); - buf.append( LS ); - buf.append( " " ); - buf.append( LS ); - buf.append( " " ); - buf.append( LS ); - buf.append( " " ); - buf.append( LS ); - buf.append( " " ); - buf.append( LS ); - if ( escape ) - { - buf.append( " element7" ).append( LS ).append( "&"'<>" ); + buf.append(""); + buf.append(LS); + buf.append(" element1"); + buf.append(LS); + buf.append(" "); + buf.append(LS); + buf.append(" element3"); + buf.append(LS); + buf.append(" "); + buf.append(LS); + buf.append(" "); + buf.append(LS); + buf.append(" "); + buf.append(LS); + buf.append(" "); + buf.append(LS); + if (escape) { + buf.append(" element7").append(LS).append("&"'<>"); + } else { + buf.append(" element7").append(LS).append("&\"\'<>"); } - else - { - buf.append( " element7" ).append( LS ).append( "&\"\'<>" ); - } - buf.append( LS ); - buf.append( " " ); - buf.append( LS ); - buf.append( "" ); + buf.append(LS); + buf.append(" "); + buf.append(LS); + buf.append(""); return buf.toString(); } - private Xpp3Dom createXpp3Dom() - { - Xpp3Dom dom = new Xpp3Dom( "root" ); + private Xpp3Dom createXpp3Dom() { + Xpp3Dom dom = new Xpp3Dom("root"); - Xpp3Dom el1 = new Xpp3Dom( "el1" ); - el1.setValue( "element1" ); - dom.addChild( el1 ); + Xpp3Dom el1 = new Xpp3Dom("el1"); + el1.setValue("element1"); + dom.addChild(el1); - Xpp3Dom el2 = new Xpp3Dom( "el2" ); - el2.setAttribute( "att2", "attribute2\nnextline" ); - dom.addChild( el2 ); + Xpp3Dom el2 = new Xpp3Dom("el2"); + el2.setAttribute("att2", "attribute2\nnextline"); + dom.addChild(el2); - Xpp3Dom el3 = new Xpp3Dom( "el3" ); - el3.setAttribute( "att3", "attribute3" ); - el3.setValue( "element3" ); - el2.addChild( el3 ); + Xpp3Dom el3 = new Xpp3Dom("el3"); + el3.setAttribute("att3", "attribute3"); + el3.setValue("element3"); + el2.addChild(el3); - Xpp3Dom el4 = new Xpp3Dom( "el4" ); - el4.setValue( "" ); - dom.addChild( el4 ); + Xpp3Dom el4 = new Xpp3Dom("el4"); + el4.setValue(""); + dom.addChild(el4); - Xpp3Dom el5 = new Xpp3Dom( "el5" ); - dom.addChild( el5 ); + Xpp3Dom el5 = new Xpp3Dom("el5"); + dom.addChild(el5); // test escaping - Xpp3Dom el6 = new Xpp3Dom( "el6" ); - el6.setAttribute( "att6", "attribute6\n&\"'<>" ); - dom.addChild( el6 ); + Xpp3Dom el6 = new Xpp3Dom("el6"); + el6.setAttribute("att6", "attribute6\n&\"'<>"); + dom.addChild(el6); - Xpp3Dom el7 = new Xpp3Dom( "el7" ); - el7.setValue( "element7\n&\"\'<>" ); - el6.addChild( el7 ); + Xpp3Dom el7 = new Xpp3Dom("el7"); + el7.setValue("element7\n&\"\'<>"); + el6.addChild(el7); return dom; } diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java index 0d183346..bb1a7e8f 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java @@ -20,10 +20,10 @@ * @version $Id: $Id * @since 3.4.0 */ -public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test -{ +public +class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test { - final static File testResourcesDir = new File( "src/test/resources/", "xmlconf/ibm/" ); + static final File testResourcesDir = new File("src/test/resources/", "xmlconf/ibm/"); MXParser parser; @@ -31,8 +31,7 @@ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMX *

    setUp.

    */ @BeforeEach - public void setUp() - { + public void setUp() { parser = new MXParser(); } @@ -46,228 +45,190 @@ public void setUp() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n01xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n01.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P24_ibm24n01xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n01.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests VersionInfo with a required field missing. The VersionNum is missing in the VersionInfo in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected apostrophe (') or quotation mark (\") after version and not ?" ) ); + fail( + "Tests VersionInfo with a required field missing. The VersionNum is missing in the VersionInfo in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue( + e.getMessage().contains("expected apostrophe (') or quotation mark (\") after version and not ?")); } } - /** - * Test ID:
    ibm-not-wf-P24-ibm24n02.xml
    - * Test URI:
    not-wf/P24/ibm24n02.xml
    - * Comment:
    Tests VersionInfo with a required field missing. The white space is     missing between the key word "xml" and the VersionInfo in the XMLDecl.
    - * Sections:
    2.8
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P24_ibm24n02xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n02.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests VersionInfo with a required field missing. The white space is missing between the key word \"xml\" and the VersionInfo in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected v in version and not ?" ) ); - } - } - - /** - * Test ID:
    ibm-not-wf-P24-ibm24n03.xml
    - * Test URI:
    not-wf/P24/ibm24n03.xml
    - * Comment:
    Tests VersionInfo with a required field missing. The "="      (equal sign) is missing between the key word "version" and the VersionNum.
    - * Sections:
    2.8
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P24_ibm24n03xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n03.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests VersionInfo with a required field missing. The \"=\" (equal sign) is missing between the key word \"version\" and the VersionNum." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected equals sign (=) after version and not \\'" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P24-ibm24n02.xml
    + * Test URI:
    not-wf/P24/ibm24n02.xml
    + * Comment:
    Tests VersionInfo with a required field missing. The white space is     missing between the key word "xml" and the VersionInfo in the XMLDecl.
    + * Sections:
    2.8
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P24_ibm24n02xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n02.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests VersionInfo with a required field missing. The white space is missing between the key word \"xml\" and the VersionInfo in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected v in version and not ?")); + } + } - /** - * Test ID:
    ibm-not-wf-P24-ibm24n04.xml
    - * Test URI:
    not-wf/P24/ibm24n04.xml
    - * Comment:
    Tests VersionInfo with wrong field ordering. The VersionNum     occurs before "=" and "version".
    - * Sections:
    2.8
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P24_ibm24n04xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n04.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests VersionInfo with wrong field ordering. The VersionNum occurs before \"=\" and \"version\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected v in version and not \\'" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P24-ibm24n03.xml
    + * Test URI:
    not-wf/P24/ibm24n03.xml
    + * Comment:
    Tests VersionInfo with a required field missing. The "="      (equal sign) is missing between the key word "version" and the VersionNum.
    + * Sections:
    2.8
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P24_ibm24n03xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n03.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests VersionInfo with a required field missing. The \"=\" (equal sign) is missing between the key word \"version\" and the VersionNum."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected equals sign (=) after version and not \\'")); + } + } - /** - * Test ID:
    ibm-not-wf-P24-ibm24n05.xml
    - * Test URI:
    not-wf/P24/ibm24n05.xml
    - * Comment:
    Tests VersionInfo with wrong field ordering. The "=" occurs     after "version" and the VersionNum.
    - * Sections:
    2.8
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P24_ibm24n05xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n05.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests VersionInfo with wrong field ordering. The \"=\" occurs after \"version\" and the VersionNum." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected equals sign (=) after version and not \\'" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P24-ibm24n04.xml
    + * Test URI:
    not-wf/P24/ibm24n04.xml
    + * Comment:
    Tests VersionInfo with wrong field ordering. The VersionNum     occurs before "=" and "version".
    + * Sections:
    2.8
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P24_ibm24n04xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n04.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests VersionInfo with wrong field ordering. The VersionNum occurs before \"=\" and \"version\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected v in version and not \\'")); + } + } - /** - * Test ID:
    ibm-not-wf-P24-ibm24n06.xml
    - * Test URI:
    not-wf/P24/ibm24n06.xml
    - * Comment:
    Tests VersionInfo with the wrong key word "Version".
    - * Sections:
    2.8
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P24_ibm24n06xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n06.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests VersionInfo with the wrong key word \"Version\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected v in version and not V" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P24-ibm24n05.xml
    + * Test URI:
    not-wf/P24/ibm24n05.xml
    + * Comment:
    Tests VersionInfo with wrong field ordering. The "=" occurs     after "version" and the VersionNum.
    + * Sections:
    2.8
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P24_ibm24n05xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n05.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests VersionInfo with wrong field ordering. The \"=\" occurs after \"version\" and the VersionNum."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected equals sign (=) after version and not \\'")); + } + } - /** - * Test ID:
    ibm-not-wf-P24-ibm24n07.xml
    - * Test URI:
    not-wf/P24/ibm24n07.xml
    - * Comment:
    Tests VersionInfo with the wrong key word "versioN".
    - * Sections:
    2.8
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P24_ibm24n07xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n07.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests VersionInfo with the wrong key word \"versioN\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected n in version and not N" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P24-ibm24n06.xml
    + * Test URI:
    not-wf/P24/ibm24n06.xml
    + * Comment:
    Tests VersionInfo with the wrong key word "Version".
    + * Sections:
    2.8
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P24_ibm24n06xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n06.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail("Tests VersionInfo with the wrong key word \"Version\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected v in version and not V")); + } + } - /** - * Test ID:
    ibm-not-wf-P24-ibm24n08.xml
    - * Test URI:
    not-wf/P24/ibm24n08.xml
    - * Comment:
    Tests VersionInfo with mismatched quotes around the VersionNum.      version = '1.0" is used as the VersionInfo.
    - * Sections:
    2.8
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P24_ibm24n08xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n08.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests VersionInfo with mismatched quotes around the VersionNum. version = '1.0\" is used as the VersionInfo." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "ibm-not-wf-P24-ibm24n07.xml
    + * Test URI:
    not-wf/P24/ibm24n07.xml
    + * Comment:
    Tests VersionInfo with the wrong key word "versioN".
    + * Sections:
    2.8
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P24_ibm24n07xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n07.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail("Tests VersionInfo with the wrong key word \"versioN\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected n in version and not N")); + } + } - /** - * Test ID:
    ibm-not-wf-P24-ibm24n09.xml
    - * Test URI:
    not-wf/P24/ibm24n09.xml
    - * Comment:
    Tests VersionInfo with mismatched quotes around the VersionNum.      The closing bracket for the VersionNum is missing.
    - * Sections:
    2.8
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P24_ibm24n09xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n09.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests VersionInfo with mismatched quotes around the VersionNum. The closing bracket for the VersionNum is missing." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "ibm-not-wf-P24-ibm24n08.xml
    + * Test URI:
    not-wf/P24/ibm24n08.xml
    + * Comment:
    Tests VersionInfo with mismatched quotes around the VersionNum.      version = '1.0" is used as the VersionInfo.
    + * Sections:
    2.8
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P24_ibm24n08xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n08.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests VersionInfo with mismatched quotes around the VersionNum. version = '1.0\" is used as the VersionInfo."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("ibm-not-wf-P24-ibm24n09.xml
    + * Test URI:
    not-wf/P24/ibm24n09.xml
    + * Comment:
    Tests VersionInfo with mismatched quotes around the VersionNum.      The closing bracket for the VersionNum is missing.
    + * Sections:
    2.8
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P24_ibm24n09xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n09.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests VersionInfo with mismatched quotes around the VersionNum. The closing bracket for the VersionNum is missing."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("ibm-not-wf-P02-ibm02n02.xml
    * Test URI:
    not-wf/P02/ibm02n02.xml
    @@ -78,19 +73,14 @@ public void testibm_not_wf_P02_ibm02n01xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n02xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n02.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n02xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n02.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x01" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x1 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x01"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x1 found in comment")); } } @@ -104,19 +94,14 @@ public void testibm_not_wf_P02_ibm02n02xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n03xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n03.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n03xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n03.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x02" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x2 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x02"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x2 found in comment")); } } @@ -130,19 +115,14 @@ public void testibm_not_wf_P02_ibm02n03xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n04xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n04.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n04xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n04.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x03" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x3 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x03"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x3 found in comment")); } } @@ -156,19 +136,14 @@ public void testibm_not_wf_P02_ibm02n04xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n05xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n05.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n05xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n05.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x04" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x4 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x04"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x4 found in comment")); } } @@ -182,19 +157,14 @@ public void testibm_not_wf_P02_ibm02n05xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n06xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n06.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n06xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n06.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x05" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x5 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x05"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x5 found in comment")); } } @@ -209,18 +179,16 @@ public void testibm_not_wf_P02_ibm02n06xml() */ @Test public void testibm_not_wf_P02_ibm02n07xml() throws IOException { - try(Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n07.xml"))) { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n07.xml"))) { parser.setInput(reader); - while (parser.nextToken() != XmlPullParser.END_DOCUMENT); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; fail("Tests a comment which contains an illegal Char: #x06"); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x6 found in comment" ) ); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x6 found in comment")); } } - /** * Test ID:
    ibm-not-wf-P02-ibm02n08.xml
    * Test URI:
    not-wf/P02/ibm02n08.xml
    @@ -231,19 +199,14 @@ public void testibm_not_wf_P02_ibm02n07xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n08xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n08.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n08xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n08.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x07" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x7 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x07"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x7 found in comment")); } } @@ -257,19 +220,14 @@ public void testibm_not_wf_P02_ibm02n08xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n09xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n09.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n09xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n09.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x08" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x8 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x08"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x8 found in comment")); } } @@ -283,19 +241,14 @@ public void testibm_not_wf_P02_ibm02n09xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n10xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n10.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n10xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n10.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x0B" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0xb found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x0B"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0xb found in comment")); } } @@ -309,19 +262,14 @@ public void testibm_not_wf_P02_ibm02n10xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n11xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n11.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n11xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n11.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x0C" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0xc found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x0C"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0xc found in comment")); } } @@ -335,19 +283,14 @@ public void testibm_not_wf_P02_ibm02n11xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n12xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n12.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n12xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n12.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x0E" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0xe found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x0E"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0xe found in comment")); } } @@ -361,19 +304,14 @@ public void testibm_not_wf_P02_ibm02n12xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n13xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n13.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n13xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n13.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x0F" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0xf found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x0F"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0xf found in comment")); } } @@ -387,19 +325,14 @@ public void testibm_not_wf_P02_ibm02n13xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n14xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n14.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n14xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n14.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x10" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x10 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x10"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x10 found in comment")); } } @@ -413,19 +346,14 @@ public void testibm_not_wf_P02_ibm02n14xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n15xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n15.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n15xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n15.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x11" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x11 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x11"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x11 found in comment")); } } @@ -439,19 +367,14 @@ public void testibm_not_wf_P02_ibm02n15xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n16xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n16.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n16xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n16.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x12" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x12 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x12"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x12 found in comment")); } } @@ -465,19 +388,14 @@ public void testibm_not_wf_P02_ibm02n16xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n17xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n17.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n17xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n17.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x13" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x13 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x13"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x13 found in comment")); } } @@ -491,19 +409,14 @@ public void testibm_not_wf_P02_ibm02n17xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n18xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n18.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n18xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n18.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x14" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x14 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x14"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x14 found in comment")); } } @@ -517,19 +430,14 @@ public void testibm_not_wf_P02_ibm02n18xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n19xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n19.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n19xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n19.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x15" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x15 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x15"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x15 found in comment")); } } @@ -543,19 +451,14 @@ public void testibm_not_wf_P02_ibm02n19xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n20xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n20.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n20xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n20.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x16" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x16 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x16"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x16 found in comment")); } } @@ -569,19 +472,14 @@ public void testibm_not_wf_P02_ibm02n20xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n21xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n21.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n21xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n21.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x17" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x17 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x17"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x17 found in comment")); } } @@ -595,19 +493,14 @@ public void testibm_not_wf_P02_ibm02n21xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n22xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n22.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n22xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n22.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x18" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x18 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x18"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x18 found in comment")); } } @@ -621,19 +514,14 @@ public void testibm_not_wf_P02_ibm02n22xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n23xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n23.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n23xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n23.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x19" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x19 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x19"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x19 found in comment")); } } @@ -647,19 +535,14 @@ public void testibm_not_wf_P02_ibm02n23xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n24xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n24.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n24xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n24.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x1A" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x1a found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x1A"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x1a found in comment")); } } @@ -673,19 +556,14 @@ public void testibm_not_wf_P02_ibm02n24xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n25xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n25.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n25xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n25.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x1B" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x1b found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x1B"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x1b found in comment")); } } @@ -699,19 +577,14 @@ public void testibm_not_wf_P02_ibm02n25xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n26xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n26.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n26xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n26.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x1C" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x1c found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x1C"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x1c found in comment")); } } @@ -725,19 +598,14 @@ public void testibm_not_wf_P02_ibm02n26xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n27xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n27.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n27xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n27.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x1D" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x1d found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x1D"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x1d found in comment")); } } @@ -751,19 +619,14 @@ public void testibm_not_wf_P02_ibm02n27xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n28xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n28.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n28xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n28.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x1E" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x1e found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x1E"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x1e found in comment")); } } @@ -777,19 +640,14 @@ public void testibm_not_wf_P02_ibm02n28xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n29xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n29.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n29xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n29.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #x1F" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0x1f found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #x1F"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0x1f found in comment")); } } @@ -804,22 +662,17 @@ public void testibm_not_wf_P02_ibm02n29xml() * * NOTE: This test file is malformed into the original test suite, so I skip it. */ - //@Test - public void testibm_not_wf_P02_ibm02n30xml() - throws IOException - { - try ( BufferedReader reader = - Files.newBufferedReader( Paths.get( testResourcesDir.getCanonicalPath(), "not-wf/P02/ibm02n30.xml" ), - Charset.forName( "ISO-8859-15" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + // @Test + public void testibm_not_wf_P02_ibm02n30xml() throws IOException { + try (BufferedReader reader = Files.newBufferedReader( + Paths.get(testResourcesDir.getCanonicalPath(), "not-wf/P02/ibm02n30.xml"), + Charset.forName("ISO-8859-15"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #xD800" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0xd800 found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #xD800"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0xd800 found in comment")); } } @@ -834,21 +687,16 @@ public void testibm_not_wf_P02_ibm02n30xml() * * NOTE: This test file is malformed into the original test suite, so I skip it. */ - //@Test - public void testibm_not_wf_P02_ibm02n31xml() - throws IOException - { - try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "not-wf/P02/ibm02n31.xml" ) ); - InputStreamReader reader = new InputStreamReader( is, "ISO-8859-15" ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + // @Test + public void testibm_not_wf_P02_ibm02n31xml() throws IOException { + try (FileInputStream is = new FileInputStream(new File(testResourcesDir, "not-wf/P02/ibm02n31.xml")); + InputStreamReader reader = new InputStreamReader(is, "ISO-8859-15")) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #xDFFF" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0xdfff found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #xDFFF"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0xdfff found in comment")); } } @@ -862,20 +710,15 @@ public void testibm_not_wf_P02_ibm02n31xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n32xml() - throws IOException - { - try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "not-wf/P02/ibm02n32.xml" ) ); - InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_8 ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n32xml() throws IOException { + try (FileInputStream is = new FileInputStream(new File(testResourcesDir, "not-wf/P02/ibm02n32.xml")); + InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #xFFFE" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0xfffe found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #xFFFE"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0xfffe found in comment")); } } @@ -889,21 +732,15 @@ public void testibm_not_wf_P02_ibm02n32xml() * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n33xml() - throws IOException - { - try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "not-wf/P02/ibm02n33.xml" ) ); - InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_8 ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testibm_not_wf_P02_ibm02n33xml() throws IOException { + try (FileInputStream is = new FileInputStream(new File(testResourcesDir, "not-wf/P02/ibm02n33.xml")); + InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "Tests a comment which contains an illegal Char: #xFFFF" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "Illegal character 0xffff found in comment" ) ); + fail("Tests a comment which contains an illegal Char: #xFFFF"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("Illegal character 0xffff found in comment")); } } - } diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java index 9a877456..f99e1ead 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java @@ -20,10 +20,10 @@ * @version $Id: $Id * @since 3.4.0 */ -public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test -{ +public +class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test { - final static File testResourcesDir = new File( "src/test/resources/", "xmlconf/ibm/" ); + static final File testResourcesDir = new File("src/test/resources/", "xmlconf/ibm/"); MXParser parser; @@ -31,246 +31,203 @@ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMX *

    setUp.

    */ @BeforeEach - public void setUp() - { + public void setUp() { parser = new MXParser(); } - /** - * Test ID:
    ibm-not-wf-P32-ibm32n01.xml
    - * Test URI:
    not-wf/P32/ibm32n01.xml
    - * Comment:
    Tests SDDecl with a required field missing. The leading white space     is missing with the SDDecl in the XMLDecl.
    - * Sections:
    2.9
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P32_ibm32n01xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n01.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests SDDecl with a required field missing. The leading white space is missing with the SDDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected a space after version and not s" ) ); - } - } - - /** - * Test ID:
    ibm-not-wf-P32-ibm32n02.xml
    - * Test URI:
    not-wf/P32/ibm32n02.xml
    - * Comment:
    Tests SDDecl with a required field missing. The "=" sign is missing     in the SDDecl in the XMLDecl.
    - * Sections:
    2.9
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P32_ibm32n02xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n02.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests SDDecl with a required field missing. The \"=\" sign is missing in the SDDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected equals sign (=) after standalone and not \"" ) ); - } - } - - /** - * Test ID:
    ibm-not-wf-P32-ibm32n03.xml
    - * Test URI:
    not-wf/P32/ibm32n03.xml
    - * Comment:
    Tests SDDecl with wrong key word. The word "Standalone" occurs in      the SDDecl in the XMLDecl.
    - * Sections:
    2.9
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P32_ibm32n03xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n03.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests SDDecl with wrong key word. The word \"Standalone\" occurs in the SDDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "unexpected character S" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P32-ibm32n01.xml
    + * Test URI:
    not-wf/P32/ibm32n01.xml
    + * Comment:
    Tests SDDecl with a required field missing. The leading white space     is missing with the SDDecl in the XMLDecl.
    + * Sections:
    2.9
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P32_ibm32n01xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n01.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests SDDecl with a required field missing. The leading white space is missing with the SDDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected a space after version and not s")); + } + } - /** - * Test ID:
    ibm-not-wf-P32-ibm32n04.xml
    - * Test URI:
    not-wf/P32/ibm32n04.xml
    - * Comment:
    Tests SDDecl with wrong key word. The word "Yes" occurs in the     SDDecl in the XMLDecl.
    - * Sections:
    2.9
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P32_ibm32n04xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n04.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests SDDecl with wrong key word. The word \"Yes\" occurs in the SDDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected 'yes' or 'no' after standalone and not Y" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P32-ibm32n02.xml
    + * Test URI:
    not-wf/P32/ibm32n02.xml
    + * Comment:
    Tests SDDecl with a required field missing. The "=" sign is missing     in the SDDecl in the XMLDecl.
    + * Sections:
    2.9
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P32_ibm32n02xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n02.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests SDDecl with a required field missing. The \"=\" sign is missing in the SDDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected equals sign (=) after standalone and not \"")); + } + } - /** - * Test ID:
    ibm-not-wf-P32-ibm32n05.xml
    - * Test URI:
    not-wf/P32/ibm32n05.xml
    - * Comment:
    Tests SDDecl with wrong key word. The word "YES" occurs in the     SDDecl in the XMLDecl.
    - * Sections:
    2.9
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P32_ibm32n05xml() - throws IOException - { + /** + * Test ID:
    ibm-not-wf-P32-ibm32n03.xml
    + * Test URI:
    not-wf/P32/ibm32n03.xml
    + * Comment:
    Tests SDDecl with wrong key word. The word "Standalone" occurs in      the SDDecl in the XMLDecl.
    + * Sections:
    2.9
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P32_ibm32n03xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n03.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail("Tests SDDecl with wrong key word. The word \"Standalone\" occurs in the SDDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("unexpected character S")); + } + } - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n05.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests SDDecl with wrong key word. The word \"YES\" occurs in the SDDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected 'yes' or 'no' after standalone and not Y" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P32-ibm32n04.xml
    + * Test URI:
    not-wf/P32/ibm32n04.xml
    + * Comment:
    Tests SDDecl with wrong key word. The word "Yes" occurs in the     SDDecl in the XMLDecl.
    + * Sections:
    2.9
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P32_ibm32n04xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n04.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail("Tests SDDecl with wrong key word. The word \"Yes\" occurs in the SDDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected 'yes' or 'no' after standalone and not Y")); + } + } - /** - * Test ID:
    ibm-not-wf-P32-ibm32n06.xml
    - * Test URI:
    not-wf/P32/ibm32n06.xml
    - * Comment:
    Tests SDDecl with wrong key word. The word "No" occurs in the     SDDecl in the XMLDecl.
    - * Sections:
    2.9
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P32_ibm32n06xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n06.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests SDDecl with wrong key word. The word \"No\" occurs in the SDDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected 'yes' or 'no' after standalone and not N" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P32-ibm32n05.xml
    + * Test URI:
    not-wf/P32/ibm32n05.xml
    + * Comment:
    Tests SDDecl with wrong key word. The word "YES" occurs in the     SDDecl in the XMLDecl.
    + * Sections:
    2.9
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P32_ibm32n05xml() throws IOException { + + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n05.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail("Tests SDDecl with wrong key word. The word \"YES\" occurs in the SDDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected 'yes' or 'no' after standalone and not Y")); + } + } - /** - * Test ID:
    ibm-not-wf-P32-ibm32n07.xml
    - * Test URI:
    not-wf/P32/ibm32n07.xml
    - * Comment:
    Tests SDDecl with wrong key word. The word "NO" occurs in the     SDDecl in the XMLDecl.
    - * Sections:
    2.9
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P32_ibm32n07xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n07.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests SDDecl with wrong key word. The word \"NO\" occurs in the SDDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected 'yes' or 'no' after standalone and not N" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P32-ibm32n06.xml
    + * Test URI:
    not-wf/P32/ibm32n06.xml
    + * Comment:
    Tests SDDecl with wrong key word. The word "No" occurs in the     SDDecl in the XMLDecl.
    + * Sections:
    2.9
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P32_ibm32n06xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n06.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail("Tests SDDecl with wrong key word. The word \"No\" occurs in the SDDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected 'yes' or 'no' after standalone and not N")); + } + } - /** - * Test ID:
    ibm-not-wf-P32-ibm32n08.xml
    - * Test URI:
    not-wf/P32/ibm32n08.xml
    - * Comment:
    Tests SDDecl with wrong field ordering. The "=" sign occurs      after the key word "yes" in the SDDecl in the XMLDecl.
    - * Sections:
    2.9
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P32_ibm32n08xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n08.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests SDDecl with wrong field ordering. The \"=\" sign occurs after the key word \"yes\" in the SDDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected equals sign (=) after standalone and not \"" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P32-ibm32n07.xml
    + * Test URI:
    not-wf/P32/ibm32n07.xml
    + * Comment:
    Tests SDDecl with wrong key word. The word "NO" occurs in the     SDDecl in the XMLDecl.
    + * Sections:
    2.9
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P32_ibm32n07xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n07.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail("Tests SDDecl with wrong key word. The word \"NO\" occurs in the SDDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected 'yes' or 'no' after standalone and not N")); + } + } - /** - * Test ID:
    ibm-not-wf-P32-ibm32n09.xml
    - * Test URI:
    not-wf/P32/ibm32n09.xml
    - * Comment:
    This is test violates WFC: Entity Declared in P68.     The standalone document declaration has the value yes, BUT there is an      external markup declaration of an entity (other than amp, lt, gt, apos,     quot), and references to this entity appear in the document.
    - * Sections:
    2.9
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - * - * NOTE: This test is SKIPPED as MXParser does not support parsing inside DOCTYPEDECL. - */ - // @Test - public void testibm_not_wf_P32_ibm32n09xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n09.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "This is test violates WFC: Entity Declared in P68. The standalone document declaration has the value yes, BUT there is an external markup declaration of an entity (other than amp, lt, gt, apos, quot), and references to this entity appear in the document." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected ?> as last part of ibm-not-wf-P32-ibm32n08.xml
  • + * Test URI:
    not-wf/P32/ibm32n08.xml
    + * Comment:
    Tests SDDecl with wrong field ordering. The "=" sign occurs      after the key word "yes" in the SDDecl in the XMLDecl.
    + * Sections:
    2.9
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P32_ibm32n08xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n08.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests SDDecl with wrong field ordering. The \"=\" sign occurs after the key word \"yes\" in the SDDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected equals sign (=) after standalone and not \"")); + } + } + /** + * Test ID:
    ibm-not-wf-P32-ibm32n09.xml
    + * Test URI:
    not-wf/P32/ibm32n09.xml
    + * Comment:
    This is test violates WFC: Entity Declared in P68.     The standalone document declaration has the value yes, BUT there is an      external markup declaration of an entity (other than amp, lt, gt, apos,     quot), and references to this entity appear in the document.
    + * Sections:
    2.9
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + * + * NOTE: This test is SKIPPED as MXParser does not support parsing inside DOCTYPEDECL. + */ + // @Test + public void testibm_not_wf_P32_ibm32n09xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n09.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "This is test violates WFC: Entity Declared in P68. The standalone document declaration has the value yes, BUT there is an external markup declaration of an entity (other than amp, lt, gt, apos, quot), and references to this entity appear in the document."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected ?> as last part of setUp.

    */ @BeforeEach - public void setUp() - { + public void setUp() { parser = new MXParser(); } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n01.xml
    - * Test URI:
    not-wf/P66/ibm66n01.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#002f" is      used as the referred character in the CharRef in the EntityDecl in the DTD.
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n01xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n01.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#002f\" is used as the referred character in the CharRef in the EntityDecl in the DTD." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with decimal value) may not contain f" ) ); - } - } - - /** - * Test ID:
    ibm-not-wf-P66-ibm66n02.xml
    - * Test URI:
    not-wf/P66/ibm66n02.xml
    - * Comment:
    Tests CharRef with the semicolon character missing. The semicolon      character is missing at the end of the CharRef in the attribute value in     the STag of element "root".
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n02xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n02.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with the semicolon character missing. The semicolon character is missing at the end of the CharRef in the attribute value in the STag of element \"root\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain \"" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n01.xml
    + * Test URI:
    not-wf/P66/ibm66n01.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#002f" is      used as the referred character in the CharRef in the EntityDecl in the DTD.
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n01xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n01.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#002f\" is used as the referred character in the CharRef in the EntityDecl in the DTD."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with decimal value) may not contain f")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n03.xml
    - * Test URI:
    not-wf/P66/ibm66n03.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "49" is      used as the referred character in the CharRef in the EntityDecl in the DTD.
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n03xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n03.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"49\" is used as the referred character in the CharRef in the EntityDecl in the DTD." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "entity reference names can not start with character '4'" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n02.xml
    + * Test URI:
    not-wf/P66/ibm66n02.xml
    + * Comment:
    Tests CharRef with the semicolon character missing. The semicolon      character is missing at the end of the CharRef in the attribute value in     the STag of element "root".
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n02xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n02.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with the semicolon character missing. The semicolon character is missing at the end of the CharRef in the attribute value in the STag of element \"root\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value) may not contain \"")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n04.xml
    - * Test URI:
    not-wf/P66/ibm66n04.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#5~0" is      used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n04xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n04.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#5~0\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with decimal value) may not contain ~" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n03.xml
    + * Test URI:
    not-wf/P66/ibm66n03.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "49" is      used as the referred character in the CharRef in the EntityDecl in the DTD.
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n03xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n03.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"49\" is used as the referred character in the CharRef in the EntityDecl in the DTD."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("entity reference names can not start with character '4'")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n05.xml
    - * Test URI:
    not-wf/P66/ibm66n05.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#x002g" is     used as the referred character in the CharRef in the EntityDecl in the DTD.
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - * @throws java.io.FileNotFoundException if any. - * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. - */ - @Test - public void testibm_not_wf_P66_ibm66n05xml() - throws FileNotFoundException, IOException, XmlPullParserException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n05.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#x002g\" is used as the referred character in the CharRef in the EntityDecl in the DTD." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain g" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n04.xml
    + * Test URI:
    not-wf/P66/ibm66n04.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#5~0" is      used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n04xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n04.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#5~0\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with decimal value) may not contain ~")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n06.xml
    - * Test URI:
    not-wf/P66/ibm66n06.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#x006G" is     used as the referred character in the attribute value in the EmptyElemTag      of the element "root".
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n06xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n06.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#x006G\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain G" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n05.xml
    + * Test URI:
    not-wf/P66/ibm66n05.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#x002g" is     used as the referred character in the CharRef in the EntityDecl in the DTD.
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + * @throws java.io.FileNotFoundException if any. + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + */ + @Test + public void testibm_not_wf_P66_ibm66n05xml() throws FileNotFoundException, IOException, XmlPullParserException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n05.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#x002g\" is used as the referred character in the CharRef in the EntityDecl in the DTD."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value) may not contain g")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n07.xml
    - * Test URI:
    not-wf/P66/ibm66n07.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#0=2f" is      used as the referred character in the CharRef in the EntityDecl in the DTD.
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n07xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n07.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#0=2f\" is used as the referred character in the CharRef in the EntityDecl in the DTD." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain =" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n06.xml
    + * Test URI:
    not-wf/P66/ibm66n06.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#x006G" is     used as the referred character in the attribute value in the EmptyElemTag      of the element "root".
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n06xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n06.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#x006G\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value) may not contain G")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n08.xml
    - * Test URI:
    not-wf/P66/ibm66n08.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#56.0" is      used as the referred character in the attribute value in the EmptyElemTag      of the element "root".
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n08xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n08.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#56.0\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with decimal value) may not contain ." ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n07.xml
    + * Test URI:
    not-wf/P66/ibm66n07.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#0=2f" is      used as the referred character in the CharRef in the EntityDecl in the DTD.
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n07xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n07.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#0=2f\" is used as the referred character in the CharRef in the EntityDecl in the DTD."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value) may not contain =")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n09.xml
    - * Test URI:
    not-wf/P66/ibm66n09.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#x00/2f"      is used as the referred character in the CharRef in the EntityDecl in the      DTD.
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n09xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n09.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#x00/2f\" is used as the referred character in the CharRef in the EntityDecl in the DTD." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain /" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n08.xml
    + * Test URI:
    not-wf/P66/ibm66n08.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#56.0" is      used as the referred character in the attribute value in the EmptyElemTag      of the element "root".
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n08xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n08.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#56.0\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with decimal value) may not contain .")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n10.xml
    - * Test URI:
    not-wf/P66/ibm66n10.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#51)" is      used as the referred character in the attribute value in the EmptyElemTag      of the element "root".
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n10xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n10.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#51)\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with decimal value) may not contain )" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n09.xml
    + * Test URI:
    not-wf/P66/ibm66n09.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#x00/2f"      is used as the referred character in the CharRef in the EntityDecl in the      DTD.
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n09xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n09.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#x00/2f\" is used as the referred character in the CharRef in the EntityDecl in the DTD."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value) may not contain /")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n11.xml
    - * Test URI:
    not-wf/P66/ibm66n11.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#00 2f"     is used as the referred character in the CharRef in the EntityDecl in the      DTD.
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n11xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n11.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#00 2f\" is used as the referred character in the CharRef in the EntityDecl in the DTD." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain " ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n10.xml
    + * Test URI:
    not-wf/P66/ibm66n10.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#51)" is      used as the referred character in the attribute value in the EmptyElemTag      of the element "root".
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n10xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n10.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#51)\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with decimal value) may not contain )")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n12.xml
    - * Test URI:
    not-wf/P66/ibm66n12.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#x0000"      is used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n12xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n12.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#x0000\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value 0000) is invalid" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n11.xml
    + * Test URI:
    not-wf/P66/ibm66n11.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#00 2f"     is used as the referred character in the CharRef in the EntityDecl in the      DTD.
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n11xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n11.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#00 2f\" is used as the referred character in the CharRef in the EntityDecl in the DTD."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value) may not contain ")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n13.xml
    - * Test URI:
    not-wf/P66/ibm66n13.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#x001f"      is used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n13xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n13.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#x001f\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value 001f) is invalid" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n12.xml
    + * Test URI:
    not-wf/P66/ibm66n12.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#x0000"      is used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n12xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n12.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#x0000\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value 0000) is invalid")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n14.xml
    - * Test URI:
    not-wf/P66/ibm66n14.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#xfffe"      is used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n14xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n14.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#xfffe\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value fffe) is invalid" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n13.xml
    + * Test URI:
    not-wf/P66/ibm66n13.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#x001f"      is used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n13xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n13.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#x001f\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value 001f) is invalid")); + } + } - /** - * Test ID:
    ibm-not-wf-P66-ibm66n15.xml
    - * Test URI:
    not-wf/P66/ibm66n15.xml
    - * Comment:
    Tests CharRef with an illegal character referred to. The "#xffff"      is used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    - * Sections:
    4.1
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P66_ibm66n15xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n15.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests CharRef with an illegal character referred to. The \"#xffff\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value ffff) is invalid" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n14.xml
    + * Test URI:
    not-wf/P66/ibm66n14.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#xfffe"      is used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n14xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n14.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#xfffe\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value fffe) is invalid")); + } + } + /** + * Test ID:
    ibm-not-wf-P66-ibm66n15.xml
    + * Test URI:
    not-wf/P66/ibm66n15.xml
    + * Comment:
    Tests CharRef with an illegal character referred to. The "#xffff"      is used as the referred character in the attribute value in the EmptyElemTag     of the element "root".
    + * Sections:
    4.1
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P66_ibm66n15xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n15.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests CharRef with an illegal character referred to. The \"#xffff\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value ffff) is invalid")); + } + } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java index 7d7fc20a..9581bedc 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java @@ -20,10 +20,10 @@ * @version $Id: $Id * @since 3.4.0 */ -public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test -{ +public +class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test { - final static File testResourcesDir = new File( "src/test/resources/", "xmlconf/ibm/" ); + static final File testResourcesDir = new File("src/test/resources/", "xmlconf/ibm/"); MXParser parser; @@ -31,165 +31,140 @@ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMX *

    setUp.

    */ @BeforeEach - public void setUp() - { + public void setUp() { parser = new MXParser(); } - /** - * Test ID:
    ibm-not-wf-P80-ibm80n01.xml
    - * Test URI:
    not-wf/P80/ibm80n01.xml
    - * Comment:
    Tests EncodingDecl with a required field missing. The leading white      space is missing in the EncodingDecl in the XMLDecl.
    - * Sections:
    4.3.3
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P80_ibm80n01xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n01.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests EncodingDecl with a required field missing. The leading white space is missing in the EncodingDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected a space after version and not e" ) ); - } - } - - /** - * Test ID:
    ibm-not-wf-P80-ibm80n02.xml
    - * Test URI:
    not-wf/P80/ibm80n02.xml
    - * Comment:
    Tests EncodingDecl with a required field missing. The "=" sign is      missing in the EncodingDecl in the XMLDecl.
    - * Sections:
    4.3.3
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P80_ibm80n02xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n02.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests EncodingDecl with a required field missing. The \"=\" sign is missing in the EncodingDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected equals sign (=) after encoding and not \"" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P80-ibm80n01.xml
    + * Test URI:
    not-wf/P80/ibm80n01.xml
    + * Comment:
    Tests EncodingDecl with a required field missing. The leading white      space is missing in the EncodingDecl in the XMLDecl.
    + * Sections:
    4.3.3
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P80_ibm80n01xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n01.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests EncodingDecl with a required field missing. The leading white space is missing in the EncodingDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected a space after version and not e")); + } + } - /** - * Test ID:
    ibm-not-wf-P80-ibm80n03.xml
    - * Test URI:
    not-wf/P80/ibm80n03.xml
    - * Comment:
    Tests EncodingDecl with a required field missing. The double quoted      EncName are missing in the EncodingDecl in the XMLDecl.
    - * Sections:
    4.3.3
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P80_ibm80n03xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n03.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests EncodingDecl with a required field missing. The double quoted EncName are missing in the EncodingDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "expected apostrophe (') or quotation mark (\") after encoding and not ?" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P80-ibm80n02.xml
    + * Test URI:
    not-wf/P80/ibm80n02.xml
    + * Comment:
    Tests EncodingDecl with a required field missing. The "=" sign is      missing in the EncodingDecl in the XMLDecl.
    + * Sections:
    4.3.3
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P80_ibm80n02xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n02.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests EncodingDecl with a required field missing. The \"=\" sign is missing in the EncodingDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("expected equals sign (=) after encoding and not \"")); + } + } - /** - * Test ID:
    ibm-not-wf-P80-ibm80n04.xml
    - * Test URI:
    not-wf/P80/ibm80n04.xml
    - * Comment:
    Tests EncodingDecl with wrong field ordering. The string "encoding="    occurs after the double quoted EncName in the EncodingDecl in the XMLDecl.
    - * Sections:
    4.3.3
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P80_ibm80n04xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n04.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests EncodingDecl with wrong field ordering. The string \"encoding=\" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "unexpected character \"" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P80-ibm80n03.xml
    + * Test URI:
    not-wf/P80/ibm80n03.xml
    + * Comment:
    Tests EncodingDecl with a required field missing. The double quoted      EncName are missing in the EncodingDecl in the XMLDecl.
    + * Sections:
    4.3.3
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P80_ibm80n03xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n03.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests EncodingDecl with a required field missing. The double quoted EncName are missing in the EncodingDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue( + e.getMessage().contains("expected apostrophe (') or quotation mark (\") after encoding and not ?")); + } + } - /** - * Test ID:
    ibm-not-wf-P80-ibm80n05.xml
    - * Test URI:
    not-wf/P80/ibm80n05.xml
    - * Comment:
    Tests EncodingDecl with wrong field ordering. The "encoding" occurs     after the double quoted EncName in the EncodingDecl in the XMLDecl.
    - * Sections:
    4.3.3
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P80_ibm80n05xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n05.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests EncodingDecl with wrong field ordering. The \"encoding\" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "unexpected character \"" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P80-ibm80n04.xml
    + * Test URI:
    not-wf/P80/ibm80n04.xml
    + * Comment:
    Tests EncodingDecl with wrong field ordering. The string "encoding="    occurs after the double quoted EncName in the EncodingDecl in the XMLDecl.
    + * Sections:
    4.3.3
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P80_ibm80n04xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n04.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests EncodingDecl with wrong field ordering. The string \"encoding=\" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("unexpected character \"")); + } + } - /** - * Test ID:
    ibm-not-wf-P80-ibm80n06.xml
    - * Test URI:
    not-wf/P80/ibm80n06.xml
    - * Comment:
    Tests EncodingDecl with wrong key word. The string "Encoding" is      used as the key word in the EncodingDecl in the XMLDecl.
    - * Sections:
    4.3.3
    - * Version: - * - * @throws java.io.IOException if there is an I/O error - */ - @Test - public void testibm_not_wf_P80_ibm80n06xml() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n06.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) - ; - fail( "Tests EncodingDecl with wrong key word. The string \"Encoding\" is used as the key word in the EncodingDecl in the XMLDecl." ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "unexpected character E" ) ); - } - } + /** + * Test ID:
    ibm-not-wf-P80-ibm80n05.xml
    + * Test URI:
    not-wf/P80/ibm80n05.xml
    + * Comment:
    Tests EncodingDecl with wrong field ordering. The "encoding" occurs     after the double quoted EncName in the EncodingDecl in the XMLDecl.
    + * Sections:
    4.3.3
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P80_ibm80n05xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n05.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests EncodingDecl with wrong field ordering. The \"encoding\" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("unexpected character \"")); + } + } + /** + * Test ID:
    ibm-not-wf-P80-ibm80n06.xml
    + * Test URI:
    not-wf/P80/ibm80n06.xml
    + * Comment:
    Tests EncodingDecl with wrong key word. The string "Encoding" is      used as the key word in the EncodingDecl in the XMLDecl.
    + * Sections:
    4.3.3
    + * Version: + * + * @throws java.io.IOException if there is an I/O error + */ + @Test + public void testibm_not_wf_P80_ibm80n06xml() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n06.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) + ; + fail( + "Tests EncodingDecl with wrong key word. The string \"Encoding\" is used as the key word in the EncodingDecl in the XMLDecl."); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("unexpected character E")); + } + } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java index c4d1a74f..ef6e30a2 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java @@ -51,21 +51,19 @@ public class MXParserPerfTest { @State(Scope.Benchmark) - static public class AdditionState { + public static class AdditionState { byte[] data; @Setup(Level.Iteration) public void setUp() throws IOException, XmlPullParserException { - try (InputStream buf = getClass().getResourceAsStream( "/xml/pom.xml" ) ) - { - data = new byte[ buf.available() ]; - buf.read( data, 0, data.length ); + try (InputStream buf = getClass().getResourceAsStream("/xml/pom.xml")) { + data = new byte[buf.available()]; + buf.read(data, 0, data.length); } } } - /** *

    benchmarkBuild.

    * @@ -75,9 +73,8 @@ public void setUp() throws IOException, XmlPullParserException { * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Benchmark - public Xpp3Dom benchmarkBuild( AdditionState state ) throws IOException, XmlPullParserException - { - return Xpp3DomBuilder.build( new ByteArrayInputStream( state.data ), null ); + public Xpp3Dom benchmarkBuild(AdditionState state) throws IOException, XmlPullParserException { + return Xpp3DomBuilder.build(new ByteArrayInputStream(state.data), null); } /** @@ -86,15 +83,13 @@ public Xpp3Dom benchmarkBuild( AdditionState state ) throws IOException, XmlPull * @param args a {@link java.lang.String} object. * @throws org.openjdk.jmh.runner.RunnerException if any. */ - public static void main( String... args ) - throws RunnerException - { + public static void main(String... args) throws RunnerException { Options opts = new OptionsBuilder() - .measurementIterations( 3 ) - .measurementTime( TimeValue.milliseconds( 3000 ) ) - .forks( 1 ) - .include( "org.codehaus.plexus.util.xml.pull.MXParserPerfTest" ) + .measurementIterations(3) + .measurementTime(TimeValue.milliseconds(3000)) + .forks(1) + .include("org.codehaus.plexus.util.xml.pull.MXParserPerfTest") .build(); - new Runner( opts ).run(); + new Runner(opts).run(); } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 51df710b..8c3fd284 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -40,32 +40,29 @@ * @version $Id: $Id * @since 3.4.0 */ -public class MXParserTest -{ +public class MXParserTest { /** *

    testHexadecimalEntities.

    * * @throws java.lang.Exception if any. */ @Test - public void testHexadecimalEntities() - throws Exception - { + public void testHexadecimalEntities() throws Exception { MXParser parser = new MXParser(); - parser.defineEntityReplacementText( "test", "replacement" ); + parser.defineEntityReplacementText("test", "replacement"); String input = "A"; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - assertEquals( XmlPullParser.START_TAG, parser.next() ); + assertEquals(XmlPullParser.START_TAG, parser.next()); - assertEquals( XmlPullParser.TEXT, parser.next() ); + assertEquals(XmlPullParser.TEXT, parser.next()); - assertEquals( "A", parser.getText() ); + assertEquals("A", parser.getText()); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + assertEquals(XmlPullParser.END_TAG, parser.next()); } /** @@ -74,24 +71,22 @@ public void testHexadecimalEntities() * @throws java.lang.Exception if any. */ @Test - public void testDecimalEntities() - throws Exception - { + public void testDecimalEntities() throws Exception { MXParser parser = new MXParser(); - parser.defineEntityReplacementText( "test", "replacement" ); + parser.defineEntityReplacementText("test", "replacement"); String input = "A"; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - assertEquals( XmlPullParser.START_TAG, parser.next() ); + assertEquals(XmlPullParser.START_TAG, parser.next()); - assertEquals( XmlPullParser.TEXT, parser.next() ); + assertEquals(XmlPullParser.TEXT, parser.next()); - assertEquals( "A", parser.getText() ); + assertEquals("A", parser.getText()); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + assertEquals(XmlPullParser.END_TAG, parser.next()); } /** @@ -100,24 +95,22 @@ public void testDecimalEntities() * @throws java.lang.Exception if any. */ @Test - public void testPredefinedEntities() - throws Exception - { + public void testPredefinedEntities() throws Exception { MXParser parser = new MXParser(); - parser.defineEntityReplacementText( "test", "replacement" ); + parser.defineEntityReplacementText("test", "replacement"); String input = "<>&'""; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - assertEquals( XmlPullParser.START_TAG, parser.next() ); + assertEquals(XmlPullParser.START_TAG, parser.next()); - assertEquals( XmlPullParser.TEXT, parser.next() ); + assertEquals(XmlPullParser.TEXT, parser.next()); - assertEquals( "<>&'\"", parser.getText() ); + assertEquals("<>&'\"", parser.getText()); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + assertEquals(XmlPullParser.END_TAG, parser.next()); } /** @@ -127,19 +120,17 @@ public void testPredefinedEntities() * @throws java.io.IOException if any. */ @Test - public void testEntityReplacementMap() - throws XmlPullParserException, IOException - { - EntityReplacementMap erm = new EntityReplacementMap( new String[][] { { "abc", "CDE" }, { "EFG", "HIJ" } } ); - MXParser parser = new MXParser( erm ); + public void testEntityReplacementMap() throws XmlPullParserException, IOException { + EntityReplacementMap erm = new EntityReplacementMap(new String[][] {{"abc", "CDE"}, {"EFG", "HIJ"}}); + MXParser parser = new MXParser(erm); String input = "&EFG;"; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - assertEquals( XmlPullParser.START_TAG, parser.next() ); - assertEquals( XmlPullParser.TEXT, parser.next() ); - assertEquals( "HIJ", parser.getText() ); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + assertEquals(XmlPullParser.START_TAG, parser.next()); + assertEquals(XmlPullParser.TEXT, parser.next()); + assertEquals("HIJ", parser.getText()); + assertEquals(XmlPullParser.END_TAG, parser.next()); } /** @@ -148,28 +139,26 @@ public void testEntityReplacementMap() * @throws java.lang.Exception if any. */ @Test - public void testCustomEntities() - throws Exception - { + public void testCustomEntities() throws Exception { MXParser parser = new MXParser(); String input = "&myentity;"; - parser.setInput( new StringReader( input ) ); - parser.defineEntityReplacementText( "myentity", "replacement" ); - assertEquals( XmlPullParser.START_TAG, parser.next() ); - assertEquals( XmlPullParser.TEXT, parser.next() ); - assertEquals( "replacement", parser.getText() ); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + parser.setInput(new StringReader(input)); + parser.defineEntityReplacementText("myentity", "replacement"); + assertEquals(XmlPullParser.START_TAG, parser.next()); + assertEquals(XmlPullParser.TEXT, parser.next()); + assertEquals("replacement", parser.getText()); + assertEquals(XmlPullParser.END_TAG, parser.next()); parser = new MXParser(); input = "&myCustom;"; - parser.setInput( new StringReader( input ) ); - parser.defineEntityReplacementText( "fo", "A" ); - parser.defineEntityReplacementText( "myCustom", "&fo;" ); - assertEquals( XmlPullParser.START_TAG, parser.next() ); - assertEquals( XmlPullParser.TEXT, parser.next() ); - assertEquals( "A", parser.getText() ); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + parser.setInput(new StringReader(input)); + parser.defineEntityReplacementText("fo", "A"); + parser.defineEntityReplacementText("myCustom", "&fo;"); + assertEquals(XmlPullParser.START_TAG, parser.next()); + assertEquals(XmlPullParser.TEXT, parser.next()); + assertEquals("A", parser.getText()); + assertEquals(XmlPullParser.END_TAG, parser.next()); } /** @@ -178,26 +167,24 @@ public void testCustomEntities() * @throws java.lang.Exception if any. */ @Test - public void testUnicodeEntities() - throws Exception - { + public void testUnicodeEntities() throws Exception { MXParser parser = new MXParser(); String input = "𝟭"; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "\uD835\uDFED", parser.getText() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("\uD835\uDFED", parser.getText()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); parser = new MXParser(); input = "ř"; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "\u0159", parser.getText() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("\u0159", parser.getText()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); } /** @@ -206,22 +193,17 @@ public void testUnicodeEntities() * @throws java.lang.Exception if any. */ @Test - public void testInvalidCharacterReferenceHexa() - throws Exception - { + public void testInvalidCharacterReferenceHexa() throws Exception { MXParser parser = new MXParser(); String input = ""; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - try - { - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - fail( "Should fail since � is an illegal character reference" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value 110000) is invalid" ) ); + try { + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + fail("Should fail since � is an illegal character reference"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value 110000) is invalid")); } } @@ -231,45 +213,41 @@ public void testInvalidCharacterReferenceHexa() * @throws java.lang.Exception if any. */ @Test - public void testValidCharacterReferenceHexa() - throws Exception - { + public void testValidCharacterReferenceHexa() throws Exception { MXParser parser = new MXParser(); - String input = " Ȁ퟿ᄁ�𐀀􏿽􏿿"; - parser.setInput( new StringReader( input ) ); - - try - { - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0x9, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0xA, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0xD, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0x20, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0x200, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0xD7FF, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0xE000, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0xFFA2, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0xFFFD, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0x10000, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0x10FFFD, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 0x10FFFF, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - } - catch ( XmlPullParserException e ) - { - fail( "Should success since the input represents all legal character references" ); + String input = + " Ȁ퟿ᄁ�𐀀􏿽􏿿"; + parser.setInput(new StringReader(input)); + + try { + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x9, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xA, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xD, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x20, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x200, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xD7FF, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xE000, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xFFA2, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xFFFD, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x10000, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x10FFFD, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x10FFFF, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + } catch (XmlPullParserException e) { + fail("Should success since the input represents all legal character references"); } } @@ -279,22 +257,17 @@ public void testValidCharacterReferenceHexa() * @throws java.lang.Exception if any. */ @Test - public void testInvalidCharacterReferenceDecimal() - throws Exception - { + public void testInvalidCharacterReferenceDecimal() throws Exception { MXParser parser = new MXParser(); String input = ""; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - try - { - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - fail( "Should fail since � is an illegal character reference" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with decimal value 1114112) is invalid" ) ); + try { + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + fail("Should fail since � is an illegal character reference"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with decimal value 1114112) is invalid")); } } @@ -304,46 +277,41 @@ public void testInvalidCharacterReferenceDecimal() * @throws java.lang.Exception if any. */ @Test - public void testValidCharacterReferenceDecimal() - throws Exception - { + public void testValidCharacterReferenceDecimal() throws Exception { MXParser parser = new MXParser(); String input = - " Ȁ퟿ᄁ�𐀀􏿽􏿿"; - parser.setInput( new StringReader( input ) ); - - try - { - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 9, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 10, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 13, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 32, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 512, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 55295, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 57344, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 65442, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 65533, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 65536, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 1114109, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( 1114111, parser.getText().codePointAt( 0 ) ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - } - catch ( XmlPullParserException e ) - { - fail( "Should success since the input represents all legal character references" ); + " Ȁ퟿ᄁ�𐀀􏿽􏿿"; + parser.setInput(new StringReader(input)); + + try { + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(9, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(10, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(13, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(32, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(512, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(55295, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(57344, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(65442, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(65533, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(65536, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(1114109, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(1114111, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + } catch (XmlPullParserException e) { + fail("Should success since the input represents all legal character references"); } } @@ -353,47 +321,44 @@ public void testValidCharacterReferenceDecimal() * @throws java.lang.Exception if any. */ @Test - public void testParserPosition() - throws Exception - { - String input = " \n \tnnn\n"; + public void testParserPosition() throws Exception { + String input = + " \n \tnnn\n"; MXParser parser = new MXParser(); - parser.setInput( new StringReader( input ) ); - - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertPosition( 1, 39, parser ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertPosition( 1, 49, parser ); - assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); - assertPosition( 2, 3, parser ); // end when next token starts - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertPosition( 2, 12, parser ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertPosition( 2, 18, parser ); - assertEquals( XmlPullParser.TEXT, parser.nextToken() ); - assertPosition( 2, 23, parser ); // end when next token starts - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertPosition( 2, 29, parser ); - assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); - assertPosition( 3, 2, parser ); // end when next token starts - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertPosition( 4, 6, parser ); + parser.setInput(new StringReader(input)); + + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertPosition(1, 39, parser); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertPosition(1, 49, parser); + assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken()); + assertPosition(2, 3, parser); // end when next token starts + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertPosition(2, 12, parser); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertPosition(2, 18, parser); + assertEquals(XmlPullParser.TEXT, parser.nextToken()); + assertPosition(2, 23, parser); // end when next token starts + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertPosition(2, 29, parser); + assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken()); + assertPosition(3, 2, parser); // end when next token starts + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertPosition(4, 6, parser); } @Test - public void testProcessingInstruction() - throws Exception - { + public void testProcessingInstruction() throws Exception { String input = "nnn"; MXParser parser = new MXParser(); - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.TEXT, parser.nextToken() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.TEXT, parser.nextToken()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); } /** @@ -402,28 +367,26 @@ public void testProcessingInstruction() * @throws java.lang.Exception if any. */ @Test - public void testProcessingInstructionsContainingXml() - throws Exception - { + public void testProcessingInstructionsContainingXml() throws Exception { StringBuffer sb = new StringBuffer(); - sb.append( "" ); - sb.append( "\n" ); - sb.append( " \n" ); - sb.append( " \n" ); - sb.append( " ?>\n" ); - sb.append( "" ); + sb.append(""); + sb.append("\n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" ?>\n"); + sb.append(""); MXParser parser = new MXParser(); - parser.setInput( new StringReader( sb.toString() ) ); - - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.TEXT, parser.nextToken() ); // whitespace - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( XmlPullParser.TEXT, parser.nextToken() ); // whitespace - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + parser.setInput(new StringReader(sb.toString())); + + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.TEXT, parser.nextToken()); // whitespace + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.TEXT, parser.nextToken()); // whitespace + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); } /** @@ -432,56 +395,50 @@ public void testProcessingInstructionsContainingXml() * @throws java.lang.Exception if any. */ @Test - public void testMalformedProcessingInstructionsContainingXmlNoClosingQuestionMark() - throws Exception - { + public void testMalformedProcessingInstructionsContainingXmlNoClosingQuestionMark() throws Exception { StringBuffer sb = new StringBuffer(); - sb.append( "\n" ); - sb.append( "\n" ); - sb.append( "\n" ); - sb.append( " >\n" ); + sb.append("\n"); + sb.append("\n"); + sb.append("\n"); + sb.append(" >\n"); MXParser parser = new MXParser(); - parser.setInput( new StringReader( sb.toString() ) ); - - try - { - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - - fail( "Should fail since it has invalid PI" ); - } - catch ( XmlPullParserException ex ) - { - assertTrue( ex.getMessage().contains( "processing instruction started on line 3 and column 1 was not closed" ) ); + parser.setInput(new StringReader(sb.toString())); + + try { + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken()); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + + fail("Should fail since it has invalid PI"); + } catch (XmlPullParserException ex) { + assertTrue( + ex.getMessage().contains("processing instruction started on line 3 and column 1 was not closed")); } } @Test - public void testSubsequentProcessingInstructionShort() - throws Exception - { + public void testSubsequentProcessingInstructionShort() throws Exception { StringBuffer sb = new StringBuffer(); - sb.append( "" ); - sb.append( "" ); - sb.append( "" ); - sb.append( "" ); - sb.append( "" ); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); MXParser parser = new MXParser(); - parser.setInput( new StringReader( sb.toString() ) ); + parser.setInput(new StringReader(sb.toString())); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); } /** @@ -490,46 +447,42 @@ public void testSubsequentProcessingInstructionShort() * @throws java.lang.Exception if any. */ @Test - public void testSubsequentProcessingInstructionMoreThan8k() - throws Exception - { + public void testSubsequentProcessingInstructionMoreThan8k() throws Exception { StringBuffer sb = new StringBuffer(); - sb.append( "" ); - sb.append( "" ); + sb.append(""); + sb.append(""); // add ten times 1000 chars as comment - for ( int j = 0; j < 10; j++ ) - { + for (int j = 0; j < 10; j++) { - sb.append( "" ); + sb.append(" -->"); } - sb.append( "" ); - sb.append( "" ); + sb.append(""); + sb.append(""); MXParser parser = new MXParser(); - parser.setInput( new StringReader( sb.toString() ) ); - - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + parser.setInput(new StringReader(sb.toString())); + + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); } /** @@ -538,25 +491,23 @@ public void testSubsequentProcessingInstructionMoreThan8k() * @throws java.lang.Exception if any. */ @Test - public void testLargeText_NoOverflow() - throws Exception - { + public void testLargeText_NoOverflow() throws Exception { StringBuffer sb = new StringBuffer(); - sb.append( "" ); - sb.append( "" ); + sb.append(""); + sb.append(""); // Anything above 33,554,431 would fail without a fix for // https://web.archive.org/web/20070831191548/http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=228 // with java.io.IOException: error reading input, returned 0 - sb.append( new String( new char[33554432] ) ); - sb.append( "" ); + sb.append(new String(new char[33554432])); + sb.append(""); MXParser parser = new MXParser(); - parser.setInput( new StringReader( sb.toString() ) ); + parser.setInput(new StringReader(sb.toString())); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.TEXT, parser.nextToken() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.TEXT, parser.nextToken()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); } /** @@ -565,28 +516,23 @@ public void testLargeText_NoOverflow() * @throws java.lang.Exception if any. */ @Test - public void testMalformedProcessingInstructionAfterTag() - throws Exception - { + public void testMalformedProcessingInstructionAfterTag() throws Exception { MXParser parser = new MXParser(); String input = ""; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - try - { - assertEquals( XmlPullParser.START_TAG, parser.next() ); + try { + assertEquals(XmlPullParser.START_TAG, parser.next()); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + assertEquals(XmlPullParser.END_TAG, parser.next()); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.next() ); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.next()); - fail( "Should fail since it has an invalid Processing Instruction" ); - } - catch ( XmlPullParserException ex ) - { - assertTrue( ex.getMessage().contains( "processing instruction PITarget name not found" ) ); + fail("Should fail since it has an invalid Processing Instruction"); + } catch (XmlPullParserException ex) { + assertTrue(ex.getMessage().contains("processing instruction PITarget name not found")); } } @@ -596,28 +542,23 @@ public void testMalformedProcessingInstructionAfterTag() * @throws java.lang.Exception if any. */ @Test - public void testMalformedProcessingInstructionBeforeTag() - throws Exception - { + public void testMalformedProcessingInstructionBeforeTag() throws Exception { MXParser parser = new MXParser(); String input = ""; - parser.setInput( new StringReader( input ) ); + parser.setInput(new StringReader(input)); - try - { - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.next() ); + try { + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.next()); - assertEquals( XmlPullParser.START_TAG, parser.next() ); + assertEquals(XmlPullParser.START_TAG, parser.next()); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + assertEquals(XmlPullParser.END_TAG, parser.next()); - fail( "Should fail since it has invalid PI" ); - } - catch ( XmlPullParserException ex ) - { - assertTrue( ex.getMessage().contains( "processing instruction PITarget name not found" ) ); + fail("Should fail since it has invalid PI"); + } catch (XmlPullParserException ex) { + assertTrue(ex.getMessage().contains("processing instruction PITarget name not found")); } } @@ -627,30 +568,27 @@ public void testMalformedProcessingInstructionBeforeTag() * @throws java.lang.Exception if any. */ @Test - public void testMalformedProcessingInstructionSpaceBeforeName() - throws Exception - { + public void testMalformedProcessingInstructionSpaceBeforeName() throws Exception { MXParser parser = new MXParser(); StringBuilder sb = new StringBuilder(); - sb.append( "" ); - sb.append( "" ); + sb.append(""); + sb.append(""); - parser.setInput( new StringReader( sb.toString() ) ); + parser.setInput(new StringReader(sb.toString())); - try - { - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.next() ); + try { + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.next()); - assertEquals( XmlPullParser.START_TAG, parser.next() ); + assertEquals(XmlPullParser.START_TAG, parser.next()); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + assertEquals(XmlPullParser.END_TAG, parser.next()); - fail( "Should fail since it has invalid PI" ); - } - catch ( XmlPullParserException ex ) - { - assertTrue( ex.getMessage().contains( "processing instruction PITarget must be exactly after " ); - sb.append( "" ); + sb.append(""); + sb.append(""); - parser.setInput( new StringReader( sb.toString() ) ); + parser.setInput(new StringReader(sb.toString())); - try - { - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.next() ); + try { + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.next()); - assertEquals( XmlPullParser.START_TAG, parser.next() ); + assertEquals(XmlPullParser.START_TAG, parser.next()); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + assertEquals(XmlPullParser.END_TAG, parser.next()); - fail( "Should fail since it has invalid PI" ); - } - catch ( XmlPullParserException ex ) - { - assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 1 was not closed" ) ); + fail("Should fail since it has invalid PI"); + } catch (XmlPullParserException ex) { + assertTrue( + ex.getMessage().contains("processing instruction started on line 1 and column 1 was not closed")); } } @@ -693,30 +627,26 @@ public void testMalformedProcessingInstructionNoClosingQuestionMark() * @throws java.lang.Exception if any. */ @Test - public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() - throws Exception - { + public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() throws Exception { MXParser parser = new MXParser(); StringBuilder sb = new StringBuilder(); - sb.append( "" ); - sb.append( "" ); + sb.append(""); + sb.append(""); - parser.setInput( new StringReader( sb.toString() ) ); + parser.setInput(new StringReader(sb.toString())); - try - { - assertEquals( XmlPullParser.START_TAG, parser.next() ); + try { + assertEquals(XmlPullParser.START_TAG, parser.next()); - assertEquals( XmlPullParser.END_TAG, parser.next() ); + assertEquals(XmlPullParser.END_TAG, parser.next()); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.next() ); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.next()); - fail( "Should fail since it has invalid PI" ); - } - catch ( XmlPullParserException ex ) - { - assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 12 was not closed" ) ); + fail("Should fail since it has invalid PI"); + } catch (XmlPullParserException ex) { + assertTrue( + ex.getMessage().contains("processing instruction started on line 1 and column 12 was not closed")); } } @@ -726,75 +656,61 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() * @throws java.lang.Exception if any. */ @Test - public void testSubsequentAbortedProcessingInstruction() - throws Exception - { + public void testSubsequentAbortedProcessingInstruction() throws Exception { MXParser parser = new MXParser(); StringBuilder sb = new StringBuilder(); - sb.append( "" ); - sb.append( ""); + sb.append("" ); - sb.append( "\n" - + " \n" - + " \n" - + "\n" - + "\n" - + "]", parser.getText() ); - assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( "document", parser.getName() ); - assertEquals( 1, parser.getAttributeCount() ); - assertEquals( "name", parser.getAttributeName( 0 ) ); - assertEquals( "section name with entities: '&' 'Α' '<' ' ' '>' '𝟭' ''' 'ř' '\"'", - parser.getAttributeValue( 0 ) ); - - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "myCustomEntity", parser.getName() ); - assertEquals( "ř", parser.getText() ); - - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); - } - catch ( XmlPullParserException e ) - { - fail( "should not raise exception: " + e ); + parser.setInput(input, null); + parser.defineEntityReplacementText("nbsp", " "); + parser.defineEntityReplacementText("Alpha", "Α"); + parser.defineEntityReplacementText("tritPos", "𝟭"); + parser.defineEntityReplacementText("flo", "ř"); + parser.defineEntityReplacementText("myCustomEntity", "&flo;"); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken()); + assertEquals(XmlPullParser.DOCDECL, parser.nextToken()); + assertEquals( + " document [\n" + + " \n" + + " \n" + + " \n" + + "\n" + + "\n" + + "]", + parser.getText()); + assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("document", parser.getName()); + assertEquals(1, parser.getAttributeCount()); + assertEquals("name", parser.getAttributeName(0)); + assertEquals( + "section name with entities: '&' 'Α' '<' ' ' '>' '𝟭' ''' 'ř' '\"'", + parser.getAttributeValue(0)); + + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("myCustomEntity", parser.getName()); + assertEquals("ř", parser.getText()); + + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); + } catch (XmlPullParserException e) { + fail("should not raise exception: " + e); } } @@ -1421,10 +1252,8 @@ private void testDocdeclTextWithEntitiesInAttributes( String filename ) * @since 3.4.2 */ @Test - public void testEntityRefTextUnix() - throws IOException - { - testEntityRefText( "\n" ); + public void testEntityRefTextUnix() throws IOException { + testEntityRefText("\n"); } /** @@ -1437,63 +1266,58 @@ public void testEntityRefTextUnix() * @since 3.4.2 */ @Test - public void testEntityRefTextDOS() - throws IOException - { - testEntityRefText( "\r\n" ); + public void testEntityRefTextDOS() throws IOException { + testEntityRefText("\r\n"); } - private void testEntityRefText( String newLine ) - throws IOException - { + private void testEntityRefText(String newLine) throws IOException { StringBuilder sb = new StringBuilder(); - sb.append( "" ).append( newLine ); - sb.append( "" ).append( newLine ); - sb.append( "" ).append( newLine ); - sb.append( "" ).append( newLine ); - sb.append( "]>" ).append( newLine ); - sb.append( "&foo;&foo1;&foo2;&tritPos;" ); - - try - { + sb.append("").append(newLine); + sb.append("").append(newLine); + sb.append("").append(newLine); + sb.append("").append(newLine); + sb.append("]>").append(newLine); + sb.append("&foo;&foo1;&foo2;&tritPos;"); + + try { MXParser parser = new MXParser(); - parser.setInput( new StringReader( sb.toString() ) ); - parser.defineEntityReplacementText( "foo", "ř" ); - parser.defineEntityReplacementText( "nbsp", " " ); - parser.defineEntityReplacementText( "foo1", " " ); - parser.defineEntityReplacementText( "foo2", "š" ); - parser.defineEntityReplacementText( "tritPos", "𝟭" ); - - assertEquals( XmlPullParser.DOCDECL, parser.nextToken() ); - assertEquals( " test [\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "]", parser.getText() ); - assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( "b", parser.getName() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "ř", parser.getText() ); - assertEquals( "foo", parser.getName() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( " ", parser.getText() ); - assertEquals( "foo1", parser.getName() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "š", parser.getText() ); - assertEquals( "foo2", parser.getName() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "𝟭", parser.getText() ); - assertEquals( "tritPos", parser.getName() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( "b", parser.getName() ); - assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); - } - catch ( XmlPullParserException e ) - { - fail( "should not raise exception: " + e ); + parser.setInput(new StringReader(sb.toString())); + parser.defineEntityReplacementText("foo", "ř"); + parser.defineEntityReplacementText("nbsp", " "); + parser.defineEntityReplacementText("foo1", " "); + parser.defineEntityReplacementText("foo2", "š"); + parser.defineEntityReplacementText("tritPos", "𝟭"); + + assertEquals(XmlPullParser.DOCDECL, parser.nextToken()); + assertEquals( + " test [\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "]", + parser.getText()); + assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("b", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("ř", parser.getText()); + assertEquals("foo", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(" ", parser.getText()); + assertEquals("foo1", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("š", parser.getText()); + assertEquals("foo2", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("𝟭", parser.getText()); + assertEquals("tritPos", parser.getName()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("b", parser.getName()); + assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); + } catch (XmlPullParserException e) { + fail("should not raise exception: " + e); } } @@ -1510,35 +1334,32 @@ private void testEntityRefText( String newLine ) public void testEntityReplacement() throws IOException { String input = "

      

    "; - try - { + try { MXParser parser = new MXParser(); - parser.setInput( new StringReader( input ) ); - parser.defineEntityReplacementText( "nbsp", " " ); - - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( "p", parser.getName() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( " a pagebreak: ", parser.getText() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( " PB ", parser.getText() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "\u00A0", parser.getText() ); - assertEquals( "#160", parser.getName() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( " ", parser.getText() ); - assertEquals( "nbsp", parser.getName() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( "unknown", parser.getName() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( "unknown", parser.getName() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( "p", parser.getName() ); - assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); - } - catch ( XmlPullParserException e ) - { - fail( "should not raise exception: " + e ); + parser.setInput(new StringReader(input)); + parser.defineEntityReplacementText("nbsp", " "); + + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("p", parser.getName()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(" a pagebreak: ", parser.getText()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(" PB ", parser.getText()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("\u00A0", parser.getText()); + assertEquals("#160", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(" ", parser.getText()); + assertEquals("nbsp", parser.getName()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("unknown", parser.getName()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("unknown", parser.getName()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("p", parser.getName()); + assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); + } catch (XmlPullParserException e) { + fail("should not raise exception: " + e); } } @@ -1553,47 +1374,42 @@ public void testEntityReplacement() throws IOException { * @since 3.4.2 */ @Test - public void testReplacementInPCArrayWithShorterCharArray() - throws IOException - { + public void testReplacementInPCArrayWithShorterCharArray() throws IOException { String input = "]>" - + "

    &&foo;&tritPos;

    "; + + "

    &&foo;&tritPos;

    "; - try - { + try { MXParser parser = new MXParser(); - parser.setInput( new StringReader( new String(input.getBytes(), "ISO-8859-1" ) ) ); - parser.defineEntityReplacementText( "foo", "ř" ); - parser.defineEntityReplacementText( "tritPos", "𝟭" ); - - assertEquals( XmlPullParser.DOCDECL, parser.nextToken() ); - assertEquals( " test []", parser.getText() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( "section", parser.getName() ); - assertEquals( 1, parser.getAttributeCount() ); - assertEquals( "name" , parser.getAttributeName( 0 ) ); - assertEquals( "&ř𝟭" , parser.getAttributeValue( 0 ) ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( "

    ", parser.getText() ); - assertEquals( "p", parser.getName() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "&", parser.getText() ); - assertEquals( "amp", parser.getName() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "ř", parser.getText() ); - assertEquals( "foo", parser.getName() ); - assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); - assertEquals( "𝟭", parser.getText() ); - assertEquals( "tritPos", parser.getName() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( "p", parser.getName() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( "section", parser.getName() ); - assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); - } - catch ( XmlPullParserException e ) - { - fail( "should not raise exception: " + e ); + parser.setInput(new StringReader(new String(input.getBytes(), "ISO-8859-1"))); + parser.defineEntityReplacementText("foo", "ř"); + parser.defineEntityReplacementText("tritPos", "𝟭"); + + assertEquals(XmlPullParser.DOCDECL, parser.nextToken()); + assertEquals(" test []", parser.getText()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("section", parser.getName()); + assertEquals(1, parser.getAttributeCount()); + assertEquals("name", parser.getAttributeName(0)); + assertEquals("&ř𝟭", parser.getAttributeValue(0)); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("

    ", parser.getText()); + assertEquals("p", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("&", parser.getText()); + assertEquals("amp", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("ř", parser.getText()); + assertEquals("foo", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("𝟭", parser.getText()); + assertEquals("tritPos", parser.getName()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("p", parser.getName()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("section", parser.getName()); + assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); + } catch (XmlPullParserException e) { + fail("should not raise exception: " + e); } } @@ -1604,64 +1420,57 @@ public void testReplacementInPCArrayWithShorterCharArray() public void testUnicode() throws IOException { String input = ""; - try - { + try { MXParser parser = new MXParser(); - parser.setInput( new StringReader( input ) ); - - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( "project", parser.getName() ); - assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); - assertEquals( "ALL TEH BOMS! \uD83D\uDCA3 ", parser.getText() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( "project", parser.getName() ); - } - catch ( XmlPullParserException e ) - { + parser.setInput(new StringReader(input)); + + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("project", parser.getName()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals("ALL TEH BOMS! \uD83D\uDCA3 ", parser.getText()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("project", parser.getName()); + } catch (XmlPullParserException e) { e.printStackTrace(); - fail( "should not raise exception: " + e ); + fail("should not raise exception: " + e); } } @Test - public void testProcessingInstructionTokenizeBeforeFirstTag() - throws Exception - { + public void testProcessingInstructionTokenizeBeforeFirstTag() throws Exception { String input = "nnn"; MXParser parser = new MXParser(); - parser.setInput( new StringReader( input ) ); - - assertEquals( XmlPullParser.START_DOCUMENT, parser.getEventType() ); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( "a", parser.getText() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( "test", parser.getName() ); - assertEquals( XmlPullParser.TEXT, parser.nextToken() ); - assertEquals( "nnn", parser.getText() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); + parser.setInput(new StringReader(input)); + + assertEquals(XmlPullParser.START_DOCUMENT, parser.getEventType()); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals("a", parser.getText()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("test", parser.getName()); + assertEquals(XmlPullParser.TEXT, parser.nextToken()); + assertEquals("nnn", parser.getText()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); } @Test - public void testProcessingInstructionTokenizeAfterXMLDeclAndBeforeFirstTag() - throws Exception - { + public void testProcessingInstructionTokenizeAfterXMLDeclAndBeforeFirstTag() throws Exception { String input = "nnn"; MXParser parser = new MXParser(); - parser.setInput( new StringReader( input ) ); - - assertEquals( XmlPullParser.START_DOCUMENT, parser.getEventType() ); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( "xml version=\"1.0\" encoding=\"UTF-8\"", parser.getText() ); - assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); - assertEquals( "a", parser.getText() ); - assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); - assertEquals( "test", parser.getName() ); - assertEquals( XmlPullParser.TEXT, parser.nextToken() ); - assertEquals( "nnn", parser.getText() ); - assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); - assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); + parser.setInput(new StringReader(input)); + + assertEquals(XmlPullParser.START_DOCUMENT, parser.getEventType()); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals("xml version=\"1.0\" encoding=\"UTF-8\"", parser.getText()); + assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); + assertEquals("a", parser.getText()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("test", parser.getName()); + assertEquals(XmlPullParser.TEXT, parser.nextToken()); + assertEquals("nnn", parser.getText()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java index 8c174f54..642e729f 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java @@ -22,10 +22,9 @@ * @version $Id: $Id * @since 3.4.0 */ -public class eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test -{ +public class eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test { - final static File testResourcesDir = new File("src/test/resources/", "xmlconf/eduni/misc/"); + static final File testResourcesDir = new File("src/test/resources/", "xmlconf/eduni/misc/"); MXParser parser; @@ -33,8 +32,7 @@ public class eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test *

    setUp.

    */ @BeforeEach - public void setUp() - { + public void setUp() { parser = new MXParser(); } @@ -48,19 +46,14 @@ public void setUp() * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_bh_001() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "001.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testhst_bh_001() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "001.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "decimal charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value FF000000F6) is invalid" ) ); + fail("decimal charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value FF000000F6) is invalid")); } } @@ -74,19 +67,14 @@ public void testhst_bh_001() * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_bh_002() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "002.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testhst_bh_002() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "002.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "hex charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with decimal value 4294967542) is invalid" ) ); + fail("hex charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with decimal value 4294967542) is invalid")); } } @@ -100,19 +88,14 @@ public void testhst_bh_002() * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_bh_003() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "003.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testhst_bh_003() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "003.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "decimal charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with hex value FFFFFFFF000000F6) is invalid" ) ); + fail("decimal charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("character reference (with hex value FFFFFFFF000000F6) is invalid")); } } @@ -126,19 +109,15 @@ public void testhst_bh_003() * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_bh_004() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "004.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testhst_bh_004() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "004.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "hex charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "character reference (with decimal value 18446744073709551862) is invalid" ) ); + fail("hex charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage() + .contains("character reference (with decimal value 18446744073709551862) is invalid")); } } @@ -154,19 +133,14 @@ public void testhst_bh_004() * NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing. */ // @Test - public void testhst_bh_005() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "005.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testhst_bh_005() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "005.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "xmlns:xml is an attribute as far as validation is concerned and must be declared" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( true ); + fail("xmlns:xml is an attribute as far as validation is concerned and must be declared"); + } catch (XmlPullParserException e) { + assertTrue(true); } } @@ -182,19 +156,14 @@ public void testhst_bh_005() * NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing. */ // @Test - public void testhst_bh_006() - throws IOException - { - try ( Reader reader = new FileReader( new File( testResourcesDir, "006.xml" ) ) ) - { - parser.setInput( reader ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testhst_bh_006() throws IOException { + try (Reader reader = new FileReader(new File(testResourcesDir, "006.xml"))) { + parser.setInput(reader); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "xmlns:foo is an attribute as far as validation is concerned and must be declared" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( true ); + fail("xmlns:foo is an attribute as far as validation is concerned and must be declared"); + } catch (XmlPullParserException e) { + assertTrue(true); } } @@ -208,19 +177,14 @@ public void testhst_bh_006() * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_lhs_007() - throws IOException - { - try ( InputStream is = new FileInputStream( new File( testResourcesDir, "007.xml" ) ) ) - { - parser.setInput( is, null ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testhst_lhs_007() throws IOException { + try (InputStream is = new FileInputStream(new File(testResourcesDir, "007.xml"))) { + parser.setInput(is, null); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "UTF-8 BOM plus xml decl of ISO-8859-1 incompatible" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "UTF-8 BOM plus xml decl of ISO-8859-1 is incompatible" ) ); + fail("UTF-8 BOM plus xml decl of ISO-8859-1 incompatible"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("UTF-8 BOM plus xml decl of ISO-8859-1 is incompatible")); } } @@ -234,19 +198,14 @@ public void testhst_lhs_007() * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_lhs_008() - throws IOException - { - try ( InputStream is = new FileInputStream( new File( testResourcesDir, "008.xml" ) ) ) - { - parser.setInput( is, null ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testhst_lhs_008() throws IOException { + try (InputStream is = new FileInputStream(new File(testResourcesDir, "008.xml"))) { + parser.setInput(is, null); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "UTF-16 BOM plus xml decl of UTF-8 (using UTF-16 coding) incompatible" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "UTF-16 BOM in a UTF-8 encoded file is incompatible" ) ); + fail("UTF-16 BOM plus xml decl of UTF-8 (using UTF-16 coding) incompatible"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("UTF-16 BOM in a UTF-8 encoded file is incompatible")); } } @@ -260,20 +219,14 @@ public void testhst_lhs_008() * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_lhs_009() - throws IOException - { - try ( InputStream is = new FileInputStream( new File( testResourcesDir, "009.xml" ) ) ) - { - parser.setInput( is, null ); - while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + public void testhst_lhs_009() throws IOException { + try (InputStream is = new FileInputStream(new File(testResourcesDir, "009.xml"))) { + parser.setInput(is, null); + while (parser.nextToken() != XmlPullParser.END_DOCUMENT) ; - fail( "UTF-16 BOM plus xml decl of UTF-8 (using UTF-8 coding) incompatible" ); - } - catch ( XmlPullParserException e ) - { - assertTrue( e.getMessage().contains( "UTF-16 BOM in a UTF-8 encoded file is incompatible" ), e.getMessage() ); + fail("UTF-16 BOM plus xml decl of UTF-8 (using UTF-8 coding) incompatible"); + } catch (XmlPullParserException e) { + assertTrue(e.getMessage().contains("UTF-16 BOM in a UTF-8 encoded file is incompatible"), e.getMessage()); } } - }