You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sa...@apache.org on 2004/12/10 19:46:43 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler Output.java Parser.java SyntaxTreeNode.java

santiagopg    2004/12/10 10:46:43

  Modified:    java/src/org/apache/xalan/xsltc/compiler Output.java
                        Parser.java SyntaxTreeNode.java
  Log:
  Patch for Jira 1761. Output properties from multiple xsl:output instructions are now correctly merged (previously, only cdata-section-elements were handled correctly).
  
  Revision  Changes    Path
  1.27      +49 -18    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Output.java
  
  Index: Output.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Output.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- Output.java	15 Jul 2004 07:00:18 -0000	1.26
  +++ Output.java	10 Dec 2004 18:46:42 -0000	1.27
  @@ -58,9 +58,8 @@
       private String  _cdata;
       private boolean _indent = false;
       private String  _mediaType;
  -    private String  _cdataToMerge;
       private String _indentamount;
  -
  +    
       // Disables this output element (when other element has higher precedence)
       private boolean _disabled = false;
   
  @@ -98,8 +97,41 @@
       	return _method;
       }
       
  -    public void mergeCdata(String cdata) {
  -	_cdataToMerge = cdata;
  +    private void transferAttribute(Output previous, String qname) {
  +        if (!hasAttribute(qname) && previous.hasAttribute(qname)) {
  +            addAttribute(qname, previous.getAttribute(qname));            
  +        }        
  +    }
  +    
  +    public void mergeOutput(Output previous) {
  +        // Transfer attributes from previous xsl:output
  +        transferAttribute(previous, "version");
  +        transferAttribute(previous, "method");
  +        transferAttribute(previous, "encoding");
  +        transferAttribute(previous, "doctype-system");
  +        transferAttribute(previous, "doctype-public");      
  +        transferAttribute(previous, "media-type");
  +        transferAttribute(previous, "indent");        
  +        transferAttribute(previous, "omit-xml-declaration");
  +        transferAttribute(previous, "standalone");
  +        
  +        // Merge cdata-section-elements
  +        if (previous.hasAttribute("cdata-section-elements")) {
  +            // addAttribute works as a setter if it already exists
  +            addAttribute("cdata-section-elements",
  +                previous.getAttribute("cdata-section-elements") + ' ' +
  +                getAttribute("cdata-section-elements"));
  +        }
  +
  +        // Transfer non-standard attributes as well
  +        String prefix = lookupPrefix("http://xml.apache.org/xalan");
  +        if (prefix != null) {
  +            transferAttribute(previous, prefix + ':' + "indent-amount");
  +        }
  +        prefix = lookupPrefix("http://xml.apache.org/xslt");
  +        if (prefix != null) {
  +            transferAttribute(previous, prefix + ':' + "indent-amount");
  +        }                
       }
   
       /**
  @@ -118,7 +150,7 @@
   
   	// Get the output version
   	_version = getAttribute("version");
  -	if (_version == null || _version.equals(Constants.EMPTYSTRING)) {
  +	if (_version.equals(Constants.EMPTYSTRING)) {
   	    _version = null;
   	}
   	else {
  @@ -150,8 +182,8 @@
   	else {
   	    try {
   		// Create a write to verify encoding support
  -        String canonicalEncoding;
  -        canonicalEncoding = Encodings.convertMime2JavaEncoding(_encoding);
  +                String canonicalEncoding;
  +                canonicalEncoding = Encodings.convertMime2JavaEncoding(_encoding);
   		OutputStreamWriter writer =
   		    new OutputStreamWriter(System.out, canonicalEncoding); 
   	    }
  @@ -165,7 +197,7 @@
   
   	// Should the XML header be omitted - translate to true/false
   	attrib = getAttribute("omit-xml-declaration");
  -	if (attrib != null && !attrib.equals(Constants.EMPTYSTRING)) {
  +	if (!attrib.equals(Constants.EMPTYSTRING)) {
   	    if (attrib.equals("yes")) {
   		_omitHeader = true;
   	    }
  @@ -201,7 +233,7 @@
   
   	// Names the elements of whose text contents should be output as CDATA
   	_cdata = getAttribute("cdata-section-elements");
  -	if (_cdata != null && _cdata.equals(Constants.EMPTYSTRING)) {
  +	if (_cdata.equals(Constants.EMPTYSTRING)) {
   	    _cdata = null;
   	}
   	else {
  @@ -219,16 +251,13 @@
           	   parser.getQName(qname).toString()).append(' ');
   	    }
   	    _cdata = expandedNames.toString();
  -	    if (_cdataToMerge != null) {
  -		_cdata = _cdata + _cdataToMerge;
  -	    }
   	    outputProperties.setProperty(OutputKeys.CDATA_SECTION_ELEMENTS, 
   		_cdata);
   	}
   
   	// Get the indent setting - only has effect for xml and html output
   	attrib = getAttribute("indent");
  -	if (attrib != null && !attrib.equals(EMPTYSTRING)) {
  +	if (!attrib.equals(EMPTYSTRING)) {
   	    if (attrib.equals("yes")) {
   		_indent = true;
   	    }
  @@ -239,12 +268,14 @@
   	}
   	
           // indent-amount: extension attribute of xsl:output
  -        _indentamount = getAttributes().getValue(lookupPrefix("http://xml.apache.org/xalan"),"indent-amount");
  +        _indentamount = getAttribute(
  +            lookupPrefix("http://xml.apache.org/xalan"), "indent-amount");
           //  Hack for supporting Old Namespace URI.
  -        if(_indentamount == null || _indentamount.equals(EMPTYSTRING)){
  -            _indentamount = getAttributes().getValue(lookupPrefix("http://xml.apache.org/xslt"),"indent-amount");
  +        if (_indentamount.equals(EMPTYSTRING)){
  +            _indentamount = getAttribute(
  +                lookupPrefix("http://xml.apache.org/xslt"), "indent-amount");
           }
  -        if(_indentamount != null && !_indentamount.equals(EMPTYSTRING)) {
  +        if (!_indentamount.equals(EMPTYSTRING)) {
               outputProperties.setProperty("indent_amount", _indentamount);
           }
           
  
  
  
  1.66      +4 -4      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- Parser.java	21 May 2004 20:29:28 -0000	1.65
  +++ Parser.java	10 Dec 2004 18:46:42 -0000	1.66
  @@ -126,7 +126,7 @@
   	if (_output != null) {
   	    if (_output.getImportPrecedence() <= output.getImportPrecedence()) {
   		String cdata = _output.getCdata();
  -		output.mergeCdata(cdata);
  +                output.mergeOutput(_output);
   		_output.disable();
   		_output = output;
   	    }
  @@ -355,7 +355,7 @@
   		stylesheet = new Stylesheet();
   		stylesheet.setSimplified();
   		stylesheet.addElement(element);
  -		stylesheet.setAttributes(element.getAttributes());
  +		stylesheet.setAttributes((AttributeList) element.getAttributes());
   
   		// Map the default NS if not already defined
   		if (element.lookupNamespace(EMPTYSTRING) == null) {
  @@ -1251,7 +1251,7 @@
   	    parent.addElement(element);
   	    element.setParent(parent);
   	}
  -	element.setAttributes((Attributes)new AttributeList(attributes));
  +	element.setAttributes(new AttributeList(attributes));
   	element.setPrefixMapping(_prefixMapping);
   	
   	if (element instanceof Stylesheet) {
  
  
  
  1.31      +13 -3     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
  
  Index: SyntaxTreeNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- SyntaxTreeNode.java	21 May 2004 20:29:28 -0000	1.30
  +++ SyntaxTreeNode.java	10 Dec 2004 18:46:42 -0000	1.31
  @@ -43,10 +43,12 @@
   import org.apache.xalan.xsltc.compiler.util.Type;
   import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
   import org.apache.xalan.xsltc.DOM;
  +import org.apache.xalan.xsltc.runtime.AttributeList;
   
   import org.xml.sax.Attributes;
   
   
  +
   /**
    * @author Jacek Ambroziak
    * @author Santiago Pericas-Geertsen
  @@ -69,7 +71,7 @@
       // Element description data
       protected QName _qname;                    // The element QName
       private int _line;                         // Source file line number
  -    protected Attributes _attributes = null;   // Attributes of this element
  +    protected AttributeList _attributes = null;   // Attributes of this element
       private   Hashtable _prefixMapping = null; // Namespace declarations
   
       // Sentinel - used to denote unrecognised syntaxt tree nodes.
  @@ -160,7 +162,7 @@
        * @param attributes Attributes for the element. Must be passed in as an
        *                   implementation of org.xml.sax.Attributes.
        */
  -    protected void setAttributes(Attributes attributes) {
  +    protected void setAttributes(AttributeList attributes) {
   	_attributes = attributes;
       }
   
  @@ -177,9 +179,17 @@
   	return (value == null || value.equals(EMPTYSTRING)) ? 
   	    EMPTYSTRING : value;
       }
  +    
  +    protected String getAttribute(String prefix, String localName) {
  +        return getAttribute(prefix + ':' + localName);
  +    }
   
       protected boolean hasAttribute(String qname) {
   	return (_attributes != null && _attributes.getValue(qname) != null);
  +    }
  +    
  +    protected void addAttribute(String qname, String value) {
  +        _attributes.add(qname, value);
       }
   
       /**
  
  
  

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