xml-xalan-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minc...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xml/serializer ToXMLSAXHandler.java ToSAXHandler.java
Date Tue, 21 Oct 2003 23:18:56 GMT
minchau     2003/10/21 16:18:55

  Modified:    java/src/org/apache/xml/serializer ToXMLSAXHandler.java
                        ToSAXHandler.java
  Log:
  PR: bugzilla 7205
  Submitted by:	Richard Cao
  Reviewed by:	Brian Minchau/Henry Zongaro
  Do NOT  have ToXMLSAXHandler always mirror namespaces given via
  startPrefixMapping("prefix1", "uri1")
   as attribute values of the form xmlns:prefix1="uri1"
  
  Revision  Changes    Path
  1.10      +36 -29    xml-xalan/java/src/org/apache/xml/serializer/ToXMLSAXHandler.java
  
  Index: ToXMLSAXHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToXMLSAXHandler.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ToXMLSAXHandler.java	21 Oct 2003 19:27:37 -0000	1.9
  +++ ToXMLSAXHandler.java	21 Oct 2003 23:18:55 -0000	1.10
  @@ -401,28 +401,33 @@
           {
               m_saxHandler.startPrefixMapping(prefix,uri);
               
  -            /* bjm: don't know if we really needto do this. The
  -             * callers of this object should have injected both
  -             * startPrefixMapping and the attributes.  We are
  -             * just covering our butt here.
  -             */
  -            String name;
  -            if (EMPTYSTRING.equals(prefix))
  +            if (getShouldOutputNSAttr()) 
               {
  -                name = "xmlns";
  -                addAttributeAlways(XMLNS_URI, prefix, name,"CDATA",uri);
  -            }
  -            else {
  -                if (!EMPTYSTRING.equals(uri)) // hack for XSLTC attribset16 test
  -                {                             // that maps ns1 prefix to "" URI 
  -                    name = "xmlns:" + prefix;
  -
  -                    /* for something like xmlns:abc="w3.pretend.org"
  -             	 	 *  the      uri is the value, that is why we pass it in the
  -             	 	 * value, or 5th slot of addAttributeAlways()
  -                 	 */
  -                    addAttributeAlways(XMLNS_URI, prefix, name,"CDATA",uri);
  -                }
  +
  +	              /* bjm: don't know if we really needto do this. The
  +	               * callers of this object should have injected both
  +	               * startPrefixMapping and the attributes.  We are
  +	               * just covering our butt here.
  +	               */
  +	              String name;
  +  	            if (EMPTYSTRING.equals(prefix))
  +  	            {
  +  	                name = "xmlns";
  +  	                addAttributeAlways(XMLNS_URI, prefix, name,"CDATA",uri);
  +  	            }
  +  	            else 
  +                {
  +  	                if (!EMPTYSTRING.equals(uri)) // hack for XSLTC attribset16 test
  +  	                {                             // that maps ns1 prefix to "" URI 
  +  	                    name = "xmlns:" + prefix;
  +  	
  +  	                    /* for something like xmlns:abc="w3.pretend.org"
  +  	             	 	     *  the uri is the value, that is why we pass it in the
  +  	             	 	     * value, or 5th slot of addAttributeAlways()
  +  	                 	   */
  +  	                    addAttributeAlways(XMLNS_URI, prefix, name,"CDATA",uri);
  +  	                }
  +  	            }
               }
           }
           return pushed;
  @@ -733,14 +738,16 @@
                   {
                       this.startPrefixMapping(prefix, ns, false);
   
  -                    // Bugzilla1133: Generate attribute as well as namespace event.
  -                    // SAX does expect both.
  -                    this.addAttributeAlways(
  -                        "http://www.w3.org/2000/xmlns/",
  -                        prefix,
  -                        "xmlns" + (prefix.length() == 0 ? "" : ":") + prefix,
  -                        "CDATA",
  -                        ns);
  +                    if (getShouldOutputNSAttr()) {
  +                        // Bugzilla1133: Generate attribute as well as namespace event.
  +                        // SAX does expect both.
  +                        this.addAttributeAlways(
  +                            "http://www.w3.org/2000/xmlns/",
  +                            prefix,
  +                            "xmlns" + (prefix.length() == 0 ? "" : ":") + prefix,
  +                            "CDATA",
  +                            ns);
  +                    }
                   }
   
               }
  
  
  
  1.9       +33 -0     xml-xalan/java/src/org/apache/xml/serializer/ToSAXHandler.java
  
  Index: ToSAXHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToSAXHandler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ToSAXHandler.java	21 Oct 2003 19:27:37 -0000	1.8
  +++ ToSAXHandler.java	21 Oct 2003 23:18:55 -0000	1.9
  @@ -100,6 +100,16 @@
        */
       protected LexicalHandler m_lexHandler;
   
  +    /**
  +     * A startPrefixMapping() call on a ToSAXHandler will pass that call
  +     * on to the wrapped ContentHandler, but should we also mirror these calls
  +     * with matching attributes, if so this field is true.
  +     * For example if this field is true then a call such as
  +     * startPrefixMapping("prefix1","uri1") will also cause the additional
  +     * internally generated attribute xmlns:prefix1="uri1" to be effectively added
  +     * to the attributes passed to the wrapped ContentHandler.
  +     */ 
  +    private boolean m_shouldGenerateNSAttribute = true;
       
       /** If this is true, then the content handler wrapped by this
        * serializer implements the TransformState interface which
  @@ -278,6 +288,28 @@
       {
           // do nothing
       }
  +    
  +    /** Set whether or not namespace declarations (e.g. 
  +     * xmlns:foo) should appear as attributes of 
  +     * elements
  +     * @param doOutputNSAttr whether or not namespace declarations
  +     * should appear as attributes
  +     */
  +    public void setShouldOutputNSAttr(boolean doOutputNSAttr)
  +    {
  +        m_shouldGenerateNSAttribute = doOutputNSAttr;
  +    }
  + 
  +    /** 
  +     * Returns true if namespace declarations from calls such as
  +     * startPrefixMapping("prefix1","uri1") should
  +     * also be mirrored with self generated additional attributes of elements 
  +     * that declare the namespace, for example the attribute xmlns:prefix1="uri1"
  +     */
  +    boolean getShouldOutputNSAttr()
  +    {
  +        return m_shouldGenerateNSAttribute;
  +    }
   
       /**
        * This method flushes any pending events, which can be startDocument()
  @@ -442,6 +474,7 @@
           this.m_lexHandler = null;
           this.m_saxHandler = null;
           this.m_state = null;
  +        this.m_shouldGenerateNSAttribute = false;
       }  
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message