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