4
// $Id: //poco/1.2/Foundation/include/Poco/URIStreamOpener.h#1 $
8
// Module: URIStreamOpener
10
// Definition of the URIStreamOpener class.
12
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
39
#ifndef Foundation_URIStreamOpener_INCLUDED
40
#define Foundation_URIStreamOpener_INCLUDED
43
#include "Poco/Foundation.h"
44
#include "Poco/Mutex.h"
53
class URIStreamFactory;
57
class Foundation_API URIStreamOpener
58
/// The URIStreamOpener class is used to create and open input streams
59
/// for resourced identified by Uniform Resource Identifiers.
61
/// For every URI scheme used, a URIStreamFactory must be registered.
62
/// A FileStreamFactory is automatically registered for file URIs.
66
/// Creates the URIStreamOpener and registers a FileStreamFactory
70
/// Destroys the URIStreamOpener and deletes all registered
71
/// URI stream factories.
73
std::istream* open(const URI& uri) const;
74
/// Tries to create and open an input stream for the resource specified
75
/// by the given uniform resource identifier.
77
/// If no URIStreamFactory has been registered for the URI's
78
/// scheme, a UnknownURIScheme exception is thrown.
79
/// If the stream cannot be opened for any reason, an
80
/// IOException is thrown.
82
/// The given URI must be a valid one. This excludes file system paths.
84
/// Whoever calls the method is responsible for deleting
85
/// the returned stream.
87
std::istream* open(const std::string& pathOrURI) const;
88
/// Tries to create and open an input stream for the resource specified
89
/// by the given path or uniform resource identifier.
91
/// If the stream cannot be opened for any reason, an
92
/// Exception is thrown.
94
/// The method first tries to interpret the given pathOrURI as an URI.
95
/// If this fails, the pathOrURI is treated as local filesystem path.
96
/// If this also fails, an exception is thrown.
98
/// Whoever calls the method is responsible for deleting
99
/// the returned stream.
101
std::istream* open(const std::string& basePathOrURI, const std::string& pathOrURI) const;
102
/// Tries to create and open an input stream for the resource specified
103
/// by the given path or uniform resource identifier.
105
/// pathOrURI is resolved against basePathOrURI (see URI::resolve() and
106
/// Path::resolve() for more information).
108
/// If the stream cannot be opened for any reason, an
109
/// Exception is thrown.
111
/// Whoever calls the method is responsible for deleting
112
/// the returned stream.
114
void registerStreamFactory(const std::string& scheme, URIStreamFactory* pFactory);
115
/// Registers a URIStreamFactory for the given scheme. If another factory
116
/// has already been registered for the scheme, an ExistsException is thrown.
118
/// The URIStreamOpener takes ownership of the factory and deletes it when it is
119
/// no longer needed (in other words, when the URIStreamOpener is deleted).
121
void unregisterStreamFactory(const std::string& scheme);
122
/// Unregisters and deletes the URIStreamFactory for the given scheme.
124
/// Throws a NotFoundException if no URIStreamFactory has been registered
125
/// for the given scheme.
127
bool supportsScheme(const std::string& scheme);
128
/// Returns true iff a URIStreamFactory for the given scheme
129
/// has been registered.
131
static URIStreamOpener& defaultOpener();
132
/// Returns a reference to the default URIStreamOpener.
135
std::istream* openFile(const Path& path) const;
138
URIStreamOpener(const URIStreamOpener&);
139
URIStreamOpener& operator = (const URIStreamOpener&);
141
typedef std::map<std::string, URIStreamFactory*> FactoryMap;
144
mutable FastMutex _mutex;
151
#endif // Foundation_URIStreamOpener_INCLUDED