~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Foundation/include/Poco/URIStreamOpener.h

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// URIStreamOpener.h
 
3
//
 
4
// $Id: //poco/1.2/Foundation/include/Poco/URIStreamOpener.h#1 $
 
5
//
 
6
// Library: Foundation
 
7
// Package: URI
 
8
// Module:  URIStreamOpener
 
9
//
 
10
// Definition of the URIStreamOpener class.
 
11
//
 
12
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
 
13
// and Contributors.
 
14
//
 
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:
 
21
// 
 
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.
 
28
// 
 
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.
 
36
//
 
37
 
 
38
 
 
39
#ifndef Foundation_URIStreamOpener_INCLUDED
 
40
#define Foundation_URIStreamOpener_INCLUDED
 
41
 
 
42
 
 
43
#include "Poco/Foundation.h"
 
44
#include "Poco/Mutex.h"
 
45
#include <istream>
 
46
#include <map>
 
47
 
 
48
 
 
49
namespace Poco {
 
50
 
 
51
 
 
52
class URI;
 
53
class URIStreamFactory;
 
54
class Path;
 
55
 
 
56
 
 
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.
 
60
        ///
 
61
        /// For every URI scheme used, a URIStreamFactory must be registered.
 
62
        /// A FileStreamFactory is automatically registered for file URIs.
 
63
{
 
64
public:
 
65
        URIStreamOpener();
 
66
                /// Creates the URIStreamOpener and registers a FileStreamFactory
 
67
                /// for file URIs.
 
68
 
 
69
        ~URIStreamOpener();
 
70
                /// Destroys the URIStreamOpener and deletes all registered
 
71
                /// URI stream factories.
 
72
 
 
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.
 
76
                ///
 
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.
 
81
                ///
 
82
                /// The given URI must be a valid one. This excludes file system paths.
 
83
                ///
 
84
                /// Whoever calls the method is responsible for deleting
 
85
                /// the returned stream.
 
86
 
 
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.
 
90
                ///
 
91
                /// If the stream cannot be opened for any reason, an
 
92
                /// Exception is thrown.
 
93
                ///
 
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.
 
97
                ///
 
98
                /// Whoever calls the method is responsible for deleting
 
99
                /// the returned stream.
 
100
 
 
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.
 
104
                ///
 
105
                /// pathOrURI is resolved against basePathOrURI (see URI::resolve() and
 
106
                /// Path::resolve() for more information).
 
107
                ///
 
108
                /// If the stream cannot be opened for any reason, an
 
109
                /// Exception is thrown.
 
110
                ///
 
111
                /// Whoever calls the method is responsible for deleting
 
112
                /// the returned stream.
 
113
                
 
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.
 
117
                ///
 
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).
 
120
 
 
121
        void unregisterStreamFactory(const std::string& scheme);
 
122
                /// Unregisters and deletes the URIStreamFactory for the given scheme.
 
123
                ///
 
124
                /// Throws a NotFoundException if no URIStreamFactory has been registered
 
125
                /// for the given scheme.
 
126
                
 
127
        bool supportsScheme(const std::string& scheme);
 
128
                /// Returns true iff a URIStreamFactory for the given scheme
 
129
                /// has been registered.
 
130
 
 
131
        static URIStreamOpener& defaultOpener();
 
132
                /// Returns a reference to the default URIStreamOpener.
 
133
 
 
134
protected:
 
135
        std::istream* openFile(const Path& path) const;
 
136
 
 
137
private:
 
138
        URIStreamOpener(const URIStreamOpener&);
 
139
        URIStreamOpener& operator = (const URIStreamOpener&);
 
140
 
 
141
        typedef std::map<std::string, URIStreamFactory*> FactoryMap;
 
142
        
 
143
        FactoryMap        _map;
 
144
        mutable FastMutex _mutex;
 
145
};
 
146
 
 
147
 
 
148
} // namespace Poco
 
149
 
 
150
 
 
151
#endif // Foundation_URIStreamOpener_INCLUDED