diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index b76b8957..99bc7a7e 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -2,9 +2,24 @@ version: 2
updates:
- package-ecosystem: "maven"
directory: "/"
+ target-branch: "master"
schedule:
interval: "daily"
+
+ - package-ecosystem: "maven"
+ directory: "/"
+ target-branch: "3.x"
+ schedule:
+ interval: "daily"
+
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ target-branch: "master"
+ schedule:
+ interval: "daily"
+
- package-ecosystem: "github-actions"
directory: "/"
+ target-branch: "3.x"
schedule:
interval: "daily"
diff --git a/.github/release-drafter-3.x.yml b/.github/release-drafter-3.x.yml
new file mode 100644
index 00000000..2b81e3e6
--- /dev/null
+++ b/.github/release-drafter-3.x.yml
@@ -0,0 +1,5 @@
+_extends: .github:.github/release-drafter.yml
+tag-template: plexus-xml-$NEXT_PATCH_VERSION
+version-template: 3.$MINOR.$PATCH
+commitish: 3.x
+filter-by-commitish: true
diff --git a/.github/release-drafter-master.yml b/.github/release-drafter-master.yml
new file mode 100644
index 00000000..6c322a82
--- /dev/null
+++ b/.github/release-drafter-master.yml
@@ -0,0 +1,5 @@
+_extends: .github:.github/release-drafter.yml
+tag-template: plexus-xml-$NEXT_PATCH_VERSION
+version-template: 4.$MINOR.$PATCH
+commitish: master
+filter-by-commitish: true
diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml
deleted file mode 100644
index c7f59480..00000000
--- a/.github/release-drafter.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-_extends: .github
-tag-template: plexus-utils-$NEXT_MINOR_VERSION
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 81f67f61..e8a60412 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -22,4 +22,17 @@ on: [push, pull_request]
jobs:
build:
name: Build it
- uses: codehaus-plexus/.github/.github/workflows/maven.yml@v0.0.5
+ uses: codehaus-plexus/.github/.github/workflows/maven.yml@master
+ with:
+ # Works with Java 17+
+ matrix-exclude: >
+ [
+ {"jdk": "8"},
+ {"jdk": "11"}
+ ]
+
+ deploy:
+ name: Deploy
+ needs: build
+ uses: codehaus-plexus/.github/.github/workflows/maven-deploy.yml@master
+ secrets: inherit
diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml
index 4000f8c4..e10bac4a 100644
--- a/.github/workflows/release-drafter.yml
+++ b/.github/workflows/release-drafter.yml
@@ -1,4 +1,4 @@
-name: Release Drafter
+name: Release Drafter Master
on:
push:
branches:
@@ -7,6 +7,8 @@ jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- - uses: release-drafter/release-drafter@v5
+ - uses: release-drafter/release-drafter@v6
+ with:
+ config-name: 'release-drafter-master.yml' # located in .github/ in default branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/README.md b/README.md
index 054e151b..d72d9e96 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,25 @@
Plexus-Xml
-============
+==========
[](https://github.com/codehaus-plexus/plexus-xml/actions)
+[](https://search.maven.org/artifact/org.codehaus.plexus/plexus-xml)
[](https://search.maven.org/artifact/org.codehaus.plexus/plexus-xml)
+[](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/codehaus/plexus/plexus-xml/README.md)
-This library consists of XML classes (`org.codehaus.plexus.util.xml`, and `ReaderFactory`/`WriterFactory` moved from `org.codehaus.plexus.util`) that have been extracted from `plexus-utils` 4.
+This library consists of XML classes (`org.codehaus.plexus.util.xml` and `org.codehaus.plexus.util.xml.pull`) that:
+
+1. have been extracted from [`plexus-utils`](https://github.com/codehaus-plexus/plexus-utils/) 4:\
+ this step is released as `plexus-xml` 3, maintained in [3.x branch](tree/3.x)\
+ [](https://search.maven.org/artifact/org.codehaus.plexus/plexus-xml),
+
+2. then updated to use Maven 4-specific [`maven-xml-api`](https://github.com/apache/maven/tree/maven-4.0.0-rc-2/api/maven-api-xml)/[`maven-xml`](https://github.com/apache/maven/tree/maven-4.0.0-rc-2/maven-xml):\
+ this is the `master` branch from which `plexus-xml` 4 is released\
+ Version 4.x requires Java 17 (like Maven 4)
+ [](https://search.maven.org/artifact/org.codehaus.plexus/plexus-xml)
For publishing [the site](https://codehaus-plexus.github.io/plexus-xml/) do the following:
```
mvn -Preporting verify site site:stage scm-publish:publish-scm
```
+
diff --git a/pom.xml b/pom.xml
index 61e81547..90efae8a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
-
-
4.0.0org.codehaus.plexusplexus
- 10
+ 23plexus-xml
- 4.0.0-SNAPSHOT
+ 4.1.1-SNAPSHOTPlexus XML UtilitiesA collection of various utility classes to ease working with XML.
+ https://codehaus-plexus.github.io/plexus-xml/
+
+
+
+ Apache-2.0
+ https://www.apache.org/licenses/LICENSE-2.0.txt
+ repo
+
+
- scm:git:git@github.com:codehaus-plexus/plexus-xml.git
- scm:git:git@github.com:codehaus-plexus/plexus-xml.git
- http://github.com/codehaus-plexus/plexus-xml
+ scm:git:https://github.com/codehaus-plexus/plexus-xml.git
+ ${project.scm.connection}master
+ https://github.com/codehaus-plexus/plexus-xml/tree/${project.scm.tag}/github
- http://github.com/codehaus-plexus/plexus-xml/issues
+ https://github.com/codehaus-plexus/plexus-xml/issues
@@ -49,75 +56,64 @@ limitations under the License.
- 2023-03-02T01:23:19Z
+ 17
+ 1.37
+ 2025-04-05T16:07:06Z
- org.codehaus.plexus
- plexus-utils
- 4.0.0-SNAPSHOT
- test
+ org.apache.maven
+ maven-xml
+ 4.0.0-rc-4
+
+
+ org.eclipse.sisu
+ org.eclipse.sisu.plexus
+
+ org.openjdk.jmhjmh-core
- 1.36
+ ${jmhVersion}testorg.openjdk.jmhjmh-generator-annprocess
- 1.36
+ ${jmhVersion}test
- junit
- junit
- 4.13.2
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-paramstest
-
-
-
- org.apache.maven.plugins
- maven-resources-plugin
- 3.3.1
-
-
-
-
- maven-compiler-plugin
-
-
- default-compile
-
- compile
-
-
- 1.8
- 1.8
-
-
-
- org.apache.maven.pluginsmaven-scm-publish-plugin
- ${project.reporting.outputDirectory}
+ ${project.reporting.outputDirectory}
+
scm-publish
- site-deploy
+
publish-scm
+ site-deploy
@@ -127,47 +123,8 @@ limitations under the License.
true
-
-
- JAVA_HOME
- ${JAVA_HOME}
-
-
- M2_HOME
- ${M2_HOME}
-
-
-
-
-
- jdk9+
-
- [9,)
-
-
-
-
-
- maven-compiler-plugin
-
-
- compile-java-9
-
- compile
-
-
- 8
-
-
-
-
-
-
-
-
-
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 8977534f..cd35289d 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java
@@ -18,24 +18,23 @@
import java.io.PrintWriter;
import java.io.Writer;
-import java.util.LinkedList;
+import java.util.ArrayDeque;
+import java.util.Deque;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * Implementation of XMLWriter which emits nicely formatted documents.
- *
+ *
Implementation of XMLWriter which emits nicely formatted documents.
*
+ *
C0n control characters except \n, \r, and \t are omitted from output
*/
-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;
- private LinkedList elementStack = new LinkedList();
+ private final Deque elementStack = new ArrayDeque<>();
private boolean tagInProgress;
@@ -57,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));
}
/**
@@ -93,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);
}
/**
@@ -104,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);
}
/**
@@ -114,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);
}
/**
@@ -124,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);
}
/**
@@ -136,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;
@@ -180,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 = escapeXmlText(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;
@@ -246,75 +224,77 @@ 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("([\\x00-\\x1F])");
- private static final Pattern lowers = Pattern.compile( "([\000-\037])" );
+ private static final Pattern illegalC0Characters = Pattern.compile("([\\x00-\\x08\\x0B-\\x0C\\x0E-\\x1F])");
- private static String escapeXmlAttribute( String text )
- {
- text = escapeXml( text );
+ private static String escapeXmlAttribute(String text) {
+ text = escapeXmlText(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();
+ }
+
+ private static String escapeXmlText(String text) {
+ text = escapeXml(text);
+
+ Matcher matcher = illegalC0Characters.matcher(text);
+ StringBuffer b = new StringBuffer();
+ while (matcher.find()) {
+ matcher = matcher.appendReplacement(b, "");
+ }
+ matcher.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();
- // see issue #51: https://github.com/codehaus-plexus/plexus-utils/issues/51
- // Rationale: replaced 1 write() with string concatenations with 3 write()
- // (this avoids the string concatenation optimization bug detected in Java 7)
- // TODO: change the below code to a more efficient expression when the library
- // be ready to target Java 8.
- write( "" );
- write( elementStack.removeLast() );
- write( ">" );
+ write("");
+ write(elementStack.removeLast());
+ write(">");
}
readyForNewLine = true;
@@ -322,25 +302,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;
@@ -353,8 +329,7 @@ private void finishTag()
*
* @return the line indenter
*/
- protected String getLineIndenter()
- {
+ protected String getLineIndenter() {
return lineIndenter;
}
@@ -363,8 +338,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;
}
@@ -374,8 +348,7 @@ protected void setLineIndenter( String lineIndenter )
* @return the line separator
* @see #LS
*/
- protected String getLineSeparator()
- {
+ protected String getLineSeparator() {
return lineSeparator;
}
@@ -384,8 +357,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;
}
@@ -395,36 +367,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();
}
@@ -435,11 +402,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;
@@ -450,8 +415,7 @@ protected void setWriter( PrintWriter writer )
*
* @return the underlying writer
*/
- protected PrintWriter getWriter()
- {
+ protected PrintWriter getWriter() {
return writer;
}
@@ -460,8 +424,7 @@ protected PrintWriter getWriter()
*
* @param depth new depth
*/
- protected void setDepth( int depth )
- {
+ protected void setDepth(int depth) {
this.depth = depth;
}
@@ -470,8 +433,7 @@ protected void setDepth( int depth )
*
* @return the current depth
*/
- protected int getDepth()
- {
+ protected int getDepth() {
return depth;
}
@@ -480,8 +442,7 @@ protected int getDepth()
*
* @param encoding new encoding
*/
- protected void setEncoding( String encoding )
- {
+ protected void setEncoding(String encoding) {
this.encoding = encoding;
}
@@ -490,8 +451,7 @@ protected void setEncoding( String encoding )
*
* @return the current encoding
*/
- protected String getEncoding()
- {
+ protected String getEncoding() {
return encoding;
}
@@ -500,8 +460,7 @@ protected String getEncoding()
*
* @param docType new docType
*/
- protected void setDocType( String docType )
- {
+ protected void setDocType(String docType) {
this.docType = docType;
}
@@ -510,16 +469,14 @@ protected void setDocType( String docType )
*
* @return the current docType
*/
- protected String getDocType()
- {
+ protected String getDocType() {
return docType;
}
/**
* @return the current elementStack;
*/
- protected LinkedList getElementStack()
- {
+ protected Deque getElementStack() {
return elementStack;
}
}
diff --git a/src/main/java/org/codehaus/plexus/util/xml/ReaderFactory.java b/src/main/java/org/codehaus/plexus/util/xml/ReaderFactory.java
deleted file mode 100644
index c8c35e18..00000000
--- a/src/main/java/org/codehaus/plexus/util/xml/ReaderFactory.java
+++ /dev/null
@@ -1,221 +0,0 @@
-package org.codehaus.plexus.util.xml;
-
-/*
- * Copyright The Codehaus Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-
-/**
- * Utility to create Readers from streams, with explicit encoding choice: platform default, XML, or specified.
- *
- * @author Herve Boutemy
- * @see Charset
- * @see Supported encodings
- *
- * @since 1.4.3
- */
-public class ReaderFactory
-{
- /**
- * ISO Latin Alphabet #1, also known as ISO-LATIN-1. Every implementation of the Java platform is required to
- * support this character encoding.
- *
- * @see Charset
- */
- public static final String ISO_8859_1 = "ISO-8859-1";
-
- /**
- * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set. Every
- * implementation of the Java platform is required to support this character encoding.
- *
- * @see Charset
- */
- public static final String US_ASCII = "US-ASCII";
-
- /**
- * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either
- * order accepted on input, big-endian used on output). Every implementation of the Java platform is required to
- * support this character encoding.
- *
- * @see Charset
- */
- public static final String UTF_16 = "UTF-16";
-
- /**
- * Sixteen-bit Unicode Transformation Format, big-endian byte order. Every implementation of the Java platform is
- * required to support this character encoding.
- *
- * @see Charset
- */
- public static final String UTF_16BE = "UTF-16BE";
-
- /**
- * Sixteen-bit Unicode Transformation Format, little-endian byte order. Every implementation of the Java platform is
- * required to support this character encoding.
- *
- * @see Charset
- */
- public static final String UTF_16LE = "UTF-16LE";
-
- /**
- * Eight-bit Unicode Transformation Format. Every implementation of the Java platform is required to support this
- * character encoding.
- *
- * @see Charset
- */
- public static final String UTF_8 = "UTF-8";
-
- /**
- * The file.encoding System Property.
- */
- public static final String FILE_ENCODING = System.getProperty( "file.encoding" );
-
- /**
- * Create a new Reader with XML encoding detection rules.
- *
- * @param in not null input stream.
- * @return an XML reader instance for the input stream.
- * @throws IOException if any.
- * @see XmlStreamReader
- */
- public static XmlStreamReader newXmlReader( InputStream in )
- throws IOException
- {
- return new XmlStreamReader( in );
- }
-
- /**
- * Create a new Reader with XML encoding detection rules.
- *
- * @param file not null file.
- * @return an XML reader instance for the input file.
- * @throws IOException if any.
- * @see XmlStreamReader
- */
- public static XmlStreamReader newXmlReader( File file )
- throws IOException
- {
- return new XmlStreamReader( file );
- }
-
- /**
- * Create a new Reader with XML encoding detection rules.
- *
- * @param url not null url.
- * @return an XML reader instance for the input url.
- * @throws IOException if any.
- * @see XmlStreamReader
- */
- public static XmlStreamReader newXmlReader( URL url )
- throws IOException
- {
- return new XmlStreamReader( url );
- }
-
- /**
- * Create a new Reader with default platform encoding.
- *
- * @param in not null input stream.
- * @return a reader instance for the input stream using the default platform charset.
- * @see Charset#defaultCharset()
- */
- public static Reader newPlatformReader( InputStream in )
- {
- return new InputStreamReader( in );
- }
-
- /**
- * Create a new Reader with default platform encoding.
- *
- * @param file not null file.
- * @return a reader instance for the input file using the default platform charset.
- * @throws IOException if any.
- * @see Charset#defaultCharset()
- */
- public static Reader newPlatformReader( File file )
- throws IOException
- {
- return Files.newBufferedReader( file.toPath() );
- }
-
- /**
- * Create a new Reader with default platform encoding.
- *
- * @param url not null url.
- * @return a reader instance for the input url using the default platform charset.
- * @throws IOException if any.
- * @see Charset#defaultCharset()
- */
- public static Reader newPlatformReader( URL url )
- throws IOException
- {
- return new InputStreamReader( url.openStream() );
- }
-
- /**
- * Create a new Reader with specified encoding.
- *
- * @param in not null input stream.
- * @param encoding not null supported encoding.
- * @return a reader instance for the input stream using the given encoding.
- * @throws UnsupportedEncodingException if any.
- * @see Supported encodings
- */
- public static Reader newReader( InputStream in, String encoding )
- throws UnsupportedEncodingException
- {
- return new InputStreamReader( in, encoding );
- }
-
- /**
- * Create a new Reader with specified encoding. Note that there is no buffering on this reader, which favours
- * clients that read into large buffers (8K+).
- *
- * @param file not null file.
- * @param encoding not null supported encoding.
- * @return a reader instance for the input file using the given encoding.
- * @throws IOException if any.
- * @see Supported encodings
- */
- public static Reader newReader( File file, String encoding )
- throws IOException
- {
- return new InputStreamReader( Files.newInputStream( file.toPath() ), encoding );
- }
-
- /**
- * Create a new Reader with specified encoding.
- *
- * @param url not null url.
- * @param encoding not null supported encoding.
- * @return a reader instance for the input url using the given encoding.
- * @throws IOException if any.
- * @see Supported encodings
- */
- public static Reader newReader( URL url, String encoding )
- throws IOException
- {
- return new InputStreamReader( url.openStream(), encoding );
- }
-}
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/WriterFactory.java b/src/main/java/org/codehaus/plexus/util/xml/WriterFactory.java
deleted file mode 100644
index 9978bfa4..00000000
--- a/src/main/java/org/codehaus/plexus/util/xml/WriterFactory.java
+++ /dev/null
@@ -1,176 +0,0 @@
-package org.codehaus.plexus.util.xml;
-
-/*
- * Copyright The Codehaus Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-
-/**
- * Utility to create Writers, with explicit encoding choice: platform default, XML, or specified.
- *
- * @author Herve Boutemy
- * @see Charset
- * @see Supported encodings
- *
- * @since 1.4.4
- */
-public class WriterFactory
-{
- /**
- * ISO Latin Alphabet #1, also known as ISO-LATIN-1. Every implementation of the Java platform is required to
- * support this character encoding.
- *
- * @see Charset
- */
- public static final String ISO_8859_1 = "ISO-8859-1";
-
- /**
- * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set. Every
- * implementation of the Java platform is required to support this character encoding.
- *
- * @see Charset
- */
- public static final String US_ASCII = "US-ASCII";
-
- /**
- * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either
- * order accepted on input, big-endian used on output). Every implementation of the Java platform is required to
- * support this character encoding.
- *
- * @see Charset
- */
- public static final String UTF_16 = "UTF-16";
-
- /**
- * Sixteen-bit Unicode Transformation Format, big-endian byte order. Every implementation of the Java platform is
- * required to support this character encoding.
- *
- * @see Charset
- */
- public static final String UTF_16BE = "UTF-16BE";
-
- /**
- * Sixteen-bit Unicode Transformation Format, little-endian byte order. Every implementation of the Java platform is
- * required to support this character encoding.
- *
- * @see Charset
- */
- public static final String UTF_16LE = "UTF-16LE";
-
- /**
- * Eight-bit Unicode Transformation Format. Every implementation of the Java platform is required to support this
- * character encoding.
- *
- * @see Charset
- */
- public static final String UTF_8 = "UTF-8";
-
- /**
- * The file.encoding System Property.
- */
- public static final String FILE_ENCODING = System.getProperty( "file.encoding" );
-
- /**
- * Create a new Writer with XML encoding detection rules.
- *
- * @param out not null output stream.
- * @return an XML writer instance for the output stream.
- * @throws IOException if any.
- * @see XmlStreamWriter
- */
- public static XmlStreamWriter newXmlWriter( OutputStream out )
- throws IOException
- {
- return new XmlStreamWriter( out );
- }
-
- /**
- * Create a new Writer with XML encoding detection rules.
- *
- * @param file not null file.
- * @return an XML writer instance for the output file.
- * @throws IOException if any.
- * @see XmlStreamWriter
- */
- public static XmlStreamWriter newXmlWriter( File file )
- throws IOException
- {
- return new XmlStreamWriter( file );
- }
-
- /**
- * Create a new Writer with default platform encoding.
- *
- * @param out not null output stream.
- * @return a writer instance for the output stream using the default platform charset.
- * @see Charset#defaultCharset()
- */
- public static Writer newPlatformWriter( OutputStream out )
- {
- return new OutputStreamWriter( out );
- }
-
- /**
- * Create a new Writer with default platform encoding.
- *
- * @param file not null file.
- * @return a writer instance for the output file using the default platform charset.
- * @throws IOException if any.
- * @see Charset#defaultCharset()
- */
- public static Writer newPlatformWriter( File file )
- throws IOException
- {
- return Files.newBufferedWriter( file.toPath() );
- }
-
- /**
- * Create a new Writer with specified encoding.
- *
- * @param out not null output stream.
- * @param encoding not null supported encoding.
- * @return a writer instance for the output stream using the given encoding.
- * @throws UnsupportedEncodingException if any.
- * @see Supported encodings
- */
- public static Writer newWriter( OutputStream out, String encoding )
- throws UnsupportedEncodingException
- {
- return new OutputStreamWriter( out, encoding );
- }
-
- /**
- * Create a new Writer with specified encoding.
- *
- * @param file not null file.
- * @param encoding not null supported encoding.
- * @return a writer instance for the output file using the given encoding.
- * @throws IOException if any.
- * @see Supported encodings
- */
- public static Writer newWriter( File file, String encoding )
- throws IOException
- {
- return newWriter( Files.newOutputStream( file.toPath() ), encoding );
- }
-}
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 e7c7cc47..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,28 +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.
- *
+ *
* @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.
+ *
+ * It looks for the UTF-8 BOM first, if none sniffs the XML prolog charset, if this is also missing defaults to
+ * UTF-8.
+ *
+ * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details.
+ *
+ *
+ * @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);
+ }
+
/**
* Creates a Reader for a File.
*
@@ -57,14 +72,12 @@ public class XmlStreamReader
*
* 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
- {
- super( file );
+ public XmlStreamReader(File file) throws IOException {
+ this(file.toPath());
}
/**
@@ -74,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);
}
/**
@@ -102,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);
}
/**
@@ -125,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);
}
/**
@@ -146,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);
}
/**
@@ -165,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);
}
/**
@@ -197,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.
@@ -205,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);
}
/**
@@ -232,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 c6742747..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 = ReaderFactory.newXmlReader( 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>
@@ -93,24 +86,20 @@ public static boolean isXml( File f )
* @param writer not null
* @throws IOException if any or invalid xml content
* @see #prettyFormat(Reader, Writer, int, String)
- * @see ReaderFactory to read an xml content
- * @see WriterFactory to write an xml content
*/
- 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>
@@ -122,51 +111,42 @@ public static void prettyFormat( Reader reader, Writer writer )
* @param indentSize positive number for the indentation
* @param lineSeparator the wanted line separator
* @throws IOException if any or invalid xml content
- * @see ReaderFactory to read an xml content
- * @see WriterFactory to write an 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>
@@ -178,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>
@@ -205,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 ( Reader reader = ReaderFactory.newXmlReader( 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( reader );
+ 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());
}
}
@@ -245,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( "" + parser.getText() + "?>" );
+ } else if (eventType == XmlPullParser.PROCESSING_INSTRUCTION) {
+ writer.writeMarkup("" + parser.getText() + "?>");
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 5650f14c..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,66 +16,43 @@
* limitations under the License.
*/
-import org.codehaus.plexus.util.xml.pull.XmlSerializer;
-
import java.io.IOException;
import java.io.Serializable;
-import java.io.StringWriter;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
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
-{
- private static final long serialVersionUID = 2567894443061173996L;
-
- protected String name;
-
- protected String value;
-
- protected Map attributes;
-
- protected final List childList;
-
- protected Xpp3Dom parent;
-
- /**
- * @since 3.2.0
- */
- protected Object inputLocation;
-
+public class Xpp3Dom implements Serializable {
private static final String[] EMPTY_STRING_ARRAY = new String[0];
- private static final Xpp3Dom[] EMPTY_DOM_ARRAY = new Xpp3Dom[0];
-
- public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = "combine.children";
+ public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = XmlNode.CHILDREN_COMBINATION_MODE_ATTRIBUTE;
- public static final String CHILDREN_COMBINATION_MERGE = "merge";
+ public static final String CHILDREN_COMBINATION_MERGE = XmlNode.CHILDREN_COMBINATION_MERGE;
- public static final String CHILDREN_COMBINATION_APPEND = "append";
+ public static final String CHILDREN_COMBINATION_APPEND = XmlNode.CHILDREN_COMBINATION_APPEND;
/**
* This default mode for combining children DOMs during merge means that where element names match, the process will
* try to merge the element data, rather than putting the dominant and recessive elements (which share the same
* element name) as siblings in the resulting DOM.
*/
- public static final String DEFAULT_CHILDREN_COMBINATION_MODE = CHILDREN_COMBINATION_MERGE;
+ public static final String DEFAULT_CHILDREN_COMBINATION_MODE = XmlNode.DEFAULT_CHILDREN_COMBINATION_MODE;
- public static final String SELF_COMBINATION_MODE_ATTRIBUTE = "combine.self";
+ public static final String SELF_COMBINATION_MODE_ATTRIBUTE = XmlNode.SELF_COMBINATION_MODE_ATTRIBUTE;
- public static final String SELF_COMBINATION_OVERRIDE = "override";
+ public static final String SELF_COMBINATION_OVERRIDE = XmlNode.SELF_COMBINATION_OVERRIDE;
- public static final String SELF_COMBINATION_MERGE = "merge";
+ public static final String SELF_COMBINATION_MERGE = XmlNode.SELF_COMBINATION_MERGE;
- public static final String SELF_COMBINATION_REMOVE = "remove";
+ public static final String SELF_COMBINATION_REMOVE = XmlNode.SELF_COMBINATION_REMOVE;
/**
* This default mode for combining a DOM node during merge means that where element names match, the process will
@@ -83,12 +60,17 @@ public class Xpp3Dom
* dominant one. This means that wherever the dominant element doesn't provide the value or a particular attribute,
* that value or attribute will be set from the recessive DOM node.
*/
- public static final String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE;
+ public static final String DEFAULT_SELF_COMBINATION_MODE = XmlNode.DEFAULT_SELF_COMBINATION_MODE;
- public Xpp3Dom( String name )
- {
- this.name = name;
- childList = new ArrayList<>();
+ public static final String ID_COMBINATION_MODE_ATTRIBUTE = XmlNode.ID_COMBINATION_MODE_ATTRIBUTE;
+
+ public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = XmlNode.KEYS_COMBINATION_MODE_ATTRIBUTE;
+
+ private ChildrenTracking childrenTracking;
+ private XmlNode dom;
+
+ public Xpp3Dom(String name) {
+ this.dom = new XmlNodeImpl(name);
}
/**
@@ -96,19 +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( name );
- this.inputLocation = 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());
}
/**
@@ -116,71 +95,58 @@ public Xpp3Dom( Xpp3Dom src )
* @param src The source Dom.
* @param name The name of the Dom.
*/
- public Xpp3Dom( Xpp3Dom src, String name )
- {
- this.name = name;
- this.inputLocation = src.inputLocation;
-
- int childCount = src.getChildCount();
+ public Xpp3Dom(Xpp3Dom src, String name) {
+ this.dom = new XmlNodeImpl(src.dom, name);
+ }
- childList = new ArrayList( childCount );
+ public Xpp3Dom(XmlNode dom) {
+ this.dom = dom;
+ }
- setValue( src.getValue() );
+ public Xpp3Dom(XmlNode dom, Xpp3Dom parent) {
+ this.dom = dom;
+ this.childrenTracking = parent::replace;
+ }
- String[] attributeNames = src.getAttributeNames();
- for ( String attributeName : attributeNames )
- {
- setAttribute( attributeName, src.getAttribute( attributeName ) );
- }
+ public Xpp3Dom(XmlNode dom, ChildrenTracking childrenTracking) {
+ this.dom = dom;
+ this.childrenTracking = childrenTracking;
+ }
- for ( int i = 0; i < childCount; i++ )
- {
- addChild( new Xpp3Dom( src.getChild( i ) ) );
- }
+ public XmlNode getDom() {
+ return dom;
}
// ----------------------------------------------------------------------
// Name handling
// ----------------------------------------------------------------------
- public String getName()
- {
- return name;
+ public String getName() {
+ return dom.getName();
}
// ----------------------------------------------------------------------
// Value handling
// ----------------------------------------------------------------------
- public String getValue()
- {
- return value;
+ public String getValue() {
+ return dom.getValue();
}
- public void setValue( String value )
- {
- this.value = value;
+ public void setValue(String value) {
+ update(new XmlNodeImpl(dom.getName(), value, dom.getAttributes(), dom.getChildren(), dom.getInputLocation()));
}
// ----------------------------------------------------------------------
// Attribute handling
// ----------------------------------------------------------------------
- public String[] getAttributeNames()
- {
- if ( null == attributes || attributes.isEmpty() )
- {
- return EMPTY_STRING_ARRAY;
- }
- else
- {
- return attributes.keySet().toArray( EMPTY_STRING_ARRAY );
- }
+ public String[] getAttributeNames() {
+ return dom.getAttributes().keySet().toArray(EMPTY_STRING_ARRAY);
}
- public String getAttribute( String name )
- {
- return ( null != attributes ) ? attributes.get( name ) : null;
+ public String getAttribute(String name) {
+ return dom.getAttribute(name);
}
/**
@@ -189,155 +155,93 @@ public String getAttribute( String name )
* @return true if the attribute has been removed
* @since 3.4.0
*/
- public boolean removeAttribute( String name )
- {
- return StringUtils.isEmpty( name ) ? false: attributes.remove( name ) == null;
+ public boolean removeAttribute(String name) {
+ if (name != null && !name.isEmpty()) {
+ Map attrs = new HashMap<>(dom.getAttributes());
+ boolean ret = attrs.remove(name) != null;
+ if (ret) {
+ update(new XmlNodeImpl(
+ dom.getName(), dom.getValue(), attrs, dom.getChildren(), dom.getInputLocation()));
+ }
+ return ret;
+ }
+ return false;
}
/**
* 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 )
- {
- throw new NullPointerException( "Attribute name can not be null" );
+ if (null == name) {
+ throw new NullPointerException("Attribute name can not be null");
}
- if ( null == attributes )
- {
- attributes = new HashMap();
- }
-
- attributes.put( name, value );
+ Map attrs = new HashMap<>(dom.getAttributes());
+ attrs.put(name, value);
+ update(new XmlNodeImpl(dom.getName(), dom.getValue(), attrs, dom.getChildren(), dom.getInputLocation()));
}
// ----------------------------------------------------------------------
// Child handling
// ----------------------------------------------------------------------
- public Xpp3Dom getChild( int i )
- {
- return childList.get( i );
- }
-
- public Xpp3Dom getChild( String name )
- {
- if ( name != null )
- {
- ListIterator it = childList.listIterator( childList.size() );
- while ( it.hasPrevious() )
- {
- Xpp3Dom child = it.previous();
- if ( name.equals( child.getName() ) )
- {
- return child;
- }
- }
- }
- return null;
+ public Xpp3Dom getChild(int i) {
+ return new Xpp3Dom(dom.getChildren().get(i), this);
}
- public void addChild( Xpp3Dom xpp3Dom )
- {
- xpp3Dom.setParent( this );
- childList.add( xpp3Dom );
+ public Xpp3Dom getChild(String name) {
+ XmlNode child = dom.getChild(name);
+ return child != null ? new Xpp3Dom(child, this) : null;
}
- public Xpp3Dom[] getChildren()
- {
- if ( null == childList || childList.isEmpty() )
- {
- return EMPTY_DOM_ARRAY;
- }
- else
- {
- return childList.toArray( EMPTY_DOM_ARRAY );
- }
+ 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()));
}
- public Xpp3Dom[] getChildren( String name )
- {
- return getChildrenAsList( name ).toArray( EMPTY_DOM_ARRAY );
+ public Xpp3Dom[] getChildren() {
+ return dom.getChildren().stream().map(d -> new Xpp3Dom(d, this)).toArray(Xpp3Dom[]::new);
}
- private List getChildrenAsList( String name )
- {
- if ( null == childList )
- {
- return Collections.emptyList();
- }
- else
- {
- ArrayList children = null;
-
- for ( Xpp3Dom configuration : childList )
- {
- if ( name.equals( configuration.getName() ) )
- {
- if ( children == null )
- {
- children = new ArrayList();
- }
- children.add( configuration );
- }
- }
-
- if ( children != null )
- {
- return children;
- }
- else
- {
- return Collections.emptyList();
- }
- }
+ public Xpp3Dom[] getChildren(String name) {
+ return dom.getChildren().stream()
+ .filter(c -> c.getName().equals(name))
+ .map(d -> new Xpp3Dom(d, this))
+ .toArray(Xpp3Dom[]::new);
}
- public int getChildCount()
- {
- if ( null == childList )
- {
- return 0;
- }
-
- return childList.size();
+ public int getChildCount() {
+ return dom.getChildren().size();
}
- public void removeChild( int i )
- {
- Xpp3Dom child = getChild( i );
- childList.remove( i );
- // In case of any dangling references
- child.setParent( null );
+ 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 )
- {
- childList.remove( child );
- // In case of any dangling references
- child.setParent( null );
+ 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()
- {
- return parent;
+ public Xpp3Dom getParent() {
+ throw new UnsupportedOperationException();
}
- public void setParent( Xpp3Dom parent )
- {
- this.parent = parent;
- }
+ public void setParent(Xpp3Dom parent) {}
// ----------------------------------------------------------------------
// Input location handling
@@ -347,34 +251,29 @@ public void setParent( Xpp3Dom parent )
* @since 3.2.0
* @return input location
*/
- public Object getInputLocation()
- {
- return inputLocation;
+ public Object getInputLocation() {
+ return dom.getInputLocation();
}
/**
* @since 3.2.0
* @param inputLocation input location to set
*/
- public void setInputLocation( Object inputLocation )
- {
- this.inputLocation = 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);
}
}
@@ -415,122 +314,12 @@ public void writeToSerializer( String namespace, XmlSerializer serializer )
*
*
*/
- 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;
}
-
- boolean mergeSelf = true;
-
- String selfMergeMode = dominant.getAttribute( SELF_COMBINATION_MODE_ATTRIBUTE );
-
- if ( SELF_COMBINATION_OVERRIDE.equals( selfMergeMode ) )
- {
- mergeSelf = false;
- }
-
- if ( mergeSelf )
- {
- if ( isEmpty( dominant.getValue() ) && !isEmpty( recessive.getValue() ) )
- {
- dominant.setValue( recessive.getValue() );
- dominant.setInputLocation( recessive.getInputLocation() );
- }
-
- if ( recessive.attributes != null )
- {
- for ( String attr : recessive.attributes.keySet() )
- {
- if ( isEmpty( dominant.getAttribute( attr ) ) )
- {
- dominant.setAttribute( attr, recessive.getAttribute( attr ) );
- }
- }
- }
-
- if ( recessive.getChildCount() > 0 )
- {
- boolean mergeChildren = true;
-
- if ( childMergeOverride != null )
- {
- mergeChildren = childMergeOverride;
- }
- else
- {
- String childMergeMode = dominant.getAttribute( CHILDREN_COMBINATION_MODE_ATTRIBUTE );
-
- if ( CHILDREN_COMBINATION_APPEND.equals( childMergeMode ) )
- {
- mergeChildren = false;
- }
- }
-
- if ( !mergeChildren )
- {
- Xpp3Dom[] dominantChildren = dominant.getChildren();
- // remove these now, so we can append them to the recessive list later.
- dominant.childList.clear();
-
- for ( int i = 0, recessiveChildCount = recessive.getChildCount(); i < recessiveChildCount; i++ )
- {
- Xpp3Dom recessiveChild = recessive.getChild( i );
- dominant.addChild( new Xpp3Dom( recessiveChild ) );
- }
-
- // now, re-add these children so they'll be appended to the recessive list.
- for ( Xpp3Dom aDominantChildren : dominantChildren )
- {
- dominant.addChild( aDominantChildren );
- }
- }
- else
- {
- Map> commonChildren = new HashMap>();
-
- for ( Xpp3Dom recChild : recessive.childList )
- {
- if ( commonChildren.containsKey( recChild.name ) )
- {
- continue;
- }
- List dominantChildren = dominant.getChildrenAsList( recChild.name );
- if ( dominantChildren.size() > 0 )
- {
- commonChildren.put( recChild.name, dominantChildren.iterator() );
- }
- }
-
- for ( int i = 0, recessiveChildCount = recessive.getChildCount(); i < recessiveChildCount; i++ )
- {
- Xpp3Dom recessiveChild = recessive.getChild( i );
- Iterator it = commonChildren.get( recessiveChild.getName() );
- if ( it == null )
- {
- dominant.addChild( new Xpp3Dom( recessiveChild ) );
- }
- else if ( it.hasNext() )
- {
- Xpp3Dom dominantChild = it.next();
-
- String dominantChildCombinationMode =
- dominantChild.getAttribute( SELF_COMBINATION_MODE_ATTRIBUTE );
- if ( SELF_COMBINATION_REMOVE.equals( dominantChildCombinationMode ) )
- {
- dominant.removeChild( dominantChild );
- }
- else
- {
- mergeIntoXpp3Dom( dominantChild, recessiveChild, childMergeOverride );
- }
- }
- }
- }
- }
- }
+ dominant.dom = dominant.dom.merge(recessive.dom, childMergeOverride);
}
/**
@@ -544,11 +333,9 @@ else if ( it.hasNext() )
* 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;
@@ -564,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;
@@ -579,82 +364,61 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
// ----------------------------------------------------------------------
@Override
- public boolean equals( Object obj )
- {
- if ( obj == this )
- {
+ public boolean equals(Object obj) {
+ if (obj == this) {
return true;
}
- if ( !( obj instanceof Xpp3Dom ) )
- {
+ if (!(obj instanceof Xpp3Dom)) {
return false;
}
Xpp3Dom dom = (Xpp3Dom) obj;
-
- if ( name == null ? dom.name != null : !name.equals( dom.name ) )
- {
- return false;
- }
- else if ( value == null ? dom.value != null : !value.equals( dom.value ) )
- {
- return false;
- }
- else if ( attributes == null ? dom.attributes != null : !attributes.equals( dom.attributes ) )
- {
- return false;
- }
- else if ( childList == null ? dom.childList != null : !childList.equals( dom.childList ) )
- {
- return false;
- }
- else
- {
- return true;
- }
+ return this.dom.equals(dom.dom);
}
@Override
- public int hashCode()
- {
- int result = 17;
- result = 37 * result + ( name != null ? name.hashCode() : 0 );
- result = 37 * result + ( value != null ? value.hashCode() : 0 );
- result = 37 * result + ( attributes != null ? attributes.hashCode() : 0 );
- result = 37 * result + ( childList != null ? childList.hashCode() : 0 );
- return result;
+ public int hashCode() {
+ return dom.hashCode();
}
@Override
- public String toString()
- {
- // TODO: WARNING! Later versions of plexus-utils psit out an header due to thinking this is a new
- // document - not the desired behaviour!
- StringWriter writer = new StringWriter();
- XMLWriter xmlWriter = new PrettyPrintXMLWriter( writer, "UTF-8", null );
- Xpp3DomWriter.write( xmlWriter, this );
- return writer.toString();
+ public String toString() {
+ return dom.toString();
}
- public String toUnescapedString()
- {
- // TODO: WARNING! Later versions of plexus-utils psit out an header due to thinking this is a new
- // document - not the desired behaviour!
- StringWriter writer = new StringWriter();
- XMLWriter xmlWriter = new PrettyPrintXMLWriter( writer, "UTF-8", null );
- Xpp3DomWriter.write( xmlWriter, this, false );
- return writer.toString();
+ 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);
+ }
+ 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()));
+ return true;
+ }
+
+ public void setChildrenTracking(ChildrenTracking childrenTracking) {
+ this.childrenTracking = childrenTracking;
+ }
+
+ @FunctionalInterface
+ 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 623b8399..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,251 +16,73 @@
* limitations under the License.
*/
-import org.codehaus.plexus.util.xml.pull.MXParser;
-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 java.util.ArrayList;
-import java.util.List;
+
+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);
}
/**
- * @param reader the reader
- * @param locationBuilder the builder
* @since 3.2.0
- * @return DOM
- * @throws XmlPullParserException xml exception
- * @throws IOException io
*/
- 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
- {
- final XmlPullParser parser = new MXParser();
- parser.setInput( is, encoding );
-
- final Xpp3Dom xpp3Dom = build( parser, trim );
- is.close();
- is = null;
-
- return xpp3Dom;
- }
- finally
- {
- if ( is != null )
- {
- try
- {
- is.close();
- }
- catch ( IOException ioe )
- {
- // ignore
- }
- }
+ 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);
}
/**
- * @param reader the reader
- * @param trim to trim
- * @param locationBuilder the builder
* @since 3.2.0
- * @return DOM
- * @throws XmlPullParserException xml exception
- * @throws IOException io
*/
- public static Xpp3Dom build( Reader reader, boolean trim, InputLocationBuilder locationBuilder )
- throws XmlPullParserException, IOException
- {
- try
- {
- final XmlPullParser parser = new MXParser();
- parser.setInput( reader );
-
- final Xpp3Dom xpp3Dom = build( parser, trim, locationBuilder );
- reader.close();
- reader = null;
-
- return xpp3Dom;
- }
- finally
- {
- if ( reader != null )
- {
- try
- {
- reader.close();
- }
- catch ( IOException ioe )
- {
- // ignore
- }
- }
+ 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
- * @param locationBuilder builder
- * @param parser the parser
- * @param trim do trim
- * @return DOM
- * @throws XmlPullParserException xml exception
- * @throws IOException io
*/
- public static Xpp3Dom build( XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder )
- throws XmlPullParserException, IOException
- {
- List elements = new ArrayList<>();
-
- List values = new ArrayList<>();
-
- int eventType = parser.getEventType();
-
- boolean spacePreserve = false;
-
- while ( eventType != XmlPullParser.END_DOCUMENT )
- {
- if ( eventType == XmlPullParser.START_TAG )
- {
- spacePreserve = false;
-
- String rawName = parser.getName();
-
- Xpp3Dom childConfiguration = new Xpp3Dom( rawName );
-
- if ( locationBuilder != null )
- {
- childConfiguration.setInputLocation( locationBuilder.toInputLocation( parser ) );
- }
-
- int depth = elements.size();
-
- if ( depth > 0 )
- {
- Xpp3Dom parent = elements.get( depth - 1 );
-
- parent.addChild( childConfiguration );
- }
-
- elements.add( childConfiguration );
-
- if ( parser.isEmptyElementTag() )
- {
- values.add( null );
- }
- else
- {
- values.add( new StringBuilder() );
- }
-
- int attributesSize = parser.getAttributeCount();
-
- for ( int i = 0; i < attributesSize; i++ )
- {
- String name = parser.getAttributeName( i );
-
- String value = parser.getAttributeValue( i );
-
- childConfiguration.setAttribute( name, value );
-
- spacePreserve = spacePreserve || ( "xml:space".equals( name ) && "preserve".equals( value ) );
- }
- }
- else if ( eventType == XmlPullParser.TEXT )
- {
- int depth = values.size() - 1;
-
- @SuppressWarnings( "MismatchedQueryAndUpdateOfStringBuilder" )
- StringBuilder valueBuffer = values.get( depth );
-
- String text = parser.getText();
-
- if ( trim && !spacePreserve )
- {
- text = text.trim();
- }
-
- valueBuffer.append( text );
- }
- else if ( eventType == XmlPullParser.END_TAG )
- {
- int depth = elements.size() - 1;
-
- Xpp3Dom finishedConfiguration = elements.remove( depth );
-
- /* this Object could be null if it is a singleton tag */
- Object accumulatedValue = values.remove( depth );
-
- if ( finishedConfiguration.getChildCount() == 0 )
- {
- if ( accumulatedValue == null )
- {
- finishedConfiguration.setValue( null );
- }
- else
- {
- finishedConfiguration.setValue( accumulatedValue.toString() );
- }
- }
-
- if ( depth == 0 )
- {
- return finishedConfiguration;
- }
- }
-
- eventType = parser.next();
- }
-
- throw new IllegalStateException( "End of document found before returning to 0 depth" );
+ 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));
}
/**
@@ -268,8 +90,7 @@ else if ( eventType == XmlPullParser.END_TAG )
*
* @since 3.2.0
*/
- public static 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 555f481e..d8a47e53 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
@@ -1,9 +1,5 @@
package org.codehaus.plexus.util.xml;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
/*
* Copyright The Codehaus Foundation.
*
@@ -20,210 +16,79 @@
* limitations under the License.
*/
+import java.io.IOException;
+
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
/** @author Jason van Zyl */
-public class Xpp3DomUtils
-{
- public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = "combine.children";
-
- public static final String CHILDREN_COMBINATION_MERGE = "merge";
-
- public static final String CHILDREN_COMBINATION_APPEND = "append";
-
+@Deprecated
+public class Xpp3DomUtils {
/**
- * This default mode for combining children DOMs during merge means that where element names match, the process will
- * try to merge the element data, rather than putting the dominant and recessive elements (which share the same
- * element name) as siblings in the resulting DOM.
+ * @deprecated use {@link Xpp3Dom#CHILDREN_COMBINATION_MODE_ATTRIBUTE}
*/
- public static final String DEFAULT_CHILDREN_COMBINATION_MODE = CHILDREN_COMBINATION_MERGE;
-
- public static final String SELF_COMBINATION_MODE_ATTRIBUTE = "combine.self";
-
- public static final String SELF_COMBINATION_OVERRIDE = "override";
-
- public static final String SELF_COMBINATION_MERGE = "merge";
+ @Deprecated
+ public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE;
/**
- * In case of complex XML structures, combining can be done based on id.
- *
- * @since 3.0.22
+ * @deprecated use {@link Xpp3Dom#CHILDREN_COMBINATION_MERGE}
*/
- public static final String ID_COMBINATION_MODE_ATTRIBUTE = "combine.id";
-
+ @Deprecated
+ public static final String CHILDREN_COMBINATION_MERGE = Xpp3Dom.CHILDREN_COMBINATION_MERGE;
+
/**
- * In case of complex XML structures, combining can be done based on keys.
- * This is a comma separated list of attribute names.
- *
- * @since 3.4.0
+ * @deprecated use {@link Xpp3Dom#CHILDREN_COMBINATION_APPEND}
*/
- public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = "combine.keys";
+ @Deprecated
+ public static final String CHILDREN_COMBINATION_APPEND = Xpp3Dom.CHILDREN_COMBINATION_APPEND;
/**
- * This default mode for combining a DOM node during merge means that where element names match, the process will
- * try to merge the element attributes and values, rather than overriding the recessive element completely with the
- * dominant one. This means that wherever the dominant element doesn't provide the value or a particular attribute,
- * that value or attribute will be set from the recessive DOM node.
+ * @deprecated use {@link Xpp3Dom#DEFAULT_CHILDREN_COMBINATION_MODE}
*/
- public static final String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE;
-
- public void writeToSerializer( String namespace, XmlSerializer serializer, Xpp3Dom dom )
- 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, dom );
- if ( xmlWriter.getExceptions().size() > 0 )
- {
- throw (IOException) xmlWriter.getExceptions().get( 0 );
- }
- }
+ @Deprecated
+ public static final String DEFAULT_CHILDREN_COMBINATION_MODE = Xpp3Dom.DEFAULT_CHILDREN_COMBINATION_MODE;
/**
- * Merges one DOM into another, given a specific algorithm and possible override points for that algorithm.
- * The algorithm is as follows:
- *
- *
if the recessive DOM is null, there is nothing to do... return.
- *
Determine whether the dominant node will suppress the recessive one (flag=mergeSelf).
- *
- *
retrieve the 'combine.self' attribute on the dominant node, and try to match against 'override'...
- * if it matches 'override', then set mergeSelf == false...the dominant node suppresses the recessive one
- * completely.
- *
otherwise, use the default value for mergeSelf, which is true...this is the same as specifying
- * 'combine.self' == 'merge' as an attribute of the dominant root node.
- *
- *
If mergeSelf == true
- *
- *
Determine whether children from the recessive DOM will be merged or appended to the dominant DOM as
- * siblings (flag=mergeChildren).
- *
- *
if childMergeOverride is set (non-null), use that value (true/false)
- *
retrieve the 'combine.children' attribute on the dominant node, and try to match against
- * 'append'...
- *
if it matches 'append', then set mergeChildren == false...the recessive children will be appended as
- * siblings of the dominant children.
- *
otherwise, use the default value for mergeChildren, which is true...this is the same as specifying
- * 'combine.children' == 'merge' as an attribute on the dominant root node.
- *
- *
Iterate through the recessive children, and:
- *
- *
if 'combine.id' is set and there is a corresponding dominant child (matched by value of 'combine.id'),
- * merge the two.
- *
if 'combine.keys' is set and there is a corresponding dominant child (matched by value of key elements),
- * merge the two.
- *
if mergeChildren == true and there is a corresponding dominant child (matched by element name),
- * merge the two.
- *
otherwise, add the recessive child as a new child on the dominant root node.
- *
- *
- *
+ * @deprecated use {@link Xpp3Dom#SELF_COMBINATION_MODE_ATTRIBUTE}
*/
- 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 )
- {
- return;
- }
-
- boolean mergeSelf = true;
-
- String selfMergeMode = dominant.getAttribute( SELF_COMBINATION_MODE_ATTRIBUTE );
-
- if ( isNotEmpty( selfMergeMode ) && SELF_COMBINATION_OVERRIDE.equals( selfMergeMode ) )
- {
- mergeSelf = false;
- }
-
- if ( mergeSelf )
- {
- String[] recessiveAttrs = recessive.getAttributeNames();
- for ( String attr : recessiveAttrs )
- {
- if ( isEmpty( dominant.getAttribute( attr ) ) )
- {
- dominant.setAttribute( attr, recessive.getAttribute( attr ) );
- }
- }
-
- boolean mergeChildren = true;
-
- if ( childMergeOverride != null )
- {
- mergeChildren = childMergeOverride;
- }
- else
- {
- String childMergeMode = dominant.getAttribute( CHILDREN_COMBINATION_MODE_ATTRIBUTE );
+ @Deprecated
+ public static final String SELF_COMBINATION_MODE_ATTRIBUTE = Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE;
- if ( isNotEmpty( childMergeMode ) && CHILDREN_COMBINATION_APPEND.equals( childMergeMode ) )
- {
- mergeChildren = false;
- }
- }
+ /**
+ * @deprecated use {@link Xpp3Dom#SELF_COMBINATION_OVERRIDE}
+ */
+ @Deprecated
+ public static final String SELF_COMBINATION_OVERRIDE = Xpp3Dom.SELF_COMBINATION_OVERRIDE;
- final String keysValue = recessive.getAttribute( KEYS_COMBINATION_MODE_ATTRIBUTE );
+ /**
+ * @deprecated use {@link Xpp3Dom#SELF_COMBINATION_MERGE}
+ */
+ @Deprecated
+ public static final String SELF_COMBINATION_MERGE = Xpp3Dom.SELF_COMBINATION_MERGE;
- Xpp3Dom[] children = recessive.getChildren();
- for ( Xpp3Dom recessiveChild : children )
- {
- String idValue = recessiveChild.getAttribute( ID_COMBINATION_MODE_ATTRIBUTE );
+ /**
+ * @deprecated use {@link Xpp3Dom#ID_COMBINATION_MODE_ATTRIBUTE}
+ */
+ @Deprecated
+ public static final String ID_COMBINATION_MODE_ATTRIBUTE = Xpp3Dom.ID_COMBINATION_MODE_ATTRIBUTE;
- Xpp3Dom childDom = null;
- if ( isNotEmpty( idValue ) )
- {
- for ( Xpp3Dom dominantChild : dominant.getChildren() )
- {
- if ( idValue.equals( dominantChild.getAttribute( ID_COMBINATION_MODE_ATTRIBUTE ) ) )
- {
- childDom = dominantChild;
- // we have a match, so don't append but merge
- mergeChildren = true;
- }
- }
- }
- else if ( isNotEmpty( keysValue ) )
- {
- String[] keys = keysValue.split( "," );
- Map recessiveKeyValues = new HashMap<>( keys.length );
- for ( String key : keys )
- {
- recessiveKeyValues.put( key, recessiveChild.getAttribute( key ) );
- }
-
- for ( Xpp3Dom dominantChild : dominant.getChildren() )
- {
- Map dominantKeyValues = new HashMap<>( keys.length );
- for ( String key : keys )
- {
- dominantKeyValues.put( key, dominantChild.getAttribute( key ) );
- }
+ /**
+ * @deprecated use {@link Xpp3Dom#KEYS_COMBINATION_MODE_ATTRIBUTE}
+ */
+ @Deprecated
+ public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = Xpp3Dom.KEYS_COMBINATION_MODE_ATTRIBUTE;
- if ( recessiveKeyValues.equals( dominantKeyValues ) )
- {
- childDom = dominantChild;
- // we have a match, so don't append but merge
- mergeChildren = true;
- }
- }
-
- }
- else
- {
- childDom = dominant.getChild( recessiveChild.getName() );
- }
+ /**
+ * @deprecated use {@link Xpp3Dom#DEFAULT_SELF_COMBINATION_MODE}
+ */
+ @Deprecated
+ public static final String DEFAULT_SELF_COMBINATION_MODE = Xpp3Dom.DEFAULT_SELF_COMBINATION_MODE;
- if ( mergeChildren && childDom != null )
- {
- mergeIntoXpp3Dom( childDom, recessiveChild, childMergeOverride );
- }
- else
- {
- dominant.addChild( new Xpp3Dom( recessiveChild ) );
- }
- }
- }
+ /**
+ * @deprecated use {@link Xpp3Dom#writeToSerializer(String, XmlSerializer)}
+ */
+ @Deprecated
+ public void writeToSerializer(String namespace, XmlSerializer serializer, Xpp3Dom dom) throws IOException {
+ dom.writeToSerializer(namespace, serializer);
}
/**
@@ -236,15 +101,11 @@ else if ( isNotEmpty( keysValue ) )
* @param childMergeOverride Overrides attribute flags to force merging or appending of child elements into the
* dominant DOM
* @return merged DOM
+ * @deprecated use {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom, Boolean)}
*/
- public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride )
- {
- if ( dominant != null )
- {
- mergeIntoXpp3Dom( dominant, recessive, childMergeOverride );
- return dominant;
- }
- return recessive;
+ @Deprecated
+ public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) {
+ return Xpp3Dom.mergeXpp3Dom(dominant, recessive, childMergeOverride);
}
/**
@@ -256,32 +117,26 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean
* @param dominant The dominant DOM into which the recessive value/attributes/children will be merged
* @param recessive The recessive DOM, which will be merged into the dominant DOM
* @return merged DOM
+ * @deprecated use {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom)}
*/
- public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
- {
- if ( dominant != null )
- {
- mergeIntoXpp3Dom( dominant, recessive, null );
- return dominant;
- }
- return recessive;
+ @Deprecated
+ 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 Use 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 Use 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 98387238..63fffedd 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
@@ -15,17 +15,15 @@
import java.io.Reader;
import java.io.UnsupportedEncodingException;
-import org.codehaus.plexus.util.xml.ReaderFactory;
-import org.codehaus.plexus.util.xml.XmlReader;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
+import org.codehaus.plexus.util.xml.XmlStreamReaderException;
-//import java.util.Hashtable;
-
-//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
@@ -33,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.
@@ -69,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;
@@ -130,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;
}
@@ -171,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];
@@ -225,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;
}
@@ -280,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;
}
@@ -314,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;
@@ -355,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;
}
@@ -405,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;
@@ -459,8 +411,7 @@ private void ensureEntityCapacity()
private String xmlDeclContent;
- private void reset()
- {
+ private void reset() {
// System.out.println("reset() called");
location = null;
lineNumber = 1;
@@ -505,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,
@@ -541,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);
}
}
@@ -591,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;
}
@@ -620,118 +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;
-
- if ( reader instanceof XmlReader ) {
- // encoding already detected
- XmlReader xsr = (XmlReader) reader;
- fileEncoding = xsr.getEncoding();
- }
- else if ( reader instanceof InputStreamReader )
- {
- InputStreamReader isr = (InputStreamReader) reader;
- if ( isr.getEncoding() != null )
- {
- fileEncoding = isr.getEncoding().toUpperCase();
- }
- }
}
@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 = ReaderFactory.newReader( inputStream, inputEncoding );
- }
- else
- {
- reader = ReaderFactory.newXmlReader( inputStream );
- }
- }
- catch ( UnsupportedEncodingException une )
- {
- throw new XmlPullParserException( "could not create reader for encoding " + inputEncoding + " : " + une,
- this, une );
- }
- 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];
}
}
@@ -742,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 ]]>???)
@@ -757,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;
}
@@ -880,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;
@@ -1024,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;
@@ -1055,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;
@@ -1099,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];
}
}
@@ -1233,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()) + ")");
}
}
@@ -1273,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;
}
}
@@ -1301,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) {
@@ -1324,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();
}
@@ -1421,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!!!
@@ -1443,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;
}
}
@@ -1545,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;
@@ -1662,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;
@@ -1738,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);
}
}
}
@@ -1806,331 +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
- boolean isXMLDecl = parsePI();
- if ( tokenize )
- {
- if ( isXMLDecl )
- {
- return eventType = START_DOCUMENT;
- }
+ parsePI();
+ 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;
- }
- 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 ""
// [42] ETag ::= '' Name S? '>'
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
@@ -2141,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 " + endname + "> 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 " + endname + "> 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 " + endname + "> 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 " + endname + "> 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
@@ -2180,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? '/>'
@@ -2196,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;
}
}
@@ -2218,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;
@@ -2231,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;
@@ -2312,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;
}
}
@@ -2336,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);
}
}
}
@@ -2391,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]
@@ -2402,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;
@@ -2549,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 );
- }
- else
- {
- ns = newStringIntern( pc, pcStart, pcEnd - pcStart );
+ if (!usePC) {
+ ns = newStringIntern(buf, posStart, pos - 1 - posStart);
+ } 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;
}
}
@@ -2645,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;
}
@@ -2679,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;
@@ -2696,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
@@ -2708,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;
@@ -2834,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;
@@ -2882,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;
}
/**
@@ -2903,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;
}
/**
@@ -2930,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];
}
}
@@ -2975,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;
}
}
@@ -3097,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 boolean parsePI()
- throws XmlPullParserException, IOException
- {
+ private void parsePI() throws XmlPullParserException, IOException {
// implements XML 1.0 Section 2.6 Processing Instructions
// [16] PI ::= '' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
// [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
// ASSUMPTION: seen
- if ( tokenize )
- posStart = pos;
+ if (tokenize) posStart = pos;
final int curLine = lineNumber;
final int curColumn = columnNumber - 2;
int piTargetStart = pos;
@@ -3131,140 +2480,108 @@ private boolean parsePI()
final boolean normalizeIgnorableWS = tokenize && !roundtripSupported;
boolean normalizedCR = false;
- try
- {
+ try {
boolean seenPITarget = false;
boolean seenInnerTag = false;
boolean seenQ = false;
char ch = more();
- if ( isS( ch ) )
- {
- throw new XmlPullParserException( "processing instruction PITarget must be exactly after and not white space character",
- this, null );
+ if (isS(ch)) {
+ throw new XmlPullParserException(
+ "processing instruction PITarget must be exactly after and not white space character",
+ this,
+ null);
}
- while ( true )
- {
+ while (true) {
// scan until it hits ?>
// 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 > 2) { // 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;
@@ -3273,28 +2590,25 @@ 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;
}
}
- return true;
}
// protected final static char[] VERSION = {'v','e','r','s','i','o','n'};
@@ -3303,19 +2617,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
@@ -3326,218 +2638,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;
@@ -3625,21 +2891,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;
}
@@ -3648,29 +2908,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
@@ -3680,44 +2934,31 @@ private void parseCDSect( boolean hadCharData )
// ASSUMPTION: seen posStart )
- {
+ if (posEnd > posStart) {
joinPC();
- }
- else
- {
+ } else {
usePC = true;
pcStart = pcEnd = 0;
}
@@ -3727,99 +2968,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;
}
}
@@ -3827,46 +3038,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;
@@ -3874,123 +3075,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( "" ).append( tagName ).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("")
+ .append(tagName)
+ .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);
@@ -4007,53 +3192,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;
@@ -4070,48 +3246,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'
@@ -4135,14 +3303,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');
@@ -4159,9 +3327,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');
}
@@ -4169,52 +3336,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..54e48dc0 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
@@ -24,28 +24,27 @@
*
PROPERTY_SERIALIZER_INDENTATION
*
PROPERTY_SERIALIZER_LINE_SEPARATOR
*
+ *
C0n control characters except \n, \r, and \t are omitted from output
*/
-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 +100,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 +158,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 +220,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" );
- }
- if ( FEATURE_NAMES_INTERNED.equals( name ) )
- {
- namesInterned = state;
+ public void setFeature(String name, boolean state) throws IllegalArgumentException, IllegalStateException {
+ if (name == null) {
+ throw new IllegalArgumentException("feature name can not be null");
}
- else if ( FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals( name ) )
- {
+ if (FEATURE_NAMES_INTERNED.equals(name)) {
+ namesInterned = state;
+ } 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" );
- }
- if ( FEATURE_NAMES_INTERNED.equals( name ) )
- {
- return namesInterned;
+ public boolean getFeature(String name) throws IllegalArgumentException {
+ if (name == null) {
+ throw new IllegalArgumentException("feature name can not be null");
}
- else if ( FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals( name ) )
- {
+ if (FEATURE_NAMES_INTERNED.equals(name)) {
+ return namesInterned;
+ } else if (FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals(name)) {
return attributeUseApostrophe;
- }
- else
- {
+ } else {
return false;
}
}
@@ -297,86 +264,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" );
- }
- if ( PROPERTY_SERIALIZER_INDENTATION.equals( name ) )
- {
- indentationString = (String) value;
+ public void setProperty(String name, Object value) throws IllegalArgumentException, IllegalStateException {
+ if (name == null) {
+ throw new IllegalArgumentException("property name can not be null");
}
- else if ( PROPERTY_SERIALIZER_LINE_SEPARATOR.equals( name ) )
- {
+ if (PROPERTY_SERIALIZER_INDENTATION.equals(name)) {
+ indentationString = (String) value;
+ } 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 +329,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" );
- }
- if ( PROPERTY_SERIALIZER_INDENTATION.equals( name ) )
- {
- return indentationString;
+ public Object getProperty(String name) throws IllegalArgumentException {
+ if (name == null) {
+ throw new IllegalArgumentException("property name can not be null");
}
- else if ( PROPERTY_SERIALIZER_LINE_SEPARATOR.equals( name ) )
- {
+ if (PROPERTY_SERIALIZER_INDENTATION.equals(name)) {
+ return indentationString;
+ } 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 +422,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 +461,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 +495,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 +529,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" );
- }
- out.write( '<' );
- if ( namespace != null )
- {
-
- if ( namespace.length() > 0 )
- {
+ 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) {
+
+ 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 +597,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( "" );
- if ( namespace != null && namespace.length() > 0 )
- {
+ out.write("");
+ if (namespace != null && namespace.length() > 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 +774,121 @@ 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( "" );
- out.write( text ); // escape?
- out.write( "?>" );
+ public void processingInstruction(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 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() );
- }
- out.write( text ); // no escape?
+ 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?
}
@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 {
+ if (value == null) {
+ return;
+ }
// .[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 +903,44 @@ else if ( ch < 32 )
}
}
}
- if ( pos > 0 )
- {
- out.write( value.substring( pos ) );
+ if (pos > 0) {
+ out.write(value.substring(pos));
+ } else {
+ out.write(value); // this is shortcut to the most common case
}
- 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 {
+ if (text == null) {
+ return;
+ }
// 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,97 +949,59 @@ 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() );
- // in XML 1.1 legal are [#x1-#xD7FF]
- // if(ch > 0) {
- // if(i > pos) out.write(text.substring(pos, i));
- // out.write("");
- // out.write(Integer.toString(ch));
- // out.write(';');
- // pos = i + 1;
- // } else {
- // throw new IllegalStateException(
- // "character zero is not allowed in XML 1.1 output"+getLocation());
- // }
+ } else {
+ // skip special char
+ if (i > pos) out.write(text.substring(pos, i));
+ pos = i + 1;
}
}
- if ( seenBracket )
- {
+ if (seenBracket) {
seenBracketBracket = seenBracket = false;
}
-
}
}
- if ( pos > 0 )
- {
- out.write( text.substring( pos ) );
+ if (pos > 0) {
+ out.write(text.substring(pos));
+ } else {
+ out.write(text); // this is shortcut to the most common case
}
- 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 +1012,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 +1028,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:
- *
+ *
*
* 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:
- *
+ *
*
- *
+ *
* 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 )
*
*
<tag>foo</tag>
*
<tag></tag> (which is equivalent to <tag/> both input can be parsed with the same code:
- *
+ *
*
- *
+ *
* 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/site/markdown/index.md b/src/site/markdown/index.md
new file mode 100644
index 00000000..7ac1952f
--- /dev/null
+++ b/src/site/markdown/index.md
@@ -0,0 +1,8 @@
+# Plexus XML Utilities
+
+A collection of various utility classes to ease working with XML.
+
+This library consists of XML classes (`org.codehaus.plexus.util.xml` and `org.codehaus.plexus.util.xml.pull`):
+1. that have been extracted from [`plexus-utils`](../plexus-utils/) 4,
+2. then updated to use [`maven-xml-api`](https://maven.apache.org/ref/4.0.0-rc-2/api/maven-api-xml/)/[`maven-xml`](https://maven.apache.org/ref/4.0.0-rc-2/maven-xml/index.html)
+
diff --git a/src/site/site.xml b/src/site/site.xml
index 38cbad8a..075f5ece 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -1,9 +1,31 @@
+
+
-
+
+
+
+
+
+
+
+
\ No newline at end of file
+
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 76125f95..f26631d0 100644
--- a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java
+++ b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java
@@ -16,23 +16,25 @@
* limitations under the License.
*/
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import javax.swing.text.html.HTML.Tag;
import java.io.File;
import java.io.IOException;
-import java.io.OutputStreamWriter;
import java.io.StringWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.NoSuchElementException;
-import javax.swing.text.html.HTML.Tag;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import org.codehaus.plexus.util.StringUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Test of {@link org.codehaus.plexus.util.xml.PrettyPrintXMLWriter}
@@ -42,8 +44,7 @@
* @version $Id: $Id
* @since 3.4.0
*/
-public class PrettyPrintXMLWriterTest
-{
+class PrettyPrintXMLWriterTest {
StringWriter w;
PrettyPrintXMLWriter writer;
@@ -51,239 +52,208 @@ public class PrettyPrintXMLWriterTest
/**
*
*/
- @Before
- public void setUp()
- {
+ @BeforeEach
+ void setUp() {
parser = new MXParser();
}
@@ -46,228 +44,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 )
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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("setUp.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
parser = new MXParser();
}
@@ -51,23 +52,17 @@ public void setUp() {
* @throws java.io.IOException if there is an I/O error
*/
@Test
- public void testibm_not_wf_P02_ibm02n01xml()
- throws IOException
- {
- try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n01.xml" ) ) )
- {
- parser.setInput( reader );
- while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ void testibm_not_wf_P02_ibm02n01xml() throws IOException {
+ try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n01.xml"))) {
+ parser.setInput(reader);
+ while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
;
- fail( "Tests a comment which contains an illegal Char: #x00" );
- }
- catch ( XmlPullParserException e )
- {
- assertTrue( e.getMessage().contains( "Illegal character 0x0 found in comment" ) );
+ fail("Tests a comment which contains an illegal Char: #x00");
+ } catch (XmlPullParserException e) {
+ assertTrue(e.getMessage().contains("Illegal character 0x0 found in comment"));
}
}
-
/**
* Test ID:
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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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"));
}
}
@@ -208,19 +178,17 @@ public void testibm_not_wf_P02_ibm02n06xml()
* @throws java.io.IOException if there is an I/O error
*/
@Test
- public void testibm_not_wf_P02_ibm02n07xml() throws IOException {
- try(Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n07.xml"))) {
+ void testibm_not_wf_P02_ibm02n07xml() throws IOException {
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 )
+ 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 a6a80030..cda5f99e 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
@@ -1,15 +1,15 @@
package org.codehaus.plexus.util.xml.pull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests.
@@ -20,257 +20,214 @@
* @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;
/**
*
setUp.
*/
- @Before
- public void setUp()
- {
+ @BeforeEach
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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.
*/
- @Before
- public void setUp()
- {
+ @BeforeEach
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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 e5510bb5..a2b2c165 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
@@ -1,15 +1,15 @@
package org.codehaus.plexus.util.xml.pull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests.
@@ -20,176 +20,150 @@
* @version $Id: $Id
* @since 3.4.0
*/
-public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test
-{
+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;
/**
*
setUp.
*/
- @Before
- public void setUp()
- {
+ @BeforeEach
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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);
}
}
}
-
/**
*