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