Author: seanoc
Date: Fri Jan 23 08:26:07 2009
New Revision: 737069

URL: http://svn.apache.org/viewvc?rev=737069&view=rev
Log:
Made change as per Dan's suggestion, looks to work on both Windows and Linux.

Modified:
    
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
    
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java

Modified: 
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java?rev=737069&r1=737068&r2=737069&view=diff
==============================================================================
--- 
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
 (original)
+++ 
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
 Fri Jan 23 08:26:07 2009
@@ -22,16 +22,15 @@
 
 import java.io.OutputStream;
 import java.io.PrintWriter;
-
+import java.io.StringWriter;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import org.w3c.dom.DOMConfiguration;
-import org.w3c.dom.bootstrap.DOMImplementationRegistry;
-import org.w3c.dom.ls.DOMImplementationLS;
-import org.w3c.dom.ls.LSInput;
-import org.w3c.dom.ls.LSParser;
-import org.w3c.dom.ls.LSSerializer;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.io.CacheAndWriteOutputStream;
@@ -79,33 +78,35 @@
         }
 
         public void onClose(CachedOutputStream cos) {
- 
+            
             try {
-                DOMImplementationRegistry registry = 
DOMImplementationRegistry.newInstance();
-                DOMImplementationLS domLS = (DOMImplementationLS) 
registry.getDOMImplementation("LS");
-                LSParser lsParser = 
domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
-
-                LSInput lsInput = domLS.createLSInput();
-                lsInput.setByteStream(cos.getInputStream());
-                org.w3c.dom.Document doc = lsParser.parse(lsInput);
-
-                LSSerializer lsSerializer = domLS.createLSSerializer();
-                DOMConfiguration config = lsSerializer.getDomConfig();
-                config.setParameter("format-pretty-print", true);
-                            
-                String prettyStr = 
lsSerializer.writeToString(doc.getDocumentElement());
+                TransformerFactory tfactory = TransformerFactory.newInstance();
+                try { 
+                    tfactory.setAttribute("indent-number", "2");
+                } catch (Exception ex) {
+                    //ignore
+                }
+                Transformer serializer;
+                serializer = tfactory.newTransformer();
+                //Setup indenting to "pretty print"
+                serializer.setOutputProperty(OutputKeys.INDENT, "yes");
+                
serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount";, "2");
+ 
                 if (writer != null) {
-                    writer.println(prettyStr);
+                    serializer.transform(new 
StreamSource(cos.getInputStream()),
+                                     new StreamResult(writer));
+ 
                     writer.close();
                 } else if (LOG.isLoggable(Level.INFO)) {
-                    System.out.println("writer is null " + prettyStr);
-                    LOG.info(prettyStr);
+                    StringWriter swriter = new StringWriter();
+                    serializer.transform(new 
StreamSource(cos.getInputStream()),
+                                         new StreamResult(swriter));
+                    LOG.info(swriter.toString());
                 }
-         
+ 
             } catch (Exception e) {
                 e.printStackTrace();
             }
-
         }
     }
 }
\ No newline at end of file

Modified: 
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java?rev=737069&r1=737068&r2=737069&view=diff
==============================================================================
--- 
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java
 (original)
+++ 
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java
 Fri Jan 23 08:26:07 2009
@@ -25,13 +25,10 @@
 import org.apache.cxf.io.CachedOutputStream;
 
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class PrettyLoggingOutInterceptorTest extends Assert {
     
-    
-    @Ignore
     @Test
     public void testFormatting() throws Exception { 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -51,7 +48,4 @@
         assertTrue(str.contains("<today>"));
 
     }
-    
-
-
 }


Reply via email to