|
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: XMLResourceIdentifier.hpp 568078 2007-08-21 11:43:25Z amassari $ |
|
36 */ |
|
37 |
|
38 #ifndef XMLRESOURCEIDENTIFIER_HPP |
|
39 #define XMLRESOURCEIDENTIFIER_HPP |
|
40 |
|
41 XERCES_CPP_NAMESPACE_BEGIN |
|
42 |
|
43 class Locator; |
|
44 |
|
45 /** |
|
46 * <p>This class is used along with XMLEntityResolver to resolve entities. |
|
47 * Instead of passing publicId and systemId on the resolveEntity call, |
|
48 * as is done with the SAX entity resolver, an object of type XMLResourceIdentifier |
|
49 * is passed. By calling the getResourceIdentifierType() method the user can |
|
50 * determine which data members are available for inspection:</p> |
|
51 * |
|
52 * <table border='1'> |
|
53 * <tr> |
|
54 * <td>ResourceIdentifierType</td> |
|
55 * <td>Available Data Members</td> |
|
56 * </tr> |
|
57 * <tr> |
|
58 * <td>SchemaGrammar</td> |
|
59 * <td>schemaLocation, nameSpace & baseURI (current document)</td> |
|
60 * </tr> |
|
61 * <tr> |
|
62 * <td>SchemaImport</td> |
|
63 * <td>schemaLocation, nameSpace & baseURI (current document)</td> |
|
64 * </tr> |
|
65 * <tr> |
|
66 * <td>SchemaInclude</td> |
|
67 * <td>schemaLocation & baseURI (current document)</td> |
|
68 * </tr> |
|
69 * <tr> |
|
70 * <td>SchemaRedefine</td> |
|
71 * <td>schemaLocation & baseURI (current document)</td> |
|
72 * </tr> |
|
73 * <tr> |
|
74 * <td>ExternalEntity</td> |
|
75 * <td>systemId, publicId & baseURI (some items may be NULL)</td> |
|
76 * </tr> |
|
77 * </table> |
|
78 * |
|
79 * <p>The following resolver would provide the application |
|
80 * with a special character stream for the entity with the system |
|
81 * identifier "http://www.myhost.com/today":</p> |
|
82 * |
|
83 *<code> |
|
84 * #include <xercesc/util/XMLEntityResolver.hpp><br> |
|
85 * #include <xercesc/sax/InputSource.hpp><br> |
|
86 *<br> |
|
87 * class MyResolver : public XMLEntityResolver {<br> |
|
88 * public:<br> |
|
89 * InputSource resolveEntity (XMLResourceIdentifier* xmlri);<br> |
|
90 * ...<br> |
|
91 * };<br> |
|
92 *<br> |
|
93 * MyResolver::resolveEntity(XMLResourceIdentifier* xmlri) {<br> |
|
94 * switch(xmlri->getResourceIdentifierType()) {<br> |
|
95 * case XMLResourceIdentifier::SystemId:<br> |
|
96 * if (XMLString::compareString(xmlri->getSystemId(), "http://www.myhost.com/today")) {<br> |
|
97 * MyReader* reader = new MyReader();<br> |
|
98 * return new InputSource(reader);<br> |
|
99 * } else {<br> |
|
100 * return null;<br> |
|
101 * }<br> |
|
102 * break;<br> |
|
103 * default:<br> |
|
104 * return null;<br> |
|
105 * }<br> |
|
106 * }</code> |
|
107 * |
|
108 * @see SAXParser#setXMLEntityResolver |
|
109 * @see InputSource#InputSource |
|
110 */ |
|
111 class XMLUTIL_EXPORT XMLResourceIdentifier |
|
112 { |
|
113 public: |
|
114 |
|
115 /** @name Public Constants */ |
|
116 //@{ |
|
117 enum ResourceIdentifierType { |
|
118 SchemaGrammar = 0, |
|
119 SchemaImport, |
|
120 SchemaInclude, |
|
121 SchemaRedefine , |
|
122 ExternalEntity, |
|
123 UnKnown = 255 |
|
124 }; |
|
125 //@} |
|
126 |
|
127 /** @name Constructors and Destructor */ |
|
128 //@{ |
|
129 /** Constructor */ |
|
130 |
|
131 XMLResourceIdentifier(const ResourceIdentifierType resourceIdentitiferType |
|
132 , const XMLCh* const systemId |
|
133 , const XMLCh* const nameSpace = 0 |
|
134 , const XMLCh* const publicId = 0 |
|
135 , const XMLCh* const baseURI = 0 |
|
136 , const Locator* locator = 0); |
|
137 |
|
138 /** Destructor */ |
|
139 ~XMLResourceIdentifier() |
|
140 { |
|
141 } |
|
142 |
|
143 //@} |
|
144 |
|
145 // ----------------------------------------------------------------------- |
|
146 // Getter methods |
|
147 // ----------------------------------------------------------------------- |
|
148 /** @name Public Methods */ |
|
149 //@{ |
|
150 ResourceIdentifierType getResourceIdentifierType() const; |
|
151 const XMLCh* getPublicId() const; |
|
152 const XMLCh* getSystemId() const; |
|
153 const XMLCh* getSchemaLocation() const; |
|
154 const XMLCh* getBaseURI() const; |
|
155 const XMLCh* getNameSpace() const; |
|
156 const Locator* getLocator() const; |
|
157 //@} |
|
158 |
|
159 private : |
|
160 |
|
161 const ResourceIdentifierType fResourceIdentifierType; |
|
162 const XMLCh* fPublicId; |
|
163 const XMLCh* fSystemId; |
|
164 const XMLCh* fBaseURI; |
|
165 const XMLCh* fNameSpace; |
|
166 const Locator* fLocator; |
|
167 |
|
168 /* Unimplemented constructors and operators */ |
|
169 |
|
170 /* Copy constructor */ |
|
171 XMLResourceIdentifier(const XMLResourceIdentifier&); |
|
172 |
|
173 /* Assignment operator */ |
|
174 XMLResourceIdentifier& operator=(const XMLResourceIdentifier&); |
|
175 |
|
176 }; |
|
177 |
|
178 inline XMLResourceIdentifier::ResourceIdentifierType XMLResourceIdentifier::getResourceIdentifierType() const |
|
179 { |
|
180 return fResourceIdentifierType; |
|
181 } |
|
182 |
|
183 inline const XMLCh* XMLResourceIdentifier::getPublicId() const |
|
184 { |
|
185 return fPublicId; |
|
186 } |
|
187 |
|
188 inline const XMLCh* XMLResourceIdentifier::getSystemId() const |
|
189 { |
|
190 return fSystemId; |
|
191 } |
|
192 |
|
193 inline const XMLCh* XMLResourceIdentifier::getSchemaLocation() const |
|
194 { |
|
195 return fSystemId; |
|
196 } |
|
197 |
|
198 inline const XMLCh* XMLResourceIdentifier::getBaseURI() const |
|
199 { |
|
200 return fBaseURI; |
|
201 } |
|
202 |
|
203 inline const XMLCh* XMLResourceIdentifier::getNameSpace() const |
|
204 { |
|
205 return fNameSpace; |
|
206 } |
|
207 |
|
208 inline const Locator* XMLResourceIdentifier::getLocator() const |
|
209 { |
|
210 return fLocator; |
|
211 } |
|
212 |
|
213 inline XMLResourceIdentifier::XMLResourceIdentifier(const ResourceIdentifierType resourceIdentifierType |
|
214 , const XMLCh* const systemId |
|
215 , const XMLCh* const nameSpace |
|
216 , const XMLCh* const publicId |
|
217 , const XMLCh* const baseURI |
|
218 , const Locator* locator ) |
|
219 : fResourceIdentifierType(resourceIdentifierType) |
|
220 , fPublicId(publicId) |
|
221 , fSystemId(systemId) |
|
222 , fBaseURI(baseURI) |
|
223 , fNameSpace(nameSpace) |
|
224 , fLocator(locator) |
|
225 { |
|
226 } |
|
227 |
|
228 XERCES_CPP_NAMESPACE_END |
|
229 |
|
230 #endif |