Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_TDOC_STORAGE_HXX
21 : #define INCLUDED_TDOC_STORAGE_HXX
22 :
23 : #include <map>
24 :
25 : #include "osl/mutex.hxx"
26 : #include "rtl/ref.hxx"
27 : #include "salhelper/simplereferenceobject.hxx"
28 :
29 : #include "com/sun/star/embed/XStorage.hpp"
30 :
31 : namespace tdoc_ucp {
32 :
33 : enum StorageAccessMode
34 : {
35 : READ, // Note: might be writable as well
36 : READ_WRITE_NOCREATE,
37 : READ_WRITE_CREATE
38 : };
39 :
40 : class Storage;
41 : class OfficeDocumentsManager;
42 :
43 : class StorageElementFactory : public salhelper::SimpleReferenceObject
44 : {
45 : public:
46 : StorageElementFactory(
47 : const com::sun::star::uno::Reference<
48 : com::sun::star::uno::XComponentContext > & rxContext,
49 : const rtl::Reference< OfficeDocumentsManager > & xDocsMgr );
50 : virtual ~StorageElementFactory();
51 :
52 : com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
53 : createTemporaryStorage()
54 : throw ( com::sun::star::uno::Exception,
55 : com::sun::star::uno::RuntimeException );
56 :
57 : com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
58 : createStorage( const OUString & rUri, StorageAccessMode eMode )
59 : throw ( com::sun::star::embed::InvalidStorageException,
60 : com::sun::star::lang::IllegalArgumentException,
61 : com::sun::star::io::IOException,
62 : com::sun::star::embed::StorageWrappedTargetException,
63 : com::sun::star::uno::RuntimeException );
64 :
65 : com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
66 : createInputStream( const OUString & rUri,
67 : const OUString & rPassword )
68 : throw ( com::sun::star::embed::InvalidStorageException,
69 : com::sun::star::lang::IllegalArgumentException,
70 : com::sun::star::io::IOException,
71 : com::sun::star::embed::StorageWrappedTargetException,
72 : com::sun::star::packages::WrongPasswordException,
73 : com::sun::star::uno::RuntimeException );
74 :
75 : com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >
76 : createOutputStream( const OUString & rUri,
77 : const OUString & rPassword,
78 : bool bTruncate )
79 : throw ( com::sun::star::embed::InvalidStorageException,
80 : com::sun::star::lang::IllegalArgumentException,
81 : com::sun::star::io::IOException,
82 : com::sun::star::embed::StorageWrappedTargetException,
83 : com::sun::star::packages::WrongPasswordException,
84 : com::sun::star::uno::RuntimeException );
85 :
86 : com::sun::star::uno::Reference< com::sun::star::io::XStream >
87 : createStream( const OUString & rUri,
88 : const OUString & rPassword,
89 : bool bTruncate )
90 : throw ( com::sun::star::embed::InvalidStorageException,
91 : com::sun::star::lang::IllegalArgumentException,
92 : com::sun::star::io::IOException,
93 : com::sun::star::embed::StorageWrappedTargetException,
94 : com::sun::star::packages::WrongPasswordException,
95 : com::sun::star::uno::RuntimeException );
96 :
97 : private:
98 : friend class Storage;
99 :
100 : void releaseElement( Storage * pElement ) SAL_THROW(());
101 :
102 : com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
103 : queryParentStorage( const OUString & rUri,
104 : StorageAccessMode eMode )
105 : throw ( com::sun::star::embed::InvalidStorageException,
106 : com::sun::star::lang::IllegalArgumentException,
107 : com::sun::star::io::IOException,
108 : com::sun::star::embed::StorageWrappedTargetException,
109 : com::sun::star::uno::RuntimeException );
110 :
111 : com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
112 : queryStorage( const com::sun::star::uno::Reference<
113 : com::sun::star::embed::XStorage > & xParentStorage,
114 : const OUString & rUri,
115 : StorageAccessMode eMode )
116 : throw ( com::sun::star::embed::InvalidStorageException,
117 : com::sun::star::lang::IllegalArgumentException,
118 : com::sun::star::io::IOException,
119 : com::sun::star::embed::StorageWrappedTargetException,
120 : com::sun::star::uno::RuntimeException );
121 :
122 : com::sun::star::uno::Reference< com::sun::star::io::XStream >
123 : queryStream( const com::sun::star::uno::Reference<
124 : com::sun::star::embed::XStorage > & xParentStorage,
125 : const OUString & rPassword,
126 : const OUString & rUri,
127 : StorageAccessMode eMode,
128 : bool bTruncate /* ignored for read-only streams */ )
129 : throw ( com::sun::star::embed::InvalidStorageException,
130 : com::sun::star::lang::IllegalArgumentException,
131 : com::sun::star::io::IOException,
132 : com::sun::star::embed::StorageWrappedTargetException,
133 : com::sun::star::packages::WrongPasswordException,
134 : com::sun::star::uno::RuntimeException );
135 :
136 : struct ltstrbool
137 : {
138 0 : bool operator()(
139 : const std::pair< OUString, bool > & s1,
140 : const std::pair< OUString, bool > & s2 ) const
141 : {
142 0 : if ( s1.first < s2.first )
143 0 : return true;
144 0 : else if ( s1.first == s2.first )
145 0 : return ( !s1.second && s2.second );
146 : else
147 0 : return false;
148 : }
149 : };
150 :
151 : // key: pair< storageuri, iswritable >
152 : typedef std::map<
153 : std::pair< OUString, bool >, Storage *, ltstrbool > StorageMap;
154 :
155 : StorageMap m_aMap;
156 : osl::Mutex m_aMutex;
157 : rtl::Reference< OfficeDocumentsManager > m_xDocsMgr;
158 : com::sun::star::uno::Reference<
159 : com::sun::star::uno::XComponentContext > m_xContext;
160 : };
161 :
162 : } // namespace tdoc_ucp
163 :
164 : #endif /* !INCLUDED_TDOC_STORAGE_HXX */
165 :
166 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|