Author: dims
Date: Wed Feb  7 09:29:57 2007
New Revision: 504627

URL: http://svn.apache.org/viewvc?view=rev&rev=504627
Log:
Fix for WSCOMMONS-160 - StAXOMBuilder is stripping off namspace prefix's from 
attributes that need namespace qualification

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java?view=diff&rev=504627&r1=504626&r2=504627
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
 Wed Feb  7 09:29:57 2007
@@ -109,7 +109,7 @@
      */
     protected void serializeElement(XMLStreamReader reader,
                                     XMLStreamWriter writer)
-            throws XMLStreamException {
+            throws XMLStreamException {
         
        // Note: To serialize the start tag, we must follow the order dictated 
by the JSR-173 (StAX) specification.
        // Please keep this code in sync with the code in 
OMSerializerUtil.serializeStartpart
@@ -203,8 +203,8 @@
                writerPrefix = (writerPrefix != null && writerPrefix.length() 
== 0) ? null : writerPrefix;
                prefix = (writerPrefix != null) ? 
                                writerPrefix :
-                       generateUniquePrefix(writer.getNamespaceContext());
-            }
+                       generateUniquePrefix(writer.getNamespaceContext());
+            }
             newPrefix = OMSerializerUtil.generateSetPrefix(prefix, namespace, 
writer, true);
             // If the prefix is not associated with a namespace yet, remember 
it so that we can
                // write out a namespace declaration
@@ -230,7 +230,7 @@
                        }
                } else {
                        writer.writeStartElement(reader.getLocalName());
-               }
+               }
         }
 
         // Now write out the list of namespace declarations in this list that 
we constructed
@@ -260,12 +260,27 @@
                // Default namespaces are not allowed on an attribute reference.
                 // Earlier in this code, a unique prefix was added for this 
case...now obtain and use it
                prefix = writer.getPrefix(namespace);
+                //XMLStreamWriter doesn't allow for getPrefix to know whether 
you're asking for the prefix
+                //for an attribute or an element. So if the namespace matches 
the default namespace getPrefix will return
+                //the empty string, as if it were an element, in all cases 
(even for attributes, and even if 
+                //there was a prefix specifically set up for this), which is 
not the desired behavior.
+                //Since the interface is base java, we can't fix it where we 
need to (by adding an attr boolean to 
+                //XMLStreamWriter.getPrefix), so we hack it in here...
+                if ( prefix == null || "".equals( prefix ) ) {
+                    for (int j=0; j<writePrefixList.size(); j++) {
+                        if ( namespace.equals( (String)writeNSList.get( j ) ) 
) {
+                            prefix = (String)writePrefixList.get( j );
+                        }
+                    }
+                }
             } else if (namespace != null) {
-               // Use the writer's prefix if it is different
-               String writerPrefix = writer.getPrefix(namespace);
-               if (!prefix.equals(writerPrefix)) {
-                       prefix = writerPrefix;
-               }
+                // Use the writer's prefix if it is different, but if the 
writers 
+                // prefix is empty then do not replace because attributes do 
not
+                // default to the default namespace like elements do.
+                String writerPrefix = writer.getPrefix(namespace);
+                if (!prefix.equals(writerPrefix) && !"".equals(writerPrefix)) {
+                    prefix = writerPrefix;
+                }
             }
             if (namespace != null) {
                // Qualified attribute
@@ -277,10 +292,10 @@
                writer.writeAttribute(reader.getAttributeLocalName(i),
                         reader.getAttributeValue(i));
             }
-        }
+        }
     }
 
-    /**
+    /**
      * Method serializeEndElement.
      *
      * @param writer



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

Reply via email to