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
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]