This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git


The following commit(s) were added to refs/heads/master by this push:
     new 0dd10e9  don't trim (#124)
0dd10e9 is described below

commit 0dd10e9030a1f29416f68cbdedf053a3993bf4f6
Author: Elliotte Rusty Harold <elh...@users.noreply.github.com>
AuthorDate: Fri Apr 28 11:06:59 2023 -0400

    don't trim (#124)
---
 .../maven/shared/utils/xml/Xpp3DomBuilder.java     | 33 ++++++++++------------
 .../maven/shared/utils/xml/Xpp3DomBuilderTest.java |  7 +----
 2 files changed, 16 insertions(+), 24 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java 
b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
index 640a9c4..b03da58 100644
--- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
+++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
@@ -40,7 +40,6 @@ import org.xml.sax.helpers.DefaultHandler;
  * @author Kristian Rosenvold
  */
 public class Xpp3DomBuilder {
-    private static final boolean DEFAULT_TRIM = true;
 
     /**
      * @param reader {@link Reader}
@@ -48,7 +47,7 @@ public class Xpp3DomBuilder {
      * @throws XmlPullParserException in case of an error
      */
     public static Xpp3Dom build(@WillClose @Nonnull Reader reader) throws 
XmlPullParserException {
-        return build(reader, DEFAULT_TRIM);
+        return build(reader, false);
     }
 
     /**
@@ -58,21 +57,23 @@ public class Xpp3DomBuilder {
      * @throws XmlPullParserException in case of an error
      */
     public static Xpp3Dom build(@WillClose InputStream is, @Nonnull String 
encoding) throws XmlPullParserException {
-        return build(is, encoding, DEFAULT_TRIM);
+        return build(is, encoding, false);
     }
 
     /**
      * @param is {@link InputStream}
      * @param encoding the encoding
-     * @param trim true/false
+     * @param noop vestigial argument with no effect
      * @return the built DOM
      * @throws XmlPullParserException in case of an error
+     * @deprecated use the two-arg variant
      */
-    public static Xpp3Dom build(@WillClose InputStream is, @Nonnull String 
encoding, boolean trim)
+    @Deprecated
+    public static Xpp3Dom build(@WillClose InputStream is, @Nonnull String 
encoding, boolean noop)
             throws XmlPullParserException {
         try {
             Reader reader = new InputStreamReader(is, encoding);
-            return build(reader, trim);
+            return build(reader);
         } catch (UnsupportedEncodingException e) {
             throw new XmlPullParserException(e);
         }
@@ -80,13 +81,15 @@ public class Xpp3DomBuilder {
 
     /**
      * @param in {@link Reader}
-     * @param trim true/false
+     * @param noop vestigial argument with no effect
      * @return the built DOM
      * @throws XmlPullParserException in case of an error
+     * @deprecated use {#build(java.io.Reader)}
      */
-    public static Xpp3Dom build(@WillClose Reader in, boolean trim) throws 
XmlPullParserException {
+    @Deprecated
+    public static Xpp3Dom build(@WillClose Reader in, boolean noop) throws 
XmlPullParserException {
         try (Reader reader = in) {
-            DocHandler docHandler = parseSax(new InputSource(reader), trim);
+            DocHandler docHandler = parseSax(new InputSource(reader));
             reader.close();
             return docHandler.result;
         } catch (final IOException e) {
@@ -94,9 +97,9 @@ public class Xpp3DomBuilder {
         }
     }
 
-    private static DocHandler parseSax(@Nonnull InputSource inputSource, 
boolean trim) throws XmlPullParserException {
+    private static DocHandler parseSax(@Nonnull InputSource inputSource) 
throws XmlPullParserException {
         try {
-            DocHandler ch = new DocHandler(trim);
+            DocHandler ch = new DocHandler();
             XMLReader parser = createXmlReader();
             parser.setContentHandler(ch);
             parser.parse(inputSource);
@@ -147,14 +150,8 @@ public class Xpp3DomBuilder {
 
         Xpp3Dom result = null;
 
-        private final boolean trim;
-
         private boolean spacePreserve = false;
 
-        DocHandler(boolean trim) {
-            this.trim = trim;
-        }
-
         @Override
         public void startElement(String uri, String localName, String qName, 
Attributes attributes)
                 throws SAXException {
@@ -216,7 +213,7 @@ public class Xpp3DomBuilder {
         @Override
         public void characters(char[] ch, int start, int length) throws 
SAXException {
             String text = new String(ch, start, length);
-            appendToTopValue((trim && !spacePreserve) ? text.trim() : text);
+            appendToTopValue(text);
         }
 
         private void appendToTopValue(String toAppend) {
diff --git 
a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java 
b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
index ab921d1..f532432 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
@@ -71,15 +71,10 @@ public class Xpp3DomBuilderTest {
         String domString = createDomString();
 
         Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true);
-
-        assertEquals("element1value", dom.getChild("element1").getValue());
-
+        assertEquals(" element1value\n ", dom.getChild("element1").getValue());
         assertEquals("  preserve space  ", 
dom.getChild("element6").getValue());
-
         dom = Xpp3DomBuilder.build(new StringReader(domString), false);
-
         assertEquals(" element1value\n ", dom.getChild("element1").getValue());
-
         assertEquals("  preserve space  ", 
dom.getChild("element6").getValue());
     }
 

Reply via email to