This is Joerg's message with the unidiff patch attached.



Ovidiu,

Ovidiu Predescu wrote:
> 
> Can you please post a unidiff patch? You can generate one with

sorry, I just blindly used what Netbeans gave me. Here you go.

Joerg Henne
Index: AbstractTextSerializer.java
===================================================================
RCS file: 
/home/cvspublic/xml-cocoon2/src/org/apache/cocoon/serialization/AbstractTextSerializer.java,v
retrieving revision 1.3
diff -u -r1.3 AbstractTextSerializer.java
--- AbstractTextSerializer.java 2001/08/20 13:55:16     1.3
+++ AbstractTextSerializer.java 2001/08/21 09:43:19
@@ -26,6 +26,8 @@
 import javax.xml.transform.sax.SAXTransformerFactory;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
 import java.util.Properties;
 
 /**
@@ -58,6 +60,13 @@
     private List uriList = new ArrayList();
 
     /**
+     * Maps of URI<->prefix mappings. Used to work around a bug in the Xalan
+     * serializer.
+     */
+    private Map uriToPrefixMap = new HashMap();
+    private Map prefixToUriMap = new HashMap();
+
+    /**
      * True if there has been some startPrefixMapping() for the coming element.
      */
     private boolean hasMappings = false;
@@ -152,6 +161,8 @@
      */
     public void recycle() {
         clearMappings();
+        this.uriToPrefixMap.clear();
+        this.prefixToUriMap.clear();
         super.recycle();
     }
 
@@ -176,10 +187,32 @@
         this.prefixList.add(prefix);
         this.uriList.add(uri);
 
+        // store mappings for xalan-bug-workaround.
+        // append the prefix colon now, in order to save concatenations later.
+        this.uriToPrefixMap.put(uri, prefix + ":");
+        this.prefixToUriMap.put(prefix, uri);
+        
         super.startPrefixMapping(prefix, uri);
     }
 
     /**
+     * End the scope of a prefix-URI mapping:
+     * remove entry from mapping tables.
+     */
+    public void endPrefixMapping(String prefix)
+      throws SAXException {
+        // remove mappings for xalan-bug-workaround.
+        // Unfortunately, we're not passed the uri, but the prefix here,
+        // so we need to maintain maps in both directions.
+        if(this.prefixToUriMap.containsKey(prefix)) {
+          this.uriToPrefixMap.remove((String) this.prefixToUriMap.get(prefix));
+          this.prefixToUriMap.remove(prefix);
+        }
+        
+        super.endPrefixMapping(prefix);
+    }
+
+    /**
      * Ensure all namespace declarations are present as <code>xmlns:</code> attributes
      * and add those needed before calling superclass. This is a workaround for a 
Xalan bug
      * (at least in version 2.0.1) : 
<code>org.apache.xalan.serialize.SerializerToXML</code>
@@ -187,7 +220,11 @@
      */
     public void startElement(String eltUri, String eltLocalName, String eltQName, 
Attributes attrs)
       throws SAXException {
-
+        
+        // try to restore the qName. The map already contains the colon
+        if(eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri) )
+          eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
+        
         if (this.hasMappings) {
             // Add xmlns* attributes where needed
 
@@ -247,6 +284,19 @@
             // Normal job
             super.startElement(eltUri, eltLocalName, eltQName, attrs);
         }
+    }
+
+    /**
+     * Receive notification of the end of an element.
+     * Try to restore the element qName.
+     */
+    public void endElement(String eltUri, String eltLocalName, String eltQName)
+    throws SAXException {
+        // try to restore the qName. The map already contains the colon
+        if(eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri) )
+          eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
+        
+        super.endElement(eltUri, eltLocalName, eltQName);
     }
 
     private void clearMappings()


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to