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