eolivelli commented on a change in pull request #286: [MNG-6656] Introduce base 
for build/consumer process
URL: https://github.com/apache/maven/pull/286#discussion_r330304611
 
 

 ##########
 File path: 
maven-xml/src/test/java/org/apache/maven/xml/filter/AbstractXMLFilterTests.java
 ##########
 @@ -0,0 +1,95 @@
+package org.apache.maven.xml.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLFilter;
+
+public abstract class AbstractXMLFilterTests
+{
+    public AbstractXMLFilterTests()
+    {
+        super();
+    }
+    
+    protected abstract XMLFilter getFilter() throws TransformerException, 
SAXException, ParserConfigurationException;
+    
+    private void setParent( XMLFilter filter ) throws SAXException, 
ParserConfigurationException
+    {
+        if( filter.getParent() == null )
+        {
+            filter.setParent( 
SAXParserFactory.newInstance().newSAXParser().getXMLReader() );
+            filter.setFeature( "http://xml.org/sax/features/namespaces";, true 
);
+        }
+    }
+
+    protected String transform( String input )
+        throws TransformerException, SAXException, ParserConfigurationException
+    {
+        return transform( new StringReader( input ) );
+    }
+
+    protected String transform( Reader input ) throws TransformerException, 
SAXException, ParserConfigurationException
+    {
+        XMLFilter filter = getFilter();
+        setParent( filter );
+        return transform( input, filter );
+    }
+    
+    protected String transform( String input, XMLFilter filter ) 
+        throws TransformerException, SAXException, ParserConfigurationException
+    {
+        setParent( filter );
+        return transform( new StringReader( input ), filter );
+    }
+
+    protected String transform( Reader input, XMLFilter filter )
+        throws TransformerException, SAXException, ParserConfigurationException
+    {
+
+        Writer writer = new StringWriter();
+        StreamResult result = new StreamResult( writer );
+
+        TransformerFactory transformerFactory = 
TransformerFactory.newInstance();
 
 Review comment:
   We should have some common factory for XML stuff, in order to ensure a 
consistent configuration.
   IIRC some objects are reusable, this will save memory

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to