| 1 | // |
| 2 | // XMLFilterImpl.cpp |
| 3 | // |
| 4 | // Library: XML |
| 5 | // Package: SAX |
| 6 | // Module: SAXFilters |
| 7 | // |
| 8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 9 | // and Contributors. |
| 10 | // |
| 11 | // SPDX-License-Identifier: BSL-1.0 |
| 12 | // |
| 13 | |
| 14 | |
| 15 | #include "Poco/SAX/XMLFilterImpl.h" |
| 16 | #include "Poco/SAX/SAXException.h" |
| 17 | |
| 18 | |
| 19 | namespace Poco { |
| 20 | namespace XML { |
| 21 | |
| 22 | |
| 23 | XMLFilterImpl::XMLFilterImpl(): |
| 24 | _pParent(0), |
| 25 | _pEntityResolver(0), |
| 26 | _pDTDHandler(0), |
| 27 | _pContentHandler(0), |
| 28 | _pErrorHandler(0) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | |
| 33 | XMLFilterImpl::XMLFilterImpl(XMLReader* pParent): |
| 34 | _pParent(pParent), |
| 35 | _pEntityResolver(0), |
| 36 | _pDTDHandler(0), |
| 37 | _pContentHandler(0), |
| 38 | _pErrorHandler(0) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | |
| 43 | XMLFilterImpl::~XMLFilterImpl() |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | |
| 48 | XMLReader* XMLFilterImpl::getParent() const |
| 49 | { |
| 50 | return _pParent; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | void XMLFilterImpl::setParent(XMLReader* pParent) |
| 55 | { |
| 56 | _pParent = pParent; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | void XMLFilterImpl::setEntityResolver(EntityResolver* pResolver) |
| 61 | { |
| 62 | _pEntityResolver = pResolver; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | EntityResolver* XMLFilterImpl::getEntityResolver() const |
| 67 | { |
| 68 | return _pEntityResolver; |
| 69 | } |
| 70 | |
| 71 | |
| 72 | void XMLFilterImpl::setDTDHandler(DTDHandler* pDTDHandler) |
| 73 | { |
| 74 | _pDTDHandler = pDTDHandler; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | DTDHandler* XMLFilterImpl::getDTDHandler() const |
| 79 | { |
| 80 | return _pDTDHandler; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | void XMLFilterImpl::setContentHandler(ContentHandler* pContentHandler) |
| 85 | { |
| 86 | _pContentHandler = pContentHandler; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | ContentHandler* XMLFilterImpl::getContentHandler() const |
| 91 | { |
| 92 | return _pContentHandler; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | void XMLFilterImpl::setErrorHandler(ErrorHandler* pErrorHandler) |
| 97 | { |
| 98 | _pErrorHandler = pErrorHandler; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | ErrorHandler* XMLFilterImpl::getErrorHandler() const |
| 103 | { |
| 104 | return _pErrorHandler; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | void XMLFilterImpl::setFeature(const XMLString& featureId, bool state) |
| 109 | { |
| 110 | if (_pParent) |
| 111 | _pParent->setFeature(featureId, state); |
| 112 | else |
| 113 | throw SAXNotRecognizedException(fromXMLString(featureId)); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | bool XMLFilterImpl::getFeature(const XMLString& featureId) const |
| 118 | { |
| 119 | if (_pParent) |
| 120 | return _pParent->getFeature(featureId); |
| 121 | else |
| 122 | throw SAXNotRecognizedException(fromXMLString(featureId)); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | void XMLFilterImpl::setProperty(const XMLString& propertyId, const XMLString& value) |
| 127 | { |
| 128 | if (_pParent) |
| 129 | _pParent->setProperty(propertyId, value); |
| 130 | else |
| 131 | throw SAXNotRecognizedException(fromXMLString(propertyId)); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | void XMLFilterImpl::setProperty(const XMLString& propertyId, void* value) |
| 136 | { |
| 137 | if (_pParent) |
| 138 | _pParent->setProperty(propertyId, value); |
| 139 | else |
| 140 | throw SAXNotRecognizedException(fromXMLString(propertyId)); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | void* XMLFilterImpl::getProperty(const XMLString& propertyId) const |
| 145 | { |
| 146 | if (_pParent) |
| 147 | return _pParent->getProperty(propertyId); |
| 148 | else |
| 149 | throw SAXNotRecognizedException(fromXMLString(propertyId)); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | void XMLFilterImpl::parse(InputSource* pSource) |
| 154 | { |
| 155 | setupParse(); |
| 156 | _pParent->parse(pSource); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | void XMLFilterImpl::parse(const XMLString& systemId) |
| 161 | { |
| 162 | setupParse(); |
| 163 | _pParent->parse(systemId); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | void XMLFilterImpl::parseMemoryNP(const char* xml, std::size_t size) |
| 168 | { |
| 169 | setupParse(); |
| 170 | _pParent->parseMemoryNP(xml, size); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | InputSource* XMLFilterImpl::resolveEntity(const XMLString* publicId, const XMLString& systemId) |
| 175 | { |
| 176 | if (_pEntityResolver) |
| 177 | return _pEntityResolver->resolveEntity(publicId, systemId); |
| 178 | else |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | |
| 183 | void XMLFilterImpl::releaseInputSource(InputSource* pSource) |
| 184 | { |
| 185 | if (_pEntityResolver) |
| 186 | _pEntityResolver->releaseInputSource(pSource); |
| 187 | } |
| 188 | |
| 189 | |
| 190 | void XMLFilterImpl::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) |
| 191 | { |
| 192 | if (_pDTDHandler) |
| 193 | _pDTDHandler->notationDecl(name, publicId, systemId); |
| 194 | } |
| 195 | |
| 196 | |
| 197 | void XMLFilterImpl::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) |
| 198 | { |
| 199 | if (_pDTDHandler) |
| 200 | _pDTDHandler->unparsedEntityDecl(name, publicId, systemId, notationName); |
| 201 | } |
| 202 | |
| 203 | |
| 204 | void XMLFilterImpl::setDocumentLocator(const Locator* loc) |
| 205 | { |
| 206 | if (_pContentHandler) |
| 207 | _pContentHandler->setDocumentLocator(loc); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | void XMLFilterImpl::startDocument() |
| 212 | { |
| 213 | if (_pContentHandler) |
| 214 | _pContentHandler->startDocument(); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | void XMLFilterImpl::endDocument() |
| 219 | { |
| 220 | if (_pContentHandler) |
| 221 | _pContentHandler->endDocument(); |
| 222 | } |
| 223 | |
| 224 | |
| 225 | void XMLFilterImpl::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList) |
| 226 | { |
| 227 | if (_pContentHandler) |
| 228 | _pContentHandler->startElement(uri, localName, qname, attrList); |
| 229 | } |
| 230 | |
| 231 | |
| 232 | void XMLFilterImpl::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) |
| 233 | { |
| 234 | if (_pContentHandler) |
| 235 | _pContentHandler->endElement(uri, localName, qname); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | void XMLFilterImpl::characters(const XMLChar ch[], int start, int length) |
| 240 | { |
| 241 | if (_pContentHandler) |
| 242 | _pContentHandler->characters(ch, start, length); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | void XMLFilterImpl::ignorableWhitespace(const XMLChar ch[], int start, int length) |
| 247 | { |
| 248 | if (_pContentHandler) |
| 249 | _pContentHandler->ignorableWhitespace(ch, start, length); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | void XMLFilterImpl::processingInstruction(const XMLString& target, const XMLString& data) |
| 254 | { |
| 255 | if (_pContentHandler) |
| 256 | _pContentHandler->processingInstruction(target, data); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | void XMLFilterImpl::startPrefixMapping(const XMLString& prefix, const XMLString& uri) |
| 261 | { |
| 262 | if (_pContentHandler) |
| 263 | _pContentHandler->startPrefixMapping(prefix, uri); |
| 264 | } |
| 265 | |
| 266 | |
| 267 | void XMLFilterImpl::endPrefixMapping(const XMLString& prefix) |
| 268 | { |
| 269 | if (_pContentHandler) |
| 270 | _pContentHandler->endPrefixMapping(prefix); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | void XMLFilterImpl::skippedEntity(const XMLString& prefix) |
| 275 | { |
| 276 | if (_pContentHandler) |
| 277 | _pContentHandler->skippedEntity(prefix); |
| 278 | } |
| 279 | |
| 280 | |
| 281 | void XMLFilterImpl::warning(const SAXException& e) |
| 282 | { |
| 283 | if (_pErrorHandler) |
| 284 | _pErrorHandler->warning(e); |
| 285 | } |
| 286 | |
| 287 | |
| 288 | void XMLFilterImpl::error(const SAXException& e) |
| 289 | { |
| 290 | if (_pErrorHandler) |
| 291 | _pErrorHandler->error(e); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | void XMLFilterImpl::fatalError(const SAXException& e) |
| 296 | { |
| 297 | if (_pErrorHandler) |
| 298 | _pErrorHandler->fatalError(e); |
| 299 | } |
| 300 | |
| 301 | |
| 302 | void XMLFilterImpl::setupParse() |
| 303 | { |
| 304 | poco_check_ptr (_pParent); |
| 305 | |
| 306 | _pParent->setEntityResolver(this); |
| 307 | _pParent->setDTDHandler(this); |
| 308 | _pParent->setContentHandler(this); |
| 309 | _pParent->setErrorHandler(this); |
| 310 | } |
| 311 | |
| 312 | |
| 313 | } } // namespace Poco::XML |
| 314 | |