You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2007/06/06 17:40:58 UTC

svn commit: r544869 - in /webservices/axis2/trunk/java/modules: java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java kernel/src/org/apache/axis2/description/java2wsdl/Java2WSDLUtils.java kernel/src/org/apache/axis2/util/XMLPrettyPrinter.java

Author: dims
Date: Wed Jun  6 08:40:54 2007
New Revision: 544869

URL: http://svn.apache.org/viewvc?view=rev&rev=544869
Log:
- Move the xml pretty stuff from Java2WSDLUtils to XMLPrettyPrinter where it belongs.
- Pretty print services.xml, build.xml and wsdl's wsdl2java much better now
- Get rid of JTidy dependency.
- Fix for AXIS2-2671 - XMLPrettyPrinterExtension => off (No need to switch it off, just make the one we use better!)




Modified:
    webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/Java2WSDLUtils.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLPrettyPrinter.java

Modified: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java?view=diff&rev=544869&r1=544868&r2=544869
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java Wed Jun  6 08:40:54 2007
@@ -12,6 +12,7 @@
 import org.apache.axis2.description.AxisService2WSDL11;
 import org.apache.axis2.description.AxisService2WSDL20;
 import org.apache.axis2.util.Loader;
+import org.apache.axis2.util.XMLPrettyPrinter;
 import org.apache.axis2.engine.MessageReceiver;
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.context.ConfigurationContext;
@@ -227,7 +228,7 @@
             if(!isPretty()){
                 wsdlElement.serialize(out);
             } else {
-                Java2WSDLUtils.prettyPrint(wsdlElement, out);
+                XMLPrettyPrinter.prettify(wsdlElement, out);
             }
         } else {
             AxisService2WSDL20 g = new AxisService2WSDL20(axisService);
@@ -235,7 +236,7 @@
             if(!isPretty()){
                 wsdlElement.serialize(out);
             } else {
-                Java2WSDLUtils.prettyPrint(wsdlElement, out);
+                XMLPrettyPrinter.prettify(wsdlElement, out);
             }
         }
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/Java2WSDLUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/Java2WSDLUtils.java?view=diff&rev=544869&r1=544868&r2=544869
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/Java2WSDLUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/Java2WSDLUtils.java Wed Jun  6 08:40:54 2007
@@ -138,33 +138,4 @@
             ret = name.substring(0, lastDot);
         return ret;
     }
-
-    private static final String prettyPrintStylesheet =
-                     "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0' " +
-                             " xmlns:xalan='http://xml.apache.org/xslt' " +
-                             " exclude-result-prefixes='xalan'>" +
-                     "  <xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
-                     "  <xsl:strip-space elements='*'/>" +
-                     "  <xsl:template match='/'>" +
-                     "    <xsl:apply-templates/>" +
-                     "  </xsl:template>" +
-                     "  <xsl:template match='node() | @*'>" +
-                     "        <xsl:copy>" +
-                     "          <xsl:apply-templates select='node() | @*'/>" +
-                     "        </xsl:copy>" +
-                     "  </xsl:template>" +
-                     "</xsl:stylesheet>";
-
-    public static void prettyPrint(OMElement wsdlElement, OutputStream out) throws Exception {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        wsdlElement.serialize(baos);
-
-        Source stylesheetSource = new StreamSource(new ByteArrayInputStream(prettyPrintStylesheet.getBytes()));
-        Source xmlSource = new StreamSource(new ByteArrayInputStream(baos.toByteArray()));
-
-        TransformerFactory tf = TransformerFactory.newInstance();
-        Templates templates = tf.newTemplates(stylesheetSource);
-        Transformer transformer = templates.newTransformer();
-        transformer.transform(xmlSource, new StreamResult(out));
-    }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLPrettyPrinter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLPrettyPrinter.java?view=diff&rev=544869&r1=544868&r2=544869
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLPrettyPrinter.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLPrettyPrinter.java Wed Jun  6 08:40:54 2007
@@ -2,12 +2,22 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.description.java2wsdl.Java2WSDLUtils;
 
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.stream.StreamResult;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
 import java.lang.reflect.Method;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
@@ -43,24 +53,6 @@
      */
     public static void prettify(File file) {
         try {
-            // Create an instance of the Jalopy bean
-            Class clazz = Loader.loadClass("org.w3c.tidy.Tidy");
-            Object prettifier = clazz.newInstance();
-
-            //set the input to be xml
-            Method setXmlInFlagMethod = clazz.getMethod(
-                    "setXmlTags",
-                    new Class[]{boolean.class});
-            setXmlInFlagMethod.invoke(prettifier,
-                                      new Object[]{Boolean.TRUE});
-
-            //set the output to be xml
-            Method setXmlOutFlagMethod = clazz.getMethod(
-                    "setXmlOut",
-                    new Class[]{boolean.class});
-            setXmlOutFlagMethod.invoke(prettifier,
-                                       new Object[]{Boolean.TRUE});
-
             //create the input stream
             InputStream input = new FileInputStream(file);
 
@@ -71,15 +63,14 @@
 
             File tempFile = new File(tempFileName);
             FileOutputStream tempFileOutputStream = new FileOutputStream(tempFile);
-            //Call the pretty printer
-            Method parsr = clazz.getMethod("parse", new Class[]{
-                    InputStream.class,
-                    OutputStream.class});
 
-            parsr.invoke(prettifier, new Object[]{input,
-                    tempFileOutputStream});
+            Source stylesheetSource = new StreamSource(new ByteArrayInputStream(prettyPrintStylesheet.getBytes()));
+            Source xmlSource = new StreamSource(input);
 
-            //rename and restore the pretty printed one as the original
+            TransformerFactory tf = TransformerFactory.newInstance();
+            Templates templates = tf.newTemplates(stylesheetSource);
+            Transformer transformer = templates.newTransformer();
+            transformer.transform(xmlSource, new StreamResult(tempFileOutputStream));
 
             //first close the streams. if not this may cause the
             // files not to be renamed
@@ -103,4 +94,32 @@
     }
 
 
+    private static final String prettyPrintStylesheet =
+                     "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0' " +
+                             " xmlns:xalan='http://xml.apache.org/xslt' " +
+                             " exclude-result-prefixes='xalan'>" +
+                     "  <xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
+                     "  <xsl:strip-space elements='*'/>" +
+                     "  <xsl:template match='/'>" +
+                     "    <xsl:apply-templates/>" +
+                     "  </xsl:template>" +
+                     "  <xsl:template match='node() | @*'>" +
+                     "        <xsl:copy>" +
+                     "          <xsl:apply-templates select='node() | @*'/>" +
+                     "        </xsl:copy>" +
+                     "  </xsl:template>" +
+                     "</xsl:stylesheet>";
+
+    public static void prettify(OMElement wsdlElement, OutputStream out) throws Exception {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        wsdlElement.serialize(baos);
+
+        Source stylesheetSource = new StreamSource(new ByteArrayInputStream(prettyPrintStylesheet.getBytes()));
+        Source xmlSource = new StreamSource(new ByteArrayInputStream(baos.toByteArray()));
+
+        TransformerFactory tf = TransformerFactory.newInstance();
+        Templates templates = tf.newTemplates(stylesheetSource);
+        Transformer transformer = templates.newTransformer();
+        transformer.transform(xmlSource, new StreamResult(out));
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org