You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by al...@apache.org on 2010/07/19 01:25:42 UTC

svn commit: r965319 - /uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java

Author: alally
Date: Sun Jul 18 23:25:42 2010
New Revision: 965319

URL: http://svn.apache.org/viewvc?rev=965319&view=rev
Log:
UIMA-1817: applied patch which fixes namespace handling.  Sends empty string instead of null as the namespace uri for attributes, and calls startPrefixMapping appropriately on the content handler.  Also added matching calls to endPrefixMapping.

Modified:
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java?rev=965319&r1=965318&r2=965319&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java Sun Jul 18 23:25:42 2010
@@ -272,6 +272,7 @@ public class XmiCasSerializer {
       }
       writeViews(); // encodes cas.sofaCount + 1 elements
       endElement(XMI_TAG);
+      endPrefixMappings();
     }
 
     private void writeViews() throws SAXException {
@@ -402,8 +403,9 @@ public class XmiCasSerializer {
 
     /**
      * @param workAttrs2
+     * @throws SAXException 
      */
-    private void computeNamespaceDeclarationAttrs(AttributesImpl workAttrs2) {
+    private void computeNamespaceDeclarationAttrs(AttributesImpl workAttrs2) throws SAXException {
       Iterator<Map.Entry<String, String>> it = nsUriToPrefixMap.entrySet().iterator();
       while (it.hasNext()) {
         Map.Entry<String, String> entry = it.next();
@@ -411,12 +413,14 @@ public class XmiCasSerializer {
         String prefix = entry.getValue();
         // write attribute
         workAttrs.addAttribute(XMLNS_NS_URI, prefix, "xmlns:" + prefix, "CDATA", nsUri);
+        ch.startPrefixMapping(prefix, nsUri);
       }
       // also add schemaLocation if specified
       if (nsUriToSchemaLocationMap != null) {
         // write xmlns:xsi attribute
         workAttrs.addAttribute(XMLNS_NS_URI, "xsi", "xmlns:xsi", "CDATA", XSI_NS_URI);
-
+        ch.startPrefixMapping("xsi", XSI_NS_URI);
+        
         // write xsi:schemaLocation attributaiton
         StringBuilder buf = new StringBuilder();
         it = nsUriToSchemaLocationMap.entrySet().iterator();
@@ -427,6 +431,18 @@ public class XmiCasSerializer {
         workAttrs.addAttribute(XSI_NS_URI, "xsi", "xsi:schemaLocation", "CDATA", buf.toString());
       }
     }
+    
+    private void endPrefixMappings() throws SAXException {
+      Iterator<Map.Entry<String, String>> it = nsUriToPrefixMap.entrySet().iterator();
+      while (it.hasNext()) {
+        Map.Entry<String, String> entry = it.next();
+        String prefix = entry.getValue();
+        ch.endPrefixMapping(prefix);
+      }
+      if (nsUriToSchemaLocationMap != null) {
+        ch.endPrefixMapping("xsi");
+      }
+    }
 
     /**
      * Enqueues all FS that are stored in the XmiSerializationSharedData's id map.
@@ -974,7 +990,8 @@ public class XmiCasSerializer {
     }
     
     private void addAttribute(AttributesImpl attrs, String attrName, String attrValue) {
-      attrs.addAttribute(null, null, attrName, cdataType, attrValue);
+      final int index = attrName.lastIndexOf(':') + 1;
+      attrs.addAttribute("", attrName.substring(index), attrName, cdataType, attrValue);
     }
 
     private void startElement(XmlElementName name, Attributes attrs, int aNumChildren)