santiagopg    2002/06/18 15:29:27

  Modified:    java/src/org/apache/xalan/xsltc/compiler Output.java
               java/src/org/apache/xalan/xsltc/runtime/output
                        OutputBase.java SAXOutput.java SAXXMLOutput.java
                        StreamHTMLOutput.java StreamOutput.java
                        StreamXMLOutput.java
  Log:
  Fixed problem with cdata-section-elements in xsl:output and namespaces.
  
  Revision  Changes    Path
  1.15      +12 -1     
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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Output.java       17 Jun 2002 18:37:11 -0000      1.14
  +++ Output.java       18 Jun 2002 22:29:27 -0000      1.15
  @@ -215,6 +215,16 @@
            _cdata = null;
        }
        else {
  +         StringBuffer expandedNames = new StringBuffer();
  +         StringTokenizer tokens = new StringTokenizer(_cdata);
  +
  +         // Make sure to store names in expanded form
  +         while (tokens.hasMoreTokens()) {
  +             
expandedNames.append(parser.getQName(tokens.nextToken()).toString())
  +                          .append(' ');
  +         }
  +         _cdata = expandedNames.toString();
  +
            outputProperties.setProperty(OutputKeys.CDATA_SECTION_ELEMENTS, 
_cdata);
        }
   
  @@ -348,6 +358,7 @@
            int index = cpg.addMethodref(TRANSLET_CLASS,
                                         "addCdataElement",
                                         "(Ljava/lang/String;)V");
  +
            StringTokenizer tokens = new StringTokenizer(_cdata);
            while (tokens.hasMoreTokens()) {
                il.append(DUP);
  
  
  
  1.7       +39 -1     
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/OutputBase.java
  
  Index: OutputBase.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/OutputBase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- OutputBase.java   4 Jun 2002 20:55:37 -0000       1.6
  +++ OutputBase.java   18 Jun 2002 22:29:27 -0000      1.7
  @@ -250,6 +250,44 @@
        }
       }
   
  +    /**
  +     * Use a namespace prefix to lookup a namespace URI
  +     */
  +    protected String lookupNamespace(String prefix) {
  +        final Stack stack = (Stack)_namespaces.get(prefix);
  +        return stack != null && !stack.isEmpty() ? (String)stack.peek() : 
null;
  +    }
  +
  +    /**
  +     * Returns the local name of a qualified name. If the name has 
  +     * no prefix, then it works as the identity (SAX2).
  +     */
  +    protected static String getLocalName(String qname) {
  +        final int col = qname.lastIndexOf(':');
  +        return (col > 0) ? qname.substring(col + 1) : qname;
  +    }
  +
  +    /**
  +     * Returns the URI of an element or attribute. Note that default 
namespaces
  +     * do not apply directly to attributes.
  +     */
  +    protected String getNamespaceURI(String qname, boolean isElement)
  +        throws TransletException
  +    {
  +        String uri = EMPTYSTRING;
  +        int col = qname.lastIndexOf(':');
  +        final String prefix = (col > 0) ? qname.substring(0, col) : 
EMPTYSTRING;
  +
  +        if (prefix != EMPTYSTRING || isElement) {
  +            uri = lookupNamespace(prefix);
  +            if (uri == null && !prefix.equals(XMLNS_PREFIX)) {
  +                BasisLibrary.runTimeError(BasisLibrary.NAMESPACE_PREFIX_ERR,
  +                                          qname.substring(0, col));
  +            }
  +        }
  +        return uri;
  +    }
  +
       // -- Temporary
       public void namespace(String prefix, String uri) throws 
TransletException { }
       public void setType(int type) { }
  
  
  
  1.12      +1 -10     
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/SAXOutput.java
  
  Index: SAXOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/SAXOutput.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SAXOutput.java    11 Jun 2002 20:11:18 -0000      1.11
  +++ SAXOutput.java    18 Jun 2002 22:29:27 -0000      1.12
  @@ -131,15 +131,6 @@
           // Redefined in SAXXMLOutput
       }
   
  -    /**
  -     * Returns the local name of a qualified name. If the name has 
  -     * no prefix, then it works as the identity (SAX2).
  -     */
  -    protected static String getLocalName(String qname) {
  -        final int col = qname.lastIndexOf(':');
  -        return (col > 0) ? qname.substring(col + 1) : qname;
  -    }
  -
       protected void closeStartTag() throws TransletException {
       }
   
  
  
  
  1.11      +16 -36    
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/SAXXMLOutput.java
  
  Index: SAXXMLOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/SAXXMLOutput.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SAXXMLOutput.java 4 Jun 2002 20:55:37 -0000       1.10
  +++ SAXXMLOutput.java 18 Jun 2002 22:29:27 -0000      1.11
  @@ -140,10 +140,6 @@
               _elementName = elementName;
               _attributes.clear();
               _startTagOpen = true;
  -
  -            if (_cdata != null && _cdata.get(elementName) != null) {
  -                _cdataStack.push(new Integer(_depth));
  -         }
        }
           catch (SAXException e) {
               throw new TransletException(e);
  @@ -312,42 +308,26 @@
           try {
               _startTagOpen = false;
   
  +         final String localName = getLocalName(_elementName);
  +         final String uri = getNamespaceURI(_elementName, true);
  +
               // Now is time to send the startElement event
  -            _saxHandler.startElement(getNamespaceURI(_elementName, true),
  -                getLocalName(_elementName), _elementName, _attributes);
  +            _saxHandler.startElement(uri, localName, _elementName, 
  +             _attributes);
  +
  +         if (_cdata != null) {
  +             final StringBuffer expandedName = (uri == EMPTYSTRING) ? 
  +                 new StringBuffer(_elementName) :
  +                 new StringBuffer(uri).append(':').append(localName);
  +
  +             if (_cdata.containsKey(expandedName.toString())) {
  +                 _cdataStack.push(new Integer(_depth));
  +             }
  +         }
           }
           catch (SAXException e) {
               throw new TransletException(e);
           }
  -    }
  -
  -    /**
  -     * Returns the URI of an element or attribute. Note that default 
namespaces
  -     * do not apply directly to attributes.
  -     */
  -    private String getNamespaceURI(String qname, boolean isElement)
  -        throws TransletException
  -    {
  -        String uri = EMPTYSTRING;
  -        int col = qname.lastIndexOf(':');
  -        final String prefix = (col > 0) ? qname.substring(0, col) : 
EMPTYSTRING;
  -
  -        if (prefix != EMPTYSTRING || isElement) {
  -            uri = lookupNamespace(prefix);
  -            if (uri == null && !prefix.equals(XMLNS_PREFIX)) {
  -                BasisLibrary.runTimeError(BasisLibrary.NAMESPACE_PREFIX_ERR,
  -                                          qname.substring(0, col));
  -            }
  -        }
  -        return uri;
  -    }
  -
  -    /**
  -     * Use a namespace prefix to lookup a namespace URI
  -     */
  -    private String lookupNamespace(String prefix) {
  -        final Stack stack = (Stack)_namespaces.get(prefix);
  -        return stack != null && !stack.isEmpty() ? (String)stack.peek() : 
null;
       }
   
       protected void closeCDATA() throws SAXException {
  
  
  
  1.11      +2 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java
  
  Index: StreamHTMLOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- StreamHTMLOutput.java     18 Jun 2002 18:00:12 -0000      1.10
  +++ StreamHTMLOutput.java     18 Jun 2002 22:29:27 -0000      1.11
  @@ -415,7 +415,7 @@
               .append(_encoding).append("\">");
       }
   
  -    protected void closeStartTag() {
  +    protected void closeStartTag() throws TransletException {
        super.closeStartTag();
   
        // Insert <META> tag directly after <HEAD> element in HTML output
  
  
  
  1.14      +4 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java
  
  Index: StreamOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StreamOutput.java 7 Jun 2002 21:51:17 -0000       1.13
  +++ StreamOutput.java 18 Jun 2002 22:29:27 -0000      1.14
  @@ -71,6 +71,8 @@
   
   import java.util.Vector;
   
  +import org.apache.xalan.xsltc.TransletException;
  +
   abstract class StreamOutput extends OutputBase {
   
       protected static final String AMP      = "&amp;";
  @@ -296,7 +298,7 @@
        }
       }
   
  -    protected void closeStartTag() {
  +    protected void closeStartTag() throws TransletException {
        appendAttributes();
        _buffer.append('>');
        _startTagOpen = false;
  
  
  
  1.14      +22 -6     
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java
  
  Index: StreamXMLOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StreamXMLOutput.java      11 Jun 2002 20:11:18 -0000      1.13
  +++ StreamXMLOutput.java      18 Jun 2002 22:29:27 -0000      1.14
  @@ -86,6 +86,8 @@
       private static final String CDATA_ESC_START = "]]>&#";
       private static final String CDATA_ESC_END   = ";<![CDATA[";
   
  +    private String _elementName;
  +
       public StreamXMLOutput(Writer writer, String encoding) {
        super(writer, encoding);
        initCDATA();
  @@ -124,7 +126,7 @@
       }
   
       public void startElement(String elementName) throws TransletException { 
  -// System.out.println("startElement = " + elementName + " _indent = " + 
_indent);
  +// System.out.println("startElement = " + elementName);
        if (_startTagOpen) {
            closeStartTag();
        }
  @@ -151,10 +153,7 @@
   
        _depth++;
        _startTagOpen = true;
  -
  -     if (_cdata != null && _cdata.containsKey(elementName)) {
  -         _cdataStack.push(new Integer(_depth));
  -     }
  +     _elementName = elementName;
       }
   
       public void endElement(String elementName) throws TransletException { 
  @@ -294,6 +293,23 @@
        else if (prefix != EMPTYSTRING || uri != EMPTYSTRING) {
            BasisLibrary.runTimeError(BasisLibrary.STRAY_NAMESPACE_ERR,
                                      prefix, uri);
  +     }
  +    }
  +
  +    protected void closeStartTag() throws TransletException {
  +     super.closeStartTag();
  +
  +     if (_cdata != null) {
  +         final String localName = getLocalName(_elementName);
  +         final String uri = getNamespaceURI(_elementName, true);
  +
  +         final StringBuffer expandedName = (uri == EMPTYSTRING) ? 
  +             new StringBuffer(_elementName) :
  +             new StringBuffer(uri).append(':').append(localName);
  +
  +         if (_cdata.containsKey(expandedName.toString())) {
  +             _cdataStack.push(new Integer(_depth));
  +         }
        }
       }
   
  
  
  

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

Reply via email to