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