xref: /trunk/main/ucb/source/ucp/package/pkgcontent.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _PKGCONTENT_HXX
25 #define _PKGCONTENT_HXX
26 
27 #include <list>
28 #include <rtl/ref.hxx>
29 
30 #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
31 #include <com/sun/star/ucb/XContentCreator.hpp>
32 #include <ucbhelper/contenthelper.hxx>
33 #include "pkguri.hxx"
34 
35 namespace com { namespace sun { namespace star {
36     namespace beans
37     {
38         struct Property;
39         struct PropertyValue;
40     }
41     namespace container
42     {
43         class XHierarchicalNameAccess;
44         class XEnumeration;
45     }
46     namespace io
47     {
48         class XInputStream;
49     }
50     namespace sdbc
51     {
52         class XRow;
53     }
54     namespace ucb
55     {
56         struct OpenCommandArgument2;
57         struct TransferInfo;
58     }
59 } } }
60 
61 namespace package_ucp
62 {
63 
64 //=========================================================================
65 
66 // UNO service name for the content.
67 #define PACKAGE_FOLDER_CONTENT_SERVICE_NAME \
68                             "com.sun.star.ucb.PackageFolderContent"
69 #define PACKAGE_STREAM_CONTENT_SERVICE_NAME \
70                             "com.sun.star.ucb.PackageStreamContent"
71 
72 //=========================================================================
73 
74 struct ContentProperties
75 {
76     ::rtl::OUString  aTitle;                // Title
77     ::rtl::OUString  aContentType;          // ContentType
78     sal_Bool         bIsDocument;           // IsDocument
79     sal_Bool         bIsFolder;             // IsFolder
80     ::rtl::OUString  aMediaType;            // MediaType
81     com::sun::star::uno::Sequence <
82         sal_Int8 >   aEncryptionKey;        // EncryptionKey
83     sal_Int64        nSize;                 // Size
84     sal_Bool         bCompressed;           // Compressed
85     sal_Bool         bEncrypted;            // Encrypted
86     sal_Bool         bHasEncryptedEntries;  // HasEncryptedEntries
87 
ContentPropertiespackage_ucp::ContentProperties88     ContentProperties()
89     : bIsDocument( sal_True ), bIsFolder( sal_False ), nSize( 0 ),
90       bCompressed( sal_True ), bEncrypted( sal_False ),
91       bHasEncryptedEntries( sal_False ) {}
92 
93     ContentProperties( const ::rtl::OUString& rContentType );
94 
95     com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo >
96     getCreatableContentsInfo( PackageUri const & rUri ) const;
97 };
98 
99 //=========================================================================
100 
101 class ContentProvider;
102 
103 class Content : public ::ucbhelper::ContentImplHelper,
104                 public com::sun::star::ucb::XContentCreator
105 {
106     enum ContentState { TRANSIENT,  // created via CreateNewContent,
107                                         // but did not process "insert" yet
108                         PERSISTENT, // processed "insert"
109                         DEAD        // processed "delete"
110                       };
111 
112     PackageUri              m_aUri;
113     ContentProperties       m_aProps;
114     ContentState            m_eState;
115     com::sun::star::uno::Reference<
116         com::sun::star::container::XHierarchicalNameAccess > m_xPackage;
117     ContentProvider*        m_pProvider;
118     sal_uInt32              m_nModifiedProps;
119 
120 private:
121     Content( const com::sun::star::uno::Reference<
122                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
123              ContentProvider* pProvider,
124              const com::sun::star::uno::Reference<
125                 com::sun::star::ucb::XContentIdentifier >& Identifier,
126              const ::com::sun::star::uno::Reference<
127                 com::sun::star::container::XHierarchicalNameAccess >& Package,
128              const PackageUri& rUri,
129              const ContentProperties& rProps );
130     Content( const com::sun::star::uno::Reference<
131                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
132              ContentProvider* pProvider,
133              const com::sun::star::uno::Reference<
134                 com::sun::star::ucb::XContentIdentifier >& Identifier,
135              const com::sun::star::uno::Reference<
136                 com::sun::star::container::XHierarchicalNameAccess >& Package,
137              const PackageUri& rUri,
138              const com::sun::star::ucb::ContentInfo& Info );
139 
140     virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
141     getProperties( const com::sun::star::uno::Reference<
142                     com::sun::star::ucb::XCommandEnvironment > & xEnv );
143     virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
144     getCommands( const com::sun::star::uno::Reference<
145                     com::sun::star::ucb::XCommandEnvironment > & xEnv );
146     virtual ::rtl::OUString getParentURL();
147 
148     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
149     getPropertyValues( const ::com::sun::star::uno::Reference<
150                         ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
151                        const ::com::sun::star::uno::Sequence<
152                             ::com::sun::star::beans::Property >& rProperties,
153                        const ContentProperties& rData,
154                        const rtl::Reference<
155                             ::ucbhelper::ContentProviderImplHelper >& rProvider,
156                        const ::rtl::OUString& rContentId );
157 
158     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
159     getPropertyValues( const ::com::sun::star::uno::Sequence<
160                         ::com::sun::star::beans::Property >& rProperties );
161     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
162     setPropertyValues( const ::com::sun::star::uno::Sequence<
163                         ::com::sun::star::beans::PropertyValue >& rValues,
164                        const ::com::sun::star::uno::Reference<
165                         ::com::sun::star::ucb::XCommandEnvironment > & xEnv );
166 
167     com::sun::star::uno::Reference<
168         com::sun::star::container::XHierarchicalNameAccess >
169     getPackage( const PackageUri& rURI );
170     com::sun::star::uno::Reference<
171         com::sun::star::container::XHierarchicalNameAccess >
172     getPackage();
173 
174     static sal_Bool
175     loadData( ContentProvider* pProvider,
176               const PackageUri& rURI,
177               ContentProperties& rProps,
178               com::sun::star::uno::Reference<
179                 com::sun::star::container::XHierarchicalNameAccess > &
180                     rxPackage );
181     static sal_Bool
182     hasData( ContentProvider* pProvider,
183              const PackageUri& rURI,
184              com::sun::star::uno::Reference<
185                 com::sun::star::container::XHierarchicalNameAccess > &
186                     rxPackage );
187 
188     sal_Bool
189     hasData( const PackageUri& rURI );
190     sal_Bool
191     renameData( const com::sun::star::uno::Reference<
192                     com::sun::star::ucb::XContentIdentifier >& xOldId,
193                 const com::sun::star::uno::Reference<
194                     com::sun::star::ucb::XContentIdentifier >& xNewId );
195     sal_Bool
196     storeData( const com::sun::star::uno::Reference<
197                     com::sun::star::io::XInputStream >& xStream );
198     sal_Bool
199     removeData();
200 
201     sal_Bool
202     flushData();
203 
204     typedef rtl::Reference< Content > ContentRef;
205     typedef std::list< ContentRef > ContentRefList;
206     void queryChildren( ContentRefList& rChildren );
207 
208     sal_Bool
209     exchangeIdentity( const ::com::sun::star::uno::Reference<
210                         ::com::sun::star::ucb::XContentIdentifier >& xNewId );
211 
212     ::com::sun::star::uno::Any
213     open( const ::com::sun::star::ucb::OpenCommandArgument2& rArg,
214           const ::com::sun::star::uno::Reference<
215                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv );
216 
217     void insert( const ::com::sun::star::uno::Reference<
218                         ::com::sun::star::io::XInputStream >& xStream,
219                  sal_Int32 nNameClashResolve,
220                  const ::com::sun::star::uno::Reference<
221                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv );
222 
223     void destroy( sal_Bool bDeletePhysical,
224                   const ::com::sun::star::uno::Reference<
225                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv );
226 
227     void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo,
228                    const ::com::sun::star::uno::Reference<
229                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv );
230 
231     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
232     getInputStream();
233 
isFolder() const234     sal_Bool isFolder() const { return m_aProps.bIsFolder; }
235 
236 public:
237     // Create existing content. Fail, if not already exists.
238     static Content* create(
239             const com::sun::star::uno::Reference<
240                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
241             ContentProvider* pProvider,
242             const com::sun::star::uno::Reference<
243                 com::sun::star::ucb::XContentIdentifier >& Identifier );
244 
245     // Create new content. Fail, if already exists.
246     static Content* create(
247             const com::sun::star::uno::Reference<
248                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
249             ContentProvider* pProvider,
250             const com::sun::star::uno::Reference<
251                 com::sun::star::ucb::XContentIdentifier >& Identifier,
252             const com::sun::star::ucb::ContentInfo& Info );
253 
254     virtual ~Content();
255 
256     // XInterface
257     XINTERFACE_DECL()
258 
259     // XTypeProvider
260     XTYPEPROVIDER_DECL()
261 
262     // XServiceInfo
263     virtual ::rtl::OUString SAL_CALL
264     getImplementationName();
265     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
266     getSupportedServiceNames();
267 
268     // XContent
269     virtual rtl::OUString SAL_CALL
270     getContentType();
271 
272     // XCommandProcessor
273     virtual com::sun::star::uno::Any SAL_CALL
274     execute( const com::sun::star::ucb::Command& aCommand,
275              sal_Int32 CommandId,
276              const com::sun::star::uno::Reference<
277                 com::sun::star::ucb::XCommandEnvironment >& Environment );
278     virtual void SAL_CALL
279     abort( sal_Int32 CommandId );
280 
281     //////////////////////////////////////////////////////////////////////
282     // Additional interfaces
283     //////////////////////////////////////////////////////////////////////
284 
285     // XContentCreator
286     virtual com::sun::star::uno::Sequence<
287                 com::sun::star::ucb::ContentInfo > SAL_CALL
288     queryCreatableContentsInfo();
289     virtual com::sun::star::uno::Reference<
290                 com::sun::star::ucb::XContent > SAL_CALL
291     createNewContent( const com::sun::star::ucb::ContentInfo& Info );
292 
293     //////////////////////////////////////////////////////////////////////
294     // Non-interface methods.
295     //////////////////////////////////////////////////////////////////////
296 
297     // Called from resultset data supplier.
298     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
299     getPropertyValues( const ::com::sun::star::uno::Reference<
300                         ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
301                        const ::com::sun::star::uno::Sequence<
302                             ::com::sun::star::beans::Property >& rProperties,
303                        ContentProvider* pProvider,
304                        const ::rtl::OUString& rContentId );
305 
306     // Called from resultset data supplier.
307     ::com::sun::star::uno::Reference<
308         ::com::sun::star::container::XEnumeration >
309     getIterator();
310 
311     static ::rtl::OUString
312     getContentType( const ::rtl::OUString& aScheme,  sal_Bool bFolder );
313 };
314 
315 }
316 
317 #endif
318