You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2003/01/13 17:30:20 UTC
cvs commit: xml-xerces/c/src/xercesc/validators/schema/identity IC_Field.cpp IC_Selector.cpp IC_Selector.hpp XPathMatcher.cpp XPathMatcher.hpp
knoaman 2003/01/13 08:30:19
Modified: c/src/xercesc/internal IGXMLScanner.cpp IGXMLScanner.hpp
IGXMLScanner2.cpp SGXMLScanner.cpp SGXMLScanner.hpp
c/src/xercesc/validators/schema/identity IC_Field.cpp
IC_Selector.cpp IC_Selector.hpp XPathMatcher.cpp
XPathMatcher.hpp
Log:
[Bug 14469] Validator doesn't enforce xsd:key.
Revision Changes Path
1.5 +8 -21 xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp
Index: IGXMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- IGXMLScanner.cpp 9 Jan 2003 22:33:32 -0000 1.4
+++ IGXMLScanner.cpp 13 Jan 2003 16:30:16 -0000 1.5
@@ -1025,7 +1025,7 @@
for (int i = oldCount - 1; i >= 0; i--) {
XPathMatcher* matcher = fMatcherStack->getMatcherAt(i);
- matcher->endElement(*(topElem->fThisElement));
+ matcher->endElement(*(topElem->fThisElement), fContent.getRawBuffer());
}
if (fMatcherStack->size() > 0) {
@@ -1040,14 +1040,8 @@
XPathMatcher* matcher = fMatcherStack->getMatcherAt(j);
IdentityConstraint* ic = matcher->getIdentityConstraint();
- if (ic && (ic->getType() != IdentityConstraint::KEYREF)) {
-
- matcher->endDocumentFragment();
+ if (ic && (ic->getType() != IdentityConstraint::KEYREF))
fValueStoreCache->transplant(ic, matcher->getInitialDepth());
- }
- else if (!ic) {
- matcher->endDocumentFragment();
- }
}
// now handle keyref's...
@@ -1063,8 +1057,6 @@
if (values) { // nothing to do if nothing matched!
values->endDcocumentFragment(fValueStoreCache);
}
-
- matcher->endDocumentFragment();
}
}
@@ -1928,6 +1920,9 @@
// ever be false if this is the root and its empty.
gotData = true;
+ // Reset element content buffer
+ fContent.reset();
+
// The current position is after the open bracket, so we need to read in
// in the element name.
if (!fReaderMgr.getName(fQNameBuf))
@@ -2437,7 +2432,7 @@
for (int i = oldCount - 1; i >= 0; i--) {
XPathMatcher* matcher = fMatcherStack->getMatcherAt(i);
- matcher->endElement(*elemDecl);
+ matcher->endElement(*elemDecl, fContent.getRawBuffer());
}
if (fMatcherStack->size() > 0) {
@@ -2452,14 +2447,8 @@
XPathMatcher* matcher = fMatcherStack->getMatcherAt(j);
IdentityConstraint* ic = matcher->getIdentityConstraint();
- if (ic && (ic->getType() != IdentityConstraint::KEYREF)) {
-
- matcher->endDocumentFragment();
+ if (ic && (ic->getType() != IdentityConstraint::KEYREF))
fValueStoreCache->transplant(ic, matcher->getInitialDepth());
- }
- else if (!ic) {
- matcher->endDocumentFragment();
- }
}
// now handle keyref's...
@@ -2475,8 +2464,6 @@
if (values) { // nothing to do if nothing matched!
values->endDcocumentFragment(fValueStoreCache);
}
-
- matcher->endDocumentFragment();
}
}
1.2 +5 -1 xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp
Index: IGXMLScanner.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IGXMLScanner.hpp 4 Dec 2002 02:05:25 -0000 1.1
+++ IGXMLScanner.hpp 13 Jan 2003 16:30:18 -0000 1.2
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.2 2003/01/13 16:30:18 knoaman
+ * [Bug 14469] Validator doesn't enforce xsd:key.
+ *
* Revision 1.1 2002/12/04 02:05:25 knoaman
* Initial checkin.
*
@@ -292,6 +295,7 @@
unsigned int fElemStateSize;
unsigned int* fElemState;
ElemStack fElemStack;
+ XMLBuffer fContent;
RefVectorOf<KVStringPair>* fRawAttrList;
DTDValidator* fDTDValidator;
SchemaValidator* fSchemaValidator;
1.8 +9 -22 xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp
Index: IGXMLScanner2.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- IGXMLScanner2.cpp 6 Jan 2003 19:44:57 -0000 1.7
+++ IGXMLScanner2.cpp 13 Jan 2003 16:30:18 -0000 1.8
@@ -965,11 +965,8 @@
((SchemaValidator*) fValidator)->setDatatypeBuffer(toFill.getRawBuffer());
// call all active identity constraints
- unsigned int count = fMatcherStack->getMatcherCount();
-
- for (unsigned int i = 0; i < count; i++) {
- fMatcherStack->getMatcherAt(i)->docCharacters(toFill.getRawBuffer(), toFill.getLen());
- }
+ if (fMatcherStack->getMatcherCount())
+ fContent.append(toFill.getRawBuffer(), toFill.getLen());
if (fDocHandler)
fDocHandler->docCharacters(toFill.getRawBuffer(), toFill.getLen(), false);
@@ -1010,11 +1007,8 @@
((SchemaValidator*) fValidator)->setDatatypeBuffer(toFill.getRawBuffer());
// call all active identity constraints
- unsigned int count = fMatcherStack->getMatcherCount();
-
- for (unsigned int i = 0; i < count; i++) {
- fMatcherStack->getMatcherAt(i)->docCharacters(toFill.getRawBuffer(), toFill.getLen());
- }
+ if (fMatcherStack->getMatcherCount())
+ fContent.append(toFill.getRawBuffer(), toFill.getLen());
if (fDocHandler)
fDocHandler->docCharacters(toFill.getRawBuffer(), toFill.getLen(), false);
@@ -1031,11 +1025,8 @@
// call all active identity constraints
if (fGrammarType == Grammar::SchemaGrammarType) {
- unsigned int count = fMatcherStack->getMatcherCount();
-
- for (unsigned int i = 0; i < count; i++) {
- fMatcherStack->getMatcherAt(i)->docCharacters(toSend.getRawBuffer(), toSend.getLen());
- }
+ if (fMatcherStack->getMatcherCount())
+ fContent.append(toSend.getRawBuffer(), toSend.getLen());
}
// Always assume its just char data if not validating
@@ -1953,12 +1944,8 @@
{
if (fGrammarType == Grammar::SchemaGrammarType) {
- // call all active identity constraints
- unsigned int count = fMatcherStack->getMatcherCount();
-
- for (unsigned int i = 0; i < count; i++) {
- fMatcherStack->getMatcherAt(i)->docCharacters(bbCData.getRawBuffer(), bbCData.getLen());
- }
+ if (fMatcherStack->getMatcherCount())
+ fContent.append(bbCData.getRawBuffer(), bbCData.getLen());
}
// If we have a doc handler, call it
1.10 +16 -41 xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp
Index: SGXMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SGXMLScanner.cpp 9 Jan 2003 22:33:32 -0000 1.9
+++ SGXMLScanner.cpp 13 Jan 2003 16:30:18 -0000 1.10
@@ -971,7 +971,7 @@
for (int i = oldCount - 1; i >= 0; i--) {
XPathMatcher* matcher = fMatcherStack->getMatcherAt(i);
- matcher->endElement(*(topElem->fThisElement));
+ matcher->endElement(*(topElem->fThisElement), fContent.getRawBuffer());
}
if (fMatcherStack->size() > 0) {
@@ -986,14 +986,8 @@
XPathMatcher* matcher = fMatcherStack->getMatcherAt(j);
IdentityConstraint* ic = matcher->getIdentityConstraint();
- if (ic && (ic->getType() != IdentityConstraint::KEYREF)) {
-
- matcher->endDocumentFragment();
+ if (ic && (ic->getType() != IdentityConstraint::KEYREF))
fValueStoreCache->transplant(ic, matcher->getInitialDepth());
- }
- else if (!ic) {
- matcher->endDocumentFragment();
- }
}
// now handle keyref's...
@@ -1009,8 +1003,6 @@
if (values) { // nothing to do if nothing matched!
values->endDcocumentFragment(fValueStoreCache);
}
-
- matcher->endDocumentFragment();
}
}
@@ -1082,6 +1074,9 @@
// ever be false if this is the root and its empty.
gotData = true;
+ // Reset element content
+ fContent.reset();
+
// The current position is after the open bracket, so we need to read in
// in the element name.
if (!fReaderMgr.getName(fQNameBuf))
@@ -1546,7 +1541,7 @@
for (int i = oldCount - 1; i >= 0; i--) {
XPathMatcher* matcher = fMatcherStack->getMatcherAt(i);
- matcher->endElement(*elemDecl);
+ matcher->endElement(*elemDecl, fContent.getRawBuffer());
}
if (fMatcherStack->size() > 0) {
@@ -1561,14 +1556,8 @@
XPathMatcher* matcher = fMatcherStack->getMatcherAt(j);
IdentityConstraint* ic = matcher->getIdentityConstraint();
- if (ic && (ic->getType() != IdentityConstraint::KEYREF)) {
-
- matcher->endDocumentFragment();
+ if (ic && (ic->getType() != IdentityConstraint::KEYREF))
fValueStoreCache->transplant(ic, matcher->getInitialDepth());
- }
- else if (!ic) {
- matcher->endDocumentFragment();
- }
}
// now handle keyref's...
@@ -1584,8 +1573,6 @@
if (values) { // nothing to do if nothing matched!
values->endDcocumentFragment(fValueStoreCache);
}
-
- matcher->endDocumentFragment();
}
}
@@ -2699,11 +2686,8 @@
((SchemaValidator*) fValidator)->setDatatypeBuffer(toFill.getRawBuffer());
// call all active identity constraints
- unsigned int count = fMatcherStack->getMatcherCount();
-
- for (unsigned int i = 0; i < count; i++) {
- fMatcherStack->getMatcherAt(i)->docCharacters(toFill.getRawBuffer(), toFill.getLen());
- }
+ if (fMatcherStack->getMatcherCount())
+ fContent.append(toFill.getRawBuffer(), toFill.getLen());
if (fDocHandler)
fDocHandler->docCharacters(toFill.getRawBuffer(), toFill.getLen(), false);
@@ -2736,11 +2720,8 @@
((SchemaValidator*) fValidator)->setDatatypeBuffer(toFill.getRawBuffer());
// call all active identity constraints
- unsigned int count = fMatcherStack->getMatcherCount();
-
- for (unsigned int i = 0; i < count; i++) {
- fMatcherStack->getMatcherAt(i)->docCharacters(toFill.getRawBuffer(), toFill.getLen());
- }
+ if (fMatcherStack->getMatcherCount())
+ fContent.append(toFill.getRawBuffer(), toFill.getLen());
if (fDocHandler)
fDocHandler->docCharacters(toFill.getRawBuffer(), toFill.getLen(), false);
@@ -2754,11 +2735,8 @@
else
{
// call all active identity constraints
- unsigned int count = fMatcherStack->getMatcherCount();
-
- for (unsigned int i = 0; i < count; i++) {
- fMatcherStack->getMatcherAt(i)->docCharacters(toSend.getRawBuffer(), toSend.getLen());
- }
+ if (fMatcherStack->getMatcherCount())
+ fContent.append(toSend.getRawBuffer(), toSend.getLen());
// Always assume its just char data if not validating
if (fDocHandler)
@@ -3439,11 +3417,8 @@
emitError(XMLErrs::Expected2ndSurrogateChar);
// call all active identity constraints
- unsigned int count = fMatcherStack->getMatcherCount();
-
- for (unsigned int i = 0; i < count; i++) {
- fMatcherStack->getMatcherAt(i)->docCharacters(bbCData.getRawBuffer(), bbCData.getLen());
- }
+ if (fMatcherStack->getMatcherCount())
+ fContent.append(bbCData.getRawBuffer(), bbCData.getLen());
// If we have a doc handler, call it
if (fDocHandler)
1.2 +5 -1 xml-xerces/c/src/xercesc/internal/SGXMLScanner.hpp
Index: SGXMLScanner.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SGXMLScanner.hpp 5 Dec 2002 16:19:27 -0000 1.1
+++ SGXMLScanner.hpp 13 Jan 2003 16:30:18 -0000 1.2
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.2 2003/01/13 16:30:18 knoaman
+ * [Bug 14469] Validator doesn't enforce xsd:key.
+ *
* Revision 1.1 2002/12/05 16:19:27 knoaman
* Initial check-in.
*
@@ -286,6 +289,7 @@
unsigned int fElemStateSize;
unsigned int* fElemState;
ElemStack fElemStack;
+ XMLBuffer fContent;
ValueHashTableOf<XMLCh>* fEntityTable;
RefVectorOf<KVStringPair>* fRawAttrList;
SchemaGrammar* fSchemaGrammar;
1.3 +4 -1 xml-xerces/c/src/xercesc/validators/schema/identity/IC_Field.cpp
Index: IC_Field.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/identity/IC_Field.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IC_Field.cpp 4 Nov 2002 14:47:41 -0000 1.2
+++ IC_Field.cpp 13 Jan 2003 16:30:19 -0000 1.3
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.3 2003/01/13 16:30:19 knoaman
+ * [Bug 14469] Validator doesn't enforce xsd:key.
+ *
* Revision 1.2 2002/11/04 14:47:41 tng
* C++ Namespace Support.
*
@@ -84,7 +87,7 @@
// ---------------------------------------------------------------------------
FieldMatcher::FieldMatcher(XercesXPath* const xpath, IC_Field* const aField,
ValueStore* const valueStore)
- : XPathMatcher(xpath, true, 0)
+ : XPathMatcher(xpath, 0)
, fField(aField)
, fValueStore(valueStore)
{
1.4 +11 -7 xml-xerces/c/src/xercesc/validators/schema/identity/IC_Selector.cpp
Index: IC_Selector.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/identity/IC_Selector.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- IC_Selector.cpp 4 Nov 2002 14:47:41 -0000 1.3
+++ IC_Selector.cpp 13 Jan 2003 16:30:19 -0000 1.4
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.4 2003/01/13 16:30:19 knoaman
+ * [Bug 14469] Validator doesn't enforce xsd:key.
+ *
* Revision 1.3 2002/11/04 14:47:41 tng
* C++ Namespace Support.
*
@@ -94,7 +97,7 @@
IC_Selector* const selector,
FieldActivator* const fieldActivator,
const int initialDepth)
- : XPathMatcher(xpath, false, selector->getIdentityConstraint())
+ : XPathMatcher(xpath, selector->getIdentityConstraint())
, fInitialDepth(initialDepth)
, fElementDepth(0)
, fMatchedDepth(-1)
@@ -123,7 +126,9 @@
fElementDepth++;
// activate the fields, if selector is matched
- if (fMatchedDepth == -1 && isMatched()) {
+ int matched = isMatched();
+ if ((fMatchedDepth == -1 && ((matched & XP_MATCHED) == XP_MATCHED))
+ || ((matched & XP_MATCHED_D) == XP_MATCHED_D)) {
IdentityConstraint* ic = fSelector->getIdentityConstraint();
int count = ic->getFieldCount();
@@ -133,17 +138,16 @@
for (int i = 0; i < count; i++) {
- IC_Field* field = ic->getFieldAt(i);
- XPathMatcher* matcher = fFieldActivator->activateField(field, fInitialDepth);
-
+ XPathMatcher* matcher = fFieldActivator->activateField(ic->getFieldAt(i), fInitialDepth);
matcher->startElement(elemDecl, urlId, elemPrefix, attrList, attrCount);
}
}
}
-void SelectorMatcher::endElement(const XMLElementDecl& elemDecl) {
+void SelectorMatcher::endElement(const XMLElementDecl& elemDecl,
+ const XMLCh* const elemContent) {
- XPathMatcher::endElement(elemDecl);
+ XPathMatcher::endElement(elemDecl, elemContent);
if (fElementDepth-- == fMatchedDepth) {
1.4 +3 -2 xml-xerces/c/src/xercesc/validators/schema/identity/IC_Selector.hpp
Index: IC_Selector.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/identity/IC_Selector.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- IC_Selector.hpp 4 Nov 2002 14:47:41 -0000 1.3
+++ IC_Selector.hpp 13 Jan 2003 16:30:19 -0000 1.4
@@ -136,7 +136,8 @@
const XMLCh* const elemPrefix,
const RefVectorOf<XMLAttr>& attrList,
const unsigned int attrCount);
- void endElement(const XMLElementDecl& elemDecl);
+ void endElement(const XMLElementDecl& elemDecl,
+ const XMLCh* const elemContent);
private:
// -----------------------------------------------------------------------
1.5 +42 -79 xml-xerces/c/src/xercesc/validators/schema/identity/XPathMatcher.cpp
Index: XPathMatcher.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/identity/XPathMatcher.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XPathMatcher.cpp 4 Nov 2002 14:47:41 -0000 1.4
+++ XPathMatcher.cpp 13 Jan 2003 16:30:19 -0000 1.5
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.5 2003/01/13 16:30:19 knoaman
+ * [Bug 14469] Validator doesn't enforce xsd:key.
+ *
* Revision 1.4 2002/11/04 14:47:41 tng
* C++ Namespace Support.
*
@@ -92,16 +95,13 @@
// XPathMatcher: Constructors and Destructor
// ---------------------------------------------------------------------------
XPathMatcher::XPathMatcher(XercesXPath* const xpath)
- : fShouldBufferContent(false)
- , fBufferContent(false)
- , fLocationPathSize(0)
+ : fLocationPathSize(0)
, fMatched(0)
, fNoMatchDepth(0)
, fCurrentStep(0)
, fStepIndexes(0)
, fLocationPaths(0)
, fIdentityConstraint(0)
- , fMatchedBuffer(128)
{
try {
init(xpath);
@@ -115,16 +115,14 @@
XPathMatcher::XPathMatcher(XercesXPath* const xpath,
- const bool shouldBufferContent,
IdentityConstraint* const ic)
- : fShouldBufferContent(shouldBufferContent)
- , fLocationPathSize(0)
+ : fLocationPathSize(0)
, fMatched(0)
, fNoMatchDepth(0)
, fCurrentStep(0)
+ , fStepIndexes(0)
, fLocationPaths(0)
, fIdentityConstraint(ic)
- , fMatchedBuffer(0)
{
try {
init(xpath);
@@ -157,7 +155,7 @@
fStepIndexes = new RefVectorOf<ValueStackOf<int> >(fLocationPathSize);
fCurrentStep = new int[fLocationPathSize];
fNoMatchDepth = new int[fLocationPathSize];
- fMatched = new bool[fLocationPathSize];
+ fMatched = new int[fLocationPathSize];
for(unsigned int i=0; i < fLocationPathSize; i++) {
fStepIndexes->addElement(new ValueStackOf<int>(8));
@@ -166,30 +164,18 @@
}
}
-void XPathMatcher::clear() {
-
- fBufferContent = false;
- fMatchedBuffer.reset();
-
- for(int i = 0; i < (int) fLocationPathSize; i++)
- fMatched[i] = false;
-
-}
// ---------------------------------------------------------------------------
// XPathMatcher: XMLDocumentHandler methods
// ---------------------------------------------------------------------------
void XPathMatcher::startDocumentFragment() {
- // reset state
- clear();
-
for(unsigned int i = 0; i < fLocationPathSize; i++) {
fStepIndexes->elementAt(i)->removeAllElements();
fCurrentStep[i] = 0;
fNoMatchDepth[i] = 0;
- fMatched[i] = false;
+ fMatched[i] = 0;
}
}
@@ -206,11 +192,15 @@
fStepIndexes->elementAt(i)->push(startStep);
// try next xpath, if not matching
- if (fMatched[i] || fNoMatchDepth[i] > 0) {
+ if ((fMatched[i] & XP_MATCHED_D) == XP_MATCHED || fNoMatchDepth[i] > 0) {
fNoMatchDepth[i]++;
continue;
}
+ if((fMatched[i] & XP_MATCHED_D) == XP_MATCHED_D) {
+ fMatched[i] = XP_MATCHED_DP;
+ }
+
// consume self::node() steps
XercesLocationPath* locPath = fLocationPaths->elementAt(i);
int stepSize = locPath->getStepSize();
@@ -222,14 +212,7 @@
if (fCurrentStep[i] == stepSize) {
- fMatched[i] = true;
- int j=0;
-
- for(; j<i && !fMatched[j]; j++) ;
-
- if(j==i)
- fBufferContent = fShouldBufferContent;
-
+ fMatched[i] = XP_MATCHED;
continue;
}
@@ -244,6 +227,7 @@
fCurrentStep[i]++;
}
+ bool sawDescendant = fCurrentStep[i] > descendantStep;
if (fCurrentStep[i] == stepSize) {
fNoMatchDepth[i]++;
@@ -279,13 +263,14 @@
if (fCurrentStep[i] == stepSize) {
- fMatched[i] = true;
- int j=0;
+ if (sawDescendant) {
- for(; j<i && !fMatched[j]; j++) ;
-
- if(j==i)
- fBufferContent = fShouldBufferContent;
+ fCurrentStep[i] = descendantStep;
+ fMatched[i] = XP_MATCHED_D;
+ }
+ else {
+ fMatched[i] = XP_MATCHED;
+ }
continue;
}
@@ -309,10 +294,10 @@
if (fCurrentStep[i] == stepSize) {
- fMatched[i] = true;
+ fMatched[i] = XP_MATCHED_A;
int j=0;
- for(; j<i && !fMatched[j]; j++) ;
+ for(; j<i && ((fMatched[j] & XP_MATCHED) != XP_MATCHED); j++) ;
if(j == i) {
@@ -326,7 +311,7 @@
}
}
- if (!fMatched[i]) {
+ if ((fMatched[i] & XP_MATCHED) != XP_MATCHED) {
if(fCurrentStep[i] > descendantStep) {
@@ -340,24 +325,14 @@
}
}
-void XPathMatcher::docCharacters(const XMLCh* const chars,
- const unsigned int length) {
-
- // collect match content
- // so long as one of our paths is matching, store the content
- for(int i=0; i < (int) fLocationPathSize; i++) {
-
- if (fBufferContent && fNoMatchDepth[i] == 0) {
- fMatchedBuffer.append(chars, length);
- break;
- }
- }
-}
-
-void XPathMatcher::endElement(const XMLElementDecl& elemDecl) {
+void XPathMatcher::endElement(const XMLElementDecl& elemDecl,
+ const XMLCh* const elemContent) {
for(int i = 0; i < (int) fLocationPathSize; i++) {
+ // go back a step
+ fCurrentStep[i] = fStepIndexes->elementAt(i)->pop();
+
// don't do anything, if not matching
if (fNoMatchDepth[i] > 0) {
fNoMatchDepth[i]--;
@@ -366,47 +341,35 @@
else {
int j=0;
+ for(; j<i && ((fMatched[j] & XP_MATCHED) != XP_MATCHED); j++) ;
- for(; j<i && !fMatched[j]; j++) ;
-
- if (j < i)
+ if (j < i || (fMatched[j] == 0)
+ || ((fMatched[j] & XP_MATCHED_A) == XP_MATCHED_A))
continue;
- if (fBufferContent) {
-
- DatatypeValidator* dv = ((SchemaElementDecl*) &elemDecl)->getDatatypeValidator();
- bool isNillable = (((SchemaElementDecl *) &elemDecl)->getMiscFlags() & SchemaSymbols::NILLABLE) != 0;
+ DatatypeValidator* dv = ((SchemaElementDecl*) &elemDecl)->getDatatypeValidator();
+ bool isNillable = (((SchemaElementDecl *) &elemDecl)->getMiscFlags() & SchemaSymbols::NILLABLE) != 0;
- fBufferContent = false;
- matched(fMatchedBuffer.getRawBuffer(), dv, isNillable);
- }
-
- clear();
+ matched(elemContent, dv, isNillable);
+ fMatched[i] = 0;
}
-
- // go back a step
- fCurrentStep[i] = fStepIndexes->elementAt(i)->pop();
}
}
-void XPathMatcher::endDocumentFragment() {
-
- clear();
-}
-
// ---------------------------------------------------------------------------
// XPathMatcher: Match methods
// ---------------------------------------------------------------------------
-bool XPathMatcher::isMatched() {
+int XPathMatcher::isMatched() {
// xpath has been matched if any one of the members of the union have matched.
for (int i=0; i < (int) fLocationPathSize; i++) {
- if (fMatched[i])
- return true;
+ if (((fMatched[i] & XP_MATCHED) == XP_MATCHED)
+ && ((fMatched[i] & XP_MATCHED_DP) != XP_MATCHED_DP))
+ return fMatched[i];
}
- return false;
+ return 0;
}
void XPathMatcher::matched(const XMLCh* const content,
1.4 +17 -23 xml-xerces/c/src/xercesc/validators/schema/identity/XPathMatcher.hpp
Index: XPathMatcher.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/identity/XPathMatcher.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XPathMatcher.hpp 4 Nov 2002 14:47:41 -0000 1.3
+++ XPathMatcher.hpp 13 Jan 2003 16:30:19 -0000 1.4
@@ -89,7 +89,7 @@
// Constructors/Destructor
// -----------------------------------------------------------------------
XPathMatcher(XercesXPath* const xpath);
- XPathMatcher(XercesXPath* const xpath, const bool shouldBufferContent,
+ XPathMatcher(XercesXPath* const xpath,
IdentityConstraint* const ic);
virtual ~XPathMatcher();
@@ -104,23 +104,32 @@
/**
* Returns true if XPath has been matched.
*/
- bool isMatched();
+ int isMatched();
virtual int getInitialDepth() const;
// -----------------------------------------------------------------------
// XMLDocumentHandler methods
// -----------------------------------------------------------------------
virtual void startDocumentFragment();
- virtual void endDocumentFragment();
virtual void startElement(const XMLElementDecl& elemDecl,
const unsigned int urlId,
const XMLCh* const elemPrefix,
const RefVectorOf<XMLAttr>& attrList,
const unsigned int attrCount);
- virtual void endElement(const XMLElementDecl& elemDecl);
- virtual void docCharacters(const XMLCh* const chars, const unsigned int length);
+ virtual void endElement(const XMLElementDecl& elemDecl,
+ const XMLCh* const elemContent);
protected:
+
+ enum
+ {
+ XP_MATCHED = 1 // matched any way
+ , XP_MATCHED_A = 3 // matched on the attribute axis
+ , XP_MATCHED_D = 5 // matched on the descendant-or-self axixs
+ , XP_MATCHED_DP = 13 // matched some previous (ancestor) node on the
+ // descendant-or-self-axis, but not this node
+ };
+
// -----------------------------------------------------------------------
// Match methods
// -----------------------------------------------------------------------
@@ -133,26 +142,16 @@
DatatypeValidator* const dv, const bool isNil);
private:
+
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
void init(XercesXPath* const xpath);
void cleanUp();
- /**
- * Clears the match values.
- */
- void clear();
-
// -----------------------------------------------------------------------
// Data members
//
- // fShouldBufferContent
- // Application preference to buffer content or not.
- //
- // fBufferContent
- // True, if we should buffer character content at this time.
- //
// fMatched
// Indicates whether XPath has been matched or not
//
@@ -174,19 +173,14 @@
// The identity constraint we're the matcher for. Only used for
// selectors.
//
- // fMatchedBuffer
- // To hold match text.
// -----------------------------------------------------------------------
- bool fShouldBufferContent;
- bool fBufferContent;
unsigned int fLocationPathSize;
- bool* fMatched;
+ int* fMatched;
int* fNoMatchDepth;
int* fCurrentStep;
RefVectorOf<ValueStackOf<int> >* fStepIndexes;
RefVectorOf<XercesLocationPath>* fLocationPaths;
IdentityConstraint* fIdentityConstraint;
- XMLBuffer fMatchedBuffer;
};
// ---------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org