1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _ZIP_PACKAGE_HXX
20 #define _ZIP_PACKAGE_HXX
22 #include <cppuhelper/implbase7.hxx>
23 #include <com/sun/star/lang/XInitialization.hpp>
24 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
25 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
26 #include <com/sun/star/util/XChangesBatch.hpp>
27 #include <com/sun/star/lang/XUnoTunnel.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <com/sun/star/beans/NamedValue.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/xml/crypto/CipherID.hpp>
33 #include <com/sun/star/lang/IllegalArgumentException.hpp>
35 #include <HashMaps.hxx>
37 #include <mutexholder.hxx>
40 class ZipOutputStream
;
41 class ZipPackageFolder
;
43 namespace com
{ namespace sun
{ namespace star
{
44 namespace container
{ class XNameContainer
; }
45 namespace io
{ class XStream
; class XOutputStream
; class XInputStream
; class XSeekable
; class XActiveDataStreamer
; }
46 namespace lang
{ class XMultiServiceFactory
; }
47 namespace uno
{ class XComponentContext
; }
48 namespace task
{ class XInteractionHandler
; }
58 enum InitialisationMode
66 class ZipPackage
: public cppu::WeakImplHelper7
68 com::sun::star::lang::XInitialization
,
69 com::sun::star::lang::XSingleServiceFactory
,
70 com::sun::star::lang::XUnoTunnel
,
71 com::sun::star::lang::XServiceInfo
,
72 com::sun::star::container::XHierarchicalNameAccess
,
73 com::sun::star::util::XChangesBatch
,
74 com::sun::star::beans::XPropertySet
78 SotMutexHolderRef m_aMutexHolder
;
80 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
> m_aStorageEncryptionKeys
;
81 ::com::sun::star::uno::Sequence
< sal_Int8
> m_aEncryptionKey
;
86 sal_Int32 m_nStartKeyGenerationID
;
87 sal_Int32 m_nChecksumDigestID
;
88 sal_Int32 m_nCommonEncryptionID
;
89 sal_Bool m_bHasEncryptedEntries
;
90 sal_Bool m_bHasNonEncryptedEntries
;
92 sal_Bool m_bInconsistent
;
93 sal_Bool m_bForceRecovery
;
95 sal_Bool m_bMediaTypeFallbackUsed
;
97 sal_Bool m_bAllowRemoveOnInsert
;
99 InitialisationMode m_eMode
;
101 ::com::sun::star::uno::Reference
< com::sun::star::container::XNameContainer
> m_xRootFolder
;
102 ::com::sun::star::uno::Reference
< com::sun::star::io::XStream
> m_xStream
;
103 ::com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> m_xContentStream
;
104 ::com::sun::star::uno::Reference
< com::sun::star::io::XSeekable
> m_xContentSeek
;
105 const ::com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_xContext
;
107 ZipPackageFolder
*m_pRootFolder
;
110 sal_Bool
isLocalFile() const;
112 void parseManifest();
113 void parseContentType();
114 void getZipFileContents();
116 void WriteMimetypeMagicFile( ZipOutputStream
& aZipOut
);
117 void WriteManifest( ZipOutputStream
& aZipOut
, const ::std::vector
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> >& aManList
);
118 void WriteContentTypes( ZipOutputStream
& aZipOut
, const ::std::vector
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> >& aManList
);
120 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> writeTempFile();
121 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XActiveDataStreamer
> openOriginalForOutput();
122 void DisconnectFromTargetAndThrowException_Impl(
123 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xTempStream
);
126 ZipPackage( const ::com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> &xContext
);
127 virtual ~ZipPackage( void );
128 ZipFile
& getZipFile() { return *m_pZipFile
;}
129 sal_Int32
getFormat() const { return m_nFormat
; }
131 sal_Int32
GetStartKeyGenID() const { return m_nStartKeyGenerationID
; }
132 sal_Int32
GetEncAlgID() const { return m_nCommonEncryptionID
; }
133 sal_Int32
GetChecksumAlgID() const { return m_nChecksumDigestID
; }
134 sal_Int32
GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID
== ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING
? 32 : 16; }
136 SotMutexHolderRef
GetSharedMutexRef() { return m_aMutexHolder
; }
138 void ConnectTo( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xInStream
);
139 const ::com::sun::star::uno::Sequence
< sal_Int8
> GetEncryptionKey();
142 virtual void SAL_CALL
initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
)
143 throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
144 // XHierarchicalNameAccess
145 virtual ::com::sun::star::uno::Any SAL_CALL
getByHierarchicalName( const OUString
& aName
)
146 throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
);
147 virtual sal_Bool SAL_CALL
hasByHierarchicalName( const OUString
& aName
)
148 throw(::com::sun::star::uno::RuntimeException
);
149 // XSingleServiceFactory
150 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
createInstance( )
151 throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
152 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
)
153 throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
155 virtual void SAL_CALL
commitChanges( )
156 throw(::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
157 virtual sal_Bool SAL_CALL
hasPendingChanges( )
158 throw(::com::sun::star::uno::RuntimeException
);
159 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::util::ElementChange
> SAL_CALL
getPendingChanges( )
160 throw(::com::sun::star::uno::RuntimeException
);
162 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
)
163 throw(::com::sun::star::uno::RuntimeException
);
164 com::sun::star::uno::Sequence
< sal_Int8
> getUnoTunnelImplementationId( void )
165 throw(::com::sun::star::uno::RuntimeException
);
167 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( )
168 throw(::com::sun::star::uno::RuntimeException
);
169 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const ::com::sun::star::uno::Any
& aValue
)
170 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
);
171 virtual ::com::sun::star::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
)
172 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
173 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& xListener
)
174 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
175 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& aListener
)
176 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
177 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XVetoableChangeListener
>& aListener
)
178 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
179 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XVetoableChangeListener
>& aListener
)
180 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
183 virtual OUString SAL_CALL
getImplementationName( )
184 throw (::com::sun::star::uno::RuntimeException
);
185 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
)
186 throw (::com::sun::star::uno::RuntimeException
);
187 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( )
188 throw (::com::sun::star::uno::RuntimeException
);
190 // Uno componentiseralation
191 static OUString
static_getImplementationName();
192 static ::com::sun::star::uno::Sequence
< OUString
> static_getSupportedServiceNames();
193 static ::com::sun::star::uno::Reference
< com::sun::star::lang::XSingleServiceFactory
> createServiceFactory( com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> const & rServiceFactory
);
194 sal_Bool SAL_CALL
static_supportsService(OUString
const & rServiceName
);
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */