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
23using Poco::URIStreamOpener;
24using Poco::URI;
25using Poco::Path;
26using Poco::Exception;
27using Poco::IOException;
28using Poco::OpenFileException;
29
30
31namespace Poco {
32namespace XML {
33
34
35EntityResolverImpl::EntityResolverImpl():
36 _opener(URIStreamOpener::defaultOpener())
37{
38}
39
40
41EntityResolverImpl::EntityResolverImpl(const URIStreamOpener& opener):
42 _opener(opener)
43{
44}
45
46
47EntityResolverImpl::~EntityResolverImpl()
48{
49}
50
51
52InputSource* 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
62void EntityResolverImpl::releaseInputSource(InputSource* pSource)
63{
64 poco_check_ptr (pSource);
65
66 delete pSource->getByteStream();
67 delete pSource;
68}
69
70
71std::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