Bug #2173060 bug with element with underscore in schemas

This commit is contained in:
Zane U. Ji 2012-08-06 19:50:48 +08:00
parent c93e94db6f
commit 865701cf62
2 changed files with 46 additions and 19 deletions

View File

@ -24,7 +24,6 @@
#include "xmlencodinghandler.h" #include "xmlencodinghandler.h"
#include "readfile.h" #include "readfile.h"
#include "replace.h" #include "replace.h"
#include "getword.h"
#include "pathresolver.h" #include "pathresolver.h"
#undef XMLCALL #undef XMLCALL
@ -462,6 +461,7 @@ void XmlPromptGenerator::handleSchema (
return; return;
} }
char *s;
while ( elemEnum.hasMoreElements() ) while ( elemEnum.hasMoreElements() )
{ {
const SchemaElementDecl& curElem = elemEnum.nextElement(); const SchemaElementDecl& curElem = elemEnum.nextElement();
@ -472,7 +472,9 @@ void XmlPromptGenerator::handleSchema (
const QName *qnm = curElem.getElementName(); const QName *qnm = curElem.getElementName();
if ( qnm ) if ( qnm )
{ {
element = XMLString::transcode ( qnm->getRawName() ); // this includes any prefix:localname combinations s = XMLString::transcode ( qnm->getRawName() ); // this includes any prefix:localname combinations
element = s;
XMLString::release( &s );
} }
if ( element.empty() ) if ( element.empty() )
continue; continue;
@ -480,23 +482,19 @@ void XmlPromptGenerator::handleSchema (
const XMLCh* fmtCntModel = curElem.getFormattedContentModel(); const XMLCh* fmtCntModel = curElem.getFormattedContentModel();
if ( fmtCntModel != NULL ) // tbd: this does not yet pick up prefix:localname combinations if ( fmtCntModel != NULL ) // tbd: this does not yet pick up prefix:localname combinations
{ {
size_t len;
char *s, *word;
std::string structure; std::string structure;
s = ( char * ) XMLString::transcode ( fmtCntModel ); s = XMLString::transcode ( fmtCntModel );
structure = s; structure = s;
XMLString::release( &s );
d->elementStructureMap.insert ( make_pair ( element, structure ) ); d->elementStructureMap.insert ( make_pair ( element, structure ) );
while ( ( word = GetWord::run ( &s, &len ) ) != NULL )
{
std::string currentValue ( word, len );
if ( currentValue.size() )
children.insert ( currentValue );
}
} }
if ( !children.empty() ) const ContentSpecNode *spec = curElem.getContentSpec();
d->elementMap.insert ( make_pair ( element, children ) ); if ( spec != NULL )
{
getContent ( spec, children );
if ( !children.empty() )
d->elementMap.insert ( make_pair ( element, children ) );
}
// fetch attributes // fetch attributes
if ( curElem.hasAttDefs() && ! ( curElem.getAttDefList().isEmpty() ) ) if ( curElem.hasAttDefs() && ! ( curElem.getAttDefList().isEmpty() ) )
@ -518,7 +516,9 @@ void XmlPromptGenerator::handleSchema (
const QName *qnm = pAttr->getAttName(); const QName *qnm = pAttr->getAttName();
if ( qnm ) if ( qnm )
{ {
attribute = XMLString::transcode ( qnm->getRawName() ); s = XMLString::transcode ( qnm->getRawName() );
attribute = s;
XMLString::release( &s );
} }
if ( attribute.empty() ) if ( attribute.empty() )
continue; continue;
@ -526,7 +526,9 @@ void XmlPromptGenerator::handleSchema (
// Value // Value
if ( pAttr->getValue() ) if ( pAttr->getValue() )
{ {
attributeValue = XMLString::transcode ( pAttr->getValue() ); s = XMLString::transcode ( pAttr->getValue() );
attributeValue = s;
XMLString::release( &s );
attributeValueSet.insert ( attributeValue ); attributeValueSet.insert ( attributeValue );
} }
@ -539,3 +541,24 @@ void XmlPromptGenerator::handleSchema (
delete parser; delete parser;
XMLPlatformUtils::Terminate(); XMLPlatformUtils::Terminate();
} }
void XmlPromptGenerator::getContent (
const ContentSpecNode *spec,
std::set<std::string> &list )
{
//if ( spec == NULL) return;
const QName *qnm = spec->getElement();
if ( qnm )
{
char *element = XMLString::transcode ( qnm->getRawName() );
if ( element != NULL )
list.insert( element );
XMLString::release( &element );
}
if ( spec->getFirst() != NULL)
getContent( spec->getFirst(), list );
if ( spec->getSecond() != NULL)
getContent( spec->getSecond(), list );
}

View File

@ -26,6 +26,7 @@
#include <memory> #include <memory>
#include "wrapexpat.h" #include "wrapexpat.h"
#include "parserdata.h" #include "parserdata.h"
#include <xercesc/validators/common/ContentSpecNode.hpp>
struct PromptGeneratorData : public ParserData struct PromptGeneratorData : public ParserData
{ {
@ -109,6 +110,9 @@ class XmlPromptGenerator : public WrapExpat
PromptGeneratorData *d, PromptGeneratorData *d,
const XML_Char *el, const XML_Char *el,
const XML_Char **attr ); const XML_Char **attr );
static void getContent (
const xercesc::ContentSpecNode *spec,
std::set<std::string> &list );
}; };
#endif #endif