knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject knox git commit: KNOX-863 - Consolidate TransformerFactory calls + enable (Colm O hEigeartaigh via Sandeep More)
Date Mon, 13 Feb 2017 21:44:40 GMT
Repository: knox
Updated Branches:
  refs/heads/master 3f8ff2aaf -> d82f834ce


KNOX-863 - Consolidate TransformerFactory calls + enable (Colm O hEigeartaigh via Sandeep
More)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/d82f834c
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/d82f834c
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/d82f834c

Branch: refs/heads/master
Commit: d82f834ceffd52ead5112400a7f56af5a1c59590
Parents: 3f8ff2a
Author: Sandeep More <more@apache.org>
Authored: Mon Feb 13 16:44:24 2017 -0500
Committer: Sandeep More <more@apache.org>
Committed: Mon Feb 13 16:44:24 2017 -0500

----------------------------------------------------------------------
 .../ha/provider/impl/HaDescriptorManager.java   | 15 +------
 .../rewrite/impl/xml/XmlFilterReader.java       | 13 +------
 .../impl/html/HtmlFilterReaderBaseTest.java     | 31 ---------------
 .../rewrite/impl/xml/XmlFilterReaderTest.java   | 31 ---------------
 .../apache/hadoop/gateway/GatewayServer.java    |  4 +-
 .../gateway/deploy/DeploymentFactoryTest.java   |  1 -
 .../gateway/shell/hbase/table/CreateTable.java  | 16 ++------
 .../gateway/shell/hbase/table/UpdateTable.java  | 16 ++------
 .../gateway/shell/hbase/table/row/StoreRow.java | 16 ++------
 .../hbase/table/scanner/CreateScanner.java      | 16 ++------
 .../java/org/apache/hadoop/test/TestUtils.java  | 17 --------
 .../deploy/DeploymentFactoryFuncTest.java       | 17 --------
 .../apache/hadoop/gateway/util/XmlUtils.java    | 41 +++++++++++++-------
 13 files changed, 51 insertions(+), 183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
index 6f7af32..f5e159f 100644
--- a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
+++ b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
@@ -28,12 +28,8 @@ import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Writer;
@@ -70,15 +66,8 @@ public class HaDescriptorManager implements HaDescriptorConstants {
             }
          }
 
-         TransformerFactory transformerFactory = TransformerFactory.newInstance();
-         transformerFactory.setAttribute("indent-number", 2);
-         Transformer transformer = transformerFactory.newTransformer();
-         transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
-         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-         StreamResult result = new StreamResult(writer);
-         DOMSource source = new DOMSource(document);
-         transformer.transform(source, result);
-
+         Transformer t = XmlUtils.getTransformer( true, true, 2, false );
+         XmlUtils.writeXml( document, writer, t );
       } catch (ParserConfigurationException e) {
          LOG.failedToWriteHaDescriptor(e);
          throw new IOException(e);

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
index 070ccce..2dd6519 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
@@ -49,11 +49,8 @@ import javax.xml.stream.events.Namespace;
 import javax.xml.stream.events.StartDocument;
 import javax.xml.stream.events.StartElement;
 import javax.xml.stream.events.XMLEvent;
-import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.xpath.XPath;
@@ -636,17 +633,11 @@ public abstract class XmlFilterReader extends Reader {
 
   private static final void writeBufferedElement( Node node, Writer writer ) throws IOException
{
     try {
-      getTransformer().transform( new DOMSource( node ), new StreamResult( writer ) );
+      Transformer t = XmlUtils.getTransformer( false, false, 0, true );
+      t.transform( new DOMSource( node ), new StreamResult( writer ) );
     } catch( TransformerException e ) {
       throw new IOException( e );
     }
   }
 
-  private static final Transformer getTransformer() throws TransformerConfigurationException
{
-    TransformerFactory tf = TransformerFactory.newInstance();
-    Transformer t = tf.newTransformer();
-    t.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );
-    return t;
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
index 257a4ca..55c7ca8 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
@@ -37,23 +37,14 @@ import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteActionDescriptorBa
 import org.hamcrest.Matchers;
 import org.junit.Before;
 import org.junit.Test;
-import org.w3c.dom.Node;
 import org.xml.sax.SAXException;
 import org.xmlmatchers.namespace.SimpleNamespaceContext;
 
 import javax.xml.namespace.QName;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.io.IOException;
-import java.io.OutputStream;
 import java.io.Reader;
 import java.io.StringReader;
-import java.io.Writer;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -771,26 +762,4 @@ public class HtmlFilterReaderBaseTest {
     }
   }
 
-  public void dump( Node node, Writer writer ) throws TransformerException {
-    Transformer t = TransformerFactory.newInstance().newTransformer();
-    t.setOutputProperty( OutputKeys.METHOD, "xml" );
-    t.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
-    t.setOutputProperty( OutputKeys.INDENT, "yes" );
-    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
-    t.transform( new DOMSource( node ), new StreamResult( writer ) );
-  }
-
-  public void dump( Node node, OutputStream stream ) throws TransformerException {
-    Transformer t = TransformerFactory.newInstance().newTransformer();
-    t.setOutputProperty( OutputKeys.METHOD, "xml" );
-    t.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
-    t.setOutputProperty( OutputKeys.INDENT, "yes" );
-    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
-    t.transform( new DOMSource( node ), new StreamResult( stream ) );
-  }
-
-//  public void dump( Node node ) throws TransformerException {
-//    dump( node, System.out );
-//  }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
index a345dcf..08b4d33 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
@@ -41,25 +41,16 @@ import org.apache.hadoop.test.TestUtils;
 import org.hamcrest.Matchers;
 import org.junit.Before;
 import org.junit.Test;
-import org.w3c.dom.Node;
 import org.xml.sax.SAXException;
 import org.xmlmatchers.namespace.SimpleNamespaceContext;
 
 import javax.xml.namespace.QName;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.Reader;
 import java.io.StringReader;
-import java.io.Writer;
 import java.nio.charset.Charset;
 import java.util.HashMap;
 import java.util.List;
@@ -1009,26 +1000,4 @@ public class XmlFilterReaderTest {
 
   }
 
-  public void dump( Node node, Writer writer ) throws TransformerException {
-    Transformer t = TransformerFactory.newInstance().newTransformer();
-    t.setOutputProperty( OutputKeys.METHOD, "xml" );
-    t.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
-    t.setOutputProperty( OutputKeys.INDENT, "yes" );
-    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
-    t.transform( new DOMSource( node ), new StreamResult( writer ) );
-  }
-
-  public void dump( Node node, OutputStream stream ) throws TransformerException {
-    Transformer t = TransformerFactory.newInstance().newTransformer();
-    t.setOutputProperty( OutputKeys.METHOD, "xml" );
-    t.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
-    t.setOutputProperty( OutputKeys.INDENT, "yes" );
-    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
-    t.transform( new DOMSource( node ), new StreamResult( stream ) );
-  }
-
-//  public void dump( Node node ) throws TransformerException {
-//    dump( node, System.out );
-//  }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
index 559f9cc..442004c 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.gateway;
 
 import java.io.File;
+import java.io.FileWriter;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
@@ -519,7 +520,8 @@ public class GatewayServer {
           originalRoot.appendChild( importedNode );
         }
       }
-      XmlUtils.writeXml( webXmlDoc, webXmlFile );
+      
+      XmlUtils.writeXml( webXmlDoc, new FileWriter(webXmlFile) );
     }
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
b/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
index 76f7858..da804f3 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
@@ -50,7 +50,6 @@ public class DeploymentFactoryTest {
     EnterpriseArchive archive = DeploymentFactory.createDeployment( config, topology );
 
     Document xml = XmlUtils.readXml( archive.get( "/META-INF/topology.xml" ).getAsset().openStream()
);
-    //TestUtils.dumpXml( xml );
     assertThat( xml, hasXPath( "/topology/gateway" ) );
     assertThat( xml, hasXPath( "/topology/name", equalTo( "test-topology" ) ) );
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
index d1fcc88..f20652d 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
@@ -30,16 +30,13 @@ import org.apache.http.entity.StringEntity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
 
+import javax.xml.transform.Transformer;
+
 public class CreateTable {
 
   public static class Request extends AbstractRequest<Response> implements FamilyContainer<Request>
{
@@ -96,14 +93,9 @@ public class CreateTable {
             root.appendChild( columnSchema );
           }
 
-          TransformerFactory transformerFactory = TransformerFactory.newInstance();
-          Transformer transformer = transformerFactory.newTransformer();
-          transformer.setOutputProperty( OutputKeys.STANDALONE, "yes" );
-
           StringWriter writer = new StringWriter();
-          StreamResult result = new StreamResult( writer );
-          DOMSource source = new DOMSource( document );
-          transformer.transform( source, result );
+          Transformer t = XmlUtils.getTransformer( true, false, 0, false );
+          XmlUtils.writeXml( document, writer, t );
 
           URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/schema" );
           HttpPut request = new HttpPut( uri.build() );

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
index 80c7b47..c382bd2 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
@@ -30,16 +30,13 @@ import org.apache.http.entity.StringEntity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
 
+import javax.xml.transform.Transformer;
+
 public class UpdateTable {
 
   public static class Request extends AbstractRequest<Response> implements FamilyContainer<Request>
{
@@ -86,14 +83,9 @@ public class UpdateTable {
             root.appendChild( columnSchema );
           }
 
-          TransformerFactory transformerFactory = TransformerFactory.newInstance();
-          Transformer transformer = transformerFactory.newTransformer();
-          transformer.setOutputProperty( OutputKeys.STANDALONE, "yes" );
-
           StringWriter writer = new StringWriter();
-          StreamResult result = new StreamResult( writer );
-          DOMSource source = new DOMSource( document );
-          transformer.transform( source, result );
+          Transformer t = XmlUtils.getTransformer( true, false, 0, false );
+          XmlUtils.writeXml( document, writer, t );
 
           URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/schema" );
           HttpPost request = new HttpPost( uri.build() );

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
index c78b3c5..afd851a 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
@@ -31,16 +31,13 @@ import org.apache.http.entity.StringEntity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
 
+import javax.xml.transform.Transformer;
+
 public class StoreRow {
 
   public static class Request extends AbstractRequest<Response> {
@@ -95,14 +92,9 @@ public class StoreRow {
             row.appendChild( cell );
           }
 
-          TransformerFactory transformerFactory = TransformerFactory.newInstance();
-          Transformer transformer = transformerFactory.newTransformer();
-          transformer.setOutputProperty( OutputKeys.STANDALONE, "yes" );
-
           StringWriter writer = new StringWriter();
-          StreamResult result = new StreamResult( writer );
-          DOMSource source = new DOMSource( document );
-          transformer.transform( source, result );
+          Transformer t = XmlUtils.getTransformer( true, false, 0, false );
+          XmlUtils.writeXml( document, writer, t );
 
           URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/false-row-key" );
           HttpPost request = new HttpPost( uri.build() );

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
index df95514..720906d 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
@@ -33,16 +33,13 @@ import org.apache.http.entity.StringEntity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
 
+import javax.xml.transform.Transformer;
+
 public class CreateScanner {
 
   public static class Request extends AbstractRequest<Response> {
@@ -168,14 +165,9 @@ public class CreateScanner {
             root.appendChild( filterElement );
           }
 
-          TransformerFactory transformerFactory = TransformerFactory.newInstance();
-          Transformer transformer = transformerFactory.newTransformer();
-          transformer.setOutputProperty( OutputKeys.STANDALONE, "yes" );
-
           StringWriter writer = new StringWriter();
-          StreamResult result = new StreamResult( writer );
-          DOMSource source = new DOMSource( document );
-          transformer.transform( source, result );
+          Transformer t = XmlUtils.getTransformer( true, false, 0, false );
+          XmlUtils.writeXml( document, writer, t );
 
           URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/scanner" );
           HttpPut request = new HttpPut( uri.build() );

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
----------------------------------------------------------------------
diff --git a/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java b/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
index 143973e..076c312 100644
--- a/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
+++ b/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
@@ -33,12 +33,6 @@ import java.nio.ByteBuffer;
 import java.util.Properties;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
@@ -50,7 +44,6 @@ import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 import org.eclipse.jetty.http.HttpTester;
 import org.eclipse.jetty.servlet.ServletTester;
-import org.w3c.dom.Document;
 
 public class TestUtils {
 
@@ -113,16 +106,6 @@ public class TestUtils {
     return tempDir;
   }
 
-  public static void dumpXml( Document document ) throws TransformerException {
-    Transformer transformer = TransformerFactory.newInstance().newTransformer();
-    transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
-    StreamResult result = new StreamResult( new StringWriter() );
-    DOMSource source = new DOMSource( document );
-    transformer.transform( source, result );
-    String xmlString = result.getWriter().toString();
-    System.out.println( xmlString );
-  }
-
   public static void LOG_ENTER() {
     StackTraceElement caller = Thread.currentThread().getStackTrace()[2];
     System.out.flush();

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
index 0763ea5..798c84f 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
@@ -19,7 +19,6 @@ package org.apache.hadoop.gateway.deploy;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.StringWriter;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Arrays;
@@ -29,12 +28,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
@@ -262,7 +256,6 @@ public class DeploymentFactoryFuncTest {
 //    File file = war.as( ExplodedExporter.class ).exportExploded( dir, "test-cluster.war"
);
 
     Document web = XmlUtils.readXml( war.get( "%2F/WEB-INF/web.xml" ).getAsset().openStream()
);
-    //TestUtils.dumpXml( web );
     assertThat( web, hasXPath( "/web-app" ) );
     assertThat( web, hasXPath( "/web-app/servlet" ) );
     assertThat( web, hasXPath( "/web-app/servlet/servlet-name" ) );
@@ -659,16 +652,6 @@ public class DeploymentFactoryFuncTest {
 
   }
 
-  private void dump( Document document ) throws TransformerException {
-    Transformer transformer = TransformerFactory.newInstance().newTransformer();
-    transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
-    StreamResult result = new StreamResult( new StringWriter() );
-    DOMSource source = new DOMSource( document );
-    transformer.transform( source, result );
-    String xmlString = result.getWriter().toString();
-    System.out.println( xmlString );
-  }
-
   private Node node( Node scope, String expression ) throws XPathExpressionException {
     return (Node)XPathFactory.newInstance().newXPath().compile( expression ).evaluate( scope,
XPathConstants.NODE );
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/d82f834c/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
index 44bd3b1..a5d6009 100644
--- a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
@@ -18,7 +18,6 @@ package org.apache.hadoop.gateway.util;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Writer;
@@ -59,23 +58,39 @@ public class XmlUtils {
   }
 
   public static void writeXml( Document document, Writer writer ) throws TransformerException
{
-    TransformerFactory f = TransformerFactory.newInstance();
-//    if( f.getClass().getPackage().getName().equals( "com.sun.org.apache.xalan.internal.xsltc.trax"
) ) {
-      f.setAttribute( "indent-number", 4 );
-//    }
-    Transformer t = f.newTransformer();
-    t.setOutputProperty( OutputKeys.INDENT, "yes" );
-    t.setOutputProperty( "{xml.apache.org/xslt}indent-amount", "4" );
+    Transformer t = XmlUtils.getTransformer( false, true, 4, false );
+    writeXml( document, writer, t );
+  }
+  
+  public static void writeXml( Document document, Writer writer, Transformer transformer
) throws TransformerException {
     DOMSource s = new DOMSource( document );
     StreamResult r = new StreamResult( writer );
-    t.transform( s, r );
+    transformer.transform( s, r );
   }
-
-  public static void writeXml( Document document, File file ) throws TransformerException,
IOException {
-    writeXml( document, new FileWriter( file ) );
+  
+  public static Transformer getTransformer( boolean standalone, boolean indent, int indentNumber,
+                                            boolean omitXmlDeclaration) throws TransformerException
{
+    TransformerFactory f = TransformerFactory.newInstance();
+    f.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
+    if ( indent ) {
+      f.setAttribute( "indent-number", indentNumber );
+    }
+    
+    Transformer t = f.newTransformer();
+    if ( standalone ) {
+      t.setOutputProperty( OutputKeys.STANDALONE, "yes" );
+    }
+    if ( indent ) {
+      t.setOutputProperty( OutputKeys.INDENT, "yes" );
+      t.setOutputProperty( "{xml.apache.org/xslt}indent-amount", "" + indentNumber );
+    }
+    if ( omitXmlDeclaration ) {
+      t.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );
+    }
+    
+    return t;
   }
 
-
   public static Document createDocument() throws ParserConfigurationException {
     return createDocument(true);
   }


Mime
View raw message