Hi guys,

At the moment, SAXGenerator isn't generating startPrefixMapping() and endPrefixMapping() events on instances of ContentHandler. This causes Xalan 2.3.0 and higher to crash when parsing XSLT that contains markup in other non-default namespaces.

The attached patch fixes this. Can someone please review the patch and commit it.

Thanks!
Mike.

--
Mike Gratton <[EMAIL PROTECTED]>, <http://web.vee.net/>
"Every motive escalate."
Index: java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java
===================================================================
RCS file: 
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java,v
retrieving revision 1.4
diff -u -r1.4 SAXEventGenerator.java
--- java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java  22 Feb 2002 
22:51:14 -0000      1.4
+++ java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java  2 Mar 2002 
07:48:38 -0000
@@ -90,6 +90,9 @@
 
    private boolean interrupt = false;
 
+   static final String XMLNS_ATTR_PREFIX = "xmlns:";
+   static final int XMLNS_MAP_INCREMENT = 5;
+
    public SAXEventGenerator(SymbolTable symbols, byte[] data) {
       this.symbols = symbols;
       this.data = data;
@@ -196,6 +199,8 @@
       String elemName = null;
       String localName = null;
       String nsURI = null;
+      String[] mappedPrefixes = null;
+      int nsMapCount = 0;
 
       if ( element ) {
          in.readSignature();
@@ -216,8 +221,26 @@
             String attrName = symbols.getName(symbol);
             String attrURI = symbols.getNamespaceURI(symbol);
             String lclName = getLocalName(attrName);
+            String attrValue = new String(b, "UTF-8");
+
+           // look for and buffer newly mapped namespace prefixes
+           if (attrName.startsWith(XMLNS_ATTR_PREFIX)) {
+               // create the buffer if needed
+               if (mappedPrefixes == null) 
+                   mappedPrefixes = new String[XMLNS_MAP_INCREMENT];
+
+               // check the buffer's capacity
+               if (nsMapCount >= mappedPrefixes.length) {
+                   String[] newBuf = new String[mappedPrefixes.length + 
XMLNS_MAP_INCREMENT];
+                   System.arraycopy(mappedPrefixes, 0, newBuf, 0, 
newBuf.length);
+                   mappedPrefixes = newBuf;
+               }
+
+               content.startPrefixMapping(lclName, attrValue);
+               mappedPrefixes[nsMapCount++] = lclName;
+           }
             
-            attrs.addAttribute(attrURI != null ? attrURI : "", lclName, 
attrName, "", new String(b, "UTF-8"));
+            attrs.addAttribute(attrURI != null ? attrURI : "", lclName, 
attrName, "", attrValue);
          }
          if ( comp != null ) {
             comp.symbolID(elemSymbol);
@@ -296,8 +319,13 @@
          bis.skip(len);
       }
 
-      if ( element && !interrupt)
+      if ( element && !interrupt) {
+        // unmap any prefixes
+        for (int i = 0; i < nsMapCount; i++)
+            content.endPrefixMapping(mappedPrefixes[i]);
+
          content.endElement(nsURI != null ? nsURI : "", localName, elemName);
+      }
 
       return !interrupt;
    }

Reply via email to