1 | // |
2 | // URIStreamFactory.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: URI |
6 | // Module: URIStreamFactory |
7 | // |
8 | // Definition of the URIStreamFactory class. |
9 | // |
10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_URIStreamFactory_INCLUDED |
18 | #define Foundation_URIStreamFactory_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include <istream> |
23 | |
24 | |
25 | namespace Poco { |
26 | |
27 | |
28 | class URI; |
29 | |
30 | |
31 | class Foundation_API URIStreamFactory |
32 | /// This class defines the interface that all |
33 | /// URI stream factories must implement. |
34 | /// |
35 | /// Subclasses must implement the open() method. |
36 | { |
37 | public: |
38 | URIStreamFactory(); |
39 | /// Creates the URIStreamFactory. |
40 | |
41 | virtual std::istream* open(const URI& uri) = 0; |
42 | /// Tries to create and open an input stream for the |
43 | /// resource specified by the given URI. |
44 | /// |
45 | /// If the stream cannot be opened for whatever reason, |
46 | /// an appropriate IOException must be thrown. |
47 | /// |
48 | /// If opening the stream results in a redirect, a |
49 | /// URIRedirection exception should be thrown. |
50 | |
51 | protected: |
52 | virtual ~URIStreamFactory(); |
53 | /// Destroys the URIStreamFactory. |
54 | |
55 | private: |
56 | URIStreamFactory(const URIStreamFactory&); |
57 | URIStreamFactory& operator = (const URIStreamFactory&); |
58 | |
59 | friend class URIStreamOpener; |
60 | }; |
61 | |
62 | |
63 | class Foundation_API URIRedirection |
64 | /// An instance of URIRedirection is thrown by a URIStreamFactory::open() |
65 | /// if opening the original URI resulted in a redirection response |
66 | /// (such as a MOVED PERMANENTLY in HTTP). |
67 | { |
68 | public: |
69 | URIRedirection(const std::string& uri); |
70 | URIRedirection(const URIRedirection& redir); |
71 | |
72 | URIRedirection& operator = (const URIRedirection& redir); |
73 | void swap(URIRedirection& redir); |
74 | |
75 | const std::string& uri() const; |
76 | /// Returns the new URI. |
77 | |
78 | private: |
79 | URIRedirection(); |
80 | |
81 | std::string _uri; |
82 | }; |
83 | |
84 | |
85 | // |
86 | // inlines |
87 | // |
88 | inline const std::string& URIRedirection::uri() const |
89 | { |
90 | return _uri; |
91 | } |
92 | |
93 | |
94 | } // namespace Poco |
95 | |
96 | |
97 | #endif // Foundation_URIStreamFactory_INCLUDED |
98 | |