1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _COMPHELPER_STORAGEHELPER_HXX 24 #define _COMPHELPER_STORAGEHELPER_HXX 25 26 #include <com/sun/star/uno/Sequence.hxx> 27 #include <com/sun/star/uno/Reference.hxx> 28 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 29 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 30 #include <com/sun/star/embed/XStorage.hpp> 31 #include <com/sun/star/embed/ElementModes.hpp> 32 #include <com/sun/star/beans/NamedValue.hpp> 33 #include <com/sun/star/io/XInputStream.hpp> 34 #include <com/sun/star/io/XOutputStream.hpp> 35 #include <com/sun/star/io/XStream.hpp> 36 #include "comphelper/comphelperdllapi.h" 37 38 39 #define PACKAGE_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageFormat" ) ) 40 #define ZIP_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) ) 41 #define OFOPXML_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) ) 42 43 #define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA256UTF8EncryptionKey" ) ) 44 #define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1UTF8EncryptionKey" ) ) 45 #define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1MS1252EncryptionKey" ) ) 46 47 namespace comphelper { 48 49 class COMPHELPER_DLLPUBLIC OStorageHelper 50 { 51 public: 52 static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > 53 GetStorageFactory( 54 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF 55 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 56 57 static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > 58 GetFileSystemStorageFactory( 59 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF 60 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 61 62 static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 63 GetTemporaryStorage( 64 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 65 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 66 67 /// this one will only return Storage 68 static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 69 GetStorageFromURL( 70 const ::rtl::OUString& aURL, 71 sal_Int32 nStorageMode, 72 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 73 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 74 75 /// this one will return either Storage or FileSystemStorage 76 static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 77 GetStorageFromURL2( 78 const ::rtl::OUString& aURL, 79 sal_Int32 nStorageMode, 80 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 81 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 82 83 static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 84 GetStorageFromInputStream( 85 const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream, 86 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 87 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 88 89 static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 90 GetStorageFromStream( 91 const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream, 92 sal_Int32 nStorageMode = ::com::sun::star::embed::ElementModes::READWRITE, 93 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 94 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 95 96 static void CopyInputToOutput( 97 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInput, 98 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput ); 99 100 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 101 GetInputStreamFromURL( 102 const ::rtl::OUString& aURL, 103 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 104 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 105 106 static void SetCommonStorageEncryptionData( 107 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, 108 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ); 109 110 // the following method supports only storages of OOo formats 111 static sal_Int32 GetXStorageFormat( 112 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); 113 114 // The followin methods are related to creation of a storage of specified format 115 static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 116 GetTemporaryStorageOfFormat( 117 const ::rtl::OUString& aFormat, 118 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 119 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 120 121 static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 122 GetStorageOfFormatFromURL( 123 const ::rtl::OUString& aFormat, 124 const ::rtl::OUString& aURL, 125 sal_Int32 nStorageMode, 126 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 127 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(), 128 sal_Bool bRepairStorage = sal_False ); 129 130 static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 131 GetStorageOfFormatFromInputStream( 132 const ::rtl::OUString& aFormat, 133 const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream, 134 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 135 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(), 136 sal_Bool bRepairStorage = sal_False ); 137 138 static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 139 GetStorageOfFormatFromStream( 140 const ::rtl::OUString& aFormat, 141 const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream, 142 sal_Int32 nStorageMode = ::com::sun::star::embed::ElementModes::READWRITE, 143 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory 144 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(), 145 sal_Bool bRepairStorage = sal_False ); 146 147 static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > 148 CreatePackageEncryptionData( 149 const ::rtl::OUString& aPassword, 150 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF 151 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); 152 153 static sal_Bool IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed ); 154 static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed ); 155 156 static sal_Bool PathHasSegment( const ::rtl::OUString& aPath, const ::rtl::OUString& aSegment ); 157 }; 158 159 } 160 161 #endif 162