1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ZipPackage.hxx,v $
10 * $Revision: 1.41.20.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _ZIP_PACKAGE_HXX
31 #define _ZIP_PACKAGE_HXX
33 #include <cppuhelper/implbase7.hxx>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
36 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37 #include <com/sun/star/util/XChangesBatch.hpp>
38 #include <com/sun/star/lang/XUnoTunnel.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #ifndef _COM_SUN_STAR_LANG_XPSERVICEINFO_HPP_
42 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <HashMaps.hxx>
45 #include <com/sun/star/lang/IllegalArgumentException.hpp>
47 #include <mutexholder.hxx>
49 class ZipOutputStream
;
50 class ZipPackageFolder
;
53 namespace com
{ namespace sun
{ namespace star
{
54 namespace container
{ class XNameContainer
; }
55 namespace io
{ class XStream
; class XOutputStream
; class XInputStream
; class XSeekable
; class XActiveDataStreamer
; }
56 namespace lang
{ class XMultiServiceFactory
; }
57 namespace task
{ class XInteractionHandler
; }
67 enum InitialisationMode
75 class ZipPackage
: public cppu::WeakImplHelper7
77 com::sun::star::lang::XInitialization
,
78 com::sun::star::lang::XSingleServiceFactory
,
79 com::sun::star::lang::XUnoTunnel
,
80 com::sun::star::lang::XServiceInfo
,
81 com::sun::star::container::XHierarchicalNameAccess
,
82 com::sun::star::util::XChangesBatch
,
83 com::sun::star::beans::XPropertySet
87 SotMutexHolderRef m_aMutexHolder
;
89 ::com::sun::star::uno::Sequence
< sal_Int8
> aEncryptionKey
;
92 sal_Bool bHasEncryptedEntries
;
93 sal_Bool bUseManifest
;
94 sal_Bool bForceRecovery
;
96 sal_Bool m_bMediaTypeFallbackUsed
;
98 sal_Bool m_bAllowRemoveOnInsert
;
100 InitialisationMode eMode
;
102 ::com::sun::star::uno::Reference
< com::sun::star::container::XNameContainer
> xRootFolder
;
103 ::com::sun::star::uno::Reference
< com::sun::star::io::XStream
> xStream
;
104 ::com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> xContentStream
;
105 ::com::sun::star::uno::Reference
< com::sun::star::io::XSeekable
> xContentSeek
;
106 const ::com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> xFactory
;
108 ZipPackageFolder
*pRootFolder
;
111 void parseManifest();
112 void parseContentType();
113 void getZipFileContents();
115 void WriteMimetypeMagicFile( ZipOutputStream
& aZipOut
);
116 void WriteManifest( ZipOutputStream
& aZipOut
, const ::std::vector
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> >& aManList
);
117 void WriteContentTypes( ZipOutputStream
& aZipOut
, const ::std::vector
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> >& aManList
);
119 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> writeTempFile();
120 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XActiveDataStreamer
> openOriginalForOutput();
121 void DisconnectFromTargetAndThrowException_Impl(
122 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xTempStream
);
125 ZipPackage (const ::com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> &xNewFactory
);
126 virtual ~ZipPackage( void );
127 ZipFile
& getZipFile() { return *pZipFile
;}
128 const com::sun::star::uno::Sequence
< sal_Int8
> & getEncryptionKey ( ) {return aEncryptionKey
;}
129 sal_Int16
getFormat() const { return m_nFormat
; }
131 SotMutexHolderRef
GetSharedMutexRef() { return m_aMutexHolder
; }
133 void ConnectTo( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xInStream
);
136 virtual void SAL_CALL
initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
)
137 throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
138 // XHierarchicalNameAccess
139 virtual ::com::sun::star::uno::Any SAL_CALL
getByHierarchicalName( const ::rtl::OUString
& aName
)
140 throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
);
141 virtual sal_Bool SAL_CALL
hasByHierarchicalName( const ::rtl::OUString
& aName
)
142 throw(::com::sun::star::uno::RuntimeException
);
143 // XSingleServiceFactory
144 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
createInstance( )
145 throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
146 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
createInstanceWithArguments( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
)
147 throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
149 virtual void SAL_CALL
commitChanges( )
150 throw(::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
151 virtual sal_Bool SAL_CALL
hasPendingChanges( )
152 throw(::com::sun::star::uno::RuntimeException
);
153 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::util::ElementChange
> SAL_CALL
getPendingChanges( )
154 throw(::com::sun::star::uno::RuntimeException
);
156 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
)
157 throw(::com::sun::star::uno::RuntimeException
);
158 com::sun::star::uno::Sequence
< sal_Int8
> getUnoTunnelImplementationId( void )
159 throw(::com::sun::star::uno::RuntimeException
);
161 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( )
162 throw(::com::sun::star::uno::RuntimeException
);
163 virtual void SAL_CALL
setPropertyValue( const ::rtl::OUString
& aPropertyName
, const ::com::sun::star::uno::Any
& aValue
)
164 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
165 virtual ::com::sun::star::uno::Any SAL_CALL
getPropertyValue( const ::rtl::OUString
& PropertyName
)
166 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
167 virtual void SAL_CALL
addPropertyChangeListener( const ::rtl::OUString
& aPropertyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& xListener
)
168 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
169 virtual void SAL_CALL
removePropertyChangeListener( const ::rtl::OUString
& aPropertyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& aListener
)
170 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
171 virtual void SAL_CALL
addVetoableChangeListener( const ::rtl::OUString
& PropertyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XVetoableChangeListener
>& aListener
)
172 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
173 virtual void SAL_CALL
removeVetoableChangeListener( const ::rtl::OUString
& PropertyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XVetoableChangeListener
>& aListener
)
174 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
177 virtual ::rtl::OUString SAL_CALL
getImplementationName( )
178 throw (::com::sun::star::uno::RuntimeException
);
179 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
)
180 throw (::com::sun::star::uno::RuntimeException
);
181 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( )
182 throw (::com::sun::star::uno::RuntimeException
);
184 // Uno componentiseralation
185 static ::rtl::OUString
static_getImplementationName();
186 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> static_getSupportedServiceNames();
187 static ::com::sun::star::uno::Reference
< com::sun::star::lang::XSingleServiceFactory
> createServiceFactory( com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> const & rServiceFactory
);
188 sal_Bool SAL_CALL
static_supportsService(rtl::OUString
const & rServiceName
);