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