You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by "Eran Chinthaka (JIRA)" <ji...@apache.org> on 2006/07/26 07:19:17 UTC

[jira] Commented: (WSCOMMONS-33) StreamingOMSerializer.serializeAttributes() method attempts to use the namespace even if there isn't one.

    [ http://issues.apache.org/jira/browse/WSCOMMONS-33?page=comments#action_12423526 ] 
            
Eran Chinthaka commented on WSCOMMONS-33:
-----------------------------------------

Hi,

I can not see a bold text here. Can you please help me to re-produce this bug, preferrably with a test case? I appreciate if you can provide a patch to fix this bug, if exists, as well :).

-- Chinthaka

> StreamingOMSerializer.serializeAttributes() method attempts to use the namespace even if there isn't one.
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: WSCOMMONS-33
>                 URL: http://issues.apache.org/jira/browse/WSCOMMONS-33
>             Project: WS-Commons
>          Issue Type: Bug
>          Components: AXIOM
>         Environment: Windows XP, JBOSS4.0.3 SP1
>            Reporter: Lakshmi Chaparala
>
>   If the XML to be streamed back has a tag with attributes,  but no namespace, a null pointer exception is thrown in the streaming process. This is because the StreamingOMSerializer.serializeAttributes() method attempts to use the  namespace even if there isn't one.
> CORRECTION:  I modified the method to perform a null check on the 
>  namespace and not use it if it was null.  This allowed the xml to be 
>  properly streamed out.  The modified code, in bold, is shown below:
>      /**
>       * @param reader
>       * @param writer
>       * @throws XMLStreamException
>       */
>      protected void serializeAttributes(XMLStreamReader reader,    XMLStreamWriter writer)
>              throws XMLStreamException {
>          int count = reader.getAttributeCount();
>          String prefix = null;
>          String namespaceName = null;
>          String writerPrefix=null;
>          for (int i = 0; i < count; i++) {
>              prefix = reader.getAttributePrefix(i);
>              namespaceName = reader.getAttributeNamespace(i);
>              if ((namespaceName != null) && !"".equals(namespaceName)){
>                  writerPrefix =writer.getNamespaceContext().getPrefix(namespaceName); 
>                   //moved this  line into the if statement
>                  //prefix has already being declared but this  particular attrib has a
>                  //no prefix attached. So use the prefix provided by  the writer
>                  if (writerPrefix!=null && (prefix==null ||  prefix.equals(""))){
>                      writer.writeAttribute(writerPrefix, namespaceName,
>                              reader.getAttributeLocalName(i),
>                              reader.getAttributeValue(i));
>                      //writer prefix is available but different from  the current
>                      //prefix of the attrib. We should be decalring the  new prefix
>                      //as a namespace declaration
>                  }else if (prefix!=null && !"".equals(prefix)&&  !prefix.equals(writerPrefix)){
>                      writer.writeNamespace(prefix,namespaceName);
>                      writer.writeAttribute(prefix, namespaceName,
>                              reader.getAttributeLocalName(i),
>                              reader.getAttributeValue(i));
>                      //prefix is null (or empty), but the namespace  name is valid! it has not
>                      //being written previously also. So we need to  generate a prefix      //here
>                  }else{
>                      prefix = generateUniquePrefix(writer.getNamespaceContext());
>                      writer.writeNamespace(prefix,namespaceName);
>                      writer.writeAttribute(prefix, namespaceName,
>                              reader.getAttributeLocalName(i),
>                              reader.getAttributeValue(i));
>              }
>              }else{
>                  //empty namespace is equal to no namespace!
>                  writer.writeAttribute(reader.getAttributeLocalName(i),
>                          reader.getAttributeValue(i));
>              }
>         }
>      }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org