diff options
Diffstat (limited to 'package/source')
65 files changed, 0 insertions, 24999 deletions
diff --git a/package/source/manifest/Base64Codec.cxx b/package/source/manifest/Base64Codec.cxx deleted file mode 100644 index 5dc4ebfa4..000000000 --- a/package/source/manifest/Base64Codec.cxx +++ /dev/null @@ -1,208 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include "Base64Codec.hxx" -#include <rtl/ustrbuf.hxx> -#include <osl/diagnose.h> -using namespace osl; -using namespace com::sun::star; - -using ::rtl::OUStringBuffer; - -const - sal_Char aBase64EncodeTable[] = - { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; - -const - sal_uInt8 aBase64DecodeTable[] = - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-15 - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31 - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, // 32-47 -// + / - - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, // 48-63 -// 0 1 2 3 4 5 6 7 8 9 = - - 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 64-79 -// A B C D E F G H I J K L M N O - - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, // 80-95 -// P Q R S T U V W X Y Z - - 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 96-111 -// a b c d e f g h i j k l m n o - - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, // 112-127 -// p q r s t u v w x y z - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - - -void ThreeByteToFourByte (const sal_uInt8* pBuffer, const sal_Int32 nStart, const sal_Int32 nFullLen, rtl::OUStringBuffer& sBuffer) -{ - sal_Int32 nLen(nFullLen - nStart); - if (nLen > 3) - nLen = 3; - if (nLen == 0) - { - sBuffer.setLength(0); - return; - } - - sal_Int32 nBinaer; - switch (nLen) - { - case 1: - { - nBinaer = ((sal_uInt8)pBuffer[nStart + 0]) << 16; - } - break; - case 2: - { - nBinaer = (((sal_uInt8)pBuffer[nStart + 0]) << 16) + - (((sal_uInt8)pBuffer[nStart + 1]) << 8); - } - break; - default: - { - nBinaer = (((sal_uInt8)pBuffer[nStart + 0]) << 16) + - (((sal_uInt8)pBuffer[nStart + 1]) << 8) + - ((sal_uInt8)pBuffer[nStart + 2]); - } - break; - } - - sBuffer.appendAscii("===="); - - sal_uInt8 nIndex = static_cast< sal_uInt8 >((nBinaer & 0xFC0000) >> 18); - sBuffer.setCharAt(0, aBase64EncodeTable [nIndex]); - - nIndex = static_cast< sal_uInt8 >((nBinaer & 0x3F000) >> 12); - sBuffer.setCharAt(1, aBase64EncodeTable [nIndex]); - if (nLen == 1) - return; - - nIndex = static_cast< sal_uInt8 >((nBinaer & 0xFC0) >> 6); - sBuffer.setCharAt(2, aBase64EncodeTable [nIndex]); - if (nLen == 2) - return; - - nIndex = static_cast< sal_uInt8 >(nBinaer & 0x3F); - sBuffer.setCharAt(3, aBase64EncodeTable [nIndex]); -} - -void Base64Codec::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence < sal_Int8 >& aPass) -{ - sal_Int32 i(0); - sal_Int32 nBufferLength(aPass.getLength()); - const sal_uInt8* pBuffer = reinterpret_cast< const sal_uInt8* >( aPass.getConstArray() ); - while (i < nBufferLength) - { - rtl::OUStringBuffer sBuffer; - ThreeByteToFourByte (pBuffer, i, nBufferLength, sBuffer); - aStrBuffer.append(sBuffer); - i += 3; - } -} - -const rtl::OUString s2equal(RTL_CONSTASCII_USTRINGPARAM("==")); -const rtl::OUString s1equal(RTL_CONSTASCII_USTRINGPARAM("=")); - -void FourByteToThreeByte (sal_uInt8* pBuffer, sal_Int32& nLength, const sal_Int32 nStart, const rtl::OUString& sString) -{ - nLength = 0; - sal_Int32 nLen (sString.getLength()); - - OSL_ASSERT( nLen == 4 ); - if (nLen != 4) - return; - - if (sString.indexOf(s2equal) == 2) - nLength = 1; - else if (sString.indexOf(s1equal) == 3) - nLength = 2; - else - nLength = 3; - - sal_Int32 nBinaer ((aBase64DecodeTable [sString [0]] << 18) + - (aBase64DecodeTable [sString [1]] << 12) + - (aBase64DecodeTable [sString [2]] << 6) + - (aBase64DecodeTable [sString [3]])); - - sal_uInt8 OneByte = static_cast< sal_uInt8 >((nBinaer & 0xFF0000) >> 16); - pBuffer[nStart + 0] = (sal_uInt8)OneByte; - - if (nLength == 1) - return; - - OneByte = static_cast< sal_uInt8 >((nBinaer & 0xFF00) >> 8); - pBuffer[nStart + 1] = OneByte; - - if (nLength == 2) - return; - - OneByte = static_cast< sal_uInt8 >(nBinaer & 0xFF); - pBuffer[nStart + 2] = OneByte; -} - -void Base64Codec::decodeBase64(uno::Sequence< sal_Int8 >& aBuffer, const rtl::OUString& sBuffer) -{ - sal_Int32 nFirstLength((sBuffer.getLength() / 4) * 3); - sal_uInt8* pBuffer = new sal_uInt8[nFirstLength]; - sal_Int32 nSecondLength(0); - sal_Int32 nLength(0); - sal_Int32 i = 0; - sal_Int32 k = 0; - while (i < sBuffer.getLength()) - { - FourByteToThreeByte (pBuffer, nLength, k, sBuffer.copy(i, 4)); - nSecondLength += nLength; - nLength = 0; - i += 4; - k += 3; - } - aBuffer = uno::Sequence<sal_Int8>( reinterpret_cast< sal_Int8* >( pBuffer ), nSecondLength ); - delete[] pBuffer; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/Base64Codec.hxx b/package/source/manifest/Base64Codec.hxx deleted file mode 100644 index 60456ad32..000000000 --- a/package/source/manifest/Base64Codec.hxx +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _BASE64_CODEC_HXX -#define _BASE64_CODEC_HXX - -#include <com/sun/star/uno/Sequence.hxx> - -namespace rtl -{ -class OUString; -class OUStringBuffer; -} - -class Base64Codec -{ -public: - static void encodeBase64(rtl::OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_Int8>& aPass); - static void decodeBase64(com::sun::star::uno::Sequence<sal_Int8>& aPass, const rtl::OUString& sBuffer); -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestDefines.hxx b/package/source/manifest/ManifestDefines.hxx deleted file mode 100644 index b4fa4b72a..000000000 --- a/package/source/manifest/ManifestDefines.hxx +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _MANIFEST_DEFINES_HXX -#define _MANIFEST_DEFINES_HXX - -#include <PackageConstants.hxx> - -#define MANIFEST_NSPREFIX "manifest:" -#define ELEMENT_MANIFEST "manifest:manifest" -#define ATTRIBUTE_XMLNS "xmlns:manifest" -#define MANIFEST_NAMESPACE "http://openoffice.org/2001/manifest" -#define MANIFEST_OASIS_NAMESPACE "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" -#define MANIFEST_DOCTYPE "<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">" -#define ATTRIBUTE_CDATA "CDATA" - -#define ELEMENT_FILE_ENTRY "manifest:file-entry" -#define ATTRIBUTE_FULL_PATH "manifest:full-path" -#define ATTRIBUTE_VERSION "manifest:version" -#define ATTRIBUTE_MEDIA_TYPE "manifest:media-type" -#define ATTRIBUTE_SIZE "manifest:size" - -#define ELEMENT_ENCRYPTION_DATA "manifest:encryption-data" -#define ATTRIBUTE_CHECKSUM_TYPE "manifest:checksum-type" -#define ATTRIBUTE_CHECKSUM "manifest:checksum" - -#define ELEMENT_ALGORITHM "manifest:algorithm" -#define ATTRIBUTE_ALGORITHM_NAME "manifest:algorithm-name" -#define ATTRIBUTE_INITIALISATION_VECTOR "manifest:initialisation-vector" - -#define ELEMENT_START_KEY_GENERATION "manifest:start-key-generation" -#define ATTRIBUTE_START_KEY_GENERATION_NAME "manifest:start-key-generation-name" -#define ATTRIBUTE_KEY_SIZE "manifest:key-size" - -#define ELEMENT_KEY_DERIVATION "manifest:key-derivation" -#define ATTRIBUTE_KEY_DERIVATION_NAME "manifest:key-derivation-name" -#define ATTRIBUTE_SALT "manifest:salt" -#define ATTRIBUTE_ITERATION_COUNT "manifest:iteration-count" - -#define SHA256_URL "http://www.w3.org/2001/04/xmlenc#sha256" -//http://tools.oasis-open.org/issues/browse/OFFICE-3702 -//http://tools.oasis-open.org/issues/browse/OFFICE-3708 -#define SHA256_URL_TYPO "http://www.w3.org/2000/09/xmldsig#sha256" -#define SHA1_NAME "SHA1" -#define SHA1_URL "http://www.w3.org/2000/09/xmldsig#sha1" - -#define SHA1_1K_NAME "SHA1/1K" -#define SHA1_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha1-1k" -#define SHA256_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha256-1k" - -#define BLOWFISH_NAME "Blowfish CFB" -#define BLOWFISH_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#blowfish" -#define AES128_URL "http://www.w3.org/2001/04/xmlenc#aes128-cbc" -#define AES192_URL "http://www.w3.org/2001/04/xmlenc#aes192-cbc" -#define AES256_URL "http://www.w3.org/2001/04/xmlenc#aes256-cbc" - -#define PBKDF2_NAME "PBKDF2" -#define PBKDF2_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#pbkdf2" - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx deleted file mode 100644 index 0a8c1d08a..000000000 --- a/package/source/manifest/ManifestExport.cxx +++ /dev/null @@ -1,394 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> -#include <com/sun/star/xml/sax/XDocumentHandler.hpp> -#include <com/sun/star/xml/sax/XAttributeList.hpp> -#include <com/sun/star/xml/crypto/DigestID.hpp> -#include <com/sun/star/xml/crypto/CipherID.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/uno/RuntimeException.hpp> - -#include <ManifestDefines.hxx> -#include <ManifestExport.hxx> -#include <Base64Codec.hxx> - -#include <rtl/ustrbuf.hxx> -#include <comphelper/documentconstants.hxx> -#include <comphelper/attributelist.hxx> - -using namespace ::com::sun::star; - -using ::rtl::OUString; -using ::rtl::OUStringBuffer; - -ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > xHandler, const uno::Sequence< uno::Sequence < beans::PropertyValue > >& rManList ) -{ - const ::rtl::OUString sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ); - const ::rtl::OUString sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ); - const ::rtl::OUString sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ); - const ::rtl::OUString sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ); - const ::rtl::OUString sStartKeyGenerationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ); - const ::rtl::OUString sKeyDerivationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ); - - const ::rtl::OUString sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ); - const ::rtl::OUString sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ); - const ::rtl::OUString sVersionAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ); - const ::rtl::OUString sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ); - const ::rtl::OUString sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ); - const ::rtl::OUString sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ); - const ::rtl::OUString sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ); - const ::rtl::OUString sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ); - const ::rtl::OUString sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ); - const ::rtl::OUString sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ); - const ::rtl::OUString sStartKeyGenerationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ); - const ::rtl::OUString sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ); - const ::rtl::OUString sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ); - const ::rtl::OUString sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM) ); - - const ::rtl::OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - const ::rtl::OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); - const ::rtl::OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - const ::rtl::OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); - const ::rtl::OUString sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); - const ::rtl::OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); - const ::rtl::OUString sInitialisationVectorProperty( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); - const ::rtl::OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); - const ::rtl::OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); - const ::rtl::OUString sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); - const ::rtl::OUString sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); - const ::rtl::OUString sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); - - const ::rtl::OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); - - const ::rtl::OUString sSHA256_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) ); - const ::rtl::OUString sSHA1_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) ); - - const ::rtl::OUString sSHA1_1k_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) ); - const ::rtl::OUString sSHA256_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) ); - - const ::rtl::OUString sBlowfish_Name ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) ); - const ::rtl::OUString sAES256_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) ); - - const ::rtl::OUString sPBKDF2_Name ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) ); - - ::comphelper::AttributeList * pRootAttrList = new ::comphelper::AttributeList; - const uno::Sequence < beans::PropertyValue > *pSequence = rManList.getConstArray(); - const sal_uInt32 nManLength = rManList.getLength(); - - // find the mediatype of the document if any - ::rtl::OUString aDocMediaType; - ::rtl::OUString aDocVersion; - for (sal_uInt32 nInd = 0; nInd < nManLength ; nInd++ ) - { - ::rtl::OUString aMediaType; - ::rtl::OUString aPath; - ::rtl::OUString aVersion; - - const beans::PropertyValue *pValue = pSequence[nInd].getConstArray(); - for (sal_uInt32 j = 0, nNum = pSequence[nInd].getLength(); j < nNum; j++, pValue++) - { - if (pValue->Name.equals (sMediaTypeProperty) ) - { - pValue->Value >>= aMediaType; - } - else if (pValue->Name.equals (sFullPathProperty) ) - { - pValue->Value >>= aPath; - } - else if (pValue->Name.equals (sVersionProperty) ) - { - pValue->Value >>= aVersion; - } - - if ( aPath.getLength() && aMediaType.getLength() && aVersion.getLength() ) - break; - } - - if ( aPath.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ) ) - { - aDocMediaType = aMediaType; - aDocVersion = aVersion; - break; - } - } - - sal_Bool bProvideDTD = sal_False; - sal_Bool bAcceptNonemptyVersion = sal_False; - sal_Bool bStoreStartKeyGeneration = sal_False; - if ( aDocMediaType.getLength() ) - { - if ( aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) ) ) - - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) ) ) ) - - { - // oasis format - pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), - sCdataAttribute, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_OASIS_NAMESPACE ) ) ); - bAcceptNonemptyVersion = sal_True; - if ( aDocVersion.compareTo( ODFVER_012_TEXT ) >= 0 ) - { - // this is ODF12 generation, let encrypted streams contain start-key-generation entry - bStoreStartKeyGeneration = sal_True; - pRootAttrList->AddAttribute ( sVersionAttribute, sCdataAttribute, aDocVersion ); - } - } - else - { - // even if it is no SO6 format the namespace must be specified - // thus SO6 format is used as default one - pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), - sCdataAttribute, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_NAMESPACE ) ) ); - - bProvideDTD = sal_True; - } - } - - uno::Reference < xml::sax::XAttributeList > xRootAttrList (pRootAttrList); - - xHandler->startDocument(); - uno::Reference < xml::sax::XExtendedDocumentHandler > xExtHandler ( xHandler, uno::UNO_QUERY ); - if ( xExtHandler.is() && bProvideDTD ) - { - ::rtl::OUString aDocType ( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_DOCTYPE ) ); - xExtHandler->unknown ( aDocType ); - xHandler->ignorableWhitespace ( sWhiteSpace ); - } - xHandler->startElement( sManifestElement, xRootAttrList ); - - for (sal_uInt32 i = 0 ; i < nManLength ; i++) - { - ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList; - const beans::PropertyValue *pValue = pSequence[i].getConstArray(); - ::rtl::OUString aString; - const uno::Any *pVector = NULL, *pSalt = NULL, *pIterationCount = NULL, *pDigest = NULL, *pDigestAlg = NULL, *pEncryptAlg = NULL, *pStartKeyAlg = NULL, *pDerivedKeySize = NULL; - for (sal_uInt32 j = 0, nNum = pSequence[i].getLength(); j < nNum; j++, pValue++) - { - if (pValue->Name.equals (sMediaTypeProperty) ) - { - pValue->Value >>= aString; - pAttrList->AddAttribute ( sMediaTypeAttribute, sCdataAttribute, aString ); - } - else if (pValue->Name.equals (sVersionProperty) ) - { - pValue->Value >>= aString; - // the version is stored only if it is not empty - if ( bAcceptNonemptyVersion && aString.getLength() ) - pAttrList->AddAttribute ( sVersionAttribute, sCdataAttribute, aString ); - } - else if (pValue->Name.equals (sFullPathProperty) ) - { - pValue->Value >>= aString; - pAttrList->AddAttribute ( sFullPathAttribute, sCdataAttribute, aString ); - } - else if (pValue->Name.equals (sSizeProperty) ) - { - sal_Int32 nSize = 0; - pValue->Value >>= nSize; - ::rtl::OUStringBuffer aBuffer; - aBuffer.append ( nSize ); - pAttrList->AddAttribute ( sSizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - } - else if (pValue->Name.equals (sInitialisationVectorProperty) ) - pVector = &pValue->Value; - else if (pValue->Name.equals (sSaltProperty) ) - pSalt = &pValue->Value; - else if (pValue->Name.equals (sIterationCountProperty) ) - pIterationCount = &pValue->Value; - else if (pValue->Name.equals ( sDigestProperty ) ) - pDigest = &pValue->Value; - else if (pValue->Name.equals ( sDigestAlgProperty ) ) - pDigestAlg = &pValue->Value; - else if (pValue->Name.equals ( sEncryptionAlgProperty ) ) - pEncryptAlg = &pValue->Value; - else if (pValue->Name.equals ( sStartKeyAlgProperty ) ) - pStartKeyAlg = &pValue->Value; - else if (pValue->Name.equals ( sDerivedKeySizeProperty ) ) - pDerivedKeySize = &pValue->Value; - } - - xHandler->ignorableWhitespace ( sWhiteSpace ); - uno::Reference < xml::sax::XAttributeList > xAttrList ( pAttrList ); - xHandler->startElement( sFileEntryElement , xAttrList); - if ( pVector && pSalt && pIterationCount && pDigest && pDigestAlg && pEncryptAlg && pStartKeyAlg && pDerivedKeySize ) - { - // ==== Encryption Data - ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList; - uno::Reference < xml::sax::XAttributeList > xNewAttrList (pNewAttrList); - ::rtl::OUStringBuffer aBuffer; - uno::Sequence < sal_Int8 > aSequence; - - xHandler->ignorableWhitespace ( sWhiteSpace ); - - // ==== Digest - ::rtl::OUString sChecksumType; - sal_Int32 nDigestAlgID = 0; - *pDigestAlg >>= nDigestAlgID; - if ( nDigestAlgID == xml::crypto::DigestID::SHA256_1K ) - sChecksumType = sSHA256_1k_URL; - else if ( nDigestAlgID == xml::crypto::DigestID::SHA1_1K ) - sChecksumType = sSHA1_1k_Name; - else - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected digest algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); - - pNewAttrList->AddAttribute ( sChecksumTypeAttribute, sCdataAttribute, sChecksumType ); - *pDigest >>= aSequence; - Base64Codec::encodeBase64( aBuffer, aSequence ); - pNewAttrList->AddAttribute ( sChecksumAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - - xHandler->startElement( sEncryptionDataElement , xNewAttrList); - - // ==== Algorithm - pNewAttrList = new ::comphelper::AttributeList; - xNewAttrList = pNewAttrList; - - sal_Int32 nEncAlgID = 0; - sal_Int32 nDerivedKeySize = 0; - *pEncryptAlg >>= nEncAlgID; - *pDerivedKeySize >>= nDerivedKeySize; - - ::rtl::OUString sEncAlgName; - if ( nEncAlgID == xml::crypto::CipherID::AES_CBC_W3C_PADDING ) - { - OSL_ENSURE( nDerivedKeySize, "Unexpected key size is provided!" ); - if ( nDerivedKeySize != 32 ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected key size is provided!" ) ), uno::Reference< uno::XInterface >() ); - - sEncAlgName = sAES256_URL; - } - else if ( nEncAlgID == xml::crypto::CipherID::BLOWFISH_CFB_8 ) - { - sEncAlgName = sBlowfish_Name; - } - else - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpecte encryption algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); - - pNewAttrList->AddAttribute ( sAlgorithmNameAttribute, sCdataAttribute, sEncAlgName ); - - *pVector >>= aSequence; - Base64Codec::encodeBase64 ( aBuffer, aSequence ); - pNewAttrList->AddAttribute ( sInitialisationVectorAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - - xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->startElement( sAlgorithmElement , xNewAttrList); - xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->endElement( sAlgorithmElement ); - - // ==== Key Derivation - pNewAttrList = new ::comphelper::AttributeList; - xNewAttrList = pNewAttrList; - - pNewAttrList->AddAttribute ( sKeyDerivationNameAttribute, sCdataAttribute, sPBKDF2_Name ); - - if ( bStoreStartKeyGeneration ) - { - aBuffer.append( nDerivedKeySize ); - pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - } - - sal_Int32 nCount = 0; - *pIterationCount >>= nCount; - aBuffer.append (nCount); - pNewAttrList->AddAttribute ( sIterationCountAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - - *pSalt >>= aSequence; - Base64Codec::encodeBase64 ( aBuffer, aSequence ); - pNewAttrList->AddAttribute ( sSaltAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - - xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->startElement( sKeyDerivationElement , xNewAttrList); - xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->endElement( sKeyDerivationElement ); - - // we have to store start-key-generation element as the last one to workaround the parsing problem - // in OOo3.1 and older versions - if ( bStoreStartKeyGeneration ) - { - // ==== Start Key Generation - pNewAttrList = new ::comphelper::AttributeList; - xNewAttrList = pNewAttrList; - - ::rtl::OUString sStartKeyAlg; - ::rtl::OUString sStartKeySize; - sal_Int32 nStartKeyAlgID = 0; - *pStartKeyAlg >>= nStartKeyAlgID; - if ( nStartKeyAlgID == xml::crypto::DigestID::SHA256 ) - { - sStartKeyAlg = sSHA256_URL; - aBuffer.append( (sal_Int32)32 ); - sStartKeySize = aBuffer.makeStringAndClear(); - } - else if ( nStartKeyAlgID == xml::crypto::DigestID::SHA1 ) - { - sStartKeyAlg = sSHA1_Name; - aBuffer.append( (sal_Int32)20 ); - sStartKeySize = aBuffer.makeStringAndClear(); - } - else - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); - - pNewAttrList->AddAttribute ( sStartKeyGenerationNameAttribute, sCdataAttribute, sStartKeyAlg ); - pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sStartKeySize ); - - xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->startElement( sStartKeyGenerationElement , xNewAttrList); - xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->endElement( sStartKeyGenerationElement ); - } - - xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->endElement( sEncryptionDataElement ); - } - xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->endElement( sFileEntryElement ); - } - xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->endElement( sManifestElement ); - xHandler->endDocument(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestExport.hxx b/package/source/manifest/ManifestExport.hxx deleted file mode 100644 index 860c8e60d..000000000 --- a/package/source/manifest/ManifestExport.hxx +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _MANIFEST_EXPORT_HXX -#define _MANIFEST_EXPORT_HXX - -#include <com/sun/star/uno/Sequence.h> -#include <com/sun/star/uno/Reference.h> -#include <rtl/ustring.hxx> - -namespace com { namespace sun { namespace star { - namespace beans { struct PropertyValue;} - namespace xml { namespace sax { class XDocumentHandler; } } -} } } -class ManifestExport -{ -public: - ManifestExport(com::sun::star::uno::Reference < com::sun::star::xml::sax::XDocumentHandler > xHandler, const com::sun::star::uno::Sequence < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList ); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx deleted file mode 100644 index cf5a77785..000000000 --- a/package/source/manifest/ManifestImport.cxx +++ /dev/null @@ -1,435 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER( update_precomp.py ): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ManifestImport.hxx> -#include <ManifestDefines.hxx> -#include <Base64Codec.hxx> -#include <com/sun/star/xml/sax/XAttributeList.hpp> -#include <com/sun/star/xml/crypto/DigestID.hpp> -#include <com/sun/star/xml/crypto/CipherID.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> - -using namespace com::sun::star::uno; -using namespace com::sun::star::beans; -using namespace com::sun::star; -using namespace std; - -using ::rtl::OUString; - -// --------------------------------------------------- -ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector ) -: nNumProperty ( 0 ) -, bIgnoreEncryptData ( sal_False ) -, nDerivedKeySize( 0 ) -, rManVector ( rNewManVector ) - -, sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ) -, sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ) -, sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ) -, sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ) -, sStartKeyAlgElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ) -, sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ) - -, sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ) -, sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ) -, sVersionAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ) -, sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ) -, sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ) -, sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ) -, sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ) -, sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ) -, sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ) -, sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ) -, sStartKeyAlgNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ) -, sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ) -, sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM ) ) -, sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ) - -, sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ) -, sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ) -, sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ) -, sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ) -, sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ) -, sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ) -, sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ) -, sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ) -, sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ) -, sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ) -, sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ) -, sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ) - -, sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ) - -, sSHA256_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) ) -, sSHA256_URL_TYPO ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL_TYPO ) ) -, sSHA1_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) ) -, sSHA1_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_URL ) ) - -, sSHA256_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) ) -, sSHA1_1k_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) ) -, sSHA1_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_URL ) ) - -, sBlowfish_Name ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) ) -, sBlowfish_URL ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_URL ) ) -, sAES128_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES128_URL ) ) -, sAES192_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES192_URL ) ) -, sAES256_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) ) - -, sPBKDF2_Name ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) ) -, sPBKDF2_URL ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_URL ) ) -{ - aStack.reserve( 10 ); -} - -// --------------------------------------------------- -ManifestImport::~ManifestImport ( void ) -{ -} - -// --------------------------------------------------- -void SAL_CALL ManifestImport::startDocument( ) - throw( xml::sax::SAXException, uno::RuntimeException ) -{ -} - -// --------------------------------------------------- -void SAL_CALL ManifestImport::endDocument( ) - throw( xml::sax::SAXException, uno::RuntimeException ) -{ -} - -// --------------------------------------------------- -void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) - throw( xml::sax::SAXException, uno::RuntimeException ) -{ - StringHashMap aConvertedAttribs; - ::rtl::OUString aConvertedName = PushNameAndNamespaces( aName, xAttribs, aConvertedAttribs ); - - if ( aConvertedName == sFileEntryElement ) - { - aSequence.realloc ( PKG_SIZE_ENCR_MNFST ); - - // Put full-path property first for MBA - aSequence[nNumProperty].Name = sFullPathProperty; - aSequence[nNumProperty++].Value <<= aConvertedAttribs[sFullPathAttribute]; - aSequence[nNumProperty].Name = sMediaTypeProperty; - aSequence[nNumProperty++].Value <<= aConvertedAttribs[sMediaTypeAttribute]; - - OUString sVersion = aConvertedAttribs[sVersionAttribute]; - if ( sVersion.getLength() ) - { - aSequence[nNumProperty].Name = sVersionProperty; - aSequence[nNumProperty++].Value <<= sVersion; - } - - OUString sSize = aConvertedAttribs[sSizeAttribute]; - if ( sSize.getLength() ) - { - sal_Int32 nSize; - nSize = sSize.toInt32(); - aSequence[nNumProperty].Name = sSizeProperty; - aSequence[nNumProperty++].Value <<= nSize; - } - } - else if ( aStack.size() > 1 ) - { - ManifestStack::reverse_iterator aIter = aStack.rbegin(); - ++aIter; - - if ( aIter->m_aConvertedName.equals( sFileEntryElement ) ) - { - if ( aConvertedName.equals( sEncryptionDataElement ) ) - { - // If this element exists, then this stream is encrypted and we need - // to import the initialisation vector, salt and iteration count used - nDerivedKeySize = 0; - OUString aString = aConvertedAttribs[sChecksumTypeAttribute]; - if ( !bIgnoreEncryptData ) - { - if ( aString.equals( sSHA1_1k_Name ) || aString.equals( sSHA1_1k_URL ) ) - { - aSequence[nNumProperty].Name = sDigestAlgProperty; - aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1_1K; - } - else if ( aString.equals( sSHA256_1k_URL ) ) - { - aSequence[nNumProperty].Name = sDigestAlgProperty; - aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256_1K; - } - else - bIgnoreEncryptData = sal_True; - - if ( !bIgnoreEncryptData ) - { - aString = aConvertedAttribs[sChecksumAttribute]; - uno::Sequence < sal_Int8 > aDecodeBuffer; - Base64Codec::decodeBase64( aDecodeBuffer, aString ); - aSequence[nNumProperty].Name = sDigestProperty; - aSequence[nNumProperty++].Value <<= aDecodeBuffer; - } - } - } - } - else if ( aIter->m_aConvertedName.equals( sEncryptionDataElement ) ) - { - if ( aConvertedName == sAlgorithmElement ) - { - if ( !bIgnoreEncryptData ) - { - OUString aString = aConvertedAttribs[sAlgorithmNameAttribute]; - if ( aString.equals( sBlowfish_Name ) || aString.equals( sBlowfish_URL ) ) - { - aSequence[nNumProperty].Name = sEncryptionAlgProperty; - aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8; - } - else if ( aString.equals( sAES256_URL ) ) - { - aSequence[nNumProperty].Name = sEncryptionAlgProperty; - aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; - OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" ); - nDerivedKeySize = 32; - } - else if ( aString.equals( sAES192_URL ) ) - { - aSequence[nNumProperty].Name = sEncryptionAlgProperty; - aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; - OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" ); - nDerivedKeySize = 24; - } - else if ( aString.equals( sAES128_URL ) ) - { - aSequence[nNumProperty].Name = sEncryptionAlgProperty; - aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; - OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" ); - nDerivedKeySize = 16; - } - else - bIgnoreEncryptData = sal_True; - - if ( !bIgnoreEncryptData ) - { - aString = aConvertedAttribs[sInitialisationVectorAttribute]; - uno::Sequence < sal_Int8 > aDecodeBuffer; - Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); - aSequence[nNumProperty].Name = sInitialisationVectorProperty; - aSequence[nNumProperty++].Value <<= aDecodeBuffer; - } - } - } - else if ( aConvertedName == sKeyDerivationElement ) - { - if ( !bIgnoreEncryptData ) - { - OUString aString = aConvertedAttribs[sKeyDerivationNameAttribute]; - if ( aString.equals( sPBKDF2_Name ) || aString.equals( sPBKDF2_URL ) ) - { - aString = aConvertedAttribs[sSaltAttribute]; - uno::Sequence < sal_Int8 > aDecodeBuffer; - Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); - aSequence[nNumProperty].Name = sSaltProperty; - aSequence[nNumProperty++].Value <<= aDecodeBuffer; - - aString = aConvertedAttribs[sIterationCountAttribute]; - aSequence[nNumProperty].Name = sIterationCountProperty; - aSequence[nNumProperty++].Value <<= aString.toInt32(); - - aString = aConvertedAttribs[sKeySizeAttribute]; - if ( aString.getLength() ) - { - sal_Int32 nKey = aString.toInt32(); - OSL_ENSURE( !nDerivedKeySize || nKey == nDerivedKeySize , "Provided derived key length differs from the expected one!" ); - nDerivedKeySize = nKey; - } - else if ( !nDerivedKeySize ) - nDerivedKeySize = 16; - else if ( nDerivedKeySize != 16 ) - OSL_ENSURE( sal_False, "Default derived key length differs from the expected one!" ); - - aSequence[nNumProperty].Name = sDerivedKeySizeProperty; - aSequence[nNumProperty++].Value <<= nDerivedKeySize; - } - else - bIgnoreEncryptData = sal_True; - } - } - else if ( aConvertedName == sStartKeyAlgElement ) - { - OUString aString = aConvertedAttribs[sStartKeyAlgNameAttribute]; - if (aString.equals(sSHA256_URL) || aString.equals(sSHA256_URL_TYPO)) - { - aSequence[nNumProperty].Name = sStartKeyAlgProperty; - aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256; - } - else if ( aString.equals( sSHA1_Name ) || aString.equals( sSHA1_URL ) ) - { - aSequence[nNumProperty].Name = sStartKeyAlgProperty; - aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1; - } - else - bIgnoreEncryptData = sal_True; - } - } - } -} - -// --------------------------------------------------- -void SAL_CALL ManifestImport::endElement( const OUString& aName ) - throw( xml::sax::SAXException, uno::RuntimeException ) -{ - ::rtl::OUString aConvertedName = ConvertName( aName ); - if ( !aStack.empty() && aStack.rbegin()->m_aConvertedName.equals( aConvertedName ) ) - { - if ( aConvertedName.equals( sFileEntryElement ) ) - { - aSequence.realloc ( nNumProperty ); - bIgnoreEncryptData = sal_False; - rManVector.push_back ( aSequence ); - nNumProperty = 0; - } - - aStack.pop_back(); - } -} - -// --------------------------------------------------- -void SAL_CALL ManifestImport::characters( const OUString& /*aChars*/ ) - throw( xml::sax::SAXException, uno::RuntimeException ) -{ -} - -// --------------------------------------------------- -void SAL_CALL ManifestImport::ignorableWhitespace( const OUString& /*aWhitespaces*/ ) - throw( xml::sax::SAXException, uno::RuntimeException ) -{ -} - -// --------------------------------------------------- -void SAL_CALL ManifestImport::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ ) - throw( xml::sax::SAXException, uno::RuntimeException ) -{ -} - -// --------------------------------------------------- -void SAL_CALL ManifestImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ ) - throw( xml::sax::SAXException, uno::RuntimeException ) -{ -} - -// --------------------------------------------------- -::rtl::OUString ManifestImport::PushNameAndNamespaces( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs, StringHashMap& o_aConvertedAttribs ) -{ - StringHashMap aNamespaces; - ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > aAttribsStrs; - - if ( xAttribs.is() ) - { - sal_Int16 nAttrCount = xAttribs.is() ? xAttribs->getLength() : 0; - aAttribsStrs.reserve( nAttrCount ); - - for( sal_Int16 nInd = 0; nInd < nAttrCount; nInd++ ) - { - ::rtl::OUString aAttrName = xAttribs->getNameByIndex( nInd ); - ::rtl::OUString aAttrValue = xAttribs->getValueByIndex( nInd ); - if ( aAttrName.getLength() >= 5 - && aAttrName.compareToAscii( "xmlns", 5 ) == 0 - && ( aAttrName.getLength() == 5 || aAttrName.getStr()[5] == ( sal_Unicode )':' ) ) - { - // this is a namespace declaration - ::rtl::OUString aNsName( ( aAttrName.getLength() == 5 ) ? ::rtl::OUString() : aAttrName.copy( 6 ) ); - aNamespaces[aNsName] = aAttrValue; - } - else - { - // this is no namespace declaration - aAttribsStrs.push_back( pair< ::rtl::OUString, ::rtl::OUString >( aAttrName, aAttrValue ) ); - } - } - } - - ::rtl::OUString aConvertedName = ConvertNameWithNamespace( aName, aNamespaces ); - if ( !aConvertedName.getLength() ) - aConvertedName = ConvertName( aName ); - - aStack.push_back( ManifestScopeEntry( aConvertedName, aNamespaces ) ); - - for ( sal_uInt16 nInd = 0; nInd < aAttribsStrs.size(); nInd++ ) - { - // convert the attribute names on filling - o_aConvertedAttribs[ConvertName( aAttribsStrs[nInd].first )] = aAttribsStrs[nInd].second; - } - - return aConvertedName; -} - -// --------------------------------------------------- -::rtl::OUString ManifestImport::ConvertNameWithNamespace( const ::rtl::OUString& aName, const StringHashMap& aNamespaces ) -{ - ::rtl::OUString aNsAlias; - ::rtl::OUString aPureName = aName; - - sal_Int32 nInd = aName.indexOf( ( sal_Unicode )':' ); - if ( nInd != -1 && nInd < aName.getLength() ) - { - aNsAlias = aName.copy( 0, nInd ); - aPureName = aName.copy( nInd + 1 ); - } - - ::rtl::OUString aResult; - - StringHashMap::const_iterator aIter = aNamespaces.find( aNsAlias ); - if ( aIter != aNamespaces.end() - && ( aIter->second.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_NAMESPACE ) ) ) - || aIter->second.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_OASIS_NAMESPACE ) ) ) ) ) - { - // no check for manifest.xml consistency currently since the old versions have supported inconsistent documents as well - aResult = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_NSPREFIX ) ); - aResult += aPureName; - } - - return aResult; -} - -// --------------------------------------------------- -::rtl::OUString ManifestImport::ConvertName( const ::rtl::OUString& aName ) -{ - ::rtl::OUString aConvertedName; - for ( ManifestStack::reverse_iterator aIter = aStack.rbegin(); !aConvertedName.getLength() && aIter != aStack.rend(); ++aIter ) - { - if ( !aIter->m_aNamespaces.empty() ) - aConvertedName = ConvertNameWithNamespace( aName, aIter->m_aNamespaces ); - } - - if ( !aConvertedName.getLength() ) - aConvertedName = aName; - - return aConvertedName; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestImport.hxx b/package/source/manifest/ManifestImport.hxx deleted file mode 100644 index 4b927971c..000000000 --- a/package/source/manifest/ManifestImport.hxx +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _MANIFEST_IMPORT_HXX -#define _MANIFEST_IMPORT_HXX - -#include <cppuhelper/implbase1.hxx> // helper for implementations -#include <com/sun/star/xml/sax/XDocumentHandler.hpp> -#include <vector> - -#include <HashMaps.hxx> - -namespace com { namespace sun { namespace star { - namespace xml { namespace sax { class XAttributeList; } } - namespace beans { struct PropertyValue; } -} } } - -typedef ::boost::unordered_map< ::rtl::OUString, ::rtl::OUString, ::rtl::OUStringHash, eqFunc > StringHashMap; - -struct ManifestScopeEntry -{ - ::rtl::OUString m_aConvertedName; - StringHashMap m_aNamespaces; - - ManifestScopeEntry( const ::rtl::OUString& aConvertedName, const StringHashMap& aNamespaces ) - : m_aConvertedName( aConvertedName ) - , m_aNamespaces( aNamespaces ) - {} - - ~ManifestScopeEntry() - {} -}; - -typedef ::std::vector< ManifestScopeEntry > ManifestStack; - -class ManifestImport : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler > -{ -protected: - com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aSequence; - sal_Int16 nNumProperty; - ManifestStack aStack; - sal_Bool bIgnoreEncryptData; - sal_Int32 nDerivedKeySize; - ::std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rManVector; - - const ::rtl::OUString sFileEntryElement; - const ::rtl::OUString sManifestElement; - const ::rtl::OUString sEncryptionDataElement; - const ::rtl::OUString sAlgorithmElement; - const ::rtl::OUString sStartKeyAlgElement; - const ::rtl::OUString sKeyDerivationElement; - - const ::rtl::OUString sCdataAttribute; - const ::rtl::OUString sMediaTypeAttribute; - const ::rtl::OUString sVersionAttribute; - const ::rtl::OUString sFullPathAttribute; - const ::rtl::OUString sSizeAttribute; - const ::rtl::OUString sSaltAttribute; - const ::rtl::OUString sInitialisationVectorAttribute; - const ::rtl::OUString sIterationCountAttribute; - const ::rtl::OUString sKeySizeAttribute; - const ::rtl::OUString sAlgorithmNameAttribute; - const ::rtl::OUString sStartKeyAlgNameAttribute; - const ::rtl::OUString sKeyDerivationNameAttribute; - const ::rtl::OUString sChecksumAttribute; - const ::rtl::OUString sChecksumTypeAttribute; - - const ::rtl::OUString sFullPathProperty; - const ::rtl::OUString sMediaTypeProperty; - const ::rtl::OUString sVersionProperty; - const ::rtl::OUString sIterationCountProperty; - const ::rtl::OUString sDerivedKeySizeProperty; - const ::rtl::OUString sSaltProperty; - const ::rtl::OUString sInitialisationVectorProperty; - const ::rtl::OUString sSizeProperty; - const ::rtl::OUString sDigestProperty; - const ::rtl::OUString sEncryptionAlgProperty; - const ::rtl::OUString sStartKeyAlgProperty; - const ::rtl::OUString sDigestAlgProperty; - - const ::rtl::OUString sWhiteSpace; - - const ::rtl::OUString sSHA256_URL; - const ::rtl::OUString sSHA256_URL_TYPO; - const ::rtl::OUString sSHA1_Name; - const ::rtl::OUString sSHA1_URL; - - const ::rtl::OUString sSHA256_1k_URL; - const ::rtl::OUString sSHA1_1k_Name; - const ::rtl::OUString sSHA1_1k_URL; - - const ::rtl::OUString sBlowfish_Name; - const ::rtl::OUString sBlowfish_URL; - const ::rtl::OUString sAES128_URL; - const ::rtl::OUString sAES192_URL; - const ::rtl::OUString sAES256_URL; - - const ::rtl::OUString sPBKDF2_Name; - const ::rtl::OUString sPBKDF2_URL; - - - ::rtl::OUString PushNameAndNamespaces( const ::rtl::OUString& aName, - const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs, - StringHashMap& o_aConvertedAttribs ); - ::rtl::OUString ConvertNameWithNamespace( const ::rtl::OUString& aName, const StringHashMap& aNamespaces ); - ::rtl::OUString ConvertName( const ::rtl::OUString& aName ); - -public: - ManifestImport( std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rNewVector ); - ~ManifestImport( void ); - virtual void SAL_CALL startDocument( ) - throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL endDocument( ) - throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) - throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) - throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) - throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) - throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) - throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) - throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestReader.cxx b/package/source/manifest/ManifestReader.cxx deleted file mode 100644 index 34fe9e262..000000000 --- a/package/source/manifest/ManifestReader.cxx +++ /dev/null @@ -1,143 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ManifestReader.hxx> -#include <ManifestImport.hxx> -#include <cppuhelper/factory.hxx> -#include <com/sun/star/xml/sax/XDocumentHandler.hpp> -#include <com/sun/star/xml/sax/SAXParseException.hpp> -#include <com/sun/star/xml/sax/XParser.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <vector> - -using namespace ::std; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::io; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::registry; -using namespace ::com::sun::star::packages; -using namespace ::com::sun::star::xml::sax; -using namespace ::com::sun::star::packages::manifest; -using ::rtl::OUString; - -ManifestReader::ManifestReader( const Reference < XMultiServiceFactory > & xNewFactory ) -: xFactory ( xNewFactory ) -{ -} -ManifestReader::~ManifestReader() -{ -} -Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream ) - throw (::com::sun::star::uno::RuntimeException) -{ - Sequence < Sequence < PropertyValue > > aManifestSequence; - Reference < XParser > xParser (xFactory->createInstance ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Parser" ) ) ), UNO_QUERY ); - if (xParser.is()) - { - try - { - vector < Sequence < PropertyValue > > aManVector; - Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector ); - InputSource aParserInput; - aParserInput.aInputStream = rStream; - aParserInput.sSystemId = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) ); - xParser->setDocumentHandler ( xFilter ); - xParser->parseStream( aParserInput ); - aManifestSequence.realloc ( aManVector.size() ); - Sequence < PropertyValue > * pSequence = aManifestSequence.getArray(); - ::std::vector < Sequence < PropertyValue > >::const_iterator aIter = aManVector.begin(); - ::std::vector < Sequence < PropertyValue > >::const_iterator aEnd = aManVector.end(); - while( aIter != aEnd ) - *pSequence++ = (*aIter++); - } - catch (SAXParseException& ) - { - } - catch (SAXException& ) - { - } - catch (IOException& ) - { - } - } - xParser->setDocumentHandler ( Reference < XDocumentHandler > () ); - return aManifestSequence; -} -// Component functions - -Reference < XInterface > SAL_CALL ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory ) -{ - return *new ManifestReader( rServiceFactory ); -} -OUString ManifestReader::static_getImplementationName() -{ - return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestReader" ) ); -} - -sal_Bool SAL_CALL ManifestReader::static_supportsService(OUString const & rServiceName) -{ - return rServiceName == getSupportedServiceNames()[0]; -} - -Sequence < OUString > ManifestReader::static_getSupportedServiceNames() -{ - Sequence < OUString > aNames(1); - aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) ); - return aNames; -} - -OUString ManifestReader::getImplementationName() - throw (RuntimeException) -{ - return static_getImplementationName(); -} - -sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName) - throw (RuntimeException) -{ - return static_supportsService ( rServiceName ); -} - -Sequence < OUString > ManifestReader::getSupportedServiceNames() - throw (RuntimeException) -{ - return static_getSupportedServiceNames(); -} -Reference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory ) -{ - return cppu::createSingleFactory (rServiceFactory, - static_getImplementationName(), - ManifestReader_createInstance, - static_getSupportedServiceNames()); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestReader.hxx b/package/source/manifest/ManifestReader.hxx deleted file mode 100644 index b200f6efb..000000000 --- a/package/source/manifest/ManifestReader.hxx +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _MANIFEST_READER_HXX -#define _MANIFEST_READER_HXX - -#include <cppuhelper/implbase2.hxx> -#include <com/sun/star/packages/manifest/XManifestReader.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> - -namespace com { namespace sun { namespace star { - namespace lang { class XMultiServiceFactory; class XSingleServiceFactory; } -} } } - -class ManifestReader: public ::cppu::WeakImplHelper2 -< - ::com::sun::star::packages::manifest::XManifestReader, - ::com::sun::star::lang::XServiceInfo -> -{ -protected: - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory; -public: - ManifestReader( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xNewFactory ); - virtual ~ManifestReader(); - - // XManifestReader - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > SAL_CALL readManifestSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rStream ) - throw (::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) - throw (::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) - throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) - throw (::com::sun::star::uno::RuntimeException); - - // Component constructor - static ::rtl::OUString static_getImplementationName(); - static ::com::sun::star::uno::Sequence < ::rtl::OUString > static_getSupportedServiceNames(); - sal_Bool SAL_CALL static_supportsService(rtl::OUString const & rServiceName); - static ::com::sun::star::uno::Reference < com::sun::star::lang::XSingleServiceFactory > createServiceFactory( com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > const & rServiceFactory ); -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestWriter.cxx b/package/source/manifest/ManifestWriter.cxx deleted file mode 100644 index 6d7c84801..000000000 --- a/package/source/manifest/ManifestWriter.cxx +++ /dev/null @@ -1,128 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ManifestWriter.hxx> -#include <ManifestExport.hxx> -#include <cppuhelper/factory.hxx> -#include <com/sun/star/io/XActiveDataSource.hpp> -#include <com/sun/star/xml/sax/XDocumentHandler.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/xml/sax/SAXException.hpp> - -#include <osl/diagnose.hxx> - -using namespace ::rtl; -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::io; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::registry; -using namespace ::com::sun::star::packages; -using namespace ::com::sun::star::xml::sax; -using namespace ::com::sun::star::packages::manifest; - -ManifestWriter::ManifestWriter( const Reference < XMultiServiceFactory > & xNewFactory ) -: xFactory ( xNewFactory ) -{ -} -ManifestWriter::~ManifestWriter() -{ -} - -// XManifestWriter methods -void SAL_CALL ManifestWriter::writeManifestSequence( const Reference< XOutputStream >& rStream, const Sequence< Sequence< PropertyValue > >& rSequence ) - throw (RuntimeException) -{ - OUString sSaxWriter ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Writer" ) ); - Reference < XActiveDataSource > xSource ( xFactory->createInstance ( sSaxWriter ), UNO_QUERY ); - if (xSource.is()) - { - xSource->setOutputStream ( rStream ); - Reference < XDocumentHandler > xHandler ( xSource, UNO_QUERY ); - if (xHandler.is()) - try { - ManifestExport aExporter ( xHandler, rSequence); - } - catch( SAXException& ) - { - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } -} - -// Component methods -Reference < XInterface > SAL_CALL ManifestWriter_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory ) -{ - return *new ManifestWriter( rServiceFactory ); -} - -OUString ManifestWriter::static_getImplementationName() -{ - return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestWriter" ) ); -} - -sal_Bool SAL_CALL ManifestWriter::static_supportsService(OUString const & rServiceName) -{ - return rServiceName == getSupportedServiceNames()[0]; -} -Sequence < OUString > ManifestWriter::static_getSupportedServiceNames() -{ - Sequence < OUString > aNames(1); - aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestWriter" ) ); - return aNames; -} - -OUString ManifestWriter::getImplementationName() - throw (RuntimeException) -{ - return static_getImplementationName(); -} - -sal_Bool SAL_CALL ManifestWriter::supportsService(OUString const & rServiceName) - throw (RuntimeException) -{ - return static_supportsService ( rServiceName ); -} -Sequence < OUString > ManifestWriter::getSupportedServiceNames() - throw (RuntimeException) -{ - return static_getSupportedServiceNames(); -} -Reference < XSingleServiceFactory > ManifestWriter::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory ) -{ - return cppu::createSingleFactory (rServiceFactory, - static_getImplementationName(), - ManifestWriter_createInstance, - static_getSupportedServiceNames()); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestWriter.hxx b/package/source/manifest/ManifestWriter.hxx deleted file mode 100644 index 34c4e45d3..000000000 --- a/package/source/manifest/ManifestWriter.hxx +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _MANIFEST_WRITER_HXX -#define _MANIFEST_WRITER_HXX - -#include <cppuhelper/implbase2.hxx> -#include <com/sun/star/packages/manifest/XManifestWriter.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> - -namespace com { namespace sun { namespace star { - namespace lang { class XMultiServiceFactory; class XSingleServiceFactory; } -} } } - -class ManifestWriter: public ::cppu::WeakImplHelper2 -< - ::com::sun::star::packages::manifest::XManifestWriter, - ::com::sun::star::lang::XServiceInfo -> -{ -protected: - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory; -public: - ManifestWriter( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xNewFactory ); - virtual ~ManifestWriter(); - - // XManifestWriter - virtual void SAL_CALL writeManifestSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rStream, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& rSequence ) - throw (::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) - throw (::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) - throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) - throw (::com::sun::star::uno::RuntimeException); - - // Component constructor - static ::rtl::OUString static_getImplementationName(); - static ::com::sun::star::uno::Sequence < ::rtl::OUString > static_getSupportedServiceNames(); - static ::com::sun::star::uno::Reference < com::sun::star::lang::XSingleServiceFactory > createServiceFactory( com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > const & rServiceFactory ); - sal_Bool SAL_CALL static_supportsService(rtl::OUString const & rServiceName); -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/UnoRegister.cxx b/package/source/manifest/UnoRegister.cxx deleted file mode 100644 index c5734977d..000000000 --- a/package/source/manifest/UnoRegister.cxx +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ManifestReader.hxx> -#include <ManifestWriter.hxx> -#include <cppuhelper/factory.hxx> -#include <com/sun/star/registry/XRegistryKey.hpp> -#include <osl/diagnose.h> -#include <ZipPackage.hxx> - -#include <zipfileaccess.hxx> - -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::registry; -using namespace ::com::sun::star::packages; -using namespace ::com::sun::star::packages::manifest; - -using rtl::OUString; - -/** - * This function is called to get service factories for an implementation. - * @param pImplName name of implementation - * @param pServiceManager generic uno interface providing a service manager to instantiate components - * @param pRegistryKey registry data key to read and write component persistent data - * @return a component factory (generic uno interface) - */ -extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( - const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) -{ - void * pRet = 0; - uno::Reference< XMultiServiceFactory > xSMgr( - reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); - uno::Reference< XSingleServiceFactory > xFactory; - - if (ManifestReader::static_getImplementationName().compareToAscii( pImplName ) == 0) - xFactory = ManifestReader::createServiceFactory ( xSMgr ); - else if (ManifestWriter::static_getImplementationName().compareToAscii( pImplName ) == 0) - xFactory = ManifestWriter::createServiceFactory ( xSMgr ); - else if (ZipPackage::static_getImplementationName().compareToAscii( pImplName ) == 0) - xFactory = ZipPackage::createServiceFactory ( xSMgr ); - else if ( OZipFileAccess::impl_staticGetImplementationName().compareToAscii( pImplName ) == 0 ) - xFactory = ::cppu::createSingleFactory( xSMgr, - OZipFileAccess::impl_staticGetImplementationName(), - OZipFileAccess::impl_staticCreateSelfInstance, - OZipFileAccess::impl_staticGetSupportedServiceNames() ); - - if ( xFactory.is() ) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - return pRet; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/makefile.mk b/package/source/manifest/makefile.mk deleted file mode 100644 index abc61848f..000000000 --- a/package/source/manifest/makefile.mk +++ /dev/null @@ -1,55 +0,0 @@ -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2000, 2010 Oracle and/or its affiliates. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# <http://www.openoffice.org/license.html> -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -PRJ=..$/.. -PRJNAME=package -TARGET=manifest -AUTOSEG=true - -ENABLE_EXCEPTIONS=TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE : settings.mk - -# --- Files -------------------------------------------------------- - -.IF "$(L10N_framework)"=="" - -SLOFILES= \ - $(SLO)$/ManifestReader.obj \ - $(SLO)$/ManifestWriter.obj \ - $(SLO)$/ManifestImport.obj \ - $(SLO)$/ManifestExport.obj \ - $(SLO)$/Base64Codec.obj \ - $(SLO)$/UnoRegister.obj - -.ENDIF # L10N_framework - -# --- Targets ------------------------------------------------------ - -.INCLUDE : target.mk diff --git a/package/source/xstor/disposelistener.cxx b/package/source/xstor/disposelistener.cxx deleted file mode 100644 index 312c77d04..000000000 --- a/package/source/xstor/disposelistener.cxx +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include "disposelistener.hxx" -#include "xstorage.hxx" - -using namespace ::com::sun::star; - -OChildDispListener_Impl::OChildDispListener_Impl( OStorage& aStorage ) -: m_pStorage( &aStorage ) -{} - -OChildDispListener_Impl::~OChildDispListener_Impl() -{} - -void OChildDispListener_Impl::OwnerIsDisposed() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - m_pStorage = NULL; -} - -void SAL_CALL OChildDispListener_Impl::disposing( const lang::EventObject& Source ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - // ObjectIsDisposed must not contain any locking! - if ( m_pStorage && Source.Source.is() ) - m_pStorage->ChildIsDisposed( Source.Source ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/disposelistener.hxx b/package/source/xstor/disposelistener.hxx deleted file mode 100644 index 54b336688..000000000 --- a/package/source/xstor/disposelistener.hxx +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef __DISPOSELISTENER_HXX_ -#define __DISPOSELISTENER_HXX_ - -#include <com/sun/star/lang/XEventListener.hpp> -#include <cppuhelper/implbase1.hxx> -#include <osl/mutex.hxx> - -class OStorage; -class OChildDispListener_Impl : public ::cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener > -{ - ::osl::Mutex m_aMutex; - OStorage* m_pStorage; - -public: - OChildDispListener_Impl( OStorage& aStorage ); - virtual ~OChildDispListener_Impl(); - - void OwnerIsDisposed(); - - virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/makefile.mk b/package/source/xstor/makefile.mk deleted file mode 100644 index 5c381ba4c..000000000 --- a/package/source/xstor/makefile.mk +++ /dev/null @@ -1,83 +0,0 @@ -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2000, 2010 Oracle and/or its affiliates. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# <http://www.openoffice.org/license.html> -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -PRJ=..$/.. - -PRJNAME=package -TARGET=xstor - -ENABLE_EXCEPTIONS=TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE : settings.mk - -# --- Files -------------------------------------------------------- - -.IF "$(L10N_framework)"=="" - -SLOFILES = \ - $(SLO)$/ohierarchyholder.obj\ - $(SLO)$/ocompinstream.obj\ - $(SLO)$/oseekinstream.obj\ - $(SLO)$/owriteablestream.obj\ - $(SLO)$/xstorage.obj\ - $(SLO)$/xfactory.obj\ - $(SLO)$/disposelistener.obj\ - $(SLO)$/selfterminatefilestream.obj\ - $(SLO)$/switchpersistencestream.obj\ - $(SLO)$/register.obj - -SHL1TARGET=$(TARGET) -SHL1STDLIBS=\ - $(SALLIB) \ - $(CPPULIB) \ - $(CPPUHELPERLIB) \ - $(COMPHELPERLIB) - -SHL1OBJS=$(SLOFILES) -SHL1DEF=$(MISC)$/$(TARGET).def - -SHL1IMPLIB=i$(SHL1TARGET) - -DEF1NAME=$(SHL1TARGET) -DEF1EXPORTFILE=$(SHL1TARGET).dxp - -.ENDIF # L10N_framework - -# --- Targets ------------------------------------------------------- - -.INCLUDE : target.mk - - -ALLTAR : $(MISC)/xstor.component - -$(MISC)/xstor.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \ - xstor.component - $(XSLTPROC) --nonet --stringparam uri \ - '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \ - $(SOLARENV)/bin/createcomponent.xslt xstor.component diff --git a/package/source/xstor/ocompinstream.cxx b/package/source/xstor/ocompinstream.cxx deleted file mode 100644 index 5134d4f56..000000000 --- a/package/source/xstor/ocompinstream.cxx +++ /dev/null @@ -1,761 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include "ocompinstream.hxx" -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/lang/DisposedException.hpp> -#include <osl/diagnose.h> - -#include "owriteablestream.hxx" -#include "xstorage.hxx" - -using namespace ::com::sun::star; - -//----------------------------------------------- -OInputCompStream::OInputCompStream( OWriteStream_Impl& aImpl, - uno::Reference < io::XInputStream > xStream, - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Int32 nStorageType ) -: m_pImpl( &aImpl ) -, m_rMutexRef( m_pImpl->m_rMutexRef ) -, m_xStream( xStream ) -, m_pInterfaceContainer( NULL ) -, m_aProperties( aProps ) -, m_bDisposed( sal_False ) -, m_nStorageType( nStorageType ) -{ - OSL_ENSURE( m_pImpl->m_rMutexRef.Is(), "No mutex is provided!\n" ); - if ( !m_pImpl->m_rMutexRef.Is() ) - throw uno::RuntimeException(); // just a disaster - - OSL_ENSURE( xStream.is(), "No stream is provided!\n" ); -} - -//----------------------------------------------- -OInputCompStream::OInputCompStream( uno::Reference < io::XInputStream > xStream, - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Int32 nStorageType ) -: m_pImpl( NULL ) -, m_rMutexRef( new SotMutexHolder ) -, m_xStream( xStream ) -, m_pInterfaceContainer( NULL ) -, m_aProperties( aProps ) -, m_bDisposed( sal_False ) -, m_nStorageType( nStorageType ) -{ - OSL_ENSURE( xStream.is(), "No stream is provided!\n" ); -} - -//----------------------------------------------- -OInputCompStream::~OInputCompStream() -{ - { - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_bDisposed ) - { - m_refCount++; - dispose(); - } - - if ( m_pInterfaceContainer ) - delete m_pInterfaceContainer; - } -} - -//----------------------------------------------- -uno::Any SAL_CALL OInputCompStream::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - uno::Any aReturn; - - // common interfaces - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<io::XInputStream*> ( this ) - , static_cast<io::XStream*> ( this ) - , static_cast<lang::XComponent*> ( this ) - , static_cast<beans::XPropertySet*> ( this ) - , static_cast<embed::XExtendedStorageStream*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XRelationshipAccess*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - } - - return OWeakObject::queryInterface( rType ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OInputCompStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No stream!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xStream->readBytes( aData, nBytesToRead ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OInputCompStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No stream!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xStream->readSomeBytes( aData, nMaxBytesToRead ); - -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::skipBytes( sal_Int32 nBytesToSkip ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No stream!" ) ) ); - throw uno::RuntimeException(); - } - - m_xStream->skipBytes( nBytesToSkip ); - -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OInputCompStream::available( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No stream!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xStream->available(); - -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::closeInput( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - dispose(); -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OInputCompStream::getInputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - return uno::Reference< io::XInputStream >(); - - return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY ); -} - -//----------------------------------------------- -uno::Reference< io::XOutputStream > SAL_CALL OInputCompStream::getOutputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - return uno::Reference< io::XOutputStream >(); -} - -//----------------------------------------------- -void OInputCompStream::InternalDispose() -{ - // can be called only by OWriteStream_Impl - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - // the source object is also a kind of locker for the current object - // since the listeners could dispose the object while being notified - lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) ); - - if ( m_pInterfaceContainer ) - m_pInterfaceContainer->disposeAndClear( aSource ); - - try - { - m_xStream->closeInput(); - } - catch( uno::Exception& ) - {} - - m_pImpl = NULL; - m_bDisposed = sal_True; -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::dispose( ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pInterfaceContainer ) - { - lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) ); - m_pInterfaceContainer->disposeAndClear( aSource ); - } - - m_xStream->closeInput(); - - if ( m_pImpl ) - { - m_pImpl->InputStreamDisposed( this ); - m_pImpl = NULL; - } - - m_bDisposed = sal_True; -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_pInterfaceContainer ) - m_pInterfaceContainer = new ::cppu::OInterfaceContainerHelper( m_rMutexRef->GetMutex() ); - - m_pInterfaceContainer->addInterface( xListener ); -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pInterfaceContainer ) - m_pInterfaceContainer->removeInterface( xListener ); -} - -//----------------------------------------------- -sal_Bool SAL_CALL OInputCompStream::hasByID( const ::rtl::OUString& sID ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - try - { - getRelationshipByID( sID ); - return sal_True; - } - catch( container::NoSuchElementException& ) - {} - - return sal_False; -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OInputCompStream::getTargetByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Target" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OInputCompStream::getTypeByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -uno::Sequence< beans::StringPair > SAL_CALL OInputCompStream::getRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - return aSeq[nInd1]; - break; - } - - throw container::NoSuchElementException(); -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OInputCompStream::getRelationshipsByType( const ::rtl::OUString& sType ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< uno::Sequence< beans::StringPair > > aResult; - sal_Int32 nEntriesNum = 0; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sType ) ) - { - aResult.realloc( nEntriesNum ); - aResult[nEntriesNum-1] = aSeq[nInd1]; - } - break; - } - - return aResult; -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OInputCompStream::getAllRelationships() - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - // TODO/LATER: in future the information could be taken directly from m_pImpl when possible - uno::Sequence< uno::Sequence< beans::StringPair > > aResult; - for ( sal_Int32 aInd = 0; aInd < m_aProperties.getLength(); aInd++ ) - if ( m_aProperties[aInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - { - if ( m_aProperties[aInd].Value >>= aResult ) - return aResult; - - break; - } - - throw io::IOException(); // the relations info could not be read -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::insertRelationshipByID( const ::rtl::OUString& /*sID*/, const uno::Sequence< beans::StringPair >& /*aEntry*/, ::sal_Bool /*bReplace*/ ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - throw io::IOException(); // TODO: Access denied -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::removeRelationshipByID( const ::rtl::OUString& /*sID*/ ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - throw io::IOException(); // TODO: Access denied -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::insertRelationships( const uno::Sequence< uno::Sequence< beans::StringPair > >& /*aEntries*/, ::sal_Bool /*bReplace*/ ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - throw io::IOException(); // TODO: Access denied -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::clearRelationships() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - throw io::IOException(); // TODO: Access denied -} - -//----------------------------------------------- -uno::Reference< beans::XPropertySetInfo > SAL_CALL OInputCompStream::getPropertySetInfo() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: - return uno::Reference< beans::XPropertySetInfo >(); -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& /*aValue*/ ) - throw ( beans::UnknownPropertyException, - beans::PropertyVetoException, - lang::IllegalArgumentException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - // all the provided properties are accessible - for ( sal_Int32 aInd = 0; aInd < m_aProperties.getLength(); aInd++ ) - { - if ( m_aProperties[aInd].Name.equals( aPropertyName ) ) - { - throw beans::PropertyVetoException(); // TODO - } - } - - throw beans::UnknownPropertyException(); // TODO -} - - -//----------------------------------------------- -uno::Any SAL_CALL OInputCompStream::getPropertyValue( const ::rtl::OUString& aProp ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - ::rtl::OUString aPropertyName; - if ( aProp.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsEncrypted" ) ) ) - aPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ); - else - aPropertyName = aProp; - - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - throw beans::UnknownPropertyException(); // TODO - - // all the provided properties are accessible - for ( sal_Int32 aInd = 0; aInd < m_aProperties.getLength(); aInd++ ) - { - if ( m_aProperties[aInd].Name.equals( aPropertyName ) ) - { - return m_aProperties[aInd].Value; - } - } - - throw beans::UnknownPropertyException(); // TODO -} - - -//----------------------------------------------- -void SAL_CALL OInputCompStream::addPropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OInputCompStream::removePropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OInputCompStream::addVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OInputCompStream::removeVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/ocompinstream.hxx b/package/source/xstor/ocompinstream.hxx deleted file mode 100644 index c585f18fc..000000000 --- a/package/source/xstor/ocompinstream.hxx +++ /dev/null @@ -1,130 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _INPUTCOMPSTREAM_HXX_ -#define _INPUTCOMPSTREAM_HXX_ - -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/embed/XExtendedStorageStream.hpp> -#include <com/sun/star/embed/XRelationshipAccess.hpp> -#include <cppuhelper/implbase4.hxx> -#include <cppuhelper/interfacecontainer.h> - -#include "mutexholder.hxx" - -struct OWriteStream_Impl; - -class OInputCompStream : public cppu::WeakImplHelper4 < ::com::sun::star::io::XInputStream - ,::com::sun::star::embed::XExtendedStorageStream - ,::com::sun::star::embed::XRelationshipAccess - ,::com::sun::star::beans::XPropertySet > -{ -protected: - OWriteStream_Impl* m_pImpl; - - SotMutexHolderRef m_rMutexRef; - - ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > m_xStream; - - ::cppu::OInterfaceContainerHelper* m_pInterfaceContainer; - - ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > m_aProperties; - - sal_Bool m_bDisposed; - - sal_Int32 m_nStorageType; - -public: - OInputCompStream( OWriteStream_Impl& pImpl, - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Int32 nStorageType ); - - OInputCompStream( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Int32 nStorageType ); - - virtual ~OInputCompStream(); - - void InternalDispose(); - - // XInterface - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) - throw( ::com::sun::star::uno::RuntimeException ); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XStream - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); - - //XComponent - virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); - - //XRelationshipAccess - virtual ::sal_Bool SAL_CALL hasByID( const ::rtl::OUString& sID ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getTargetByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getTypeByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > SAL_CALL getRelationshipByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getRelationshipsByType( const ::rtl::OUString& sType ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getAllRelationships( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertRelationshipByID( const ::rtl::OUString& sID, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aEntry, ::sal_Bool bReplace ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeRelationshipByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertRelationships( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aEntries, ::sal_Bool bReplace ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL clearRelationships( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XPropertySet - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw ( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) 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 ); - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/ohierarchyholder.cxx b/package/source/xstor/ohierarchyholder.cxx deleted file mode 100644 index 250e4bb59..000000000 --- a/package/source/xstor/ohierarchyholder.cxx +++ /dev/null @@ -1,361 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/XHierarchicalStorageAccess2.hpp> -#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> - -#include "ohierarchyholder.hxx" - -using namespace ::com::sun::star; - -//=============================================== -// OHierarchyHolder_Impl -//=============================================== - -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - uno::Reference< embed::XStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW ); - - if ( !( nStorageMode & embed::ElementModes::WRITE ) && ( nStreamMode & embed::ElementModes::WRITE ) ) - throw io::IOException(); - - uno::Reference< embed::XExtendedStorageStream > xResult = - m_xChild->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aEncryptionData ); - if ( !xResult.is() ) - throw uno::RuntimeException(); - - return xResult; -} - -//----------------------------------------------- -void OHierarchyHolder_Impl::RemoveStreamHierarchically( OStringList_Impl& aListPath ) -{ - uno::Reference< embed::XStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW ); - - m_xChild->RemoveStreamHierarchically( aListPath ); -} - -//----------------------------------------------- -// static -OStringList_Impl OHierarchyHolder_Impl::GetListPathFromString( const ::rtl::OUString& aPath ) -{ - OStringList_Impl aResult; - sal_Int32 nIndex = 0; - do - { - ::rtl::OUString aName = aPath.getToken( 0, '/', nIndex ); - if ( !aName.getLength() ) - throw lang::IllegalArgumentException(); - - aResult.push_back( aName ); - } - while ( nIndex >= 0 ); - - return aResult; -} - -//=============================================== -// OHierarchyElement_Impl -//=============================================== - -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !( nStorageMode & embed::ElementModes::WRITE ) && ( nStreamMode & embed::ElementModes::WRITE ) ) - throw io::IOException(); - - if ( !aListPath.size() ) - throw uno::RuntimeException(); - - ::rtl::OUString aNextName = *(aListPath.begin()); - aListPath.erase( aListPath.begin() ); - - uno::Reference< embed::XExtendedStorageStream > xResult; - - uno::Reference< embed::XStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage - : uno::Reference< embed::XStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY ); - if ( !xOwnStor.is() ) - throw uno::RuntimeException(); - - if ( !aListPath.size() ) - { - if ( !aEncryptionData.size() ) - { - uno::Reference< embed::XHierarchicalStorageAccess > xHStorage( xOwnStor, uno::UNO_QUERY_THROW ); - xResult = xHStorage->openStreamElementByHierarchicalName( aNextName, nStreamMode ); - } - else - { - uno::Reference< embed::XHierarchicalStorageAccess2 > xHStorage( xOwnStor, uno::UNO_QUERY_THROW ); - xResult = xHStorage->openEncryptedStreamByHierarchicalName( aNextName, nStreamMode, aEncryptionData.getAsConstNamedValueList() ); - } - - uno::Reference< embed::XTransactedObject > xTransact( xResult, uno::UNO_QUERY ); - if ( xTransact.is() ) - { - // the existance of the transacted object means that the stream is opened for writing also - // so the whole chain must be commited - uno::Reference< embed::XTransactionBroadcaster > xTrBroadcast( xTransact, uno::UNO_QUERY_THROW ); - xTrBroadcast->addTransactionListener( static_cast< embed::XTransactionListener* >( this ) ); - } - else - { - uno::Reference< lang::XComponent > xStreamComp( xResult, uno::UNO_QUERY_THROW ); - xStreamComp->addEventListener( static_cast< lang::XEventListener* >( this ) ); - } - - m_aOpenStreams.push_back( uno::WeakReference< embed::XExtendedStorageStream >( xResult ) ); - } - else - { - sal_Bool bNewElement = sal_False; - ::rtl::Reference< OHierarchyElement_Impl > aElement; - OHierarchyElementList_Impl::iterator aIter = m_aChildren.find( aNextName ); - if ( aIter != m_aChildren.end() ) - aElement = aIter->second; - - if ( !aElement.is() ) - { - bNewElement = sal_True; - uno::Reference< embed::XStorage > xChildStorage = xOwnStor->openStorageElement( aNextName, nStorageMode ); - if ( !xChildStorage.is() ) - throw uno::RuntimeException(); - - aElement = new OHierarchyElement_Impl( NULL, xChildStorage ); - } - - xResult = aElement->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aEncryptionData ); - if ( !xResult.is() ) - throw uno::RuntimeException(); - - if ( bNewElement ) - { - m_aChildren[aNextName] = aElement; - aElement->SetParent( this ); - } - } - - // the subelement was opened successfuly, remember the storage to let it be locked - m_xOwnStorage = xOwnStor; - - return xResult; -} - -//----------------------------------------------- -void OHierarchyElement_Impl::RemoveStreamHierarchically( OStringList_Impl& aListPath ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !aListPath.size() ) - throw uno::RuntimeException(); - - ::rtl::OUString aNextName = *(aListPath.begin()); - aListPath.erase( aListPath.begin() ); - - uno::Reference< embed::XExtendedStorageStream > xResult; - - uno::Reference< embed::XStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage - : uno::Reference< embed::XStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY ); - if ( !xOwnStor.is() ) - throw uno::RuntimeException(); - - if ( !aListPath.size() ) - { - xOwnStor->removeElement( aNextName ); - } - else - { - ::rtl::Reference< OHierarchyElement_Impl > aElement; - OHierarchyElementList_Impl::iterator aIter = m_aChildren.find( aNextName ); - if ( aIter != m_aChildren.end() ) - aElement = aIter->second; - - if ( !aElement.is() ) - { - uno::Reference< embed::XStorage > xChildStorage = xOwnStor->openStorageElement( aNextName, - embed::ElementModes::READWRITE ); - if ( !xChildStorage.is() ) - throw uno::RuntimeException(); - - aElement = new OHierarchyElement_Impl( NULL, xChildStorage ); - } - - aElement->RemoveStreamHierarchically( aListPath ); - } - - uno::Reference< embed::XTransactedObject > xTransact( xOwnStor, uno::UNO_QUERY ); - if ( xTransact.is() ) - xTransact->commit(); - - TestForClosing(); -} - -//----------------------------------------------- -void OHierarchyElement_Impl::Commit() -{ - ::rtl::Reference< OHierarchyElement_Impl > aLocker( this ); - ::rtl::Reference< OHierarchyElement_Impl > aParent; - uno::Reference< embed::XStorage > xOwnStor; - - { - ::osl::MutexGuard aGuard( m_aMutex ); - aParent = m_rParent; - xOwnStor = m_xOwnStorage; - } - - if ( xOwnStor.is() ) - { - uno::Reference< embed::XTransactedObject > xTransact( xOwnStor, uno::UNO_QUERY_THROW ); - xTransact->commit(); - if ( aParent.is() ) - aParent->Commit(); - } -} - -//----------------------------------------------- -void OHierarchyElement_Impl::TestForClosing() -{ - ::rtl::Reference< OHierarchyElement_Impl > aLocker( this ); - { - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_aOpenStreams.size() && !m_aChildren.size() ) - { - if ( m_rParent.is() ) - { - // only the root storage should not be disposed, other storages can be disposed - if ( m_xOwnStorage.is() ) - { - try - { - m_xOwnStorage->dispose(); - } - catch( uno::Exception& ) - {} - } - - m_rParent->RemoveElement( this ); - } - - m_xOwnStorage = uno::Reference< embed::XStorage >(); - } - } -} - -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::disposing( const lang::EventObject& Source ) - throw ( uno::RuntimeException ) -{ - uno::Sequence< embed::XStorage > aStoragesToCommit; - - try - { - ::osl::ClearableMutexGuard aGuard( m_aMutex ); - uno::Reference< embed::XExtendedStorageStream > xStream( Source.Source, uno::UNO_QUERY ); - - for ( OWeakStorRefList_Impl::iterator pStorageIter = m_aOpenStreams.begin(); - pStorageIter != m_aOpenStreams.end(); ) - { - OWeakStorRefList_Impl::iterator pTmp = pStorageIter++; - if ( !pTmp->get().is() || pTmp->get() == xStream ) - m_aOpenStreams.erase( pTmp ); - } - - aGuard.clear(); - - TestForClosing(); - } - catch( uno::Exception& ) - { - throw uno::RuntimeException(); // no exception must happen here, usually an exception means disaster - } -} - -//----------------------------------------------- -void OHierarchyElement_Impl::RemoveElement( const ::rtl::Reference< OHierarchyElement_Impl >& aRef ) -{ - { - ::osl::MutexGuard aGuard( m_aMutex ); - for ( OHierarchyElementList_Impl::iterator aIter = m_aChildren.begin(); - aIter != m_aChildren.end(); /* increment is done in body */) - { - OHierarchyElementList_Impl::iterator aTmpIter = aIter; - aIter++; - - if ( aTmpIter->second == aRef ) - m_aChildren.erase( aTmpIter ); - } - } - - TestForClosing(); -} - -// XTransactionListener -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::preCommit( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) - throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) -{ -} - -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::commited( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) - throw (::com::sun::star::uno::RuntimeException) -{ - try - { - Commit(); - } - catch( uno::Exception& e ) - { - throw lang::WrappedTargetRuntimeException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not commit storage sequence!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); - } -} - -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::preRevert( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) - throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) -{ -} - -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::reverted( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) - throw (::com::sun::star::uno::RuntimeException) -{ -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/ohierarchyholder.hxx b/package/source/xstor/ohierarchyholder.hxx deleted file mode 100644 index 9fffdc5af..000000000 --- a/package/source/xstor/ohierarchyholder.hxx +++ /dev/null @@ -1,143 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _OHIERARCHYHOLDER_HXX_ -#define _OHIERARCHYHOLDER_HXX_ - -#include <com/sun/star/embed/XStorage.hpp> -#include <com/sun/star/embed/XTransactionListener.hpp> -#include <com/sun/star/embed/XExtendedStorageStream.hpp> -#include <cppuhelper/implbase1.hxx> - -#include <comphelper/sequenceashashmap.hxx> - -#include <rtl/ref.hxx> - -#include <boost/unordered_map.hpp> -#include <list> -#include <vector> - -struct OHierarchyElement_Impl; - -struct eqFunc -{ - sal_Bool operator()( const rtl::OUString &r1, - const rtl::OUString &r2) const - { - return r1 == r2; - } -}; -typedef ::boost::unordered_map< ::rtl::OUString, - ::rtl::Reference< OHierarchyElement_Impl >, - ::rtl::OUStringHash, - eqFunc > OHierarchyElementList_Impl; - -typedef ::std::vector< ::rtl::OUString > OStringList_Impl; -typedef ::std::list< ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XExtendedStorageStream > > - OWeakStorRefList_Impl; - -struct OHierarchyElement_Impl : public cppu::WeakImplHelper1< ::com::sun::star::embed::XTransactionListener > -{ - ::osl::Mutex m_aMutex; - - ::rtl::Reference< OHierarchyElement_Impl > m_rParent; - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xOwnStorage; - ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage; - - OHierarchyElementList_Impl m_aChildren; - - OWeakStorRefList_Impl m_aOpenStreams; - -public: - OHierarchyElement_Impl( OHierarchyElement_Impl* pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ) - : m_rParent( pParent ) - , m_xOwnStorage( xStorage ) - {} - - OHierarchyElement_Impl( const ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >& xWeakStorage ) - : m_rParent( NULL ) - , m_xWeakOwnStorage( xWeakStorage ) - {} - - void Commit(); - - void SetParent( const ::rtl::Reference< OHierarchyElement_Impl >& rParent ) { m_rParent = rParent; } - - void TestForClosing(); - - void RemoveElement( const ::rtl::Reference< OHierarchyElement_Impl >& aRef ); - - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > - GetStreamHierarchically( sal_Int32 nStorageMode, - OStringList_Impl& aPath, - sal_Int32 nStreamMode, - const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() ); - - void RemoveStreamHierarchically( OStringList_Impl& aListPath ); - - // XEventListener - virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) - throw (::com::sun::star::uno::RuntimeException); - - - // XTransactionListener - virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) - throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) - throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) - throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ) - throw (::com::sun::star::uno::RuntimeException); - -}; - -class OHierarchyHolder_Impl : public ::cppu::OWeakObject -{ - ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage; - ::rtl::Reference< OHierarchyElement_Impl > m_xChild; -public: - OHierarchyHolder_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xOwnStorage ) - : m_xWeakOwnStorage( xOwnStorage ) - , m_xChild( new OHierarchyElement_Impl( ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >( xOwnStorage ) ) ) - {} - - static OStringList_Impl GetListPathFromString( const ::rtl::OUString& aPath ); - - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > - GetStreamHierarchically( sal_Int32 nStorageMode, - OStringList_Impl& aListPath, - sal_Int32 nStreamMode, - const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() ); - - void RemoveStreamHierarchically( OStringList_Impl& aListPath ); -}; - -#endif // _OHIERARCHYHOLDER - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/oseekinstream.cxx b/package/source/xstor/oseekinstream.cxx deleted file mode 100644 index 229bba9eb..000000000 --- a/package/source/xstor/oseekinstream.cxx +++ /dev/null @@ -1,182 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/lang/DisposedException.hpp> -#include <cppuhelper/typeprovider.hxx> -#include <osl/diagnose.h> - -#include "oseekinstream.hxx" -#include "owriteablestream.hxx" - -using namespace ::com::sun::star; - -OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl, - uno::Reference < io::XInputStream > xStream, - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Int32 nStorageType ) -: OInputCompStream( pImpl, xStream, aProps, nStorageType ) -{ - if ( m_xStream.is() ) - { - m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY ); - OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" ); - } -} - -OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > xStream, - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Int32 nStorageType ) -: OInputCompStream( xStream, aProps, nStorageType ) -{ - if ( m_xStream.is() ) - { - m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY ); - OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" ); - } -} - -OInputSeekStream::~OInputSeekStream() -{ -} - -uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes() - throw ( uno::RuntimeException ) -{ - static ::cppu::OTypeCollection* pTypeCollection = NULL ; - - if ( pTypeCollection == NULL ) - { - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( pTypeCollection == NULL ) - { - static ::cppu::OTypeCollection aTypeCollection( - ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ), - OInputCompStream::getTypes() ); - - pTypeCollection = &aTypeCollection ; - } - } - - return pTypeCollection->getTypes() ; -} - -uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - // Attention: - // Don't use mutex or guard in this method!!! Is a method of XInterface. - - uno::Any aReturn( ::cppu::queryInterface( rType, - static_cast< io::XSeekable* >( this ) ) ); - - if ( aReturn.hasValue() == sal_True ) - { - return aReturn ; - } - - return OInputCompStream::queryInterface( rType ) ; -} - -void SAL_CALL OInputSeekStream::acquire() - throw() -{ - OInputCompStream::acquire(); -} - -void SAL_CALL OInputSeekStream::release() - throw() -{ - OInputCompStream::release(); -} - - -void SAL_CALL OInputSeekStream::seek( sal_Int64 location ) - throw ( lang::IllegalArgumentException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) ); - throw uno::RuntimeException(); - } - - m_xSeekable->seek( location ); -} - -sal_Int64 SAL_CALL OInputSeekStream::getPosition() - throw ( io::IOException, - uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xSeekable->getPosition(); -} - -sal_Int64 SAL_CALL OInputSeekStream::getLength() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xSeekable->getLength(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/oseekinstream.hxx b/package/source/xstor/oseekinstream.hxx deleted file mode 100644 index b605d25e8..000000000 --- a/package/source/xstor/oseekinstream.hxx +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _INPUTSEEKSTREAM_HXX_ -#define _INPUTSEEKSTREAM_HXX_ - -#include <com/sun/star/io/XSeekable.hpp> - -#include "ocompinstream.hxx" - -class OInputSeekStream : public OInputCompStream - , public ::com::sun::star::io::XSeekable -{ -protected: - ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > m_xSeekable; - -public: - OInputSeekStream( OWriteStream_Impl& pImpl, - ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > xStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Int32 nStorageType ); - - OInputSeekStream( ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > xStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Int32 nStorageType ); - - virtual ~OInputSeekStream(); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); - - // XInterface - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL acquire() throw(); - virtual void SAL_CALL release() throw(); - - //XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx deleted file mode 100644 index 2c94e3c8a..000000000 --- a/package/source/xstor/owriteablestream.cxx +++ /dev/null @@ -1,3623 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/ucb/XCommandEnvironment.hpp> -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/lang/XTypeProvider.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/IOException.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> -#include <cppuhelper/typeprovider.hxx> -#include <cppuhelper/exc_hlp.hxx> -#include <osl/diagnose.h> - -#include <comphelper/processfactory.hxx> -#include <comphelper/componentcontext.hxx> -#include <comphelper/storagehelper.hxx> -#include <comphelper/ofopxmlhelper.hxx> - -#include <rtl/digest.h> -#include <rtl/logfile.hxx> -#include <rtl/instance.hxx> - -#include <PackageConstants.hxx> -#include <mutexholder.hxx> - -#include "selfterminatefilestream.hxx" -#include "owriteablestream.hxx" -#include "oseekinstream.hxx" -#include "xstorage.hxx" - -// since the copying uses 32000 blocks usually, it makes sense to have a smaller size -#define MAX_STORCACHE_SIZE 30000 - - -using namespace ::com::sun::star; - -namespace package -{ -//----------------------------------------------- -bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, const ::comphelper::SequenceAsHashMap& aHash2 ) -{ - bool bResult = ( aHash1.size() && aHash1.size() == aHash2.size() ); - for ( ::comphelper::SequenceAsHashMap::const_iterator aIter = aHash1.begin(); - bResult && aIter != aHash1.end(); - aIter++ ) - { - uno::Sequence< sal_Int8 > aKey1; - bResult = ( ( aIter->second >>= aKey1 ) && aKey1.getLength() ); - if ( bResult ) - { - uno::Sequence< sal_Int8 > aKey2 = aHash2.getUnpackedValueOrDefault( aIter->first, uno::Sequence< sal_Int8 >() ); - bResult = ( aKey1.getLength() == aKey2.getLength() ); - for ( sal_Int32 nInd = 0; bResult && nInd < aKey1.getLength(); nInd++ ) - bResult = ( aKey1[nInd] == aKey2[nInd] ); - } - } - - return bResult; -} - -//----------------------------------------------- -void StaticAddLog( const ::rtl::OUString& aMessage ) -{ - try - { - ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); - if ( aContext.is() ) - { - uno::Reference< logging::XSimpleLogRing > xLogRing( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW ); - xLogRing->logString( aMessage ); - } - } - catch( const uno::Exception& ) - { - // No log - } -} -} // namespace package - -// ================================================================ -namespace -{ -//----------------------------------------------- -void SetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet, - const uno::Sequence< beans::NamedValue >& aKey ) -{ - OSL_ENSURE( xPropertySet.is(), "No property set is provided!\n" ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - try { - xPropertySet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), uno::makeAny( aKey ) ); - } - catch ( const uno::Exception& rException ) - { - ::package::StaticAddLog( rException.Message ); - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't set encryption") ) ); - OSL_FAIL( "Can't write encryption related properties!\n" ); - throw io::IOException(); // TODO - } -} - -//----------------------------------------------- -uno::Any GetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet ) -{ - OSL_ENSURE( xPropertySet.is(), "No property set is provided!\n" ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - try { - return xPropertySet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ); - } - catch ( const uno::Exception& rException ) - { - ::package::StaticAddLog( rException.Message ); - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get encryption property" ) ) ); - - OSL_FAIL( "Can't get encryption related properties!\n" ); - throw io::IOException(); // TODO - } -} - -//----------------------------------------------- -bool SequencesEqual( const uno::Sequence< sal_Int8 >& aSequence1, const uno::Sequence< sal_Int8 >& aSequence2 ) -{ - if ( aSequence1.getLength() != aSequence2.getLength() ) - return false; - - for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ ) - if ( aSequence1[nInd] != aSequence2[nInd] ) - return false; - - return true; -} - -//----------------------------------------------- -bool SequencesEqual( const uno::Sequence< beans::NamedValue >& aSequence1, const uno::Sequence< beans::NamedValue >& aSequence2 ) -{ - if ( aSequence1.getLength() != aSequence2.getLength() ) - return false; - - for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ ) - { - bool bHasMember = false; - uno::Sequence< sal_Int8 > aMember1; - sal_Int32 nMember1 = 0; - if ( ( aSequence1[nInd].Value >>= aMember1 ) ) - { - for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ ) - { - if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) ) - { - bHasMember = true; - - uno::Sequence< sal_Int8 > aMember2; - if ( !( aSequence2[nInd2].Value >>= aMember2 ) || !SequencesEqual( aMember1, aMember2 ) ) - return false; - } - } - } - else if ( ( aSequence1[nInd].Value >>= nMember1 ) ) - { - for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ ) - { - if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) ) - { - bHasMember = true; - - sal_Int32 nMember2 = 0; - if ( !( aSequence2[nInd2].Value >>= nMember2 ) || nMember1 != nMember2 ) - return false; - } - } - } - else - return false; - - if ( !bHasMember ) - return false; - } - - return true; -} - -//----------------------------------------------- -sal_Bool KillFile( const ::rtl::OUString& aURL, const uno::Reference< lang::XMultiServiceFactory >& xFactory ) -{ - if ( !xFactory.is() ) - return sal_False; - - sal_Bool bRet = sal_False; - - try - { - uno::Reference < ucb::XSimpleFileAccess > xAccess( - xFactory->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess" ) ) ), - uno::UNO_QUERY ); - - if ( xAccess.is() ) - { - xAccess->kill( aURL ); - bRet = sal_True; - } - } - catch( const uno::Exception& rException ) - { - ::package::StaticAddLog( rException.Message ); - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception") ) ); - } - - return bRet; -} - -const sal_Int32 n_ConstBufferSize = 32000; - -//----------------------------------------------- -::rtl::OUString GetNewTempFileURL( const uno::Reference< lang::XMultiServiceFactory > xFactory ) -{ - ::rtl::OUString aTempURL; - - uno::Reference < beans::XPropertySet > xTempFile( - xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY ); - - if ( !xTempFile.is() ) - throw uno::RuntimeException(); // TODO - - try { - xTempFile->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveFile") ), uno::makeAny( sal_False ) ); - uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Uri") ) ); - aUrl >>= aTempURL; - } - catch ( const uno::Exception& rException ) - { - ::package::StaticAddLog( rException.Message ); - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception") ) ); - } - - if ( !aTempURL.getLength() ) - throw uno::RuntimeException(); // TODO: can not create tempfile - - return aTempURL; -} - -//----------------------------------------------- -uno::Reference< io::XStream > CreateMemoryStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory ) -{ - if ( !xFactory.is() ) - throw uno::RuntimeException(); - - return uno::Reference< io::XStream >( xFactory->createInstance (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.MemoryStream") ) ), uno::UNO_QUERY_THROW); -} - -} // anonymous namespace -// ================================================================ - -//----------------------------------------------- -OWriteStream_Impl::OWriteStream_Impl( OStorage_Impl* pParent, - const uno::Reference< packages::XDataSinkEncrSupport >& xPackageStream, - const uno::Reference< lang::XSingleServiceFactory >& xPackage, - const uno::Reference< lang::XMultiServiceFactory >& xFactory, - sal_Bool bForceEncrypted, - sal_Int32 nStorageType, - sal_Bool bDefaultCompress, - const uno::Reference< io::XInputStream >& xRelInfoStream ) -: m_pAntiImpl( NULL ) -, m_bHasDataToFlush( sal_False ) -, m_bFlushed( sal_False ) -, m_xPackageStream( xPackageStream ) -, m_xFactory( xFactory ) -, m_pParent( pParent ) -, m_bForceEncrypted( bForceEncrypted ) -, m_bUseCommonEncryption( !bForceEncrypted && nStorageType == embed::StorageFormats::PACKAGE ) -, m_bHasCachedEncryptionData( sal_False ) -, m_bCompressedSetExplicit( !bDefaultCompress ) -, m_xPackage( xPackage ) -, m_bHasInsertedStreamOptimization( sal_False ) -, m_nStorageType( nStorageType ) -, m_xOrigRelInfoStream( xRelInfoStream ) -, m_bOrigRelInfoBroken( sal_False ) -, m_nRelInfoStatus( RELINFO_NO_INIT ) -, m_nRelId( 1 ) -{ - OSL_ENSURE( xPackageStream.is(), "No package stream is provided!\n" ); - OSL_ENSURE( xPackage.is(), "No package component is provided!\n" ); - OSL_ENSURE( m_xFactory.is(), "No package stream is provided!\n" ); - OSL_ENSURE( pParent, "No parent storage is provided!\n" ); - OSL_ENSURE( m_nStorageType == embed::StorageFormats::OFOPXML || !m_xOrigRelInfoStream.is(), "The Relations info makes sence only for OFOPXML format!\n" ); -} - -//----------------------------------------------- -OWriteStream_Impl::~OWriteStream_Impl() -{ - DisposeWrappers(); - - if ( m_aTempURL.getLength() ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - } - - CleanCacheStream(); -} - -//----------------------------------------------- -void OWriteStream_Impl::CleanCacheStream() -{ - if ( m_xCacheStream.is() ) - { - try - { - uno::Reference< io::XInputStream > xInputCache = m_xCacheStream->getInputStream(); - if ( xInputCache.is() ) - xInputCache->closeInput(); - } - catch( const uno::Exception& ) - {} - - try - { - uno::Reference< io::XOutputStream > xOutputCache = m_xCacheStream->getOutputStream(); - if ( xOutputCache.is() ) - xOutputCache->closeOutput(); - } - catch( const uno::Exception& ) - {} - - m_xCacheStream = uno::Reference< io::XStream >(); - m_xCacheSeek = uno::Reference< io::XSeekable >(); - } -} - -//----------------------------------------------- -void OWriteStream_Impl::AddLog( const ::rtl::OUString& aMessage ) -{ - if ( !m_xLogRing.is() ) - { - try - { - ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); - if ( aContext.is() ) - m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW ); - } - catch( const uno::Exception& ) - { - // No log - } - } - - if ( m_xLogRing.is() ) - m_xLogRing->logString( aMessage ); -} - - -//----------------------------------------------- -void OWriteStream_Impl::InsertIntoPackageFolder( const ::rtl::OUString& aName, - const uno::Reference< container::XNameContainer >& xParentPackageFolder ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_bFlushed, "This method must not be called for nonflushed streams!\n" ); - if ( m_bFlushed ) - { - OSL_ENSURE( m_xPackageStream.is(), "An inserted stream is incomplete!\n" ); - uno::Reference< lang::XUnoTunnel > xTunnel( m_xPackageStream, uno::UNO_QUERY ); - if ( !xTunnel.is() ) - throw uno::RuntimeException(); // TODO - - xParentPackageFolder->insertByName( aName, uno::makeAny( xTunnel ) ); - - m_bFlushed = sal_False; - m_bHasInsertedStreamOptimization = sal_False; - } -} -//----------------------------------------------- -sal_Bool OWriteStream_Impl::IsEncrypted() -{ - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - return sal_False; - - if ( m_bForceEncrypted || m_bHasCachedEncryptionData ) - return sal_True; - - if ( m_aTempURL.getLength() || m_xCacheStream.is() ) - return sal_False; - - GetStreamProperties(); - - // the following value can not be cached since it can change after root commit - sal_Bool bWasEncr = sal_False; - uno::Reference< beans::XPropertySet > xPropSet( m_xPackageStream, uno::UNO_QUERY ); - if ( xPropSet.is() ) - { - uno::Any aValue = xPropSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WasEncrypted") ) ); - if ( !( aValue >>= bWasEncr ) ) - { - OSL_FAIL( "The property WasEncrypted has wrong type!\n" ); - } - } - - sal_Bool bToBeEncr = sal_False; - for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ ) - { - if ( m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) - { - if ( !( m_aProps[nInd].Value >>= bToBeEncr ) ) - { - OSL_FAIL( "The property has wrong type!\n" ); - } - } - } - - // since a new key set to the package stream it should not be removed except the case when - // the stream becomes nonencrypted - uno::Sequence< beans::NamedValue > aKey; - if ( bToBeEncr ) - GetEncryptionKeyProperty_Impl( xPropSet ) >>= aKey; - - // If the properties must be investigated the stream is either - // was never changed or was changed, the parent was commited - // and the stream was closed. - // That means that if it is intended to use common storage key - // it is already has no encryption but is marked to be stored - // encrypted and the key is empty. - if ( !bWasEncr && bToBeEncr && !aKey.getLength() ) - { - // the stream is intended to use common storage password - m_bUseCommonEncryption = sal_True; - return sal_False; - } - else - return bToBeEncr; -} - -//----------------------------------------------- -void OWriteStream_Impl::SetDecrypted() -{ - OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE, "The encryption is supported only for package storages!\n" ); - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - GetStreamProperties(); - - // let the stream be modified - FillTempGetFileName(); - m_bHasDataToFlush = sal_True; - - // remove encryption - m_bForceEncrypted = sal_False; - m_bHasCachedEncryptionData = sal_False; - m_aEncryptionData.clear(); - - for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ ) - { - if ( m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) - m_aProps[nInd].Value <<= sal_False; - } -} - -//----------------------------------------------- -void OWriteStream_Impl::SetEncrypted( const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE, "The encryption is supported only for package storages!\n" ); - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - if ( !aEncryptionData.size() ) - throw uno::RuntimeException(); - - GetStreamProperties(); - - // let the stream be modified - FillTempGetFileName(); - m_bHasDataToFlush = sal_True; - - // introduce encryption info - for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ ) - { - if ( m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) - m_aProps[nInd].Value <<= sal_True; - } - - m_bUseCommonEncryption = sal_False; // very important to set it to false - - m_bHasCachedEncryptionData = sal_True; - m_aEncryptionData = aEncryptionData; -} - -//----------------------------------------------- -void OWriteStream_Impl::DisposeWrappers() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_pAntiImpl ) - { - try { - m_pAntiImpl->dispose(); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - AddLog( rRuntimeException.Message ); - AddLog( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(OSL_LOG_PREFIX "Quiet exception") ) ); - } - - m_pAntiImpl = NULL; - } - m_pParent = NULL; - - if ( !m_aInputStreamsList.empty() ) - { - for ( InputStreamsList_Impl::iterator pStreamIter = m_aInputStreamsList.begin(); - pStreamIter != m_aInputStreamsList.end(); pStreamIter++ ) - { - if ( (*pStreamIter) ) - { - (*pStreamIter)->InternalDispose(); - (*pStreamIter) = NULL; - } - } - - m_aInputStreamsList.clear(); - } -} - -//----------------------------------------------- -uno::Reference< lang::XMultiServiceFactory > OWriteStream_Impl::GetServiceFactory() -{ - if ( m_xFactory.is() ) - return m_xFactory; - - return ::comphelper::getProcessServiceFactory(); -} - -//----------------------------------------------- -::rtl::OUString OWriteStream_Impl::GetFilledTempFileIfNo( const uno::Reference< io::XInputStream >& xStream ) -{ - if ( !m_aTempURL.getLength() ) - { - ::rtl::OUString aTempURL = GetNewTempFileURL( GetServiceFactory() ); - - try { - if ( aTempURL.getLength() && xStream.is() ) - { - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( aTempURL ); - if ( xTempOutStream.is() ) - { - // the current position of the original stream should be still OK, copy further - ::comphelper::OStorageHelper::CopyInputToOutput( xStream, xTempOutStream ); - xTempOutStream->closeOutput(); - xTempOutStream = uno::Reference< io::XOutputStream >(); - } - else - throw io::IOException(); // TODO: - } - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - AddLog( rWrongPasswordException.Message ); - AddLog( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow") ) ); - - KillFile( aTempURL, GetServiceFactory() ); - throw; - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow") ) ); - - KillFile( aTempURL, GetServiceFactory() ); - throw; - } - - if ( aTempURL.getLength() ) - CleanCacheStream(); - - m_aTempURL = aTempURL; - } - - return m_aTempURL; -} - -//----------------------------------------------- -::rtl::OUString OWriteStream_Impl::FillTempGetFileName() -{ - // should try to create cache first, if the amount of contents is too big, the temp file should be taken - if ( !m_xCacheStream.is() && !m_aTempURL.getLength() ) - { - uno::Reference< io::XInputStream > xOrigStream = m_xPackageStream->getDataStream(); - if ( !xOrigStream.is() ) - { - // in case of new inserted package stream it is possible that input stream still was not set - uno::Reference< io::XStream > xCacheStream = CreateMemoryStream( GetServiceFactory() ); - OSL_ENSURE( xCacheStream.is(), "If the stream can not be created an exception must be thrown!\n" ); - m_xCacheSeek.set( xCacheStream, uno::UNO_QUERY_THROW ); - m_xCacheStream = xCacheStream; - } - else - { - sal_Int32 nRead = 0; - uno::Sequence< sal_Int8 > aData( MAX_STORCACHE_SIZE + 1 ); - nRead = xOrigStream->readBytes( aData, MAX_STORCACHE_SIZE + 1 ); - if ( aData.getLength() > nRead ) - aData.realloc( nRead ); - - if ( nRead <= MAX_STORCACHE_SIZE ) - { - uno::Reference< io::XStream > xCacheStream = CreateMemoryStream( GetServiceFactory() ); - OSL_ENSURE( xCacheStream.is(), "If the stream can not be created an exception must be thrown!\n" ); - - if ( nRead ) - { - uno::Reference< io::XOutputStream > xOutStream( xCacheStream->getOutputStream(), uno::UNO_SET_THROW ); - xOutStream->writeBytes( aData ); - } - m_xCacheSeek.set( xCacheStream, uno::UNO_QUERY_THROW ); - m_xCacheStream = xCacheStream; - m_xCacheSeek->seek( 0 ); - } - else if ( !m_aTempURL.getLength() ) - { - m_aTempURL = GetNewTempFileURL( GetServiceFactory() ); - - try { - if ( m_aTempURL.getLength() ) - { - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - - uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( m_aTempURL ); - if ( xTempOutStream.is() ) - { - // copy stream contents to the file - xTempOutStream->writeBytes( aData ); - - // the current position of the original stream should be still OK, copy further - ::comphelper::OStorageHelper::CopyInputToOutput( xOrigStream, xTempOutStream ); - xTempOutStream->closeOutput(); - xTempOutStream = uno::Reference< io::XOutputStream >(); - } - else - throw io::IOException(); // TODO: - } - } - catch( const packages::WrongPasswordException& ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - - throw; - } - catch( const uno::Exception& ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - } - } - } - } - - return m_aTempURL; -} - -//----------------------------------------------- -uno::Reference< io::XStream > OWriteStream_Impl::GetTempFileAsStream() -{ - uno::Reference< io::XStream > xTempStream; - - if ( !m_xCacheStream.is() ) - { - if ( !m_aTempURL.getLength() ) - m_aTempURL = FillTempGetFileName(); - - if ( m_aTempURL.getLength() ) - { - // the temporary file is not used if the cache is used - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - try - { - xTempStream = xTempAccess->openFileReadWrite( m_aTempURL ); - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - } - - if ( m_xCacheStream.is() ) - xTempStream = m_xCacheStream; - - // the method must always return a stream - // in case the stream can not be open - // an exception should be thrown - if ( !xTempStream.is() ) - throw io::IOException(); //TODO: - - return xTempStream; -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > OWriteStream_Impl::GetTempFileAsInputStream() -{ - uno::Reference< io::XInputStream > xInputStream; - - if ( !m_xCacheStream.is() ) - { - if ( !m_aTempURL.getLength() ) - m_aTempURL = FillTempGetFileName(); - - if ( m_aTempURL.getLength() ) - { - // the temporary file is not used if the cache is used - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - try - { - xInputStream = xTempAccess->openFileRead( m_aTempURL ); - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - } - - if ( m_xCacheStream.is() ) - xInputStream = m_xCacheStream->getInputStream(); - - // the method must always return a stream - // in case the stream can not be open - // an exception should be thrown - if ( !xInputStream.is() ) - throw io::IOException(); // TODO: - - return xInputStream; -} - -// ================================================================================================= - -//----------------------------------------------- -void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputStream >& xInStream, - const uno::Sequence< beans::PropertyValue >& aProps ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - // this call can be made only during parent storage commit - // the parent storage is responsible for the correct handling - // of deleted and renamed contents - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( m_bHasDataToFlush ) - throw io::IOException(); - - OSL_ENSURE( !m_aTempURL.getLength() && !m_xCacheStream.is(), "The temporary must not exist!\n" ); - - // use new file as current persistent representation - // the new file will be removed after it's stream is closed - m_xPackageStream->setDataStream( xInStream ); - - // copy properties to the package stream - uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - // The storage-package communication has a problem - // the storage caches properties, thus if the package changes one of them itself - // the storage does not know about it - - // Depending from MediaType value the package can change the compressed property itself - // Thus if Compressed property is provided it must be set as the latest one - sal_Bool bCompressedIsSet = sal_False; - sal_Bool bCompressed = sal_False; - ::rtl::OUString aComprPropName( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ); - ::rtl::OUString aMedTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - for ( sal_Int32 nInd = 0; nInd < aProps.getLength(); nInd++ ) - { - if ( aProps[nInd].Name.equals( aComprPropName ) ) - { - bCompressedIsSet = sal_True; - aProps[nInd].Value >>= bCompressed; - } - else if ( ( m_nStorageType == embed::StorageFormats::OFOPXML || m_nStorageType == embed::StorageFormats::PACKAGE ) - && aProps[nInd].Name.equals( aMedTypePropName ) ) - { - xPropertySet->setPropertyValue( aProps[nInd].Name, aProps[nInd].Value ); - } - else if ( m_nStorageType == embed::StorageFormats::PACKAGE && aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) ) - aProps[nInd].Value >>= m_bUseCommonEncryption; - else - throw lang::IllegalArgumentException(); - - // if there are cached properties update them - if ( aProps[nInd].Name.equals( aMedTypePropName ) || aProps[nInd].Name.equals( aComprPropName ) ) - for ( sal_Int32 nMemInd = 0; nMemInd < m_aProps.getLength(); nMemInd++ ) - { - if ( aProps[nInd].Name.equals( m_aProps[nMemInd].Name ) ) - m_aProps[nMemInd].Value = aProps[nInd].Value; - } - } - - if ( bCompressedIsSet ) - { - xPropertySet->setPropertyValue( aComprPropName, uno::makeAny( (sal_Bool)bCompressed ) ); - m_bCompressedSetExplicit = sal_True; - } - - if ( m_bUseCommonEncryption ) - { - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - // set to be encrypted but do not use encryption key - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ), - uno::makeAny( sal_True ) ); - } - - // the stream should be free soon, after package is stored - m_bHasDataToFlush = sal_False; - m_bFlushed = sal_True; // will allow to use transaction on stream level if will need it - m_bHasInsertedStreamOptimization = sal_True; -} - -//----------------------------------------------- -void OWriteStream_Impl::Commit() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( !m_bHasDataToFlush ) - return; - - uno::Reference< packages::XDataSinkEncrSupport > xNewPackageStream; - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_False; - - if ( m_xCacheStream.is() ) - { - if ( m_pAntiImpl ) - m_pAntiImpl->DeInit(); - - uno::Reference< io::XInputStream > xInStream( m_xCacheStream->getInputStream(), uno::UNO_SET_THROW ); - - xNewPackageStream = uno::Reference< packages::XDataSinkEncrSupport >( - m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY_THROW ); - - xNewPackageStream->setDataStream( xInStream ); - - m_xCacheStream = uno::Reference< io::XStream >(); - m_xCacheSeek = uno::Reference< io::XSeekable >(); - - } - else if ( m_aTempURL.getLength() ) - { - if ( m_pAntiImpl ) - m_pAntiImpl->DeInit(); - - uno::Reference< io::XInputStream > xInStream; - try - { - xInStream.set( static_cast< io::XInputStream* >( new OSelfTerminateFileStream( GetServiceFactory(), m_aTempURL ) ), uno::UNO_QUERY ); - } - catch( const uno::Exception& ) - { - } - - if ( !xInStream.is() ) - throw io::IOException(); - - xNewPackageStream = uno::Reference< packages::XDataSinkEncrSupport >( - m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY_THROW ); - - // TODO/NEW: Let the temporary file be removed after commit - xNewPackageStream->setDataStream( xInStream ); - m_aTempURL = ::rtl::OUString(); - } - else // if ( m_bHasInsertedStreamOptimization ) - { - // if the optimization is used the stream can be accessed directly - xNewPackageStream = m_xPackageStream; - } - - // copy properties to the package stream - uno::Reference< beans::XPropertySet > xPropertySet( xNewPackageStream, uno::UNO_QUERY ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ ) - { - if ( m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) - { - if ( m_pAntiImpl && !m_bHasInsertedStreamOptimization && m_pAntiImpl->m_xSeekable.is() ) - { - m_aProps[nInd].Value <<= ((sal_Int32)m_pAntiImpl->m_xSeekable->getLength()); - xPropertySet->setPropertyValue( m_aProps[nInd].Name, m_aProps[nInd].Value ); - } - } - else - xPropertySet->setPropertyValue( m_aProps[nInd].Name, m_aProps[nInd].Value ); - } - - if ( m_bUseCommonEncryption ) - { - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - // set to be encrypted but do not use encryption key - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ), - uno::makeAny( sal_True ) ); - } - else if ( m_bHasCachedEncryptionData ) - { - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( m_aEncryptionData.getAsConstNamedValueList() ) ); - } - - // the stream should be free soon, after package is stored - m_xPackageStream = xNewPackageStream; - m_bHasDataToFlush = sal_False; - m_bFlushed = sal_True; // will allow to use transaction on stream level if will need it -} - -//----------------------------------------------- -void OWriteStream_Impl::Revert() -{ - // can be called only from parent storage - // means complete reload of the stream - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( !m_bHasDataToFlush ) - return; // nothing to do - - OSL_ENSURE( m_aTempURL.getLength() || m_xCacheStream.is(), "The temporary must exist!\n" ); - - if ( m_xCacheStream.is() ) - { - m_xCacheStream = uno::Reference< io::XStream >(); - m_xCacheSeek = uno::Reference< io::XSeekable >(); - } - - if ( m_aTempURL.getLength() ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - } - - m_aProps.realloc( 0 ); - - m_bHasDataToFlush = sal_False; - - m_bUseCommonEncryption = sal_True; - m_bHasCachedEncryptionData = sal_False; - m_aEncryptionData.clear(); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - // currently the relations storage is changed only on commit - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - if ( m_xOrigRelInfoStream.is() ) - { - // the original stream is still here, that means that it was not parsed - m_aOrigRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_nRelInfoStatus = RELINFO_NO_INIT; - } - else - { - // the original stream was aready parsed - if ( !m_bOrigRelInfoBroken ) - m_nRelInfoStatus = RELINFO_READ; - else - m_nRelInfoStatus = RELINFO_BROKEN; - } - } -} - -//----------------------------------------------- -uno::Sequence< beans::PropertyValue > OWriteStream_Impl::GetStreamProperties() -{ - if ( !m_aProps.getLength() ) - m_aProps = ReadPackageStreamProperties(); - - return m_aProps; -} - -//----------------------------------------------- -uno::Sequence< beans::PropertyValue > OWriteStream_Impl::InsertOwnProps( - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Bool bUseCommonEncryption ) -{ - uno::Sequence< beans::PropertyValue > aResult( aProps ); - sal_Int32 nLen = aResult.getLength(); - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ ) - if ( aResult[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) ) - { - aResult[nInd].Value <<= bUseCommonEncryption; - return aResult; - } - - aResult.realloc( ++nLen ); - aResult[nLen - 1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption") ); - aResult[nLen - 1].Value <<= bUseCommonEncryption; - } - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - ReadRelInfoIfNecessary(); - - uno::Any aValue; - if ( m_nRelInfoStatus == RELINFO_READ ) - aValue <<= m_aOrigRelInfo; - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED ) - aValue <<= m_aNewRelInfo; - else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Wrong relinfo stream!" ) ), - uno::Reference< uno::XInterface >() ); - - for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ ) - if ( aResult[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - { - aResult[nInd].Value = aValue; - return aResult; - } - - aResult.realloc( ++nLen ); - aResult[nLen - 1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RelationsInfo") ); - aResult[nLen - 1].Value = aValue; - } - - return aResult; -} - -//----------------------------------------------- -sal_Bool OWriteStream_Impl::IsTransacted() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - return ( m_pAntiImpl && m_pAntiImpl->m_bTransacted ); -} - -void OWriteStream_Impl::ReadRelInfoIfNecessary() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return; - - if ( m_nRelInfoStatus == RELINFO_NO_INIT ) - { - try - { - // Init from original stream - if ( m_xOrigRelInfoStream.is() ) - m_aOrigRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence( - m_xOrigRelInfoStream, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/*.rels" ) ), - m_xFactory ); - - // in case of success the stream must be thrown away, that means that the OrigRelInfo is initialized - // the reason for this is that the original stream might not be seekable ( at the same time the new - // provided stream must be seekable ), so it must be read only once - m_xOrigRelInfoStream = uno::Reference< io::XInputStream >(); - m_nRelInfoStatus = RELINFO_READ; - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - m_nRelInfoStatus = RELINFO_BROKEN; - m_bOrigRelInfoBroken = sal_True; - } - } - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - // Init from the new stream - try - { - if ( m_xNewRelInfoStream.is() ) - m_aNewRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence( - m_xNewRelInfoStream, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/*.rels" ) ), - m_xFactory ); - - m_nRelInfoStatus = RELINFO_CHANGED_STREAM_READ; - } - catch( const uno::Exception& ) - { - m_nRelInfoStatus = RELINFO_CHANGED_BROKEN; - } - } -} - -//----------------------------------------------- -uno::Sequence< beans::PropertyValue > OWriteStream_Impl::ReadPackageStreamProperties() -{ - sal_Int32 nPropNum = 0; - if ( m_nStorageType == embed::StorageFormats::ZIP ) - nPropNum = 2; - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - nPropNum = 3; - else if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - nPropNum = 4; - uno::Sequence< beans::PropertyValue > aResult( nPropNum ); - - // The "Compressed" property must be set after "MediaType" property, - // since the setting of the last one can change the value of the first one - - if ( m_nStorageType == embed::StorageFormats::OFOPXML || m_nStorageType == embed::StorageFormats::PACKAGE ) - { - aResult[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType") ); - aResult[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Compressed") ); - aResult[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size") ); - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - aResult[3].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ); - } - else - { - aResult[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Compressed") ); - aResult[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size") ); - - } - - // TODO: may be also raw stream should be marked - - uno::Reference< beans::XPropertySet > xPropSet( m_xPackageStream, uno::UNO_QUERY ); - if ( xPropSet.is() ) - { - for ( sal_Int32 nInd = 0; nInd < aResult.getLength(); nInd++ ) - { - try { - aResult[nInd].Value = xPropSet->getPropertyValue( aResult[nInd].Name ); - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - OSL_FAIL( "A property can't be retrieved!\n" ); - } - } - } - else - { - OSL_FAIL( "Can not get properties from a package stream!\n" ); - throw uno::RuntimeException(); - } - - return aResult; -} - -//----------------------------------------------- -void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream >& xDestStream, - const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( !m_bUseCommonEncryption, "The stream can not be encrypted!" ); - - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException(); - - if ( m_pAntiImpl ) - { - m_pAntiImpl->CopyToStreamInternally_Impl( xDestStream ); - } - else - { - uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, aEncryptionData, sal_False ); - if ( !xOwnStream.is() ) - throw io::IOException(); // TODO - - OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() ); - } - - uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDestStream, uno::UNO_QUERY ); - if ( xEncr.is() ) - xEncr->setEncryptionData( aEncryptionData.getAsConstNamedValueList() ); -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > OWriteStream_Impl::GetAllRelationshipsIfAny() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return uno::Sequence< uno::Sequence< beans::StringPair > >(); - - ReadRelInfoIfNecessary(); - - if ( m_nRelInfoStatus == RELINFO_READ ) - return m_aOrigRelInfo; - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED ) - return m_aNewRelInfo; - else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Wrong relinfo stream!" ) ), - uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream >& xDestStream ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( m_pAntiImpl ) - { - m_pAntiImpl->CopyToStreamInternally_Impl( xDestStream ); - } - else - { - uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, sal_False ); - if ( !xOwnStream.is() ) - throw io::IOException(); // TODO - - OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() ); - } -} - -//----------------------------------------------- -uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData, sal_Bool bHierarchyAccess ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( m_pAntiImpl ) - throw io::IOException(); // TODO: - - if ( !IsEncrypted() ) - throw packages::NoEncryptionException(); - - uno::Reference< io::XStream > xResultStream; - - uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - if ( m_bHasCachedEncryptionData ) - { - if ( !::package::PackageEncryptionDatasEqual( m_aEncryptionData, aEncryptionData ) ) - throw packages::WrongPasswordException(); - - // the correct key must be set already - xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); - } - else - { - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() ); - - try { - xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); - - m_bUseCommonEncryption = sal_False; // very important to set it to false - m_bHasCachedEncryptionData = sal_True; - m_aEncryptionData = aEncryptionData; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - AddLog( rWrongPasswordException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - OSL_FAIL( "Can't write encryption related properties!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - throw io::IOException(); // TODO: - } - } - - OSL_ENSURE( xResultStream.is(), "In case stream can not be retrieved an exception must be thrown!\n" ); - - return xResultStream; -} - -//----------------------------------------------- -uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, sal_Bool bHierarchyAccess ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( m_pAntiImpl ) - throw io::IOException(); // TODO: - - uno::Reference< io::XStream > xResultStream; - - if ( IsEncrypted() ) - { - ::comphelper::SequenceAsHashMap aGlobalEncryptionData; - try - { - aGlobalEncryptionData = GetCommonRootEncryptionData(); - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - AddLog( rNoEncryptionException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw packages::WrongPasswordException(); - } - - xResultStream = GetStream( nStreamMode, aGlobalEncryptionData, bHierarchyAccess ); - } - else - xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); - - return xResultStream; -} - -//----------------------------------------------- -uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStreamMode, sal_Bool bHierarchyAccess ) -{ - // private method, no mutex is used - GetStreamProperties(); - - // TODO/LATER: this info might be read later, on demand in future - ReadRelInfoIfNecessary(); - - if ( ( nStreamMode & embed::ElementModes::READWRITE ) == embed::ElementModes::READ ) - { - uno::Reference< io::XInputStream > xInStream; - if ( m_xCacheStream.is() || m_aTempURL.getLength() ) - xInStream = GetTempFileAsInputStream(); //TODO: - else - xInStream = m_xPackageStream->getDataStream(); - - // The stream does not exist in the storage - if ( !xInStream.is() ) - throw io::IOException(); - - OInputCompStream* pStream = new OInputCompStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); - uno::Reference< io::XStream > xCompStream( - static_cast< ::cppu::OWeakObject* >( pStream ), - uno::UNO_QUERY ); - OSL_ENSURE( xCompStream.is(), - "OInputCompStream MUST provide XStream interfaces!\n" ); - - m_aInputStreamsList.push_back( pStream ); - return xCompStream; - } - else if ( ( nStreamMode & embed::ElementModes::READWRITE ) == embed::ElementModes::SEEKABLEREAD ) - { - if ( !m_xCacheStream.is() && !m_aTempURL.getLength() && !( m_xPackageStream->getDataStream().is() ) ) - { - // The stream does not exist in the storage - throw io::IOException(); - } - - uno::Reference< io::XInputStream > xInStream; - - xInStream = GetTempFileAsInputStream(); //TODO: - - if ( !xInStream.is() ) - throw io::IOException(); - - OInputSeekStream* pStream = new OInputSeekStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); - uno::Reference< io::XStream > xSeekStream( - static_cast< ::cppu::OWeakObject* >( pStream ), - uno::UNO_QUERY ); - OSL_ENSURE( xSeekStream.is(), - "OInputSeekStream MUST provide XStream interfaces!\n" ); - - m_aInputStreamsList.push_back( pStream ); - return xSeekStream; - } - else if ( ( nStreamMode & embed::ElementModes::WRITE ) == embed::ElementModes::WRITE ) - { - if ( !m_aInputStreamsList.empty() ) - throw io::IOException(); // TODO: - - uno::Reference< io::XStream > xStream; - if ( ( nStreamMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE ) - { - if ( m_aTempURL.getLength() ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - } - if ( m_xCacheStream.is() ) - CleanCacheStream(); - - m_bHasDataToFlush = sal_True; - - // this call is triggered by the parent and it will recognize the change of the state - if ( m_pParent ) - m_pParent->m_bIsModified = sal_True; - - xStream = CreateMemoryStream( GetServiceFactory() ); - m_xCacheSeek.set( xStream, uno::UNO_QUERY_THROW ); - m_xCacheStream = xStream; - } - else if ( !m_bHasInsertedStreamOptimization ) - { - if ( !m_aTempURL.getLength() && !m_xCacheStream.is() && !( m_xPackageStream->getDataStream().is() ) ) - { - // The stream does not exist in the storage - m_bHasDataToFlush = sal_True; - - // this call is triggered by the parent and it will recognize the change of the state - if ( m_pParent ) - m_pParent->m_bIsModified = sal_True; - xStream = GetTempFileAsStream(); - } - - // if the stream exists the temporary file is created on demand - // xStream = GetTempFileAsStream(); - } - - if ( !xStream.is() ) - m_pAntiImpl = new OWriteStream( this, bHierarchyAccess ); - else - m_pAntiImpl = new OWriteStream( this, xStream, bHierarchyAccess ); - - uno::Reference< io::XStream > xWriteStream = - uno::Reference< io::XStream >( static_cast< ::cppu::OWeakObject* >( m_pAntiImpl ), - uno::UNO_QUERY ); - - OSL_ENSURE( xWriteStream.is(), "OWriteStream MUST implement XStream && XComponent interfaces!\n" ); - - return xWriteStream; - } - - throw lang::IllegalArgumentException(); // TODO -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > OWriteStream_Impl::GetPlainRawInStream() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - // this method is used only internally, this stream object should not go outside of this implementation - // if ( m_pAntiImpl ) - // throw io::IOException(); // TODO: - - return m_xPackageStream->getPlainRawStream(); -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > OWriteStream_Impl::GetRawInStream() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( m_pAntiImpl ) - throw io::IOException(); // TODO: - - OSL_ENSURE( IsEncrypted(), "Impossible to get raw representation for nonencrypted stream!\n" ); - if ( !IsEncrypted() ) - throw packages::NoEncryptionException(); - - return m_xPackageStream->getRawStream(); -} - -//----------------------------------------------- -::comphelper::SequenceAsHashMap OWriteStream_Impl::GetCommonRootEncryptionData() - throw ( packages::NoEncryptionException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( m_nStorageType != embed::StorageFormats::PACKAGE || !m_pParent ) - throw packages::NoEncryptionException(); - - return m_pParent->GetCommonRootEncryptionData(); -} - -//----------------------------------------------- -void OWriteStream_Impl::InputStreamDisposed( OInputCompStream* pStream ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - m_aInputStreamsList.remove( pStream ); -} - -//----------------------------------------------- -void OWriteStream_Impl::CreateReadonlyCopyBasedOnData( const uno::Reference< io::XInputStream >& xDataToCopy, const uno::Sequence< beans::PropertyValue >& aProps, sal_Bool, uno::Reference< io::XStream >& xTargetStream ) -{ - uno::Reference < io::XStream > xTempFile; - if ( !xTargetStream.is() ) - xTempFile = uno::Reference < io::XStream >( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY ); - else - xTempFile = xTargetStream; - - uno::Reference < io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY ); - if ( !xTempSeek.is() ) - throw uno::RuntimeException(); // TODO - - uno::Reference < io::XOutputStream > xTempOut = xTempFile->getOutputStream(); - if ( !xTempOut.is() ) - throw uno::RuntimeException(); - - if ( xDataToCopy.is() ) - ::comphelper::OStorageHelper::CopyInputToOutput( xDataToCopy, xTempOut ); - - xTempOut->closeOutput(); - xTempSeek->seek( 0 ); - - uno::Reference< io::XInputStream > xInStream = xTempFile->getInputStream(); - if ( !xInStream.is() ) - throw io::IOException(); - - // TODO: remember last state of m_bUseCommonEncryption - if ( !xTargetStream.is() ) - xTargetStream = uno::Reference< io::XStream > ( - static_cast< ::cppu::OWeakObject* >( - new OInputSeekStream( xInStream, InsertOwnProps( aProps, m_bUseCommonEncryption ), m_nStorageType ) ), - uno::UNO_QUERY_THROW ); -} - -//----------------------------------------------- -void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_xPackageStream.is(), "The source stream for copying is incomplete!\n" ); - if ( !m_xPackageStream.is() ) - throw uno::RuntimeException(); - - uno::Reference< io::XInputStream > xDataToCopy; - if ( IsEncrypted() ) - { - // an encrypted stream must contain input stream - ::comphelper::SequenceAsHashMap aGlobalEncryptionData; - try - { - aGlobalEncryptionData = GetCommonRootEncryptionData(); - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - AddLog( rNoEncryptionException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Element" ) ) ); - - throw packages::WrongPasswordException(); - } - - GetCopyOfLastCommit( xTargetStream, aGlobalEncryptionData ); - } - else - { - xDataToCopy = m_xPackageStream->getDataStream(); - - // in case of new inserted package stream it is possible that input stream still was not set - GetStreamProperties(); - - CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream ); - } -} - -//----------------------------------------------- -void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream, const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_xPackageStream.is(), "The source stream for copying is incomplete!\n" ); - if ( !m_xPackageStream.is() ) - throw uno::RuntimeException(); - - if ( !IsEncrypted() ) - throw packages::NoEncryptionException(); - - uno::Reference< io::XInputStream > xDataToCopy; - - if ( m_bHasCachedEncryptionData ) - { - // TODO: introduce last commited cashed password information and use it here - // that means "use common pass" also should be remembered on flash - uno::Sequence< beans::NamedValue > aKey = aEncryptionData.getAsConstNamedValueList(); - - uno::Reference< beans::XPropertySet > xProps( m_xPackageStream, uno::UNO_QUERY ); - if ( !xProps.is() ) - throw uno::RuntimeException(); - - sal_Bool bEncr = sal_False; - xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) ) >>= bEncr; - if ( !bEncr ) - throw packages::NoEncryptionException(); - - uno::Sequence< beans::NamedValue > aPackKey; - xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) >>= aPackKey; - if ( !SequencesEqual( aKey, aPackKey ) ) - throw packages::WrongPasswordException(); - - // the correct key must be set already - xDataToCopy = m_xPackageStream->getDataStream(); - } - else - { - uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY ); - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() ); - - try { - xDataToCopy = m_xPackageStream->getDataStream(); - - if ( !xDataToCopy.is() ) - { - OSL_FAIL( "Encrypted ZipStream must already have input stream inside!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - } - } - catch( const uno::Exception& rException ) - { - OSL_FAIL( "Can't open encrypted stream!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - } - - // in case of new inserted package stream it is possible that input stream still was not set - GetStreamProperties(); - - CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream ); -} - -//----------------------------------------------- -void OWriteStream_Impl::CommitStreamRelInfo( const uno::Reference< embed::XStorage >& xRelStorage, const ::rtl::OUString& aOrigStreamName, const ::rtl::OUString& aNewStreamName ) -{ - // at this point of time the old stream must be already cleaned - OSL_ENSURE( m_nStorageType == embed::StorageFormats::OFOPXML, "The method should be used only with OFOPXML format!\n" ); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - OSL_ENSURE( aOrigStreamName.getLength() && aNewStreamName.getLength() && xRelStorage.is(), - "Wrong relation persistence information is provided!\n" ); - - if ( !xRelStorage.is() || !aOrigStreamName.getLength() || !aNewStreamName.getLength() ) - throw uno::RuntimeException(); - - if ( m_nRelInfoStatus == RELINFO_BROKEN || m_nRelInfoStatus == RELINFO_CHANGED_BROKEN ) - throw io::IOException(); // TODO: - - ::rtl::OUString aOrigRelStreamName = aOrigStreamName; - aOrigRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ); - - ::rtl::OUString aNewRelStreamName = aNewStreamName; - aNewRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ); - - sal_Bool bRenamed = !aOrigRelStreamName.equals( aNewRelStreamName ); - if ( m_nRelInfoStatus == RELINFO_CHANGED - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - if ( bRenamed && xRelStorage->hasByName( aOrigRelStreamName ) ) - xRelStorage->removeElement( aOrigRelStreamName ); - - if ( m_nRelInfoStatus == RELINFO_CHANGED ) - { - if ( m_aNewRelInfo.getLength() ) - { - uno::Reference< io::XStream > xRelsStream = - xRelStorage->openStreamElement( aNewRelStreamName, - embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE ); - - uno::Reference< io::XOutputStream > xOutStream = xRelsStream->getOutputStream(); - if ( !xOutStream.is() ) - throw uno::RuntimeException(); - - ::comphelper::OFOPXMLHelper::WriteRelationsInfoSequence( xOutStream, m_aNewRelInfo, m_xFactory ); - - // set the mediatype - uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW ); - xPropSet->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), - uno::makeAny( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) ); - - m_nRelInfoStatus = RELINFO_READ; - } - } - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - uno::Reference< io::XStream > xRelsStream = - xRelStorage->openStreamElement( aNewRelStreamName, - embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE ); - - uno::Reference< io::XOutputStream > xOutputStream = xRelsStream->getOutputStream(); - if ( !xOutputStream.is() ) - throw uno::RuntimeException(); - - uno::Reference< io::XSeekable > xSeek( m_xNewRelInfoStream, uno::UNO_QUERY_THROW ); - xSeek->seek( 0 ); - ::comphelper::OStorageHelper::CopyInputToOutput( m_xNewRelInfoStream, xOutputStream ); - xSeek->seek( 0 ); - - // set the mediatype - uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW ); - xPropSet->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), - uno::makeAny( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) ); - - if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - m_nRelInfoStatus = RELINFO_NO_INIT; - else - { - // the information is already parsed and the stream is stored, no need in temporary stream any more - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_nRelInfoStatus = RELINFO_READ; - } - } - - // the original stream makes no sence after this step - m_xOrigRelInfoStream = m_xNewRelInfoStream; - m_aOrigRelInfo = m_aNewRelInfo; - m_bOrigRelInfoBroken = sal_False; - m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - } - else - { - // the stream is not changed but it might be renamed - if ( bRenamed && xRelStorage->hasByName( aOrigRelStreamName ) ) - xRelStorage->renameElement( aOrigRelStreamName, aNewRelStreamName ); - } - } -} - -//=============================================== -// OWriteStream implementation -//=============================================== - -//----------------------------------------------- -OWriteStream::OWriteStream( OWriteStream_Impl* pImpl, sal_Bool bTransacted ) -: m_pImpl( pImpl ) -, m_bInStreamDisconnected( sal_False ) -, m_bInitOnDemand( sal_True ) -, m_nInitPosition( 0 ) -, m_bTransacted( bTransacted ) -{ - OSL_ENSURE( pImpl, "No base implementation!\n" ); - OSL_ENSURE( m_pImpl->m_rMutexRef.Is(), "No mutex!\n" ); - - if ( !m_pImpl || !m_pImpl->m_rMutexRef.Is() ) - throw uno::RuntimeException(); // just a disaster - - m_pData = new WSInternalData_Impl( pImpl->m_rMutexRef, m_pImpl->m_nStorageType ); -} - -//----------------------------------------------- -OWriteStream::OWriteStream( OWriteStream_Impl* pImpl, uno::Reference< io::XStream > xStream, sal_Bool bTransacted ) -: m_pImpl( pImpl ) -, m_bInStreamDisconnected( sal_False ) -, m_bInitOnDemand( sal_False ) -, m_nInitPosition( 0 ) -, m_bTransacted( bTransacted ) -{ - OSL_ENSURE( pImpl && xStream.is(), "No base implementation!\n" ); - OSL_ENSURE( m_pImpl->m_rMutexRef.Is(), "No mutex!\n" ); - - if ( !m_pImpl || !m_pImpl->m_rMutexRef.Is() ) - throw uno::RuntimeException(); // just a disaster - - m_pData = new WSInternalData_Impl( pImpl->m_rMutexRef, m_pImpl->m_nStorageType ); - - if ( xStream.is() ) - { - m_xInStream = xStream->getInputStream(); - m_xOutStream = xStream->getOutputStream(); - m_xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY ); - OSL_ENSURE( m_xInStream.is() && m_xOutStream.is() && m_xSeekable.is(), "Stream implementation is incomplete!\n" ); - } -} - -//----------------------------------------------- -OWriteStream::~OWriteStream() -{ - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - if ( m_pImpl ) - { - m_refCount++; - try { - dispose(); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - } - - if ( m_pData && m_pData->m_pTypeCollection ) - delete m_pData->m_pTypeCollection; - - if ( m_pData ) - delete m_pData; -} - -//----------------------------------------------- -void OWriteStream::DeInit() -{ - if ( !m_pImpl ) - return; // do nothing - - if ( m_xSeekable.is() ) - m_nInitPosition = m_xSeekable->getPosition(); - - m_xInStream = uno::Reference< io::XInputStream >(); - m_xOutStream = uno::Reference< io::XOutputStream >(); - m_xSeekable = uno::Reference< io::XSeekable >(); - m_bInitOnDemand = sal_True; -} - -//----------------------------------------------- -void OWriteStream::CheckInitOnDemand() -{ - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_bInitOnDemand ) - { - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::CheckInitOnDemand, initializing" ); - uno::Reference< io::XStream > xStream = m_pImpl->GetTempFileAsStream(); - if ( xStream.is() ) - { - m_xInStream.set( xStream->getInputStream(), uno::UNO_SET_THROW ); - m_xOutStream.set( xStream->getOutputStream(), uno::UNO_SET_THROW ); - m_xSeekable.set( xStream, uno::UNO_QUERY_THROW ); - m_xSeekable->seek( m_nInitPosition ); - - m_nInitPosition = 0; - m_bInitOnDemand = sal_False; - } - } -} - -//----------------------------------------------- -void OWriteStream::CopyToStreamInternally_Impl( const uno::Reference< io::XStream >& xDest ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_xInStream.is() ) - throw uno::RuntimeException(); - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - uno::Reference< beans::XPropertySet > xDestProps( xDest, uno::UNO_QUERY ); - if ( !xDestProps.is() ) - throw uno::RuntimeException(); //TODO - - uno::Reference< io::XOutputStream > xDestOutStream = xDest->getOutputStream(); - if ( !xDestOutStream.is() ) - throw io::IOException(); // TODO - - sal_Int64 nCurPos = m_xSeekable->getPosition(); - m_xSeekable->seek( 0 ); - - uno::Exception eThrown; - sal_Bool bThrown = sal_False; - try { - ::comphelper::OStorageHelper::CopyInputToOutput( m_xInStream, xDestOutStream ); - } - catch ( const uno::Exception& e ) - { - eThrown = e; - bThrown = sal_True; - } - - // position-related section below is critical - // if it fails the stream will become invalid - try { - m_xSeekable->seek( nCurPos ); - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - // TODO: set the stoream in invalid state or dispose - OSL_FAIL( "The stream become invalid during copiing!\n" ); - throw uno::RuntimeException(); - } - - if ( bThrown ) - throw eThrown; - - // now the properties can be copied - // the order of the properties setting is not important for StorageStream API - ::rtl::OUString aPropName (RTL_CONSTASCII_USTRINGPARAM("Compressed") ); - xDestProps->setPropertyValue( aPropName, getPropertyValue( aPropName ) ); - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE || m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - aPropName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType" ) ); - xDestProps->setPropertyValue( aPropName, getPropertyValue( aPropName ) ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - aPropName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption") ); - xDestProps->setPropertyValue( aPropName, getPropertyValue( aPropName ) ); - } - } -} - -//----------------------------------------------- -void OWriteStream::ModifyParentUnlockMutex_Impl( ::osl::ResettableMutexGuard& aGuard ) -{ - if ( m_pImpl->m_pParent ) - { - if ( m_pImpl->m_pParent->m_pAntiImpl ) - { - uno::Reference< util::XModifiable > xParentModif( (util::XModifiable*)(m_pImpl->m_pParent->m_pAntiImpl) ); - aGuard.clear(); - xParentModif->setModified( sal_True ); - } - else - m_pImpl->m_pParent->m_bIsModified = sal_True; - } -} - -//----------------------------------------------- -uno::Any SAL_CALL OWriteStream::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - uno::Any aReturn; - - // common interfaces - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<lang::XTypeProvider*> ( this ) - , static_cast<io::XInputStream*> ( this ) - , static_cast<io::XOutputStream*> ( this ) - , static_cast<io::XStream*> ( this ) - , static_cast<embed::XExtendedStorageStream*> ( this ) - , static_cast<io::XSeekable*> ( this ) - , static_cast<io::XTruncate*> ( this ) - , static_cast<lang::XComponent*> ( this ) - , static_cast<beans::XPropertySet*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XEncryptionProtectedSource2*> ( this ) - , static_cast<embed::XEncryptionProtectedSource*> ( this ) ); - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XRelationshipAccess*> ( this ) ); - } - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - if ( m_bTransacted ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XTransactedObject*> ( this ) - , static_cast<embed::XTransactionBroadcaster*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - } - - return OWeakObject::queryInterface( rType ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::acquire() throw() -{ - OWeakObject::acquire(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::release() throw() -{ - OWeakObject::release(); -} - -//----------------------------------------------- -uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes() - throw( uno::RuntimeException ) -{ - if ( m_pData->m_pTypeCollection == NULL ) - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( m_pData->m_pTypeCollection == NULL ) - { - if ( m_bTransacted ) - { - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - ::cppu::OTypeCollection aTmpCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) ); - - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) - , aTmpCollection.getTypes() ); - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else // if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - } - else - { - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else // if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - } - } - } - - return m_pData->m_pTypeCollection->getTypes() ; -} - -namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } - -//----------------------------------------------- -uno::Sequence< sal_Int8 > SAL_CALL OWriteStream::getImplementationId() - throw( uno::RuntimeException ) -{ - ::cppu::OImplementationId &rId = lcl_ImplId::get(); - return rId.getImplementationId(); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OWriteStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xInStream.is() ) - throw io::NotConnectedException(); - - return m_xInStream->readBytes( aData, nBytesToRead ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OWriteStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xInStream.is() ) - throw io::NotConnectedException(); - - return m_xInStream->readSomeBytes( aData, nMaxBytesToRead ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::skipBytes( sal_Int32 nBytesToSkip ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xInStream.is() ) - throw io::NotConnectedException(); - - m_xInStream->skipBytes( nBytesToSkip ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OWriteStream::available( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xInStream.is() ) - throw io::NotConnectedException(); - - return m_xInStream->available(); - -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::closeInput( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bInitOnDemand && ( m_bInStreamDisconnected || !m_xInStream.is() ) ) - throw io::NotConnectedException(); - - // the input part of the stream stays open for internal purposes ( to allow reading during copiing ) - // since it can not be reopened until output part is closed, it will be closed with output part. - m_bInStreamDisconnected = sal_True; - // m_xInStream->closeInput(); - // m_xInStream = uno::Reference< io::XInputStream >(); - - if ( !m_xOutStream.is() ) - dispose(); -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OWriteStream::getInputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bInitOnDemand && ( m_bInStreamDisconnected || !m_xInStream.is() ) ) - return uno::Reference< io::XInputStream >(); - - return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY ); -} - -//----------------------------------------------- -uno::Reference< io::XOutputStream > SAL_CALL OWriteStream::getOutputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xOutStream.is() ) - return uno::Reference< io::XOutputStream >(); - - return uno::Reference< io::XOutputStream >( static_cast< io::XOutputStream* >( this ), uno::UNO_QUERY ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::writeBytes( const uno::Sequence< sal_Int8 >& aData ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - // the write method makes initialization itself, since it depends from the aData length - // NO CheckInitOnDemand()! - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bInitOnDemand ) - { - if ( !m_xOutStream.is() || !m_xSeekable.is()) - throw io::NotConnectedException(); - - if ( m_pImpl->m_xCacheStream.is() ) - { - // check whether the cache should be turned off - sal_Int64 nPos = m_xSeekable->getPosition(); - if ( nPos + aData.getLength() > MAX_STORCACHE_SIZE ) - { - // disconnect the cache and copy the data to the temporary file - m_xSeekable->seek( 0 ); - - // it is enough to copy the cached stream, the cache should already contain everything - if ( m_pImpl->GetFilledTempFileIfNo( m_xInStream ).getLength() ) - { - DeInit(); - // the last position is known and it is differs from the current stream position - m_nInitPosition = nPos; - } - } - } - } - - if ( m_bInitOnDemand ) - { - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::CheckInitOnDemand, initializing" ); - uno::Reference< io::XStream > xStream = m_pImpl->GetTempFileAsStream(); - if ( xStream.is() ) - { - m_xInStream.set( xStream->getInputStream(), uno::UNO_SET_THROW ); - m_xOutStream.set( xStream->getOutputStream(), uno::UNO_SET_THROW ); - m_xSeekable.set( xStream, uno::UNO_QUERY_THROW ); - m_xSeekable->seek( m_nInitPosition ); - - m_nInitPosition = 0; - m_bInitOnDemand = sal_False; - } - } - - - if ( !m_xOutStream.is() ) - throw io::NotConnectedException(); - - m_xOutStream->writeBytes( aData ); - m_pImpl->m_bHasDataToFlush = sal_True; - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::flush() - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - // In case stream is flushed it's current version becomes visible - // to the parent storage. Usually parent storage flushes the stream - // during own commit but a user can explicitly flush the stream - // so the changes will be available through cloning functionality. - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bInitOnDemand ) - { - if ( !m_xOutStream.is() ) - throw io::NotConnectedException(); - - m_xOutStream->flush(); - m_pImpl->Commit(); - } -} - -//----------------------------------------------- -void OWriteStream::CloseOutput_Impl() -{ - // all the checks must be done in calling method - - m_xOutStream->closeOutput(); - m_xOutStream = uno::Reference< io::XOutputStream >(); - - if ( !m_bInitOnDemand ) - { - // after the stream is disposed it can be commited - // so transport correct size property - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( m_pImpl->m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) - m_pImpl->m_aProps[nInd].Value <<= ((sal_Int32)m_xSeekable->getLength()); - } - } -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::closeOutput() - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xOutStream.is() ) - throw io::NotConnectedException(); - - CloseOutput_Impl(); - - if ( m_bInStreamDisconnected || !m_xInStream.is() ) - dispose(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::seek( sal_Int64 location ) - throw ( lang::IllegalArgumentException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - m_xSeekable->seek( location ); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OWriteStream::getPosition() - throw ( io::IOException, - uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return m_xSeekable->getPosition(); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OWriteStream::getLength() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return m_xSeekable->getLength(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::truncate() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xOutStream.is() ) - throw uno::RuntimeException(); - - uno::Reference< io::XTruncate > xTruncate( m_xOutStream, uno::UNO_QUERY ); - - if ( !xTruncate.is() ) - { - OSL_FAIL( "The output stream must support XTruncate interface!\n" ); - throw uno::RuntimeException(); - } - - xTruncate->truncate(); - - m_pImpl->m_bHasDataToFlush = sal_True; - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::dispose() - throw ( uno::RuntimeException ) -{ - // should be an internal method since it can be called only from parent storage - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_xOutStream.is() ) - CloseOutput_Impl(); - - if ( m_xInStream.is() ) - { - m_xInStream->closeInput(); - m_xInStream = uno::Reference< io::XInputStream >(); - } - - m_xSeekable = uno::Reference< io::XSeekable >(); - - m_pImpl->m_pAntiImpl = NULL; - - if ( !m_bInitOnDemand ) - { - try - { - if ( !m_bTransacted ) - { - m_pImpl->Commit(); - } - else - { - // throw away all the changes - m_pImpl->Revert(); - } - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not commit/revert the storage!\n") ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - } - - m_pImpl = NULL; - } - - // the listener might try to get rid of parent storage, and the storage would delete this object; - // for now the listener is just notified at the end of the method to workaround the problem - // in future a more elegant way should be found - - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - m_pData->m_aListenersContainer.disposeAndClear( aSource ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::addEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), - xListener ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), - xListener ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::setEncryptionPassword( const ::rtl::OUString& aPass ) - throw ( uno::RuntimeException, - io::IOException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" ); - - m_pImpl->SetEncrypted( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeEncryption() - throw ( uno::RuntimeException, - io::IOException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" ); - - m_pImpl->SetDecrypted(); - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" ); - - m_pImpl->SetEncrypted( aEncryptionData ); - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -sal_Bool SAL_CALL OWriteStream::hasByID( const ::rtl::OUString& sID ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - try - { - getRelationshipByID( sID ); - return sal_True; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Element" ) ) ); - } - - return sal_False; -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OWriteStream::getTargetByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Target" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OWriteStream::getTypeByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -uno::Sequence< beans::StringPair > SAL_CALL OWriteStream::getRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - return aSeq[nInd1]; - break; - } - - throw container::NoSuchElementException(); -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OWriteStream::getRelationshipsByType( const ::rtl::OUString& sType ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< uno::Sequence< beans::StringPair > > aResult; - sal_Int32 nEntriesNum = 0; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sType ) ) - { - aResult.realloc( nEntriesNum ); - aResult[nEntriesNum-1] = aSeq[nInd1]; - } - break; - } - - return aResult; -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OWriteStream::getAllRelationships() - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - return m_pImpl->GetAllRelationshipsIfAny(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::insertRelationshipByID( const ::rtl::OUString& sID, const uno::Sequence< beans::StringPair >& aEntry, ::sal_Bool bReplace ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) ); - - sal_Int32 nIDInd = -1; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equals( aIDTag ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - nIDInd = nInd1; - - break; - } - - if ( nIDInd == -1 || bReplace ) - { - if ( nIDInd == -1 ) - { - nIDInd = aSeq.getLength(); - aSeq.realloc( nIDInd + 1 ); - } - - aSeq[nIDInd].realloc( aEntry.getLength() + 1 ); - - aSeq[nIDInd][0].First = aIDTag; - aSeq[nIDInd][0].Second = sID; - sal_Int32 nIndTarget = 1; - for ( sal_Int32 nIndOrig = 0; - nIndOrig < aEntry.getLength(); - nIndOrig++ ) - { - if ( !aEntry[nIndOrig].First.equals( aIDTag ) ) - aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig]; - } - - aSeq[nIDInd].realloc( nIndTarget ); - } - else - throw container::ElementExistException(); // TODO - - - m_pImpl->m_aNewRelInfo = aSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - { - sal_Int32 nLength = aSeq.getLength(); - aSeq[nInd1] = aSeq[nLength-1]; - aSeq.realloc( nLength - 1 ); - - m_pImpl->m_aNewRelInfo = aSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; - - // TODO/LATER: in future the unification of the ID could be checked - return; - } - - break; - } - - throw container::NoSuchElementException(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::insertRelationships( const uno::Sequence< uno::Sequence< beans::StringPair > >& aEntries, ::sal_Bool bReplace ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) ); - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - uno::Sequence< uno::Sequence< beans::StringPair > > aResultSeq( aSeq.getLength() + aEntries.getLength() ); - sal_Int32 nResultInd = 0; - - for ( sal_Int32 nIndTarget1 = 0; nIndTarget1 < aSeq.getLength(); nIndTarget1++ ) - for ( sal_Int32 nIndTarget2 = 0; nIndTarget2 < aSeq[nIndTarget1].getLength(); nIndTarget2++ ) - if ( aSeq[nIndTarget1][nIndTarget2].First.equals( aIDTag ) ) - { - sal_Int32 nIndSourceSame = -1; - - for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ ) - for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ ) - { - if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) ) - { - if ( aEntries[nIndSource1][nIndSource2].Second.equals( aSeq[nIndTarget1][nIndTarget2].Second ) ) - { - if ( !bReplace ) - throw container::ElementExistException(); - - nIndSourceSame = nIndSource1; - } - - break; - } - } - - if ( nIndSourceSame == -1 ) - { - // no such element in the provided sequence - aResultSeq[nResultInd++] = aSeq[nIndTarget1]; - } - - break; - } - - for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ ) - { - aResultSeq[nResultInd].realloc( aEntries[nIndSource1].getLength() ); - sal_Bool bHasID = sal_False; - sal_Int32 nResInd2 = 1; - - for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ ) - if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) ) - { - aResultSeq[nResultInd][0] = aEntries[nIndSource1][nIndSource2]; - bHasID = sal_True; - } - else if ( nResInd2 < aResultSeq[nResultInd].getLength() ) - aResultSeq[nResultInd][nResInd2++] = aEntries[nIndSource1][nIndSource2]; - else - throw io::IOException(); // TODO: illegal relation ( no ID ) - - if ( !bHasID ) - throw io::IOException(); // TODO: illegal relations - - nResultInd++; - } - - aResultSeq.realloc( nResultInd ); - m_pImpl->m_aNewRelInfo = aResultSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::clearRelationships() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - m_pImpl->m_aNewRelInfo.realloc( 0 ); - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -uno::Reference< beans::XPropertySetInfo > SAL_CALL OWriteStream::getPropertySetInfo() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - //TODO: - return uno::Reference< beans::XPropertySetInfo >(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) - throw ( beans::UnknownPropertyException, - beans::PropertyVetoException, - lang::IllegalArgumentException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - m_pImpl->GetStreamProperties(); - ::rtl::OUString aCompressedString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ); - ::rtl::OUString aMediaTypeString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && aPropertyName.equals( aMediaTypeString ) ) - { - // if the "Compressed" property is not set explicitly, the MediaType can change the default value - sal_Bool bCompressedValueFromType = sal_True; - ::rtl::OUString aType; - aValue >>= aType; - - if ( !m_pImpl->m_bCompressedSetExplicit ) - { - if ( aType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/jpeg" ) ) ) - || aType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) ) ) - || aType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/gif" ) ) ) ) - bCompressedValueFromType = sal_False; - } - - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) ) - m_pImpl->m_aProps[nInd].Value = aValue; - else if ( !m_pImpl->m_bCompressedSetExplicit && aCompressedString.equals( m_pImpl->m_aProps[nInd].Name ) ) - m_pImpl->m_aProps[nInd].Value <<= bCompressedValueFromType; - } - } - else if ( aPropertyName.equals( aCompressedString ) ) - { - // if the "Compressed" property is not set explicitly, the MediaType can change the default value - m_pImpl->m_bCompressedSetExplicit = sal_True; - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) ) - m_pImpl->m_aProps[nInd].Value = aValue; - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) ) - { - sal_Bool bUseCommonEncryption = sal_False; - if ( aValue >>= bUseCommonEncryption ) - { - if ( m_bInitOnDemand && m_pImpl->m_bHasInsertedStreamOptimization ) - { - // the data stream is provided to the packagestream directly - m_pImpl->m_bUseCommonEncryption = bUseCommonEncryption; - } - else if ( bUseCommonEncryption ) - { - if ( !m_pImpl->m_bUseCommonEncryption ) - { - m_pImpl->SetDecrypted(); - m_pImpl->m_bUseCommonEncryption = sal_True; - } - } - else - m_pImpl->m_bUseCommonEncryption = sal_False; - } - else - throw lang::IllegalArgumentException(); //TODO - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName.equals( aMediaTypeString ) ) - { - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) ) - m_pImpl->m_aProps[nInd].Value = aValue; - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfoStream" ) ) ) - { - uno::Reference< io::XInputStream > xInRelStream; - if ( ( aValue >>= xInRelStream ) && xInRelStream.is() ) - { - uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY ); - if ( !xSeek.is() ) - { - // currently this is an internal property that is used for optimization - // and the stream must support XSeekable interface - // TODO/LATER: in future it can be changed if property is used from outside - throw lang::IllegalArgumentException(); // TODO - } - - m_pImpl->m_xNewRelInfoStream = xInRelStream; - m_pImpl->m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM; - } - else - throw lang::IllegalArgumentException(); // TODO - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - { - if ( aValue >>= m_pImpl->m_aNewRelInfo ) - { - } - else - throw lang::IllegalArgumentException(); // TODO - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) - throw beans::PropertyVetoException(); // TODO - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsEncrypted" ) ) || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) ) - throw beans::PropertyVetoException(); // TODO - else - throw beans::UnknownPropertyException(); // TODO - - m_pImpl->m_bHasDataToFlush = sal_True; - ModifyParentUnlockMutex_Impl( aGuard ); -} - - -//----------------------------------------------- -uno::Any SAL_CALL OWriteStream::getPropertyValue( const ::rtl::OUString& aProp ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( aProp.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelId" ) ) ) - { - return uno::makeAny( m_pImpl->GetNewRelId() ); - } - - ::rtl::OUString aPropertyName; - if ( aProp.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsEncrypted" ) ) ) - aPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ); - else - aPropertyName = aProp; - - if ( ( ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE || m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - || ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Compressed" ) ) ) - { - m_pImpl->GetStreamProperties(); - - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) ) - return m_pImpl->m_aProps[nInd].Value; - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) ) - return uno::makeAny( m_pImpl->m_bUseCommonEncryption ); - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) - { - CheckInitOnDemand(); - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return uno::makeAny( (sal_Int32)m_xSeekable->getLength() ); - } - - throw beans::UnknownPropertyException(); // TODO -} - - -//----------------------------------------------- -void SAL_CALL OWriteStream::addPropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OWriteStream::removePropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OWriteStream::addVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - -//____________________________________________________________________________________________________ -// XTransactedObject -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void OWriteStream::BroadcastTransaction( sal_Int8 nMessage ) -/* - 1 - preCommit - 2 - commited - 3 - preRevert - 4 - reverted -*/ -{ - // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - - ::cppu::OInterfaceContainerHelper* pContainer = - m_pData->m_aListenersContainer.getContainer( - ::getCppuType( ( const uno::Reference< embed::XTransactionListener >*) NULL ) ); - if ( pContainer ) - { - ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); - while ( pIterator.hasMoreElements( ) ) - { - OSL_ENSURE( nMessage >= 1 && nMessage <= 4, "Wrong internal notification code is used!\n" ); - - switch( nMessage ) - { - case STOR_MESS_PRECOMMIT: - ( ( embed::XTransactionListener* )pIterator.next( ) )->preCommit( aSource ); - break; - case STOR_MESS_COMMITED: - ( ( embed::XTransactionListener* )pIterator.next( ) )->commited( aSource ); - break; - case STOR_MESS_PREREVERT: - ( ( embed::XTransactionListener* )pIterator.next( ) )->preRevert( aSource ); - break; - case STOR_MESS_REVERTED: - ( ( embed::XTransactionListener* )pIterator.next( ) )->reverted( aSource ); - break; - } - } - } -} -//----------------------------------------------- -void SAL_CALL OWriteStream::commit() - throw ( io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::commit" ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bTransacted ) - throw uno::RuntimeException(); - - try { - BroadcastTransaction( STOR_MESS_PRECOMMIT ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - m_pImpl->Commit(); - - // when the storage is commited the parent is modified - ModifyParentUnlockMutex_Impl( aGuard ); - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Problems on commit!") ), - uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), - aCaught ); - } - - BroadcastTransaction( STOR_MESS_COMMITED ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::revert() - throw ( io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::revert" ); - - // the method removes all the changes done after last commit - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bTransacted ) - throw uno::RuntimeException(); - - BroadcastTransaction( STOR_MESS_PREREVERT ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - try { - m_pImpl->Revert(); - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Problems on revert!") ), - uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), - aCaught ); - } - - aGuard.clear(); - - BroadcastTransaction( STOR_MESS_REVERTED ); -} - -//____________________________________________________________________________________________________ -// XTransactionBroadcaster -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OWriteStream::addTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bTransacted ) - throw uno::RuntimeException(); - - m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0), - aListener ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bTransacted ) - throw uno::RuntimeException(); - - m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0), - aListener ); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/owriteablestream.hxx b/package/source/xstor/owriteablestream.hxx deleted file mode 100644 index ab5a2c07f..000000000 --- a/package/source/xstor/owriteablestream.hxx +++ /dev/null @@ -1,419 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _WRITESTREAM_HXX_ -#define _WRITESTREAM_HXX_ - -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XTruncate.hpp> -#include <com/sun/star/packages/XDataSinkEncrSupport.hpp> -#include <com/sun/star/packages/NoEncryptionException.hpp> -#include <com/sun/star/lang/XEventListener.hpp> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp> -#include <com/sun/star/embed/XStorage.hpp> -#include <com/sun/star/embed/XRelationshipAccess.hpp> -#include <com/sun/star/embed/XExtendedStorageStream.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/embed/XTransactionBroadcaster.hpp> -#include <com/sun/star/container/XNameContainer.hpp> -#include <com/sun/star/beans/StringPair.hpp> -#include <com/sun/star/logging/XSimpleLogRing.hpp> - - -#include <cppuhelper/implbase1.hxx> -#include <cppuhelper/weak.hxx> -#include <cppuhelper/interfacecontainer.h> - -#include <comphelper/sequenceashashmap.hxx> - -#include <list> - -#include "ocompinstream.hxx" -#include "mutexholder.hxx" - - -struct PreCreationStruct -{ - SotMutexHolderRef m_rMutexRef; - - PreCreationStruct() - : m_rMutexRef( new SotMutexHolder ) - {} - -}; - -namespace cppu { - class OTypeCollection; -} - -namespace package { - void StaticAddLog( const ::rtl::OUString& aMessage ); - bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, const ::comphelper::SequenceAsHashMap& aHash2 ); -} - -struct WSInternalData_Impl -{ - SotMutexHolderRef m_rSharedMutexRef; - ::cppu::OTypeCollection* m_pTypeCollection; - ::cppu::OMultiTypeInterfaceContainerHelper m_aListenersContainer; // list of listeners - sal_Int32 m_nStorageType; - - // the mutex reference MUST NOT be empty - WSInternalData_Impl( const SotMutexHolderRef rMutexRef, sal_Int32 nStorageType ) - : m_rSharedMutexRef( rMutexRef ) - , m_pTypeCollection( NULL ) - , m_aListenersContainer( rMutexRef->GetMutex() ) - , m_nStorageType( nStorageType ) - {} -}; - -typedef ::std::list< OInputCompStream* > InputStreamsList_Impl; - -struct OStorage_Impl; -class OWriteStream; - -struct OWriteStream_Impl : public PreCreationStruct -{ - friend struct OStorage_Impl; - friend class OWriteStream; - friend class OInputCompStream; - - OWriteStream* m_pAntiImpl; - ::rtl::OUString m_aTempURL; - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xCacheStream; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xCacheSeek; - - InputStreamsList_Impl m_aInputStreamsList; - - sal_Bool m_bHasDataToFlush; // only modified elements will be sent to the original content - sal_Bool m_bFlushed; // sending the streams is coordinated by the root storage of the package - - ::com::sun::star::uno::Reference< ::com::sun::star::packages::XDataSinkEncrSupport > m_xPackageStream; - ::com::sun::star::uno::Reference< ::com::sun::star::logging::XSimpleLogRing > m_xLogRing; - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - - OStorage_Impl* m_pParent; - - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aProps; - - sal_Bool m_bForceEncrypted; - - sal_Bool m_bUseCommonEncryption; - sal_Bool m_bHasCachedEncryptionData; - ::comphelper::SequenceAsHashMap m_aEncryptionData; - - sal_Bool m_bCompressedSetExplicit; - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > m_xPackage; - - sal_Bool m_bHasInsertedStreamOptimization; - - sal_Int32 m_nStorageType; - - // Relations info related data, stored in *.rels file in OFOPXML format - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xOrigRelInfoStream; - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aOrigRelInfo; - sal_Bool m_bOrigRelInfoBroken; - - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aNewRelInfo; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xNewRelInfoStream; - sal_Int16 m_nRelInfoStatus; - sal_Int32 m_nRelId; - - -private: - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > GetServiceFactory(); - - ::rtl::OUString GetFilledTempFileIfNo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream ); - ::rtl::OUString FillTempGetFileName(); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetTempFileAsStream(); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetTempFileAsInputStream(); - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream_Impl( sal_Int32 nStreamMode, - sal_Bool bHierarchyAccess ); - - ::comphelper::SequenceAsHashMap GetCommonRootEncryptionData() throw ( ::com::sun::star::packages::NoEncryptionException ); - - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > ReadPackageStreamProperties(); - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > InsertOwnProps( - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Bool bUseCommonEncryption ); - -public: - OWriteStream_Impl( - OStorage_Impl* pParent, - const ::com::sun::star::uno::Reference< ::com::sun::star::packages::XDataSinkEncrSupport >& xPackageStream, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >& xPackage, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, - sal_Bool bForceEncrypted, - sal_Int32 nStorageType, - sal_Bool bDefaultCompress, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xRelInfoStream = - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >() ); - - ~OWriteStream_Impl(); - - void CleanCacheStream(); - - void AddLog( const ::rtl::OUString& aMessage ); - - sal_Bool UsesCommonEncryption_Impl() { return m_bUseCommonEncryption; } - sal_Bool HasTempFile_Impl() const { return ( m_aTempURL.getLength() != 0 ); } - sal_Bool IsTransacted(); - - sal_Bool HasWriteOwner_Impl() const { return ( m_pAntiImpl != NULL ); } - - void InsertIntoPackageFolder( - const ::rtl::OUString& aName, - const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xParentPackageFolder ); - - void SetToBeCommited() { m_bFlushed = sal_True; } - - sal_Bool HasCachedEncryptionData() { return m_bHasCachedEncryptionData; } - ::comphelper::SequenceAsHashMap& GetCachedEncryptionData() { return m_aEncryptionData; } - - sal_Bool IsModified() { return m_bHasDataToFlush || m_bFlushed; } - - sal_Bool IsEncrypted(); - void SetDecrypted(); - void SetEncrypted( const ::comphelper::SequenceAsHashMap& aEncryptionData ); - - void DisposeWrappers(); - - void InsertStreamDirectly( - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps ); - - void Commit(); - void Revert(); - - void Free( sal_Bool bMust ); // allows to try to disconnect from the temporary stream - // in case bMust is set to sal_True the method - // will throw exception in case the file is still busy - - void SetModified(); // can be done only by parent storage after renaming - - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > GetStreamProperties(); - - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetAllRelationshipsIfAny(); - - void CopyInternallyTo_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDestStream, - const ::comphelper::SequenceAsHashMap& aEncryptionData ); - void CopyInternallyTo_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDestStream ); - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream( - sal_Int32 nStreamMode, - const ::comphelper::SequenceAsHashMap& aEncryptionData, - sal_Bool bHierarchyAccess ); - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream( - sal_Int32 nStreamMode, - sal_Bool bHierarchyAccess ); - - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawInStream(); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetPlainRawInStream(); - - void InputStreamDisposed( OInputCompStream* pStream ); - - void CreateReadonlyCopyBasedOnData( - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xDataToCopy, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Bool bUseCommonEncryption, - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ); - - void GetCopyOfLastCommit( ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ); - void GetCopyOfLastCommit( - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream, - const ::comphelper::SequenceAsHashMap& aEncryptionData ); - - - void CommitStreamRelInfo( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xRelStorage, - const ::rtl::OUString& aOrigStreamName, - const ::rtl::OUString& aNewStreamName ); - - void ReadRelInfoIfNecessary(); - - sal_Int32 GetNewRelId() { return m_nRelId ++; } -}; - -class OWriteStream : ::com::sun::star::lang::XTypeProvider - , public ::com::sun::star::io::XInputStream - , public ::com::sun::star::io::XOutputStream - , public ::com::sun::star::embed::XExtendedStorageStream - , public ::com::sun::star::io::XSeekable - , public ::com::sun::star::io::XTruncate - , public ::com::sun::star::embed::XEncryptionProtectedSource2 - , public ::com::sun::star::embed::XRelationshipAccess - , public ::com::sun::star::embed::XTransactedObject - , public ::com::sun::star::embed::XTransactionBroadcaster - , public ::com::sun::star::beans::XPropertySet - , public ::cppu::OWeakObject -{ - friend struct OWriteStream_Impl; - -protected: - ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > m_xInStream; - ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > m_xOutStream; - ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > m_xSeekable; - - OWriteStream_Impl* m_pImpl; - WSInternalData_Impl* m_pData; - - sal_Bool m_bInStreamDisconnected; - sal_Bool m_bInitOnDemand; - sal_Int64 m_nInitPosition; - - sal_Bool m_bTransacted; - - OWriteStream( OWriteStream_Impl* pImpl, sal_Bool bTransacted ); - OWriteStream( OWriteStream_Impl* pImpl, ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xStream, sal_Bool bTransacted ); - - void CloseOutput_Impl(); - - void CopyToStreamInternally_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); - - void ModifyParentUnlockMutex_Impl( ::osl::ResettableMutexGuard& aGuard ); - - void BroadcastTransaction( sal_Int8 nMessage ); - -public: - - virtual ~OWriteStream(); - - void CheckInitOnDemand(); - void DeInit(); - - // XInterface - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) - throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL acquire() throw(); - virtual void SAL_CALL release() throw(); - - // XTypeProvider - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() - throw( ::com::sun::star::uno::RuntimeException ); - virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() - throw( ::com::sun::star::uno::RuntimeException ); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - // XOutputStream - virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL flush( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeOutput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XStream - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); - - // XTruncate - virtual void SAL_CALL truncate() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XComponent - virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); - - //XEncryptionProtectedSource - virtual void SAL_CALL setEncryptionPassword( const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::uno::RuntimeException, - ::com::sun::star::io::IOException ); - virtual void SAL_CALL removeEncryption() - throw ( ::com::sun::star::uno::RuntimeException, - ::com::sun::star::io::IOException ); - - //XEncryptionProtectedSource2 - virtual void SAL_CALL setEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XRelationshipAccess - virtual ::sal_Bool SAL_CALL hasByID( const ::rtl::OUString& sID ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getTargetByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getTypeByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > SAL_CALL getRelationshipByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getRelationshipsByType( const ::rtl::OUString& sType ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getAllRelationships( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertRelationshipByID( const ::rtl::OUString& sID, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aEntry, ::sal_Bool bReplace ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeRelationshipByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertRelationships( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aEntries, ::sal_Bool bReplace ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL clearRelationships( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XPropertySet - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw ( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) 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 ); - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - - // XTransactedObject - virtual void SAL_CALL commit() - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL revert() - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - // XTransactionBroadcaster - virtual void SAL_CALL addTransactionListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XTransactionListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removeTransactionListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XTransactionListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/register.cxx b/package/source/xstor/register.cxx deleted file mode 100644 index 480a11732..000000000 --- a/package/source/xstor/register.cxx +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - - -#include <com/sun/star/registry/XRegistryKey.hpp> -#include <com/sun/star/registry/InvalidRegistryException.hpp> -#include <cppuhelper/factory.hxx> - -#include "xfactory.hxx" - -using namespace ::com::sun::star; - - -extern "C" { - -SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) -{ - void * pRet = 0; - - ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) ); - uno::Reference< lang::XSingleServiceFactory > xFactory; - - if ( pServiceManager && aImplName.equals( OStorageFactory::impl_staticGetImplementationName() ) ) - { - xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ), - OStorageFactory::impl_staticGetImplementationName(), - OStorageFactory::impl_staticCreateSelfInstance, - OStorageFactory::impl_staticGetSupportedServiceNames() ); - } - - if ( xFactory.is() ) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - - return pRet; -} - -} // extern "C" - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/selfterminatefilestream.cxx b/package/source/xstor/selfterminatefilestream.cxx deleted file mode 100644 index 3a2dd7530..000000000 --- a/package/source/xstor/selfterminatefilestream.cxx +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> - -#include "selfterminatefilestream.hxx" -#include <comphelper/processfactory.hxx> - -using namespace ::com::sun::star; - -//----------------------------------------------- -OSelfTerminateFileStream::OSelfTerminateFileStream( const uno::Reference< lang::XMultiServiceFactory > xFactory, const ::rtl::OUString& aURL ) -: m_aURL( aURL ) -{ - uno::Reference< lang::XMultiServiceFactory > xOwnFactory = xFactory; - if ( !xOwnFactory.is() ) - xOwnFactory.set( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); - - // IMPORTANT: The implementation is based on idea that m_xFileAccess, m_xInputStream and m_xSeekable are always set - // otherwise an exception is thrown in constructor - - m_xFileAccess.set( xOwnFactory->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY_THROW ); - - m_xInputStream.set( m_xFileAccess->openFileRead( aURL ), uno::UNO_SET_THROW ); - m_xSeekable.set( m_xInputStream, uno::UNO_QUERY_THROW ); -} - -//----------------------------------------------- -OSelfTerminateFileStream::~OSelfTerminateFileStream() -{ - CloseStreamDeleteFile(); -} - -//----------------------------------------------- -void OSelfTerminateFileStream::CloseStreamDeleteFile() -{ - try - { - m_xInputStream->closeInput(); - } - catch( uno::Exception& ) - {} - - try - { - m_xFileAccess->kill( m_aURL ); - } - catch( uno::Exception& ) - {} -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OSelfTerminateFileStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - return m_xInputStream->readBytes( aData, nBytesToRead ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OSelfTerminateFileStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead ); -} - -//----------------------------------------------- -void SAL_CALL OSelfTerminateFileStream::skipBytes( sal_Int32 nBytesToSkip ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - return m_xInputStream->skipBytes( nBytesToSkip ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OSelfTerminateFileStream::available( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - return m_xInputStream->available(); -} - -//----------------------------------------------- -void SAL_CALL OSelfTerminateFileStream::closeInput( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - CloseStreamDeleteFile(); -} - -//----------------------------------------------- -void SAL_CALL OSelfTerminateFileStream::seek( sal_Int64 location ) - throw ( lang::IllegalArgumentException, - io::IOException, - uno::RuntimeException ) -{ - m_xSeekable->seek( location ); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OSelfTerminateFileStream::getPosition() - throw ( io::IOException, - uno::RuntimeException) -{ - return m_xSeekable->getPosition(); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OSelfTerminateFileStream::getLength() - throw ( io::IOException, - uno::RuntimeException ) -{ - return m_xSeekable->getLength(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/selfterminatefilestream.hxx b/package/source/xstor/selfterminatefilestream.hxx deleted file mode 100644 index a9d28f0a6..000000000 --- a/package/source/xstor/selfterminatefilestream.hxx +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _SELFTERMINATEFILESTREAM_HXX_ -#define _SELFTERMINATEFILESTREAM_HXX_ - -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <cppuhelper/implbase2.hxx> - -struct OWriteStream_Impl; - -class OSelfTerminateFileStream : public cppu::WeakImplHelper2< ::com::sun::star::io::XInputStream, - ::com::sun::star::io::XSeekable > -{ -protected: - ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > m_xFileAccess; - - ::rtl::OUString m_aURL; - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xSeekable; - -public: - OSelfTerminateFileStream( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, const ::rtl::OUString& aURL ); - - virtual ~OSelfTerminateFileStream(); - - void CloseStreamDeleteFile(); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available() - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput() - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/switchpersistencestream.cxx b/package/source/xstor/switchpersistencestream.cxx deleted file mode 100644 index a03e63892..000000000 --- a/package/source/xstor/switchpersistencestream.cxx +++ /dev/null @@ -1,490 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <osl/diagnose.h> - -#include <comphelper/storagehelper.hxx> -#include <switchpersistencestream.hxx> - -using namespace ::com::sun::star; - -// ======================================================================== -struct SPStreamData_Impl -{ - uno::Reference< lang::XMultiServiceFactory > m_xFactory; - - sal_Bool m_bInStreamBased; - - // the streams below are not visible from outside so there is no need to remember position - - // original stream related members - uno::Reference< io::XStream > m_xOrigStream; - uno::Reference< io::XTruncate > m_xOrigTruncate; - uno::Reference< io::XSeekable > m_xOrigSeekable; - uno::Reference< io::XInputStream > m_xOrigInStream; - uno::Reference< io::XOutputStream > m_xOrigOutStream; - - sal_Bool m_bInOpen; - sal_Bool m_bOutOpen; - - - SPStreamData_Impl( - const uno::Reference< lang::XMultiServiceFactory >& xFactory, - sal_Bool bInStreamBased, - const uno::Reference< io::XStream >& xOrigStream, - const uno::Reference< io::XTruncate >& xOrigTruncate, - const uno::Reference< io::XSeekable >& xOrigSeekable, - const uno::Reference< io::XInputStream >& xOrigInStream, - const uno::Reference< io::XOutputStream >& xOrigOutStream, - sal_Bool bInOpen, - sal_Bool bOutOpen ) - : m_xFactory( xFactory ) - , m_bInStreamBased( bInStreamBased ) - , m_xOrigStream( xOrigStream ) - , m_xOrigTruncate( xOrigTruncate ) - , m_xOrigSeekable( xOrigSeekable ) - , m_xOrigInStream( xOrigInStream ) - , m_xOrigOutStream( xOrigOutStream ) - , m_bInOpen( bInOpen ) - , m_bOutOpen( bOutOpen ) - { - } -}; - -// ======================================================================== -// ------------------------------------------------------------------------ -SwitchablePersistenceStream::SwitchablePersistenceStream( - const uno::Reference< lang::XMultiServiceFactory >& xFactory, - const uno::Reference< io::XStream >& xStream ) -: m_xFactory( xFactory ) -, m_pStreamData( NULL ) -{ - SwitchPersistenceTo( xStream ); -} - -// ------------------------------------------------------------------------ -SwitchablePersistenceStream::SwitchablePersistenceStream( - const uno::Reference< lang::XMultiServiceFactory >& xFactory, - const uno::Reference< io::XInputStream >& xInputStream ) -: m_xFactory( xFactory ) -, m_pStreamData( NULL ) -{ - SwitchPersistenceTo( xInputStream ); -} - -// ------------------------------------------------------------------------ -SwitchablePersistenceStream::~SwitchablePersistenceStream() -{ - CloseAll_Impl(); -} - -// ------------------------------------------------------------------------ -void SwitchablePersistenceStream::SwitchPersistenceTo( const uno::Reference< io::XStream >& xStream ) -{ - uno::Reference< io::XTruncate > xNewTruncate( xStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XSeekable > xNewSeekable( xStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XInputStream > xNewInStream = xStream->getInputStream(); - uno::Reference< io::XOutputStream > xNewOutStream = xStream->getOutputStream(); - if ( !xNewInStream.is() || !xNewOutStream.is() ) - throw uno::RuntimeException(); - - sal_Int64 nPos = 0; - sal_Bool bInOpen = sal_False; - sal_Bool bOutOpen = sal_False; - - if ( m_pStreamData && m_pStreamData->m_xOrigSeekable.is() ) - { - // check that the length is the same - if ( m_pStreamData->m_xOrigSeekable->getLength() != xNewSeekable->getLength() ) - throw uno::RuntimeException(); - - // get the current position - nPos = m_pStreamData->m_xOrigSeekable->getPosition(); - bInOpen = m_pStreamData->m_bInOpen; - bOutOpen = m_pStreamData->m_bOutOpen; - } - - xNewSeekable->seek( nPos ); - - CloseAll_Impl(); - - m_pStreamData = new SPStreamData_Impl( m_xFactory, sal_False, - xStream, xNewTruncate, xNewSeekable, xNewInStream, xNewOutStream, - bInOpen, bOutOpen ); -} - -// ------------------------------------------------------------------------ -void SwitchablePersistenceStream::SwitchPersistenceTo( const uno::Reference< io::XInputStream >& xInputStream ) -{ - uno::Reference< io::XStream > xNewStream; - uno::Reference< io::XTruncate > xNewTruncate; - uno::Reference< io::XSeekable > xNewSeekable( xInputStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XOutputStream > xNewOutStream; - if ( !xInputStream.is() ) - throw uno::RuntimeException(); - - sal_Int64 nPos = 0; - sal_Bool bInOpen = sal_False; - sal_Bool bOutOpen = sal_False; - - if ( m_pStreamData && m_pStreamData->m_xOrigSeekable.is() ) - { - // check that the length is the same - if ( m_pStreamData->m_xOrigSeekable->getLength() != xNewSeekable->getLength() ) - throw uno::RuntimeException(); - - // get the current position - nPos = m_pStreamData->m_xOrigSeekable->getPosition(); - bInOpen = m_pStreamData->m_bInOpen; - bOutOpen = m_pStreamData->m_bOutOpen; - } - - xNewSeekable->seek( nPos ); - - CloseAll_Impl(); - - m_pStreamData = new SPStreamData_Impl( m_xFactory, sal_True, - xNewStream, xNewTruncate, xNewSeekable, xInputStream, xNewOutStream, - bInOpen, bOutOpen ); - -} - -// ------------------------------------------------------------------------ -void SwitchablePersistenceStream::CopyAndSwitchPersistenceTo( const uno::Reference< io::XStream >& xStream ) -{ - uno::Reference< io::XStream > xTargetStream = xStream; - uno::Reference< io::XSeekable > xTargetSeek; - - if ( !xTargetStream.is() ) - { - xTargetStream = uno::Reference < io::XStream >( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY_THROW ); - - xTargetSeek = uno::Reference< io::XSeekable >( xTargetStream, uno::UNO_QUERY_THROW ); - } - else - { - // the provided stream must be empty - xTargetSeek = uno::Reference< io::XSeekable >( xTargetStream, uno::UNO_QUERY_THROW ); - if ( xTargetSeek->getLength() ) - throw io::IOException(); - } - - uno::Reference< io::XTruncate > xTargetTruncate( xTargetStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XInputStream > xTargetInStream = xTargetStream->getInputStream(); - uno::Reference< io::XOutputStream > xTargetOutStream = xTargetStream->getOutputStream(); - if ( !xTargetInStream.is() || !xTargetOutStream.is() ) - throw uno::RuntimeException(); - - if ( !m_pStreamData->m_xOrigInStream.is() || !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - sal_Int64 nPos = m_pStreamData->m_xOrigSeekable->getPosition(); - m_pStreamData->m_xOrigSeekable->seek( 0 ); - ::comphelper::OStorageHelper::CopyInputToOutput( m_pStreamData->m_xOrigInStream, xTargetOutStream ); - xTargetOutStream->flush(); - xTargetSeek->seek( nPos ); - - sal_Bool bInOpen = m_pStreamData->m_bInOpen; - sal_Bool bOutOpen = m_pStreamData->m_bOutOpen; - - CloseAll_Impl(); - - m_pStreamData = new SPStreamData_Impl( m_xFactory, sal_False, - xTargetStream, xTargetTruncate, xTargetSeek, xTargetInStream, xTargetOutStream, - bInOpen, bOutOpen ); -} - -// ------------------------------------------------------------------------ -void SwitchablePersistenceStream::CloseAll_Impl() -{ - if ( m_pStreamData ) - { - delete m_pStreamData; - m_pStreamData = NULL; - } -} - -// com::sun::star::io::XStream -// ------------------------------------------------------------------------ -uno::Reference< io::XInputStream > SAL_CALL SwitchablePersistenceStream::getInputStream( ) - throw (uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pStreamData ) - m_pStreamData->m_bInOpen = sal_True; - return static_cast< io::XInputStream* >( this ); -} - - -// ------------------------------------------------------------------------ -uno::Reference< io::XOutputStream > SAL_CALL SwitchablePersistenceStream::getOutputStream( ) - throw (uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pStreamData ) - m_pStreamData->m_bOutOpen = sal_True; - return static_cast< io::XOutputStream* >( this ); -} - - - -// com::sun::star::io::XInputStream -// ------------------------------------------------------------------------ -::sal_Int32 SAL_CALL SwitchablePersistenceStream::readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigInStream->readBytes( aData, nBytesToRead ); -} - - -// ------------------------------------------------------------------------ -::sal_Int32 SAL_CALL SwitchablePersistenceStream::readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigInStream->readBytes( aData, nMaxBytesToRead ); -} - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::skipBytes( ::sal_Int32 nBytesToSkip ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigInStream->skipBytes( nBytesToSkip ); -} - - -// ------------------------------------------------------------------------ -::sal_Int32 SAL_CALL SwitchablePersistenceStream::available( ) - throw (io::NotConnectedException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigInStream->available(); -} - - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::closeInput() - throw (io::NotConnectedException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - m_pStreamData->m_bInOpen = sal_False; - if ( !m_pStreamData->m_bOutOpen ) - CloseAll_Impl(); -} - - - -// com::sun::star::io::XOutputStream -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::writeBytes( const uno::Sequence< ::sal_Int8 >& aData ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bInStreamBased ) - throw io::IOException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigOutStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigOutStream->writeBytes( aData ); -} - - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::flush( ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData || m_pStreamData->m_bInStreamBased ) - { - OSL_FAIL( "flush() is not acceptable!\n" ); - return; - // in future throw exception, for now some code might call flush() on closed stream - // since file ucp implementation allows it - // throw io::NotConnectedException(); - } - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigOutStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigOutStream->flush(); -} - - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::closeOutput( ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - m_pStreamData->m_bOutOpen = sal_False; - if ( !m_pStreamData->m_bInOpen ) - CloseAll_Impl(); -} - - - -// com::sun::star::io::XTruncate -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::truncate( ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bInStreamBased ) - throw io::IOException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigTruncate.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigTruncate->truncate(); -} - - -// com::sun::star::io::XSeekable -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::seek( ::sal_Int64 location ) - throw (lang::IllegalArgumentException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigSeekable->seek( location ); -} - - -// ------------------------------------------------------------------------ -::sal_Int64 SAL_CALL SwitchablePersistenceStream::getPosition( ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigSeekable->getPosition(); -} - - -// ------------------------------------------------------------------------ -::sal_Int64 SAL_CALL SwitchablePersistenceStream::getLength( ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigSeekable->getLength(); -} - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::waitForCompletion() - throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) -{ - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( m_pStreamData->m_xOrigOutStream, uno::UNO_QUERY ); - if ( asyncOutputMonitor.is() ) - asyncOutputMonitor->waitForCompletion(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/switchpersistencestream.hxx b/package/source/xstor/switchpersistencestream.hxx deleted file mode 100644 index 730aca1bf..000000000 --- a/package/source/xstor/switchpersistencestream.hxx +++ /dev/null @@ -1,122 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _SPSTREAM_HXX -#define _SPSTREAM_HXX - -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XTruncate.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/beans/XPropertySetInfo.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/io/XAsyncOutputMonitor.hpp> -#include <osl/mutex.hxx> -#include <cppuhelper/implbase6.hxx> - -//================================================================== -// SwitchablePersistenceStream -// -// Allows to switch the stream persistence on the fly. The target -// stream ( if not filled by the implementation ) MUST have the same -// size as the original one! -//================================================================== - -struct SPStreamData_Impl; -class SwitchablePersistenceStream - : public ::cppu::WeakImplHelper6 < - ::com::sun::star::io::XStream, - ::com::sun::star::io::XInputStream, - ::com::sun::star::io::XOutputStream, - ::com::sun::star::io::XTruncate, - ::com::sun::star::io::XSeekable, - ::com::sun::star::io::XAsyncOutputMonitor > -{ - ::osl::Mutex m_aMutex; - - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - - SPStreamData_Impl* m_pStreamData; - - void CloseAll_Impl(); - -public: - - SwitchablePersistenceStream( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); - - SwitchablePersistenceStream( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); - - ~SwitchablePersistenceStream(); - - void SwitchPersistenceTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); - - void SwitchPersistenceTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInputStream ); - - void CopyAndSwitchPersistenceTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); - -// com::sun::star::io::XStream - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XInputStream - virtual ::sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int32 SAL_CALL available( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XOutputStream - virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL flush( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeOutput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XTruncate - virtual void SAL_CALL truncate( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XSeekable - virtual void SAL_CALL seek( ::sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// ::com::sun::star::io::XAsyncOutputMonitor - virtual void SAL_CALL waitForCompletion( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif //_SPSTREAM_HXX - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/xfactory.cxx b/package/source/xstor/xfactory.cxx deleted file mode 100644 index 3ab16c53c..000000000 --- a/package/source/xstor/xfactory.cxx +++ /dev/null @@ -1,326 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/io/XSeekable.hpp> - -#include <comphelper/storagehelper.hxx> - -#include "xfactory.hxx" -#include "xstorage.hxx" - - -using namespace ::com::sun::star; - -//------------------------------------------------------------------------- -sal_Bool CheckPackageSignature_Impl( const uno::Reference< io::XInputStream >& xInputStream, - const uno::Reference< io::XSeekable >& xSeekable ) -{ - if ( !xInputStream.is() || !xSeekable.is() ) - throw uno::RuntimeException(); - - if ( xSeekable->getLength() ) - { - uno::Sequence< sal_Int8 > aData( 4 ); - xSeekable->seek( 0 ); - sal_Int32 nRead = xInputStream->readBytes( aData, 4 ); - xSeekable->seek( 0 ); - - // TODO/LATER: should the disk spanned files be supported? - // 0x50, 0x4b, 0x07, 0x08 - return ( nRead == 4 && aData[0] == 0x50 && aData[1] == 0x4b && aData[2] == 0x03 && aData[3] == 0x04 ); - } - else - return sal_True; // allow to create a storage based on empty stream -} - -//------------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OStorageFactory::impl_staticGetSupportedServiceNames() -{ - uno::Sequence< ::rtl::OUString > aRet(2); - aRet[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.StorageFactory") ); - aRet[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.StorageFactory") ); - return aRet; -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL OStorageFactory::impl_staticGetImplementationName() -{ - return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.StorageFactory") ); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL OStorageFactory::impl_staticCreateSelfInstance( - const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) -{ - return uno::Reference< uno::XInterface >( *new OStorageFactory( xServiceManager ) ); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL OStorageFactory::createInstance() - throw ( uno::Exception, - uno::RuntimeException ) -{ - // TODO: reimplement TempStream service to support XStream interface - uno::Reference < io::XStream > xTempStream( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY ); - - if ( !xTempStream.is() ) - throw uno::RuntimeException(); // TODO: - - return uno::Reference< uno::XInterface >( - static_cast< OWeakObject* >( new OStorage( xTempStream, - embed::ElementModes::READWRITE, - uno::Sequence< beans::PropertyValue >(), - m_xFactory, - embed::StorageFormats::PACKAGE ) ), - uno::UNO_QUERY ); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL OStorageFactory::createInstanceWithArguments( - const uno::Sequence< uno::Any >& aArguments ) - throw ( uno::Exception, - uno::RuntimeException ) -{ - // The request for storage can be done with up to three arguments - - // The first argument specifies a source for the storage - // it can be URL, XStream, XInputStream. - // The second value is a mode the storage should be open in. - // And the third value is a media descriptor. - - sal_Int32 nArgNum = aArguments.getLength(); - OSL_ENSURE( nArgNum < 4, "Wrong parameter number" ); - - if ( !nArgNum ) - return createInstance(); - - // first try to retrieve storage open mode if any - // by default the storage will be open in readonly mode - sal_Int32 nStorageMode = embed::ElementModes::READ; - if ( nArgNum >= 2 ) - { - if( !( aArguments[1] >>= nStorageMode ) ) - { - OSL_FAIL( "Wrong second argument!\n" ); - throw lang::IllegalArgumentException(); // TODO: - } - // it's allways possible to read written storage in this implementation - nStorageMode |= embed::ElementModes::READ; - } - - if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE - && ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ) - throw lang::IllegalArgumentException(); // TODO: - - // retrieve storage source stream - ::rtl::OUString aURL; - uno::Reference< io::XStream > xStream; - uno::Reference< io::XInputStream > xInputStream; - - if ( aArguments[0] >>= aURL ) - { - if ( !aURL.getLength() ) - { - OSL_FAIL( "Empty URL is provided!\n" ); - throw lang::IllegalArgumentException(); // TODO: - } - - if ( aURL.equalsIgnoreAsciiCaseAsciiL( "vnd.sun.star.pkg", 16 ) ) - { - OSL_FAIL( "Packages URL's are not valid for storages!\n" ); // ??? - throw lang::IllegalArgumentException(); // TODO: - } - - uno::Reference < ::com::sun::star::ucb::XSimpleFileAccess > xTempAccess( - m_xFactory->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - if ( nStorageMode & embed::ElementModes::WRITE ) - xStream = xTempAccess->openFileReadWrite( aURL ); - else - xInputStream = xTempAccess->openFileRead( aURL ); - } - else if ( !( aArguments[0] >>= xStream ) && !( aArguments[0] >>= xInputStream ) ) - { - OSL_FAIL( "Wrong first argument!\n" ); - throw uno::Exception(); // TODO: Illegal argument - } - - // retrieve mediadescriptor and set storage properties - uno::Sequence< beans::PropertyValue > aDescr; - uno::Sequence< beans::PropertyValue > aPropsToSet; - - sal_Int32 nStorageType = embed::StorageFormats::PACKAGE; - - if ( nArgNum >= 3 ) - { - if( aArguments[2] >>= aDescr ) - { - if ( aURL.getLength() ) - { - aPropsToSet.realloc(1); - aPropsToSet[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL") ); - aPropsToSet[0].Value <<= aURL; - } - - for ( sal_Int32 nInd = 0, nNumArgs = 1; nInd < aDescr.getLength(); nInd++ ) - { - if ( aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "InteractionHandler" ) ) - || aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Password" ) ) - || aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) - || aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StatusIndicator" ) ) ) - // || aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Unpacked" ) ) // TODO: - { - aPropsToSet.realloc( ++nNumArgs ); - aPropsToSet[nNumArgs-1].Name = aDescr[nInd].Name; - aPropsToSet[nNumArgs-1].Value = aDescr[nInd].Value; - } - else if ( aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StorageFormat" ) ) ) - { - ::rtl::OUString aFormatName; - sal_Int32 nFormatID = 0; - if ( aDescr[nInd].Value >>= aFormatName ) - { - if ( aFormatName.equals( PACKAGE_STORAGE_FORMAT_STRING ) ) - nStorageType = embed::StorageFormats::PACKAGE; - else if ( aFormatName.equals( ZIP_STORAGE_FORMAT_STRING ) ) - nStorageType = embed::StorageFormats::ZIP; - else if ( aFormatName.equals( OFOPXML_STORAGE_FORMAT_STRING ) ) - nStorageType = embed::StorageFormats::OFOPXML; - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - } - else if ( aDescr[nInd].Value >>= nFormatID ) - { - if ( nFormatID != embed::StorageFormats::PACKAGE - && nFormatID != embed::StorageFormats::ZIP - && nFormatID != embed::StorageFormats::OFOPXML ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - nStorageType = nFormatID; - } - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - } - else - OSL_FAIL( "Unacceptable property, will be ignored!\n" ); - } - } - else - { - OSL_FAIL( "Wrong third argument!\n" ); - throw uno::Exception(); // TODO: Illegal argument - } - - } - - // create storage based on source - if ( xInputStream.is() ) - { - // if xInputStream is set the storage should be open from it - if ( ( nStorageMode & embed::ElementModes::WRITE ) ) - throw uno::Exception(); // TODO: access denied - - uno::Reference< io::XSeekable > xSeekable( xInputStream, uno::UNO_QUERY ); - if ( !xSeekable.is() ) - { - // TODO: wrap stream to let it be seekable - OSL_FAIL( "Nonseekable streams are not supported for now!\n" ); - } - - if ( !CheckPackageSignature_Impl( xInputStream, xSeekable ) ) - throw io::IOException(); // TODO: this is not a package file - - return uno::Reference< uno::XInterface >( - static_cast< OWeakObject* >( new OStorage( xInputStream, nStorageMode, aPropsToSet, m_xFactory, nStorageType ) ), - uno::UNO_QUERY ); - } - else if ( xStream.is() ) - { - if ( ( ( nStorageMode & embed::ElementModes::WRITE ) && !xStream->getOutputStream().is() ) - || !xStream->getInputStream().is() ) - throw uno::Exception(); // TODO: access denied - - uno::Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY ); - if ( !xSeekable.is() ) - { - // TODO: wrap stream to let it be seekable - OSL_FAIL( "Nonseekable streams are not supported for now!\n" ); - } - - if ( !CheckPackageSignature_Impl( xStream->getInputStream(), xSeekable ) ) - throw io::IOException(); // TODO: this is not a package file - - return uno::Reference< uno::XInterface >( - static_cast< OWeakObject* >( new OStorage( xStream, nStorageMode, aPropsToSet, m_xFactory, nStorageType ) ), - uno::UNO_QUERY ); - } - - throw uno::Exception(); // general error during creation -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL OStorageFactory::getImplementationName() - throw ( uno::RuntimeException ) -{ - return impl_staticGetImplementationName(); -} - -//------------------------------------------------------------------------- -sal_Bool SAL_CALL OStorageFactory::supportsService( const ::rtl::OUString& ServiceName ) - throw ( uno::RuntimeException ) -{ - uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); - - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( ServiceName.compareTo( aSeq[nInd] ) == 0 ) - return sal_True; - - return sal_False; -} - -//------------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OStorageFactory::getSupportedServiceNames() - throw ( uno::RuntimeException ) -{ - return impl_staticGetSupportedServiceNames(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/xfactory.hxx b/package/source/xstor/xfactory.hxx deleted file mode 100644 index 0a6a5fad7..000000000 --- a/package/source/xstor/xfactory.hxx +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef __XFACTORY_HXX_ -#define __XFACTORY_HXX_ - -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> - - -#include <cppuhelper/implbase2.hxx> - - -class OStorage; - -class OStorageFactory : public ::cppu::WeakImplHelper2< ::com::sun::star::lang::XSingleServiceFactory, - ::com::sun::star::lang::XServiceInfo > -{ - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - -public: - OStorageFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ) - : m_xFactory( xFactory ) - { - OSL_ENSURE( xFactory.is(), "No service manager is provided!\n" ); - } - - static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL - impl_staticGetSupportedServiceNames(); - - static ::rtl::OUString SAL_CALL impl_staticGetImplementationName(); - - static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL - impl_staticCreateSelfInstance( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ); - - - // XSingleServiceFactory - virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - 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 ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/xstor.component b/package/source/xstor/xstor.component deleted file mode 100644 index f338d6a54..000000000 --- a/package/source/xstor/xstor.component +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!--********************************************************************** -* -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* Copyright 2000, 2010 Oracle and/or its affiliates. -* -* OpenOffice.org - a multi-platform office productivity suite -* -* This file is part of OpenOffice.org. -* -* OpenOffice.org is free software: you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License version 3 -* only, as published by the Free Software Foundation. -* -* OpenOffice.org is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License version 3 for more details -* (a copy is included in the LICENSE file that accompanied this code). -* -* You should have received a copy of the GNU Lesser General Public License -* version 3 along with OpenOffice.org. If not, see -* <http://www.openoffice.org/license.html> -* for a copy of the LGPLv3 License. -* -**********************************************************************--> - -<component loader="com.sun.star.loader.SharedLibrary" - xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.embed.StorageFactory"> - <service name="com.sun.star.comp.embed.StorageFactory"/> - <service name="com.sun.star.embed.StorageFactory"/> - </implementation> -</component> diff --git a/package/source/xstor/xstor.dxp b/package/source/xstor/xstor.dxp deleted file mode 100644 index 700330789..000000000 --- a/package/source/xstor/xstor.dxp +++ /dev/null @@ -1 +0,0 @@ -component_getFactory diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx deleted file mode 100644 index e05eac0b6..000000000 --- a/package/source/xstor/xstorage.cxx +++ /dev/null @@ -1,6405 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/UseBackupException.hpp> -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/ucb/XProgressHandler.hpp> -#include <com/sun/star/container/XHierarchicalNameAccess.hpp> -#include <com/sun/star/container/XEnumerationAccess.hpp> -#include <com/sun/star/container/XNamed.hpp> -#include <com/sun/star/util/XChangesBatch.hpp> -#include <com/sun/star/util/XCloneable.hpp> - - -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> -#include <com/sun/star/beans/NamedValue.hpp> - -#include <PackageConstants.hxx> - -#include <cppuhelper/typeprovider.hxx> -#include <cppuhelper/exc_hlp.hxx> -#include <rtl/logfile.hxx> -#include <rtl/instance.hxx> - -#include <comphelper/processfactory.hxx> -#include <comphelper/componentcontext.hxx> -#include <comphelper/storagehelper.hxx> -#include <comphelper/ofopxmlhelper.hxx> - -#include "xstorage.hxx" -#include "owriteablestream.hxx" -#include "disposelistener.hxx" -#include "switchpersistencestream.hxx" -#include "ohierarchyholder.hxx" - -using namespace ::com::sun::star; - -//========================================================= - -typedef ::std::list< uno::WeakReference< lang::XComponent > > WeakComponentList; - -struct StorInternalData_Impl -{ - SotMutexHolderRef m_rSharedMutexRef; - ::cppu::OMultiTypeInterfaceContainerHelper m_aListenersContainer; // list of listeners - ::cppu::OTypeCollection* m_pTypeCollection; - sal_Bool m_bIsRoot; - sal_Int32 m_nStorageType; // the mode in wich the storage is used - sal_Bool m_bReadOnlyWrap; - - OChildDispListener_Impl* m_pSubElDispListener; - - WeakComponentList m_aOpenSubComponentsList; - - ::rtl::Reference< OHierarchyHolder_Impl > m_rHierarchyHolder; - - // the mutex reference MUST NOT be empty - StorInternalData_Impl( const SotMutexHolderRef& rMutexRef, sal_Bool bRoot, sal_Int32 nStorageType, sal_Bool bReadOnlyWrap ) - : m_rSharedMutexRef( rMutexRef ) - , m_aListenersContainer( rMutexRef->GetMutex() ) - , m_pTypeCollection( NULL ) - , m_bIsRoot( bRoot ) - , m_nStorageType( nStorageType ) - , m_bReadOnlyWrap( bReadOnlyWrap ) - , m_pSubElDispListener( NULL ) - {} - - ~StorInternalData_Impl(); -}; - -//========================================================= -::rtl::OUString GetNewTempFileURL( const uno::Reference< lang::XMultiServiceFactory > xFactory ); - -// static -void OStorage_Impl::completeStorageStreamCopy_Impl( - const uno::Reference< io::XStream >& xSource, - const uno::Reference< io::XStream >& xDest, - sal_Int32 nStorageType, - const uno::Sequence< uno::Sequence< beans::StringPair > >& aRelInfo ) -{ - uno::Reference< beans::XPropertySet > xSourceProps( xSource, uno::UNO_QUERY ); - uno::Reference< beans::XPropertySet > xDestProps( xDest, uno::UNO_QUERY ); - if ( !xSourceProps.is() || !xDestProps.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XOutputStream > xDestOutStream = xDest->getOutputStream(); - if ( !xDestOutStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XInputStream > xSourceInStream = xSource->getInputStream(); - if ( !xSourceInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // TODO: headers of encripted streams should be copied also - ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInStream, xDestOutStream ); - - uno::Sequence< ::rtl::OUString > aPropNames( 1 ); - aPropNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ); - - if ( nStorageType == embed::StorageFormats::PACKAGE ) - { - aPropNames.realloc( 3 ); - aPropNames[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - aPropNames[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ); - } - else if ( nStorageType == embed::StorageFormats::OFOPXML ) - { - // TODO/LATER: in future it might make sence to provide the stream if there is one - uno::Reference< embed::XRelationshipAccess > xRelAccess( xDest, uno::UNO_QUERY_THROW ); - xRelAccess->clearRelationships(); - xRelAccess->insertRelationships( aRelInfo, sal_False ); - - aPropNames.realloc( 2 ); - aPropNames[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - } - - for ( int ind = 0; ind < aPropNames.getLength(); ind++ ) - xDestProps->setPropertyValue( aPropNames[ind], xSourceProps->getPropertyValue( aPropNames[ind] ) ); -} - -uno::Reference< io::XInputStream > GetSeekableTempCopy( uno::Reference< io::XInputStream > xInStream, - uno::Reference< lang::XMultiServiceFactory > xFactory ) -{ - uno::Reference < io::XOutputStream > xTempOut( - xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), - uno::UNO_QUERY ); - uno::Reference < io::XInputStream > xTempIn( xTempOut, uno::UNO_QUERY ); - - if ( !xTempOut.is() || !xTempIn.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut ); - xTempOut->closeOutput(); - - return xTempIn; -} - -StorInternalData_Impl::~StorInternalData_Impl() -{ - if ( m_pTypeCollection ) - delete m_pTypeCollection; -} - - -SotElement_Impl::SotElement_Impl( const ::rtl::OUString& rName, sal_Bool bStor, sal_Bool bNew ) -: m_aName( rName ) -, m_aOriginalName( rName ) -, m_bIsRemoved( sal_False ) -, m_bIsInserted( bNew ) -, m_bIsStorage( bStor ) -, m_pStorage( NULL ) -, m_pStream( NULL ) -{ -} - -SotElement_Impl::~SotElement_Impl() -{ - if ( m_pStorage ) - delete m_pStorage; - - if ( m_pStream ) - delete m_pStream; -} - -//----------------------------------------------- -// most of properties are holt by the storage but are not used -OStorage_Impl::OStorage_Impl( uno::Reference< io::XInputStream > xInputStream, - sal_Int32 nMode, - uno::Sequence< beans::PropertyValue > xProperties, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_rMutexRef( new SotMutexHolder ) -, m_pAntiImpl( NULL ) -, m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE ) -, m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) -, m_bBroadcastModified( sal_False ) -, m_bCommited( sal_False ) -, m_bIsRoot( sal_True ) -, m_bListCreated( sal_False ) -, m_xFactory( xFactory ) -, m_xProperties( xProperties ) -, m_bHasCommonEncryptionData( sal_False ) -, m_pParent( NULL ) -, m_bControlMediaType( sal_False ) -, m_bMTFallbackUsed( sal_False ) -, m_bControlVersion( sal_False ) -, m_pSwitchStream( NULL ) -, m_nStorageType( nStorageType ) -, m_pRelStorElement( NULL ) -, m_nRelInfoStatus( RELINFO_NO_INIT ) -{ - // all the checks done below by assertion statements must be done by factory - OSL_ENSURE( xInputStream.is(), "No input stream is provided!\n" ); - - m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, xInputStream ); - m_xInputStream = m_pSwitchStream->getInputStream(); - - if ( m_nStorageMode & embed::ElementModes::WRITE ) - { - // check that the stream allows to write - OSL_FAIL( "No stream for writing is provided!\n" ); - } -} - -//----------------------------------------------- -// most of properties are holt by the storage but are not used -OStorage_Impl::OStorage_Impl( uno::Reference< io::XStream > xStream, - sal_Int32 nMode, - uno::Sequence< beans::PropertyValue > xProperties, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_rMutexRef( new SotMutexHolder ) -, m_pAntiImpl( NULL ) -, m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE ) -, m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) -, m_bBroadcastModified( sal_False ) -, m_bCommited( sal_False ) -, m_bIsRoot( sal_True ) -, m_bListCreated( sal_False ) -, m_xFactory( xFactory ) -, m_xProperties( xProperties ) -, m_bHasCommonEncryptionData( sal_False ) -, m_pParent( NULL ) -, m_bControlMediaType( sal_False ) -, m_bMTFallbackUsed( sal_False ) -, m_bControlVersion( sal_False ) -, m_pSwitchStream( NULL ) -, m_nStorageType( nStorageType ) -, m_pRelStorElement( NULL ) -, m_nRelInfoStatus( RELINFO_NO_INIT ) -{ - // all the checks done below by assertion statements must be done by factory - OSL_ENSURE( xStream.is(), "No stream is provided!\n" ); - - if ( m_nStorageMode & embed::ElementModes::WRITE ) - { - m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, xStream ); - m_xStream = static_cast< io::XStream* >( m_pSwitchStream ); - } - else - { - m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, - xStream->getInputStream() ); - m_xInputStream = m_pSwitchStream->getInputStream(); - } -} - -//----------------------------------------------- -OStorage_Impl::OStorage_Impl( OStorage_Impl* pParent, - sal_Int32 nMode, - uno::Reference< container::XNameContainer > xPackageFolder, - uno::Reference< lang::XSingleServiceFactory > xPackage, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_rMutexRef( new SotMutexHolder ) -, m_pAntiImpl( NULL ) -, m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE ) -, m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) -, m_bBroadcastModified( sal_False ) -, m_bCommited( sal_False ) -, m_bIsRoot( sal_False ) -, m_bListCreated( sal_False ) -, m_xPackageFolder( xPackageFolder ) -, m_xPackage( xPackage ) -, m_xFactory( xFactory ) -, m_bHasCommonEncryptionData( sal_False ) -, m_pParent( pParent ) // can be empty in case of temporary readonly substorages and relation storage -, m_bControlMediaType( sal_False ) -, m_bMTFallbackUsed( sal_False ) -, m_bControlVersion( sal_False ) -, m_pSwitchStream( NULL ) -, m_nStorageType( nStorageType ) -, m_pRelStorElement( NULL ) -, m_nRelInfoStatus( RELINFO_NO_INIT ) -{ - OSL_ENSURE( xPackageFolder.is(), "No package folder!\n" ); -} - -//----------------------------------------------- -OStorage_Impl::~OStorage_Impl() -{ - { - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_pAntiImpl ) // root storage wrapper must set this member to NULL before destruction of object - { - OSL_ENSURE( !m_bIsRoot, "The root storage wrapper must be disposed already" ); - - try { - m_pAntiImpl->InternalDispose( sal_False ); - } - catch ( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - m_pAntiImpl = NULL; - } - else if ( !m_aReadOnlyWrapList.empty() ) - { - for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin(); - pStorageIter != m_aReadOnlyWrapList.end(); pStorageIter++ ) - { - uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef; - if ( xTmp.is() ) - try { - pStorageIter->m_pPointer->InternalDispose( sal_False ); - } catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - - m_aReadOnlyWrapList.clear(); - } - - m_pParent = NULL; - } - - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - delete *pElementIter; - - m_aChildrenList.clear(); - - for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin(); - pDeletedIter != m_aDeletedList.end(); pDeletedIter++ ) - delete *pDeletedIter; - - m_aDeletedList.clear(); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_pRelStorElement ) - { - delete m_pRelStorElement; - m_pRelStorElement = NULL; - } - - m_xPackageFolder = uno::Reference< container::XNameContainer >(); - m_xPackage = uno::Reference< lang::XSingleServiceFactory >(); - - ::rtl::OUString aPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ); - for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); aInd++ ) - { - if ( m_xProperties[aInd].Name.equals( aPropertyName ) ) - { - // the storage is URL based so all the streams are opened by factory and should be closed - try - { - if ( m_xInputStream.is() ) - { - m_xInputStream->closeInput(); - m_xInputStream = uno::Reference< io::XInputStream >(); - } - - if ( m_xStream.is() ) - { - uno::Reference< io::XInputStream > xInStr = m_xStream->getInputStream(); - if ( xInStr.is() ) - xInStr->closeInput(); - - uno::Reference< io::XOutputStream > xOutStr = m_xStream->getOutputStream(); - if ( xOutStr.is() ) - xOutStr->closeOutput(); - - m_xStream = uno::Reference< io::XStream >(); - } - } - catch( const uno::Exception& rException ) - { - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - AddLog( rException.Message ); - } - } - } -} - -//----------------------------------------------- -void OStorage_Impl::AddLog( const ::rtl::OUString& aMessage ) -{ - if ( !m_xLogRing.is() ) - { - try - { - ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); - if ( aContext.is() ) - m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW ); - } - catch( const uno::Exception& ) - { - // No log - } - } - - if ( m_xLogRing.is() ) - m_xLogRing->logString( aMessage ); -} - -//----------------------------------------------- -void OStorage_Impl::SetReadOnlyWrap( OStorage& aStorage ) -{ - // Weak reference is used inside the holder so the refcount must not be zero at this point - OSL_ENSURE( aStorage.GetRefCount_Impl(), "There must be a reference alive to use this method!\n" ); - m_aReadOnlyWrapList.push_back( StorageHolder_Impl( &aStorage ) ); -} - -//----------------------------------------------- -void OStorage_Impl::RemoveReadOnlyWrap( OStorage& aStorage ) -{ - for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin(); - pStorageIter != m_aReadOnlyWrapList.end();) - { - uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef; - if ( !xTmp.is() || pStorageIter->m_pPointer == &aStorage ) - { - try { - pStorageIter->m_pPointer->InternalDispose( sal_False ); - } catch( const uno::Exception& rException ) - { - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - AddLog( rException.Message ); - } - - OStorageList_Impl::iterator pIterToDelete( pStorageIter ); - pStorageIter++; - m_aReadOnlyWrapList.erase( pIterToDelete ); - } - else - pStorageIter++; - } -} - -//----------------------------------------------- -void OStorage_Impl::OpenOwnPackage() -{ - OSL_ENSURE( m_bIsRoot, "Opening of the package has no sence!\n" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xPackageFolder.is() ) - { - if ( !m_xPackage.is() ) - { - uno::Sequence< uno::Any > aArguments( 2 ); - if ( m_nStorageMode & embed::ElementModes::WRITE ) - aArguments[ 0 ] <<= m_xStream; - else - { - OSL_ENSURE( m_xInputStream.is(), "Input stream must be set for readonly access!\n" ); - aArguments[ 0 ] <<= m_xInputStream; - // TODO: if input stream is not seekable or XSeekable interface is supported - // on XStream object a wrapper must be used - } - - // do not allow elements to remove themself from the old container in case of insertion to another container - aArguments[ 1 ] <<= beans::NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowRemoveOnInsert" ) ), - uno::makeAny( (sal_Bool)sal_False ) ); - - sal_Int32 nArgNum = 2; - for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); aInd++ ) - { - if ( m_xProperties[aInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) - || m_xProperties[aInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ProgressHandler" ) ) ) - { - beans::NamedValue aNamedValue( m_xProperties[aInd].Name, - m_xProperties[aInd].Value ); - aArguments.realloc( ++nArgNum ); - aArguments[nArgNum-1] <<= aNamedValue; - } - else if ( m_xProperties[aInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Password" ) ) ) - { - // TODO: implement password setting for documents - // the password entry must be removed after setting - } - } - - if ( m_nStorageType == embed::StorageFormats::ZIP ) - { - // let the package support only plain zip format - beans::NamedValue aNamedValue; - aNamedValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); - aNamedValue.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) ); - aArguments.realloc( ++nArgNum ); - aArguments[nArgNum-1] <<= aNamedValue; - } - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - // let the package support OFOPXML media type handling - beans::NamedValue aNamedValue; - aNamedValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); - aNamedValue.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) ); - aArguments.realloc( ++nArgNum ); - aArguments[nArgNum-1] <<= aNamedValue; - } - - m_xPackage = uno::Reference< lang::XSingleServiceFactory > ( - GetServiceFactory()->createInstanceWithArguments( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.packages.comp.ZipPackage" ) ), - aArguments ), - uno::UNO_QUERY ); - } - - uno::Reference< container::XHierarchicalNameAccess > xHNameAccess( m_xPackage, uno::UNO_QUERY ); - OSL_ENSURE( xHNameAccess.is(), "The package could not be created!\n" ); - - if ( xHNameAccess.is() ) - { - uno::Any aFolder = xHNameAccess->getByHierarchicalName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ); - aFolder >>= m_xPackageFolder; - } - } - - OSL_ENSURE( m_xPackageFolder.is(), "The package root folder can not be opened!\n" ); - if ( !m_xPackageFolder.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -uno::Reference< lang::XMultiServiceFactory > OStorage_Impl::GetServiceFactory() -{ - if ( m_xFactory.is() ) - return m_xFactory; - - return ::comphelper::getProcessServiceFactory(); -} - -//----------------------------------------------- -SotElementList_Impl& OStorage_Impl::GetChildrenList() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - ReadContents(); - return m_aChildrenList; -} - -//----------------------------------------------- -void OStorage_Impl::GetStorageProperties() -{ - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - uno::Reference< beans::XPropertySet > xProps( m_xPackageFolder, uno::UNO_QUERY_THROW ); - - if ( !m_bControlMediaType ) - { - uno::Reference< beans::XPropertySet > xPackageProps( m_xPackage, uno::UNO_QUERY_THROW ); - xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) >>= m_bMTFallbackUsed; - - xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= m_aMediaType; - m_bControlMediaType = sal_True; - } - - if ( !m_bControlVersion ) - { - xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= m_aVersion; - m_bControlVersion = sal_True; - } - } - - // the properties of OFOPXML will be handled directly -} - -//----------------------------------------------- -void OStorage_Impl::ReadRelInfoIfNecessary() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return; - - if ( m_nRelInfoStatus == RELINFO_NO_INIT ) - { - // Init from original stream - uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( ::rtl::OUString() ); - if ( xRelInfoStream.is() ) - m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence( - xRelInfoStream, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/.rels" ) ), - m_xFactory ); - - m_nRelInfoStatus = RELINFO_READ; - } - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - // Init from the new stream - try - { - if ( m_xNewRelInfoStream.is() ) - m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence( - m_xNewRelInfoStream, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/.rels" ) ), - m_xFactory ); - - m_nRelInfoStatus = RELINFO_CHANGED_STREAM_READ; - } - catch( const uno::Exception& ) - { - m_nRelInfoStatus = RELINFO_CHANGED_BROKEN; - } - } -} - -//----------------------------------------------- -void OStorage_Impl::ReadContents() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bListCreated ) - return; - - if ( m_bIsRoot ) - OpenOwnPackage(); - - uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xPackageFolder, uno::UNO_QUERY ); - if ( !xEnumAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration(); - if ( !xEnum.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_bListCreated = sal_True; - - while( xEnum->hasMoreElements() ) - { - try { - uno::Reference< container::XNamed > xNamed; - xEnum->nextElement() >>= xNamed; - - if ( !xNamed.is() ) - { - OSL_FAIL( "XNamed is not supported!\n" ); - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - ::rtl::OUString aName = xNamed->getName(); - OSL_ENSURE( aName.getLength(), "Empty name!\n" ); - - uno::Reference< container::XNameContainer > xNameContainer( xNamed, uno::UNO_QUERY ); - - SotElement_Impl* pNewElement = new SotElement_Impl( aName, xNameContainer.is(), sal_False ); - if ( m_nStorageType == embed::StorageFormats::OFOPXML && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - { - if ( !pNewElement->m_bIsStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Unexpected format - - m_pRelStorElement = pNewElement; - CreateRelStorage(); - } - else - { - if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE ) - { - // if a storage is truncated all of it elements are marked as deleted - pNewElement->m_bIsRemoved = sal_True; - } - - m_aChildrenList.push_back( pNewElement ); - } - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - AddLog( rNoSuchElementException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "NoSuchElement" ) ) ); - - OSL_FAIL( "hasMoreElements() implementation has problems!\n" ); - break; - } - } - if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE ) - { - // if a storage is truncated the relations information should be cleaned - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_nRelInfoStatus = RELINFO_CHANGED; - } - - // cache changeable folder properties - GetStorageProperties(); -} - -//----------------------------------------------- -void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDest, sal_Bool bDirect ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - uno::Reference< beans::XPropertySet > xPropSet( xDest, uno::UNO_QUERY ); - if ( !xPropSet.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - sal_Int32 nDestMode = embed::ElementModes::READ; - xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nDestMode; - - if ( !( nDestMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - - ReadContents(); - - if ( !m_xPackageFolder.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - if ( !(*pElementIter)->m_bIsRemoved ) - CopyStorageElement( *pElementIter, xDest, (*pElementIter)->m_aName, bDirect ); - } - - // move storage properties to the destination one ( means changeable properties ) - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - ::rtl::OUString aMediaTypeString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - ::rtl::OUString aVersionString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ); - xPropSet->setPropertyValue( aMediaTypeString, uno::makeAny( m_aMediaType ) ); - xPropSet->setPropertyValue( aVersionString, uno::makeAny( m_aVersion ) ); - } - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - // if this is a root storage, the common key from current one should be moved there - sal_Bool bIsRoot = sal_False; - ::rtl::OUString aRootString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsRoot" ) ); - if ( ( xPropSet->getPropertyValue( aRootString ) >>= bIsRoot ) && bIsRoot ) - { - try - { - uno::Reference< embed::XEncryptionProtectedStorage > xEncr( xDest, uno::UNO_QUERY ); - if ( xEncr.is() ) - { - xEncr->setEncryptionData( GetCommonRootEncryptionData().getAsConstNamedValueList() ); - - uno::Sequence< beans::NamedValue > aAlgorithms; - uno::Reference< beans::XPropertySet > xPackPropSet( m_xPackage, uno::UNO_QUERY_THROW ); - xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) - >>= aAlgorithms; - xEncr->setEncryptionAlgorithms( aAlgorithms ); - } - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - AddLog( rNoEncryptionException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) ); - } - } - } - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - - // TODO/LATER: currently the optimization is not active - // uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( ::rtl::OUString() ); // own stream - // if ( xRelInfoStream.is() ) - // { - // // Relations info stream is a writeonly property, introduced only to optimyze copying - // // Should be used carefuly since no check for stream consistency is done, and the stream must not stay locked - // - // ::rtl::OUString aRelInfoString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RelationsInfoStream" ) ); - // xPropSet->setPropertyValue( aRelInfoString, uno::makeAny( GetSeekableTempCopy( xRelInfoStream, m_xFactory ) ) ); - // } - - uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY ); - if ( !xRels.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False ); - } - - // if possible the destination storage should be commited after successful copying - uno::Reference< embed::XTransactedObject > xObjToCommit( xDest, uno::UNO_QUERY ); - if ( xObjToCommit.is() ) - xObjToCommit->commit(); -} - -//----------------------------------------------- -void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement, - uno::Reference< embed::XStorage > xDest, - ::rtl::OUString aName, - sal_Bool bDirect ) -{ - OSL_ENSURE( xDest.is(), "No destination storage!\n" ); - OSL_ENSURE( aName.getLength(), "Empty element name!\n" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - uno::Reference< container::XNameAccess > xDestAccess( xDest, uno::UNO_QUERY ); - if ( !xDestAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( xDestAccess->hasByName( aName ) - && !( pElement->m_bIsStorage && xDest->isStorageElement( aName ) ) ) - xDest->removeElement( aName ); - - if ( pElement->m_bIsStorage ) - { - uno::Reference< embed::XStorage > xSubDest = - xDest->openStorageElement( aName, - embed::ElementModes::WRITE ); - - OSL_ENSURE( xSubDest.is(), "No destination substorage!\n" ); - - if ( !pElement->m_pStorage ) - { - OpenSubStorage( pElement, embed::ElementModes::READ ); - if ( !pElement->m_pStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - pElement->m_pStorage->CopyToStorage( xSubDest, bDirect ); - } - else - { - if ( !pElement->m_pStream ) - { - OpenSubStream( pElement ); - if ( !pElement->m_pStream ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !pElement->m_pStream->IsEncrypted() ) - { - if ( bDirect ) - { - // fill in the properties for the stream - uno::Sequence< beans::PropertyValue > aStrProps(0); - uno::Sequence< beans::PropertyValue > aSrcPkgProps = pElement->m_pStream->GetStreamProperties(); - sal_Int32 nNum = 0; - for ( int ind = 0; ind < aSrcPkgProps.getLength(); ind++ ) - { - if ( aSrcPkgProps[ind].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ) ) - || aSrcPkgProps[ind].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "Compressed" ) ) ) ) - { - aStrProps.realloc( ++nNum ); - aStrProps[nNum-1].Name = aSrcPkgProps[ind].Name; - aStrProps[nNum-1].Value = aSrcPkgProps[ind].Value; - } - } - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - aStrProps.realloc( ++nNum ); - aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ); - aStrProps[nNum-1].Value <<= (sal_Bool)( pElement->m_pStream->UsesCommonEncryption_Impl() ); - } - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - // TODO/LATER: currently the optimization is not active - // uno::Reference< io::XInputStream > xInStream = GetRelInfoStreamForName( ::rtl::OUString() ); // own rels stream - // if ( xInStream.is() ) - // { - // aStrProps.realloc( ++nNum ); - // aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RelationsInfoStream" ) ); - // aStrProps[nNum-1].Value <<= GetSeekableTempCopy( xInStream, m_xFactory ); - // } - - uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY ); - if ( !xRels.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - - xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False ); - } - - uno::Reference< embed::XOptimizedStorage > xOptDest( xDest, uno::UNO_QUERY_THROW ); - uno::Reference < io::XInputStream > xInputToInsert; - - if ( pElement->m_pStream->HasTempFile_Impl() || !pElement->m_pStream->m_xPackageStream.is() ) - { - OSL_ENSURE( pElement->m_pStream->m_xPackageStream.is(), "No package stream!" ); - - // if the stream is modified - the temporary file must be used for insertion - xInputToInsert = pElement->m_pStream->GetTempFileAsInputStream(); - } - else - { - // for now get just nonseekable access to the stream - // TODO/LATER: the raw stream can be used - - xInputToInsert = pElement->m_pStream->m_xPackageStream->getDataStream(); - } - - if ( !xInputToInsert.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - xOptDest->insertStreamElementDirect( aName, xInputToInsert, aStrProps ); - } - else - { - uno::Reference< io::XStream > xSubStr = - xDest->openStreamElement( aName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); - OSL_ENSURE( xSubStr.is(), "No destination substream!\n" ); - - pElement->m_pStream->CopyInternallyTo_Impl( xSubStr ); - } - } - else if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - { - OSL_FAIL( "Encryption is only supported in package storage!\n" ); - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - else if ( pElement->m_pStream->HasCachedEncryptionData() - && ( pElement->m_pStream->IsModified() || pElement->m_pStream->HasWriteOwner_Impl() ) ) - { - ::comphelper::SequenceAsHashMap aCommonEncryptionData; - sal_Bool bHasCommonEncryptionData = sal_False; - try - { - aCommonEncryptionData = GetCommonRootEncryptionData(); - bHasCommonEncryptionData = sal_True; - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - AddLog( rNoEncryptionException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) ); - } - - if ( bHasCommonEncryptionData && ::package::PackageEncryptionDatasEqual( pElement->m_pStream->GetCachedEncryptionData(), aCommonEncryptionData ) ) - { - // If the stream can be opened with the common storage password - // it must be stored with the common storage password as well - uno::Reference< io::XStream > xDestStream = - xDest->openStreamElement( aName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); - - pElement->m_pStream->CopyInternallyTo_Impl( xDestStream ); - - uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW ); - xProps->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ), - uno::Any( (sal_Bool) sal_True ) ); - } - else - { - // the stream is already opened for writing or was changed - uno::Reference< embed::XStorage2 > xDest2( xDest, uno::UNO_QUERY_THROW ); - uno::Reference< io::XStream > xSubStr = - xDest2->openEncryptedStream( aName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE, - pElement->m_pStream->GetCachedEncryptionData().getAsConstNamedValueList() ); - OSL_ENSURE( xSubStr.is(), "No destination substream!\n" ); - - pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedEncryptionData() ); - } - } - else - { - // the stream is not opened at all, so it can be just opened for reading - try - { - // If the stream can be opened with the common storage password - // it must be stored with the common storage password as well - - uno::Reference< io::XStream > xOwnStream = pElement->m_pStream->GetStream( embed::ElementModes::READ, - sal_False ); - uno::Reference< io::XStream > xDestStream = - xDest->openStreamElement( aName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); - OSL_ENSURE( xDestStream.is(), "No destination substream!\n" ); - completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() ); - - uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW ); - xProps->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ), - uno::Any( (sal_Bool) sal_True ) ); - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - AddLog( rWrongPasswordException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) ); - - // If the common storage password does not allow to open the stream - // it could be copyed in raw way, the problem is that the StartKey should be the same - // in the ODF1.2 package, so an invalid package could be produced if the stream - // is copied from ODF1.1 package, where it is allowed to have different StartKeys - uno::Reference< embed::XStorageRawAccess > xRawDest( xDest, uno::UNO_QUERY_THROW ); - uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream(); - xRawDest->insertRawEncrStreamElement( aName, xRawInStream ); - } - } - } -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > OStorage_Impl::GetAllRelationshipsIfAny() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return uno::Sequence< uno::Sequence< beans::StringPair > >(); - - ReadRelInfoIfNecessary(); - - if ( m_nRelInfoStatus == RELINFO_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED ) - return m_aRelInfo; - else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong relinfo stream!" ) ), - uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -void OStorage_Impl::CopyLastCommitTo( const uno::Reference< embed::XStorage >& xNewStor ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_xPackageFolder.is(), "A commited storage is incomplete!\n" ); - if ( !m_xPackageFolder.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OStorage_Impl aTempRepresent( NULL, - embed::ElementModes::READ, - m_xPackageFolder, - m_xPackage, - m_xFactory, - m_nStorageType); - - // TODO/LATER: could use direct copying - aTempRepresent.CopyToStorage( xNewStor, sal_False ); -} - -//----------------------------------------------- -void OStorage_Impl::InsertIntoPackageFolder( const ::rtl::OUString& aName, - const uno::Reference< container::XNameContainer >& xParentPackageFolder ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_xPackageFolder.is(), "An inserted storage is incomplete!\n" ); - uno::Reference< lang::XUnoTunnel > xTunnel( m_xPackageFolder, uno::UNO_QUERY ); - if ( !xTunnel.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - xParentPackageFolder->insertByName( aName, uno::makeAny( xTunnel ) ); - - m_bCommited = sal_False; -} - -//----------------------------------------------- -void OStorage_Impl::Commit() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_bIsModified ) - return; - - // in case of a new empty storage it is possible that the contents are still not read - // ( the storage of course has no contents, but the initialization is postponed till the first use, - // thus if a new storage was created and commited immediatelly it must be initialized here ) - ReadContents(); - - // if storage is commited it should have a valid Package representation - OSL_ENSURE( m_xPackageFolder.is(), "The package representation should exist!\n" ); - if ( !m_xPackageFolder.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OSL_ENSURE( m_nStorageMode & embed::ElementModes::WRITE, - "Commit of readonly storage, should be detected before!\n" ); - - uno::Reference< container::XNameContainer > xNewPackageFolder; - - // here the storage will switch to the temporary package folder - // if the storage was already commited and the parent was not commited after that - // the switch should not be done since the package folder in use is a temporary one; - // it can be detected by m_bCommited flag ( root storage doesn't need temporary representation ) - if ( !m_bCommited && !m_bIsRoot ) - { - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_True; - - xNewPackageFolder = uno::Reference< container::XNameContainer >( - m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY ); - } - else - xNewPackageFolder = m_xPackageFolder; - - // remove replaced removed elements - for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin(); - pDeletedIter != m_aDeletedList.end(); - pDeletedIter++ ) - { - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pDeletedIter)->m_bIsStorage ) - RemoveStreamRelInfo( (*pDeletedIter)->m_aOriginalName ); - - // the removed elements are not in new temporary storage - if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pDeletedIter)->m_aOriginalName ); - delete *pDeletedIter; - *pDeletedIter = NULL; - } - m_aDeletedList.clear(); - - // remove removed elements - SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - while ( pElementIter != m_aChildrenList.end() ) - { - // renamed and inserted elements must be really inserted to package later - // since thay can conflict with removed elements - - if ( (*pElementIter)->m_bIsRemoved ) - { - if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage ) - RemoveStreamRelInfo( (*pElementIter)->m_aOriginalName ); - - // the removed elements are not in new temporary storage - if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); - - SotElement_Impl* pToDelete = *pElementIter; - - pElementIter++; // to let the iterator be valid it should be increased before removing - - m_aChildrenList.remove( pToDelete ); - delete pToDelete; - } - else - pElementIter++; - } - - // there should be no more deleted elements - for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - // if it is a 'duplicate commit' inserted elements must be really inserted to package later - // since thay can conflict with renamed elements - - if ( !(*pElementIter)->m_bIsInserted ) - { - // for now stream is opened in direct mode that means that in case - // storage is commited all the streams from it are commited in current state. - // following two steps are separated to allow easily implement transacted mode - // for streams if we need it in future. - // Only hierarchical access uses transacted streams currently - if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream - && !(*pElementIter)->m_pStream->IsTransacted() ) - (*pElementIter)->m_pStream->Commit(); - - // if the storage was not open, there is no need to commit it ??? - // the storage should be checked that it is commited - if ( (*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStorage && (*pElementIter)->m_pStorage->m_bCommited ) - { - // it's temporary PackageFolder should be inserted instead of current one - // also the new copy of PackageFolder should be used by the children storages - - // the renamed elements are not in new temporary storage - if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); - - (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); - } - else if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream && (*pElementIter)->m_pStream->m_bFlushed ) - { - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - CommitStreamRelInfo( *pElementIter ); - - // the renamed elements are not in new temporary storage - if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); - - (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); - } - else if ( !m_bCommited && !m_bIsRoot ) - { - // the element must be just copied to the new temporary package folder - // the connection with the original package should not be lost just because - // the element is still refered by the folder in the original hierarchy - uno::Any aPackageElement = m_xPackageFolder->getByName( (*pElementIter)->m_aOriginalName ); - xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement ); - } - else if ( (*pElementIter)->m_aName.compareTo( (*pElementIter)->m_aOriginalName ) ) - { - // this is the case when xNewPackageFolder refers to m_xPackageFolder - // in case the name was changed and it is not a changed storage - rename the element - uno::Reference< container::XNamed > xNamed; - uno::Any aPackageElement = xNewPackageFolder->getByName( (*pElementIter)->m_aOriginalName ); - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); - xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement ); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage ) - { - if ( !(*pElementIter)->m_pStream ) - { - OpenSubStream( *pElementIter ); - if ( !(*pElementIter)->m_pStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - CommitStreamRelInfo( *pElementIter ); - } - } - - (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName; - } - } - - for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - // now inserted elements can be inserted to the package - if ( (*pElementIter)->m_bIsInserted ) - { - (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName; - uno::Reference< lang::XUnoTunnel > xNewElement; - - if ( (*pElementIter)->m_bIsStorage ) - { - if ( (*pElementIter)->m_pStorage->m_bCommited ) - { - OSL_ENSURE( (*pElementIter)->m_pStorage, "An inserted storage is incomplete!\n" ); - if ( !(*pElementIter)->m_pStorage ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); - - (*pElementIter)->m_bIsInserted = sal_False; - } - } - else - { - OSL_ENSURE( (*pElementIter)->m_pStream, "An inserted stream is incomplete!\n" ); - if ( !(*pElementIter)->m_pStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !(*pElementIter)->m_pStream->IsTransacted() ) - (*pElementIter)->m_pStream->Commit(); - - if ( (*pElementIter)->m_pStream->m_bFlushed ) - { - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - CommitStreamRelInfo( *pElementIter ); - - (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); - - (*pElementIter)->m_bIsInserted = sal_False; - } - } - } - } - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - // move properties to the destination package folder - uno::Reference< beans::XPropertySet > xProps( xNewPackageFolder, uno::UNO_QUERY ); - if ( !xProps.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), uno::makeAny( m_aMediaType ) ); - xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), uno::makeAny( m_aVersion ) ); - } - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - CommitRelInfo( xNewPackageFolder ); // store own relations and commit complete relations storage - - if ( m_bIsRoot ) - { - uno::Reference< util::XChangesBatch > xChangesBatch( m_xPackage, uno::UNO_QUERY ); - - OSL_ENSURE( xChangesBatch.is(), "Impossible to commit package!\n" ); - if ( !xChangesBatch.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - try - { - xChangesBatch->commitChanges(); - } - catch( const lang::WrappedTargetException& r ) - { - // the wrapped UseBackupException means that the target medium can be corrupted - embed::UseBackupException aException; - if ( r.TargetException >>= aException ) - { - m_xStream = uno::Reference< io::XStream >(); - m_xInputStream = uno::Reference< io::XInputStream >(); - throw aException; - } - - AddLog( aException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - } - else if ( !m_bCommited ) - { - m_xPackageFolder = xNewPackageFolder; - m_bCommited = sal_True; - } - - // after commit the mediatype treated as the correct one - m_bMTFallbackUsed = sal_False; -} - -//----------------------------------------------- -void OStorage_Impl::Revert() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !( m_nStorageMode & embed::ElementModes::WRITE ) ) - return; // nothing to do - - // all the children must be removed - // they will be created later on demand - - SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - while ( pElementIter != m_aChildrenList.end() ) - { - if ( (*pElementIter)->m_bIsInserted ) - { - SotElement_Impl* pToDelete = *pElementIter; - - pElementIter++; // to let the iterator be valid it should be increased before removing - - m_aChildrenList.remove( pToDelete ); - delete pToDelete; - } - else - { - ClearElement( *pElementIter ); - - (*pElementIter)->m_aName = (*pElementIter)->m_aOriginalName; - (*pElementIter)->m_bIsRemoved = sal_False; - - pElementIter++; - } - } - - // return replaced removed elements - for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin(); - pDeletedIter != m_aDeletedList.end(); - pDeletedIter++ ) - { - m_aChildrenList.push_back( (*pDeletedIter) ); - - ClearElement( *pDeletedIter ); - - (*pDeletedIter)->m_aName = (*pDeletedIter)->m_aOriginalName; - (*pDeletedIter)->m_bIsRemoved = sal_False; - } - m_aDeletedList.clear(); - - m_bControlMediaType = sal_False; - m_bControlVersion = sal_False; - - GetStorageProperties(); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - // currently the relations storage is changed only on commit - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_nRelInfoStatus = RELINFO_NO_INIT; - } -} - -//----------------------------------------------- -::comphelper::SequenceAsHashMap OStorage_Impl::GetCommonRootEncryptionData() - throw ( packages::NoEncryptionException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_bIsRoot ) - { - if ( !m_bHasCommonEncryptionData ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return m_aCommonEncryptionData; - } - else - { - if ( !m_pParent ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return m_pParent->GetCommonRootEncryptionData(); - } -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::FindElement( const ::rtl::OUString& rName ) -{ - OSL_ENSURE( rName.getLength(), "Name is empty!" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - ReadContents(); - - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - if ( (*pElementIter)->m_aName == rName && !(*pElementIter)->m_bIsRemoved ) - return *pElementIter; - } - - return NULL; -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::InsertStream( ::rtl::OUString aName, sal_Bool bEncr ) -{ - OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" ); - if ( !m_xPackage.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_False; - uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY ); - - OSL_ENSURE( xNewElement.is(), "Not possible to create a new stream!\n" ); - if ( !xNewElement.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY ); - if ( !xPackageSubStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE || !bEncr, "Only package storage supports encryption!\n" ); - if ( m_nStorageType != embed::StorageFormats::PACKAGE && bEncr ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // the mode is not needed for storage stream internal implementation - SotElement_Impl* pNewElement = InsertElement( aName, sal_False ); - pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, bEncr, m_nStorageType, sal_True ); - - m_aChildrenList.push_back( pNewElement ); - m_bIsModified = sal_True; - m_bBroadcastModified = sal_True; - - return pNewElement; -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::InsertRawStream( ::rtl::OUString aName, const uno::Reference< io::XInputStream >& xInStream ) -{ - // insert of raw stream means insert and commit - OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" ); - if ( !m_xPackage.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY ); - uno::Reference< io::XInputStream > xInStrToInsert = xSeek.is() ? xInStream : - GetSeekableTempCopy( xInStream, GetServiceFactory() ); - - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_False; - uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY ); - - OSL_ENSURE( xNewElement.is(), "Not possible to create a new stream!\n" ); - if ( !xNewElement.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY ); - if ( !xPackageSubStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - xPackageSubStream->setRawStream( xInStrToInsert ); - - // the mode is not needed for storage stream internal implementation - SotElement_Impl* pNewElement = InsertElement( aName, sal_False ); - pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_True, m_nStorageType, sal_False ); - // the stream is inserted and must be treated as a commited one - pNewElement->m_pStream->SetToBeCommited(); - - m_aChildrenList.push_back( pNewElement ); - m_bIsModified = sal_True; - m_bBroadcastModified = sal_True; - - return pNewElement; -} - -//----------------------------------------------- -OStorage_Impl* OStorage_Impl::CreateNewStorageImpl( sal_Int32 nStorageMode ) -{ - OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" ); - if ( !m_xPackage.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_True; - uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY ); - - OSL_ENSURE( xNewElement.is(), "Not possible to create a new storage!\n" ); - if ( !xNewElement.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< container::XNameContainer > xPackageSubFolder( xNewElement, uno::UNO_QUERY ); - if ( !xPackageSubFolder.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OStorage_Impl* pResult = - new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xFactory, m_nStorageType ); - pResult->m_bIsModified = sal_True; - - return pResult; -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::InsertStorage( ::rtl::OUString aName, sal_Int32 nStorageMode ) -{ - SotElement_Impl* pNewElement = InsertElement( aName, sal_True ); - - pNewElement->m_pStorage = CreateNewStorageImpl( nStorageMode ); - - m_aChildrenList.push_back( pNewElement ); - - return pNewElement; -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::InsertElement( ::rtl::OUString aName, sal_Bool bIsStorage ) -{ - OSL_ENSURE( FindElement( aName ) == NULL, "Should not try to insert existing element" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - SotElement_Impl* pDeletedElm = NULL; - - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - if ( (*pElementIter)->m_aName == aName ) - { - OSL_ENSURE( (*pElementIter)->m_bIsRemoved, "Try to insert an element instead of existing one!\n" ); - if ( (*pElementIter)->m_bIsRemoved ) - { - OSL_ENSURE( !(*pElementIter)->m_bIsInserted, "Inserted elements must be deleted immediatelly!\n" ); - pDeletedElm = *pElementIter; - break; - } - } - } - - if ( pDeletedElm ) - { - if ( pDeletedElm->m_bIsStorage ) - OpenSubStorage( pDeletedElm, embed::ElementModes::READWRITE ); - else - OpenSubStream( pDeletedElm ); - - m_aChildrenList.remove( pDeletedElm ); // correct usage of list ??? - m_aDeletedList.push_back( pDeletedElm ); - } - - // create new element - return new SotElement_Impl( aName, bIsStorage, sal_True ); -} - -//----------------------------------------------- -void OStorage_Impl::OpenSubStorage( SotElement_Impl* pElement, sal_Int32 nStorageMode ) -{ - OSL_ENSURE( pElement, "pElement is not set!\n" ); - OSL_ENSURE( pElement->m_bIsStorage, "Storage flag is not set!\n" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !pElement->m_pStorage ) - { - OSL_ENSURE( !pElement->m_bIsInserted, "Inserted element must be created already!\n" ); - - uno::Reference< lang::XUnoTunnel > xTunnel; - m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel; - if ( !xTunnel.is() ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< container::XNameContainer > xPackageSubFolder( xTunnel, uno::UNO_QUERY ); - - OSL_ENSURE( xPackageSubFolder.is(), "Can not get XNameContainer interface from folder!\n" ); - - if ( !xPackageSubFolder.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - pElement->m_pStorage = new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xFactory, m_nStorageType ); - } -} - -//----------------------------------------------- -void OStorage_Impl::OpenSubStream( SotElement_Impl* pElement ) -{ - OSL_ENSURE( pElement, "pElement is not set!\n" ); - OSL_ENSURE( !pElement->m_bIsStorage, "Storage flag is set!\n" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !pElement->m_pStream ) - { - OSL_ENSURE( !pElement->m_bIsInserted, "Inserted element must be created already!\n" ); - - uno::Reference< lang::XUnoTunnel > xTunnel; - m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel; - if ( !xTunnel.is() ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xTunnel, uno::UNO_QUERY ); - if ( !xPackageSubStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // the stream can never be inserted here, because inserted stream element holds the stream till commit or destruction - pElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_False, m_nStorageType, sal_False, GetRelInfoStreamForName( pElement->m_aOriginalName ) ); - } -} - -//----------------------------------------------- -uno::Sequence< ::rtl::OUString > OStorage_Impl::GetElementNames() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - ReadContents(); - - sal_uInt32 nSize = m_aChildrenList.size(); - uno::Sequence< ::rtl::OUString > aElementNames( nSize ); - - sal_uInt32 nInd = 0; - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - if ( !(*pElementIter)->m_bIsRemoved ) - aElementNames[nInd++] = (*pElementIter)->m_aName; - } - - aElementNames.realloc( nInd ); - return aElementNames; -} - -//----------------------------------------------- -void OStorage_Impl::RemoveElement( SotElement_Impl* pElement ) -{ - OSL_ENSURE( pElement, "Element must be provided!" ); - - if ( !pElement ) - return; - - if ( (pElement->m_pStorage && ( pElement->m_pStorage->m_pAntiImpl || !pElement->m_pStorage->m_aReadOnlyWrapList.empty() )) - || (pElement->m_pStream && ( pElement->m_pStream->m_pAntiImpl || !pElement->m_pStream->m_aInputStreamsList.empty() )) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Access denied - - if ( pElement->m_bIsInserted ) - { - m_aChildrenList.remove( pElement ); - delete pElement; // ??? - } - else - { - pElement->m_bIsRemoved = sal_True; - ClearElement( pElement ); - } - - // TODO/OFOPXML: the rel stream should be removed as well -} - -//----------------------------------------------- -void OStorage_Impl::ClearElement( SotElement_Impl* pElement ) -{ - if ( pElement->m_pStorage ) - { - delete pElement->m_pStorage; - pElement->m_pStorage = NULL; - } - - if ( pElement->m_pStream ) - { - delete pElement->m_pStream; - pElement->m_pStream = NULL; - } -} - -//----------------------------------------------- -void OStorage_Impl::CloneStreamElement( const ::rtl::OUString& aStreamName, - sal_Bool bEncryptionDataProvided, - const ::comphelper::SequenceAsHashMap& aEncryptionData, - uno::Reference< io::XStream >& xTargetStream ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - SotElement_Impl *pElement = FindElement( aStreamName ); - if ( !pElement ) - { - // element does not exist, throw exception - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - } - else if ( pElement->m_bIsStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !pElement->m_pStream ) - OpenSubStream( pElement ); - - if ( pElement->m_pStream && pElement->m_pStream->m_xPackageStream.is() ) - { - // the existence of m_pAntiImpl of the child is not interesting, - // the copy will be created internally - - // usual copying is not applicable here, only last flushed version of the - // child stream should be used for copiing. Probably the childs m_xPackageStream - // can be used as a base of a new stream, that would be copied to result - // storage. The only problem is that some package streams can be accessed from outside - // at the same time ( now solwed by wrappers that remember own position ). - - if ( bEncryptionDataProvided ) - pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aEncryptionData ); - else - pElement->m_pStream->GetCopyOfLastCommit( xTargetStream ); - } - else - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error -} - -//----------------------------------------------- -void OStorage_Impl::RemoveStreamRelInfo( const ::rtl::OUString& aOriginalName ) -{ - // this method should be used only in OStorage_Impl::Commit() method - // the aOriginalName can be empty, in this case the storage relation info should be removed - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_xRelStorage.is() ) - { - ::rtl::OUString aRelStreamName = aOriginalName; - aRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ); - - if ( m_xRelStorage->hasByName( aRelStreamName ) ) - m_xRelStorage->removeElement( aRelStreamName ); - } -} - -//----------------------------------------------- -void OStorage_Impl::CreateRelStorage() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return; - - if ( !m_xRelStorage.is() ) - { - if ( !m_pRelStorElement ) - { - m_pRelStorElement = new SotElement_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ), sal_True, sal_True ); - m_pRelStorElement->m_pStorage = CreateNewStorageImpl( embed::ElementModes::WRITE ); - if ( m_pRelStorElement->m_pStorage ) - m_pRelStorElement->m_pStorage->m_pParent = NULL; // the relation storage is completely controlled by parent - } - - if ( !m_pRelStorElement->m_pStorage ) - OpenSubStorage( m_pRelStorElement, embed::ElementModes::WRITE ); - - if ( !m_pRelStorElement->m_pStorage ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OStorage* pResultStorage = new OStorage( m_pRelStorElement->m_pStorage, sal_False ); - m_xRelStorage = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage ); - } -} - -//----------------------------------------------- -void OStorage_Impl::CommitStreamRelInfo( SotElement_Impl* pStreamElement ) -{ - // this method should be used only in OStorage_Impl::Commit() method - - // the stream element must be provided - if ( !pStreamElement ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && pStreamElement->m_pStream ) - { - OSL_ENSURE( pStreamElement->m_aName.getLength(), "The name must not be empty!\n" ); - - if ( !m_xRelStorage.is() ) - { - // Create new rels storage, this is commit scenario so it must be possible - CreateRelStorage(); - } - - pStreamElement->m_pStream->CommitStreamRelInfo( m_xRelStorage, pStreamElement->m_aOriginalName, pStreamElement->m_aName ); - } -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > OStorage_Impl::GetRelInfoStreamForName( const ::rtl::OUString& aName ) -{ - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - ReadContents(); - if ( m_xRelStorage.is() ) - { - ::rtl::OUString aRelStreamName = aName; - aRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ); - if ( m_xRelStorage->hasByName( aRelStreamName ) ) - { - uno::Reference< io::XStream > xStream = m_xRelStorage->openStreamElement( aRelStreamName, embed::ElementModes::READ ); - if ( xStream.is() ) - return xStream->getInputStream(); - } - } - } - - return uno::Reference< io::XInputStream >(); -} - -//----------------------------------------------- -void OStorage_Impl::CommitRelInfo( const uno::Reference< container::XNameContainer >& xNewPackageFolder ) -{ - // this method should be used only in OStorage_Impl::Commit() method - ::rtl::OUString aRelsStorName( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ); - - if ( !xNewPackageFolder.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - if ( m_nRelInfoStatus == RELINFO_BROKEN || m_nRelInfoStatus == RELINFO_CHANGED_BROKEN ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_nRelInfoStatus == RELINFO_CHANGED - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - if ( m_nRelInfoStatus == RELINFO_CHANGED ) - { - if ( m_aRelInfo.getLength() ) - { - CreateRelStorage(); - - uno::Reference< io::XStream > xRelsStream = - m_xRelStorage->openStreamElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ), - embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE ); - - uno::Reference< io::XOutputStream > xOutStream = xRelsStream->getOutputStream(); - if ( !xOutStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - ::comphelper::OFOPXMLHelper::WriteRelationsInfoSequence( xOutStream, m_aRelInfo, m_xFactory ); - - // set the mediatype - uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW ); - xPropSet->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), - uno::makeAny( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) ); - - m_nRelInfoStatus = RELINFO_READ; - } - else if ( m_xRelStorage.is() ) - RemoveStreamRelInfo( ::rtl::OUString() ); // remove own rel info - } - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - CreateRelStorage(); - - uno::Reference< io::XStream > xRelsStream = - m_xRelStorage->openStreamElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ), - embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE ); - - uno::Reference< io::XOutputStream > xOutputStream = xRelsStream->getOutputStream(); - if ( !xOutputStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XSeekable > xSeek( m_xNewRelInfoStream, uno::UNO_QUERY_THROW ); - xSeek->seek( 0 ); - ::comphelper::OStorageHelper::CopyInputToOutput( m_xNewRelInfoStream, xOutputStream ); - - // set the mediatype - uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW ); - xPropSet->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), - uno::makeAny( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) ); - - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_nRelInfoStatus = RELINFO_NO_INIT; - } - else - m_nRelInfoStatus = RELINFO_READ; - } - } - - if ( m_xRelStorage.is() ) - { - if ( m_xRelStorage->hasElements() ) - { - uno::Reference< embed::XTransactedObject > xTrans( m_xRelStorage, uno::UNO_QUERY_THROW ); - if ( xTrans.is() ) - xTrans->commit(); - } - - if ( xNewPackageFolder.is() && xNewPackageFolder->hasByName( aRelsStorName ) ) - xNewPackageFolder->removeByName( aRelsStorName ); - - if ( !m_xRelStorage->hasElements() ) - { - // the empty relations storage should not be created - delete m_pRelStorElement; - m_pRelStorElement = NULL; - m_xRelStorage = uno::Reference< embed::XStorage >(); - } - else if ( m_pRelStorElement && m_pRelStorElement->m_pStorage && xNewPackageFolder.is() ) - m_pRelStorElement->m_pStorage->InsertIntoPackageFolder( aRelsStorName, xNewPackageFolder ); - } - } -} - -//===================================================== -// OStorage implementation -//===================================================== - -//----------------------------------------------- -OStorage::OStorage( uno::Reference< io::XInputStream > xInputStream, - sal_Int32 nMode, - uno::Sequence< beans::PropertyValue > xProperties, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_pImpl( new OStorage_Impl( xInputStream, nMode, xProperties, xFactory, nStorageType ) ) -{ - m_pImpl->m_pAntiImpl = this; - m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, sal_False ); -} - -//----------------------------------------------- -OStorage::OStorage( uno::Reference< io::XStream > xStream, - sal_Int32 nMode, - uno::Sequence< beans::PropertyValue > xProperties, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_pImpl( new OStorage_Impl( xStream, nMode, xProperties, xFactory, nStorageType ) ) -{ - m_pImpl->m_pAntiImpl = this; - m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, sal_False ); -} - -//----------------------------------------------- -OStorage::OStorage( OStorage_Impl* pImpl, sal_Bool bReadOnlyWrap ) -: m_pImpl( pImpl ) -{ - // this call can be done only from OStorage_Impl implementation to create child storage - OSL_ENSURE( m_pImpl && m_pImpl->m_rMutexRef.Is(), "The provided pointer & mutex MUST NOT be empty!\n" ); - - m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, bReadOnlyWrap ); - - OSL_ENSURE( ( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) == embed::ElementModes::WRITE || - m_pData->m_bReadOnlyWrap, - "The wrapper can not allow writing in case implementation does not!\n" ); - - if ( !bReadOnlyWrap ) - m_pImpl->m_pAntiImpl = this; -} - -//----------------------------------------------- -OStorage::~OStorage() -{ - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - if ( m_pImpl ) - { - m_refCount++; // to call dispose - try { - dispose(); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) ); - } - } - } - - if ( m_pData ) - { - if ( m_pData->m_pSubElDispListener ) - { - m_pData->m_pSubElDispListener->release(); - m_pData->m_pSubElDispListener = NULL; - } - - if ( m_pData->m_pTypeCollection ) - { - delete m_pData->m_pTypeCollection; - m_pData->m_pTypeCollection = NULL; - } - - delete m_pData; - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::InternalDispose( sal_Bool bNotifyImpl ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::InternalDispose" ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - // the source object is also a kind of locker for the current object - // since the listeners could dispose the object while being notified - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - m_pData->m_aListenersContainer.disposeAndClear( aSource ); - - if ( m_pData->m_bReadOnlyWrap ) - { - OSL_ENSURE( !m_pData->m_aOpenSubComponentsList.size() || m_pData->m_pSubElDispListener, - "If any subelements are open the listener must exist!\n" ); - - if ( m_pData->m_pSubElDispListener ) - { - m_pData->m_pSubElDispListener->OwnerIsDisposed(); - - // iterate through m_pData->m_aOpenSubComponentsList - // deregister m_pData->m_pSubElDispListener and dispose all of them - if ( !m_pData->m_aOpenSubComponentsList.empty() ) - { - for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin(); - pCompIter != m_pData->m_aOpenSubComponentsList.end(); pCompIter++ ) - { - uno::Reference< lang::XComponent > xTmp = (*pCompIter); - if ( xTmp.is() ) - { - xTmp->removeEventListener( uno::Reference< lang::XEventListener >( - static_cast< lang::XEventListener* >( m_pData->m_pSubElDispListener ) ) ); - - try { - xTmp->dispose(); - } catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - } - - m_pData->m_aOpenSubComponentsList.clear(); - } - } - - if ( bNotifyImpl ) - m_pImpl->RemoveReadOnlyWrap( *this ); - } - else - { - m_pImpl->m_pAntiImpl = NULL; - - if ( bNotifyImpl ) - { - if ( m_pData->m_bIsRoot ) - delete m_pImpl; - else - { - // the noncommited changes for the storage must be removed - m_pImpl->Revert(); - } - } - } - - m_pImpl = NULL; -} - -//----------------------------------------------- -void OStorage::ChildIsDisposed( const uno::Reference< uno::XInterface >& xChild ) -{ - // this method can only be called by child disposing listener - - // this method must not contain any locking - // the locking is done in the listener - - if ( !m_pData->m_aOpenSubComponentsList.empty() ) - { - for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin(); - pCompIter != m_pData->m_aOpenSubComponentsList.end(); ) - { - uno::Reference< lang::XComponent > xTmp = (*pCompIter); - if ( !xTmp.is() || xTmp == xChild ) - { - WeakComponentList::iterator pIterToRemove = pCompIter; - pCompIter++; - m_pData->m_aOpenSubComponentsList.erase( pIterToRemove ); - } - else - pCompIter++; - } - } -} - -//----------------------------------------------- -void OStorage::BroadcastModifiedIfNecessary() -{ - // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !m_pImpl->m_bBroadcastModified ) - return; - - m_pImpl->m_bBroadcastModified = sal_False; - - OSL_ENSURE( !m_pData->m_bReadOnlyWrap, "The storage can not be modified at all!\n" ); - - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - - ::cppu::OInterfaceContainerHelper* pContainer = - m_pData->m_aListenersContainer.getContainer( - ::getCppuType( ( const uno::Reference< util::XModifyListener >*) NULL ) ); - if ( pContainer ) - { - ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); - while ( pIterator.hasMoreElements( ) ) - { - ( ( util::XModifyListener* )pIterator.next( ) )->modified( aSource ); - } - } -} - -//----------------------------------------------- -void OStorage::BroadcastTransaction( sal_Int8 nMessage ) -/* - 1 - preCommit - 2 - commited - 3 - preRevert - 4 - reverted -*/ -{ - // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - OSL_ENSURE( !m_pData->m_bReadOnlyWrap, "The storage can not be modified at all!\n" ); - - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - - ::cppu::OInterfaceContainerHelper* pContainer = - m_pData->m_aListenersContainer.getContainer( - ::getCppuType( ( const uno::Reference< embed::XTransactionListener >*) NULL ) ); - if ( pContainer ) - { - ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); - while ( pIterator.hasMoreElements( ) ) - { - OSL_ENSURE( nMessage >= 1 && nMessage <= 4, "Wrong internal notification code is used!\n" ); - - switch( nMessage ) - { - case STOR_MESS_PRECOMMIT: - ( ( embed::XTransactionListener* )pIterator.next( ) )->preCommit( aSource ); - break; - case STOR_MESS_COMMITED: - ( ( embed::XTransactionListener* )pIterator.next( ) )->commited( aSource ); - break; - case STOR_MESS_PREREVERT: - ( ( embed::XTransactionListener* )pIterator.next( ) )->preRevert( aSource ); - break; - case STOR_MESS_REVERTED: - ( ( embed::XTransactionListener* )pIterator.next( ) )->reverted( aSource ); - break; - } - } - } -} - -//----------------------------------------------- -SotElement_Impl* OStorage::OpenStreamElement_Impl( const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, sal_Bool bEncr ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - OSL_ENSURE( !m_pData->m_bReadOnlyWrap || ( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE, - "An element can not be opened for writing in readonly storage!\n" ); - - SotElement_Impl *pElement = m_pImpl->FindElement( aStreamName ); - if ( !pElement ) - { - // element does not exist, check if creation is allowed - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) - || (( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ) - || ( nOpenMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - - // create a new StreamElement and insert it into the list - pElement = m_pImpl->InsertStream( aStreamName, bEncr ); - } - else if ( pElement->m_bIsStorage ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - OSL_ENSURE( pElement, "In case element can not be created an exception must be thrown!" ); - - if ( !pElement->m_pStream ) - m_pImpl->OpenSubStream( pElement ); - - if ( !pElement->m_pStream ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return pElement; -} - -//----------------------------------------------- -void OStorage::MakeLinkToSubComponent_Impl( const uno::Reference< lang::XComponent >& xComponent ) -{ - if ( !xComponent.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !m_pData->m_pSubElDispListener ) - { - m_pData->m_pSubElDispListener = new OChildDispListener_Impl( *this ); - m_pData->m_pSubElDispListener->acquire(); - } - - xComponent->addEventListener( uno::Reference< lang::XEventListener >( - static_cast< ::cppu::OWeakObject* >( m_pData->m_pSubElDispListener ), uno::UNO_QUERY ) ); - - m_pData->m_aOpenSubComponentsList.push_back( xComponent ); -} - -//____________________________________________________________________________________________________ -// XInterface -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - uno::Any aReturn; - - // common interfaces - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<lang::XTypeProvider*> ( this ) - , static_cast<embed::XStorage*> ( this ) - , static_cast<embed::XStorage2*> ( this ) - , static_cast<embed::XTransactedObject*> ( this ) - , static_cast<embed::XTransactionBroadcaster*> ( this ) - , static_cast<util::XModifiable*> ( this ) - , static_cast<container::XNameAccess*> ( this ) - , static_cast<container::XElementAccess*> ( this ) - , static_cast<lang::XComponent*> ( this ) - , static_cast<beans::XPropertySet*> ( this ) - , static_cast<embed::XOptimizedStorage*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XHierarchicalStorageAccess*> ( this ) - , static_cast<embed::XHierarchicalStorageAccess2*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - if ( m_pData->m_bIsRoot ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XStorageRawAccess*> ( this ) - , static_cast<embed::XEncryptionProtectedSource*> ( this ) - , static_cast<embed::XEncryptionProtectedSource2*> ( this ) - , static_cast<embed::XEncryptionProtectedStorage*> ( this ) ); - } - else - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XStorageRawAccess*> ( this ) ); - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XRelationshipAccess*> ( this ) ); - } - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - return OWeakObject::queryInterface( rType ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::acquire() throw() -{ - OWeakObject::acquire(); -} - -//----------------------------------------------- -void SAL_CALL OStorage::release() throw() -{ - OWeakObject::release(); -} - -//____________________________________________________________________________________________________ -// XTypeProvider -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes() - throw( uno::RuntimeException ) -{ - if ( m_pData->m_pTypeCollection == NULL ) - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( m_pData->m_pTypeCollection == NULL ) - { - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - if ( m_pData->m_bIsRoot ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - } - } - - return m_pData->m_pTypeCollection->getTypes() ; -} - -namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } - -//----------------------------------------------- -uno::Sequence< sal_Int8 > SAL_CALL OStorage::getImplementationId() - throw( uno::RuntimeException ) -{ - ::cppu::OImplementationId &rID = lcl_ImplId::get(); - return rID.getImplementationId(); -} - -//____________________________________________________________________________________________________ -// XStorage -//____________________________________________________________________________________________________ - - -//----------------------------------------------- -void SAL_CALL OStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest ) - throw ( embed::InvalidStorageException, - io::IOException, - lang::IllegalArgumentException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyToStorage" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - try { - m_pImpl->CopyToStorage( xDest, sal_False ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy storage!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::openStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openStreamElement" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name - - if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - uno::Reference< io::XStream > xResult; - try - { - SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_False ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - xResult = pElement->m_pStream->GetStream( nOpenMode, sal_False ); - OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" ); - - if ( m_pData->m_bReadOnlyWrap ) - { - // before the storage disposes the stream it must deregister itself as listener - uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY ); - if ( !xStreamComponent.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - MakeLinkToSubComponent_Impl( xStreamComponent ); - } - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open stream element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); - - return xResult; -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const ::rtl::OUString& aPass ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStreamElement" ); - - return openEncryptedStream( aStreamName, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); -} - -//----------------------------------------------- -uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement( - const ::rtl::OUString& aStorName, sal_Int32 nStorageMode ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openStorageElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name - - if ( ( nStorageMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) - && !( nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - // it's allways possible to read written storage in this implementation - nStorageMode |= embed::ElementModes::READ; - - uno::Reference< embed::XStorage > xResult; - try - { - SotElement_Impl *pElement = m_pImpl->FindElement( aStorName ); - if ( !pElement ) - { - // element does not exist, check if creation is allowed - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) - || (( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ) - || ( nStorageMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - - // create a new StorageElement and insert it into the list - pElement = m_pImpl->InsertStorage( aStorName, nStorageMode ); - } - else if ( !pElement->m_bIsStorage ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - else if ( pElement->m_pStorage ) - { - // storage has already been opened; it may be opened another time, if it the mode allows to do so - if ( pElement->m_pStorage->m_pAntiImpl ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - } - else if ( !pElement->m_pStorage->m_aReadOnlyWrapList.empty() - && ( nStorageMode & embed::ElementModes::WRITE ) ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - } - else - { - // in case parent storage allows writing the readonly mode of the child storage is - // virtual, that means that it is just enough to change the flag to let it be writable - // and since there is no AntiImpl nobody should be notified about it - pElement->m_pStorage->m_nStorageMode = nStorageMode | embed::ElementModes::READ; - - if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) ) - { - for ( SotElementList_Impl::iterator pElementIter = pElement->m_pStorage->m_aChildrenList.begin(); - pElementIter != pElement->m_pStorage->m_aChildrenList.end(); ) - { - SotElement_Impl* pElementToDel = (*pElementIter); - pElementIter++; - - m_pImpl->RemoveElement( pElementToDel ); - } - } - } - } - - if ( !pElement->m_pStorage ) - m_pImpl->OpenSubStorage( pElement, nStorageMode ); - - if ( !pElement->m_pStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error - - sal_Bool bReadOnlyWrap = ( ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ); - OStorage* pResultStorage = new OStorage( pElement->m_pStorage, bReadOnlyWrap ); - xResult = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage ); - - if ( bReadOnlyWrap ) - { - // Before this call is done the object must be refcounted already - pElement->m_pStorage->SetReadOnlyWrap( *pResultStorage ); - - // before the storage disposes the stream it must deregister itself as listener - uno::Reference< lang::XComponent > xStorageComponent( xResult, uno::UNO_QUERY ); - if ( !xStorageComponent.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - MakeLinkToSubComponent_Impl( xStorageComponent ); - } - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open storage!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return xResult; -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::cloneStreamElement( const ::rtl::OUString& aStreamName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneStreamElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name - - try - { - uno::Reference< io::XStream > xResult; - m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xResult ); - if ( !xResult.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return xResult; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStreamElement( - const ::rtl::OUString& aStreamName, - const ::rtl::OUString& aPass ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStreamElement" ); - - return cloneEncryptedStream( aStreamName, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyLastCommitTo( - const uno::Reference< embed::XStorage >& xTargetStorage ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyLastCommitTo" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - try - { - m_pImpl->CopyLastCommitTo( xTargetStorage ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy last commit version!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyStorageElementLastCommitTo( - const ::rtl::OUString& aStorName, - const uno::Reference< embed::XStorage >& xTargetStorage ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyStorageElementLastCommitTo" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name - - // it's allways possible to read written storage in this implementation - sal_Int32 nStorageMode = embed::ElementModes::READ; - - try - { - SotElement_Impl *pElement = m_pImpl->FindElement( aStorName ); - if ( !pElement ) - { - // element does not exist, throw exception - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - } - else if ( !pElement->m_bIsStorage ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !pElement->m_pStorage ) - m_pImpl->OpenSubStorage( pElement, nStorageMode ); - - uno::Reference< embed::XStorage > xResult; - if ( pElement->m_pStorage ) - { - // the existence of m_pAntiImpl of the child is not interesting, - // the copy will be created internally - - pElement->m_pStorage->CopyLastCommitTo( xTargetStorage ); - } - else - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy last commit element version!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::isStreamElement( const ::rtl::OUString& aElementName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable name - - SotElement_Impl* pElement = NULL; - - try - { - pElement = m_pImpl->FindElement( aElementName ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't detect whether it is a stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - return !pElement->m_bIsStorage; -} - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::isStorageElement( const ::rtl::OUString& aElementName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - SotElement_Impl* pElement = NULL; - - try - { - pElement = m_pImpl->FindElement( aElementName ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "can't detect whether it is a storage" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - return pElement->m_bIsStorage; -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeElement( const ::rtl::OUString& aElementName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeElement" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - m_pImpl->RemoveElement( pElement ); - - m_pImpl->m_bIsModified = sal_True; - m_pImpl->m_bBroadcastModified = sal_True; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't remove element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); -} - -//----------------------------------------------- -void SAL_CALL OStorage::renameElement( const ::rtl::OUString& aElementName, const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::renameElement" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) - || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) - || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // TODO: unacceptable element name - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pRefElement = m_pImpl->FindElement( aNewName ); - if ( pRefElement ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - pElement->m_aName = aNewName; - - m_pImpl->m_bIsModified = sal_True; - m_pImpl->m_bBroadcastModified = sal_True; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't rename element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyElementTo( const ::rtl::OUString& aElementName, - const uno::Reference< embed::XStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyElementTo" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) - || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !xDest.is() ) - // || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) - || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY ); - if ( !xNameAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( xNameAccess->hasByName( aNewName ) ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_pImpl->CopyStorageElement( pElement, xDest, aNewName, sal_False ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - - -//----------------------------------------------- -void SAL_CALL OStorage::moveElementTo( const ::rtl::OUString& aElementName, - const uno::Reference< embed::XStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::moveElementTo" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) - || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) - || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY ); - if ( !xNameAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( xNameAccess->hasByName( aNewName ) ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_pImpl->CopyStorageElement( pElement, xDest, aNewName, sal_False ); - - m_pImpl->RemoveElement( pElement ); - - m_pImpl->m_bIsModified = sal_True; - m_pImpl->m_bBroadcastModified = sal_True; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't move element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); -} - -//____________________________________________________________________________________________________ -// XStorage2 -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStream( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStream" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - packages::NoEncryptionException(); - - if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - if ( !aEncryptionData.getLength() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 ); - - uno::Reference< io::XStream > xResult; - try - { - SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_True ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - xResult = pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_False ); - OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" ); - - if ( m_pData->m_bReadOnlyWrap ) - { - // before the storage disposes the stream it must deregister itself as listener - uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY ); - if ( !xStreamComponent.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - MakeLinkToSubComponent_Impl( xStreamComponent ); - } - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - m_pImpl->AddLog( rNoEncryptionException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open encrypted stream stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); - - return xResult; -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStream( - const ::rtl::OUString& aStreamName, - const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStream" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - packages::NoEncryptionException(); - - if ( !aEncryptionData.getLength() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - try - { - uno::Reference< io::XStream > xResult; - m_pImpl->CloneStreamElement( aStreamName, sal_True, aEncryptionData, xResult ); - if ( !xResult.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return xResult; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - m_pImpl->AddLog( rNoEncryptionException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone encrypted stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - - -//____________________________________________________________________________________________________ -// XStorageRawAccess -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OStorage::getPlainRawStreamElement( - const ::rtl::OUString& sStreamName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getPlainRawStreamElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface is not supported and must not be accessible - - if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - uno::Reference < io::XInputStream > xTempIn; - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !pElement->m_pStream ) - { - m_pImpl->OpenSubStream( pElement ); - if ( !pElement->m_pStream ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetPlainRawInStream(); - if ( !xRawInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference < io::XOutputStream > xTempOut( - m_pImpl->GetServiceFactory()->createInstance ( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), - uno::UNO_QUERY ); - xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY ); - uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY ); - - if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // Copy temporary file to a new one - ::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut ); - xTempOut->closeOutput(); - xSeek->seek( 0 ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get plain raw stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return xTempIn; -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OStorage::getRawEncrStreamElement( - const ::rtl::OUString& sStreamName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getRawEncrStreamElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - uno::Reference < io::XInputStream > xTempIn; - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !pElement->m_pStream ) - { - m_pImpl->OpenSubStream( pElement ); - if ( !pElement->m_pStream ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !pElement->m_pStream->IsEncrypted() ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream(); - if ( !xRawInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference < io::XOutputStream > xTempOut( - m_pImpl->GetServiceFactory()->createInstance ( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), - uno::UNO_QUERY ); - xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY ); - uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY ); - - if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // Copy temporary file to a new one - ::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut ); - xTempOut->closeOutput(); - xSeek->seek( 0 ); - - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - m_pImpl->AddLog( rNoEncryptionException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get raw stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return xTempIn; -} - -//----------------------------------------------- -void SAL_CALL OStorage::insertRawEncrStreamElement( const ::rtl::OUString& aStreamName, - const uno::Reference< io::XInputStream >& xInStream ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoRawFormatException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::insertRawEncrStreamElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !xInStream.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName ); - if ( pElement ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_pImpl->InsertRawStream( aStreamName, xInStream ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::NoRawFormatException& rNoRawFormatException ) - { - m_pImpl->AddLog( rNoRawFormatException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't insert raw stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//____________________________________________________________________________________________________ -// XTransactedObject -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OStorage::commit() - throw ( io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::commit" ); - - uno::Reference< util::XModifiable > xParentModif; - - try { - BroadcastTransaction( STOR_MESS_PRECOMMIT ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - - m_pImpl->Commit(); // the root storage initiates the storing to source - - // when the storage is commited the parent is modified - if ( m_pImpl->m_pParent && m_pImpl->m_pParent->m_pAntiImpl ) - xParentModif = (util::XModifiable*)m_pImpl->m_pParent->m_pAntiImpl; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Problems on commit!" ) ), - uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), - aCaught ); - } - - setModified( sal_False ); - if ( xParentModif.is() ) - xParentModif->setModified( sal_True ); - - BroadcastTransaction( STOR_MESS_COMMITED ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::revert() - throw ( io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::revert" ); - - // the method removes all the changes done after last commit - - BroadcastTransaction( STOR_MESS_PREREVERT ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - for ( SotElementList_Impl::iterator pElementIter = m_pImpl->m_aChildrenList.begin(); - pElementIter != m_pImpl->m_aChildrenList.end(); pElementIter++ ) - { - if ( ((*pElementIter)->m_pStorage - && ( (*pElementIter)->m_pStorage->m_pAntiImpl || !(*pElementIter)->m_pStorage->m_aReadOnlyWrapList.empty() )) - || ((*pElementIter)->m_pStream - && ( (*pElementIter)->m_pStream->m_pAntiImpl || !(*pElementIter)->m_pStream->m_aInputStreamsList.empty()) ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - } - - if ( m_pData->m_bReadOnlyWrap || !m_pImpl->m_bListCreated ) - return; // nothing to do - - try { - m_pImpl->Revert(); - m_pImpl->m_bIsModified = sal_False; - m_pImpl->m_bBroadcastModified = sal_True; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Problems on revert!" ) ), - uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), - aCaught ); - } - - aGuard.clear(); - - setModified( sal_False ); - BroadcastTransaction( STOR_MESS_REVERTED ); -} - -//____________________________________________________________________________________________________ -// XTransactionBroadcaster -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OStorage::addTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0), - aListener ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0), - aListener ); -} - -//____________________________________________________________________________________________________ -// XModifiable -// TODO: if there will be no demand on this interface it will be removed from implementation, -// I do not want to remove it now since it is still possible that it will be inserted -// to the service back. -//____________________________________________________________________________________________________ - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::isModified() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - return m_pImpl->m_bIsModified; -} - - -//----------------------------------------------- -void SAL_CALL OStorage::setModified( sal_Bool bModified ) - throw ( beans::PropertyVetoException, - uno::RuntimeException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_bReadOnlyWrap ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - if ( m_pImpl->m_bIsModified != bModified ) - m_pImpl->m_bIsModified = bModified; - - aGuard.clear(); - if ( bModified ) - { - m_pImpl->m_bBroadcastModified = sal_True; - BroadcastModifiedIfNecessary(); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::addModifyListener( - const uno::Reference< util::XModifyListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.addInterface( - ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), aListener ); -} - - -//----------------------------------------------- -void SAL_CALL OStorage::removeModifyListener( - const uno::Reference< util::XModifyListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.removeInterface( - ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), aListener ); -} - -//____________________________________________________________________________________________________ -// XNameAccess -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Any SAL_CALL OStorage::getByName( const ::rtl::OUString& aName ) - throw ( container::NoSuchElementException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getByName" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name - - uno::Any aResult; - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( pElement->m_bIsStorage ) - aResult <<= openStorageElement( aName, embed::ElementModes::READ ); - else - aResult <<= openStreamElement( aName, embed::ElementModes::READ ); - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::WrappedTargetException& rWrappedTargetException ) - { - m_pImpl->AddLog( rWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - return aResult; -} - - -//----------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OStorage::getElementNames() - throw ( uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getElementNames" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - try - { - return m_pImpl->GetElementNames(); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } -} - - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::hasByName( const ::rtl::OUString& aName ) - throw ( uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::hasByName" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aName.getLength() ) - return sal_False; - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - return sal_False; - - SotElement_Impl* pElement = NULL; - try - { - pElement = m_pImpl->FindElement( aName ); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - return ( pElement != NULL ); -} - - -//----------------------------------------------- -uno::Type SAL_CALL OStorage::getElementType() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - // it is a multitype container - return uno::Type(); -} - - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::hasElements() - throw ( uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::hasElements" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - try - { - return ( m_pImpl->GetChildrenList().size() != 0 ); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } -} - - -//____________________________________________________________________________________________________ -// XComponent -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OStorage::dispose() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - try - { - InternalDispose( sal_True ); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::addEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.addInterface( - ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.removeInterface( - ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener ); -} - -//____________________________________________________________________________________________________ -// XEncryptionProtectedSource -//____________________________________________________________________________________________________ - -void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass ) - throw ( uno::RuntimeException, - io::IOException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionPassword" ); - setEncryptionData( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeEncryption() - throw ( uno::RuntimeException, - io::IOException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeEncryption" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - - OSL_ENSURE( m_pData->m_bIsRoot, "removeEncryption() method is not available for nonroot storages!\n" ); - if ( m_pData->m_bIsRoot ) - { - try { - m_pImpl->ReadContents(); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - // TODO: check if the password is valid - // update all streams that was encrypted with old password - - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); - try - { - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); - - m_pImpl->m_bHasCommonEncryptionData = sal_False; - m_pImpl->m_aCommonEncryptionData.clear(); - } - catch( const uno::RuntimeException& rRException ) - { - m_pImpl->AddLog( rRException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - OSL_FAIL( "The call must not fail, it is pretty simple!" ); - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } -} - -//____________________________________________________________________________________________________ -// XEncryptionProtectedSource2 -//____________________________________________________________________________________________________ - -void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw ( io::IOException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionData" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - - if ( !aEncryptionData.getLength() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption data!") ), uno::Reference< uno::XInterface >() ); - - OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionData() method is not available for nonroot storages!\n" ); - if ( m_pData->m_bIsRoot ) - { - try { - m_pImpl->ReadContents(); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), - aCaught ); - } - - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); - try - { - ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData ); - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( aEncryptionMap.getAsConstNamedValueList() ) ); - - m_pImpl->m_bHasCommonEncryptionData = sal_True; - m_pImpl->m_aCommonEncryptionData = aEncryptionMap; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } -} - -//____________________________________________________________________________________________________ -// XEncryptionProtectedStorage -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OStorage::setEncryptionAlgorithms( const uno::Sequence< beans::NamedValue >& aAlgorithms ) - throw (lang::IllegalArgumentException, uno::RuntimeException) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionAlgorithms" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - - if ( !aAlgorithms.getLength() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption algorithms list!") ), uno::Reference< uno::XInterface >() ); - - OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionAlgorithms() method is not available for nonroot storages!\n" ); - if ( m_pData->m_bIsRoot ) - { - try { - m_pImpl->ReadContents(); - } - catch ( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); - try - { - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ), - uno::makeAny( aAlgorithms ) ); - } - catch ( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( lang::IllegalArgumentException& aIAException ) - { - m_pImpl->AddLog( aIAException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw; - } - catch( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } -} - -//----------------------------------------------- -uno::Sequence< beans::NamedValue > SAL_CALL OStorage::getEncryptionAlgorithms() - throw (uno::RuntimeException) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getEncryptionAlgorithms" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - - uno::Sequence< beans::NamedValue > aResult; - OSL_ENSURE( m_pData->m_bIsRoot, "getEncryptionAlgorithms() method is not available for nonroot storages!\n" ); - if ( m_pData->m_bIsRoot ) - { - try { - m_pImpl->ReadContents(); - } - catch ( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); - try - { - xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) >>= aResult; - } - catch ( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } - - return aResult; -} - - -//____________________________________________________________________________________________________ -// XPropertySet -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Reference< beans::XPropertySetInfo > SAL_CALL OStorage::getPropertySetInfo() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: - return uno::Reference< beans::XPropertySetInfo >(); -} - - -//----------------------------------------------- -void SAL_CALL OStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) - throw ( beans::UnknownPropertyException, - beans::PropertyVetoException, - lang::IllegalArgumentException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setPropertyValue" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: think about interaction handler - - // WORKAROUND: - // The old document might have no version in the manifest.xml, so we have to allow to set the version - // even for readonly storages, so that the version from content.xml can be used. - if ( m_pData->m_bReadOnlyWrap && !aPropertyName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Access denied - - if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP ) - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - { - aValue >>= m_pImpl->m_aMediaType; - m_pImpl->m_bControlMediaType = sal_True; - - m_pImpl->m_bBroadcastModified = sal_True; - m_pImpl->m_bIsModified = sal_True; - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Version" ) ) ) - { - aValue >>= m_pImpl->m_aVersion; - m_pImpl->m_bControlVersion = sal_True; - - // this property can be set even for readonly storage - if ( !m_pData->m_bReadOnlyWrap ) - { - m_pImpl->m_bBroadcastModified = sal_True; - m_pImpl->m_bIsModified = sal_True; - } - } - else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( IS_INCONSISTENT_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsRoot" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfoStream" ) ) ) - { - uno::Reference< io::XInputStream > xInRelStream; - if ( ( aValue >>= xInRelStream ) && xInRelStream.is() ) - { - uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY ); - if ( !xSeek.is() ) - { - // currently this is an internal property that is used for optimization - // and the stream must support XSeekable interface - // TODO/LATER: in future it can be changed if property is used from outside - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - } - - m_pImpl->m_xNewRelInfoStream = xInRelStream; - m_pImpl->m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM; - m_pImpl->m_bBroadcastModified = sal_True; - m_pImpl->m_bIsModified = sal_True; - } - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - { - if ( aValue >>= m_pImpl->m_aRelInfo ) - { - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; - m_pImpl->m_bBroadcastModified = sal_True; - m_pImpl->m_bIsModified = sal_True; - } - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - } - else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsRoot" ) ) ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - else - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - BroadcastModifiedIfNecessary(); -} - - -//----------------------------------------------- -uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyName ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getPropertyValue" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Version" ) ) ) ) - { - try - { - m_pImpl->ReadContents(); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't read contents!" ) ), - uno::Reference< XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), - aCaught ); - } - - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - return uno::makeAny( m_pImpl->m_aMediaType ); - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Version" ) ) ) - return uno::makeAny( m_pImpl->m_aVersion ); - else - return uno::makeAny( m_pImpl->m_bMTFallbackUsed ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsRoot" ) ) ) - { - return uno::makeAny( m_pData->m_bIsRoot ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OpenMode" ) ) ) - { - return uno::makeAny( m_pImpl->m_nStorageMode ); - } - else if ( m_pData->m_bIsRoot ) - { - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) ) - { - for ( sal_Int32 aInd = 0; aInd < m_pImpl->m_xProperties.getLength(); aInd++ ) - { - if ( m_pImpl->m_xProperties[aInd].Name.equals( aPropertyName ) ) - return m_pImpl->m_xProperties[aInd].Value; - } - - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) ) - return uno::makeAny( ::rtl::OUString() ); - - return uno::makeAny( sal_False ); // RepairPackage - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( IS_INCONSISTENT_PROPERTY ) ) ) ) - { - try { - m_pImpl->ReadContents(); - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY ); - if ( !xPackPropSet.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return xPackPropSet->getPropertyValue( aPropertyName ); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - } - } - - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - - -//----------------------------------------------- -void SAL_CALL OStorage::addPropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OStorage::removePropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OStorage::addVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OStorage::removeVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: -} - -//____________________________________________________________________________________________________ -// XRelationshipAccess -//____________________________________________________________________________________________________ - -// TODO/LATER: the storage and stream implementations of this interface are very similar, they could use a helper class - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::hasByID( const ::rtl::OUString& sID ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - try - { - getRelationshipByID( sID ); - return sal_True; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - - return sal_False; -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OStorage::getTargetByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Target" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OStorage::getTypeByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -uno::Sequence< beans::StringPair > SAL_CALL OStorage::getRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - return aSeq[nInd1]; - break; - } - - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getRelationshipsByType( const ::rtl::OUString& sType ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< uno::Sequence< beans::StringPair > > aResult; - sal_Int32 nEntriesNum = 0; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - { - // the type is usually an URL, so the check should be case insensitive - if ( aSeq[nInd1][nInd2].Second.equalsIgnoreAsciiCase( sType ) ) - { - aResult.realloc( ++nEntriesNum ); - aResult[nEntriesNum-1] = aSeq[nInd1]; - } - break; - } - - return aResult; -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getAllRelationships() - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return m_pImpl->GetAllRelationshipsIfAny(); -} - -//----------------------------------------------- -void SAL_CALL OStorage::insertRelationshipByID( const ::rtl::OUString& sID, const uno::Sequence< beans::StringPair >& aEntry, ::sal_Bool bReplace ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) ); - - sal_Int32 nIDInd = -1; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equals( aIDTag ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - nIDInd = nInd1; - - break; - } - - if ( nIDInd == -1 || bReplace ) - { - if ( nIDInd == -1 ) - { - nIDInd = aSeq.getLength(); - aSeq.realloc( nIDInd + 1 ); - } - - aSeq[nIDInd].realloc( aEntry.getLength() + 1 ); - - aSeq[nIDInd][0].First = aIDTag; - aSeq[nIDInd][0].Second = sID; - sal_Int32 nIndTarget = 1; - for ( sal_Int32 nIndOrig = 0; - nIndOrig < aEntry.getLength(); - nIndOrig++ ) - { - if ( !aEntry[nIndOrig].First.equals( aIDTag ) ) - aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig]; - } - - aSeq[nIDInd].realloc( nIndTarget ); - } - else - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - - m_pImpl->m_aRelInfo = aSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - { - sal_Int32 nLength = aSeq.getLength(); - aSeq[nInd1] = aSeq[nLength-1]; - aSeq.realloc( nLength - 1 ); - - m_pImpl->m_aRelInfo = aSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; - - // TODO/LATER: in future the unification of the ID could be checked - return; - } - - break; - } - - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::insertRelationships( const uno::Sequence< uno::Sequence< beans::StringPair > >& aEntries, ::sal_Bool bReplace ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) ); - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - uno::Sequence< uno::Sequence< beans::StringPair > > aResultSeq( aSeq.getLength() + aEntries.getLength() ); - sal_Int32 nResultInd = 0; - - for ( sal_Int32 nIndTarget1 = 0; nIndTarget1 < aSeq.getLength(); nIndTarget1++ ) - for ( sal_Int32 nIndTarget2 = 0; nIndTarget2 < aSeq[nIndTarget1].getLength(); nIndTarget2++ ) - if ( aSeq[nIndTarget1][nIndTarget2].First.equals( aIDTag ) ) - { - sal_Int32 nIndSourceSame = -1; - - for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ ) - for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ ) - { - if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) ) - { - if ( aEntries[nIndSource1][nIndSource2].Second.equals( aSeq[nIndTarget1][nIndTarget2].Second ) ) - { - if ( !bReplace ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - nIndSourceSame = nIndSource1; - } - - break; - } - } - - if ( nIndSourceSame == -1 ) - { - // no such element in the provided sequence - aResultSeq[nResultInd++] = aSeq[nIndTarget1]; - } - - break; - } - - for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ ) - { - aResultSeq[nResultInd].realloc( aEntries[nIndSource1].getLength() ); - sal_Bool bHasID = sal_False; - sal_Int32 nResInd2 = 1; - - for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ ) - if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) ) - { - aResultSeq[nResultInd][0] = aEntries[nIndSource1][nIndSource2]; - bHasID = sal_True; - } - else if ( nResInd2 < aResultSeq[nResultInd].getLength() ) - aResultSeq[nResultInd][nResInd2++] = aEntries[nIndSource1][nIndSource2]; - else - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: illegal relation ( no ID ) - - if ( !bHasID ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: illegal relations - - nResultInd++; - } - - aResultSeq.realloc( nResultInd ); - m_pImpl->m_aRelInfo = aResultSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -void SAL_CALL OStorage::clearRelationships() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_pImpl->m_aRelInfo.realloc( 0 ); - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//____________________________________________________________________________________________________ -// XOptimizedStorage -//____________________________________________________________________________________________________ -//----------------------------------------------- -void SAL_CALL OStorage::insertRawNonEncrStreamElementDirect( - const ::rtl::OUString& /*sStreamName*/, - const uno::Reference< io::XInputStream >& /*xInStream*/ ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoRawFormatException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - // not implemented currently because there is still no demand - // might need to be implemented if direct copying of compressed streams is used - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::insertStreamElementDirect( - const ::rtl::OUString& aStreamName, - const uno::Reference< io::XInputStream >& xInStream, - const uno::Sequence< beans::PropertyValue >& aProps ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::insertStreamElementDirect" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name - - if ( m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName ); - - if ( pElement ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - pElement = OpenStreamElement_Impl( aStreamName, embed::ElementModes::READWRITE, sal_False ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - pElement->m_pStream->InsertStreamDirectly( xInStream, aProps ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't insert stream directly!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyElementDirectlyTo( - const ::rtl::OUString& aElementName, - const uno::Reference< embed::XOptimizedStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyElementDirectlyTo" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) - || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) - || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable name - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY ); - if ( !xNameAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( xNameAccess->hasByName( aNewName ) ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // let the element be copied directly - uno::Reference< embed::XStorage > xStorDest( xDest, uno::UNO_QUERY_THROW ); - m_pImpl->CopyStorageElement( pElement, xStorDest, aNewName, sal_True ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy element direcly!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::writeAndAttachToStream( const uno::Reference< io::XStream >& xStream ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::writeAndAttachToStream" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !m_pData->m_bIsRoot ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - - if ( !m_pImpl->m_pSwitchStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - try - { - m_pImpl->m_pSwitchStream->CopyAndSwitchPersistenceTo( xStream ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't write and attach to stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - -} - -//----------------------------------------------- -void SAL_CALL OStorage::attachToURL( const ::rtl::OUString& sURL, - sal_Bool bReadOnly ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::attachToURL" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !m_pData->m_bIsRoot ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - - if ( !m_pImpl->m_pSwitchStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference < ucb::XSimpleFileAccess > xAccess( - m_pImpl->m_xFactory->createInstance ( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ), - uno::UNO_QUERY_THROW ); - - try - { - if ( bReadOnly ) - { - uno::Reference< io::XInputStream > xInputStream = xAccess->openFileRead( sURL ); - m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xInputStream ); - } - else - { - uno::Reference< io::XStream > xStream = xAccess->openFileReadWrite( sURL ); - m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xStream ); - } - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't attach to URL!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -uno::Any SAL_CALL OStorage::getElementPropertyValue( const ::rtl::OUString& aElementName, const ::rtl::OUString& aPropertyName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - beans::UnknownPropertyException, - beans::PropertyVetoException, - embed::StorageWrappedTargetException, - uno::RuntimeException) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getElementPropertyValue" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name - - try - { - SotElement_Impl *pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // TODO/LATER: Currently it is only implemented for MediaType property of substorages, might be changed in future - if ( !pElement->m_bIsStorage || m_pData->m_nStorageType != embed::StorageFormats::PACKAGE || !aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !pElement->m_pStorage ) - m_pImpl->OpenSubStorage( pElement, embed::ElementModes::READ ); - - if ( !pElement->m_pStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error - - pElement->m_pStorage->ReadContents(); - return uno::makeAny( pElement->m_pStorage->m_aMediaType ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const beans::UnknownPropertyException& rUnknownPropertyException ) - { - m_pImpl->AddLog( rUnknownPropertyException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const beans::PropertyVetoException& rPropertyVetoException ) - { - m_pImpl->AddLog( rPropertyVetoException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get element property!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyStreamElementData( const ::rtl::OUString& aStreamName, const uno::Reference< io::XStream >& xTargetStream ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable name - - if ( !xTargetStream.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - try - { - uno::Reference< io::XStream > xNonconstRef = xTargetStream; - m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xNonconstRef ); - - OSL_ENSURE( xNonconstRef == xTargetStream, "The provided stream reference seems not be filled in correctly!\n" ); - if ( xNonconstRef != xTargetStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // if the stream reference is set it must not be changed! - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy stream data!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - -} - -//____________________________________________________________________________________________________ -// XHierarchicalStorageAccess -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) - && ( nOpenMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied - - OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath ); - OSL_ENSURE( aListPath.size(), "The result list must not be empty!" ); - - uno::Reference< embed::XExtendedStorageStream > xResult; - if ( aListPath.size() == 1 ) - { - // that must be a direct request for a stream - // the transacted version of the stream should be opened - - SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, sal_False ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - xResult = uno::Reference< embed::XExtendedStorageStream >( - pElement->m_pStream->GetStream( nOpenMode, sal_True ), - uno::UNO_QUERY_THROW ); - } - else - { - // there are still storages in between - if ( !m_pData->m_rHierarchyHolder.is() ) - m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl( - uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) ); - - xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically( - ( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ), - aListPath, - nOpenMode ); - } - - if ( !xResult.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return xResult; -} - -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode, const ::rtl::OUString& sPassword ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - return openEncryptedStreamByHierarchicalName( aStreamPath, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( sPassword ) ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied - - OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath ); - OSL_ENSURE( aListPath.size(), "The result list must not be empty!" ); - - if ( !m_pData->m_rHierarchyHolder.is() ) - m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl( - uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) ); - - m_pData->m_rHierarchyHolder->RemoveStreamHierarchically( aListPath ); -} - -//____________________________________________________________________________________________________ -// XHierarchicalStorageAccess2 -//____________________________________________________________________________________________________ - -uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !aEncryptionData.getLength() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 ); - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) - && ( nOpenMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied - - OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath ); - OSL_ENSURE( aListPath.size(), "The result list must not be empty!" ); - - uno::Reference< embed::XExtendedStorageStream > xResult; - if ( aListPath.size() == 1 ) - { - // that must be a direct request for a stream - // the transacted version of the stream should be opened - - SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, sal_True ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - xResult = uno::Reference< embed::XExtendedStorageStream >( - pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_True ), - uno::UNO_QUERY_THROW ); - } - else - { - // there are still storages in between - if ( !m_pData->m_rHierarchyHolder.is() ) - m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl( - uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) ); - - xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically( - ( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ), - aListPath, - nOpenMode, - aEncryptionData ); - } - - if ( !xResult.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return xResult; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx deleted file mode 100644 index 46de9361c..000000000 --- a/package/source/xstor/xstorage.hxx +++ /dev/null @@ -1,860 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef __XSTORAGE_HXX_ -#define __XSTORAGE_HXX_ - -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/embed/XStorage2.hpp> -#include <com/sun/star/embed/XOptimizedStorage.hpp> -#include <com/sun/star/embed/XHierarchicalStorageAccess2.hpp> -#include <com/sun/star/embed/XStorageRawAccess.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/embed/XTransactionBroadcaster.hpp> -#include <com/sun/star/embed/XClassifiedObject.hpp> -#include <com/sun/star/embed/XEncryptionProtectedStorage.hpp> -#include <com/sun/star/embed/XRelationshipAccess.hpp> -#include <com/sun/star/util/XModifiable.hpp> -#include <com/sun/star/container/XNameAccess.hpp> -#include <com/sun/star/container/XNameContainer.hpp> -#include <com/sun/star/util/XCloseable.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/beans/StringPair.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/lang/XTypeProvider.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/packages/NoEncryptionException.hpp> -#include <com/sun/star/logging/XSimpleLogRing.hpp> - -#include <cppuhelper/weak.hxx> -#include <cppuhelper/interfacecontainer.h> -#include <comphelper/sequenceashashmap.hxx> - -#include "mutexholder.hxx" - -#define RELINFO_NO_INIT 1 -#define RELINFO_READ 2 -#define RELINFO_CHANGED 3 -#define RELINFO_CHANGED_STREAM 4 -#define RELINFO_CHANGED_STREAM_READ 5 -#define RELINFO_BROKEN 6 -#define RELINFO_CHANGED_BROKEN 7 - -#define STOR_MESS_PRECOMMIT 1 -#define STOR_MESS_COMMITED 2 -#define STOR_MESS_PREREVERT 3 -#define STOR_MESS_REVERTED 4 - -namespace cppu -{ - class OTypeCollection; -} - -//================================================ -// a common implementation for an entry - -struct StorInternalData_Impl; -struct OStorage_Impl; -struct OWriteStream_Impl; - -struct SotElement_Impl -{ - ::rtl::OUString m_aName; - ::rtl::OUString m_aOriginalName; - sal_Bool m_bIsRemoved; - sal_Bool m_bIsInserted; - sal_Bool m_bIsStorage; - - OStorage_Impl* m_pStorage; - OWriteStream_Impl* m_pStream; - -public: - SotElement_Impl( const ::rtl::OUString& rName, sal_Bool bStor, sal_Bool bNew ); - ~SotElement_Impl(); -}; - -#include <list> -typedef ::std::list< SotElement_Impl* > SotElementList_Impl; - -//========================================================================= -// Main storage implementation - -class OStorage; - -struct StorageHolder_Impl -{ - OStorage* m_pPointer; - ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakRef; - - StorageHolder_Impl( OStorage* pStorage ) - : m_pPointer( pStorage ) - , m_xWeakRef( ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >( - (::com::sun::star::embed::XStorage*)pStorage ) ) - { - } - - StorageHolder_Impl( const StorageHolder_Impl& aSH ) - : m_pPointer( aSH.m_pPointer ) - , m_xWeakRef( aSH.m_xWeakRef ) - { - } -}; - -typedef ::std::list< StorageHolder_Impl > OStorageList_Impl; - -class SwitchablePersistenceStream; -struct OStorage_Impl -{ - SotMutexHolderRef m_rMutexRef; - - OStorage* m_pAntiImpl; // only valid if external references exists - OStorageList_Impl m_aReadOnlyWrapList; // only valid if readonly external reference exists - - sal_Int32 m_nStorageMode; // open mode ( read/write/trunc/nocreate ) - sal_Bool m_bIsModified; // only modified elements will be sent to the original content - sal_Bool m_bBroadcastModified; // will be set if notification is required - sal_Bool m_bCommited; // sending the streams is coordinated by the root storage of the package - - sal_Bool m_bIsRoot; // marks this storage as root storages that manages all commits and reverts - sal_Bool m_bListCreated; - - - SotElementList_Impl m_aChildrenList; - SotElementList_Impl m_aDeletedList; - - ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xPackageFolder; - ::com::sun::star::uno::Reference< ::com::sun::star::logging::XSimpleLogRing > m_xLogRing; - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > m_xPackage; - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - - // valid only for root storage - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; // ??? may be stored in properties - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream; // ??? may be stored in properties - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_xProperties; - sal_Bool m_bHasCommonEncryptionData; - ::comphelper::SequenceAsHashMap m_aCommonEncryptionData; - - // must be empty in case of root storage - OStorage_Impl* m_pParent; - - sal_Bool m_bControlMediaType; - ::rtl::OUString m_aMediaType; - sal_Bool m_bMTFallbackUsed; - - sal_Bool m_bControlVersion; - ::rtl::OUString m_aVersion; - - SwitchablePersistenceStream* m_pSwitchStream; - - sal_Int32 m_nStorageType; // the mode in wich the storage is used - - // the _rels substorage that is handled in a special way in embed::StorageFormats::OFOPXML - SotElement_Impl* m_pRelStorElement; - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xRelStorage; - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aRelInfo; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xNewRelInfoStream; - sal_Int16 m_nRelInfoStatus; - - ////////////////////////////////////////// - // Constructors - - OStorage_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream, - sal_Int32 nMode, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - OStorage_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xStream, - sal_Int32 nMode, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - // constructor for a substorage - OStorage_Impl( OStorage_Impl* pParent, - sal_Int32 nMode, - ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > xPackageFolder, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > xPackage, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - ~OStorage_Impl(); - - void AddLog( const ::rtl::OUString& aMessage ); - - void SetReadOnlyWrap( OStorage& aStorage ); - void RemoveReadOnlyWrap( OStorage& aStorage ); - - void OpenOwnPackage(); - void ReadContents(); - void ReadRelInfoIfNecessary(); - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > GetServiceFactory(); - SotElementList_Impl& GetChildrenList(); - void GetStorageProperties(); - - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetAllRelationshipsIfAny(); - void CopyLastCommitTo( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xNewStor ); - void CopyLastCommitTo( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xNewStor, - const ::rtl::OUString& aPass ); - - void InsertIntoPackageFolder( - const ::rtl::OUString& aName, - const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xParentPackageFolder ); - - void Commit(); - void Revert(); - - ::comphelper::SequenceAsHashMap GetCommonRootEncryptionData() throw ( ::com::sun::star::packages::NoEncryptionException ); - - void CopyToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, - sal_Bool bDirect ); - void CopyStorageElement( SotElement_Impl* pElement, - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > xDest, - ::rtl::OUString aName, - sal_Bool bDirect ); - - void SetModified( sal_Bool bModified ); - - SotElement_Impl* FindElement( const ::rtl::OUString& rName ); - - - SotElement_Impl* InsertStream( ::rtl::OUString aName, sal_Bool bEncr ); - SotElement_Impl* InsertRawStream( ::rtl::OUString aName, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); - - OStorage_Impl* CreateNewStorageImpl( sal_Int32 nStorageMode ); - SotElement_Impl* InsertStorage( ::rtl::OUString aName, sal_Int32 nStorageMode ); - SotElement_Impl* InsertElement( ::rtl::OUString aName, sal_Bool bIsStorage ); - - void OpenSubStorage( SotElement_Impl* pElement, sal_Int32 nStorageMode ); - void OpenSubStream( SotElement_Impl* pElement ); - - ::com::sun::star::uno::Sequence< ::rtl::OUString > GetElementNames(); - - void RemoveElement( SotElement_Impl* pElement ); - void ClearElement( SotElement_Impl* pElement ); - void DisposeChildren(); - - void CloneStreamElement( - const ::rtl::OUString& aStreamName, - sal_Bool bPassProvided, - const ::comphelper::SequenceAsHashMap& aEncryptionData, - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - void RemoveStreamRelInfo( const ::rtl::OUString& aOriginalName ); - void CreateRelStorage(); - void CommitStreamRelInfo( SotElement_Impl* pStreamElement ); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRelInfoStreamForName( const ::rtl::OUString& aName ); - void CommitRelInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xNewPackageFolder ); - - static void completeStorageStreamCopy_Impl( - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xSource, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDest, - sal_Int32 nStorageType, - const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aRelInfo ); - -}; - - -class OStorage : public ::com::sun::star::lang::XTypeProvider - , public ::com::sun::star::embed::XStorage2 - , public ::com::sun::star::embed::XStorageRawAccess - , public ::com::sun::star::embed::XTransactedObject - , public ::com::sun::star::embed::XTransactionBroadcaster - , public ::com::sun::star::util::XModifiable - , public ::com::sun::star::embed::XEncryptionProtectedStorage - , public ::com::sun::star::beans::XPropertySet - , public ::com::sun::star::embed::XOptimizedStorage - , public ::com::sun::star::embed::XRelationshipAccess - , public ::com::sun::star::embed::XHierarchicalStorageAccess2 - , public ::cppu::OWeakObject -{ - OStorage_Impl* m_pImpl; - StorInternalData_Impl* m_pData; - -protected: - - void Commit_Impl(); - - SotElement_Impl* OpenStreamElement_Impl( const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, sal_Bool bEncr ); - - void BroadcastModifiedIfNecessary(); - - void BroadcastTransaction( sal_Int8 nMessage ); - - void MakeLinkToSubComponent_Impl( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xComponent ); - -public: - - OStorage( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream, - sal_Int32 nMode, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - OStorage( ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xStream, - sal_Int32 nMode, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - OStorage( OStorage_Impl* pImpl, sal_Bool bReadOnlyWrap ); - - virtual ~OStorage(); - - void SAL_CALL InternalDispose( sal_Bool bNotifyImpl ); - - void ChildIsDisposed( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xChild ); - - sal_Int32 GetRefCount_Impl() { return m_refCount; } - - //____________________________________________________________________________________________________ - // XInterface - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) - throw( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL acquire() throw(); - - virtual void SAL_CALL release() throw(); - - //____________________________________________________________________________________________________ - // XTypeProvider - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() - throw( ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() - throw( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XStorage - //____________________________________________________________________________________________________ - - virtual void SAL_CALL copyToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openEncryptedStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL openStorageElement( - const ::rtl::OUString& aStorName, sal_Int32 nStorageMode ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneStreamElement( - const ::rtl::OUString& aStreamName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneEncryptedStreamElement( - const ::rtl::OUString& aStreamName, const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyLastCommitTo( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xTargetStorage ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyStorageElementLastCommitTo( - const ::rtl::OUString& aStorName, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xTargetStorage ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL isStreamElement( const ::rtl::OUString& aElementName ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL isStorageElement( const ::rtl::OUString& aElementName ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeElement( const ::rtl::OUString& aElementName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL renameElement( const ::rtl::OUString& rEleName, const ::rtl::OUString& rNewName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyElementTo( const ::rtl::OUString& aElementName, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL moveElementTo( const ::rtl::OUString& aElementName, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, - const ::rtl::OUString& rNewName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XStorage2 - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openEncryptedStream( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneEncryptedStream( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XStorageRawAccess - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getPlainRawStreamElement( - const ::rtl::OUString& sStreamName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawEncrStreamElement( - const ::rtl::OUString& sStreamName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL insertRawEncrStreamElement( const ::rtl::OUString& aStreamName, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoRawFormatException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XTransactedObject - //____________________________________________________________________________________________________ - - virtual void SAL_CALL commit() - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL revert() - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XTransactionBroadcaster - //____________________________________________________________________________________________________ - - virtual void SAL_CALL addTransactionListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XTransactionListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeTransactionListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XTransactionListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XModifiable - //____________________________________________________________________________________________________ - - virtual sal_Bool SAL_CALL isModified() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL setModified( sal_Bool bModified ) - throw ( ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addModifyListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeModifyListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XNameAccess - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Type SAL_CALL getElementType() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL hasElements() - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XComponent - //____________________________________________________________________________________________________ - - virtual void SAL_CALL dispose() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XEncryptionProtectedSource - //____________________________________________________________________________________________________ - - virtual void SAL_CALL setEncryptionPassword( const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::uno::RuntimeException, - ::com::sun::star::io::IOException ); - - virtual void SAL_CALL removeEncryption() - throw ( ::com::sun::star::uno::RuntimeException, - ::com::sun::star::io::IOException ); - - //____________________________________________________________________________________________________ - // XEncryptionProtectedSource2 - //____________________________________________________________________________________________________ - - virtual void SAL_CALL setEncryptionData( - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XEncryptionProtectedStorage - //____________________________________________________________________________________________________ - - virtual void SAL_CALL setEncryptionAlgorithms( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aAlgorithms ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > SAL_CALL getEncryptionAlgorithms() throw (::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XPropertySet - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) - 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 ); - - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addPropertyChangeListener( - const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removePropertyChangeListener( - const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addVetoableChangeListener( - const ::rtl::OUString& PropertyName, - const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XOptimizedStorage - //____________________________________________________________________________________________________ - virtual void SAL_CALL insertRawNonEncrStreamElementDirect( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoRawFormatException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL insertStreamElementDirect( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyElementDirectlyTo( const ::rtl::OUString& sSourceName, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XOptimizedStorage >& xTargetStorage, const ::rtl::OUString& sTargetName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL writeAndAttachToStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL attachToURL( const ::rtl::OUString& sURL, sal_Bool bReadOnly ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Any SAL_CALL getElementPropertyValue( const ::rtl::OUString& sElementName, const ::rtl::OUString& sPropertyName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL copyStreamElementData( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XRelationshipAccess - //____________________________________________________________________________________________________ - - virtual ::sal_Bool SAL_CALL hasByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::rtl::OUString SAL_CALL getTargetByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::rtl::OUString SAL_CALL getTypeByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > SAL_CALL getRelationshipByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getRelationshipsByType( const ::rtl::OUString& sType ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getAllRelationships( ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL insertRelationshipByID( const ::rtl::OUString& sID, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aEntry, ::sal_Bool bReplace ) - throw ( ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL removeRelationshipByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL insertRelationships( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aEntries, ::sal_Bool bReplace ) - throw ( ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL clearRelationships( ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XHierarchicalStorageAccess - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath, ::sal_Int32 nOpenMode ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::rtl::OUString& sPassword ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL removeStreamElementByHierarchicalName( const ::rtl::OUString& sElementPath ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XHierarchicalStorageAccess2 - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openEncryptedStreamByHierarchicalName( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); -}; - - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/ByteChucker.cxx b/package/source/zipapi/ByteChucker.cxx deleted file mode 100644 index 73025fe12..000000000 --- a/package/source/zipapi/ByteChucker.cxx +++ /dev/null @@ -1,115 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ByteChucker.hxx> -#include <PackageConstants.hxx> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XOutputStream.hpp> - -using namespace ::com::sun::star::io; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; - -ByteChucker::ByteChucker(Reference<XOutputStream> xOstream) -: xStream(xOstream) -, xSeek (xOstream, UNO_QUERY ) -, a1Sequence ( 1 ) -, a2Sequence ( 2 ) -, a4Sequence ( 4 ) -, p1Sequence ( a1Sequence.getArray() ) -, p2Sequence ( a2Sequence.getArray() ) -, p4Sequence ( a4Sequence.getArray() ) -{ -} - -ByteChucker::~ByteChucker() -{ -} - -void ByteChucker::WriteBytes( const Sequence< sal_Int8 >& aData ) - throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - xStream->writeBytes(aData); -} - -sal_Int64 ByteChucker::GetPosition( ) - throw(IOException, RuntimeException) -{ - return xSeek->getPosition(); -} - -ByteChucker& ByteChucker::operator << (sal_Int8 nInt8) -{ - p1Sequence[0] = nInt8 & 0xFF; - WriteBytes( a1Sequence ); - return *this; -} - -ByteChucker& ByteChucker::operator << (sal_Int16 nInt16) -{ - p2Sequence[0] = static_cast< sal_Int8 >((nInt16 >> 0 ) & 0xFF); - p2Sequence[1] = static_cast< sal_Int8 >((nInt16 >> 8 ) & 0xFF); - WriteBytes( a2Sequence ); - return *this; -} -ByteChucker& ByteChucker::operator << (sal_Int32 nInt32) -{ - p4Sequence[0] = static_cast< sal_Int8 >((nInt32 >> 0 ) & 0xFF); - p4Sequence[1] = static_cast< sal_Int8 >((nInt32 >> 8 ) & 0xFF); - p4Sequence[2] = static_cast< sal_Int8 >((nInt32 >> 16 ) & 0xFF); - p4Sequence[3] = static_cast< sal_Int8 >((nInt32 >> 24 ) & 0xFF); - WriteBytes( a4Sequence ); - return *this; -} - -ByteChucker& ByteChucker::operator << (sal_uInt8 nuInt8) -{ - p1Sequence[0] = nuInt8 & 0xFF; - WriteBytes( a1Sequence ); - return *this; -} -ByteChucker& ByteChucker::operator << (sal_uInt16 nuInt16) -{ - p2Sequence[0] = static_cast< sal_Int8 >((nuInt16 >> 0 ) & 0xFF); - p2Sequence[1] = static_cast< sal_Int8 >((nuInt16 >> 8 ) & 0xFF); - WriteBytes( a2Sequence ); - return *this; -} -ByteChucker& ByteChucker::operator << (sal_uInt32 nuInt32) -{ - p4Sequence[0] = static_cast < sal_Int8 > ((nuInt32 >> 0 ) & 0xFF); - p4Sequence[1] = static_cast < sal_Int8 > ((nuInt32 >> 8 ) & 0xFF); - p4Sequence[2] = static_cast < sal_Int8 > ((nuInt32 >> 16 ) & 0xFF); - p4Sequence[3] = static_cast < sal_Int8 > ((nuInt32 >> 24 ) & 0xFF); - WriteBytes( a4Sequence ); - return *this; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/ByteGrabber.cxx b/package/source/zipapi/ByteGrabber.cxx deleted file mode 100644 index 34bd9a7ac..000000000 --- a/package/source/zipapi/ByteGrabber.cxx +++ /dev/null @@ -1,194 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ByteGrabber.hxx> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XInputStream.hpp> - -using namespace ::com::sun::star; - -/** ByteGrabber implements the >> operators on an XOutputStream. This is - * potentially quite slow and may need to be optimised - */ - -ByteGrabber::ByteGrabber(uno::Reference < io::XInputStream > xIstream) -: xStream(xIstream) -, xSeek (xIstream, uno::UNO_QUERY ) -, aSequence ( 4 ) -{ - pSequence = aSequence.getArray(); -} - -ByteGrabber::~ByteGrabber() -{ -} - -void ByteGrabber::setInputStream (uno::Reference < io::XInputStream > xNewStream) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - xStream = xNewStream; - xSeek = uno::Reference < io::XSeekable > (xNewStream, uno::UNO_QUERY); -} - -// XInputStream chained -sal_Int32 SAL_CALL ByteGrabber::readBytes( uno::Sequence< sal_Int8 >& aData, - sal_Int32 nBytesToRead ) - throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - return xStream->readBytes(aData, nBytesToRead ); -} - -// XSeekable chained... -sal_Int64 SAL_CALL ByteGrabber::seek( sal_Int64 location ) - throw(lang::IllegalArgumentException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if (xSeek.is() ) - { - sal_Int64 nLen = xSeek->getLength(); - if ( location < 0 || location > nLen ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - if (location > nLen ) - location = nLen; - xSeek->seek( location ); - return location; - } - else - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -sal_Int64 SAL_CALL ByteGrabber::getPosition( ) - throw(io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if (xSeek.is() ) - return xSeek->getPosition(); - else - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -sal_Int64 SAL_CALL ByteGrabber::getLength( ) - throw(io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if (xSeek.is() ) - return xSeek->getLength(); - else - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -ByteGrabber& ByteGrabber::operator >> (sal_Int8& rInt8) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if (xStream->readBytes(aSequence,1) != 1) - rInt8 = 0; - else - rInt8 = aSequence[0] & 0xFF; - return *this; -} - -ByteGrabber& ByteGrabber::operator >> (sal_Int16& rInt16) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if (xStream->readBytes ( aSequence, 2) != 2) - rInt16 = 0; - else - { - pSequence = aSequence.getConstArray(); - rInt16 = static_cast <sal_Int16> - ( (pSequence[0] & 0xFF) - | (pSequence[1] & 0xFF) << 8); - } - return *this; -} - -ByteGrabber& ByteGrabber::operator >> (sal_Int32& rInt32) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (xStream->readBytes(aSequence, 4) != 4) - rInt32 = 0; - else - { - pSequence = aSequence.getConstArray(); - rInt32 = static_cast < sal_Int32 > - ( (pSequence[0] & 0xFF) - | ( pSequence[1] & 0xFF ) << 8 - | ( pSequence[2] & 0xFF ) << 16 - | ( pSequence[3] & 0xFF ) << 24 ); - } - return *this; -} - -ByteGrabber& ByteGrabber::operator >> (sal_uInt8& rInt8) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (xStream->readBytes(aSequence,1) != 1) - rInt8 = 0; - else - rInt8 = static_cast < sal_uInt8 > (aSequence[0] & 0xFF ); - return *this; -} -ByteGrabber& ByteGrabber::operator >> (sal_uInt16& rInt16) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (xStream->readBytes(aSequence, 2) != 2) - rInt16 = 0; - else - { - pSequence = aSequence.getConstArray(); - rInt16 = static_cast <sal_uInt16> - ( (pSequence[0] & 0xFF) - | (pSequence[1] & 0xFF) << 8); - } - return *this; -} -ByteGrabber& ByteGrabber::operator >> (sal_uInt32& ruInt32) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (xStream->readBytes(aSequence, 4) != 4) - ruInt32 = 0; - else - { - pSequence = aSequence.getConstArray(); - ruInt32 = static_cast < sal_uInt32 > - ( (pSequence[0] & 0xFF) - | ( pSequence[1] & 0xFF ) << 8 - | ( pSequence[2] & 0xFF ) << 16 - | ( pSequence[3] & 0xFF ) << 24 ); - } - return *this; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/CRC32.cxx b/package/source/zipapi/CRC32.cxx deleted file mode 100644 index bf2fff6ff..000000000 --- a/package/source/zipapi/CRC32.cxx +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <CRC32.hxx> -#ifndef _ZLIB_H -#ifdef SYSTEM_ZLIB -#include <zlib.h> -#else -#include <external/zlib/zlib.h> -#endif -#endif -#include <PackageConstants.hxx> -#include <com/sun/star/io/XInputStream.hpp> - -using namespace com::sun::star::uno; -using namespace com::sun::star::io; - -/** A class to compute the CRC32 value of a data stream - */ - -CRC32::CRC32() -: nCRC(0) -{ -} -CRC32::~CRC32() -{ -} -void SAL_CALL CRC32::reset() - throw(RuntimeException) -{ - nCRC=0; -} -sal_Int32 SAL_CALL CRC32::getValue() - throw(RuntimeException) -{ - return nCRC & 0xFFFFFFFFL; -} -/** Update CRC32 with specified sequence of bytes - */ -void SAL_CALL CRC32::updateSegment(const Sequence< sal_Int8 > &b, - sal_Int32 off, - sal_Int32 len) - throw(RuntimeException) -{ - nCRC = crc32(nCRC, (const unsigned char*)b.getConstArray()+off, len ); -} -/** Update CRC32 with specified sequence of bytes - */ -void SAL_CALL CRC32::update(const Sequence< sal_Int8 > &b) - throw(RuntimeException) -{ - nCRC = crc32(nCRC, (const unsigned char*)b.getConstArray(),b.getLength()); -} - -sal_Int32 SAL_CALL CRC32::updateStream( Reference < XInputStream > & xStream ) - throw ( RuntimeException ) -{ - sal_Int32 nLength, nTotal = 0; - Sequence < sal_Int8 > aSeq ( n_ConstBufferSize ); - do - { - nLength = xStream->readBytes ( aSeq, n_ConstBufferSize ); - updateSegment ( aSeq, 0, nLength ); - nTotal += nLength; - } - while ( nLength == n_ConstBufferSize ); - - return nTotal; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/Deflater.cxx b/package/source/zipapi/Deflater.cxx deleted file mode 100644 index bb48b4ef3..000000000 --- a/package/source/zipapi/Deflater.cxx +++ /dev/null @@ -1,216 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <Deflater.hxx> -#ifndef _ZLIB_H -#ifdef SYSTEM_ZLIB -#include <zlib.h> -#else -#include <external/zlib/zlib.h> -#endif -#endif -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <string.h> // for memset - -using namespace com::sun::star::packages::zip::ZipConstants; -using namespace com::sun::star; -using namespace ZipUtils; - -/** Provides general purpose compression using the ZLIB compression - * library. - */ - -Deflater::~Deflater(void) -{ - end(); -} -void Deflater::init (sal_Int32 nLevelArg, sal_Int32 nStrategyArg, sal_Bool bNowrap) -{ - pStream = new z_stream; - /* Memset it to 0...sets zalloc/zfree/opaque to NULL */ - memset (pStream, 0, sizeof(*pStream)); - - switch (deflateInit2(pStream, nLevelArg, Z_DEFLATED, bNowrap? -MAX_WBITS : MAX_WBITS, - DEF_MEM_LEVEL, nStrategyArg)) - { - case Z_OK: - break; - case Z_MEM_ERROR: - delete pStream; - break; - case Z_STREAM_ERROR: - delete pStream; - break; - default: - break; - } -} - -Deflater::Deflater(sal_Int32 nSetLevel, sal_Bool bNowrap) -: bFinish(sal_False) -, bFinished(sal_False) -, bSetParams(sal_False) -, nLevel(nSetLevel) -, nStrategy(DEFAULT_STRATEGY) -, nOffset(0) -, nLength(0) -{ - init(nSetLevel, DEFAULT_STRATEGY, bNowrap); -} - -sal_Int32 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength) -{ - sal_Int32 nResult; - if (bSetParams) - { - pStream->next_in = (unsigned char*) sInBuffer.getConstArray() + nOffset; - pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset; - pStream->avail_in = nLength; - pStream->avail_out = nNewLength; - -#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX - nResult = deflateParams(pStream, nLevel, nStrategy); -#else - nResult = z_deflateParams(pStream, nLevel, nStrategy); -#endif - switch (nResult) - { - case Z_OK: - bSetParams = sal_False; - nOffset += nLength - pStream->avail_in; - nLength = pStream->avail_in; - return nNewLength - pStream->avail_out; - case Z_BUF_ERROR: - bSetParams = sal_False; - return 0; - default: - return 0; - } - } - else - { - pStream->next_in = (unsigned char*) sInBuffer.getConstArray() + nOffset; - pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset; - pStream->avail_in = nLength; - pStream->avail_out = nNewLength; - -#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX - nResult = deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH); -#else - nResult = z_deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH); -#endif - switch (nResult) - { - case Z_STREAM_END: - bFinished = sal_True; - case Z_OK: - nOffset += nLength - pStream->avail_in; - nLength = pStream->avail_in; - return nNewLength - pStream->avail_out; - case Z_BUF_ERROR: - bSetParams = sal_False; - return 0; - default: - return 0; - } - } -} - -void SAL_CALL Deflater::setInputSegment( const uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) -{ - OSL_ASSERT( !(nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength())); - - sInBuffer = rBuffer; - nOffset = nNewOffset; - nLength = nNewLength; -} -void SAL_CALL Deflater::setLevel( sal_Int32 nNewLevel ) -{ - if ((nNewLevel < 0 || nNewLevel > 9) && nNewLevel != DEFAULT_COMPRESSION) - { - // do error handling - } - if (nNewLevel != nLevel) - { - nLevel = nNewLevel; - bSetParams = sal_True; - } -} -sal_Bool SAL_CALL Deflater::needsInput( ) -{ - return nLength <=0; -} -void SAL_CALL Deflater::finish( ) -{ - bFinish = sal_True; -} -sal_Bool SAL_CALL Deflater::finished( ) -{ - return bFinished; -} -sal_Int32 SAL_CALL Deflater::doDeflateSegment( uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) -{ - OSL_ASSERT( !(nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength())); - return doDeflateBytes(rBuffer, nNewOffset, nNewLength); -} -sal_Int32 SAL_CALL Deflater::getTotalIn( ) -{ - return pStream->total_in; -} -sal_Int32 SAL_CALL Deflater::getTotalOut( ) -{ - return pStream->total_out; -} -void SAL_CALL Deflater::reset( ) -{ -#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIXB - deflateReset(pStream); -#else - z_deflateReset(pStream); -#endif - bFinish = sal_False; - bFinished = sal_False; - nOffset = nLength = 0; -} -void SAL_CALL Deflater::end( ) -{ - if (pStream != NULL) - { -#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX - deflateEnd(pStream); -#else - z_deflateEnd(pStream); -#endif - delete pStream; - } - pStream = NULL; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/Inflater.cxx b/package/source/zipapi/Inflater.cxx deleted file mode 100644 index a340caa05..000000000 --- a/package/source/zipapi/Inflater.cxx +++ /dev/null @@ -1,165 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <Inflater.hxx> -#ifndef _ZLIB_H -#ifdef SYSTEM_ZLIB -#include <zlib.h> -#else -#include <external/zlib/zlib.h> -#endif -#endif -#include <string.h> // for memset - -using namespace com::sun::star::uno; -using namespace ZipUtils; - -/** Provides general purpose decompression using the ZLIB library */ - -Inflater::Inflater(sal_Bool bNoWrap) -: bFinished(sal_False), - bSetParams(sal_False), - bNeedDict(sal_False), - nOffset(0), - nLength(0), - nLastInflateError(0), - pStream(NULL) -{ - pStream = new z_stream; - /* memset to 0 to set zalloc/opaque etc */ - memset (pStream, 0, sizeof(*pStream)); - sal_Int32 nRes; - nRes = inflateInit2(pStream, bNoWrap ? -MAX_WBITS : MAX_WBITS); - switch (nRes) - { - case Z_OK: - break; - case Z_MEM_ERROR: - delete pStream; - break; - case Z_STREAM_ERROR: - delete pStream; - break; - default: - break; - } -} - -Inflater::~Inflater() -{ - end(); -} - -void SAL_CALL Inflater::setInput( const Sequence< sal_Int8 >& rBuffer ) -{ - sInBuffer = rBuffer; - nOffset = 0; - nLength = rBuffer.getLength(); -} - -sal_Bool SAL_CALL Inflater::needsDictionary( ) -{ - return bNeedDict; -} - -sal_Bool SAL_CALL Inflater::finished( ) -{ - return bFinished; -} - -sal_Int32 SAL_CALL Inflater::doInflateSegment( Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) -{ - if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()) - { - // do error handling - } - return doInflateBytes(rBuffer, nNewOffset, nNewLength); -} - -void SAL_CALL Inflater::end( ) -{ - if (pStream != NULL) - { -#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX - inflateEnd(pStream); -#else - z_inflateEnd(pStream); -#endif - delete pStream; - } - pStream = NULL; -} - -sal_Int32 Inflater::doInflateBytes (Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength) -{ - if ( !pStream ) - { - nLastInflateError = Z_STREAM_ERROR; - return 0; - } - - nLastInflateError = 0; - - pStream->next_in = ( unsigned char* ) ( sInBuffer.getConstArray() + nOffset ); - pStream->avail_in = nLength; - pStream->next_out = reinterpret_cast < unsigned char* > ( rBuffer.getArray() + nNewOffset ); - pStream->avail_out = nNewLength; - -#if defined SYSTEM_ZLIB || !defined ZLIB_PREFIX - sal_Int32 nResult = ::inflate(pStream, Z_PARTIAL_FLUSH); -#else - sal_Int32 nResult = ::z_inflate(pStream, Z_PARTIAL_FLUSH); -#endif - - switch (nResult) - { - case Z_STREAM_END: - bFinished = sal_True; - case Z_OK: - nOffset += nLength - pStream->avail_in; - nLength = pStream->avail_in; - return nNewLength - pStream->avail_out; - - case Z_NEED_DICT: - bNeedDict = sal_True; - nOffset += nLength - pStream->avail_in; - nLength = pStream->avail_in; - return 0; - - default: - // it is no error, if there is no input or no output - if ( nLength && nNewLength ) - nLastInflateError = nResult; - } - - return 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/MemoryByteGrabber.hxx b/package/source/zipapi/MemoryByteGrabber.hxx deleted file mode 100644 index b2eec4049..000000000 --- a/package/source/zipapi/MemoryByteGrabber.hxx +++ /dev/null @@ -1,180 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _MEMORY_BYTE_GRABBER_HXX_ -#define _MEMORY_BYTE_GRABBER_HXX_ - -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <string.h> - -class MemoryByteGrabber -{ -protected: - const com::sun::star::uno::Sequence < sal_Int8 > maBuffer; - const sal_Int8 *mpBuffer; - sal_Int32 mnCurrent, mnEnd; -public: - MemoryByteGrabber ( const com::sun::star::uno::Sequence < sal_Int8 > & rBuffer ) - : maBuffer ( rBuffer ) - , mpBuffer ( rBuffer.getConstArray() ) - , mnCurrent ( 0 ) - , mnEnd ( rBuffer.getLength() ) - { - } - MemoryByteGrabber() - { - } - const sal_Int8 * getCurrentPos () { return mpBuffer + mnCurrent; } - - // XInputStream chained - sal_Int32 SAL_CALL readBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData, - sal_Int32 nBytesToRead ) - throw(com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException) - { - if ( nBytesToRead < 0) - throw com::sun::star::io::BufferSizeExceededException(); - - if (nBytesToRead + mnCurrent > mnEnd) - nBytesToRead = mnEnd - mnCurrent; - - aData.realloc ( nBytesToRead ); - rtl_copyMemory( aData.getArray(), mpBuffer + mnCurrent, nBytesToRead ); - mnCurrent += nBytesToRead; - return nBytesToRead; - } - - sal_Int32 SAL_CALL readSomeBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData, - sal_Int32 nMaxBytesToRead ) - throw(com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException) - { - return readBytes( aData, nMaxBytesToRead ); - } - void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException) - { - mnCurrent += nBytesToSkip; - } - sal_Int32 SAL_CALL available( ) - throw(com::sun::star::io::NotConnectedException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException) - { - return mnEnd - mnCurrent; - } - void SAL_CALL closeInput( ) - throw(com::sun::star::io::NotConnectedException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException) - { - } - - // XSeekable chained... - sal_Int64 SAL_CALL seek( sal_Int64 location ) - throw(com::sun::star::lang::IllegalArgumentException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException) - { - if ( location < 0 || location > mnEnd ) - throw com::sun::star::lang::IllegalArgumentException (); - mnCurrent = static_cast < sal_Int32 > ( location ); - return mnCurrent; - } - sal_Int64 SAL_CALL getPosition( ) - throw(com::sun::star::io::IOException, com::sun::star::uno::RuntimeException) - { - return mnCurrent; - } - sal_Int64 SAL_CALL getLength( ) - throw(com::sun::star::io::IOException, com::sun::star::uno::RuntimeException) - { - return mnEnd; - } - MemoryByteGrabber& operator >> (sal_Int8& rInt8) - { - if (mnCurrent + 1 > mnEnd ) - rInt8 = 0; - else - rInt8 = mpBuffer [mnCurrent++] & 0xFF; - return *this; - } - MemoryByteGrabber& operator >> (sal_Int16& rInt16) - { - if (mnCurrent + 2 > mnEnd ) - rInt16 = 0; - else - { - rInt16 = mpBuffer[mnCurrent++] & 0xFF; - rInt16 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8; - } - return *this; - } - MemoryByteGrabber& operator >> (sal_Int32& rInt32) - { - if (mnCurrent + 4 > mnEnd ) - rInt32 = 0; - else - { - rInt32 = mpBuffer[mnCurrent++] & 0xFF; - rInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8; - rInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 16; - rInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 24; - } - return *this; - } - - MemoryByteGrabber& operator >> (sal_uInt8& rInt8) - { - if (mnCurrent + 1 > mnEnd ) - rInt8 = 0; - else - rInt8 = mpBuffer [mnCurrent++] & 0xFF; - return *this; - } - MemoryByteGrabber& operator >> (sal_uInt16& rInt16) - { - if (mnCurrent + 2 > mnEnd ) - rInt16 = 0; - else - { - rInt16 = mpBuffer [mnCurrent++] & 0xFF; - rInt16 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 8; - } - return *this; - } - MemoryByteGrabber& operator >> (sal_uInt32& rInt32) - { - if (mnCurrent + 4 > mnEnd ) - rInt32 = 0; - else - { - rInt32 = mpBuffer [mnCurrent++] & 0xFF; - rInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 8; - rInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 16; - rInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 24; - } - return *this; - } -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/XUnbufferedStream.cxx b/package/source/zipapi/XUnbufferedStream.cxx deleted file mode 100644 index a6049fd2c..000000000 --- a/package/source/zipapi/XUnbufferedStream.cxx +++ /dev/null @@ -1,379 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <com/sun/star/packages/zip/ZipIOException.hpp> -#include <com/sun/star/xml/crypto/CipherID.hpp> - -#include <XUnbufferedStream.hxx> -#include <EncryptionData.hxx> -#include <PackageConstants.hxx> -#include <ZipFile.hxx> -#include <EncryptedDataHeader.hxx> -#include <algorithm> -#include <string.h> - -#include <osl/mutex.hxx> - -#if 0 -// for debugging purposes here -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <comphelper/processfactory.hxx> -using namespace ::com::sun::star; -#endif - -using namespace ::com::sun::star; -using namespace com::sun::star::packages::zip::ZipConstants; -using namespace com::sun::star::io; -using namespace com::sun::star::uno; -using com::sun::star::lang::IllegalArgumentException; -using com::sun::star::packages::zip::ZipIOException; -using ::rtl::OUString; - -XUnbufferedStream::XUnbufferedStream( - const uno::Reference< lang::XMultiServiceFactory >& xFactory, - SotMutexHolderRef aMutexHolder, - ZipEntry & rEntry, - Reference < XInputStream > xNewZipStream, - const ::rtl::Reference< EncryptionData >& rData, - sal_Int8 nStreamMode, - sal_Bool bIsEncrypted, - const ::rtl::OUString& aMediaType, - sal_Bool bRecoveryMode ) -: maMutexHolder( aMutexHolder.Is() ? aMutexHolder : SotMutexHolderRef( new SotMutexHolder ) ) -, mxZipStream ( xNewZipStream ) -, mxZipSeek ( xNewZipStream, UNO_QUERY ) -, maEntry ( rEntry ) -, mxData ( rData ) -, mnBlockSize( 1 ) -, maInflater ( sal_True ) -, mbRawStream ( nStreamMode == UNBUFF_STREAM_RAW || nStreamMode == UNBUFF_STREAM_WRAPPEDRAW ) -, mbWrappedRaw ( nStreamMode == UNBUFF_STREAM_WRAPPEDRAW ) -, mbFinished ( sal_False ) -, mnHeaderToRead ( 0 ) -, mnZipCurrent ( 0 ) -, mnZipEnd ( 0 ) -, mnZipSize ( 0 ) -, mnMyCurrent ( 0 ) -, mbCheckCRC( !bRecoveryMode ) -{ - mnZipCurrent = maEntry.nOffset; - if ( mbRawStream ) - { - mnZipSize = maEntry.nMethod == DEFLATED ? maEntry.nCompressedSize : maEntry.nSize; - mnZipEnd = maEntry.nOffset + mnZipSize; - } - else - { - mnZipSize = maEntry.nSize; - mnZipEnd = maEntry.nMethod == DEFLATED ? maEntry.nOffset + maEntry.nCompressedSize : maEntry.nOffset + maEntry.nSize; - } - sal_Bool bHaveEncryptData = ( rData.is() && rData->m_aSalt.getLength() && rData->m_aInitVector.getLength() && rData->m_nIterationCount != 0 ) ? sal_True : sal_False; - sal_Bool bMustDecrypt = ( nStreamMode == UNBUFF_STREAM_DATA && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False; - - if ( bMustDecrypt ) - { - m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false ); - mnBlockSize = ( rData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 1 ); - } - - if ( bHaveEncryptData && mbWrappedRaw && bIsEncrypted ) - { - // if we have the data needed to decrypt it, but didn't want it decrypted (or - // we couldn't decrypt it due to wrong password), then we prepend this - // data to the stream - - // Make a buffer big enough to hold both the header and the data itself - maHeader.realloc ( n_ConstHeaderSize + - rData->m_aInitVector.getLength() + - rData->m_aSalt.getLength() + - rData->m_aDigest.getLength() + - aMediaType.getLength() * sizeof( sal_Unicode ) ); - sal_Int8 * pHeader = maHeader.getArray(); - ZipFile::StaticFillHeader( rData, rEntry.nSize, aMediaType, pHeader ); - mnHeaderToRead = static_cast < sal_Int16 > ( maHeader.getLength() ); - } -} - -// allows to read package raw stream -XUnbufferedStream::XUnbufferedStream( - const uno::Reference< lang::XMultiServiceFactory >& /*xFactory*/, - const Reference < XInputStream >& xRawStream, - const ::rtl::Reference< EncryptionData >& rData ) -: maMutexHolder( new SotMutexHolder ) -, mxZipStream ( xRawStream ) -, mxZipSeek ( xRawStream, UNO_QUERY ) -, mxData ( rData ) -, mnBlockSize( 1 ) -, maInflater ( sal_True ) -, mbRawStream ( sal_False ) -, mbWrappedRaw ( sal_False ) -, mbFinished ( sal_False ) -, mnHeaderToRead ( 0 ) -, mnZipCurrent ( 0 ) -, mnZipEnd ( 0 ) -, mnZipSize ( 0 ) -, mnMyCurrent ( 0 ) -, mbCheckCRC( sal_False ) -{ - // for this scenario maEntry is not set !!! - OSL_ENSURE( mxZipSeek.is(), "The stream must be seekable!\n" ); - - // skip raw header, it must be already parsed to rData - mnZipCurrent = n_ConstHeaderSize + rData->m_aInitVector.getLength() + - rData->m_aSalt.getLength() + rData->m_aDigest.getLength(); - - try { - if ( mxZipSeek.is() ) - mnZipSize = mxZipSeek->getLength(); - } catch( Exception& ) - { - // in case of problem the size will stay set to 0 - } - - mnZipEnd = mnZipCurrent + mnZipSize; - - // the raw data will not be decrypted, no need for the cipher - // m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false ); -} - -XUnbufferedStream::~XUnbufferedStream() -{ -} - -sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - ::osl::MutexGuard aGuard( maMutexHolder->GetMutex() ); - - sal_Int32 nRequestedBytes = nBytesToRead; - OSL_ENSURE( !mnHeaderToRead || mbWrappedRaw, "Only encrypted raw stream can be provided with header!" ); - if ( mnMyCurrent + nRequestedBytes > mnZipSize + maHeader.getLength() ) - nRequestedBytes = static_cast < sal_Int32 > ( mnZipSize + maHeader.getLength() - mnMyCurrent ); - - sal_Int32 nTotal = 0; - aData.realloc ( nRequestedBytes ); - if ( nRequestedBytes ) - { - sal_Int32 nRead = 0; - sal_Int32 nLastRead = 0; - if ( mbRawStream ) - { - sal_Int64 nDiff = mnZipEnd - mnZipCurrent; - - if ( mbWrappedRaw && mnHeaderToRead ) - { - sal_Int16 nHeadRead = static_cast< sal_Int16 >(( nRequestedBytes > mnHeaderToRead ? - mnHeaderToRead : nRequestedBytes )); - rtl_copyMemory ( aData.getArray(), maHeader.getConstArray() + maHeader.getLength() - mnHeaderToRead, nHeadRead ); - mnHeaderToRead = mnHeaderToRead - nHeadRead; - - if ( nHeadRead < nRequestedBytes ) - { - sal_Int32 nToRead = nRequestedBytes - nHeadRead; - nToRead = ( nDiff < nToRead ) ? sal::static_int_cast< sal_Int32 >( nDiff ) : nToRead; - - Sequence< sal_Int8 > aPureData( nToRead ); - mxZipSeek->seek ( mnZipCurrent ); - nRead = mxZipStream->readBytes ( aPureData, nToRead ); - mnZipCurrent += nRead; - - aPureData.realloc( nRead ); - if ( mbCheckCRC ) - maCRC.update( aPureData ); - - aData.realloc( nHeadRead + nRead ); - - sal_Int8* pPureBuffer = aPureData.getArray(); - sal_Int8* pBuffer = aData.getArray(); - for ( sal_Int32 nInd = 0; nInd < nRead; nInd++ ) - pBuffer[ nHeadRead + nInd ] = pPureBuffer[ nInd ]; - } - - nRead += nHeadRead; - } - else - { - mxZipSeek->seek ( mnZipCurrent ); - - nRead = mxZipStream->readBytes ( - aData, - static_cast < sal_Int32 > ( nDiff < nRequestedBytes ? nDiff : nRequestedBytes ) ); - - mnZipCurrent += nRead; - - aData.realloc( nRead ); - if ( mbWrappedRaw && mbCheckCRC ) - maCRC.update( aData ); - } - } - else - { - while ( 0 == ( nLastRead = maInflater.doInflateSegment( aData, nRead, aData.getLength() - nRead ) ) || - ( nRead + nLastRead != nRequestedBytes && mnZipCurrent < mnZipEnd ) ) - { - nRead += nLastRead; - - if ( nRead > nRequestedBytes ) - throw RuntimeException( - OUString( RTL_CONSTASCII_USTRINGPARAM( "Should not be possible to read more then requested!" ) ), - Reference< XInterface >() ); - - if ( maInflater.finished() || maInflater.getLastInflateError() ) - throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ), - Reference< XInterface >() ); - - if ( maInflater.needsDictionary() ) - throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "Dictionaries are not supported!" ) ), - Reference< XInterface >() ); - - sal_Int32 nDiff = static_cast< sal_Int32 >( mnZipEnd - mnZipCurrent ); - if ( nDiff > 0 ) - { - mxZipSeek->seek ( mnZipCurrent ); - - sal_Int32 nToRead = std::max( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) ); - if ( mnBlockSize > 1 ) - nToRead = nToRead + mnBlockSize - nToRead % mnBlockSize; - nToRead = std::min( nDiff, nToRead ); - - sal_Int32 nZipRead = mxZipStream->readBytes( maCompBuffer, nToRead ); - if ( nZipRead < nToRead ) - throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "No expected data!" ) ), - Reference< XInterface >() ); - - mnZipCurrent += nZipRead; - // maCompBuffer now has the data, check if we need to decrypt - // before passing to the Inflater - if ( m_xCipherContext.is() ) - { - if ( mbCheckCRC ) - maCRC.update( maCompBuffer ); - - maCompBuffer = m_xCipherContext->convertWithCipherContext( maCompBuffer ); - if ( mnZipCurrent == mnZipEnd ) - { - uno::Sequence< sal_Int8 > aSuffix = m_xCipherContext->finalizeCipherContextAndDispose(); - if ( aSuffix.getLength() ) - { - sal_Int32 nOldLen = maCompBuffer.getLength(); - maCompBuffer.realloc( nOldLen + aSuffix.getLength() ); - rtl_copyMemory( maCompBuffer.getArray() + nOldLen, aSuffix.getConstArray(), aSuffix.getLength() ); - } - } - } - maInflater.setInput ( maCompBuffer ); - } - else - { - throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ), - Reference< XInterface >() ); - } - } - } - - mnMyCurrent += nRead + nLastRead; - nTotal = nRead + nLastRead; - if ( nTotal < nRequestedBytes) - aData.realloc ( nTotal ); - - if ( mbCheckCRC && ( !mbRawStream || mbWrappedRaw ) ) - { - if ( !m_xCipherContext.is() && !mbWrappedRaw ) - maCRC.update( aData ); - -#if 0 - // for debugging purposes here - if ( mbWrappedRaw ) - { - if ( 0 ) - { - uno::Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); - uno::Reference< ucb::XSimpleFileAccess > xAccess( xFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), uno::UNO_QUERY ); - uno::Reference< io::XOutputStream > xOut = xAccess->openFileWrite(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "file:///d:/777/Encrypted/picture") ) ); - xOut->writeBytes( aData ); - xOut->closeOutput(); - } - } -#endif - - if ( mnZipSize + maHeader.getLength() == mnMyCurrent && maCRC.getValue() != maEntry.nCrc ) - throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ), - Reference< XInterface >() ); - } - } - - return nTotal; -} - -sal_Int32 SAL_CALL XUnbufferedStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - return readBytes ( aData, nMaxBytesToRead ); -} -void SAL_CALL XUnbufferedStream::skipBytes( sal_Int32 nBytesToSkip ) - throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - if ( nBytesToSkip ) - { - Sequence < sal_Int8 > aSequence ( nBytesToSkip ); - readBytes ( aSequence, nBytesToSkip ); - } -} - -sal_Int32 SAL_CALL XUnbufferedStream::available( ) - throw( NotConnectedException, IOException, RuntimeException) -{ - return static_cast < sal_Int32 > ( mnZipSize - mnMyCurrent ); -} - -void SAL_CALL XUnbufferedStream::closeInput( ) - throw( NotConnectedException, IOException, RuntimeException) -{ -} -/* -void SAL_CALL XUnbufferedStream::seek( sal_Int64 location ) - throw( IllegalArgumentException, IOException, RuntimeException) -{ -} -sal_Int64 SAL_CALL XUnbufferedStream::getPosition( ) - throw(IOException, RuntimeException) -{ - return mnMyCurrent; -} -sal_Int64 SAL_CALL XUnbufferedStream::getLength( ) - throw(IOException, RuntimeException) -{ - return mnZipSize; -} -*/ - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/XUnbufferedStream.hxx b/package/source/zipapi/XUnbufferedStream.hxx deleted file mode 100644 index c0e8fc5f9..000000000 --- a/package/source/zipapi/XUnbufferedStream.hxx +++ /dev/null @@ -1,115 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _XUNBUFFERED_STREAM_HXX -#define _XUNBUFFERED_STREAM_HXX - -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/xml/crypto/XCipherContext.hpp> - -#include <cppuhelper/implbase1.hxx> -#include <rtl/ref.hxx> -#include <Inflater.hxx> -#include <ZipEntry.hxx> -#include <CRC32.hxx> -#include <mutexholder.hxx> - -#define UNBUFF_STREAM_DATA 0 -#define UNBUFF_STREAM_RAW 1 -#define UNBUFF_STREAM_WRAPPEDRAW 2 - -class EncryptionData; -class XUnbufferedStream : public cppu::WeakImplHelper1 -< - com::sun::star::io::XInputStream -> -{ -protected: - SotMutexHolderRef maMutexHolder; - - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxZipStream; - com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek; - com::sun::star::uno::Sequence < sal_Int8 > maCompBuffer, maHeader; - ZipEntry maEntry; - ::rtl::Reference< EncryptionData > mxData; - sal_Int32 mnBlockSize; - ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; - ZipUtils::Inflater maInflater; - sal_Bool mbRawStream, mbWrappedRaw, mbFinished; - sal_Int16 mnHeaderToRead; - sal_Int64 mnZipCurrent, mnZipEnd, mnZipSize, mnMyCurrent; - CRC32 maCRC; - sal_Bool mbCheckCRC; - -public: - XUnbufferedStream( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, - SotMutexHolderRef aMutexHolder, - ZipEntry & rEntry, - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream, - const ::rtl::Reference< EncryptionData >& rData, - sal_Int8 nStreamMode, - sal_Bool bIsEncrypted, - const ::rtl::OUString& aMediaType, - sal_Bool bRecoveryMode ); - - // allows to read package raw stream - XUnbufferedStream( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, - const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& xRawStream, - const ::rtl::Reference< EncryptionData >& rData ); - - - virtual ~XUnbufferedStream(); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - // XSeekable - /* - virtual void SAL_CALL seek( sal_Int64 location ) - throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - */ -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/ZipEnumeration.cxx b/package/source/zipapi/ZipEnumeration.cxx deleted file mode 100644 index 45ac260ea..000000000 --- a/package/source/zipapi/ZipEnumeration.cxx +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ZipEnumeration.hxx> - -/** Provides an Enumeration over the contents of a Zip file */ - -ZipEnumeration::ZipEnumeration( EntryHash & rNewEntryHash) -: rEntryHash(rNewEntryHash) -, aIterator(rEntryHash.begin()) -{ -} -ZipEnumeration::~ZipEnumeration( void ) -{ -} -sal_Bool SAL_CALL ZipEnumeration::hasMoreElements() -{ - return (aIterator != rEntryHash.end()); -} - -const ZipEntry* SAL_CALL ZipEnumeration::nextElement() -{ - if (aIterator != rEntryHash.end()) - return &((*aIterator++).second); - else - return NULL; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx deleted file mode 100644 index 91ffb4264..000000000 --- a/package/source/zipapi/ZipFile.cxx +++ /dev/null @@ -1,1100 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/ucb/XProgressHandler.hpp> -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <com/sun/star/xml/crypto/XCipherContext.hpp> -#include <com/sun/star/xml/crypto/XDigestContext.hpp> -#include <com/sun/star/xml/crypto/XCipherContextSupplier.hpp> -#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp> -#include <com/sun/star/xml/crypto/CipherID.hpp> -#include <com/sun/star/xml/crypto/DigestID.hpp> - -#include <comphelper/storagehelper.hxx> -#include <comphelper/processfactory.hxx> -#include <rtl/digest.h> - -#include <vector> - -#include "blowfishcontext.hxx" -#include "sha1context.hxx" -#include <ZipFile.hxx> -#include <ZipEnumeration.hxx> -#include <XUnbufferedStream.hxx> -#include <PackageConstants.hxx> -#include <EncryptedDataHeader.hxx> -#include <EncryptionData.hxx> -#include <MemoryByteGrabber.hxx> - -#include <CRC32.hxx> - -#define AES_CBC_BLOCK_SIZE 16 - -using namespace com::sun::star; -using namespace com::sun::star::io; -using namespace com::sun::star::uno; -using namespace com::sun::star::ucb; -using namespace com::sun::star::lang; -using namespace com::sun::star::packages; -using namespace com::sun::star::packages::zip; -using namespace com::sun::star::packages::zip::ZipConstants; - -using rtl::OUString; -using ZipUtils::Inflater; - -/** This class is used to read entries from a zip file - */ -ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise ) - throw(IOException, ZipException, RuntimeException) -: aGrabber(xInput) -, aInflater (sal_True) -, xStream(xInput) -, xSeek(xInput, UNO_QUERY) -, m_xFactory ( xNewFactory ) -, bRecoveryMode( sal_False ) -{ - if (bInitialise) - { - if ( readCEN() == -1 ) - { - aEntries.clear(); - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () ); - } - } -} - - - -ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise, sal_Bool bForceRecovery, uno::Reference < XProgressHandler > xProgress ) - throw(IOException, ZipException, RuntimeException) -: aGrabber(xInput) -, aInflater (sal_True) -, xStream(xInput) -, xSeek(xInput, UNO_QUERY) -, m_xFactory ( xNewFactory ) -, xProgressHandler( xProgress ) -, bRecoveryMode( bForceRecovery ) -{ - if (bInitialise) - { - if ( bForceRecovery ) - { - recover(); - } - else if ( readCEN() == -1 ) - { - aEntries.clear(); - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () ); - } - } -} - -ZipFile::~ZipFile() -{ - aEntries.clear(); -} - -void ZipFile::setInputStream ( uno::Reference < XInputStream > xNewStream ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - xStream = xNewStream; - xSeek = uno::Reference < XSeekable > ( xStream, UNO_QUERY ); - aGrabber.setInputStream ( xStream ); -} - -uno::Reference< xml::crypto::XDigestContext > ZipFile::StaticGetDigestContextForChecksum( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData ) -{ - uno::Reference< xml::crypto::XDigestContext > xDigestContext; - if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA256_1K ) - { - uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory; - if ( !xFactory.is() ) - xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); - - uno::Reference< xml::crypto::XDigestContextSupplier > xDigestContextSupplier( - xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), - uno::UNO_QUERY_THROW ); - - xDigestContext.set( xDigestContextSupplier->getDigestContext( xEncryptionData->m_nCheckAlg, uno::Sequence< beans::NamedValue >() ), uno::UNO_SET_THROW ); - } - else if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA1_1K ) - xDigestContext.set( SHA1DigestContext::Create(), uno::UNO_SET_THROW ); - - return xDigestContext; -} - -uno::Reference< xml::crypto::XCipherContext > ZipFile::StaticGetCipher( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData, bool bEncrypt ) -{ - uno::Reference< xml::crypto::XCipherContext > xResult; - - try - { - uno::Sequence< sal_Int8 > aDerivedKey( xEncryptionData->m_nDerivedKeySize ); - if ( rtl_Digest_E_None != rtl_digest_PBKDF2( reinterpret_cast< sal_uInt8* >( aDerivedKey.getArray() ), - aDerivedKey.getLength(), - reinterpret_cast< const sal_uInt8 * > (xEncryptionData->m_aKey.getConstArray() ), - xEncryptionData->m_aKey.getLength(), - reinterpret_cast< const sal_uInt8 * > ( xEncryptionData->m_aSalt.getConstArray() ), - xEncryptionData->m_aSalt.getLength(), - xEncryptionData->m_nIterationCount ) ) - { - throw ZipIOException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not create derived key!") ), - uno::Reference< XInterface >() ); - } - - if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING ) - { - uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory; - if ( !xFactory.is() ) - xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); - - uno::Reference< xml::crypto::XCipherContextSupplier > xCipherContextSupplier( - xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), - uno::UNO_QUERY_THROW ); - - xResult = xCipherContextSupplier->getCipherContext( xEncryptionData->m_nEncAlg, aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt, uno::Sequence< beans::NamedValue >() ); - } - else if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::BLOWFISH_CFB_8 ) - { - xResult = BlowfishCFB8CipherContext::Create( aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt ); - } - else - { - throw ZipIOException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown cipher algorithm is requested!") ), - uno::Reference< XInterface >() ); - } - } - catch( uno::Exception& ) - { - OSL_ENSURE( sal_False, "Can not create cipher context!" ); - } - - return xResult; -} - -void ZipFile::StaticFillHeader( const ::rtl::Reference< EncryptionData >& rData, - sal_Int32 nSize, - const ::rtl::OUString& aMediaType, - sal_Int8 * & pHeader ) -{ - // I think it's safe to restrict vector and salt length to 2 bytes ! - sal_Int16 nIVLength = static_cast < sal_Int16 > ( rData->m_aInitVector.getLength() ); - sal_Int16 nSaltLength = static_cast < sal_Int16 > ( rData->m_aSalt.getLength() ); - sal_Int16 nDigestLength = static_cast < sal_Int16 > ( rData->m_aDigest.getLength() ); - sal_Int16 nMediaTypeLength = static_cast < sal_Int16 > ( aMediaType.getLength() * sizeof( sal_Unicode ) ); - - // First the header - *(pHeader++) = ( n_ConstHeader >> 0 ) & 0xFF; - *(pHeader++) = ( n_ConstHeader >> 8 ) & 0xFF; - *(pHeader++) = ( n_ConstHeader >> 16 ) & 0xFF; - *(pHeader++) = ( n_ConstHeader >> 24 ) & 0xFF; - - // Then the version - *(pHeader++) = ( n_ConstCurrentVersion >> 0 ) & 0xFF; - *(pHeader++) = ( n_ConstCurrentVersion >> 8 ) & 0xFF; - - // Then the iteration Count - sal_Int32 nIterationCount = rData->m_nIterationCount; - *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 8 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 16 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 24 ) & 0xFF); - - // Then the size - *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 8 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 16 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 24 ) & 0xFF); - - // Then the encryption algorithm - sal_Int32 nEncAlgID = rData->m_nEncAlg; - *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 8 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 16 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 24 ) & 0xFF); - - // Then the checksum algorithm - sal_Int32 nChecksumAlgID = rData->m_nCheckAlg; - *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 8 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 16 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 24 ) & 0xFF); - - // Then the derived key size - sal_Int32 nDerivedKeySize = rData->m_nDerivedKeySize; - *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 8 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 16 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 24 ) & 0xFF); - - // Then the start key generation algorithm - sal_Int32 nKeyAlgID = rData->m_nStartKeyGenID; - *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 8 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 16 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 24 ) & 0xFF); - - // Then the salt length - *(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 8 ) & 0xFF); - - // Then the IV length - *(pHeader++) = static_cast< sal_Int8 >(( nIVLength >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nIVLength >> 8 ) & 0xFF); - - // Then the digest length - *(pHeader++) = static_cast< sal_Int8 >(( nDigestLength >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nDigestLength >> 8 ) & 0xFF); - - // Then the mediatype length - *(pHeader++) = static_cast< sal_Int8 >(( nMediaTypeLength >> 0 ) & 0xFF); - *(pHeader++) = static_cast< sal_Int8 >(( nMediaTypeLength >> 8 ) & 0xFF); - - // Then the salt content - rtl_copyMemory ( pHeader, rData->m_aSalt.getConstArray(), nSaltLength ); - pHeader += nSaltLength; - - // Then the IV content - rtl_copyMemory ( pHeader, rData->m_aInitVector.getConstArray(), nIVLength ); - pHeader += nIVLength; - - // Then the digest content - rtl_copyMemory ( pHeader, rData->m_aDigest.getConstArray(), nDigestLength ); - pHeader += nDigestLength; - - // Then the mediatype itself - rtl_copyMemory ( pHeader, aMediaType.getStr(), nMediaTypeLength ); - pHeader += nMediaTypeLength; -} - -sal_Bool ZipFile::StaticFillData ( ::rtl::Reference< BaseEncryptionData > & rData, - sal_Int32 &rEncAlg, - sal_Int32 &rChecksumAlg, - sal_Int32 &rDerivedKeySize, - sal_Int32 &rStartKeyGenID, - sal_Int32 &rSize, - ::rtl::OUString& aMediaType, - const uno::Reference< XInputStream >& rStream ) -{ - sal_Bool bOk = sal_False; - const sal_Int32 nHeaderSize = n_ConstHeaderSize - 4; - Sequence < sal_Int8 > aBuffer ( nHeaderSize ); - if ( nHeaderSize == rStream->readBytes ( aBuffer, nHeaderSize ) ) - { - sal_Int16 nPos = 0; - sal_Int8 *pBuffer = aBuffer.getArray(); - sal_Int16 nVersion = pBuffer[nPos++] & 0xFF; - nVersion |= ( pBuffer[nPos++] & 0xFF ) << 8; - if ( nVersion == n_ConstCurrentVersion ) - { - sal_Int32 nCount = pBuffer[nPos++] & 0xFF; - nCount |= ( pBuffer[nPos++] & 0xFF ) << 8; - nCount |= ( pBuffer[nPos++] & 0xFF ) << 16; - nCount |= ( pBuffer[nPos++] & 0xFF ) << 24; - rData->m_nIterationCount = nCount; - - rSize = pBuffer[nPos++] & 0xFF; - rSize |= ( pBuffer[nPos++] & 0xFF ) << 8; - rSize |= ( pBuffer[nPos++] & 0xFF ) << 16; - rSize |= ( pBuffer[nPos++] & 0xFF ) << 24; - - rEncAlg = pBuffer[nPos++] & 0xFF; - rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 8; - rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 16; - rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 24; - - rChecksumAlg = pBuffer[nPos++] & 0xFF; - rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 8; - rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 16; - rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 24; - - rDerivedKeySize = pBuffer[nPos++] & 0xFF; - rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 8; - rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 16; - rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 24; - - rStartKeyGenID = pBuffer[nPos++] & 0xFF; - rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 8; - rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 16; - rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 24; - - sal_Int16 nSaltLength = pBuffer[nPos++] & 0xFF; - nSaltLength |= ( pBuffer[nPos++] & 0xFF ) << 8; - sal_Int16 nIVLength = ( pBuffer[nPos++] & 0xFF ); - nIVLength |= ( pBuffer[nPos++] & 0xFF ) << 8; - sal_Int16 nDigestLength = pBuffer[nPos++] & 0xFF; - nDigestLength |= ( pBuffer[nPos++] & 0xFF ) << 8; - - sal_Int16 nMediaTypeLength = pBuffer[nPos++] & 0xFF; - nMediaTypeLength |= ( pBuffer[nPos++] & 0xFF ) << 8; - - if ( nSaltLength == rStream->readBytes ( aBuffer, nSaltLength ) ) - { - rData->m_aSalt.realloc ( nSaltLength ); - rtl_copyMemory ( rData->m_aSalt.getArray(), aBuffer.getConstArray(), nSaltLength ); - if ( nIVLength == rStream->readBytes ( aBuffer, nIVLength ) ) - { - rData->m_aInitVector.realloc ( nIVLength ); - rtl_copyMemory ( rData->m_aInitVector.getArray(), aBuffer.getConstArray(), nIVLength ); - if ( nDigestLength == rStream->readBytes ( aBuffer, nDigestLength ) ) - { - rData->m_aDigest.realloc ( nDigestLength ); - rtl_copyMemory ( rData->m_aDigest.getArray(), aBuffer.getConstArray(), nDigestLength ); - - if ( nMediaTypeLength == rStream->readBytes ( aBuffer, nMediaTypeLength ) ) - { - aMediaType = ::rtl::OUString( (sal_Unicode*)aBuffer.getConstArray(), - nMediaTypeLength / sizeof( sal_Unicode ) ); - bOk = sal_True; - } - } - } - } - } - } - return bOk; -} - -uno::Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory, - const uno::Reference< XInputStream >& xStream, - const ::rtl::Reference< EncryptionData > &rData ) - throw ( packages::WrongPasswordException, ZipIOException, RuntimeException ) -{ - if ( !rData.is() ) - throw ZipIOException( OUString(RTL_CONSTASCII_USTRINGPARAM( "Encrypted stream without encryption data!\n" )), - uno::Reference< XInterface >() ); - - if ( !rData->m_aKey.getLength() ) - throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< XSeekable > xSeek( xStream, UNO_QUERY ); - if ( !xSeek.is() ) - throw ZipIOException( OUString(RTL_CONSTASCII_USTRINGPARAM( "The stream must be seekable!\n" )), - uno::Reference< XInterface >() ); - - - // if we have a digest, then this file is an encrypted one and we should - // check if we can decrypt it or not - OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!\n" ); - if ( rData->m_aDigest.getLength() ) - { - sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() ); - if ( nSize > n_ConstDigestLength + 32 ) - nSize = n_ConstDigestLength + 32; - - // skip header - xSeek->seek( n_ConstHeaderSize + rData->m_aInitVector.getLength() + - rData->m_aSalt.getLength() + rData->m_aDigest.getLength() ); - - // Only want to read enough to verify the digest - Sequence < sal_Int8 > aReadBuffer ( nSize ); - - xStream->readBytes( aReadBuffer, nSize ); - - if ( !StaticHasValidPassword( xFactory, aReadBuffer, rData ) ) - throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - return new XUnbufferedStream( xFactory, xStream, rData ); -} - -#if 0 -// for debugging purposes -void CheckSequence( const uno::Sequence< sal_Int8 >& aSequence ) -{ - if ( aSequence.getLength() ) - { - sal_Int32* pPointer = *( (sal_Int32**)&aSequence ); - sal_Int32 nSize = *( pPointer + 1 ); - sal_Int32 nMemSize = *( pPointer - 2 ); - sal_Int32 nUsedMemSize = ( nSize + 4 * sizeof( sal_Int32 ) ); - OSL_ENSURE( nSize == aSequence.getLength() && nUsedMemSize + 7 - ( nUsedMemSize - 1 ) % 8 == nMemSize, "Broken Sequence!" ); - } -} -#endif - -sal_Bool ZipFile::StaticHasValidPassword( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const Sequence< sal_Int8 > &aReadBuffer, const ::rtl::Reference< EncryptionData > &rData ) -{ - if ( !rData.is() || !rData->m_aKey.getLength() ) - return sal_False; - - sal_Bool bRet = sal_False; - - uno::Reference< xml::crypto::XCipherContext > xCipher( StaticGetCipher( xFactory, rData, false ), uno::UNO_SET_THROW ); - - uno::Sequence< sal_Int8 > aDecryptBuffer; - uno::Sequence< sal_Int8 > aDecryptBuffer2; - try - { - aDecryptBuffer = xCipher->convertWithCipherContext( aReadBuffer ); - aDecryptBuffer2 = xCipher->finalizeCipherContextAndDispose(); - } - catch( uno::Exception& ) - { - // decryption with padding will throw the exception in finalizing if the buffer represent only part of the stream - // it is no problem, actually this is why we read 32 additional bytes ( two of maximal possible encryption blocks ) - } - - if ( aDecryptBuffer2.getLength() ) - { - sal_Int32 nOldLen = aDecryptBuffer.getLength(); - aDecryptBuffer.realloc( nOldLen + aDecryptBuffer2.getLength() ); - rtl_copyMemory( aDecryptBuffer.getArray() + nOldLen, aDecryptBuffer2.getArray(), aDecryptBuffer2.getLength() ); - } - - if ( aDecryptBuffer.getLength() > n_ConstDigestLength ) - aDecryptBuffer.realloc( n_ConstDigestLength ); - - uno::Sequence< sal_Int8 > aDigestSeq; - uno::Reference< xml::crypto::XDigestContext > xDigestContext( StaticGetDigestContextForChecksum( xFactory, rData ), uno::UNO_SET_THROW ); - - xDigestContext->updateDigest( aDecryptBuffer ); - aDigestSeq = xDigestContext->finalizeDigestAndDispose(); - - // If we don't have a digest, then we have to assume that the password is correct - if ( rData->m_aDigest.getLength() != 0 && - ( aDigestSeq.getLength() != rData->m_aDigest.getLength() || - 0 != rtl_compareMemory ( aDigestSeq.getConstArray(), - rData->m_aDigest.getConstArray(), - aDigestSeq.getLength() ) ) ) - { - // We should probably tell the user that the password they entered was wrong - } - else - bRet = sal_True; - - return bRet; -} - -sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ::rtl::Reference< EncryptionData >& rData ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Bool bRet = sal_False; - if ( rData.is() && rData->m_aKey.getLength() ) - { - xSeek->seek( rEntry.nOffset ); - sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize; - - // Only want to read enough to verify the digest - if ( nSize > n_ConstDigestDecrypt ) - nSize = n_ConstDigestDecrypt; - - Sequence < sal_Int8 > aReadBuffer ( nSize ); - - xStream->readBytes( aReadBuffer, nSize ); - - bRet = StaticHasValidPassword( m_xFactory, aReadBuffer, rData ); - } - - return bRet; -} - -uno::Reference< XInputStream > ZipFile::createUnbufferedStream( - SotMutexHolderRef aMutexHolder, - ZipEntry & rEntry, - const ::rtl::Reference< EncryptionData > &rData, - sal_Int8 nStreamMode, - sal_Bool bIsEncrypted, - ::rtl::OUString aMediaType ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - return new XUnbufferedStream ( m_xFactory, aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode ); -} - - -ZipEnumeration * SAL_CALL ZipFile::entries( ) -{ - return new ZipEnumeration ( aEntries ); -} - -uno::Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry, - const ::rtl::Reference< EncryptionData > &rData, - sal_Bool bIsEncrypted, - SotMutexHolderRef aMutexHolder ) - throw(IOException, ZipException, RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( rEntry.nOffset <= 0 ) - readLOC( rEntry ); - - // We want to return a rawStream if we either don't have a key or if the - // key is wrong - - sal_Bool bNeedRawStream = rEntry.nMethod == STORED; - - // if we have a digest, then this file is an encrypted one and we should - // check if we can decrypt it or not - if ( bIsEncrypted && rData.is() && rData->m_aDigest.getLength() ) - bNeedRawStream = !hasValidPassword ( rEntry, rData ); - - return createUnbufferedStream ( aMutexHolder, - rEntry, - rData, - bNeedRawStream ? UNBUFF_STREAM_RAW : UNBUFF_STREAM_DATA, - bIsEncrypted ); -} - -uno::Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry, - const ::rtl::Reference< EncryptionData > &rData, - sal_Bool bIsEncrypted, - SotMutexHolderRef aMutexHolder ) - throw ( packages::WrongPasswordException, - IOException, - ZipException, - RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( rEntry.nOffset <= 0 ) - readLOC( rEntry ); - - // An exception must be thrown in case stream is encrypted and - // there is no key or the key is wrong - sal_Bool bNeedRawStream = sal_False; - if ( bIsEncrypted ) - { - // in case no digest is provided there is no way - // to detect password correctness - if ( !rData.is() ) - throw ZipException( OUString(RTL_CONSTASCII_USTRINGPARAM( "Encrypted stream without encryption data!\n" )), - uno::Reference< XInterface >() ); - - // if we have a digest, then this file is an encrypted one and we should - // check if we can decrypt it or not - OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!\n" ); - if ( rData->m_aDigest.getLength() && !hasValidPassword ( rEntry, rData ) ) - throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - else - bNeedRawStream = ( rEntry.nMethod == STORED ); - - return createUnbufferedStream ( aMutexHolder, - rEntry, - rData, - bNeedRawStream ? UNBUFF_STREAM_RAW : UNBUFF_STREAM_DATA, - bIsEncrypted ); -} - -uno::Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry, - const ::rtl::Reference< EncryptionData >& rData, - sal_Bool bIsEncrypted, - SotMutexHolderRef aMutexHolder ) - throw(IOException, ZipException, RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( rEntry.nOffset <= 0 ) - readLOC( rEntry ); - - return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted ); -} - -uno::Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream( - ZipEntry& rEntry, - const ::rtl::Reference< EncryptionData >& rData, - const ::rtl::OUString& aMediaType, - SotMutexHolderRef aMutexHolder ) - throw ( packages::NoEncryptionException, - IOException, - ZipException, - RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !rData.is() ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( rEntry.nOffset <= 0 ) - readLOC( rEntry ); - - return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_WRAPPEDRAW, sal_True, aMediaType ); -} - -sal_Bool ZipFile::readLOC( ZipEntry &rEntry ) - throw(IOException, ZipException, RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nTestSig, nTime, nCRC, nSize, nCompressedSize; - sal_Int16 nVersion, nFlag, nHow, nPathLen, nExtraLen; - sal_Int32 nPos = -rEntry.nOffset; - - aGrabber.seek(nPos); - aGrabber >> nTestSig; - - if (nTestSig != LOCSIG) - throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid LOC header (bad signature") ), uno::Reference < XInterface > () ); - aGrabber >> nVersion; - aGrabber >> nFlag; - aGrabber >> nHow; - aGrabber >> nTime; - aGrabber >> nCRC; - aGrabber >> nCompressedSize; - aGrabber >> nSize; - aGrabber >> nPathLen; - aGrabber >> nExtraLen; - rEntry.nOffset = static_cast < sal_Int32 > (aGrabber.getPosition()) + nPathLen + nExtraLen; - - sal_Bool bBroken = sal_False; - - try - { - // read always in UTF8, some tools seem not to set UTF8 bit - uno::Sequence < sal_Int8 > aNameBuffer( nPathLen ); - sal_Int32 nRead = aGrabber.readBytes( aNameBuffer, nPathLen ); - if ( nRead < aNameBuffer.getLength() ) - aNameBuffer.realloc( nRead ); - - ::rtl::OUString sLOCPath = rtl::OUString::intern( (sal_Char *) aNameBuffer.getArray(), - aNameBuffer.getLength(), - RTL_TEXTENCODING_UTF8 ); - - if ( rEntry.nPathLen == -1 ) // the file was created - { - rEntry.nPathLen = nPathLen; - rEntry.sPath = sLOCPath; - } - - // the method can be reset for internal use so it is not checked - bBroken = rEntry.nVersion != nVersion - || rEntry.nFlag != nFlag - || rEntry.nTime != nTime - || rEntry.nPathLen != nPathLen - || !rEntry.sPath.equals( sLOCPath ); - } - catch(::std::bad_alloc &) - { - bBroken = sal_True; - } - - if ( bBroken && !bRecoveryMode ) - throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ), - uno::Reference< XInterface >() ); - - return sal_True; -} - -sal_Int32 ZipFile::findEND( ) - throw(IOException, ZipException, RuntimeException) -{ - // this method is called in constructor only, no need for mutex - sal_Int32 nLength, nPos, nEnd; - Sequence < sal_Int8 > aBuffer; - try - { - nLength = static_cast <sal_Int32 > (aGrabber.getLength()); - if (nLength == 0 || nLength < ENDHDR) - return -1; - nPos = nLength - ENDHDR - ZIP_MAXNAMELEN; - nEnd = nPos >= 0 ? nPos : 0 ; - - aGrabber.seek( nEnd ); - aGrabber.readBytes ( aBuffer, nLength - nEnd ); - - const sal_Int8 *pBuffer = aBuffer.getConstArray(); - - nPos = nLength - nEnd - ENDHDR; - while ( nPos >= 0 ) - { - if (pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 5 && pBuffer[nPos+3] == 6 ) - return nPos + nEnd; - nPos--; - } - } - catch ( IllegalArgumentException& ) - { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); - } - catch ( NotConnectedException& ) - { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); - } - catch ( BufferSizeExceededException& ) - { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); - } - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); -} - -sal_Int32 ZipFile::readCEN() - throw(IOException, ZipException, RuntimeException) -{ - // this method is called in constructor only, no need for mutex - sal_Int32 nCenLen, nCenPos = -1, nCenOff, nEndPos, nLocPos; - sal_uInt16 nCount, nTotal; - - try - { - nEndPos = findEND(); - if (nEndPos == -1) - return -1; - aGrabber.seek(nEndPos + ENDTOT); - aGrabber >> nTotal; - aGrabber >> nCenLen; - aGrabber >> nCenOff; - - if ( nTotal * CENHDR > nCenLen ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "invalid END header (bad entry count)") ), uno::Reference < XInterface > () ); - - if ( nTotal > ZIP_MAXENTRIES ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "too many entries in ZIP File") ), uno::Reference < XInterface > () ); - - if ( nCenLen < 0 || nCenLen > nEndPos ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () ); - - nCenPos = nEndPos - nCenLen; - - if ( nCenOff < 0 || nCenOff > nCenPos ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () ); - - nLocPos = nCenPos - nCenOff; - aGrabber.seek( nCenPos ); - Sequence < sal_Int8 > aCENBuffer ( nCenLen ); - sal_Int64 nRead = aGrabber.readBytes ( aCENBuffer, nCenLen ); - if ( static_cast < sal_Int64 > ( nCenLen ) != nRead ) - throw ZipException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Error reading CEN into memory buffer!") ), uno::Reference < XInterface > () ); - - MemoryByteGrabber aMemGrabber ( aCENBuffer ); - - ZipEntry aEntry; - sal_Int32 nTestSig; - sal_Int16 nCommentLen; - - for (nCount = 0 ; nCount < nTotal; nCount++) - { - aMemGrabber >> nTestSig; - if ( nTestSig != CENSIG ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad signature)") ), uno::Reference < XInterface > () ); - - aMemGrabber.skipBytes ( 2 ); - aMemGrabber >> aEntry.nVersion; - - if ( ( aEntry.nVersion & 1 ) == 1 ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (encrypted entry)") ), uno::Reference < XInterface > () ); - - aMemGrabber >> aEntry.nFlag; - aMemGrabber >> aEntry.nMethod; - - if ( aEntry.nMethod != STORED && aEntry.nMethod != DEFLATED) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad compression method)") ), uno::Reference < XInterface > () ); - - aMemGrabber >> aEntry.nTime; - aMemGrabber >> aEntry.nCrc; - aMemGrabber >> aEntry.nCompressedSize; - aMemGrabber >> aEntry.nSize; - aMemGrabber >> aEntry.nPathLen; - aMemGrabber >> aEntry.nExtraLen; - aMemGrabber >> nCommentLen; - aMemGrabber.skipBytes ( 8 ); - aMemGrabber >> aEntry.nOffset; - - aEntry.nOffset += nLocPos; - aEntry.nOffset *= -1; - - if ( aEntry.nPathLen < 0 ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected name length" ) ), uno::Reference < XInterface > () ); - - if ( nCommentLen < 0 ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected comment length" ) ), uno::Reference < XInterface > () ); - - if ( aEntry.nExtraLen < 0 ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected extra header info length") ), uno::Reference < XInterface > () ); - - // read always in UTF8, some tools seem not to set UTF8 bit - aEntry.sPath = rtl::OUString::intern ( (sal_Char *) aMemGrabber.getCurrentPos(), - aEntry.nPathLen, - RTL_TEXTENCODING_UTF8 ); - - if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aEntry.sPath, sal_True ) ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), uno::Reference < XInterface > () ); - - aMemGrabber.skipBytes( aEntry.nPathLen + aEntry.nExtraLen + nCommentLen ); - aEntries[aEntry.sPath] = aEntry; - } - - if (nCount != nTotal) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Count != Total") ), uno::Reference < XInterface > () ); - } - catch ( IllegalArgumentException & ) - { - // seek can throw this... - nCenPos = -1; // make sure we return -1 to indicate an error - } - return nCenPos; -} - -sal_Int32 ZipFile::recover() - throw(IOException, ZipException, RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nLength; - Sequence < sal_Int8 > aBuffer; - Sequence < sal_Int32 > aHeaderOffsets; - - try - { - nLength = static_cast <sal_Int32 > (aGrabber.getLength()); - if (nLength == 0 || nLength < ENDHDR) - return -1; - - aGrabber.seek( 0 ); - - const sal_Int32 nToRead = 32000; - for( sal_Int32 nGenPos = 0; aGrabber.readBytes( aBuffer, nToRead ) && aBuffer.getLength() > 16; ) - { - const sal_Int8 *pBuffer = aBuffer.getConstArray(); - sal_Int32 nBufSize = aBuffer.getLength(); - - sal_Int32 nPos = 0; - // the buffer should contain at least one header, - // or if it is end of the file, at least the postheader with sizes and hash - while( nPos < nBufSize - 30 - || ( nBufSize < nToRead && nPos < nBufSize - 16 ) ) - - { - if ( nPos < nBufSize - 30 && pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 3 && pBuffer[nPos+3] == 4 ) - { - ZipEntry aEntry; - MemoryByteGrabber aMemGrabber ( Sequence< sal_Int8 >( ((sal_Int8*)(&(pBuffer[nPos+4]))), 26 ) ); - - aMemGrabber >> aEntry.nVersion; - if ( ( aEntry.nVersion & 1 ) != 1 ) - { - aMemGrabber >> aEntry.nFlag; - aMemGrabber >> aEntry.nMethod; - - if ( aEntry.nMethod == STORED || aEntry.nMethod == DEFLATED ) - { - aMemGrabber >> aEntry.nTime; - aMemGrabber >> aEntry.nCrc; - aMemGrabber >> aEntry.nCompressedSize; - aMemGrabber >> aEntry.nSize; - aMemGrabber >> aEntry.nPathLen; - aMemGrabber >> aEntry.nExtraLen; - - sal_Int32 nDescrLength = - ( aEntry.nMethod == DEFLATED && ( aEntry.nFlag & 8 ) ) ? - 16 : 0; - - - // This is a quick fix for OOo1.1RC - // For OOo2.0 the whole package must be switched to unsigned values - if ( aEntry.nCompressedSize < 0 ) aEntry.nCompressedSize = 0x7FFFFFFF; - if ( aEntry.nSize < 0 ) aEntry.nSize = 0x7FFFFFFF; - if ( aEntry.nPathLen < 0 ) aEntry.nPathLen = 0x7FFF; - if ( aEntry.nExtraLen < 0 ) aEntry.nExtraLen = 0x7FFF; - // End of quick fix - - sal_Int32 nDataSize = ( aEntry.nMethod == DEFLATED ) ? aEntry.nCompressedSize : aEntry.nSize; - sal_Int32 nBlockLength = nDataSize + aEntry.nPathLen + aEntry.nExtraLen + 30 + nDescrLength; - if ( aEntry.nPathLen >= 0 && aEntry.nExtraLen >= 0 - && ( nGenPos + nPos + nBlockLength ) <= nLength ) - { - // read always in UTF8, some tools seem not to set UTF8 bit - if( nPos + 30 + aEntry.nPathLen <= nBufSize ) - aEntry.sPath = OUString ( (sal_Char *) &pBuffer[nPos + 30], - aEntry.nPathLen, - RTL_TEXTENCODING_UTF8 ); - else - { - Sequence < sal_Int8 > aFileName; - aGrabber.seek( nGenPos + nPos + 30 ); - aGrabber.readBytes( aFileName, aEntry.nPathLen ); - aEntry.sPath = OUString ( (sal_Char *) aFileName.getArray(), - aFileName.getLength(), - RTL_TEXTENCODING_UTF8 ); - aEntry.nPathLen = static_cast< sal_Int16 >(aFileName.getLength()); - } - - aEntry.nOffset = nGenPos + nPos + 30 + aEntry.nPathLen + aEntry.nExtraLen; - - if ( ( aEntry.nSize || aEntry.nCompressedSize ) && !checkSizeAndCRC( aEntry ) ) - { - aEntry.nCrc = 0; - aEntry.nCompressedSize = 0; - aEntry.nSize = 0; - } - - if ( aEntries.find( aEntry.sPath ) == aEntries.end() ) - aEntries[aEntry.sPath] = aEntry; - } - } - } - - nPos += 4; - } - else if (pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 7 && pBuffer[nPos+3] == 8 ) - { - sal_Int32 nCompressedSize, nSize, nCRC32; - MemoryByteGrabber aMemGrabber ( Sequence< sal_Int8 >( ((sal_Int8*)(&(pBuffer[nPos+4]))), 12 ) ); - aMemGrabber >> nCRC32; - aMemGrabber >> nCompressedSize; - aMemGrabber >> nSize; - - for( EntryHash::iterator aIter = aEntries.begin(); aIter != aEntries.end(); ++aIter ) - { - ZipEntry aTmp = (*aIter).second; - - // this is a broken package, accept this block not only for DEFLATED streams - if( (*aIter).second.nFlag & 8 ) - { - sal_Int32 nStreamOffset = nGenPos + nPos - nCompressedSize; - if ( nStreamOffset == (*aIter).second.nOffset && nCompressedSize > (*aIter).second.nCompressedSize ) - { - // only DEFLATED blocks need to be checked - sal_Bool bAcceptBlock = ( (*aIter).second.nMethod == STORED && nCompressedSize == nSize ); - - if ( !bAcceptBlock ) - { - sal_Int32 nRealSize = 0, nRealCRC = 0; - getSizeAndCRC( nStreamOffset, nCompressedSize, &nRealSize, &nRealCRC ); - bAcceptBlock = ( nRealSize == nSize && nRealCRC == nCRC32 ); - } - - if ( bAcceptBlock ) - { - (*aIter).second.nCrc = nCRC32; - (*aIter).second.nCompressedSize = nCompressedSize; - (*aIter).second.nSize = nSize; - } - } -#if 0 -// for now ignore clearly broken streams - else if( !(*aIter).second.nCompressedSize ) - { - (*aIter).second.nCrc = nCRC32; - sal_Int32 nRealStreamSize = nGenPos + nPos - (*aIter).second.nOffset; - (*aIter).second.nCompressedSize = nGenPos + nPos - (*aIter).second.nOffset; - (*aIter).second.nSize = nSize; - } -#endif - } - } - - nPos += 4; - } - else - nPos++; - } - - nGenPos += nPos; - aGrabber.seek( nGenPos ); - } - - return 0; - } - catch ( IllegalArgumentException& ) - { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); - } - catch ( NotConnectedException& ) - { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); - } - catch ( BufferSizeExceededException& ) - { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); - } -} - -sal_Bool ZipFile::checkSizeAndCRC( const ZipEntry& aEntry ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nSize = 0, nCRC = 0; - - if( aEntry.nMethod == STORED ) - return ( getCRC( aEntry.nOffset, aEntry.nSize ) == aEntry.nCrc ); - - getSizeAndCRC( aEntry.nOffset, aEntry.nCompressedSize, &nSize, &nCRC ); - return ( aEntry.nSize == nSize && aEntry.nCrc == nCRC ); -} - -sal_Int32 ZipFile::getCRC( sal_Int32 nOffset, sal_Int32 nSize ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - Sequence < sal_Int8 > aBuffer; - CRC32 aCRC; - sal_Int32 nBlockSize = ::std::min( nSize, static_cast< sal_Int32 >( 32000 ) ); - - aGrabber.seek( nOffset ); - for ( int ind = 0; - aGrabber.readBytes( aBuffer, nBlockSize ) && ind * nBlockSize < nSize; - ind++ ) - { - aCRC.updateSegment( aBuffer, 0, ::std::min( nBlockSize, nSize - ind * nBlockSize ) ); - } - - return aCRC.getValue(); -} - -void ZipFile::getSizeAndCRC( sal_Int32 nOffset, sal_Int32 nCompressedSize, sal_Int32 *nSize, sal_Int32 *nCRC ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - Sequence < sal_Int8 > aBuffer; - CRC32 aCRC; - sal_Int32 nRealSize = 0; - Inflater aInflaterLocal( sal_True ); - sal_Int32 nBlockSize = ::std::min( nCompressedSize, static_cast< sal_Int32 >( 32000 ) ); - - aGrabber.seek( nOffset ); - for ( int ind = 0; - !aInflaterLocal.finished() && aGrabber.readBytes( aBuffer, nBlockSize ) && ind * nBlockSize < nCompressedSize; - ind++ ) - { - Sequence < sal_Int8 > aData( nBlockSize ); - sal_Int32 nLastInflated = 0; - sal_Int32 nInBlock = 0; - - aInflaterLocal.setInput( aBuffer ); - do - { - nLastInflated = aInflaterLocal.doInflateSegment( aData, 0, nBlockSize ); - aCRC.updateSegment( aData, 0, nLastInflated ); - nInBlock += nLastInflated; - } while( !aInflater.finished() && nLastInflated ); - - nRealSize += nInBlock; - } - - *nSize = nRealSize; - *nCRC = aCRC.getValue(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx deleted file mode 100644 index 8efe20ebc..000000000 --- a/package/source/zipapi/ZipOutputStream.cxx +++ /dev/null @@ -1,452 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <comphelper/storagehelper.hxx> - -#include <osl/time.h> - -#include <EncryptionData.hxx> -#include <PackageConstants.hxx> -#include <ZipEntry.hxx> -#include <ZipFile.hxx> -#include <ZipPackageStream.hxx> -#include <ZipOutputStream.hxx> - -using namespace com::sun::star; -using namespace com::sun::star::io; -using namespace com::sun::star::uno; -using namespace com::sun::star::packages; -using namespace com::sun::star::packages::zip; -using namespace com::sun::star::packages::zip::ZipConstants; - -/** This class is used to write Zip files - */ -ZipOutputStream::ZipOutputStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory, - const uno::Reference < XOutputStream > &xOStream ) -: m_xFactory( xFactory ) -, xStream(xOStream) -, m_aDeflateBuffer(n_ConstBufferSize) -, aDeflater(DEFAULT_COMPRESSION, sal_True) -, aChucker(xOStream) -, pCurrentEntry(NULL) -, nMethod(DEFLATED) -, bFinished(sal_False) -, bEncryptCurrentEntry(sal_False) -, m_pCurrentStream(NULL) -{ -} - -ZipOutputStream::~ZipOutputStream( void ) -{ - for (sal_Int32 i = 0, nEnd = aZipList.size(); i < nEnd; i++) - delete aZipList[i]; -} - -void SAL_CALL ZipOutputStream::setMethod( sal_Int32 nNewMethod ) - throw(RuntimeException) -{ - nMethod = static_cast < sal_Int16 > (nNewMethod); -} -void SAL_CALL ZipOutputStream::setLevel( sal_Int32 nNewLevel ) - throw(RuntimeException) -{ - aDeflater.setLevel( nNewLevel); -} - -void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry, - ZipPackageStream* pStream, - sal_Bool bEncrypt) - throw(IOException, RuntimeException) -{ - if (pCurrentEntry != NULL) - closeEntry(); - if (rEntry.nTime == -1) - rEntry.nTime = getCurrentDosTime(); - if (rEntry.nMethod == -1) - rEntry.nMethod = nMethod; - rEntry.nVersion = 20; - rEntry.nFlag = 1 << 11; - if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 || - rEntry.nCrc == -1) - { - rEntry.nSize = rEntry.nCompressedSize = 0; - rEntry.nFlag |= 8; - } - - if (bEncrypt) - { - bEncryptCurrentEntry = sal_True; - - m_xCipherContext = ZipFile::StaticGetCipher( m_xFactory, pStream->GetEncryptionData(), true ); - m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( m_xFactory, pStream->GetEncryptionData() ); - mnDigested = 0; - rEntry.nFlag |= 1 << 4; - m_pCurrentStream = pStream; - } - sal_Int32 nLOCLength = writeLOC(rEntry); - rEntry.nOffset = static_cast < sal_Int32 > (aChucker.GetPosition()) - nLOCLength; - aZipList.push_back( &rEntry ); - pCurrentEntry = &rEntry; -} - -void SAL_CALL ZipOutputStream::closeEntry( ) - throw(IOException, RuntimeException) -{ - ZipEntry *pEntry = pCurrentEntry; - if (pEntry) - { - switch (pEntry->nMethod) - { - case DEFLATED: - aDeflater.finish(); - while (!aDeflater.finished()) - doDeflate(); - if ((pEntry->nFlag & 8) == 0) - { - if (pEntry->nSize != aDeflater.getTotalIn()) - { - OSL_FAIL("Invalid entry size"); - } - if (pEntry->nCompressedSize != aDeflater.getTotalOut()) - { - // Different compression strategies make the merit of this - // test somewhat dubious - pEntry->nCompressedSize = aDeflater.getTotalOut(); - } - if (pEntry->nCrc != aCRC.getValue()) - { - OSL_FAIL("Invalid entry CRC-32"); - } - } - else - { - if ( !bEncryptCurrentEntry ) - { - pEntry->nSize = aDeflater.getTotalIn(); - pEntry->nCompressedSize = aDeflater.getTotalOut(); - } - pEntry->nCrc = aCRC.getValue(); - writeEXT(*pEntry); - } - aDeflater.reset(); - aCRC.reset(); - break; - case STORED: - if (!((pEntry->nFlag & 8) == 0)) - OSL_FAIL( "Serious error, one of compressed size, size or CRC was -1 in a STORED stream"); - break; - default: - OSL_FAIL("Invalid compression method"); - break; - } - - if (bEncryptCurrentEntry) - { - bEncryptCurrentEntry = sal_False; - - m_xCipherContext.clear(); - - uno::Sequence< sal_Int8 > aDigestSeq; - if ( m_xDigestContext.is() ) - { - aDigestSeq = m_xDigestContext->finalizeDigestAndDispose(); - m_xDigestContext.clear(); - } - - if ( m_pCurrentStream ) - m_pCurrentStream->setDigest( aDigestSeq ); - } - pCurrentEntry = NULL; - m_pCurrentStream = NULL; - } -} - -void SAL_CALL ZipOutputStream::write( const Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) - throw(IOException, RuntimeException) -{ - switch (pCurrentEntry->nMethod) - { - case DEFLATED: - if (!aDeflater.finished()) - { - aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength); - while (!aDeflater.needsInput()) - doDeflate(); - if (!bEncryptCurrentEntry) - aCRC.updateSegment(rBuffer, nNewOffset, nNewLength); - } - break; - case STORED: - { - Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength ); - aChucker.WriteBytes( aTmpBuffer ); - } - break; - } -} - -void SAL_CALL ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 /*nNewOffset*/, sal_Int32 nNewLength ) - throw(IOException, RuntimeException) -{ - Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength ); - aChucker.WriteBytes( aTmpBuffer ); -} - -void SAL_CALL ZipOutputStream::rawCloseEntry( ) - throw(IOException, RuntimeException) -{ - if ( pCurrentEntry->nMethod == DEFLATED && ( pCurrentEntry->nFlag & 8 ) ) - writeEXT(*pCurrentEntry); - pCurrentEntry = NULL; -} - -void SAL_CALL ZipOutputStream::finish( ) - throw(IOException, RuntimeException) -{ - if (bFinished) - return; - - if (pCurrentEntry != NULL) - closeEntry(); - - if (aZipList.size() < 1) - OSL_FAIL("Zip file must have at least one entry!\n"); - - sal_Int32 nOffset= static_cast < sal_Int32 > (aChucker.GetPosition()); - for (sal_Int32 i =0, nEnd = aZipList.size(); i < nEnd; i++) - writeCEN( *aZipList[i] ); - writeEND( nOffset, static_cast < sal_Int32 > (aChucker.GetPosition()) - nOffset); - bFinished = sal_True; - xStream->flush(); -} - -void ZipOutputStream::doDeflate() -{ - sal_Int32 nLength = aDeflater.doDeflateSegment(m_aDeflateBuffer, 0, m_aDeflateBuffer.getLength()); - - if ( nLength > 0 ) - { - uno::Sequence< sal_Int8 > aTmpBuffer( m_aDeflateBuffer.getConstArray(), nLength ); - if ( bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) - { - // Need to update our digest before encryption... - sal_Int32 nDiff = n_ConstDigestLength - mnDigested; - if ( nDiff ) - { - sal_Int32 nEat = ::std::min( nLength, nDiff ); - uno::Sequence< sal_Int8 > aTmpSeq( aTmpBuffer.getConstArray(), nEat ); - m_xDigestContext->updateDigest( aTmpSeq ); - mnDigested = mnDigested + static_cast< sal_Int16 >( nEat ); - } - - uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer ); - - aChucker.WriteBytes( aEncryptionBuffer ); - - // the sizes as well as checksum for encrypted streams is calculated here - pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); - pCurrentEntry->nSize = pCurrentEntry->nCompressedSize; - aCRC.update( aEncryptionBuffer ); - } - else - { - aChucker.WriteBytes ( aTmpBuffer ); - } - } - - if ( aDeflater.finished() && bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) - { - uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose(); - if ( aEncryptionBuffer.getLength() ) - { - aChucker.WriteBytes( aEncryptionBuffer ); - - // the sizes as well as checksum for encrypted streams is calculated hier - pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); - pCurrentEntry->nSize = pCurrentEntry->nCompressedSize; - aCRC.update( aEncryptionBuffer ); - } - } -} - -void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) - throw(IOException, RuntimeException) -{ - aChucker << ENDSIG; - aChucker << static_cast < sal_Int16 > ( 0 ); - aChucker << static_cast < sal_Int16 > ( 0 ); - aChucker << static_cast < sal_Int16 > ( aZipList.size() ); - aChucker << static_cast < sal_Int16 > ( aZipList.size() ); - aChucker << nLength; - aChucker << nOffset; - aChucker << static_cast < sal_Int16 > ( 0 ); -} -void ZipOutputStream::writeCEN( const ZipEntry &rEntry ) - throw(IOException, RuntimeException) -{ - if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) ) - throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); - - ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); - sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); - - aChucker << CENSIG; - aChucker << rEntry.nVersion; - aChucker << rEntry.nVersion; - if (rEntry.nFlag & (1 << 4) ) - { - // If it's an encrypted entry, we pretend its stored plain text - ZipEntry *pEntry = const_cast < ZipEntry * > ( &rEntry ); - pEntry->nFlag &= ~(1 <<4 ); - aChucker << rEntry.nFlag; - aChucker << static_cast < sal_Int16 > ( STORED ); - } - else - { - aChucker << rEntry.nFlag; - aChucker << rEntry.nMethod; - } - aChucker << static_cast < sal_uInt32> ( rEntry.nTime ); - aChucker << static_cast < sal_uInt32> ( rEntry.nCrc ); - aChucker << rEntry.nCompressedSize; - aChucker << rEntry.nSize; - aChucker << nNameLength; - aChucker << static_cast < sal_Int16> (0); - aChucker << static_cast < sal_Int16> (0); - aChucker << static_cast < sal_Int16> (0); - aChucker << static_cast < sal_Int16> (0); - aChucker << static_cast < sal_Int32> (0); - aChucker << rEntry.nOffset; - - Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() ); - aChucker.WriteBytes( aSequence ); -} -void ZipOutputStream::writeEXT( const ZipEntry &rEntry ) - throw(IOException, RuntimeException) -{ - aChucker << EXTSIG; - aChucker << static_cast < sal_uInt32> ( rEntry.nCrc ); - aChucker << rEntry.nCompressedSize; - aChucker << rEntry.nSize; -} - -sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) - throw(IOException, RuntimeException) -{ - if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) ) - throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); - - ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); - sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); - - aChucker << LOCSIG; - aChucker << rEntry.nVersion; - - if (rEntry.nFlag & (1 << 4) ) - { - // If it's an encrypted entry, we pretend its stored plain text - sal_Int16 nTmpFlag = rEntry.nFlag; - nTmpFlag &= ~(1 <<4 ); - aChucker << nTmpFlag; - aChucker << static_cast < sal_Int16 > ( STORED ); - } - else - { - aChucker << rEntry.nFlag; - aChucker << rEntry.nMethod; - } - - aChucker << static_cast < sal_uInt32 > (rEntry.nTime); - if ((rEntry.nFlag & 8) == 8 ) - { - aChucker << static_cast < sal_Int32 > (0); - aChucker << static_cast < sal_Int32 > (0); - aChucker << static_cast < sal_Int32 > (0); - } - else - { - aChucker << static_cast < sal_uInt32 > (rEntry.nCrc); - aChucker << rEntry.nCompressedSize; - aChucker << rEntry.nSize; - } - aChucker << nNameLength; - aChucker << static_cast < sal_Int16 > (0); - - Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() ); - aChucker.WriteBytes( aSequence ); - - return LOCHDR + nNameLength; -} -sal_uInt32 ZipOutputStream::getCurrentDosTime( ) -{ - oslDateTime aDateTime; - TimeValue aTimeValue; - osl_getSystemTime ( &aTimeValue ); - osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime); - - sal_uInt32 nYear = static_cast <sal_uInt32> (aDateTime.Year); - - if (nYear>1980) - nYear-=1980; - else if (nYear>80) - nYear-=80; - sal_uInt32 nResult = static_cast < sal_uInt32>( ( ( ( aDateTime.Day) + - ( 32 * (aDateTime.Month)) + - ( 512 * nYear ) ) << 16) | - ( ( aDateTime.Seconds/2) + - ( 32 * aDateTime.Minutes) + - ( 2048 * static_cast <sal_uInt32 > (aDateTime.Hours) ) ) ); - return nResult; -} -/* - - This is actually never used, so I removed it, but thought that the - implementation details may be useful in the future...mtg 20010307 - - I stopped using the time library and used the OSL version instead, but - it might still be useful to have this code here.. - -void ZipOutputStream::dosDateToTMDate ( tm &rTime, sal_uInt32 nDosDate) -{ - sal_uInt32 nDate = static_cast < sal_uInt32 > (nDosDate >> 16); - rTime.tm_mday = static_cast < sal_uInt32 > ( nDate & 0x1F); - rTime.tm_mon = static_cast < sal_uInt32 > ( ( ( (nDate) & 0x1E0)/0x20)-1); - rTime.tm_year = static_cast < sal_uInt32 > ( ( (nDate & 0x0FE00)/0x0200)+1980); - - rTime.tm_hour = static_cast < sal_uInt32 > ( (nDosDate & 0xF800)/0x800); - rTime.tm_min = static_cast < sal_uInt32 > ( (nDosDate & 0x7E0)/0x20); - rTime.tm_sec = static_cast < sal_uInt32 > ( 2 * (nDosDate & 0x1F) ); -} -*/ - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/blowfishcontext.cxx b/package/source/zipapi/blowfishcontext.cxx deleted file mode 100644 index 6459cc4e4..000000000 --- a/package/source/zipapi/blowfishcontext.cxx +++ /dev/null @@ -1,122 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include <rtl/cipher.h> -#include <rtl/ref.hxx> - -#include "blowfishcontext.hxx" - -using namespace ::com::sun::star; - -// static -uno::Reference< xml::crypto::XCipherContext > BlowfishCFB8CipherContext::Create( const uno::Sequence< sal_Int8 >& aDerivedKey, const uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt ) -{ - ::rtl::Reference< BlowfishCFB8CipherContext > xResult = new BlowfishCFB8CipherContext(); - xResult->m_pCipher = rtl_cipher_create( rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream ); - if ( !xResult->m_pCipher ) - throw uno::RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not create cipher!")), - uno::Reference< XInterface >() ); - - if ( rtl_Cipher_E_None != rtl_cipher_init( - xResult->m_pCipher, - bEncrypt ? rtl_Cipher_DirectionEncode : rtl_Cipher_DirectionDecode, - reinterpret_cast< const sal_uInt8* >( aDerivedKey.getConstArray() ), - aDerivedKey.getLength(), - reinterpret_cast< const sal_uInt8* >( aInitVector.getConstArray() ), - aInitVector.getLength() ) ) - { - throw uno::RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not initialize cipher!") ), - uno::Reference< XInterface >() ); - } - - xResult->m_bEncrypt = bEncrypt; - - return uno::Reference< xml::crypto::XCipherContext >( xResult.get() ); -} - -BlowfishCFB8CipherContext::~BlowfishCFB8CipherContext() -{ - if ( m_pCipher ) - { - rtl_cipher_destroy ( m_pCipher ); - m_pCipher = NULL; - } -} - -uno::Sequence< sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::convertWithCipherContext( const uno::Sequence< ::sal_Int8 >& aData ) - throw( lang::IllegalArgumentException, lang::DisposedException, uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( !m_pCipher ) - throw lang::DisposedException(); - - uno::Sequence< sal_Int8 > aResult( aData.getLength() ); - rtlCipherError nError = rtl_Cipher_E_None; - - if ( m_bEncrypt ) - { - rtl_cipher_encode( m_pCipher, - aData.getConstArray(), - aData.getLength(), - reinterpret_cast< sal_uInt8* >( aResult.getArray() ), - aResult.getLength() ); - } - else - { - rtl_cipher_decode( m_pCipher, - aData.getConstArray(), - aData.getLength(), - reinterpret_cast< sal_uInt8* >( aResult.getArray() ), - aResult.getLength() ); - } - - if ( rtl_Cipher_E_None != nError ) - { - throw uno::RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not decrypt/encrypt with cipher!") ), - uno::Reference< uno::XInterface >() ); - } - - return aResult; -} - -uno::Sequence< ::sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::finalizeCipherContextAndDispose() - throw( lang::DisposedException, uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( !m_pCipher ) - throw lang::DisposedException(); - - rtl_cipher_destroy ( m_pCipher ); - m_pCipher = NULL; - - return uno::Sequence< sal_Int8 >(); -} - - diff --git a/package/source/zipapi/blowfishcontext.hxx b/package/source/zipapi/blowfishcontext.hxx deleted file mode 100644 index 49cce2fc0..000000000 --- a/package/source/zipapi/blowfishcontext.hxx +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _BLOWFISHCONTEXT_HXX -#define _BLOWFISHCONTEXT_HXX - -#include <com/sun/star/xml/crypto/XCipherContext.hpp> - -#include <cppuhelper/implbase1.hxx> -#include <osl/mutex.hxx> - -class BlowfishCFB8CipherContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XCipherContext > -{ - ::osl::Mutex m_aMutex; - void* m_pCipher; - bool m_bEncrypt; - - BlowfishCFB8CipherContext() - : m_pCipher( NULL ) - , m_bEncrypt( false ) - {} - -public: - - virtual ~BlowfishCFB8CipherContext(); - - static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > - Create( const ::com::sun::star::uno::Sequence< sal_Int8 >& aDerivedKey, const ::com::sun::star::uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt ); - - virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL convertWithCipherContext( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeCipherContextAndDispose( ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); -}; - -#endif // _BLOWFISHCONTEXT_HXX - diff --git a/package/source/zipapi/makefile.mk b/package/source/zipapi/makefile.mk deleted file mode 100644 index 8a07d448d..000000000 --- a/package/source/zipapi/makefile.mk +++ /dev/null @@ -1,62 +0,0 @@ -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2000, 2010 Oracle and/or its affiliates. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# <http://www.openoffice.org/license.html> -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -PRJ=..$/.. -PRJNAME=package -TARGET=zipapi - -ENABLE_EXCEPTIONS=TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE : settings.mk -.INCLUDE : $(PRJ)$/util$/package.pmk - -# --- Files -------------------------------------------------------- -.IF "$(L10N_framework)"=="" -.IF "$(SYSTEM_ZLIB)" == "YES" -CFLAGS+=-DSYSTEM_ZLIB -.ENDIF - -SLOFILES= \ - $(SLO)$/CRC32.obj \ - $(SLO)$/ByteChucker.obj \ - $(SLO)$/ByteGrabber.obj \ - $(SLO)$/blowfishcontext.obj \ - $(SLO)$/Inflater.obj \ - $(SLO)$/Deflater.obj \ - $(SLO)$/sha1context.obj \ - $(SLO)$/ZipEnumeration.obj \ - $(SLO)$/ZipFile.obj \ - $(SLO)$/ZipOutputStream.obj \ - $(SLO)$/XUnbufferedStream.obj - -.ENDIF # L10N_framework - -# --- Targets ------------------------------------------------------ - -.INCLUDE : target.mk diff --git a/package/source/zipapi/sha1context.cxx b/package/source/zipapi/sha1context.cxx deleted file mode 100644 index 0e34fd4a9..000000000 --- a/package/source/zipapi/sha1context.cxx +++ /dev/null @@ -1,97 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include <rtl/digest.h> -#include <rtl/ref.hxx> - -#include "sha1context.hxx" - -using namespace ::com::sun::star; - -// static -uno::Reference< xml::crypto::XDigestContext > SHA1DigestContext::Create() -{ - ::rtl::Reference< SHA1DigestContext > xResult = new SHA1DigestContext(); - xResult->m_pDigest = rtl_digest_createSHA1(); - if ( !xResult->m_pDigest ) - throw uno::RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not create cipher!") ), - uno::Reference< XInterface >() ); - - return uno::Reference< xml::crypto::XDigestContext >( xResult.get() ); -} - -SHA1DigestContext::~SHA1DigestContext() -{ - if ( m_pDigest ) - { - rtl_digest_destroySHA1( m_pDigest ); - m_pDigest = NULL; - } -} - -void SAL_CALL SHA1DigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& aData ) - throw( lang::DisposedException, uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( !m_pDigest ) - throw lang::DisposedException(); - - if ( rtl_Digest_E_None != rtl_digest_updateSHA1( m_pDigest, aData.getConstArray(), aData.getLength() ) ) - { - rtl_digest_destroySHA1( m_pDigest ); - m_pDigest = NULL; - - throw uno::RuntimeException(); - } -} - -uno::Sequence< ::sal_Int8 > SAL_CALL SHA1DigestContext::finalizeDigestAndDispose() - throw( lang::DisposedException, uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( !m_pDigest ) - throw lang::DisposedException(); - - uno::Sequence< sal_Int8 > aResult( RTL_DIGEST_LENGTH_SHA1 ); - if ( rtl_Digest_E_None != rtl_digest_getSHA1( m_pDigest, reinterpret_cast< sal_uInt8* >( aResult.getArray() ), aResult.getLength() ) ) - { - rtl_digest_destroySHA1( m_pDigest ); - m_pDigest = NULL; - - throw uno::RuntimeException(); - } - - rtl_digest_destroySHA1( m_pDigest ); - m_pDigest = NULL; - - return aResult; -} - - diff --git a/package/source/zipapi/sha1context.hxx b/package/source/zipapi/sha1context.hxx deleted file mode 100644 index 6d9374db8..000000000 --- a/package/source/zipapi/sha1context.hxx +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _SHA1CONTEXT_HXX -#define _SHA1CONTEXT_HXX - -#include <com/sun/star/xml/crypto/XDigestContext.hpp> - -#include <cppuhelper/implbase1.hxx> -#include <osl/mutex.hxx> - -class SHA1DigestContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XDigestContext > -{ - ::osl::Mutex m_aMutex; - void* m_pDigest; - - SHA1DigestContext() - : m_pDigest( NULL ) - {} - -public: - - virtual ~SHA1DigestContext(); - - static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > - Create(); - - virtual void SAL_CALL updateDigest( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeDigestAndDispose() throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ContentInfo.hxx b/package/source/zippackage/ContentInfo.hxx deleted file mode 100644 index 65a8a0c7a..000000000 --- a/package/source/zippackage/ContentInfo.hxx +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _CONTENT_INFO_HXX_ -#define _CONTENT_INFO_HXX_ - -#include <com/sun/star/container/XNameContainer.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <ZipPackageFolder.hxx> -#include <ZipPackageStream.hxx> - -namespace com { namespace sun { namespace star { namespace packages { -class ContentInfo : public cppu::OWeakObject -{ -public: - com::sun::star::uno::Reference < com::sun::star::lang::XUnoTunnel > xTunnel; - bool bFolder; - union - { - ZipPackageFolder *pFolder; - ZipPackageStream *pStream; - }; - ContentInfo ( ZipPackageStream * pNewStream ) - : xTunnel ( pNewStream ) - , bFolder ( false ) - , pStream ( pNewStream ) - { - } - ContentInfo ( ZipPackageFolder * pNewFolder ) - : xTunnel ( pNewFolder ) - , bFolder ( true ) - , pFolder ( pNewFolder ) - { - } - virtual ~ContentInfo () - { - if ( bFolder ) - pFolder->releaseUpwardRef(); - else - pStream->clearParent(); - } -}; -} } } } -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx deleted file mode 100644 index b3eb2fc47..000000000 --- a/package/source/zippackage/ZipPackage.cxx +++ /dev/null @@ -1,1890 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * ( a copy is included in the LICENSE file that accompanied this code ). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER( update_precomp.py ): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ZipPackage.hxx> -#include <ZipPackageSink.hxx> -#include <ZipEnumeration.hxx> -#include <ZipPackageStream.hxx> -#include <ZipPackageFolder.hxx> -#include <ZipOutputStream.hxx> -#include <ZipPackageBuffer.hxx> -#include <ZipFile.hxx> -#include <PackageConstants.hxx> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <com/sun/star/packages/manifest/XManifestReader.hpp> -#include <com/sun/star/packages/manifest/XManifestWriter.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/io/XTruncate.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/container/XNameContainer.hpp> -#include <com/sun/star/ucb/IOErrorCode.hpp> -#include <ucbhelper/content.hxx> -#include <cppuhelper/factory.hxx> -#include <cppuhelper/exc_hlp.hxx> -#include <com/sun/star/ucb/TransferInfo.hpp> -#include <com/sun/star/ucb/NameClash.hpp> -#include <com/sun/star/ucb/OpenCommandArgument2.hpp> -#include <com/sun/star/ucb/OpenMode.hpp> -#include <com/sun/star/ucb/XProgressHandler.hpp> -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/io/XActiveDataStreamer.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/embed/UseBackupException.hpp> -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/beans/NamedValue.hpp> -#include <com/sun/star/xml/crypto/DigestID.hpp> -#include <com/sun/star/xml/crypto/CipherID.hpp> -#include <cppuhelper/implbase1.hxx> -#include <ContentInfo.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <rtl/uri.hxx> -#include <rtl/random.h> -#include <rtl/logfile.hxx> -#include <rtl/instance.hxx> -#include <osl/time.h> -#include <osl/file.hxx> -#include "com/sun/star/io/XAsyncOutputMonitor.hpp" - -#include <memory> -#include <vector> - -#include <ucbhelper/contentbroker.hxx> -#include <ucbhelper/fileidentifierconverter.hxx> -#include <comphelper/seekableinput.hxx> -#include <comphelper/storagehelper.hxx> -#include <comphelper/ofopxmlhelper.hxx> -#include <comphelper/documentconstants.hxx> -#include <comphelper/sequenceashashmap.hxx> - -using namespace std; -using namespace osl; -using namespace cppu; -using namespace ucbhelper; -using namespace com::sun::star; -using namespace com::sun::star::io; -using namespace com::sun::star::uno; -using namespace com::sun::star::ucb; -using namespace com::sun::star::util; -using namespace com::sun::star::lang; -using namespace com::sun::star::task; -using namespace com::sun::star::beans; -using namespace com::sun::star::packages; -using namespace com::sun::star::container; -using namespace com::sun::star::packages::zip; -using namespace com::sun::star::packages::manifest; -using namespace com::sun::star::packages::zip::ZipConstants; - -using ::rtl::OUString; -using ::rtl::OString; - -#define LOGFILE_AUTHOR "mg115289" - - -namespace { - -sal_Bool isLocalFile_Impl( ::rtl::OUString aURL ) -{ - ::rtl::OUString aSystemPath; - ContentBroker* pBroker = ContentBroker::get(); - if ( !pBroker ) - { - ::rtl::OUString aRet; - if ( FileBase::getSystemPathFromFileURL( aURL, aRet ) == FileBase::E_None ) - aSystemPath = aRet; - } - else - { - uno::Reference< XContentProviderManager > xManager = - pBroker->getContentProviderManagerInterface(); - try - { - aSystemPath = getSystemPathFromFileURL( xManager, aURL ); - } - catch ( Exception& ) - { - } - } - - return ( aSystemPath.getLength() != 0 ); -} - -} - -//=========================================================================== - -class ActiveDataStreamer : public ::cppu::WeakImplHelper1< XActiveDataStreamer > -{ - uno::Reference< XStream > mStream; -public: - - virtual uno::Reference< XStream > SAL_CALL getStream() - throw( RuntimeException ) - { return mStream; } - - virtual void SAL_CALL setStream( const uno::Reference< XStream >& stream ) - throw( RuntimeException ) - { mStream = stream; } -}; - -class DummyInputStream : public ::cppu::WeakImplHelper1< XInputStream > -{ - virtual sal_Int32 SAL_CALL readBytes( uno::Sequence< sal_Int8 >&, sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) - { return 0; } - - virtual sal_Int32 SAL_CALL readSomeBytes( uno::Sequence< sal_Int8 >&, sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) - { return 0; } - - virtual void SAL_CALL skipBytes( sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) - {} - - virtual sal_Int32 SAL_CALL available() - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) - { return 0; } - - virtual void SAL_CALL closeInput() - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) - {} -}; - -//=========================================================================== - -ZipPackage::ZipPackage ( const uno::Reference < XMultiServiceFactory > &xNewFactory ) -: m_aMutexHolder( new SotMutexHolder ) -, m_nStartKeyGenerationID( xml::crypto::DigestID::SHA1 ) -, m_nChecksumDigestID( xml::crypto::DigestID::SHA1_1K ) -, m_nCommonEncryptionID( xml::crypto::CipherID::BLOWFISH_CFB_8 ) -, m_bHasEncryptedEntries ( sal_False ) -, m_bHasNonEncryptedEntries ( sal_False ) -, m_bInconsistent ( sal_False ) -, m_bForceRecovery ( sal_False ) -, m_bMediaTypeFallbackUsed ( sal_False ) -, m_nFormat( embed::StorageFormats::PACKAGE ) // package is the default format -, m_bAllowRemoveOnInsert( sal_True ) -, m_eMode ( e_IMode_None ) -, m_xFactory( xNewFactory ) -, m_pRootFolder( NULL ) -, m_pZipFile( NULL ) -{ - m_xRootFolder = m_pRootFolder = new ZipPackageFolder( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert ); -} - -ZipPackage::~ZipPackage( void ) -{ - delete m_pZipFile; - - // All folders and streams contain pointers to their parents, when a parent diappeares - // it should disconnect all the children from itself during destruction automatically. - // So there is no need in explicit m_pRootFolder->releaseUpwardRef() call here any more - // since m_pRootFolder has no parent and cleaning of it's children will be done automatically - // during m_pRootFolder dieing by refcount. -} - -//-------------------------------------------------------- -void ZipPackage::parseManifest() -{ - if ( m_nFormat == embed::StorageFormats::PACKAGE ) - { - sal_Bool bManifestParsed = sal_False; - bool bDifferentStartKeyAlgorithm = false; - const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) ); - if ( m_xRootFolder->hasByName( sMeta ) ) - { - const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ); - - try { - uno::Reference< XUnoTunnel > xTunnel; - Any aAny = m_xRootFolder->getByName( sMeta ); - aAny >>= xTunnel; - uno::Reference< XNameContainer > xMetaInfFolder( xTunnel, UNO_QUERY ); - if ( xMetaInfFolder.is() && xMetaInfFolder->hasByName( sManifest ) ) - { - aAny = xMetaInfFolder->getByName( sManifest ); - aAny >>= xTunnel; - uno::Reference < XActiveDataSink > xSink ( xTunnel, UNO_QUERY ); - if ( xSink.is() ) - { - OUString sManifestReader ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) ); - uno::Reference < XManifestReader > xReader ( m_xFactory->createInstance( sManifestReader ), UNO_QUERY ); - if ( xReader.is() ) - { - const OUString sPropFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - const OUString sPropVersion ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); - const OUString sPropMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - const OUString sPropInitialisationVector ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); - const OUString sPropSalt ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); - const OUString sPropIterationCount ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); - const OUString sPropSize ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); - const OUString sPropDigest ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); - const OUString sPropDerivedKeySize ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); - const OUString sPropDigestAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); - const OUString sPropEncryptionAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); - const OUString sPropStartKeyAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); - - uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence = xReader->readManifestSequence ( xSink->getInputStream() ); - sal_Int32 nLength = aManifestSequence.getLength(); - const uno::Sequence < PropertyValue > *pSequence = aManifestSequence.getConstArray(); - ZipPackageStream *pStream = NULL; - ZipPackageFolder *pFolder = NULL; - - for ( sal_Int32 i = 0; i < nLength ; i++, pSequence++ ) - { - OUString sPath, sMediaType, sVersion; - const PropertyValue *pValue = pSequence->getConstArray(); - const Any *pSalt = NULL, *pVector = NULL, *pCount = NULL, *pSize = NULL, *pDigest = NULL, *pDigestAlg = NULL, *pEncryptionAlg = NULL, *pStartKeyAlg = NULL, *pDerivedKeySize = NULL; - for ( sal_Int32 j = 0, nNum = pSequence->getLength(); j < nNum; j++ ) - { - if ( pValue[j].Name.equals( sPropFullPath ) ) - pValue[j].Value >>= sPath; - else if ( pValue[j].Name.equals( sPropVersion ) ) - pValue[j].Value >>= sVersion; - else if ( pValue[j].Name.equals( sPropMediaType ) ) - pValue[j].Value >>= sMediaType; - else if ( pValue[j].Name.equals( sPropSalt ) ) - pSalt = &( pValue[j].Value ); - else if ( pValue[j].Name.equals( sPropInitialisationVector ) ) - pVector = &( pValue[j].Value ); - else if ( pValue[j].Name.equals( sPropIterationCount ) ) - pCount = &( pValue[j].Value ); - else if ( pValue[j].Name.equals( sPropSize ) ) - pSize = &( pValue[j].Value ); - else if ( pValue[j].Name.equals( sPropDigest ) ) - pDigest = &( pValue[j].Value ); - else if ( pValue[j].Name.equals( sPropDigestAlgorithm ) ) - pDigestAlg = &( pValue[j].Value ); - else if ( pValue[j].Name.equals( sPropEncryptionAlgorithm ) ) - pEncryptionAlg = &( pValue[j].Value ); - else if ( pValue[j].Name.equals( sPropStartKeyAlgorithm ) ) - pStartKeyAlg = &( pValue[j].Value ); - else if ( pValue[j].Name.equals( sPropDerivedKeySize ) ) - pDerivedKeySize = &( pValue[j].Value ); - } - - if ( sPath.getLength() && hasByHierarchicalName ( sPath ) ) - { - aAny = getByHierarchicalName( sPath ); - uno::Reference < XUnoTunnel > xUnoTunnel; - aAny >>= xUnoTunnel; - sal_Int64 nTest=0; - if ( (nTest = xUnoTunnel->getSomething( ZipPackageFolder::static_getImplementationId() )) != 0 ) - { - pFolder = reinterpret_cast < ZipPackageFolder* > ( nTest ); - pFolder->SetMediaType ( sMediaType ); - pFolder->SetVersion ( sVersion ); - } - else - { - pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething( ZipPackageStream::static_getImplementationId() )); - pStream->SetMediaType ( sMediaType ); - pStream->SetFromManifest( sal_True ); - - if ( pSalt && pVector && pCount && pSize && pDigest && pDigestAlg && pEncryptionAlg ) - { - uno::Sequence < sal_Int8 > aSequence; - sal_Int32 nCount = 0, nSize = 0, nDigestAlg = 0, nEncryptionAlg = 0, nDerivedKeySize = 16, nStartKeyAlg = xml::crypto::DigestID::SHA1; - - pStream->SetToBeEncrypted ( sal_True ); - - *pSalt >>= aSequence; - pStream->setSalt ( aSequence ); - - *pVector >>= aSequence; - pStream->setInitialisationVector ( aSequence ); - - *pCount >>= nCount; - pStream->setIterationCount ( nCount ); - - *pSize >>= nSize; - pStream->setSize ( nSize ); - - *pDigest >>= aSequence; - pStream->setDigest ( aSequence ); - - *pDigestAlg >>= nDigestAlg; - pStream->SetImportedChecksumAlgorithm( nDigestAlg ); - - *pEncryptionAlg >>= nEncryptionAlg; - pStream->SetImportedEncryptionAlgorithm( nEncryptionAlg ); - - if ( pDerivedKeySize ) - *pDerivedKeySize >>= nDerivedKeySize; - pStream->SetImportedDerivedKeySize( nDerivedKeySize ); - - if ( pStartKeyAlg ) - *pStartKeyAlg >>= nStartKeyAlg; - pStream->SetImportedStartKeyAlgorithm( nStartKeyAlg ); - - pStream->SetToBeCompressed ( sal_True ); - pStream->SetToBeEncrypted ( sal_True ); - pStream->SetIsEncrypted ( sal_True ); - if ( !m_bHasEncryptedEntries - && pStream->getName().equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ) ) ) - { - m_bHasEncryptedEntries = sal_True; - m_nStartKeyGenerationID = nStartKeyAlg; - m_nChecksumDigestID = nDigestAlg; - m_nCommonEncryptionID = nEncryptionAlg; - } - } - else - m_bHasNonEncryptedEntries = sal_True; - } - } - } - - bManifestParsed = sal_True; - } - else - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No manifes parser!" ) ), uno::Reference< uno::XInterface >() ); - } - - // now hide the manifest.xml file from user - xMetaInfFolder->removeByName( sManifest ); - } - } - catch( Exception& ) - { - if ( !m_bForceRecovery ) - throw; - } - } - - if ( !bManifestParsed && !m_bForceRecovery ) - throw ZipIOException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Could not parse manifest.xml\n" ) ), - uno::Reference< uno::XInterface >() ); - - const OUString sMimetype ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) ); - if ( m_xRootFolder->hasByName( sMimetype ) ) - { - // get mediatype from the "mimetype" stream - ::rtl::OUString aPackageMediatype; - uno::Reference< lang::XUnoTunnel > xMimeTypeTunnel; - m_xRootFolder->getByName( sMimetype ) >>= xMimeTypeTunnel; - uno::Reference < io::XActiveDataSink > xMimeSink( xMimeTypeTunnel, UNO_QUERY ); - if ( xMimeSink.is() ) - { - uno::Reference< io::XInputStream > xMimeInStream = xMimeSink->getInputStream(); - if ( xMimeInStream.is() ) - { - // Mediatypes longer than 1024 symbols should not appear here - uno::Sequence< sal_Int8 > aData( 1024 ); - sal_Int32 nRead = xMimeInStream->readBytes( aData, 1024 ); - if ( nRead > aData.getLength() ) - nRead = aData.getLength(); - - if ( nRead ) - aPackageMediatype = ::rtl::OUString( ( sal_Char* )aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US ); - } - } - - - if ( !bManifestParsed ) - { - // the manifest.xml could not be successfuly parsed, this is an inconsistent package - if ( aPackageMediatype.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "application/vnd." ) ) == 0 ) - { - // accept only types that look similar to own mediatypes - m_pRootFolder->SetMediaType( aPackageMediatype ); - m_bMediaTypeFallbackUsed = sal_True; - } - } - else if ( !m_bForceRecovery ) - { - // the mimetype stream should contain the information from manifest.xml - if ( !m_pRootFolder->GetMediaType().equals( aPackageMediatype ) ) - throw ZipIOException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "mimetype conflicts with manifest.xml\n" ) ), - uno::Reference< uno::XInterface >() ); - } - - m_xRootFolder->removeByName( sMimetype ); - } - - m_bInconsistent = m_pRootFolder->LookForUnexpectedODF12Streams( ::rtl::OUString() ); - - sal_Bool bODF12AndNewer = ( m_pRootFolder->GetVersion().compareTo( ODFVER_012_TEXT ) >= 0 ); - if ( !m_bForceRecovery && bODF12AndNewer ) - { - if ( m_bInconsistent ) - { - // this is an ODF1.2 document that contains streams not referred in the manifest.xml; - // in case of ODF1.2 documents without version in manifest.xml the property IsInconsistent - // should be checked later - throw ZipIOException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "there are streams not referred in manifest.xml\n" ) ), - uno::Reference< uno::XInterface >() ); - } - else if ( bDifferentStartKeyAlgorithm ) - { - // all the streams should be encrypted with the same StartKey in ODF1.2 - // TODO/LATER: in future the exception should be thrown - OSL_ENSURE( false, "ODF1.2 contains different StartKey Algorithms" ); - // throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "More than one Start Key Generation algorithm is specified!" ) ), uno::Reference< uno::XInterface >() ); - } - } - - // in case it is a correct ODF1.2 document, the version must be set - // and the META-INF folder is reserved for package format - if ( bODF12AndNewer ) - m_xRootFolder->removeByName( sMeta ); - } -} - -//-------------------------------------------------------- -void ZipPackage::parseContentType() -{ - if ( m_nFormat == embed::StorageFormats::OFOPXML ) - { - const ::rtl::OUString aContentTypes( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) ); - try { - // the content type must exist in OFOPXML format! - if ( !m_xRootFolder->hasByName( aContentTypes ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong format!" ) ), - uno::Reference< uno::XInterface >() ); - - uno::Reference< lang::XUnoTunnel > xTunnel; - uno::Any aAny = m_xRootFolder->getByName( aContentTypes ); - aAny >>= xTunnel; - uno::Reference < io::XActiveDataSink > xSink( xTunnel, UNO_QUERY ); - if ( xSink.is() ) - { - uno::Reference< io::XInputStream > xInStream = xSink->getInputStream(); - if ( xInStream.is() ) - { - sal_Int32 nInd = 0; - // here aContentTypeInfo[0] - Defaults, and aContentTypeInfo[1] - Overrides - uno::Sequence< uno::Sequence< beans::StringPair > > aContentTypeInfo = - ::comphelper::OFOPXMLHelper::ReadContentTypeSequence( xInStream, m_xFactory ); - - if ( aContentTypeInfo.getLength() != 2 ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // set the implicit types fist - for ( nInd = 0; nInd < aContentTypeInfo[0].getLength(); nInd++ ) - m_pRootFolder->setChildStreamsTypeByExtension( aContentTypeInfo[0][nInd] ); - - // now set the explicit types - for ( nInd = 0; nInd < aContentTypeInfo[1].getLength(); nInd++ ) - { - ::rtl::OUString aPath; - if ( aContentTypeInfo[1][nInd].First.toChar() == ( sal_Unicode )'/' ) - aPath = aContentTypeInfo[1][nInd].First.copy( 1 ); - else - aPath = aContentTypeInfo[1][nInd].First; - - if ( aPath.getLength() && hasByHierarchicalName( aPath ) ) - { - uno::Any aIterAny = getByHierarchicalName( aPath ); - uno::Reference < lang::XUnoTunnel > xIterTunnel; - aIterAny >>= xIterTunnel; - sal_Int64 nTest = xIterTunnel->getSomething( ZipPackageStream::static_getImplementationId() ); - if ( nTest != 0 ) - { - // this is a package stream, in OFOPXML format only streams can have mediatype - ZipPackageStream *pStream = reinterpret_cast < ZipPackageStream* > ( nTest ); - pStream->SetMediaType( aContentTypeInfo[1][nInd].Second ); - } - } - } - } - } - - m_xRootFolder->removeByName( aContentTypes ); - } - catch( uno::Exception& ) - { - if ( !m_bForceRecovery ) - throw; - } - } -} - -//-------------------------------------------------------- -void ZipPackage::getZipFileContents() -{ - auto_ptr < ZipEnumeration > pEnum ( m_pZipFile->entries() ); - ZipPackageStream *pPkgStream; - ZipPackageFolder *pPkgFolder, *pCurrent; - OUString sTemp, sDirName; - sal_Int32 nOldIndex, nIndex, nStreamIndex; - FolderHash::iterator aIter; - - while ( pEnum->hasMoreElements() ) - { - nIndex = nOldIndex = 0; - pCurrent = m_pRootFolder; - const ZipEntry & rEntry = *pEnum->nextElement(); - OUString rName = rEntry.sPath; - - if ( m_bForceRecovery ) - { - // the PKZIP Application note version 6.2 does not allows to use '\' as separator - // unfortunately it is used by some implementations, so we have to support it in recovery mode - rName = rName.replace( '\\', '/' ); - } - - nStreamIndex = rName.lastIndexOf ( '/' ); - if ( nStreamIndex != -1 ) - { - sDirName = rName.copy ( 0, nStreamIndex ); - aIter = m_aRecent.find ( sDirName ); - if ( aIter != m_aRecent.end() ) - pCurrent = ( *aIter ).second; - } - - if ( pCurrent == m_pRootFolder ) - { - while ( ( nIndex = rName.indexOf( '/', nOldIndex ) ) != -1 ) - { - sTemp = rName.copy ( nOldIndex, nIndex - nOldIndex ); - if ( nIndex == nOldIndex ) - break; - if ( !pCurrent->hasByName( sTemp ) ) - { - pPkgFolder = new ZipPackageFolder( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert ); - pPkgFolder->setName( sTemp ); - pPkgFolder->doSetParent( pCurrent, sal_True ); - pCurrent = pPkgFolder; - } - else - pCurrent = pCurrent->doGetByName( sTemp ).pFolder; - nOldIndex = nIndex+1; - } - if ( nStreamIndex != -1 && sDirName.getLength() ) - m_aRecent [ sDirName ] = pCurrent; - } - if ( rName.getLength() -1 != nStreamIndex ) - { - nStreamIndex++; - sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex ); - pPkgStream = new ZipPackageStream( *this, m_xFactory, m_bAllowRemoveOnInsert ); - pPkgStream->SetPackageMember( sal_True ); - pPkgStream->setZipEntryOnLoading( rEntry ); - pPkgStream->setName( sTemp ); - pPkgStream->doSetParent( pCurrent, sal_True ); - } - } - - if ( m_nFormat == embed::StorageFormats::PACKAGE ) - parseManifest(); - else if ( m_nFormat == embed::StorageFormats::OFOPXML ) - parseContentType(); -} - -//-------------------------------------------------------- -void SAL_CALL ZipPackage::initialize( const uno::Sequence< Any >& aArguments ) - throw( Exception, RuntimeException ) -{ - RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::initialize" ); - sal_Bool bBadZipFile = sal_False, bHaveZipFile = sal_True; - uno::Reference< XProgressHandler > xProgressHandler; - beans::NamedValue aNamedValue; - - if ( aArguments.getLength() ) - { - for( int ind = 0; ind < aArguments.getLength(); ind++ ) - { - OUString aParamUrl; - if ( ( aArguments[ind] >>= aParamUrl )) - { - m_eMode = e_IMode_URL; - try - { - sal_Int32 nParam = aParamUrl.indexOf( '?' ); - if ( nParam >= 0 ) - { - m_aURL = aParamUrl.copy( 0, nParam ); - OUString aParam = aParamUrl.copy( nParam + 1 ); - - sal_Int32 nIndex = 0; - do - { - ::rtl::OUString aCommand = aParam.getToken( 0, '&', nIndex ); - if ( aCommand.equals( OUString(RTL_CONSTASCII_USTRINGPARAM( "repairpackage" )) ) ) - { - m_bForceRecovery = sal_True; - break; - } - else if ( aCommand.equals( OUString(RTL_CONSTASCII_USTRINGPARAM( "purezip" )) ) ) - { - m_nFormat = embed::StorageFormats::ZIP; - m_pRootFolder->setPackageFormat_Impl( m_nFormat ); - break; - } - else if ( aCommand.equals( OUString(RTL_CONSTASCII_USTRINGPARAM( "ofopxml" )) ) ) - { - m_nFormat = embed::StorageFormats::OFOPXML; - m_pRootFolder->setPackageFormat_Impl( m_nFormat ); - break; - } - } - while ( nIndex >= 0 ); - } - else - m_aURL = aParamUrl; - - Content aContent ( m_aURL, uno::Reference < XCommandEnvironment >() ); - Any aAny = aContent.getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM( "Size" )) ); - sal_uInt64 aSize = 0; - // kind of optimisation: treat empty files as nonexistent files - // and write to such files directly. Note that "Size" property is optional. - bool bHasSizeProperty = aAny >>= aSize; - if( !bHasSizeProperty || ( bHasSizeProperty && aSize ) ) - { - uno::Reference < XActiveDataSink > xSink = new ZipPackageSink; - if ( aContent.openStream ( xSink ) ) - m_xContentStream = xSink->getInputStream(); - } - else - bHaveZipFile = sal_False; - } - catch ( com::sun::star::uno::Exception& ) - { - // Exception derived from uno::Exception thrown. This probably - // means the file doesn't exist...we'll create it at - // commitChanges time - bHaveZipFile = sal_False; - } - } - else if ( ( aArguments[ind] >>= m_xStream ) ) - { - // a writable stream can implement both XStream & XInputStream - m_eMode = e_IMode_XStream; - m_xContentStream = m_xStream->getInputStream(); - } - else if ( ( aArguments[ind] >>= m_xContentStream ) ) - { - m_eMode = e_IMode_XInputStream; - } - else if ( ( aArguments[ind] >>= aNamedValue ) ) - { - if ( aNamedValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) ) - aNamedValue.Value >>= m_bForceRecovery; - else if ( aNamedValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PackageFormat" ) ) ) - { - // setting this argument to true means Package format - // setting it to false means plain Zip format - - sal_Bool bPackFormat = sal_True; - aNamedValue.Value >>= bPackFormat; - if ( !bPackFormat ) - m_nFormat = embed::StorageFormats::ZIP; - - m_pRootFolder->setPackageFormat_Impl( m_nFormat ); - } - else if ( aNamedValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StorageFormat" ) ) ) - { - ::rtl::OUString aFormatName; - sal_Int32 nFormatID = 0; - if ( aNamedValue.Value >>= aFormatName ) - { - if ( aFormatName.equals( PACKAGE_STORAGE_FORMAT_STRING ) ) - m_nFormat = embed::StorageFormats::PACKAGE; - else if ( aFormatName.equals( ZIP_STORAGE_FORMAT_STRING ) ) - m_nFormat = embed::StorageFormats::ZIP; - else if ( aFormatName.equals( OFOPXML_STORAGE_FORMAT_STRING ) ) - m_nFormat = embed::StorageFormats::OFOPXML; - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - } - else if ( aNamedValue.Value >>= nFormatID ) - { - if ( nFormatID != embed::StorageFormats::PACKAGE - && nFormatID != embed::StorageFormats::ZIP - && nFormatID != embed::StorageFormats::OFOPXML ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - m_nFormat = nFormatID; - } - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - m_pRootFolder->setPackageFormat_Impl( m_nFormat ); - } - else if ( aNamedValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "AllowRemoveOnInsert" ) ) ) - { - aNamedValue.Value >>= m_bAllowRemoveOnInsert; - m_pRootFolder->setRemoveOnInsertMode_Impl( m_bAllowRemoveOnInsert ); - } - - // for now the progress handler is not used, probably it will never be - // if ( aNamedValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ProgressHandler" ) ) - } - else - { - // The URL is not acceptable - throw com::sun::star::uno::Exception ( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Bad arguments." ) ), - static_cast < ::cppu::OWeakObject * > ( this ) ); - } - } - - try - { - if ( m_xContentStream.is() ) - { - // the stream must be seekable, if it is not it will be wrapped - m_xContentStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( m_xContentStream, m_xFactory ); - m_xContentSeek = uno::Reference < XSeekable > ( m_xContentStream, UNO_QUERY ); - if ( ! m_xContentSeek.is() ) - throw com::sun::star::uno::Exception ( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "The package component _requires_ an XSeekable interface!" ) ), - static_cast < ::cppu::OWeakObject * > ( this ) ); - - if ( !m_xContentSeek->getLength() ) - bHaveZipFile = sal_False; - } - else - bHaveZipFile = sal_False; - } - catch ( com::sun::star::uno::Exception& ) - { - // Exception derived from uno::Exception thrown. This probably - // means the file doesn't exist...we'll create it at - // commitChanges time - bHaveZipFile = sal_False; - } - if ( bHaveZipFile ) - { - try - { - m_pZipFile = new ZipFile ( m_xContentStream, m_xFactory, sal_True, m_bForceRecovery, xProgressHandler ); - getZipFileContents(); - } - catch ( IOException & ) - { - bBadZipFile = sal_True; - } - catch ( ZipException & ) - { - bBadZipFile = sal_True; - } - catch ( Exception & ) - { - if( m_pZipFile ) { delete m_pZipFile; m_pZipFile = NULL; } - throw; - } - - if ( bBadZipFile ) - { - // clean up the memory, and tell the UCB about the error - if( m_pZipFile ) { delete m_pZipFile; m_pZipFile = NULL; } - - throw com::sun::star::packages::zip::ZipIOException ( - OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Bad Zip File." ) ), - static_cast < ::cppu::OWeakObject * > ( this ) ); - } - } - } - - RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::initialize" ); -} - -//-------------------------------------------------------- -Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) - throw( NoSuchElementException, RuntimeException ) -{ - OUString sTemp, sDirName; - sal_Int32 nOldIndex, nIndex, nStreamIndex; - FolderHash::iterator aIter; - - if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) - return makeAny ( uno::Reference < XUnoTunnel > ( m_pRootFolder ) ); - else - { - nStreamIndex = aName.lastIndexOf ( '/' ); - bool bFolder = nStreamIndex == nIndex-1; - if ( nStreamIndex != -1 ) - { - sDirName = aName.copy ( 0, nStreamIndex ); - aIter = m_aRecent.find ( sDirName ); - if ( aIter != m_aRecent.end() ) - { - if ( bFolder ) - { - sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex ); - sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 ); - if ( sTemp == ( *aIter ).second->getName() ) - return makeAny ( uno::Reference < XUnoTunnel > ( ( *aIter ).second ) ); - else - m_aRecent.erase ( aIter ); - } - else - { - sTemp = aName.copy ( nStreamIndex + 1 ); - if ( ( *aIter ).second->hasByName( sTemp ) ) - return ( *aIter ).second->getByName( sTemp ); - else - m_aRecent.erase( aIter ); - } - } - } - else - { - if ( m_pRootFolder->hasByName ( aName ) ) - return m_pRootFolder->getByName ( aName ); - } - nOldIndex = 0; - ZipPackageFolder * pCurrent = m_pRootFolder; - ZipPackageFolder * pPrevious = NULL; - while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 ) - { - sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex ); - if ( nIndex == nOldIndex ) - break; - if ( pCurrent->hasByName( sTemp ) ) - { - pPrevious = pCurrent; - pCurrent = pCurrent->doGetByName( sTemp ).pFolder; - } - else - throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - nOldIndex = nIndex+1; - } - if ( bFolder ) - { - if ( nStreamIndex != -1 ) - m_aRecent[sDirName] = pPrevious; - return makeAny ( uno::Reference < XUnoTunnel > ( pCurrent ) ); - } - else - { - sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex ); - if ( pCurrent->hasByName ( sTemp ) ) - { - if ( nStreamIndex != -1 ) - m_aRecent[sDirName] = pCurrent; - return pCurrent->getByName( sTemp ); - } - else - throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } -} - -//-------------------------------------------------------- -sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) - throw( RuntimeException ) -{ - OUString sTemp, sDirName; - sal_Int32 nOldIndex, nIndex, nStreamIndex; - FolderHash::iterator aIter; - - if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) - return sal_True; - else - { - nStreamIndex = aName.lastIndexOf ( '/' ); - bool bFolder = nStreamIndex == nIndex-1; - if ( nStreamIndex != -1 ) - { - sDirName = aName.copy ( 0, nStreamIndex ); - aIter = m_aRecent.find ( sDirName ); - if ( aIter != m_aRecent.end() ) - { - if ( bFolder ) - { - sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex ); - sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 ); - if ( sTemp == ( *aIter ).second->getName() ) - return sal_True; - else - m_aRecent.erase ( aIter ); - } - else - { - sTemp = aName.copy ( nStreamIndex + 1 ); - if ( ( *aIter ).second->hasByName( sTemp ) ) - return sal_True; - else - m_aRecent.erase( aIter ); - } - } - } - else - { - if ( m_pRootFolder->hasByName ( aName ) ) - return sal_True; - } - ZipPackageFolder * pCurrent = m_pRootFolder; - ZipPackageFolder * pPrevious = NULL; - nOldIndex = 0; - while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 ) - { - sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex ); - if ( nIndex == nOldIndex ) - break; - if ( pCurrent->hasByName( sTemp ) ) - { - pPrevious = pCurrent; - pCurrent = pCurrent->doGetByName( sTemp ).pFolder; - } - else - return sal_False; - nOldIndex = nIndex+1; - } - if ( bFolder ) - { - m_aRecent[sDirName] = pPrevious; - return sal_True; - } - else - { - sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex ); - - if ( pCurrent->hasByName( sTemp ) ) - { - m_aRecent[sDirName] = pCurrent; - return sal_True; - } - } - return sal_False; - } -} - -//-------------------------------------------------------- -uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance() - throw( Exception, RuntimeException ) -{ - uno::Reference < XInterface > xRef = *( new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ) ); - return xRef; -} -//-------------------------------------------------------- -uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const uno::Sequence< Any >& aArguments ) - throw( Exception, RuntimeException ) -{ - sal_Bool bArg = sal_False; - uno::Reference < XInterface > xRef; - if ( aArguments.getLength() ) - aArguments[0] >>= bArg; - if ( bArg ) - xRef = *new ZipPackageFolder ( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert ); - else - xRef = *new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ); - - return xRef; -} - -//-------------------------------------------------------- -void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) -{ - const OUString sMime ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) ); - if ( m_xRootFolder->hasByName( sMime ) ) - m_xRootFolder->removeByName( sMime ); - - ZipEntry * pEntry = new ZipEntry; - sal_Int32 nBufferLength = m_pRootFolder->GetMediaType().getLength(); - OString sMediaType = OUStringToOString( m_pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US ); - uno::Sequence< sal_Int8 > aType( ( sal_Int8* )sMediaType.getStr(), - nBufferLength ); - - - pEntry->sPath = sMime; - pEntry->nMethod = STORED; - pEntry->nSize = pEntry->nCompressedSize = nBufferLength; - pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - - CRC32 aCRC32; - aCRC32.update( aType ); - pEntry->nCrc = aCRC32.getValue(); - - try - { - aZipOut.putNextEntry( *pEntry, NULL ); - aZipOut.write( aType, 0, nBufferLength ); - aZipOut.closeEntry(); - } - catch ( ::com::sun::star::io::IOException & r ) - { - throw WrappedTargetException( - OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Error adding mimetype to the ZipOutputStream!" ) ), - static_cast < OWeakObject * > ( this ), - makeAny( r ) ); - } -} - -//-------------------------------------------------------- -void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) -{ - // Write the manifest - uno::Reference < XOutputStream > xManOutStream; - OUString sManifestWriter( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestWriter" ) ); - uno::Reference < XManifestWriter > xWriter ( m_xFactory->createInstance( sManifestWriter ), UNO_QUERY ); - if ( xWriter.is() ) - { - ZipEntry * pEntry = new ZipEntry; - ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); - xManOutStream = uno::Reference < XOutputStream > ( *pBuffer, UNO_QUERY ); - - pEntry->sPath = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) ); - pEntry->nMethod = DEFLATED; - pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; - pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - - // Convert vector into a uno::Sequence - uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence ( aManList.size() ); - sal_Int32 nInd = 0; - for ( vector < uno::Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); - aIter != aEnd; - aIter++, nInd++ ) - { - aManifestSequence[nInd] = ( *aIter ); - } - xWriter->writeManifestSequence ( xManOutStream, aManifestSequence ); - - sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() ); - pBuffer->realloc( nBufferLength ); - - // the manifest.xml is never encrypted - so pass an empty reference - aZipOut.putNextEntry( *pEntry, NULL ); - aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); - aZipOut.closeEntry(); - } - else - { - OSL_FAIL( "Couldn't get a ManifestWriter!" ); - IOException aException; - throw WrappedTargetException( - OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Couldn't get a ManifestWriter!" ) ), - static_cast < OWeakObject * > ( this ), - makeAny( aException ) ); - } -} - -//-------------------------------------------------------- -void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) -{ - const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - - ZipEntry* pEntry = new ZipEntry; - ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); - uno::Reference< io::XOutputStream > xConTypeOutStream( *pBuffer, UNO_QUERY ); - - pEntry->sPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) ); - pEntry->nMethod = DEFLATED; - pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; - pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - - // Convert vector into a uno::Sequence - // TODO/LATER: use Defaulst entries in future - uno::Sequence< beans::StringPair > aDefaultsSequence; - uno::Sequence< beans::StringPair > aOverridesSequence( aManList.size() ); - sal_Int32 nSeqLength = 0; - for ( vector< uno::Sequence< beans::PropertyValue > >::const_iterator aIter = aManList.begin(), - aEnd = aManList.end(); - aIter != aEnd; - ++aIter) - { - ::rtl::OUString aPath; - ::rtl::OUString aType; - OSL_ENSURE( ( *aIter )[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && ( *aIter )[PKG_MNFST_FULLPATH].Name.equals( sFullPath ), - "The mediatype sequence format is wrong!\n" ); - ( *aIter )[PKG_MNFST_MEDIATYPE].Value >>= aType; - if ( aType.getLength() ) - { - // only nonempty type makes sence here - nSeqLength++; - ( *aIter )[PKG_MNFST_FULLPATH].Value >>= aPath; - aOverridesSequence[nSeqLength-1].First = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) + aPath; - aOverridesSequence[nSeqLength-1].Second = aType; - } - } - aOverridesSequence.realloc( nSeqLength ); - - ::comphelper::OFOPXMLHelper::WriteContentSequence( - xConTypeOutStream, aDefaultsSequence, aOverridesSequence, m_xFactory ); - - sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() ); - pBuffer->realloc( nBufferLength ); - - // there is no encryption in this format currently - aZipOut.putNextEntry( *pEntry, NULL ); - aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); - aZipOut.closeEntry(); -} - -//-------------------------------------------------------- -void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream ) -{ - m_xContentSeek.set( xInStream, uno::UNO_QUERY_THROW ); - m_xContentStream = xInStream; - - // seek back to the beginning of the temp file so we can read segments from it - m_xContentSeek->seek( 0 ); - if ( m_pZipFile ) - m_pZipFile->setInputStream( m_xContentStream ); - else - m_pZipFile = new ZipFile ( m_xContentStream, m_xFactory, sal_False ); -} - -//-------------------------------------------------------- -uno::Reference< io::XInputStream > ZipPackage::writeTempFile() -{ - // In case the target local file does not exist or empty - // write directly to it otherwize create a temporary file to write to. - // If a temporary file is created it is returned back by the method. - // If the data written directly, xComponentStream will be switched here - - sal_Bool bUseTemp = sal_True; - uno::Reference < io::XInputStream > xResult; - uno::Reference < io::XInputStream > xTempIn; - - uno::Reference < io::XOutputStream > xTempOut; - uno::Reference< io::XActiveDataStreamer > xSink; - - if ( m_eMode == e_IMode_URL && !m_pZipFile && isLocalFile_Impl( m_aURL ) ) - { - xSink = openOriginalForOutput(); - if( xSink.is() ) - { - uno::Reference< io::XStream > xStr = xSink->getStream(); - if( xStr.is() ) - { - xTempOut = xStr->getOutputStream(); - if( xTempOut.is() ) - bUseTemp = sal_False; - } - } - } - else if ( m_eMode == e_IMode_XStream && !m_pZipFile ) - { - // write directly to an empty stream - xTempOut = m_xStream->getOutputStream(); - if( xTempOut.is() ) - bUseTemp = sal_False; - } - - if( bUseTemp ) - { - // create temporary file - const OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); - uno::Reference < io::XStream > xTempFile( m_xFactory->createInstance ( sServiceName ), UNO_QUERY_THROW ); - xTempOut.set( xTempFile->getOutputStream(), UNO_SET_THROW ); - xTempIn.set( xTempFile->getInputStream(), UNO_SET_THROW ); - } - - // Hand it to the ZipOutputStream: - ZipOutputStream aZipOut( m_xFactory, xTempOut ); - aZipOut.setMethod( DEFLATED ); - aZipOut.setLevel( DEFAULT_COMPRESSION ); - - try - { - if ( m_nFormat == embed::StorageFormats::PACKAGE ) - { - // Remove the old manifest.xml file as the - // manifest will be re-generated and the - // META-INF directory implicitly created if does not exist - const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) ); - - if ( m_xRootFolder->hasByName( sMeta ) ) - { - const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ); - - uno::Reference< XUnoTunnel > xTunnel; - Any aAny = m_xRootFolder->getByName( sMeta ); - aAny >>= xTunnel; - uno::Reference< XNameContainer > xMetaInfFolder( xTunnel, UNO_QUERY ); - if ( xMetaInfFolder.is() && xMetaInfFolder->hasByName( sManifest ) ) - xMetaInfFolder->removeByName( sManifest ); - } - - // Write a magic file with mimetype - WriteMimetypeMagicFile( aZipOut ); - } - else if ( m_nFormat == embed::StorageFormats::OFOPXML ) - { - // Remove the old [Content_Types].xml file as the - // file will be re-generated - - const ::rtl::OUString aContentTypes( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) ); - - if ( m_xRootFolder->hasByName( aContentTypes ) ) - m_xRootFolder->removeByName( aContentTypes ); - } - - // Create a vector to store data for the manifest.xml file - vector < uno::Sequence < PropertyValue > > aManList; - - const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - const OUString sVersion ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); - const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - - if ( m_nFormat == embed::StorageFormats::PACKAGE ) - { - uno::Sequence < PropertyValue > aPropSeq( PKG_SIZE_NOENCR_MNFST ); - aPropSeq [PKG_MNFST_MEDIATYPE].Name = sMediaType; - aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= m_pRootFolder->GetMediaType(); - aPropSeq [PKG_MNFST_VERSION].Name = sVersion; - aPropSeq [PKG_MNFST_VERSION].Value <<= m_pRootFolder->GetVersion(); - aPropSeq [PKG_MNFST_FULLPATH].Name = sFullPath; - aPropSeq [PKG_MNFST_FULLPATH].Value <<= OUString ( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); - - aManList.push_back( aPropSeq ); - } - - // Get a random number generator and seed it with current timestamp - // This will be used to generate random salt and initialisation vectors - // for encrypted streams - TimeValue aTime; - osl_getSystemTime( &aTime ); - rtlRandomPool aRandomPool = rtl_random_createPool (); - rtl_random_addBytes ( aRandomPool, &aTime, 8 ); - - // call saveContents ( it will recursively save sub-directories - OUString aEmptyString; - m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, GetEncryptionKey(), aRandomPool ); - - // Clean up random pool memory - rtl_random_destroyPool ( aRandomPool ); - - if( m_nFormat == embed::StorageFormats::PACKAGE ) - { - WriteManifest( aZipOut, aManList ); - } - else if( m_nFormat == embed::StorageFormats::OFOPXML ) - { - WriteContentTypes( aZipOut, aManList ); - } - - aZipOut.finish(); - - if( bUseTemp ) - xResult = xTempIn; - - // Update our References to point to the new temp file - if( !bUseTemp ) - { - // the case when the original contents were written directly - xTempOut->flush(); - - // in case the stream is based on a file it will implement the following interface - // the call should be used to be sure that the contents are written to the file system - uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( xTempOut, uno::UNO_QUERY ); - if ( asyncOutputMonitor.is() ) - asyncOutputMonitor->waitForCompletion(); - - // no need to postpone switching to the new stream since the target was written directly - uno::Reference< io::XInputStream > xNewStream; - if ( m_eMode == e_IMode_URL ) - xNewStream = xSink->getStream()->getInputStream(); - else if ( m_eMode == e_IMode_XStream && m_xStream.is() ) - xNewStream = m_xStream->getInputStream(); - - if ( xNewStream.is() ) - ConnectTo( xNewStream ); - } - } - catch ( uno::Exception& ) - { - if( bUseTemp ) - { - // no information loss appeares, thus no special handling is required - uno::Any aCaught( ::cppu::getCaughtException() ); - - // it is allowed to throw WrappedTargetException - WrappedTargetException aException; - if ( aCaught >>= aException ) - throw aException; - - throw WrappedTargetException( - OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Problem writing the original content!" ) ), - static_cast < OWeakObject * > ( this ), - aCaught ); - } - else - { - // the document is written directly, although it was empty it is important to notify that the writing has failed - // TODO/LATER: let the package be able to recover in this situation - ::rtl::OUString aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is unusable!" ) ); - embed::UseBackupException aException( aErrTxt, uno::Reference< uno::XInterface >(), ::rtl::OUString() ); - throw WrappedTargetException( aErrTxt, - static_cast < OWeakObject * > ( this ), - makeAny ( aException ) ); - } - } - - return xResult; -} - -//-------------------------------------------------------- -uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() -{ - // open and truncate the original file - Content aOriginalContent ( m_aURL, uno::Reference < XCommandEnvironment >() ); - uno::Reference< XActiveDataStreamer > xSink = new ActiveDataStreamer; - - if ( m_eMode == e_IMode_URL ) - { - try - { - sal_Bool bTruncSuccess = sal_False; - - try - { - Exception aDetect; - sal_Int64 aSize = 0; - Any aAny = aOriginalContent.setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM( "Size" )), makeAny( aSize ) ); - if( !( aAny >>= aDetect ) ) - bTruncSuccess = sal_True; - } - catch( Exception& ) - { - } - - if( !bTruncSuccess ) - { - // the file is not accessible - // just try to write an empty stream to it - - uno::Reference< XInputStream > xTempIn = new DummyInputStream; //uno::Reference< XInputStream >( xTempOut, UNO_QUERY ); - aOriginalContent.writeStream( xTempIn , sal_True ); - } - - OpenCommandArgument2 aArg; - aArg.Mode = OpenMode::DOCUMENT; - aArg.Priority = 0; // unused - aArg.Sink = xSink; - aArg.Properties = uno::Sequence< Property >( 0 ); // unused - - aOriginalContent.executeCommand( OUString(RTL_CONSTASCII_USTRINGPARAM( "open" )), makeAny( aArg ) ); - } - catch( Exception& ) - { - // seems to be nonlocal file - // temporary file mechanics should be used - } - } - - return xSink; -} - -//-------------------------------------------------------- -void SAL_CALL ZipPackage::commitChanges() - throw( WrappedTargetException, RuntimeException ) -{ - // lock the component for the time of commiting - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_eMode == e_IMode_XInputStream ) - { - IOException aException; - throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ), - static_cast < OWeakObject * > ( this ), makeAny ( aException ) ); - } - - RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::commitChanges" ); - - // first the writeTempFile is called, if it returns a stream the stream should be written to the target - // if no stream was returned, the file was written directly, nothing should be done - - uno::Reference< io::XInputStream > xTempInStream = writeTempFile(); - if ( xTempInStream.is() ) - { - uno::Reference< io::XSeekable > xTempSeek( xTempInStream, uno::UNO_QUERY_THROW ); - - try - { - xTempSeek->seek( 0 ); - } - catch( uno::Exception& r ) - { - throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Temporary file should be seekable!" ) ), - static_cast < OWeakObject * > ( this ), makeAny ( r ) ); - } - - // connect to the temporary stream - ConnectTo( xTempInStream ); - - if ( m_eMode == e_IMode_XStream ) - { - // First truncate our output stream - uno::Reference < XOutputStream > xOutputStream; - - // preparation for copy step - try - { - xOutputStream = m_xStream->getOutputStream(); - uno::Reference < XTruncate > xTruncate ( xOutputStream, UNO_QUERY ); - if ( !xTruncate.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // after successful truncation the original file contents are already lost - xTruncate->truncate(); - } - catch( uno::Exception& r ) - { - throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ), - static_cast < OWeakObject * > ( this ), makeAny ( r ) ); - } - - try - { - // then copy the contents of the tempfile to our output stream - ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutputStream ); - xOutputStream->flush(); - uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( - xOutputStream, uno::UNO_QUERY ); - if ( asyncOutputMonitor.is() ) { - asyncOutputMonitor->waitForCompletion(); - } - } - catch( uno::Exception& ) - { - // if anything goes wrong in this block the target file becomes corrupted - // so an exception should be thrown as a notification about it - // and the package must disconnect from the stream - DisconnectFromTargetAndThrowException_Impl( xTempInStream ); - } - } - else if ( m_eMode == e_IMode_URL ) - { - uno::Reference< XOutputStream > aOrigFileStream; - sal_Bool bCanBeCorrupted = sal_False; - - if( isLocalFile_Impl( m_aURL ) ) - { - // write directly in case of local file - uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleAccess( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - OSL_ENSURE( xSimpleAccess.is(), "Can't instatiate SimpleFileAccess service!\n" ); - uno::Reference< io::XTruncate > xOrigTruncate; - if ( xSimpleAccess.is() ) - { - try - { - aOrigFileStream = xSimpleAccess->openFileWrite( m_aURL ); - xOrigTruncate = uno::Reference< io::XTruncate >( aOrigFileStream, uno::UNO_QUERY_THROW ); - // after successful truncation the file is already corrupted - xOrigTruncate->truncate(); - } - catch( uno::Exception& ) - {} - } - - if( xOrigTruncate.is() ) - { - try - { - ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, aOrigFileStream ); - aOrigFileStream->closeOutput(); - } - catch( uno::Exception& ) - { - try { - aOrigFileStream->closeOutput(); - } catch ( uno::Exception& ) {} - - aOrigFileStream = uno::Reference< XOutputStream >(); - // the original file can already be corrupted - bCanBeCorrupted = sal_True; - } - } - } - - if( !aOrigFileStream.is() ) - { - try - { - uno::Reference < XPropertySet > xPropSet ( xTempInStream, UNO_QUERY ); - OSL_ENSURE( xPropSet.is(), "This is a temporary file that must implement XPropertySet!\n" ); - if ( !xPropSet.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OUString sTargetFolder = m_aURL.copy ( 0, m_aURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ); - Content aContent ( sTargetFolder, uno::Reference < XCommandEnvironment > () ); - - OUString sTempURL; - Any aAny = xPropSet->getPropertyValue ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Uri" ) ) ); - aAny >>= sTempURL; - - TransferInfo aInfo; - aInfo.NameClash = NameClash::OVERWRITE; - aInfo.MoveData = sal_False; - aInfo.SourceURL = sTempURL; - aInfo.NewTitle = rtl::Uri::decode ( m_aURL.copy ( 1 + m_aURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ), - rtl_UriDecodeWithCharset, - RTL_TEXTENCODING_UTF8 ); - aAny <<= aInfo; - - // if the file is still not corrupted, it can become after the next step - aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "transfer" ) ), aAny ); - } - catch ( ::com::sun::star::uno::Exception& r ) - { - if ( bCanBeCorrupted ) - DisconnectFromTargetAndThrowException_Impl( xTempInStream ); - - throw WrappedTargetException( - OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package may be read only!" ) ), - static_cast < OWeakObject * > ( this ), - makeAny ( r ) ); - } - } - } - } - - // after successful storing it can be set to false - m_bMediaTypeFallbackUsed = sal_False; - - RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::commitChanges" ); -} - -//-------------------------------------------------------- -void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Reference< io::XInputStream >& xTempStream ) -{ - m_xStream = uno::Reference< io::XStream >( xTempStream, uno::UNO_QUERY ); - if ( m_xStream.is() ) - m_eMode = e_IMode_XStream; - else - m_eMode = e_IMode_XInputStream; - - ::rtl::OUString aTempURL; - try { - uno::Reference< beans::XPropertySet > xTempFile( xTempStream, uno::UNO_QUERY_THROW ); - uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Uri") ) ); - aUrl >>= aTempURL; - xTempFile->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveFile") ), - uno::makeAny( sal_False ) ); - } - catch ( uno::Exception& ) - { - OSL_FAIL( "These calls are pretty simple, they should not fail!\n" ); - } - - ::rtl::OUString aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ); - embed::UseBackupException aException( aErrTxt, uno::Reference< uno::XInterface >(), aTempURL ); - throw WrappedTargetException( aErrTxt, - static_cast < OWeakObject * > ( this ), - makeAny ( aException ) ); -} - -//-------------------------------------------------------- -const uno::Sequence< sal_Int8 > ZipPackage::GetEncryptionKey() -{ - uno::Sequence< sal_Int8 > aResult; - - if ( m_aStorageEncryptionKeys.getLength() ) - { - ::rtl::OUString aNameToFind; - if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA256 ) - aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; - else if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA1 ) - aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA1UTF8; - else - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); - - for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ ) - if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) ) - m_aStorageEncryptionKeys[nInd].Value >>= aResult; - - // empty keys are not allowed here - // so it is not important whether there is no key, or the key is empty, it is an error - if ( !aResult.getLength() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); - } - else - aResult = m_aEncryptionKey; - - return aResult; -} - -//-------------------------------------------------------- -sal_Bool SAL_CALL ZipPackage::hasPendingChanges() - throw( RuntimeException ) -{ - return sal_False; -} -//-------------------------------------------------------- -Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges() - throw( RuntimeException ) -{ - return uno::Sequence < ElementChange > (); -} - -/** - * Function to create a new component instance; is needed by factory helper implementation. - * @param xMgr service manager to if the components needs other component instances - */ -uno::Reference < XInterface >SAL_CALL ZipPackage_createInstance( - const uno::Reference< XMultiServiceFactory > & xMgr ) -{ - return uno::Reference< XInterface >( *new ZipPackage( xMgr ) ); -} - -//-------------------------------------------------------- -OUString ZipPackage::static_getImplementationName() -{ - return OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.comp.ZipPackage" ) ); -} - -//-------------------------------------------------------- -Sequence< OUString > ZipPackage::static_getSupportedServiceNames() -{ - uno::Sequence< OUString > aNames( 1 ); - aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.Package" ) ); - return aNames; -} -//-------------------------------------------------------- -sal_Bool SAL_CALL ZipPackage::static_supportsService( OUString const & rServiceName ) -{ - return rServiceName == getSupportedServiceNames()[0]; -} - -//-------------------------------------------------------- -OUString ZipPackage::getImplementationName() - throw ( RuntimeException ) -{ - return static_getImplementationName(); -} - -//-------------------------------------------------------- -Sequence< OUString > ZipPackage::getSupportedServiceNames() - throw ( RuntimeException ) -{ - return static_getSupportedServiceNames(); -} -//-------------------------------------------------------- -sal_Bool SAL_CALL ZipPackage::supportsService( OUString const & rServiceName ) - throw ( RuntimeException ) -{ - return static_supportsService ( rServiceName ); -} -//-------------------------------------------------------- -uno::Reference < XSingleServiceFactory > ZipPackage::createServiceFactory( uno::Reference < XMultiServiceFactory > const & rServiceFactory ) -{ - return cppu::createSingleFactory ( rServiceFactory, - static_getImplementationName(), - ZipPackage_createInstance, - static_getSupportedServiceNames() ); -} - -namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } - -//-------------------------------------------------------- -Sequence< sal_Int8 > ZipPackage::getUnoTunnelImplementationId( void ) - throw ( RuntimeException ) -{ - ::cppu::OImplementationId &rId = lcl_ImplId::get(); - return rId.getImplementationId(); -} - -//-------------------------------------------------------- -sal_Int64 SAL_CALL ZipPackage::getSomething( const uno::Sequence< sal_Int8 >& aIdentifier ) - throw( RuntimeException ) -{ - if ( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) - return reinterpret_cast < sal_Int64 > ( this ); - return 0; -} - -//-------------------------------------------------------- -uno::Reference< XPropertySetInfo > SAL_CALL ZipPackage::getPropertySetInfo() - throw( RuntimeException ) -{ - return uno::Reference < XPropertySetInfo > (); -} - -//-------------------------------------------------------- -void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) - throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException ) -{ - if ( m_nFormat != embed::StorageFormats::PACKAGE ) - throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) - ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) - ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( IS_INCONSISTENT_PROPERTY ) ) - ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) - throw PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) - { - if ( !( aValue >>= m_aEncryptionKey ) ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - m_aStorageEncryptionKeys.realloc( 0 ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) - { - // this property is only necessary to support raw passwords in storage API; - // because of this support the storage has to operate with more than one key dependent on storage generation algorithm; - // when this support is removed, the storage will get only one key from outside - // TODO/LATER: Get rid of this property as well as of support of raw passwords in storages - uno::Sequence< beans::NamedValue > aKeys; - if ( !( aValue >>= aKeys ) || ( aKeys.getLength() && aKeys.getLength() < 2 ) ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - if ( aKeys.getLength() ) - { - bool bHasSHA256 = false; - bool bHasSHA1 = false; - for ( sal_Int32 nInd = 0; nInd < aKeys.getLength(); nInd++ ) - { - if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ) ) - bHasSHA256 = true; - if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ) ) - bHasSHA1 = true; - } - - if ( !bHasSHA256 || !bHasSHA1 ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Expected keys are not provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); - } - - m_aStorageEncryptionKeys = aKeys; - m_aEncryptionKey.realloc( 0 ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) - { - uno::Sequence< beans::NamedValue > aAlgorithms; - if ( m_pZipFile || !( aValue >>= aAlgorithms ) || aAlgorithms.getLength() == 0 ) - { - // the algorithms can not be changed if the file has a persistence based on the algorithms ( m_pZipFile ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 ); - } - - for ( sal_Int32 nInd = 0; nInd < aAlgorithms.getLength(); nInd++ ) - { - if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StartKeyGenerationAlgorithm" ) ) ) - { - sal_Int32 nID = 0; - if ( !( aAlgorithms[nInd].Value >>= nID ) - || ( nID != xml::crypto::DigestID::SHA256 && nID != xml::crypto::DigestID::SHA1 ) ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); - - m_nStartKeyGenerationID = nID; - } - else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EncryptionAlgorithm" ) ) ) - { - sal_Int32 nID = 0; - if ( !( aAlgorithms[nInd].Value >>= nID ) - || ( nID != xml::crypto::CipherID::AES_CBC_W3C_PADDING && nID != xml::crypto::CipherID::BLOWFISH_CFB_8 ) ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); - - m_nCommonEncryptionID = nID; - } - else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ChecksumAlgorithm" ) ) ) - { - sal_Int32 nID = 0; - if ( !( aAlgorithms[nInd].Value >>= nID ) - || ( nID != xml::crypto::DigestID::SHA1_1K && nID != xml::crypto::DigestID::SHA256_1K ) ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); - - m_nChecksumDigestID = nID; - } - else - { - OSL_ENSURE( sal_False, "Unexpected encryption algorithm is provided!" ); - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 ); - } - } - } - else - throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//-------------------------------------------------------- -Any SAL_CALL ZipPackage::getPropertyValue( const OUString& PropertyName ) - throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) -{ - // TODO/LATER: Activate the check when zip-ucp is ready - // if ( m_nFormat != embed::StorageFormats::PACKAGE ) - // throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - Any aAny; - if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( ENCRYPTION_KEY_PROPERTY ) ) ) - { - aAny <<= m_aEncryptionKey; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) - { - ::comphelper::SequenceAsHashMap aAlgorithms; - aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StartKeyGenerationAlgorithm" ) ) ] <<= m_nStartKeyGenerationID; - aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionAlgorithm" ) ) ] <<= m_nCommonEncryptionID; - aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChecksumAlgorithm" ) ) ] <<= m_nChecksumDigestID; - aAny <<= aAlgorithms.getAsConstNamedValueList(); - return aAny; - } - if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) - { - aAny <<= m_aStorageEncryptionKeys; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) ) - { - aAny <<= m_bHasEncryptedEntries; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) ) - { - aAny <<= m_bHasNonEncryptedEntries; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( IS_INCONSISTENT_PROPERTY ) ) ) - { - aAny <<= m_bInconsistent; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) - { - aAny <<= m_bMediaTypeFallbackUsed; - return aAny; - } - throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} -//-------------------------------------------------------- -void SAL_CALL ZipPackage::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ ) - throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) -{ -} -//-------------------------------------------------------- -void SAL_CALL ZipPackage::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*aListener*/ ) - throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) -{ -} -//-------------------------------------------------------- -void SAL_CALL ZipPackage::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) - throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) -{ -} -//-------------------------------------------------------- -void SAL_CALL ZipPackage::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) - throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) -{ -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackageBuffer.cxx b/package/source/zippackage/ZipPackageBuffer.cxx deleted file mode 100644 index 2fbbd01e2..000000000 --- a/package/source/zippackage/ZipPackageBuffer.cxx +++ /dev/null @@ -1,139 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ZipPackageBuffer.hxx> -#include <string.h> // for memcpy - -using namespace ::com::sun::star; -using namespace com::sun::star::uno; -using namespace com::sun::star::io; -using com::sun::star::lang::IllegalArgumentException; - -ZipPackageBuffer::ZipPackageBuffer(sal_Int64 nNewBufferSize ) -: m_nBufferSize (nNewBufferSize) -, m_nEnd(0) -, m_nCurrent(0) -, m_bMustInitBuffer ( sal_True ) -{ -} -ZipPackageBuffer::~ZipPackageBuffer(void) -{ -} - -sal_Int32 SAL_CALL ZipPackageBuffer::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - if (nBytesToRead < 0) - throw BufferSizeExceededException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), *this ); - - if (nBytesToRead + m_nCurrent > m_nEnd) - nBytesToRead = static_cast < sal_Int32 > (m_nEnd - m_nCurrent); - - aData.realloc ( nBytesToRead ); - memcpy(aData.getArray(), m_aBuffer.getConstArray() + m_nCurrent, nBytesToRead); - m_nCurrent +=nBytesToRead; - return nBytesToRead; -} - -sal_Int32 SAL_CALL ZipPackageBuffer::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - return readBytes(aData, nMaxBytesToRead); -} -void SAL_CALL ZipPackageBuffer::skipBytes( sal_Int32 nBytesToSkip ) - throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - if (nBytesToSkip < 0) - throw BufferSizeExceededException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), *this ); - - if (nBytesToSkip + m_nCurrent > m_nEnd) - nBytesToSkip = static_cast < sal_Int32 > (m_nEnd - m_nCurrent); - - m_nCurrent+=nBytesToSkip; -} -sal_Int32 SAL_CALL ZipPackageBuffer::available( ) - throw(NotConnectedException, IOException, RuntimeException) -{ - return static_cast < sal_Int32 > (m_nEnd - m_nCurrent); -} -void SAL_CALL ZipPackageBuffer::closeInput( ) - throw(NotConnectedException, IOException, RuntimeException) -{ -} -void SAL_CALL ZipPackageBuffer::writeBytes( const Sequence< sal_Int8 >& aData ) - throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - sal_Int64 nDataLen = aData.getLength(), nCombined = m_nEnd + nDataLen; - - if ( nCombined > m_nBufferSize) - { - do - m_nBufferSize *=2; - while (nCombined > m_nBufferSize); - m_aBuffer.realloc(static_cast < sal_Int32 > (m_nBufferSize)); - m_bMustInitBuffer = sal_False; - } - else if (m_bMustInitBuffer) - { - m_aBuffer.realloc ( static_cast < sal_Int32 > ( m_nBufferSize ) ); - m_bMustInitBuffer = sal_False; - } - memcpy( m_aBuffer.getArray() + m_nCurrent, aData.getConstArray(), static_cast < sal_Int32 > (nDataLen)); - m_nCurrent+=nDataLen; - if (m_nCurrent>m_nEnd) - m_nEnd = m_nCurrent; -} -void SAL_CALL ZipPackageBuffer::flush( ) - throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ -} -void SAL_CALL ZipPackageBuffer::closeOutput( ) - throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ -} -void SAL_CALL ZipPackageBuffer::seek( sal_Int64 location ) - throw( IllegalArgumentException, IOException, RuntimeException) -{ - if ( location > m_nEnd || location < 0 ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - m_nCurrent = location; -} -sal_Int64 SAL_CALL ZipPackageBuffer::getPosition( ) - throw(IOException, RuntimeException) -{ - return m_nCurrent; -} -sal_Int64 SAL_CALL ZipPackageBuffer::getLength( ) - throw(IOException, RuntimeException) -{ - return m_nEnd; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx deleted file mode 100644 index fdb7abc95..000000000 --- a/package/source/zippackage/ZipPackageEntry.cxx +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ZipPackageEntry.hxx> -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <osl/diagnose.h> - -#include <ZipPackageFolder.hxx> -#include <ZipPackageStream.hxx> -#include <ContentInfo.hxx> - -#include <comphelper/storagehelper.hxx> - -using namespace com::sun::star; -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::container; -using namespace com::sun::star::packages::zip; -using namespace com::sun::star::packages::zip::ZipConstants; - -using rtl::OUString; - -ZipPackageEntry::ZipPackageEntry ( bool bNewFolder ) -: mbIsFolder ( bNewFolder ) -, mbAllowRemoveOnInsert( sal_True ) -, pParent ( NULL ) -{ -} - -ZipPackageEntry::~ZipPackageEntry() -{ - // When the entry is destroyed it must be already disconnected from the parent - OSL_ENSURE( !pParent, "The parent must be disconnected already! Memory corruption is possible!\n" ); -} - -// XChild -OUString SAL_CALL ZipPackageEntry::getName( ) - throw(RuntimeException) -{ - return msName; -} -void SAL_CALL ZipPackageEntry::setName( const OUString& aName ) - throw(RuntimeException) -{ - if ( pParent && msName.getLength() && pParent->hasByName ( msName ) ) - pParent->removeByName ( msName ); - - // unfortunately no other exception than RuntimeException can be thrown here - // usually the package is used through storage implementation, the problem should be detected there - if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_True ) ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); - - msName = aName; - - if ( pParent ) - pParent->doInsertByName ( this, sal_False ); -} -uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( ) - throw(RuntimeException) -{ - // return uno::Reference< XInterface >( xParent, UNO_QUERY ); - return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY ); -} - -void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert ) -{ - // xParent = pParent = pNewParent; - pParent = pNewParent; - if ( bInsert && msName.getLength() && !pNewParent->hasByName ( msName ) ) - pNewParent->doInsertByName ( this, sal_False ); -} - -void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent ) - throw(NoSupportException, RuntimeException) -{ - sal_Int64 nTest(0); - uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY ); - if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 ) - throw NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - ZipPackageFolder *pNewParent = reinterpret_cast < ZipPackageFolder * > ( nTest ); - - if ( pNewParent != pParent ) - { - if ( pParent && msName.getLength() && pParent->hasByName ( msName ) && mbAllowRemoveOnInsert ) - pParent->removeByName( msName ); - doSetParent ( pNewParent, sal_True ); - } -} - //XPropertySet -uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( ) - throw(RuntimeException) -{ - return uno::Reference < beans::XPropertySetInfo > (); -} -void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) - throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) -{ -} -void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) - throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) -{ -} -void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) -{ -} -void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) -{ -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx deleted file mode 100644 index 05281776a..000000000 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ /dev/null @@ -1,856 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ZipPackageFolder.hxx> -#include <ZipFile.hxx> -#include <ZipOutputStream.hxx> -#include <ZipPackageStream.hxx> -#include <PackageConstants.hxx> -#include <ZipPackageFolderEnumeration.hxx> -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <com/sun/star/embed/StorageFormats.hpp> -#include <osl/diagnose.h> -#include <osl/time.h> -#include <rtl/digest.h> -#include <ContentInfo.hxx> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <EncryptedDataHeader.hxx> -#include <rtl/random.h> -#include <rtl/instance.hxx> -#include <memory> - -using namespace com::sun::star; -using namespace com::sun::star::packages::zip::ZipConstants; -using namespace com::sun::star::packages::zip; -using namespace com::sun::star::packages; -using namespace com::sun::star::container; -using namespace com::sun::star::beans; -using namespace com::sun::star::lang; -using namespace com::sun::star::io; -using namespace cppu; -using namespace std; -using namespace ::com::sun::star; - -namespace { struct lcl_CachedImplId : public rtl::Static< uno::Sequence < sal_Int8 >, lcl_CachedImplId > {}; } - -ZipPackageFolder::ZipPackageFolder ( const uno::Reference< XMultiServiceFactory >& xFactory, - sal_Int32 nFormat, - sal_Bool bAllowRemoveOnInsert ) -: m_xFactory( xFactory ) -, m_nFormat( nFormat ) -{ - OSL_ENSURE( m_xFactory.is(), "No factory is provided to the package folder!" ); - - this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert; - - SetFolder ( sal_True ); - aEntry.nVersion = -1; - aEntry.nFlag = 0; - aEntry.nMethod = STORED; - aEntry.nTime = -1; - aEntry.nCrc = 0; - aEntry.nCompressedSize = 0; - aEntry.nSize = 0; - aEntry.nOffset = -1; - uno::Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get(); - if ( !rCachedImplId.getLength() ) - rCachedImplId = getImplementationId(); -} - - -ZipPackageFolder::~ZipPackageFolder() -{ -} - -sal_Bool ZipPackageFolder::LookForUnexpectedODF12Streams( const ::rtl::OUString& aPath ) -{ - sal_Bool bHasUnexpected = sal_False; - - for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end(); - !bHasUnexpected && aCI != aEnd; - ++aCI) - { - const ::rtl::OUString &rShortName = (*aCI).first; - const ContentInfo &rInfo = *(*aCI).second; - - if ( rInfo.bFolder ) - { - if ( aPath.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF/" ) ) ) ) - { - // META-INF is not allowed to contain subfolders - bHasUnexpected = sal_True; - } - else - { - ::rtl::OUString sOwnPath = aPath + rShortName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); - bHasUnexpected = rInfo.pFolder->LookForUnexpectedODF12Streams( sOwnPath ); - } - } - else - { - if ( aPath.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF/" ) ) ) ) - { - if ( !rShortName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ) ) - && rShortName.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "signatures" ) ) ) == -1 ) - { - // a stream from META-INF with unexpected name - bHasUnexpected = sal_True; - } - - // streams from META-INF with expected names are allowed not to be registered in manifest.xml - } - else if ( !rInfo.pStream->IsFromManifest() ) - { - // the stream is not in META-INF and ist notregistered in manifest.xml, - // check whether it is an internal part of the package format - if ( aPath.getLength() - || !rShortName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "mimetype" ) ) ) ) - { - // if it is not "mimetype" from the root it is not a part of the package - bHasUnexpected = sal_True; - } - } - } - } - - return bHasUnexpected; -} - -void ZipPackageFolder::setChildStreamsTypeByExtension( const beans::StringPair& aPair ) -{ - ::rtl::OUString aExt; - if ( aPair.First.toChar() == (sal_Unicode)'.' ) - aExt = aPair.First; - else - aExt = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) ) + aPair.First; - - for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end(); - aCI != aEnd; - ++aCI) - { - const ::rtl::OUString &rShortName = (*aCI).first; - const ContentInfo &rInfo = *(*aCI).second; - - if ( rInfo.bFolder ) - rInfo.pFolder->setChildStreamsTypeByExtension( aPair ); - else - { - sal_Int32 nPathLength = rShortName.getLength(); - sal_Int32 nExtLength = aExt.getLength(); - if ( nPathLength >= nExtLength && rShortName.match( aExt, nPathLength - nExtLength ) ) - rInfo.pStream->SetMediaType( aPair.Second ); - } - } -} - -void ZipPackageFolder::copyZipEntry( ZipEntry &rDest, const ZipEntry &rSource) -{ - rDest.nVersion = rSource.nVersion; - rDest.nFlag = rSource.nFlag; - rDest.nMethod = rSource.nMethod; - rDest.nTime = rSource.nTime; - rDest.nCrc = rSource.nCrc; - rDest.nCompressedSize = rSource.nCompressedSize; - rDest.nSize = rSource.nSize; - rDest.nOffset = rSource.nOffset; - rDest.sPath = rSource.sPath; - rDest.nPathLen = rSource.nPathLen; - rDest.nExtraLen = rSource.nExtraLen; -} - -const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageFolder::static_getImplementationId() -{ - return lcl_CachedImplId::get(); -} - - // XNameContainer -void SAL_CALL ZipPackageFolder::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement ) - throw(IllegalArgumentException, ElementExistException, WrappedTargetException, uno::RuntimeException) -{ - if (hasByName(aName)) - throw ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else - { - uno::Reference < XUnoTunnel > xRef; - aElement >>= xRef; - if ( ( aElement >>= xRef ) ) - { - sal_Int64 nTest; - ZipPackageEntry *pEntry; - if ( ( nTest = xRef->getSomething ( ZipPackageFolder::static_getImplementationId() ) ) != 0 ) - { - ZipPackageFolder *pFolder = reinterpret_cast < ZipPackageFolder * > ( nTest ); - pEntry = static_cast < ZipPackageEntry * > ( pFolder ); - } - else if ( ( nTest = xRef->getSomething ( ZipPackageStream::static_getImplementationId() ) ) != 0 ) - { - ZipPackageStream *pStream = reinterpret_cast < ZipPackageStream * > ( nTest ); - pEntry = static_cast < ZipPackageEntry * > ( pStream ); - } - else - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - - if (pEntry->getName() != aName ) - pEntry->setName (aName); - doInsertByName ( pEntry, sal_True ); - } - else - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - } -} -void SAL_CALL ZipPackageFolder::removeByName( const ::rtl::OUString& Name ) - throw(NoSuchElementException, WrappedTargetException, uno::RuntimeException) -{ - ContentHash::iterator aIter = maContents.find ( Name ); - if ( aIter == maContents.end() ) - throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - maContents.erase( aIter ); -} - // XEnumerationAccess -uno::Reference< XEnumeration > SAL_CALL ZipPackageFolder::createEnumeration( ) - throw(uno::RuntimeException) -{ - return uno::Reference < XEnumeration> (new ZipPackageFolderEnumeration(maContents)); -} - // XElementAccess -uno::Type SAL_CALL ZipPackageFolder::getElementType( ) - throw(uno::RuntimeException) -{ - return ::getCppuType ((const uno::Reference< XUnoTunnel > *) 0); -} -sal_Bool SAL_CALL ZipPackageFolder::hasElements( ) - throw(uno::RuntimeException) -{ - return maContents.size() > 0; -} - // XNameAccess -ContentInfo& ZipPackageFolder::doGetByName( const ::rtl::OUString& aName ) - throw(NoSuchElementException, WrappedTargetException, uno::RuntimeException) -{ - ContentHash::iterator aIter = maContents.find ( aName ); - if ( aIter == maContents.end()) - throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return *(*aIter).second; -} -uno::Any SAL_CALL ZipPackageFolder::getByName( const ::rtl::OUString& aName ) - throw(NoSuchElementException, WrappedTargetException, uno::RuntimeException) -{ - return uno::makeAny ( doGetByName ( aName ).xTunnel ); -} -uno::Sequence< ::rtl::OUString > SAL_CALL ZipPackageFolder::getElementNames( ) - throw(uno::RuntimeException) -{ - sal_uInt32 i=0, nSize = maContents.size(); - uno::Sequence < ::rtl::OUString > aSequence ( nSize ); - for ( ContentHash::const_iterator aIterator = maContents.begin(), aEnd = maContents.end(); - aIterator != aEnd; - ++i, ++aIterator) - aSequence[i] = (*aIterator).first; - return aSequence; -} -sal_Bool SAL_CALL ZipPackageFolder::hasByName( const ::rtl::OUString& aName ) - throw(uno::RuntimeException) -{ - return maContents.find ( aName ) != maContents.end (); -} - // XNameReplace -void SAL_CALL ZipPackageFolder::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement ) - throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, uno::RuntimeException) -{ - if ( hasByName( aName ) ) - removeByName( aName ); - else - throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - insertByName(aName, aElement); -} - -static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< XInputStream> & rStream ) -{ - // It's very annoying that we have to do this, but lots of zip packages - // don't allow data descriptors for STORED streams, meaning we have to - // know the size and CRC32 of uncompressed streams before we actually - // write them ! - CRC32 aCRC32; - rEntry.nMethod = STORED; - rEntry.nCompressedSize = rEntry.nSize = aCRC32.updateStream ( rStream ); - rEntry.nCrc = aCRC32.getValue(); -} - -bool ZipPackageFolder::saveChild( const ::rtl::OUString &rShortName, const ContentInfo &rInfo, ::rtl::OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, const uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool &rRandomPool) -{ - bool bSuccess = true; - - const ::rtl::OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - const ::rtl::OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); - const ::rtl::OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - const ::rtl::OUString sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); - const ::rtl::OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); - const ::rtl::OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); - const ::rtl::OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); - const ::rtl::OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); - const ::rtl::OUString sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); - const ::rtl::OUString sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); - const ::rtl::OUString sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); - const ::rtl::OUString sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); - - uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST); - - OSL_ENSURE( ( rInfo.bFolder && rInfo.pFolder ) || ( !rInfo.bFolder && rInfo.pStream ), "A valid child object is expected!" ); - if ( rInfo.bFolder ) - { - ::rtl::OUString sTempName = rPath + rShortName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); - - if ( rInfo.pFolder->GetMediaType().getLength() ) - { - aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; - aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pFolder->GetMediaType(); - aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty; - aPropSet[PKG_MNFST_VERSION].Value <<= rInfo.pFolder->GetVersion(); - aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty; - aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName; - } - else - aPropSet.realloc( 0 ); - - rInfo.pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool); - } - else - { - // if pTempEntry is necessary, it will be released and passed to the ZipOutputStream - // and be deleted in the ZipOutputStream destructor - auto_ptr < ZipEntry > pAutoTempEntry ( new ZipEntry ); - ZipEntry* pTempEntry = pAutoTempEntry.get(); - - // In case the entry we are reading is also the entry we are writing, we will - // store the ZipEntry data in pTempEntry - - ZipPackageFolder::copyZipEntry ( *pTempEntry, rInfo.pStream->aEntry ); - pTempEntry->sPath = rPath + rShortName; - pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() ); - - sal_Bool bToBeEncrypted = rInfo.pStream->IsToBeEncrypted() && (rEncryptionKey.getLength() || rInfo.pStream->HasOwnKey()); - sal_Bool bToBeCompressed = bToBeEncrypted ? sal_True : rInfo.pStream->IsToBeCompressed(); - - aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; - aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pStream->GetMediaType( ); - aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty; - aPropSet[PKG_MNFST_VERSION].Value <<= ::rtl::OUString(); // no version is stored for streams currently - aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty; - aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath; - - - OSL_ENSURE( rInfo.pStream->GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" ); - - sal_Bool bRawStream = sal_False; - if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_DETECT ) - bRawStream = rInfo.pStream->ParsePackageRawStream(); - else if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_RAW ) - bRawStream = sal_True; - - sal_Bool bTransportOwnEncrStreamAsRaw = sal_False; - // During the storing the original size of the stream can be changed - // TODO/LATER: get rid of this hack - sal_Int32 nOwnStreamOrigSize = bRawStream ? rInfo.pStream->GetMagicalHackSize() : rInfo.pStream->getSize(); - - sal_Bool bUseNonSeekableAccess = sal_False; - uno::Reference < XInputStream > xStream; - if ( !rInfo.pStream->IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed ) - { - // the stream is not a package member, not a raw stream, - // it should not be encrypted and it should be compressed, - // in this case nonseekable access can be used - - xStream = rInfo.pStream->GetOwnStreamNoWrap(); - uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY ); - - bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() ); - } - - if ( !bUseNonSeekableAccess ) - { - xStream = rInfo.pStream->getRawData(); - - if ( !xStream.is() ) - { - OSL_FAIL( "ZipPackageStream didn't have a stream associated with it, skipping!" ); - bSuccess = false; - return bSuccess; - } - - uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY ); - try - { - if ( xSeek.is() ) - { - // If the stream is a raw one, then we should be positioned - // at the beginning of the actual data - if ( !bToBeCompressed || bRawStream ) - { - // The raw stream can neither be encrypted nor connected - OSL_ENSURE( !bRawStream || !(bToBeCompressed || bToBeEncrypted), "The stream is already encrypted!\n" ); - xSeek->seek ( bRawStream ? rInfo.pStream->GetMagicalHackPos() : 0 ); - ImplSetStoredData ( *pTempEntry, xStream ); - - // TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties! - } - else if ( bToBeEncrypted ) - { - // this is the correct original size - pTempEntry->nSize = static_cast < sal_Int32 > ( xSeek->getLength() ); - nOwnStreamOrigSize = pTempEntry->nSize; - } - - xSeek->seek ( 0 ); - } - else - { - // Okay, we don't have an xSeekable stream. This is possibly bad. - // check if it's one of our own streams, if it is then we know that - // each time we ask for it we'll get a new stream that will be - // at position zero...otherwise, assert and skip this stream... - if ( rInfo.pStream->IsPackageMember() ) - { - // if the password has been changed than the stream should not be package member any more - if ( rInfo.pStream->IsEncrypted() && rInfo.pStream->IsToBeEncrypted() ) - { - // Should be handled close to the raw stream handling - bTransportOwnEncrStreamAsRaw = sal_True; - pTempEntry->nMethod = STORED; - - // TODO/LATER: get rid of this situation - // this size should be different from the one that will be stored in manifest.xml - // it is used in storing algorithms and after storing the correct size will be set - pTempEntry->nSize = pTempEntry->nCompressedSize; - } - } - else - { - bSuccess = false; - return bSuccess; - } - } - } - catch ( uno::Exception& ) - { - bSuccess = false; - return bSuccess; - } - - if ( bToBeEncrypted || bRawStream || bTransportOwnEncrStreamAsRaw ) - { - if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw ) - { - uno::Sequence < sal_Int8 > aSalt( 16 ), aVector( rInfo.pStream->GetBlockSize() ); - rtl_random_getBytes ( rRandomPool, aSalt.getArray(), 16 ); - rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() ); - sal_Int32 nIterationCount = 1024; - - if ( !rInfo.pStream->HasOwnKey() ) - rInfo.pStream->setKey ( rEncryptionKey ); - - rInfo.pStream->setInitialisationVector ( aVector ); - rInfo.pStream->setSalt ( aSalt ); - rInfo.pStream->setIterationCount ( nIterationCount ); - } - - // last property is digest, which is inserted later if we didn't have - // a magic header - aPropSet.realloc(PKG_SIZE_ENCR_MNFST); - - aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty; - aPropSet[PKG_MNFST_INIVECTOR].Value <<= rInfo.pStream->getInitialisationVector(); - aPropSet[PKG_MNFST_SALT].Name = sSaltProperty; - aPropSet[PKG_MNFST_SALT].Value <<= rInfo.pStream->getSalt(); - aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty; - aPropSet[PKG_MNFST_ITERATION].Value <<= rInfo.pStream->getIterationCount (); - - // Need to store the uncompressed size in the manifest - OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" ); - aPropSet[PKG_MNFST_UCOMPSIZE].Name = sSizeProperty; - aPropSet[PKG_MNFST_UCOMPSIZE].Value <<= nOwnStreamOrigSize; - - if ( bRawStream || bTransportOwnEncrStreamAsRaw ) - { - ::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData(); - if ( !xEncData.is() ) - throw uno::RuntimeException(); - - aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; - aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest(); - aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty; - aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg; - aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty; - aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID; - aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty; - aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg; - aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty; - aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize; - } - } - } - - // If the entry is already stored in the zip file in the format we - // want for this write...copy it raw - if ( !bUseNonSeekableAccess - && ( bRawStream || bTransportOwnEncrStreamAsRaw - || ( rInfo.pStream->IsPackageMember() && !bToBeEncrypted - && ( ( rInfo.pStream->aEntry.nMethod == DEFLATED && bToBeCompressed ) - || ( rInfo.pStream->aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) ) - { - // If it's a PackageMember, then it's an unbuffered stream and we need - // to get a new version of it as we can't seek backwards. - if ( rInfo.pStream->IsPackageMember() ) - { - xStream = rInfo.pStream->getRawData(); - if ( !xStream.is() ) - { - // Make sure that we actually _got_ a new one ! - bSuccess = false; - return bSuccess; - } - } - - try - { - if ( bRawStream ) - xStream->skipBytes( rInfo.pStream->GetMagicalHackPos() ); - - rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, sal_False ); - // the entry is provided to the ZipOutputStream that will delete it - pAutoTempEntry.release(); - - uno::Sequence < sal_Int8 > aSeq ( n_ConstBufferSize ); - sal_Int32 nLength; - - do - { - nLength = xStream->readBytes( aSeq, n_ConstBufferSize ); - rZipOut.rawWrite(aSeq, 0, nLength); - } - while ( nLength == n_ConstBufferSize ); - - rZipOut.rawCloseEntry(); - } - catch ( ZipException& ) - { - bSuccess = false; - } - catch ( IOException& ) - { - bSuccess = false; - } - } - else - { - // This stream is defenitly not a raw stream - - // If nonseekable access is used the stream should be at the beginning and - // is useless after the storing. Thus if the storing fails the package should - // be thrown away ( as actually it is done currently )! - // To allow to reuse the package after the error, the optimization must be removed! - - // If it's a PackageMember, then our previous reference held a 'raw' stream - // so we need to re-get it, unencrypted, uncompressed and positioned at the - // beginning of the stream - if ( rInfo.pStream->IsPackageMember() ) - { - xStream = rInfo.pStream->getInputStream(); - if ( !xStream.is() ) - { - // Make sure that we actually _got_ a new one ! - bSuccess = false; - return bSuccess; - } - } - - if ( bToBeCompressed ) - { - pTempEntry->nMethod = DEFLATED; - pTempEntry->nCrc = pTempEntry->nCompressedSize = pTempEntry->nSize = -1; - } - - try - { - rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, bToBeEncrypted); - // the entry is provided to the ZipOutputStream that will delete it - pAutoTempEntry.release(); - - sal_Int32 nLength; - uno::Sequence < sal_Int8 > aSeq (n_ConstBufferSize); - do - { - nLength = xStream->readBytes(aSeq, n_ConstBufferSize); - rZipOut.write(aSeq, 0, nLength); - } - while ( nLength == n_ConstBufferSize ); - - rZipOut.closeEntry(); - } - catch ( ZipException& ) - { - bSuccess = false; - } - catch ( IOException& ) - { - bSuccess = false; - } - - if ( bToBeEncrypted ) - { - ::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData(); - if ( !xEncData.is() ) - throw uno::RuntimeException(); - - aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; - aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest(); - aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty; - aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg; - aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty; - aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID; - aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty; - aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg; - aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty; - aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize; - - rInfo.pStream->SetIsEncrypted ( sal_True ); - } - } - - if( bSuccess ) - { - if ( !rInfo.pStream->IsPackageMember() ) - { - rInfo.pStream->CloseOwnStreamIfAny(); - rInfo.pStream->SetPackageMember ( sal_True ); - } - - if ( bRawStream ) - { - // the raw stream was integrated and now behaves - // as usual encrypted stream - rInfo.pStream->SetToBeEncrypted( sal_True ); - } - - // Remove hacky bit from entry flags - if ( pTempEntry->nFlag & ( 1 << 4 ) ) - { - pTempEntry->nFlag &= ~( 1 << 4 ); - pTempEntry->nMethod = STORED; - } - - // Then copy it back afterwards... - ZipPackageFolder::copyZipEntry ( rInfo.pStream->aEntry, *pTempEntry ); - - // TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving ) - if ( rInfo.pStream->IsEncrypted() ) - rInfo.pStream->setSize( nOwnStreamOrigSize ); - - rInfo.pStream->aEntry.nOffset *= -1; - } - } - - // folder can have a mediatype only in package format - if ( aPropSet.getLength() - && ( m_nFormat == embed::StorageFormats::PACKAGE || ( m_nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) ) - rManList.push_back( aPropSet ); - - return bSuccess; -} - -void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, const uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool &rRandomPool ) - throw( uno::RuntimeException ) -{ - bool bWritingFailed = false; - - if ( maContents.begin() == maContents.end() && rPath.getLength() && m_nFormat != embed::StorageFormats::OFOPXML ) - { - // it is an empty subfolder, use workaround to store it - ZipEntry* pTempEntry = new ZipEntry(); - ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry ); - pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( rPath, RTL_TEXTENCODING_UTF8 ).getLength() ); - pTempEntry->nExtraLen = -1; - pTempEntry->sPath = rPath; - - try - { - rZipOut.putNextEntry( *pTempEntry, NULL, sal_False ); - rZipOut.rawCloseEntry(); - } - catch ( ZipException& ) - { - bWritingFailed = true; - } - catch ( IOException& ) - { - bWritingFailed = true; - } - } - - bool bMimeTypeStreamStored = false; - ::rtl::OUString aMimeTypeStreamName( RTL_CONSTASCII_USTRINGPARAM( "mimetype" ) ); - if ( m_nFormat == embed::StorageFormats::ZIP && !rPath.getLength() ) - { - // let the "mimtype" stream in root folder be stored as the first stream if it is zip format - ContentHash::iterator aIter = maContents.find ( aMimeTypeStreamName ); - if ( aIter != maContents.end() && !(*aIter).second->bFolder ) - { - bMimeTypeStreamStored = true; - bWritingFailed = !saveChild( (*aIter).first, *(*aIter).second, rPath, rManList, rZipOut, rEncryptionKey, rRandomPool ); - } - } - - for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end(); - aCI != aEnd; ++aCI) - { - const ::rtl::OUString &rShortName = (*aCI).first; - const ContentInfo &rInfo = *(*aCI).second; - - if ( !bMimeTypeStreamStored || !rShortName.equals( aMimeTypeStreamName ) ) - bWritingFailed = !saveChild( rShortName, rInfo, rPath, rManList, rZipOut, rEncryptionKey, rRandomPool ); - } - - if( bWritingFailed ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -void ZipPackageFolder::releaseUpwardRef( void ) -{ - // Now it is possible that a package folder is disconnected from the package before removing of the folder. - // Such a scenario is used in storage implementation. When a new version of a folder is provided the old - // one is retrieved, removed from the package but preserved for the error handling. - // In this scenario the referencing to the parent is not really useful, since it requires disposing. - - // Actually there is no need in having a reference to the parent, it even make things more complicated and - // requires disposing mechanics. Using of a simple pointer seems to be easier solution and also a safe enough. - - clearParent(); - -#if 0 - for ( ContentHash::const_iterator aCI = maContents.begin(); - aCI!=maContents.end(); - aCI++) - { - ContentInfo &rInfo = * (*aCI).second; - if ( rInfo.bFolder )// && ! rInfo.pFolder->HasReleased () ) - rInfo.pFolder->releaseUpwardRef(); - else //if ( !rInfo.bFolder && !rInfo.pStream->HasReleased() ) - rInfo.pStream->clearParent(); - } - clearParent(); - - OSL_ENSURE ( m_refCount == 1, "Ref-count is not 1!" ); -#endif -} - -sal_Int64 SAL_CALL ZipPackageFolder::getSomething( const uno::Sequence< sal_Int8 >& aIdentifier ) - throw(uno::RuntimeException) -{ - sal_Int64 nMe = 0; - if ( aIdentifier.getLength() == 16 && - 0 == rtl_compareMemory(static_getImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) - nMe = reinterpret_cast < sal_Int64 > ( this ); - return nMe; -} -void SAL_CALL ZipPackageFolder::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) - throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, uno::RuntimeException) -{ - if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaType"))) - { - // TODO/LATER: activate when zip ucp is ready - // if ( m_nFormat != embed::StorageFormats::PACKAGE ) - // throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - aValue >>= sMediaType; - } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Version"))) - aValue >>= m_sVersion; - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Size") ) ) - aValue >>= aEntry.nSize; - else - throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} -uno::Any SAL_CALL ZipPackageFolder::getPropertyValue( const ::rtl::OUString& PropertyName ) - throw(UnknownPropertyException, WrappedTargetException, uno::RuntimeException) -{ - if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - { - // TODO/LATER: activate when zip ucp is ready - // if ( m_nFormat != embed::StorageFormats::PACKAGE ) - // throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return uno::makeAny ( sMediaType ); - } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Version" ) ) ) - return uno::makeAny( m_sVersion ); - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) ) - return uno::makeAny ( aEntry.nSize ); - else - throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -void ZipPackageFolder::doInsertByName ( ZipPackageEntry *pEntry, sal_Bool bSetParent ) - throw(IllegalArgumentException, ElementExistException, WrappedTargetException, uno::RuntimeException) -{ - try - { - if ( pEntry->IsFolder() ) - maContents[pEntry->getName()] = new ContentInfo ( static_cast < ZipPackageFolder *> ( pEntry ) ); - else - maContents[pEntry->getName()] = new ContentInfo ( static_cast < ZipPackageStream *> ( pEntry ) ); - } - catch(const uno::Exception& rEx) - { - (void)rEx; - throw; - } - if ( bSetParent ) - pEntry->setParent ( *this ); -} -::rtl::OUString ZipPackageFolder::getImplementationName() - throw (uno::RuntimeException) -{ - return ::rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageFolder" ) ); -} - -uno::Sequence< ::rtl::OUString > ZipPackageFolder::getSupportedServiceNames() - throw (uno::RuntimeException) -{ - uno::Sequence< ::rtl::OUString > aNames(1); - aNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageFolder" ) ); - return aNames; -} -sal_Bool SAL_CALL ZipPackageFolder::supportsService( ::rtl::OUString const & rServiceName ) - throw (uno::RuntimeException) -{ - return rServiceName == getSupportedServiceNames()[0]; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackageFolderEnumeration.cxx b/package/source/zippackage/ZipPackageFolderEnumeration.cxx deleted file mode 100644 index 155b398c0..000000000 --- a/package/source/zippackage/ZipPackageFolderEnumeration.cxx +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ZipPackageFolderEnumeration.hxx> -#include <ContentInfo.hxx> - -using namespace com::sun::star; -using rtl::OUString; - -ZipPackageFolderEnumeration::ZipPackageFolderEnumeration ( ContentHash &rInput) -: rContents (rInput) -, aIterator (rContents.begin()) -{ -} - -ZipPackageFolderEnumeration::~ZipPackageFolderEnumeration( void ) -{ -} - -sal_Bool SAL_CALL ZipPackageFolderEnumeration::hasMoreElements( ) - throw(uno::RuntimeException) -{ - return (aIterator != rContents.end() ); -} -uno::Any SAL_CALL ZipPackageFolderEnumeration::nextElement( ) - throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) -{ - uno::Any aAny; - if (aIterator == rContents.end() ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - aAny <<= (*aIterator).second->xTunnel; - aIterator++; - return aAny; -} - -OUString ZipPackageFolderEnumeration::getImplementationName() - throw (uno::RuntimeException) -{ - return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageFolderEnumeration" ) ); -} - -uno::Sequence< OUString > ZipPackageFolderEnumeration::getSupportedServiceNames() - throw (uno::RuntimeException) -{ - uno::Sequence< OUString > aNames(1); - aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageFolderEnumeration" ) ); - return aNames; -} -sal_Bool SAL_CALL ZipPackageFolderEnumeration::supportsService( OUString const & rServiceName ) - throw (uno::RuntimeException) -{ - return rServiceName == getSupportedServiceNames()[0]; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackageFolderEnumeration.hxx b/package/source/zippackage/ZipPackageFolderEnumeration.hxx deleted file mode 100644 index 58e4324b3..000000000 --- a/package/source/zippackage/ZipPackageFolderEnumeration.hxx +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _ZIP_PACKAGE_FOLDER_ENUMERATION_HXX -#define _ZIP_PACKAGE_FOLDER_ENUMERATION_HXX - -#include <cppuhelper/implbase2.hxx> // helper for implementations -#include <com/sun/star/container/XEnumeration.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <HashMaps.hxx> - -class ZipPackageFolderEnumeration : public cppu::WeakImplHelper2 -< - com::sun::star::container::XEnumeration, - com::sun::star::lang::XServiceInfo -> -{ -protected: - ContentHash& rContents; - ContentHash::const_iterator aIterator; -public: - //ZipPackageFolderEnumeration (boost::unordered_map < rtl::OUString, com::sun::star::uno::Reference < com::sun::star::container::XNamed >, hashFunc, eqFunc > &rInput); - ZipPackageFolderEnumeration (ContentHash &rInput); - virtual ~ZipPackageFolderEnumeration( void ); - - // XEnumeration - virtual sal_Bool SAL_CALL hasMoreElements( ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Any SAL_CALL nextElement( ) - throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) - throw (::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) - throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) - throw (::com::sun::star::uno::RuntimeException); - -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackageSink.cxx b/package/source/zippackage/ZipPackageSink.cxx deleted file mode 100644 index 227006379..000000000 --- a/package/source/zippackage/ZipPackageSink.cxx +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <ZipPackageSink.hxx> - -ZipPackageSink::ZipPackageSink(void) -: xStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > (NULL)) -{ -} -ZipPackageSink::~ZipPackageSink(void) -{ -} -void SAL_CALL ZipPackageSink::setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream ) - throw(::com::sun::star::uno::RuntimeException) -{ - xStream = aStream; -} -::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL ZipPackageSink::getInputStream( ) - throw(::com::sun::star::uno::RuntimeException) -{ - return xStream; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackageSink.hxx b/package/source/zippackage/ZipPackageSink.hxx deleted file mode 100644 index f8e0eb168..000000000 --- a/package/source/zippackage/ZipPackageSink.hxx +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _ZIP_PACKAGE_SINK_HXX -#define _ZIP_PACKAGE_SINK_HXX - -#include <com/sun/star/io/XActiveDataSink.hpp> -#include <cppuhelper/implbase1.hxx> - -class ZipPackageSink : public ::cppu::WeakImplHelper1 -< - com::sun::star::io::XActiveDataSink -> -{ -protected: - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; -public: - ZipPackageSink(); - virtual ~ZipPackageSink(); - virtual void SAL_CALL setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) - throw(::com::sun::star::uno::RuntimeException); -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx deleted file mode 100644 index b191b31df..000000000 --- a/package/source/zippackage/ZipPackageStream.cxx +++ /dev/null @@ -1,946 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * ( a copy is included in the LICENSE file that accompanied this code ). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER( update_precomp.py ): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/packages/zip/ZipIOException.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/xml/crypto/DigestID.hpp> -#include <com/sun/star/xml/crypto/CipherID.hpp> - - -#include <ZipPackageStream.hxx> -#include <ZipPackage.hxx> -#include <ZipFile.hxx> -#include <EncryptedDataHeader.hxx> -#include <osl/diagnose.h> -#include "wrapstreamforshare.hxx" - -#include <comphelper/seekableinput.hxx> -#include <comphelper/storagehelper.hxx> - -#include <rtl/instance.hxx> - -#include <PackageConstants.hxx> - -using namespace com::sun::star::packages::zip::ZipConstants; -using namespace com::sun::star::packages::zip; -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star; -using namespace cppu; - -using rtl::OUString; -namespace { struct lcl_CachedImplId : public rtl::Static< Sequence < sal_Int8 >, lcl_CachedImplId > {}; } - -const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageStream::static_getImplementationId() -{ - return lcl_CachedImplId::get(); -} - -ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage, - const uno::Reference< XMultiServiceFactory >& xFactory, - sal_Bool bAllowRemoveOnInsert ) -: m_xFactory( xFactory ) -, rZipPackage( rNewPackage ) -, bToBeCompressed ( sal_True ) -, bToBeEncrypted ( sal_False ) -, bHaveOwnKey ( sal_False ) -, bIsEncrypted ( sal_False ) -, m_nImportedStartKeyAlgorithm( 0 ) -, m_nImportedEncryptionAlgorithm( 0 ) -, m_nImportedChecksumAlgorithm( 0 ) -, m_nImportedDerivedKeySize( 0 ) -, m_nStreamMode( PACKAGE_STREAM_NOTSET ) -, m_nMagicalHackPos( 0 ) -, m_nMagicalHackSize( 0 ) -, m_bHasSeekable( sal_False ) -, m_bCompressedIsSetFromOutside( sal_False ) -, m_bFromManifest( sal_False ) -, m_bUseWinEncoding( false ) -{ - OSL_ENSURE( m_xFactory.is(), "No factory is provided to ZipPackageStream!\n" ); - - this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert; - - SetFolder ( sal_False ); - aEntry.nVersion = -1; - aEntry.nFlag = 0; - aEntry.nMethod = -1; - aEntry.nTime = -1; - aEntry.nCrc = -1; - aEntry.nCompressedSize = -1; - aEntry.nSize = -1; - aEntry.nOffset = -1; - aEntry.nPathLen = -1; - aEntry.nExtraLen = -1; - - Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get(); - if ( !rCachedImplId.getLength() ) - rCachedImplId = getImplementationId(); -} - -ZipPackageStream::~ZipPackageStream( void ) -{ -} - -void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry ) -{ - aEntry.nVersion = rInEntry.nVersion; - aEntry.nFlag = rInEntry.nFlag; - aEntry.nMethod = rInEntry.nMethod; - aEntry.nTime = rInEntry.nTime; - aEntry.nCrc = rInEntry.nCrc; - aEntry.nCompressedSize = rInEntry.nCompressedSize; - aEntry.nSize = rInEntry.nSize; - aEntry.nOffset = rInEntry.nOffset; - aEntry.sPath = rInEntry.sPath; - aEntry.nPathLen = rInEntry.nPathLen; - aEntry.nExtraLen = rInEntry.nExtraLen; - - if ( aEntry.nMethod == STORED ) - bToBeCompressed = sal_False; -} - -//-------------------------------------------------------------------------- -void ZipPackageStream::CloseOwnStreamIfAny() -{ - if ( xStream.is() ) - { - xStream->closeInput(); - xStream = uno::Reference< io::XInputStream >(); - m_bHasSeekable = sal_False; - } -} - -//-------------------------------------------------------------------------- -uno::Reference< io::XInputStream > ZipPackageStream::GetOwnSeekStream() -{ - if ( !m_bHasSeekable && xStream.is() ) - { - // The package component requires that every stream either be FROM a package or it must support XSeekable! - // The only exception is a nonseekable stream that is provided only for storing, if such a stream - // is accessed before commit it MUST be wrapped. - // Wrap the stream in case it is not seekable - xStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( xStream, m_xFactory ); - uno::Reference< io::XSeekable > xSeek( xStream, UNO_QUERY ); - if ( !xSeek.is() ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ), - uno::Reference< XInterface >() ); - - m_bHasSeekable = sal_True; - } - - return xStream; -} - -//-------------------------------------------------------------------------- -uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCopy() -{ - if ( m_nStreamMode != PACKAGE_STREAM_RAW || !GetOwnSeekStream().is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_xBaseEncryptionData.is() ) - throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Encrypted stream without encryption data!\n" ) ), - uno::Reference< XInterface >() ); - - uno::Reference< io::XSeekable > xSeek( GetOwnSeekStream(), UNO_QUERY ); - if ( !xSeek.is() ) - throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must be seekable!\n" ) ), - uno::Reference< XInterface >() ); - - // skip header - xSeek->seek( n_ConstHeaderSize + getInitialisationVector().getLength() + - getSalt().getLength() + getDigest().getLength() ); - - // create temporary stream - uno::Reference < io::XOutputStream > xTempOut( - m_xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), - uno::UNO_QUERY ); - uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY ); - uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY ); - if ( !xTempOut.is() || !xTempIn.is() || !xTempSeek.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // copy the raw stream to the temporary file starting from the current position - ::comphelper::OStorageHelper::CopyInputToOutput( GetOwnSeekStream(), xTempOut ); - xTempOut->closeOutput(); - xTempSeek->seek( 0 ); - - return xTempIn; -} - -//-------------------------------------------------------------------------- -sal_Int32 ZipPackageStream::GetEncryptionAlgorithm() const -{ - return m_nImportedEncryptionAlgorithm ? m_nImportedEncryptionAlgorithm : rZipPackage.GetEncAlgID(); -} - -//-------------------------------------------------------------------------- -sal_Int32 ZipPackageStream::GetBlockSize() const -{ - return GetEncryptionAlgorithm() == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 8; -} - -//-------------------------------------------------------------------------- -::rtl::Reference< EncryptionData > ZipPackageStream::GetEncryptionData( bool bUseWinEncoding ) -{ - ::rtl::Reference< EncryptionData > xResult; - if ( m_xBaseEncryptionData.is() ) - xResult = new EncryptionData( - *m_xBaseEncryptionData, - GetEncryptionKey( bUseWinEncoding ), - GetEncryptionAlgorithm(), - m_nImportedChecksumAlgorithm ? m_nImportedChecksumAlgorithm : rZipPackage.GetChecksumAlgID(), - m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : rZipPackage.GetDefaultDerivedKeySize(), - GetStartKeyGenID() ); - - return xResult; -} - -//-------------------------------------------------------------------------- -void ZipPackageStream::SetBaseEncryptionData( const ::rtl::Reference< BaseEncryptionData >& xData ) -{ - m_xBaseEncryptionData = xData; -} - -//-------------------------------------------------------------------------- -uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncoding ) -{ - uno::Sequence< sal_Int8 > aResult; - sal_Int32 nKeyGenID = GetStartKeyGenID(); - bUseWinEncoding = ( bUseWinEncoding || m_bUseWinEncoding ); - - if ( bHaveOwnKey && m_aStorageEncryptionKeys.getLength() ) - { - ::rtl::OUString aNameToFind; - if ( nKeyGenID == xml::crypto::DigestID::SHA256 ) - aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; - else if ( nKeyGenID == xml::crypto::DigestID::SHA1 ) - { - aNameToFind = bUseWinEncoding ? PACKAGE_ENCRYPTIONDATA_SHA1MS1252 : PACKAGE_ENCRYPTIONDATA_SHA1UTF8; - } - else - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); - - for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ ) - if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) ) - m_aStorageEncryptionKeys[nInd].Value >>= aResult; - - // empty keys are not allowed here - // so it is not important whether there is no key, or the key is empty, it is an error - if ( !aResult.getLength() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); - } - else - aResult = m_aEncryptionKey; - - if ( !aResult.getLength() || !bHaveOwnKey ) - aResult = rZipPackage.GetEncryptionKey(); - - return aResult; -} - -//-------------------------------------------------------------------------- -sal_Int32 ZipPackageStream::GetStartKeyGenID() -{ - // generally should all the streams use the same Start Key - // but if raw copy without password takes place, we should preserve the imported algorithm - return m_nImportedStartKeyAlgorithm ? m_nImportedStartKeyAlgorithm : rZipPackage.GetStartKeyGenID(); -} - -//-------------------------------------------------------------------------- -uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_Bool bAddHeaderForEncr ) -{ - if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || ( bAddHeaderForEncr && !bToBeEncrypted ) ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - Sequence< sal_Int8 > aKey; - - if ( bToBeEncrypted ) - { - aKey = GetEncryptionKey(); - if ( !aKey.getLength() ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - try - { - // create temporary file - uno::Reference < io::XStream > xTempStream( - m_xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), - uno::UNO_QUERY ); - if ( !xTempStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // create a package based on it - ZipPackage* pPackage = new ZipPackage( m_xFactory ); - uno::Reference< XSingleServiceFactory > xPackageAsFactory( static_cast< XSingleServiceFactory* >( pPackage ) ); - if ( !xPackageAsFactory.is() ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - Sequence< Any > aArgs( 1 ); - aArgs[0] <<= xTempStream; - pPackage->initialize( aArgs ); - - // create a new package stream - uno::Reference< XDataSinkEncrSupport > xNewPackStream( xPackageAsFactory->createInstance(), UNO_QUERY ); - if ( !xNewPackStream.is() ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - xNewPackStream->setDataStream( static_cast< io::XInputStream* >( - new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ) ) ); - - uno::Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY ); - if ( !xNewPSProps.is() ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // copy all the properties of this stream to the new stream - xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), makeAny( sMediaType ) ); - xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ), makeAny( bToBeCompressed ) ); - if ( bToBeEncrypted ) - { - xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ), makeAny( aKey ) ); - xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ), makeAny( sal_True ) ); - } - - // insert a new stream in the package - uno::Reference< XUnoTunnel > xTunnel; - Any aRoot = pPackage->getByHierarchicalName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ); - aRoot >>= xTunnel; - uno::Reference< container::XNameContainer > xRootNameContainer( xTunnel, UNO_QUERY ); - if ( !xRootNameContainer.is() ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< XUnoTunnel > xNPSTunnel( xNewPackStream, UNO_QUERY ); - xRootNameContainer->insertByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "dummy" ) ), makeAny( xNPSTunnel ) ); - - // commit the temporary package - pPackage->commitChanges(); - - // get raw stream from the temporary package - uno::Reference< io::XInputStream > xInRaw; - if ( bAddHeaderForEncr ) - xInRaw = xNewPackStream->getRawStream(); - else - xInRaw = xNewPackStream->getPlainRawStream(); - - // create another temporary file - uno::Reference < io::XOutputStream > xTempOut( - m_xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), - uno::UNO_QUERY ); - uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY ); - uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY ); - if ( !xTempOut.is() || !xTempIn.is() || !xTempSeek.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // copy the raw stream to the temporary file - ::comphelper::OStorageHelper::CopyInputToOutput( xInRaw, xTempOut ); - xTempOut->closeOutput(); - xTempSeek->seek( 0 ); - - // close raw stream, package stream and folder - xInRaw = uno::Reference< io::XInputStream >(); - xNewPSProps = uno::Reference< XPropertySet >(); - xNPSTunnel = uno::Reference< XUnoTunnel >(); - xNewPackStream = uno::Reference< XDataSinkEncrSupport >(); - xTunnel = uno::Reference< XUnoTunnel >(); - xRootNameContainer = uno::Reference< container::XNameContainer >(); - - // return the stream representing the first temporary file - return xTempIn; - } - catch ( RuntimeException& ) - { - throw; - } - catch ( Exception& ) - { - } - - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//-------------------------------------------------------------------------- -sal_Bool ZipPackageStream::ParsePackageRawStream() -{ - OSL_ENSURE( GetOwnSeekStream().is(), "A stream must be provided!\n" ); - - if ( !GetOwnSeekStream().is() ) - return sal_False; - - sal_Bool bOk = sal_False; - - ::rtl::Reference< BaseEncryptionData > xTempEncrData; - sal_Int32 nMagHackSize = 0; - Sequence < sal_Int8 > aHeader ( 4 ); - - try - { - if ( GetOwnSeekStream()->readBytes ( aHeader, 4 ) == 4 ) - { - const sal_Int8 *pHeader = aHeader.getConstArray(); - sal_uInt32 nHeader = ( pHeader [0] & 0xFF ) | - ( pHeader [1] & 0xFF ) << 8 | - ( pHeader [2] & 0xFF ) << 16 | - ( pHeader [3] & 0xFF ) << 24; - if ( nHeader == n_ConstHeader ) - { - // this is one of our god-awful, but extremely devious hacks, everyone cheer - xTempEncrData = new BaseEncryptionData; - - ::rtl::OUString aMediaType; - sal_Int32 nEncAlgorithm = 0; - sal_Int32 nChecksumAlgorithm = 0; - sal_Int32 nDerivedKeySize = 0; - sal_Int32 nStartKeyGenID = 0; - if ( ZipFile::StaticFillData( xTempEncrData, nEncAlgorithm, nChecksumAlgorithm, nDerivedKeySize, nStartKeyGenID, nMagHackSize, aMediaType, GetOwnSeekStream() ) ) - { - // We'll want to skip the data we've just read, so calculate how much we just read - // and remember it - m_nMagicalHackPos = n_ConstHeaderSize + xTempEncrData->m_aSalt.getLength() - + xTempEncrData->m_aInitVector.getLength() - + xTempEncrData->m_aDigest.getLength() - + aMediaType.getLength() * sizeof( sal_Unicode ); - m_nImportedEncryptionAlgorithm = nEncAlgorithm; - m_nImportedChecksumAlgorithm = nChecksumAlgorithm; - m_nImportedDerivedKeySize = nDerivedKeySize; - m_nImportedStartKeyAlgorithm = nStartKeyGenID; - m_nMagicalHackSize = nMagHackSize; - sMediaType = aMediaType; - - bOk = sal_True; - } - } - } - } - catch( Exception& ) - { - } - - if ( !bOk ) - { - // the provided stream is not a raw stream - return sal_False; - } - - m_xBaseEncryptionData = xTempEncrData; - SetIsEncrypted ( sal_True ); - // it's already compressed and encrypted - bToBeEncrypted = bToBeCompressed = sal_False; - - return sal_True; -} - -void ZipPackageStream::SetPackageMember( sal_Bool bNewValue ) -{ - if ( bNewValue ) - { - m_nStreamMode = PACKAGE_STREAM_PACKAGEMEMBER; - m_nMagicalHackPos = 0; - m_nMagicalHackSize = 0; - } - else if ( m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER ) - m_nStreamMode = PACKAGE_STREAM_NOTSET; // must be reset -} - -// XActiveDataSink -//-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setInputStream( const uno::Reference< io::XInputStream >& aStream ) - throw( RuntimeException ) -{ - // if seekable access is required the wrapping will be done on demand - xStream = aStream; - m_nImportedEncryptionAlgorithm = 0; - m_bHasSeekable = sal_False; - SetPackageMember ( sal_False ); - aEntry.nTime = -1; - m_nStreamMode = PACKAGE_STREAM_DETECT; -} - -//-------------------------------------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData() - throw( RuntimeException ) -{ - try - { - if ( IsPackageMember() ) - { - return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); - } - else if ( GetOwnSeekStream().is() ) - { - return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); - } - else - return uno::Reference < io::XInputStream > (); - } - catch ( ZipException & )//rException ) - { - OSL_FAIL( "ZipException thrown" );//rException.Message); - return uno::Reference < io::XInputStream > (); - } - catch ( Exception & ) - { - OSL_FAIL( "Exception is thrown during stream wrapping!\n" ); - return uno::Reference < io::XInputStream > (); - } -} - -//-------------------------------------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream() - throw( RuntimeException ) -{ - try - { - if ( IsPackageMember() ) - { - return rZipPackage.getZipFile().getInputStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); - } - else if ( GetOwnSeekStream().is() ) - { - return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); - } - else - return uno::Reference < io::XInputStream > (); - } - catch ( ZipException & )//rException ) - { - OSL_FAIL( "ZipException thrown" );//rException.Message); - return uno::Reference < io::XInputStream > (); - } - catch ( Exception & ) - { - OSL_FAIL( "Exception is thrown during stream wrapping!\n" ); - return uno::Reference < io::XInputStream > (); - } -} - -// XDataSinkEncrSupport -//-------------------------------------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream() - throw ( packages::WrongPasswordException, - io::IOException, - RuntimeException ) -{ - // There is no stream attached to this object - if ( m_nStreamMode == PACKAGE_STREAM_NOTSET ) - return uno::Reference< io::XInputStream >(); - - // this method can not be used together with old approach - if ( m_nStreamMode == PACKAGE_STREAM_DETECT ) - throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( IsPackageMember() ) - { - uno::Reference< io::XInputStream > xResult; - try - { - xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); - } - catch( packages::WrongPasswordException& ) - { - // workaround for the encrypted documents generated with the old OOo1.x bug. - if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 && !m_bUseWinEncoding ) - { - xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); - m_bUseWinEncoding = true; - } - else - throw; - } - return xResult; - } - else if ( m_nStreamMode == PACKAGE_STREAM_RAW ) - return ZipFile::StaticGetDataFromRawStream( m_xFactory, GetOwnSeekStream(), GetEncryptionData() ); - else if ( GetOwnSeekStream().is() ) - { - return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); - } - else - return uno::Reference< io::XInputStream >(); -} - -//-------------------------------------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream() - throw ( packages::NoEncryptionException, - io::IOException, - uno::RuntimeException ) -{ - // There is no stream attached to this object - if ( m_nStreamMode == PACKAGE_STREAM_NOTSET ) - return uno::Reference< io::XInputStream >(); - - // this method can not be used together with old approach - if ( m_nStreamMode == PACKAGE_STREAM_DETECT ) - throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( IsPackageMember() ) - { - if ( !bIsEncrypted || !GetEncryptionData().is() ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return rZipPackage.getZipFile().getWrappedRawStream( aEntry, GetEncryptionData(), sMediaType, rZipPackage.GetSharedMutexRef() ); - } - else if ( GetOwnSeekStream().is() ) - { - if ( m_nStreamMode == PACKAGE_STREAM_RAW ) - { - return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); - } - else if ( m_nStreamMode == PACKAGE_STREAM_DATA && bToBeEncrypted ) - return TryToGetRawFromDataStream( sal_True ); - } - - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - - -//-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setDataStream( const uno::Reference< io::XInputStream >& aStream ) - throw ( io::IOException, - RuntimeException ) -{ - setInputStream( aStream ); - m_nStreamMode = PACKAGE_STREAM_DATA; -} - -//-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setRawStream( const uno::Reference< io::XInputStream >& aStream ) - throw ( packages::EncryptionNotAllowedException, - packages::NoRawFormatException, - io::IOException, - RuntimeException ) -{ - // wrap the stream in case it is not seekable - uno::Reference< io::XInputStream > xNewStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( aStream, m_xFactory ); - uno::Reference< io::XSeekable > xSeek( xNewStream, UNO_QUERY ); - if ( !xSeek.is() ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ), - uno::Reference< XInterface >() ); - - xSeek->seek( 0 ); - uno::Reference< io::XInputStream > xOldStream = xStream; - xStream = xNewStream; - if ( !ParsePackageRawStream() ) - { - xStream = xOldStream; - throw packages::NoRawFormatException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - // the raw stream MUST have seekable access - m_bHasSeekable = sal_True; - - SetPackageMember ( sal_False ); - aEntry.nTime = -1; - m_nStreamMode = PACKAGE_STREAM_RAW; -} - -//-------------------------------------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getPlainRawStream() - throw ( io::IOException, - uno::RuntimeException ) -{ - // There is no stream attached to this object - if ( m_nStreamMode == PACKAGE_STREAM_NOTSET ) - return uno::Reference< io::XInputStream >(); - - // this method can not be used together with old approach - if ( m_nStreamMode == PACKAGE_STREAM_DETECT ) - throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( IsPackageMember() ) - { - return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); - } - else if ( GetOwnSeekStream().is() ) - { - if ( m_nStreamMode == PACKAGE_STREAM_RAW ) - { - // the header should not be returned here - return GetRawEncrStreamNoHeaderCopy(); - } - else if ( m_nStreamMode == PACKAGE_STREAM_DATA ) - return TryToGetRawFromDataStream( sal_False ); - } - - return uno::Reference< io::XInputStream >(); -} - -// XUnoTunnel - -//-------------------------------------------------------------------------- -sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& aIdentifier ) - throw( RuntimeException ) -{ - sal_Int64 nMe = 0; - if ( aIdentifier.getLength() == 16 && - 0 == rtl_compareMemory( static_getImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) - nMe = reinterpret_cast < sal_Int64 > ( this ); - return nMe; -} - -// XPropertySet -//-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) - throw( beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException ) -{ - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" )) ) - { - if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE && rZipPackage.getFormat() != embed::StorageFormats::OFOPXML ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( aValue >>= sMediaType ) - { - if ( sMediaType.getLength() > 0 ) - { - if ( sMediaType.indexOf ( OUString( RTL_CONSTASCII_USTRINGPARAM ( "text" ) ) ) != -1 - || sMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM ( "application/vnd.sun.star.oleobject" ) ) ) ) - bToBeCompressed = sal_True; - else if ( !m_bCompressedIsSetFromOutside ) - bToBeCompressed = sal_False; - } - } - else - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "MediaType must be a string!\n" ) ), - uno::Reference< XInterface >(), - 2 ); - - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) - { - if ( !( aValue >>= aEntry.nSize ) ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Size property!\n" ) ), - uno::Reference< XInterface >(), - 2 ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) - { - if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - sal_Bool bEnc = sal_False; - if ( aValue >>= bEnc ) - { - // In case of new raw stream, the stream must not be encrypted on storing - if ( bEnc && m_nStreamMode == PACKAGE_STREAM_RAW ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ), - uno::Reference< XInterface >(), - 2 ); - - bToBeEncrypted = bEnc; - if ( bToBeEncrypted && !m_xBaseEncryptionData.is() ) - m_xBaseEncryptionData = new BaseEncryptionData; - } - else - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Encrypted property!\n" ) ), - uno::Reference< XInterface >(), - 2 ); - - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) - { - if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< sal_Int8 > aNewKey; - - if ( !( aValue >>= aNewKey ) ) - { - OUString sTempString; - if ( ( aValue >>= sTempString ) ) - { - sal_Int32 nPathLength = sTempString.getLength(); - Sequence < sal_Int8 > aSequence ( nPathLength ); - sal_Int8 *pArray = aSequence.getArray(); - const sal_Unicode *pChar = sTempString.getStr(); - for ( sal_Int16 i = 0; i < nPathLength; i++ ) - pArray[i] = static_cast < const sal_Int8 > ( pChar[i] ); - aNewKey = aSequence; - } - else - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for EncryptionKey property!\n" ) ), - uno::Reference< XInterface >(), - 2 ); - } - - if ( aNewKey.getLength() ) - { - if ( !m_xBaseEncryptionData.is() ) - m_xBaseEncryptionData = new BaseEncryptionData; - - m_aEncryptionKey = aNewKey; - // In case of new raw stream, the stream must not be encrypted on storing - bHaveOwnKey = sal_True; - if ( m_nStreamMode != PACKAGE_STREAM_RAW ) - bToBeEncrypted = sal_True; - } - else - { - bHaveOwnKey = sal_False; - m_aEncryptionKey.realloc( 0 ); - } - - m_aStorageEncryptionKeys.realloc( 0 ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) - { - if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< beans::NamedValue > aKeys; - if ( !( aValue >>= aKeys ) ) - { - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for StorageEncryptionKeys property!\n" ) ), - uno::Reference< XInterface >(), - 2 ); - } - - if ( aKeys.getLength() ) - { - if ( !m_xBaseEncryptionData.is() ) - m_xBaseEncryptionData = new BaseEncryptionData; - - m_aStorageEncryptionKeys = aKeys; - - // In case of new raw stream, the stream must not be encrypted on storing - bHaveOwnKey = sal_True; - if ( m_nStreamMode != PACKAGE_STREAM_RAW ) - bToBeEncrypted = sal_True; - } - else - { - bHaveOwnKey = sal_False; - m_aStorageEncryptionKeys.realloc( 0 ); - } - - m_aEncryptionKey.realloc( 0 ); - } - else if ( aPropertyName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) - { - sal_Bool bCompr = sal_False; - - if ( aValue >>= bCompr ) - { - // In case of new raw stream, the stream must not be encrypted on storing - if ( bCompr && m_nStreamMode == PACKAGE_STREAM_RAW ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ), - uno::Reference< XInterface >(), - 2 ); - - bToBeCompressed = bCompr; - m_bCompressedIsSetFromOutside = sal_True; - } - else - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Compressed property!\n" ) ), - uno::Reference< XInterface >(), - 2 ); - } - else - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//-------------------------------------------------------------------------- -Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName ) - throw( beans::UnknownPropertyException, WrappedTargetException, RuntimeException ) -{ - Any aAny; - if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - { - aAny <<= sMediaType; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) ) - { - aAny <<= aEntry.nSize; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Encrypted" ) ) ) - { - aAny <<= ((m_nStreamMode == PACKAGE_STREAM_RAW) ? sal_True : bToBeEncrypted); - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WasEncrypted" ) ) ) - { - aAny <<= bIsEncrypted; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) - { - aAny <<= bToBeCompressed; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) - { - aAny <<= m_aEncryptionKey; - return aAny; - } - else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) - { - aAny <<= m_aStorageEncryptionKeys; - return aAny; - } - else - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//-------------------------------------------------------------------------- -void ZipPackageStream::setSize ( const sal_Int32 nNewSize ) -{ - if ( aEntry.nCompressedSize != nNewSize ) - aEntry.nMethod = DEFLATED; - aEntry.nSize = nNewSize; -} -//-------------------------------------------------------------------------- -OUString ZipPackageStream::getImplementationName() - throw ( RuntimeException ) -{ - return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageStream" ) ); -} - -//-------------------------------------------------------------------------- -Sequence< OUString > ZipPackageStream::getSupportedServiceNames() - throw ( RuntimeException ) -{ - Sequence< OUString > aNames( 1 ); - aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageStream" ) ); - return aNames; -} -//-------------------------------------------------------------------------- -sal_Bool SAL_CALL ZipPackageStream::supportsService( OUString const & rServiceName ) - throw ( RuntimeException ) -{ - return rServiceName == getSupportedServiceNames()[0]; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/makefile.mk b/package/source/zippackage/makefile.mk deleted file mode 100644 index c729b945f..000000000 --- a/package/source/zippackage/makefile.mk +++ /dev/null @@ -1,58 +0,0 @@ -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2000, 2010 Oracle and/or its affiliates. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# <http://www.openoffice.org/license.html> -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -PRJ=..$/.. -PRJNAME=package -TARGET=zippackage -AUTOSEG=true - -ENABLE_EXCEPTIONS=TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE : settings.mk - -# --- Files -------------------------------------------------------- - -.IF "$(L10N_framework)"=="" - -SLOFILES= \ - $(SLO)$/ZipPackage.obj \ - $(SLO)$/ZipPackageBuffer.obj \ - $(SLO)$/ZipPackageEntry.obj \ - $(SLO)$/ZipPackageFolder.obj \ - $(SLO)$/ZipPackageFolderEnumeration.obj \ - $(SLO)$/ZipPackageSink.obj \ - $(SLO)$/ZipPackageStream.obj \ - $(SLO)$/wrapstreamforshare.obj \ - $(SLO)$/zipfileaccess.obj - -.ENDIF # L10N_framework - -# --- Targets ------------------------------------------------------ - -.INCLUDE : target.mk diff --git a/package/source/zippackage/wrapstreamforshare.cxx b/package/source/zippackage/wrapstreamforshare.cxx deleted file mode 100644 index e4fcdbfb8..000000000 --- a/package/source/zippackage/wrapstreamforshare.cxx +++ /dev/null @@ -1,182 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <osl/diagnose.h> - -#include "wrapstreamforshare.hxx" - -using namespace ::com::sun::star; - - -WrapStreamForShare::WrapStreamForShare( const uno::Reference< io::XInputStream >& xInStream, - const SotMutexHolderRef& rMutexRef ) -: m_rMutexRef( rMutexRef ) -, m_xInStream( xInStream ) -, m_nCurPos( 0 ) -{ - m_xSeekable = uno::Reference< io::XSeekable >( m_xInStream, uno::UNO_QUERY ); - if ( !m_rMutexRef.Is() || !m_xInStream.is() || !m_xSeekable.is() ) - { - OSL_FAIL( "Wrong initialization of wrapping stream!\n" ); - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } -} - -WrapStreamForShare::~WrapStreamForShare() -{ -} - -// XInputStream -sal_Int32 SAL_CALL WrapStreamForShare::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_xSeekable->seek( m_nCurPos ); - - sal_Int32 nRead = m_xInStream->readBytes( aData, nBytesToRead ); - m_nCurPos += nRead; - - return nRead; -} - -sal_Int32 SAL_CALL WrapStreamForShare::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_xSeekable->seek( m_nCurPos ); - - sal_Int32 nRead = m_xInStream->readSomeBytes( aData, nMaxBytesToRead ); - m_nCurPos += nRead; - - return nRead; -} - -void SAL_CALL WrapStreamForShare::skipBytes( sal_Int32 nBytesToSkip ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_xSeekable->seek( m_nCurPos ); - - m_xInStream->skipBytes( nBytesToSkip ); - m_nCurPos = m_xSeekable->getPosition(); -} - -sal_Int32 SAL_CALL WrapStreamForShare::available() - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return m_xInStream->available(); -} - -void SAL_CALL WrapStreamForShare::closeInput() - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // the package is the owner so it will close the stream - // m_xInStream->closeInput(); - m_xInStream = uno::Reference< io::XInputStream >(); - m_xSeekable = uno::Reference< io::XSeekable >(); -} - -// XSeekable -void SAL_CALL WrapStreamForShare::seek( sal_Int64 location ) - throw ( lang::IllegalArgumentException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // let stream implementation do all the checking - m_xSeekable->seek( location ); - - m_nCurPos = m_xSeekable->getPosition(); -} - -sal_Int64 SAL_CALL WrapStreamForShare::getPosition() - throw ( io::IOException, - uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return m_nCurPos; -} - -sal_Int64 SAL_CALL WrapStreamForShare::getLength() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return m_xSeekable->getLength(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/wrapstreamforshare.hxx b/package/source/zippackage/wrapstreamforshare.hxx deleted file mode 100644 index 90b6ef496..000000000 --- a/package/source/zippackage/wrapstreamforshare.hxx +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _WRAPSTREAMFORSHARE_HXX_ -#define _WRAPSTREAMFORSHARE_HXX_ - -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <cppuhelper/implbase2.hxx> - -#include <mutexholder.hxx> - -class WrapStreamForShare : public cppu::WeakImplHelper2 < ::com::sun::star::io::XInputStream - , ::com::sun::star::io::XSeekable > -{ -protected: - SotMutexHolderRef m_rMutexRef; - ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > m_xInStream; - ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > m_xSeekable; - - sal_Int64 m_nCurPos; - -public: - WrapStreamForShare( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, - const SotMutexHolderRef& rMutexRef ); - virtual ~WrapStreamForShare(); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - - //XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx deleted file mode 100644 index 60b148a8c..000000000 --- a/package/source/zippackage/zipfileaccess.cxx +++ /dev/null @@ -1,493 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/ucb/XCommandEnvironment.hpp> -#include <com/sun/star/io/XActiveDataSink.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> - -#include <zipfileaccess.hxx> -#include <ZipEnumeration.hxx> -#include <ZipPackageSink.hxx> -#include <EncryptionData.hxx> - -#include <ucbhelper/content.hxx> -#include <rtl/ref.hxx> - -#include <memory> - - -using namespace ::com::sun::star; - -// ---------------------------------------------------------------- -OZipFileAccess::OZipFileAccess( const uno::Reference< lang::XMultiServiceFactory >& xFactory ) -: m_aMutexHolder( new SotMutexHolder ) -, m_xFactory( xFactory ) -, m_pZipFile( NULL ) -, m_pListenersContainer( NULL ) -, m_bDisposed( sal_False ) -{ - if ( !xFactory.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -// ---------------------------------------------------------------- -OZipFileAccess::~OZipFileAccess() -{ - { - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - if ( !m_bDisposed ) - { - try { - m_refCount++; // dispose will use refcounting so the further distruction must be avoided - dispose(); - } catch( uno::Exception& ) - {} - } - } -} - -// ---------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > OZipFileAccess::GetPatternsFromString_Impl( const ::rtl::OUString& aString ) -{ - if ( !aString.getLength() ) - return uno::Sequence< ::rtl::OUString >(); - - uno::Sequence< ::rtl::OUString > aPattern( 1 ); - sal_Int32 nInd = 0; - - const sal_Unicode* pString = aString.getStr(); - while( *pString ) - { - if ( *pString == (sal_Unicode)'\\' ) - { - pString++; - - if ( *pString == (sal_Unicode)'\\' ) - { - aPattern[nInd] += ::rtl::OUString::valueOf( (sal_Unicode)'\\' ); - pString++; - } - else if ( *pString == (sal_Unicode)'*' ) - { - aPattern[nInd] += ::rtl::OUString::valueOf( (sal_Unicode)'*' ); - pString++; - } - else - { - OSL_FAIL( "The backslash is not guarded!\n" ); - aPattern[nInd] += ::rtl::OUString::valueOf( (sal_Unicode)'\\' ); - } - } - else if ( *pString == (sal_Unicode)'*' ) - { - aPattern.realloc( ( ++nInd ) + 1 ); - pString++; - } - else - { - aPattern[nInd] += ::rtl::OUString::valueOf( *pString ); - pString++; - } - } - - return aPattern; -} - -// ---------------------------------------------------------------- -sal_Bool OZipFileAccess::StringGoodForPattern_Impl( const ::rtl::OUString& aString, - const uno::Sequence< ::rtl::OUString >& aPattern ) -{ - sal_Int32 nInd = aPattern.getLength() - 1; - if ( nInd < 0 ) - return sal_False; - - if ( nInd == 0 ) - { - if ( !aPattern[0].getLength() ) - return sal_True; - - return aString.equals( aPattern[0] ); - } - - sal_Int32 nBeginInd = aPattern[0].getLength(); - sal_Int32 nEndInd = aString.getLength() - aPattern[nInd].getLength(); - if ( nEndInd >= nBeginInd - && ( nEndInd == aString.getLength() || aString.copy( nEndInd ).equals( aPattern[nInd] ) ) - && ( nBeginInd == 0 || aString.copy( 0, nBeginInd ).equals( aPattern[0] ) ) ) - { - for ( sal_Int32 nCurInd = aPattern.getLength() - 2; nCurInd > 0; nCurInd-- ) - { - if ( !aPattern[nCurInd].getLength() ) - continue; - - if ( nEndInd == nBeginInd ) - return sal_False; - - // check that search does not use nEndInd position - sal_Int32 nLastInd = aString.lastIndexOf( aPattern[nCurInd], nEndInd - 1 ); - - if ( nLastInd == -1 ) - return sal_False; - - if ( nLastInd < nBeginInd ) - return sal_False; - - nEndInd = nLastInd; - } - - return sal_True; - } - - return sal_False; -} - -// XInitialization -// ---------------------------------------------------------------- -void SAL_CALL OZipFileAccess::initialize( const uno::Sequence< uno::Any >& aArguments ) - throw ( uno::Exception, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_pZipFile ) - throw uno::Exception( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // initialization is allowed only one time - - if ( !aArguments.getLength() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - OSL_ENSURE( aArguments.getLength() == 1, "Too meny arguments are provided, only the first one will be used!\n" ); - - ::rtl::OUString aParamURL; - uno::Reference< io::XStream > xStream; - uno::Reference< io::XSeekable > xSeekable; - - if ( ( aArguments[0] >>= aParamURL ) ) - { - ::ucbhelper::Content aContent ( aParamURL, uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); - uno::Reference < io::XActiveDataSink > xSink = new ZipPackageSink; - if ( aContent.openStream ( xSink ) ) - { - m_xContentStream = xSink->getInputStream(); - xSeekable = uno::Reference< io::XSeekable >( m_xContentStream, uno::UNO_QUERY ); - } - } - else if ( (aArguments[0] >>= xStream ) ) - { - // a writable stream can implement both XStream & XInputStream - m_xContentStream = xStream->getInputStream(); - xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY ); - } - else if ( !( aArguments[0] >>= m_xContentStream ) ) - { - xSeekable = uno::Reference< io::XSeekable >( m_xContentStream, uno::UNO_QUERY ); - } - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !m_xContentStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !xSeekable.is() ) - { - // TODO: after fwkbugfix02 is integrated a helper class can be used to make the stream seekable - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - // TODO: in case xSeekable is implemented on separated XStream implementation a wrapper is required - m_pZipFile = new ZipFile( - m_xContentStream, - m_xFactory, - sal_True ); -} - -// XNameAccess -// ---------------------------------------------------------------- -uno::Any SAL_CALL OZipFileAccess::getByName( const ::rtl::OUString& aName ) - throw ( container::NoSuchElementException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !m_pZipFile ) - throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - EntryHash::iterator aIter = m_pZipFile->GetEntryHash().find( aName ); - if ( aIter == m_pZipFile->GetEntryHash().end() ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second, - ::rtl::Reference< EncryptionData >(), - sal_False, - m_aMutexHolder ) ); - - if ( !xEntryStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return uno::makeAny ( xEntryStream ); -} - -// ---------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OZipFileAccess::getElementNames() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !m_pZipFile ) - throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< ::rtl::OUString > aNames( m_pZipFile->GetEntryHash().size() ); - sal_Int32 nLen = 0; - - for ( EntryHash::iterator aIter = m_pZipFile->GetEntryHash().begin(); aIter != m_pZipFile->GetEntryHash().end(); ++aIter ) - { - if ( aNames.getLength() < ++nLen ) - { - OSL_FAIL( "The size must be the same!\n" ); - aNames.realloc( nLen ); - } - - aNames[nLen-1] = (*aIter).second.sPath; - } - - if ( aNames.getLength() != nLen ) - { - OSL_FAIL( "The size must be the same!\n" ); - aNames.realloc( nLen ); - } - - return aNames; -} - -// ---------------------------------------------------------------- -sal_Bool SAL_CALL OZipFileAccess::hasByName( const ::rtl::OUString& aName ) - throw (uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !m_pZipFile ) - throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - EntryHash::iterator aIter = m_pZipFile->GetEntryHash().find( aName ); - - return ( aIter != m_pZipFile->GetEntryHash().end() ); -} - -// ---------------------------------------------------------------- -uno::Type SAL_CALL OZipFileAccess::getElementType() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !m_pZipFile ) - throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ); -} - -// ---------------------------------------------------------------- -sal_Bool SAL_CALL OZipFileAccess::hasElements() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !m_pZipFile ) - throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return ( m_pZipFile->GetEntryHash().size() != 0 ); -} - -// XZipFileAccess -// ---------------------------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OZipFileAccess::getStreamByPattern( const ::rtl::OUString& aPatternString ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !m_pZipFile ) - throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // Code to compare strings by patterns - uno::Sequence< ::rtl::OUString > aPattern = GetPatternsFromString_Impl( aPatternString ); - - for ( EntryHash::iterator aIter = m_pZipFile->GetEntryHash().begin(); aIter != m_pZipFile->GetEntryHash().end(); ++aIter ) - { - if ( StringGoodForPattern_Impl( (*aIter).second.sPath, aPattern ) ) - { - uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second, - ::rtl::Reference< EncryptionData >(), - sal_False, - m_aMutexHolder ) ); - - if ( !xEntryStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return xEntryStream; - } - } - - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -// XComponent -// ---------------------------------------------------------------- -void SAL_CALL OZipFileAccess::dispose() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_pListenersContainer ) - { - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - m_pListenersContainer->disposeAndClear( aSource ); - delete m_pListenersContainer; - m_pListenersContainer = NULL; - } - - if ( m_pZipFile ) - { - delete m_pZipFile; - m_pZipFile = NULL; - } - - if ( m_xContentStream.is() ) - try { - m_xContentStream->closeInput(); - } catch( uno::Exception& ) - {} - - m_bDisposed = sal_True; -} - -// ---------------------------------------------------------------- -void SAL_CALL OZipFileAccess::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !m_pListenersContainer ) - m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutexHolder->GetMutex() ); - m_pListenersContainer->addInterface( xListener ); -} - -// ---------------------------------------------------------------- -void SAL_CALL OZipFileAccess::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - - if ( m_bDisposed ) - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_pListenersContainer ) - m_pListenersContainer->removeInterface( xListener ); -} - -//------------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OZipFileAccess::impl_staticGetSupportedServiceNames() -{ - uno::Sequence< ::rtl::OUString > aRet(2); - aRet[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.packages.zip.ZipFileAccess") ); - aRet[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.packages.zip.ZipFileAccess") ); - return aRet; -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL OZipFileAccess::impl_staticGetImplementationName() -{ - return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.package.zip.ZipFileAccess") ); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL OZipFileAccess::impl_staticCreateSelfInstance( - const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) -{ - return uno::Reference< uno::XInterface >( *new OZipFileAccess( xServiceManager ) ); -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL OZipFileAccess::getImplementationName() - throw ( uno::RuntimeException ) -{ - return impl_staticGetImplementationName(); -} - -//------------------------------------------------------------------------- -sal_Bool SAL_CALL OZipFileAccess::supportsService( const ::rtl::OUString& ServiceName ) - throw ( uno::RuntimeException ) -{ - uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); - - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( ServiceName.compareTo( aSeq[nInd] ) == 0 ) - return sal_True; - - return sal_False; -} - -//------------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OZipFileAccess::getSupportedServiceNames() - throw ( uno::RuntimeException ) -{ - return impl_staticGetSupportedServiceNames(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |