Joerg,

Applied the patch partially. Please take a look at the latest CVS and look for the 
string "FIXME"
in 2 locations, If you uncomment the two lines of code after each FIXME, some of the 
samples don't
work. They are garbled. Can you please test against a few browsers and then send us an 
update?

Thanks,
dims

--- Joerg Henne <[EMAIL PROTECTED]> wrote:
> [This is a re-post of a pending patch.]
> 
> Joerg Henne wrote:
> > 
> > Hi,
> > 
> > the way I read the SAX specification, the qName (or raw name) of elements that
> > is passed to the callback methods is of purely informal character and does not
> > necessarily contain the full (raw) element name. However, C2's serialization
> > to XML results in the qName being used to name the output elements. This is
> > due to the missing or incomplete namespace support in the SerializerToXML from
> > Xalan which is used.
> > 
> > AbstractTextSerializer already contains code to work around Xalan problems, so
> > it could fix this problem as well, although fixing it comes at the cost of 2
> > hashtable lookups and string concatenations per element. If you agree that
> > this should be done, the following patch will do the job.
> > 
> > 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]


=====
Davanum Srinivas, JNI-FAQ Manager
http://www.jGuru.com/faq/JNI

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

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

Reply via email to