1 | // |
---|---|
2 | // EntityResolverImpl.cpp |
3 | // |
4 | // Library: XML |
5 | // Package: SAX |
6 | // Module: SAX |
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/EntityResolverImpl.h" |
16 | #include "Poco/SAX/InputSource.h" |
17 | #include "Poco/XML/XMLString.h" |
18 | #include "Poco/URI.h" |
19 | #include "Poco/Path.h" |
20 | #include "Poco/Exception.h" |
21 | |
22 | |
23 | using Poco::URIStreamOpener; |
24 | using Poco::URI; |
25 | using Poco::Path; |
26 | using Poco::Exception; |
27 | using Poco::IOException; |
28 | using Poco::OpenFileException; |
29 | |
30 | |
31 | namespace Poco { |
32 | namespace XML { |
33 | |
34 | |
35 | EntityResolverImpl::EntityResolverImpl(): |
36 | _opener(URIStreamOpener::defaultOpener()) |
37 | { |
38 | } |
39 | |
40 | |
41 | EntityResolverImpl::EntityResolverImpl(const URIStreamOpener& opener): |
42 | _opener(opener) |
43 | { |
44 | } |
45 | |
46 | |
47 | EntityResolverImpl::~EntityResolverImpl() |
48 | { |
49 | } |
50 | |
51 | |
52 | InputSource* EntityResolverImpl::resolveEntity(const XMLString* publicId, const XMLString& systemId) |
53 | { |
54 | std::istream* pIstr = resolveSystemId(systemId); |
55 | InputSource* pInputSource = new InputSource(systemId); |
56 | if (publicId) pInputSource->setPublicId(*publicId); |
57 | pInputSource->setByteStream(*pIstr); |
58 | return pInputSource; |
59 | } |
60 | |
61 | |
62 | void EntityResolverImpl::releaseInputSource(InputSource* pSource) |
63 | { |
64 | poco_check_ptr (pSource); |
65 | |
66 | delete pSource->getByteStream(); |
67 | delete pSource; |
68 | } |
69 | |
70 | |
71 | std::istream* EntityResolverImpl::resolveSystemId(const XMLString& systemId) |
72 | { |
73 | std::string sid = fromXMLString(systemId); |
74 | return _opener.open(sid); |
75 | } |
76 | |
77 | |
78 | } } // namespace Poco::XML |
79 |