You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2001/05/08 11:21:00 UTC

[Bug 1648] New - Comments in Source Document not present in Result

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1648

*** shadow/1648	Tue May  8 02:21:00 2001
--- shadow/1648.tmp.29356	Tue May  8 02:21:00 2001
***************
*** 0 ****
--- 1,76 ----
+ +============================================================================+
+ | Comments in Source Document not present in Result                          |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 1648                        Product: XalanJ2                 |
+ |       Status: NEW                         Version: 2.0.1                   |
+ |   Resolution:                            Platform: PC                      |
+ |     Severity: Normal                   OS/Version:                         |
+ |     Priority: Medium                    Component: javax.xml               |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: xalan-dev@xml.apache.org                                     |
+ |  Reported By: johnkeyes@yahoo.com                                          |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ The test case is included below.  As you see the Transformer is
+ a static member variable.  The if checks to see if the
+ Transformer has been instantiated and if not then instantiate
+ it.  If I remove the if and just create a new Transformer each
+ time the behaviour is as I would expect with the comments appearing
+ in the writer all the time.  When the if is in the code the comments
+ appear the first time print is invoked but never subsequently.
+ 
+ ### SOF ###
+ public class Dom2Writer {
+ /**
+  * The JAXP transformer factory
+  */
+  private static final TransformerFactory tfactory 
+      = TransformerFactory.newInstance();
+  
+  /**
+   * The XSLT transformer
+   */
+   private static Transformer serializer;
+  
+  /**
+   * Prints the resulting document tree to the given output stream.
+   * @param   xmlDoc      - The XML Document tree
+   * @param   out         - The output stream to write the result to.
+   * @exception
+   */
+   public void print(Document xmlDoc,Writer out)
+       throws javax.xml.transform.TransformerException
+   {
+       if (serializer == null) {
+           try {
+               synchronized(serializer) {
+                   serializer = tfactory.newTransformer();
+               }
+           }
+           catch (TransformerConfigurationException tce) {
+               tce.printStackTrace(System.err);
+           }
+       }
+  
+       synchronized (serializer) {
+  
+           try {
+               // Run the transformation
+               serializer.transform(
+                   new DOMSource( xmlData ),
+                   new StreamResult( out )
+               );
+           }
+           catch (TransformerException te) {
+               te.printStackTrace(System.err);
+           }
+           catch(IllegalArgumentException ill) {
+               ill.printStackTrace(System.err); 
+           }
+       }
+   }
+ }
+ ### EOF ###