You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by na...@apache.org on 2008/10/08 05:46:59 UTC
svn commit: r702692 - in /webservices/axis/trunk/c/src/soap:
SoapDeSerializer.cpp xsd/IAnySimpleType.cpp xsd/IAnySimpleType.hpp
Author: nadiramra
Date: Tue Oct 7 20:46:59 2008
New Revision: 702692
URL: http://svn.apache.org/viewvc?rev=702692&view=rev
Log:
AXISCPP-663 - Element values not escaped when using getAnyObject()
Modified:
webservices/axis/trunk/c/src/soap/SoapDeSerializer.cpp
webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.cpp
webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.hpp
Modified: webservices/axis/trunk/c/src/soap/SoapDeSerializer.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/soap/SoapDeSerializer.cpp?rev=702692&r1=702691&r2=702692&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/soap/SoapDeSerializer.cpp (original)
+++ webservices/axis/trunk/c/src/soap/SoapDeSerializer.cpp Tue Oct 7 20:46:59 2008
@@ -1686,11 +1686,12 @@
xsd__string ret = new char[len];
memset(ret,0,len);
- for (i=0; i<any->_size; i++) if (any->_array[i])
- {
- strcat(ret,any->_array[i]);
- delete [] any->_array[i];
- }
+ for (i=0; i<any->_size; i++)
+ if (any->_array[i])
+ {
+ strcat(ret,any->_array[i]);
+ delete [] any->_array[i];
+ }
delete [] any->_array;
delete any;
return ret;
@@ -1897,6 +1898,9 @@
list < AxisString > lstXML;
+ AxisString inValue = "";
+ AxisString outValue = "";
+
while ((END_ELEMENT != m_pNode->m_type) || (tagCount >= 0) || bContinue)
{
// Continue if processing start prefix,
@@ -1911,7 +1915,7 @@
tagCount++;
else if (END_ELEMENT == m_pNode->m_type)
tagCount--;
-
+
if (START_PREFIX == m_pNode->m_type)
{
nsDecls += " xmlns";
@@ -1930,7 +1934,11 @@
nsDecls = "";
}
else
- xmlStr += m_pNode->m_pchNameOrValue;
+ {
+ inValue = m_pNode->m_pchNameOrValue;
+ IAnySimpleType::replaceReservedCharacters(inValue, outValue);
+ xmlStr += outValue;
+ }
if ( !bContinue && tagCount == 0 && (!xmlStr.empty ())) /* copying the First level element into the list */
{
Modified: webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.cpp?rev=702692&r1=702691&r2=702692&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.cpp (original)
+++ webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.cpp Tue Oct 7 20:46:59 2008
@@ -17,31 +17,37 @@
AXIS_CPP_NAMESPACE_START
-IAnySimpleType::IAnySimpleType():m_Buf(NULL), m_isNil(true)
+IAnySimpleType::
+IAnySimpleType():m_Buf(NULL), m_isNil(true)
{
}
-IAnySimpleType::~IAnySimpleType()
+IAnySimpleType::
+~IAnySimpleType()
{
delete [] m_Buf;
}
-bool IAnySimpleType::isNil()
+bool IAnySimpleType::
+isNil()
{
return m_isNil;
}
-void IAnySimpleType::setNil(bool nil)
+void IAnySimpleType::
+setNil(bool nil)
{
m_isNil = nil;
}
-AxisChar* IAnySimpleType::serialize()
+AxisChar* IAnySimpleType::
+serialize()
{
return m_Buf;
}
-void IAnySimpleType::deserialize(const AxisChar* value)
+void IAnySimpleType::
+deserialize(const AxisChar* value)
{
delete [] m_Buf;
m_Buf = NULL;
@@ -53,28 +59,23 @@
strcpy (m_Buf, value);
}
else
- {
setNil(true);
- }
}
-AxisChar* IAnySimpleType::serialize(const AxisChar* value) throw (AxisSoapException)
+AxisChar* IAnySimpleType::
+serialize(const AxisChar* value) throw (AxisSoapException)
{
WhiteSpace* whiteSpace = getWhiteSpace();
const AxisChar* serializedValue = whiteSpace->processWhiteSpace(value);
Pattern* pattern = getPattern();
if(pattern->isSet())
- {
pattern->validatePattern(serializedValue);
- }
delete pattern;
Enumeration* enumeration = getEnumeration();
if (enumeration->isSet())
- {
enumeration->validateEnumeration(serializedValue);
- }
delete enumeration;
delete [] m_Buf;
@@ -86,80 +87,96 @@
return m_Buf;
}
-const AxisString& IAnySimpleType::replaceReservedCharacters(AxisString &value)
+const AxisString& IAnySimpleType::
+replaceReservedCharacters(AxisString &value)
{
- m_strReturnVal = "";
+ // If empty string or no entity references just return string.
if (value.empty ())
- {
return value;
- }
- /* Find entity reference characters and returns the first any of chars find
- * position
- */
unsigned long nPos = value.find_first_of (XML_ENTITY_REFERENCE_CHARS);
+ if (AxisString::npos == nPos)
+ return value;
+
+ replaceReservedCharacters(value, m_strReturnVal);
+ return m_strReturnVal;
+}
+
+
+void IAnySimpleType::
+replaceReservedCharacters(AxisString &inValue, AxisString &outValue)
+{
+ outValue = "";
+
+ // If empty string or no entity references just return string.
+ if (inValue.empty ())
+ return;
- /* Check for position validity */
+ unsigned long nPos = inValue.find_first_of (XML_ENTITY_REFERENCE_CHARS);
if (AxisString::npos == nPos)
{
- return value;
+ outValue = inValue;
+ return;
}
- unsigned long nOldIdx = 0; // Counter value
+ // Loop through character string, replacing any entity characters
+ unsigned long nOldIdx = 0;
while (AxisString::npos != nPos)
- { // Get pointered character
- switch (value.at (nPos))
+ {
+ switch (inValue.at (nPos))
{
case LESSER_THAN_CHAR: // Process < character
- m_strReturnVal.append (value.substr (nOldIdx, nPos - nOldIdx));
- m_strReturnVal.append (ENCODED_LESSER_STR);
+ outValue.append (inValue.substr (nOldIdx, nPos - nOldIdx));
+ outValue.append (ENCODED_LESSER_STR);
break;
case GREATER_THAN_CHAR: // Process > character
- m_strReturnVal.append (value.substr (nOldIdx, nPos - nOldIdx));
- m_strReturnVal.append (ENCODED_GREATER_STR);
+ outValue.append (inValue.substr (nOldIdx, nPos - nOldIdx));
+ outValue.append (ENCODED_GREATER_STR);
break;
case AMPERSAND_CHAR: // Process & character
- m_strReturnVal.append (value.substr (nOldIdx, nPos - nOldIdx));
- m_strReturnVal.append (ENCODED_AMPERSAND_STR);
+ outValue.append (inValue.substr (nOldIdx, nPos - nOldIdx));
+ outValue.append (ENCODED_AMPERSAND_STR);
break;
case DOUBLE_QUOTE_CHAR: // Process " character
- m_strReturnVal.append (value.substr (nOldIdx, nPos - nOldIdx));
- m_strReturnVal.append (ENCODED_DBL_QUOTE_STR);
+ outValue.append (inValue.substr (nOldIdx, nPos - nOldIdx));
+ outValue.append (ENCODED_DBL_QUOTE_STR);
break;
case SINGLE_QUOTE_CHAR: // Process ' character
- m_strReturnVal.append (value.substr (nOldIdx, nPos - nOldIdx));
- m_strReturnVal.append (ENCODED_SGL_QUOTE_STR);
+ outValue.append (inValue.substr (nOldIdx, nPos - nOldIdx));
+ outValue.append (ENCODED_SGL_QUOTE_STR);
break;
}
- nOldIdx = ++nPos; // Get old position
- /* Find the next entity reference characters from previous found
- * position,
- */
- nPos = value.find_first_of (XML_ENTITY_REFERENCE_CHARS, nPos);
+
+ // Get old position
+ nOldIdx = ++nPos;
+
+ // Find the next entity reference characters from previous found position
+ nPos = inValue.find_first_of (XML_ENTITY_REFERENCE_CHARS, nPos);
}
- unsigned long nDataLen = value.length (); // Get the length of the field value
+ // Apend the remaining data
+ unsigned long nDataLen = inValue.length (); // Get the length of the field value
unsigned long nLen = nDataLen - nOldIdx; // Get remaining number of characters
if (nLen > 0)
- {
- m_strReturnVal += value.substr (nOldIdx, nLen); /* Apend the remaining
- * data
- */
- }
- return m_strReturnVal;
+ outValue += inValue.substr (nOldIdx, nLen);
+
+ return;
}
-WhiteSpace* IAnySimpleType::getWhiteSpace()
+WhiteSpace* IAnySimpleType::
+getWhiteSpace()
{
return new WhiteSpace(PRESERVE);
}
-Pattern* IAnySimpleType::getPattern()
+Pattern* IAnySimpleType::
+getPattern()
{
return new Pattern();
}
-Enumeration* IAnySimpleType::getEnumeration()
+Enumeration* IAnySimpleType::
+getEnumeration()
{
return new Enumeration();
}
Modified: webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.hpp?rev=702692&r1=702691&r2=702692&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.hpp (original)
+++ webservices/axis/trunk/c/src/soap/xsd/IAnySimpleType.hpp Tue Oct 7 20:46:59 2008
@@ -102,6 +102,15 @@
* @param Serialized form of value
*/
void deserialize(const AxisChar* value);
+
+ /**
+ * Utility function to replace reserved characters in XML with corresponding
+ * entities.
+ *
+ * @param inValue - source string
+ * @param outValue - source string with reserved characters converted.
+ */
+ static void replaceReservedCharacters(AxisString& inValue, AxisString& outValue);
protected: