1 | /*
|
---|
2 | * Copyright 2001-2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Id: XPathMatcher.hpp,v 1.8 2004/09/08 13:56:59 peiyongz Exp $
|
---|
19 | */
|
---|
20 |
|
---|
21 | #if !defined(XPATHMATCHER_HPP)
|
---|
22 | #define XPATHMATCHER_HPP
|
---|
23 |
|
---|
24 |
|
---|
25 | // ---------------------------------------------------------------------------
|
---|
26 | // Includes
|
---|
27 | // ---------------------------------------------------------------------------
|
---|
28 | #include <xercesc/util/ValueStackOf.hpp>
|
---|
29 | #include <xercesc/util/RefVectorOf.hpp>
|
---|
30 | #include <xercesc/framework/XMLBuffer.hpp>
|
---|
31 |
|
---|
32 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
33 |
|
---|
34 | // ---------------------------------------------------------------------------
|
---|
35 | // Forward Declaration
|
---|
36 | // ---------------------------------------------------------------------------
|
---|
37 | class XMLElementDecl;
|
---|
38 | class XercesXPath;
|
---|
39 | class IdentityConstraint;
|
---|
40 | class DatatypeValidator;
|
---|
41 | class XMLStringPool;
|
---|
42 | class XercesLocationPath;
|
---|
43 | class XMLAttr;
|
---|
44 |
|
---|
45 | class VALIDATORS_EXPORT XPathMatcher : public XMemory
|
---|
46 | {
|
---|
47 | public:
|
---|
48 | // -----------------------------------------------------------------------
|
---|
49 | // Constructors/Destructor
|
---|
50 | // -----------------------------------------------------------------------
|
---|
51 | XPathMatcher(XercesXPath* const xpath,
|
---|
52 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
53 | XPathMatcher(XercesXPath* const xpath,
|
---|
54 | IdentityConstraint* const ic,
|
---|
55 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
56 | virtual ~XPathMatcher();
|
---|
57 |
|
---|
58 | // -----------------------------------------------------------------------
|
---|
59 | // Getter methods
|
---|
60 | // -----------------------------------------------------------------------
|
---|
61 | IdentityConstraint* getIdentityConstraint() const { return fIdentityConstraint; }
|
---|
62 | MemoryManager* getMemoryManager() const { return fMemoryManager; }
|
---|
63 |
|
---|
64 | // -----------------------------------------------------------------------
|
---|
65 | // Match methods
|
---|
66 | // -----------------------------------------------------------------------
|
---|
67 | /**
|
---|
68 | * Returns true if XPath has been matched.
|
---|
69 | */
|
---|
70 | int isMatched();
|
---|
71 | virtual int getInitialDepth() const;
|
---|
72 |
|
---|
73 | // -----------------------------------------------------------------------
|
---|
74 | // XMLDocumentHandler methods
|
---|
75 | // -----------------------------------------------------------------------
|
---|
76 | virtual void startDocumentFragment();
|
---|
77 | virtual void startElement(const XMLElementDecl& elemDecl,
|
---|
78 | const unsigned int urlId,
|
---|
79 | const XMLCh* const elemPrefix,
|
---|
80 | const RefVectorOf<XMLAttr>& attrList,
|
---|
81 | const unsigned int attrCount);
|
---|
82 | virtual void endElement(const XMLElementDecl& elemDecl,
|
---|
83 | const XMLCh* const elemContent);
|
---|
84 |
|
---|
85 | protected:
|
---|
86 |
|
---|
87 | enum
|
---|
88 | {
|
---|
89 | XP_MATCHED = 1 // matched any way
|
---|
90 | , XP_MATCHED_A = 3 // matched on the attribute axis
|
---|
91 | , XP_MATCHED_D = 5 // matched on the descendant-or-self axixs
|
---|
92 | , XP_MATCHED_DP = 13 // matched some previous (ancestor) node on the
|
---|
93 | // descendant-or-self-axis, but not this node
|
---|
94 | };
|
---|
95 |
|
---|
96 | // -----------------------------------------------------------------------
|
---|
97 | // Match methods
|
---|
98 | // -----------------------------------------------------------------------
|
---|
99 | /**
|
---|
100 | * This method is called when the XPath handler matches the XPath
|
---|
101 | * expression. Subclasses can override this method to provide default
|
---|
102 | * handling upon a match.
|
---|
103 | */
|
---|
104 | virtual void matched(const XMLCh* const content,
|
---|
105 | DatatypeValidator* const dv, const bool isNil);
|
---|
106 |
|
---|
107 | private:
|
---|
108 | // -----------------------------------------------------------------------
|
---|
109 | // Unimplemented constructors and operators
|
---|
110 | // -----------------------------------------------------------------------
|
---|
111 | XPathMatcher(const XPathMatcher&);
|
---|
112 | XPathMatcher& operator=(const XPathMatcher&);
|
---|
113 |
|
---|
114 | // -----------------------------------------------------------------------
|
---|
115 | // Helper methods
|
---|
116 | // -----------------------------------------------------------------------
|
---|
117 | void init(XercesXPath* const xpath);
|
---|
118 | void cleanUp();
|
---|
119 |
|
---|
120 | // -----------------------------------------------------------------------
|
---|
121 | // Data members
|
---|
122 | //
|
---|
123 | // fMatched
|
---|
124 | // Indicates whether XPath has been matched or not
|
---|
125 | //
|
---|
126 | // fNoMatchDepth
|
---|
127 | // Indicates whether matching is successful for the given xpath
|
---|
128 | // expression.
|
---|
129 | //
|
---|
130 | // fCurrentStep
|
---|
131 | // Stores current step.
|
---|
132 | //
|
---|
133 | // fStepIndexes
|
---|
134 | // Integer stack of step indexes.
|
---|
135 | //
|
---|
136 | // fLocationPaths
|
---|
137 | // fLocationPathSize
|
---|
138 | // XPath location path, and its size.
|
---|
139 | //
|
---|
140 | // fIdentityConstraint
|
---|
141 | // The identity constraint we're the matcher for. Only used for
|
---|
142 | // selectors.
|
---|
143 | //
|
---|
144 | // -----------------------------------------------------------------------
|
---|
145 | unsigned int fLocationPathSize;
|
---|
146 | int* fMatched;
|
---|
147 | int* fNoMatchDepth;
|
---|
148 | int* fCurrentStep;
|
---|
149 | RefVectorOf<ValueStackOf<int> >* fStepIndexes;
|
---|
150 | RefVectorOf<XercesLocationPath>* fLocationPaths;
|
---|
151 | IdentityConstraint* fIdentityConstraint;
|
---|
152 | MemoryManager* fMemoryManager;
|
---|
153 | };
|
---|
154 |
|
---|
155 | // ---------------------------------------------------------------------------
|
---|
156 | // XPathMatcher: Helper methods
|
---|
157 | // ---------------------------------------------------------------------------
|
---|
158 | inline void XPathMatcher::cleanUp() {
|
---|
159 |
|
---|
160 | fMemoryManager->deallocate(fMatched);//delete [] fMatched;
|
---|
161 | fMemoryManager->deallocate(fNoMatchDepth);//delete [] fNoMatchDepth;
|
---|
162 | fMemoryManager->deallocate(fCurrentStep);//delete [] fCurrentStep;
|
---|
163 | delete fStepIndexes;
|
---|
164 | }
|
---|
165 |
|
---|
166 | XERCES_CPP_NAMESPACE_END
|
---|
167 |
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * End of file XPathMatcher.hpp
|
---|
172 | */
|
---|
173 |
|
---|