You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Joerg Henne <j....@levigo.de> on 2001/09/18 16:43:22 UTC

[Fwd: [C2 patch] Incorrect serialization to XML]

[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

Re: [Fwd: [C2 patch] Incorrect serialization to XML]

Posted by Joerg Henne <j....@levigo.de>.
giacomo wrote:
> 
> If you think this is a Xalan bug, please send it to the xalan-dev list
> as well. It doesn't make sense to implement workaround if the problem is
> in another projects responsability which can be solved by adding an
> additional mail address.

after reading the SAX specification, I'm pretty sure that it's indeed a bug.
I'll report it to the xalan list, however, handling the additional case of a
null reference (instead of a reference to the empty string) helps making the
code a wee bit more robust, so I think we should keep it.

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [Fwd: [C2 patch] Incorrect serialization to XML]

Posted by giacomo <gi...@apache.org>.
On Wed, 19 Sep 2001, Joerg Henne wrote:

> Dims,
>
> Davanum Srinivas wrote:
> >
> > 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?
>
> it seems like Xalan dometimes generates null namespace URIs. The attached
> patch safeguards against this situation. There was another problem with empty
> prefix-mappings to the default namespace. This problem is fixed now as well.
> Can you please check if you experience problems anymore?

If you think this is a Xalan bug, please send it to the xalan-dev list
as well. It doesn't make sense to implement workaround if the problem is
in another projects responsability which can be solved by adding an
additional mail address.

Giacomo


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [Fwd: [C2 patch] Incorrect serialization to XML]

Posted by Joerg Henne <j....@levigo.de>.
Dims,

Davanum Srinivas wrote:
> 
> 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?

it seems like Xalan dometimes generates null namespace URIs. The attached
patch safeguards against this situation. There was another problem with empty
prefix-mappings to the default namespace. This problem is fixed now as well.
Can you please check if you experience problems anymore?

Joerg Henne

Re: [Fwd: [C2 patch] Incorrect serialization to XML]

Posted by Davanum Srinivas <di...@yahoo.com>.
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 <j....@levigo.de> 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: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org


=====
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: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org