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         throw( ::com::sun::star::uno::Exception );
167 
168     com::sun::star::uno::Reference<
169         com::sun::star::container::XHierarchicalNameAccess >
170     getPackage( const PackageUri& rURI );
171     com::sun::star::uno::Reference<
172         com::sun::star::container::XHierarchicalNameAccess >
173     getPackage();
174 
175     static sal_Bool
176     loadData( ContentProvider* pProvider,
177               const PackageUri& rURI,
178               ContentProperties& rProps,
179               com::sun::star::uno::Reference<
180                 com::sun::star::container::XHierarchicalNameAccess > &
181                     rxPackage );
182     static sal_Bool
183     hasData( ContentProvider* pProvider,
184              const PackageUri& rURI,
185              com::sun::star::uno::Reference<
186                 com::sun::star::container::XHierarchicalNameAccess > &
187                     rxPackage );
188 
189     sal_Bool
190     hasData( const PackageUri& rURI );
191     sal_Bool
192     renameData( const com::sun::star::uno::Reference<
193                     com::sun::star::ucb::XContentIdentifier >& xOldId,
194                 const com::sun::star::uno::Reference<
195                     com::sun::star::ucb::XContentIdentifier >& xNewId );
196     sal_Bool
197     storeData( const com::sun::star::uno::Reference<
198                     com::sun::star::io::XInputStream >& xStream );
199     sal_Bool
200     removeData();
201 
202     sal_Bool
203     flushData();
204 
205     typedef rtl::Reference< Content > ContentRef;
206     typedef std::list< ContentRef > ContentRefList;
207     void queryChildren( ContentRefList& rChildren );
208 
209     sal_Bool
210     exchangeIdentity( const ::com::sun::star::uno::Reference<
211                         ::com::sun::star::ucb::XContentIdentifier >& xNewId );
212 
213     ::com::sun::star::uno::Any
214     open( const ::com::sun::star::ucb::OpenCommandArgument2& rArg,
215           const ::com::sun::star::uno::Reference<
216                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
217         throw( ::com::sun::star::uno::Exception );
218 
219     void insert( const ::com::sun::star::uno::Reference<
220                         ::com::sun::star::io::XInputStream >& xStream,
221                  sal_Int32 nNameClashResolve,
222                  const ::com::sun::star::uno::Reference<
223                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
224         throw( ::com::sun::star::uno::Exception );
225 
226     void destroy( sal_Bool bDeletePhysical,
227                   const ::com::sun::star::uno::Reference<
228                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
229         throw( ::com::sun::star::uno::Exception );
230 
231     void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo,
232                    const ::com::sun::star::uno::Reference<
233                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
234         throw( ::com::sun::star::uno::Exception );
235 
236     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
237     getInputStream();
238 
isFolder() const239     sal_Bool isFolder() const { return m_aProps.bIsFolder; }
240 
241 public:
242     // Create existing content. Fail, if not already exists.
243     static Content* create(
244             const com::sun::star::uno::Reference<
245                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
246             ContentProvider* pProvider,
247             const com::sun::star::uno::Reference<
248                 com::sun::star::ucb::XContentIdentifier >& Identifier );
249 
250     // Create new content. Fail, if already exists.
251     static Content* create(
252             const com::sun::star::uno::Reference<
253                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
254             ContentProvider* pProvider,
255             const com::sun::star::uno::Reference<
256                 com::sun::star::ucb::XContentIdentifier >& Identifier,
257             const com::sun::star::ucb::ContentInfo& Info );
258 
259     virtual ~Content();
260 
261     // XInterface
262     XINTERFACE_DECL()
263 
264     // XTypeProvider
265     XTYPEPROVIDER_DECL()
266 
267     // XServiceInfo
268     virtual ::rtl::OUString SAL_CALL
269     getImplementationName()
270         throw( ::com::sun::star::uno::RuntimeException );
271     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
272     getSupportedServiceNames()
273         throw( ::com::sun::star::uno::RuntimeException );
274 
275     // XContent
276     virtual rtl::OUString SAL_CALL
277     getContentType()
278         throw( com::sun::star::uno::RuntimeException );
279 
280     // XCommandProcessor
281     virtual com::sun::star::uno::Any SAL_CALL
282     execute( const com::sun::star::ucb::Command& aCommand,
283              sal_Int32 CommandId,
284              const com::sun::star::uno::Reference<
285                 com::sun::star::ucb::XCommandEnvironment >& Environment )
286         throw( com::sun::star::uno::Exception,
287                com::sun::star::ucb::CommandAbortedException,
288                com::sun::star::uno::RuntimeException );
289     virtual void SAL_CALL
290     abort( sal_Int32 CommandId )
291         throw( com::sun::star::uno::RuntimeException );
292 
293     //////////////////////////////////////////////////////////////////////
294     // Additional interfaces
295     //////////////////////////////////////////////////////////////////////
296 
297     // XContentCreator
298     virtual com::sun::star::uno::Sequence<
299                 com::sun::star::ucb::ContentInfo > SAL_CALL
300     queryCreatableContentsInfo()
301         throw( com::sun::star::uno::RuntimeException );
302     virtual com::sun::star::uno::Reference<
303                 com::sun::star::ucb::XContent > SAL_CALL
304     createNewContent( const com::sun::star::ucb::ContentInfo& Info )
305         throw( com::sun::star::uno::RuntimeException );
306 
307     //////////////////////////////////////////////////////////////////////
308     // Non-interface methods.
309     //////////////////////////////////////////////////////////////////////
310 
311     // Called from resultset data supplier.
312     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
313     getPropertyValues( const ::com::sun::star::uno::Reference<
314                         ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
315                        const ::com::sun::star::uno::Sequence<
316                             ::com::sun::star::beans::Property >& rProperties,
317                        ContentProvider* pProvider,
318                        const ::rtl::OUString& rContentId );
319 
320     // Called from resultset data supplier.
321     ::com::sun::star::uno::Reference<
322         ::com::sun::star::container::XEnumeration >
323     getIterator();
324 
325     static ::rtl::OUString
326     getContentType( const ::rtl::OUString& aScheme,  sal_Bool bFolder );
327 };
328 
329 }
330 
331 #endif
332