diff options
author | obo <obo@openoffice.org> | 2010-06-18 10:54:35 +0200 |
---|---|---|
committer | obo <obo@openoffice.org> | 2010-06-18 10:54:35 +0200 |
commit | 5f7bddbfb7114b40efef037e7f9ebd4f2c35896b (patch) | |
tree | fe912b22c1f013990e76af448f52406dd08b082a /comphelper/source | |
parent | 3c3415be60ced7923b14152a025949b042357d18 (diff) | |
parent | 15744fda13dfa45bc3d737bc72f2768edfc7c81a (diff) |
CWS-TOOLING: integrate CWS tl78
Diffstat (limited to 'comphelper/source')
-rw-r--r-- | comphelper/source/misc/docpasswordhelper.cxx | 132 | ||||
-rw-r--r-- | comphelper/source/misc/docpasswordrequest.cxx | 86 | ||||
-rw-r--r-- | comphelper/source/misc/mediadescriptor.cxx | 1711 |
3 files changed, 1064 insertions, 865 deletions
diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx index ea25cb795a53..fc41eaec3194 100644 --- a/comphelper/source/misc/docpasswordhelper.cxx +++ b/comphelper/source/misc/docpasswordhelper.cxx @@ -1,4 +1,4 @@ -/************************************************************************* +/*********************************************************************** * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -33,6 +33,7 @@ #include "comphelper/mediadescriptor.hxx" using ::rtl::OUString; +using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::UNO_SET_THROW; @@ -51,6 +52,135 @@ IDocPasswordVerifier::~IDocPasswordVerifier() } // ============================================================================ +sal_uInt32 DocPasswordHelper::GetWordHashAsUINT32( + const ::rtl::OUString& aUString ) +{ + static sal_uInt16 pInitialCode[] = { + 0xE1F0, // 1 + 0x1D0F, // 2 + 0xCC9C, // 3 + 0x84C0, // 4 + 0x110C, // 5 + 0x0E10, // 6 + 0xF1CE, // 7 + 0x313E, // 8 + 0x1872, // 9 + 0xE139, // 10 + 0xD40F, // 11 + 0x84F9, // 12 + 0x280C, // 13 + 0xA96A, // 14 + 0x4EC3 // 15 + }; + + static sal_uInt16 pEncryptionMatrix[15][7] = { + { 0xAEFC, 0x4DD9, 0x9BB2, 0x2745, 0x4E8A, 0x9D14, 0x2A09}, // last-14 + { 0x7B61, 0xF6C2, 0xFDA5, 0xEB6B, 0xC6F7, 0x9DCF, 0x2BBF}, // last-13 + { 0x4563, 0x8AC6, 0x05AD, 0x0B5A, 0x16B4, 0x2D68, 0x5AD0}, // last-12 + { 0x0375, 0x06EA, 0x0DD4, 0x1BA8, 0x3750, 0x6EA0, 0xDD40}, // last-11 + { 0xD849, 0xA0B3, 0x5147, 0xA28E, 0x553D, 0xAA7A, 0x44D5}, // last-10 + { 0x6F45, 0xDE8A, 0xAD35, 0x4A4B, 0x9496, 0x390D, 0x721A}, // last-9 + { 0xEB23, 0xC667, 0x9CEF, 0x29FF, 0x53FE, 0xA7FC, 0x5FD9}, // last-8 + { 0x47D3, 0x8FA6, 0x8FA6, 0x1EDA, 0x3DB4, 0x7B68, 0xF6D0}, // last-7 + { 0xB861, 0x60E3, 0xC1C6, 0x93AD, 0x377B, 0x6EF6, 0xDDEC}, // last-6 + { 0x45A0, 0x8B40, 0x06A1, 0x0D42, 0x1A84, 0x3508, 0x6A10}, // last-5 + { 0xAA51, 0x4483, 0x8906, 0x022D, 0x045A, 0x08B4, 0x1168}, // last-4 + { 0x76B4, 0xED68, 0xCAF1, 0x85C3, 0x1BA7, 0x374E, 0x6E9C}, // last-3 + { 0x3730, 0x6E60, 0xDCC0, 0xA9A1, 0x4363, 0x86C6, 0x1DAD}, // last-2 + { 0x3331, 0x6662, 0xCCC4, 0x89A9, 0x0373, 0x06E6, 0x0DCC}, // last-1 + { 0x1021, 0x2042, 0x4084, 0x8108, 0x1231, 0x2462, 0x48C4} // last + }; + + sal_uInt32 nResult = 0; + sal_uInt32 nLen = aUString.getLength(); + + if ( nLen ) + { + if ( nLen > 15 ) + nLen = 15; + + sal_uInt16 nHighResult = pInitialCode[nLen - 1]; + sal_uInt16 nLowResult = 0; + + const sal_Unicode* pStr = aUString.getStr(); + for ( sal_uInt32 nInd = 0; nInd < nLen; nInd++ ) + { + // NO Encoding during conversion! + // The specification says that the low byte should be used in case it is not NULL + char nHighChar = (char)( pStr[nInd] >> 8 ); + char nLowChar = (char)( pStr[nInd] & 0xFF ); + char nChar = nLowChar ? nLowChar : nHighChar; + + for ( int nMatrixInd = 0; nMatrixInd < 7; ++nMatrixInd ) + { + if ( ( nChar & ( 1 << nMatrixInd ) ) != 0 ) + nHighResult = nHighResult ^ pEncryptionMatrix[15 - nLen + nInd][nMatrixInd]; + } + + nLowResult = ( ( ( nLowResult >> 14 ) & 0x0001 ) | ( ( nLowResult << 1 ) & 0x7FFF ) ) ^ nChar; + } + + nLowResult = (sal_uInt16)( ( ( ( nLowResult >> 14 ) & 0x001 ) | ( ( nLowResult << 1 ) & 0x7FF ) ) ^ nLen ^ 0xCE4B ); + + nResult = ( nHighResult << 16 ) | nLowResult; + } + + return nResult; +} + +// ============================================================================ +Sequence< sal_Int8 > DocPasswordHelper::GetWordHashAsSequence( + const ::rtl::OUString& aUString ) +{ + sal_uInt32 nHash = GetWordHashAsUINT32( aUString ); + Sequence< sal_Int8 > aResult( 4 ); + aResult[0] = ( nHash >> 24 ); + aResult[1] = ( ( nHash >> 16 ) & 0xFF ); + aResult[2] = ( ( nHash >> 8 ) & 0xFF ); + aResult[3] = ( nHash & 0xFF ); + + return aResult; +} + +// ============================================================================ +sal_uInt16 DocPasswordHelper::GetXLHashAsUINT16( + const ::rtl::OUString& aUString, + rtl_TextEncoding nEnc ) +{ + sal_uInt16 nResult = 0; + + ::rtl::OString aString = ::rtl::OUStringToOString( aUString, nEnc ); + + if ( aString.getLength() && aString.getLength() <= SAL_MAX_UINT16 ) + { + for ( sal_Int32 nInd = aString.getLength() - 1; nInd >= 0; nInd-- ) + { + nResult = ( ( nResult >> 14 ) & 0x01 ) | ( ( nResult << 1 ) & 0x7FFF ); + nResult ^= aString.getStr()[nInd]; + } + + nResult = ( ( nResult >> 14 ) & 0x01 ) | ( ( nResult << 1 ) & 0x7FFF ); + nResult ^= ( 0x8000 | ( 'N' << 8 ) | 'K' ); + nResult ^= aString.getLength(); + } + + return nResult; +} + +// ============================================================================ +Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence( + const ::rtl::OUString& aUString, + rtl_TextEncoding nEnc ) +{ + sal_uInt16 nHash = GetXLHashAsUINT16( aUString, nEnc ); + Sequence< sal_Int8 > aResult( 2 ); + aResult[0] = ( nHash >> 8 ); + aResult[1] = ( nHash & 0xFF ); + + return aResult; +} + +// ============================================================================ /*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword( IDocPasswordVerifier& rVerifier, diff --git a/comphelper/source/misc/docpasswordrequest.cxx b/comphelper/source/misc/docpasswordrequest.cxx index 9377d6c7c473..17cdb0ae2d92 100644 --- a/comphelper/source/misc/docpasswordrequest.cxx +++ b/comphelper/source/misc/docpasswordrequest.cxx @@ -29,24 +29,26 @@ #include "precompiled_comphelper.hxx" #include "comphelper/docpasswordrequest.hxx" -#include <com/sun/star/task/DocumentMSPasswordRequest.hpp> -#include <com/sun/star/task/DocumentPasswordRequest.hpp> +#include <com/sun/star/task/DocumentMSPasswordRequest2.hpp> +#include <com/sun/star/task/DocumentPasswordRequest2.hpp> #include <com/sun/star/task/XInteractionAbort.hpp> -#include <com/sun/star/task/XInteractionPassword.hpp> +#include <com/sun/star/task/XInteractionPassword2.hpp> using ::rtl::OUString; using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Type; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::XInterface; using ::com::sun::star::task::InteractionClassification_QUERY; -using ::com::sun::star::task::DocumentMSPasswordRequest; -using ::com::sun::star::task::DocumentPasswordRequest; +using ::com::sun::star::task::DocumentMSPasswordRequest2; +using ::com::sun::star::task::DocumentPasswordRequest2; using ::com::sun::star::task::PasswordRequestMode; using ::com::sun::star::task::XInteractionAbort; using ::com::sun::star::task::XInteractionContinuation; -using ::com::sun::star::task::XInteractionPassword; +using ::com::sun::star::task::XInteractionPassword2; +using ::com::sun::star::task::XInteractionRequest; namespace comphelper { @@ -57,52 +59,64 @@ class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort > public: inline explicit AbortContinuation() : mbSelected( false ) {} - inline bool isSelected() const { return mbSelected; } + inline sal_Bool isSelected() const { return mbSelected; } inline void reset() { mbSelected = false; } virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; } private: - bool mbSelected; + sal_Bool mbSelected; }; // ============================================================================ -class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword > +class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword2 > { public: - inline explicit PasswordContinuation() : mbSelected( false ) {} + inline explicit PasswordContinuation() : mbReadOnly( sal_False ), mbSelected( sal_False ) {} - inline bool isSelected() const { return mbSelected; } - inline void reset() { mbSelected = false; } + inline sal_Bool isSelected() const { return mbSelected; } + inline void reset() { mbSelected = sal_False; } + + virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = sal_True; } - virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; } virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException ) { maPassword = rPass; } virtual OUString SAL_CALL getPassword() throw( RuntimeException ) { return maPassword; } + virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) throw( RuntimeException ) { maModifyPassword = rPass; } + virtual OUString SAL_CALL getPasswordToModify() throw( RuntimeException ) { return maModifyPassword; } + + virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) throw( RuntimeException ) { mbReadOnly = bReadOnly; } + virtual sal_Bool SAL_CALL getRecommendReadOnly() throw( RuntimeException ) { return mbReadOnly; } + private: OUString maPassword; - bool mbSelected; + OUString maModifyPassword; + sal_Bool mbReadOnly; + sal_Bool mbSelected; }; // ============================================================================ DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType, - PasswordRequestMode eMode, const OUString& rDocumentName ) + PasswordRequestMode eMode, const OUString& rDocumentName, sal_Bool bPasswordToModify ) +: mpAbort( NULL ) +, mpPassword( NULL ) +, mbPasswordToModify( bPasswordToModify ) { switch( eType ) { case DocPasswordRequestType_STANDARD: { - DocumentPasswordRequest aRequest( OUString(), Reference< XInterface >(), - InteractionClassification_QUERY, eMode, rDocumentName ); + DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(), + InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify ); maRequest <<= aRequest; } break; case DocPasswordRequestType_MS: { - DocumentMSPasswordRequest aRequest( OUString(), Reference< XInterface >(), - InteractionClassification_QUERY, eMode, rDocumentName ); + DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(), + InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify ); maRequest <<= aRequest; } break; @@ -119,12 +133,32 @@ DocPasswordRequest::~DocPasswordRequest() { } -bool DocPasswordRequest::isAbort() const +/*uno::*/Any SAL_CALL DocPasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException) +{ + return ::cppu::queryInterface ( rType, + // OWeakObject interfaces + dynamic_cast< XInterface* > ( (XInteractionRequest *) this ), + static_cast< XWeak* > ( this ), + // my own interfaces + static_cast< XInteractionRequest* > ( this ) ); +} + +void SAL_CALL DocPasswordRequest::acquire( ) throw () +{ + OWeakObject::acquire(); +} + +void SAL_CALL DocPasswordRequest::release( ) throw () +{ + OWeakObject::release(); +} + +sal_Bool DocPasswordRequest::isAbort() const { return mpAbort->isSelected(); } -bool DocPasswordRequest::isPassword() const +sal_Bool DocPasswordRequest::isPassword() const { return mpPassword->isSelected(); } @@ -134,6 +168,16 @@ OUString DocPasswordRequest::getPassword() const return mpPassword->getPassword(); } +OUString DocPasswordRequest::getPasswordToModify() const +{ + return mpPassword->getPasswordToModify(); +} + +sal_Bool DocPasswordRequest::getRecommendReadOnly() const +{ + return mpPassword->getRecommendReadOnly(); +} + Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException ) { return maRequest; diff --git a/comphelper/source/misc/mediadescriptor.cxx b/comphelper/source/misc/mediadescriptor.cxx index 1bc40a454d43..a4f43ecf23db 100644 --- a/comphelper/source/misc/mediadescriptor.cxx +++ b/comphelper/source/misc/mediadescriptor.cxx @@ -1,843 +1,868 @@ -/************************************************************************* - * - * 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_comphelper.hxx" -#include <comphelper/mediadescriptor.hxx> -#include <comphelper/stillreadwriteinteraction.hxx> - -//_______________________________________________ -// includes - -#ifndef __COM_SUN_STAR_UCB_XCONTENT_HPP__ -#include <com/sun/star/ucb/XContent.hpp> -#endif - -#ifndef __COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP__ -#include <com/sun/star/ucb/XCommandEnvironment.hpp> -#endif - -#ifndef __COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP__ -#include <com/sun/star/task/XInteractionHandler.hpp> -#endif - -#ifndef __COM_SUN_STAR_IO_XSTREAM_HPP__ -#include <com/sun/star/io/XStream.hpp> -#endif -#include <com/sun/star/io/XActiveDataSink.hpp> -#include <com/sun/star/io/XSeekable.hpp> - -#ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP__ -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#endif -#include <com/sun/star/lang/IllegalArgumentException.hpp> - -#ifndef __COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP__ -#include <com/sun/star/util/XURLTransformer.hpp> -#endif - -#ifndef __COM_SUN_STAR_UCB_COMMANDFAILEDEXCEPTION_HPP__ -#include <com/sun/star/ucb/CommandFailedException.hpp> -#endif - -#ifndef __COM_SUN_STAR_URI_XURIREFERENCEFACTORY_HPP__ -#include <com/sun/star/uri/XUriReferenceFactory.hpp> -#endif - -#ifndef __COM_SUN_STAR_URI_XURIREFERENCE_HPP__ -#include <com/sun/star/uri/XUriReference.hpp> -#endif -#include <com/sun/star/ucb/PostCommandArgument2.hpp> -#include <com/sun/star/container/XNameAccess.hpp> - -#include <ucbhelper/interceptedinteraction.hxx> -#include <ucbhelper/content.hxx> -#include <ucbhelper/commandenvironment.hxx> -#include <ucbhelper/activedatasink.hxx> -#include <comphelper/processfactory.hxx> -#include <comphelper/configurationhelper.hxx> - -#if OSL_DEBUG_LEVEL>0 - #ifndef _RTL_USTRBUF_HXX_ - #include <rtl/ustrbuf.hxx> - #endif -#endif - -//_______________________________________________ -// namespace - -namespace comphelper{ - -namespace css = ::com::sun::star; - -//_______________________________________________ -// definitions - -/*----------------------------------------------- - 10.03.2004 07:35 ------------------------------------------------*/ -const ::rtl::OUString& MediaDescriptor::PROP_ABORTED() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Aborted")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_ASTEMPLATE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_CHARACTERSET() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("CharacterSet")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_COMPONENTDATA() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ComponentData")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_DEEPDETECTION() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DeepDetection")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_DETECTSERVICE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DetectService")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTSERVICE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentService")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_EXTENSION() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Extension")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_FILENAME() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FileName")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_FILTERNAME() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FilterName")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_FILTEROPTIONS() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FilterOptions")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_FORMAT() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Format")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_FRAME() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Frame")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_FRAMENAME() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FrameName")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_HIDDEN() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Hidden")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_INPUTSTREAM() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("InputStream")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_INTERACTIONHANDLER() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("InteractionHandler")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_JUMPMARK() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("JumpMark")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_MACROEXECUTIONMODE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_MEDIATYPE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("MediaType")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_MINIMIZED() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Minimized")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_NOAUTOSAVE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("NoAutoSave")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_OPENNEWVIEW() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("OpenNewView")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_OUTPUTSTREAM() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("OutputStream")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_PATTERN() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Pattern")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_POSSIZE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PosSize")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_POSTDATA() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PostData")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_POSTSTRING() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PostString")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_PREVIEW() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Preview")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_READONLY() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_REFERRER() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Referer")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_SILENT() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Silent")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_STATUSINDICATOR() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("StatusIndicator")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_STREAM() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Stream")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_STREAMFOROUTPUT() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("StreamForOutput")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_TEMPLATENAME() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TemplateName")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_TEMPLATEREGIONNAME() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TemplateRegionName")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_TYPENAME() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TypeName")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_UCBCONTENT() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("UCBContent")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_UPDATEDOCMODE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("UpdateDocMode")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_URL() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("URL")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_VERSION() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Version")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_VIEWID() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewId")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_REPAIRPACKAGE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("RepairPackage")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTTITLE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentTitle")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_MODEL() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Model")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_PASSWORD() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Password")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_TITLE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Title")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_SALVAGEDFILE() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("SalvagedFile")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_VIEWONLY() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewOnly")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTBASEURL() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentBaseURL")); - return sProp; -} - -const ::rtl::OUString& MediaDescriptor::PROP_VIEWCONTROLLERNAME() -{ - static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewControllerName")); - return sProp; -} -/*----------------------------------------------- - 10.03.2004 08:09 ------------------------------------------------*/ -MediaDescriptor::MediaDescriptor() - : SequenceAsHashMap() -{ -} - -/*----------------------------------------------- - 10.03.2004 08:09 ------------------------------------------------*/ -MediaDescriptor::MediaDescriptor(const css::uno::Any& aSource) - : SequenceAsHashMap(aSource) -{ -} - -/*----------------------------------------------- - 10.03.2004 08:09 ------------------------------------------------*/ -MediaDescriptor::MediaDescriptor(const css::uno::Sequence< css::beans::PropertyValue >& lSource) - : SequenceAsHashMap(lSource) -{ -} - -/*----------------------------------------------- - 10.03.2004 08:09 ------------------------------------------------*/ -MediaDescriptor::MediaDescriptor(const css::uno::Sequence< css::beans::NamedValue >& lSource) - : SequenceAsHashMap(lSource) -{ -} - -/*----------------------------------------------- - 18.11.2004 13:37 ------------------------------------------------*/ -sal_Bool MediaDescriptor::isStreamReadOnly() const -{ - static ::rtl::OUString CONTENTSCHEME_FILE = ::rtl::OUString::createFromAscii("file"); - static ::rtl::OUString CONTENTPROP_ISREADONLY = ::rtl::OUString::createFromAscii("IsReadOnly"); - static sal_Bool READONLY_FALLBACK = sal_False; - - sal_Bool bReadOnly = READONLY_FALLBACK; - - // check for explicit readonly state - const_iterator pIt = find(MediaDescriptor::PROP_READONLY()); - if (pIt != end()) - { - pIt->second >>= bReadOnly; - return bReadOnly; - } - - // streams based on post data are readonly by definition - pIt = find(MediaDescriptor::PROP_POSTDATA()); - if (pIt != end()) - return sal_True; - - // A XStream capsulate XInputStream and XOutputStream ... - // If it exists - the file must be open in read/write mode! - pIt = find(MediaDescriptor::PROP_STREAM()); - if (pIt != end()) - return sal_False; - - // Only file system content provider is able to provide XStream - // so for this content impossibility to create XStream triggers - // switch to readonly mode. - try - { - css::uno::Reference< css::ucb::XContent > xContent = getUnpackedValueOrDefault(MediaDescriptor::PROP_UCBCONTENT(), css::uno::Reference< css::ucb::XContent >()); - if (xContent.is()) - { - css::uno::Reference< css::ucb::XContentIdentifier > xId(xContent->getIdentifier(), css::uno::UNO_QUERY); - ::rtl::OUString aScheme; - if (xId.is()) - aScheme = xId->getContentProviderScheme(); - - if (aScheme.equalsIgnoreAsciiCase(CONTENTSCHEME_FILE)) - bReadOnly = sal_True; - else - { - ::ucbhelper::Content aContent(xContent, css::uno::Reference< css::ucb::XCommandEnvironment >()); - aContent.getPropertyValue(CONTENTPROP_ISREADONLY) >>= bReadOnly; - } - } - } - catch(const css::uno::RuntimeException& exRun) - { throw exRun; } - catch(const css::uno::Exception&) - {} - - return bReadOnly; -} - -/*----------------------------------------------- - 10.03.2004 09:02 ------------------------------------------------*/ -sal_Bool MediaDescriptor::addInputStream() -{ - return impl_addInputStream( sal_True ); -} - -/*-----------------------------------------------*/ -sal_Bool MediaDescriptor::addInputStreamOwnLock() -{ - // Own lock file implementation - - sal_Bool bUseLock = sal_True; // the system file locking is used per default - try - { - - css::uno::Reference< css::uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig( - ::comphelper::getProcessServiceFactory(), - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ), - ::comphelper::ConfigurationHelper::E_STANDARD ); - if ( !xCommonConfig.is() ) - throw css::uno::RuntimeException(); - - ::comphelper::ConfigurationHelper::readRelativeKey( - xCommonConfig, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ), - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentSystemFileLocking" ) ) ) >>= bUseLock; - } - catch( const css::uno::Exception& ) - { - } - - return impl_addInputStream( bUseLock ); -} - -/*-----------------------------------------------*/ -sal_Bool MediaDescriptor::impl_addInputStream( sal_Bool bLockFile ) -{ - // check for an already existing stream item first - const_iterator pIt = find(MediaDescriptor::PROP_INPUTSTREAM()); - if (pIt != end()) - return sal_True; - - try - { - // No stream available - create a new one - // a) data comes as PostData ... - pIt = find(MediaDescriptor::PROP_POSTDATA()); - if (pIt != end()) - { - const css::uno::Any& rPostData = pIt->second; - css::uno::Reference< css::io::XInputStream > xPostData; - rPostData >>= xPostData; - - return impl_openStreamWithPostData( xPostData ); - } - - // b) ... or we must get it from the given URL - ::rtl::OUString sURL = getUnpackedValueOrDefault(MediaDescriptor::PROP_URL(), ::rtl::OUString()); - if (!sURL.getLength()) - throw css::uno::Exception( - ::rtl::OUString::createFromAscii("Found no URL."), - css::uno::Reference< css::uno::XInterface >()); - - // Parse URL! Only the main part has to be used further. E.g. a jumpmark can make trouble - ::rtl::OUString sNormalizedURL = impl_normalizeURL( sURL ); - return impl_openStreamWithURL( sNormalizedURL, bLockFile ); - } -#if OSL_DEBUG_LEVEL>0 - catch(const css::uno::Exception& ex) - { - ::rtl::OUStringBuffer sMsg(256); - sMsg.appendAscii("Invalid MediaDescriptor detected:\n"); - sMsg.append (ex.Message ); - OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr()); - } -#else - catch(const css::uno::Exception&) - {} -#endif - - return sal_False; -} - -/*----------------------------------------------- - 25.03.2004 12:38 ------------------------------------------------*/ -sal_Bool MediaDescriptor::impl_openStreamWithPostData( const css::uno::Reference< css::io::XInputStream >& _rxPostData ) - throw(::com::sun::star::uno::RuntimeException) -{ - if ( !_rxPostData.is() ) - throw css::lang::IllegalArgumentException( - ::rtl::OUString::createFromAscii("Found invalid PostData."), - css::uno::Reference< css::uno::XInterface >(), 1); - - // PostData can't be used in read/write mode! - (*this)[MediaDescriptor::PROP_READONLY()] <<= sal_True; - - // prepare the environment - css::uno::Reference< css::task::XInteractionHandler > xInteraction = getUnpackedValueOrDefault( - MediaDescriptor::PROP_INTERACTIONHANDLER(), - css::uno::Reference< css::task::XInteractionHandler >()); - css::uno::Reference< css::ucb::XProgressHandler > xProgress; - ::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress); - css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY); - - // media type - ::rtl::OUString sMediaType = getUnpackedValueOrDefault(MediaDescriptor::PROP_MEDIATYPE(), ::rtl::OUString()); - if (!sMediaType.getLength()) - { - sMediaType = ::rtl::OUString::createFromAscii("application/x-www-form-urlencoded"); - (*this)[MediaDescriptor::PROP_MEDIATYPE()] <<= sMediaType; - } - - // url - ::rtl::OUString sURL( getUnpackedValueOrDefault( PROP_URL(), ::rtl::OUString() ) ); - - css::uno::Reference< css::io::XInputStream > xResultStream; - try - { - // seek PostData stream to the beginning - css::uno::Reference< css::io::XSeekable > xSeek( _rxPostData, css::uno::UNO_QUERY ); - if ( xSeek.is() ) - xSeek->seek( 0 ); - - // a content for the URL - ::ucbhelper::Content aContent( sURL, xCommandEnv ); - - // use post command - css::ucb::PostCommandArgument2 aPostArgument; - aPostArgument.Source = _rxPostData; - css::uno::Reference< css::io::XActiveDataSink > xSink( new ucbhelper::ActiveDataSink ); - aPostArgument.Sink = xSink; - aPostArgument.MediaType = sMediaType; - aPostArgument.Referer = getUnpackedValueOrDefault( PROP_REFERRER(), ::rtl::OUString() ); - - ::rtl::OUString sCommandName( RTL_CONSTASCII_USTRINGPARAM( "post" ) ); - aContent.executeCommand( sCommandName, css::uno::makeAny( aPostArgument ) ); - - // get result - xResultStream = xSink->getInputStream(); - } - catch( const css::uno::Exception& ) - { - } - - // success? - if ( !xResultStream.is() ) - { - OSL_ENSURE( false, "no valid reply to the HTTP-Post" ); - return sal_False; - } - - (*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xResultStream; - return sal_True; -} - -/*-----------------------------------------------*/ - -/*----------------------------------------------- - 25.03.2004 12:29 ------------------------------------------------*/ -sal_Bool MediaDescriptor::impl_openStreamWithURL( const ::rtl::OUString& sURL, sal_Bool bLockFile ) - throw(::com::sun::star::uno::RuntimeException) -{ - // prepare the environment - css::uno::Reference< css::task::XInteractionHandler > xOrgInteraction = getUnpackedValueOrDefault( - MediaDescriptor::PROP_INTERACTIONHANDLER(), - css::uno::Reference< css::task::XInteractionHandler >()); - - StillReadWriteInteraction* pInteraction = new StillReadWriteInteraction(xOrgInteraction); - css::uno::Reference< css::task::XInteractionHandler > xInteraction(static_cast< css::task::XInteractionHandler* >(pInteraction), css::uno::UNO_QUERY); - - css::uno::Reference< css::ucb::XProgressHandler > xProgress; - ::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress); - css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY); - - // try to create the content - // no content -> no stream => return immediatly with FALSE - ::ucbhelper::Content aContent; - css::uno::Reference< css::ucb::XContent > xContent; - try - { - aContent = ::ucbhelper::Content(sURL, xCommandEnv); - xContent = aContent.get(); - } - catch(const css::uno::RuntimeException&) - { throw; } - catch(const css::ucb::ContentCreationException&) - { return sal_False; } // TODO error handling - catch(const css::uno::Exception&) - { return sal_False; } // TODO error handling - - // try to open the file in read/write mode - // (if its allowed to do so). - // But handle errors in a "hidden mode". Because - // we try it readonly later - if read/write isnt an option. - css::uno::Reference< css::io::XStream > xStream ; - css::uno::Reference< css::io::XInputStream > xInputStream; - - sal_Bool bReadOnly = sal_False; - sal_Bool bModeRequestedExplicitly = sal_False; - const_iterator pIt = find(MediaDescriptor::PROP_READONLY()); - if (pIt != end()) - { - pIt->second >>= bReadOnly; - bModeRequestedExplicitly = sal_True; - } - - if ( !bReadOnly && bLockFile ) - { - try - { - // TODO: use "special" still interaction to supress error messages - xStream = aContent.openWriteableStream(); - if (xStream.is()) - xInputStream = xStream->getInputStream(); - } - catch(const css::uno::RuntimeException&) - { throw; } - catch(const css::uno::Exception&) - { - // ignore exception, if reason was problem reasoned on - // open it in WRITEABLE mode! Then we try it READONLY - // later a second time. - // All other errors must be handled as real error an - // break this method. - if (!pInteraction->wasWriteError() || bModeRequestedExplicitly) - return sal_False; - xStream.clear(); - xInputStream.clear(); - } - } - - // If opening of the stream in read/write mode wasnt allowed - // or failed by an error - we must try it in readonly mode. - if (!xInputStream.is()) - { - rtl::OUString aScheme; - - try - { - css::uno::Reference< css::ucb::XContentIdentifier > xContId( - aContent.get().is() ? aContent.get()->getIdentifier() : 0 ); - - if ( xContId.is() ) - aScheme = xContId->getContentProviderScheme(); - - // Only file system content provider is able to provide XStream - // so for this content impossibility to create XStream triggers - // switch to readonly mode in case of opening with locking on - if( bLockFile && aScheme.equalsIgnoreAsciiCaseAscii( "file" ) ) - bReadOnly = sal_True; - else - { - sal_Bool bRequestReadOnly = bReadOnly; - aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bReadOnly; - if ( bReadOnly && !bRequestReadOnly && bModeRequestedExplicitly ) - return sal_False; // the document is explicitly requested with WRITEABLE mode - } - } - catch(const css::uno::RuntimeException&) - { throw; } - catch(const css::uno::Exception&) - { /* no error handling if IsReadOnly property does not exist for UCP */ } - - if ( bReadOnly ) - (*this)[MediaDescriptor::PROP_READONLY()] <<= bReadOnly; - - pInteraction->resetInterceptions(); - pInteraction->resetErrorStates(); - try - { - // all the contents except file-URLs should be opened as usual - if ( bLockFile || !aScheme.equalsIgnoreAsciiCaseAscii( "file" ) ) - xInputStream = aContent.openStream(); - else - xInputStream = aContent.openStreamNoLock(); - } - catch(const css::uno::RuntimeException&) - { throw; } - catch(const css::uno::Exception&) - { return sal_False; } - } - - // add streams to the descriptor - if (xContent.is()) - (*this)[MediaDescriptor::PROP_UCBCONTENT()] <<= xContent; - if (xStream.is()) - (*this)[MediaDescriptor::PROP_STREAM()] <<= xStream; - if (xInputStream.is()) - (*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xInputStream; - - // At least we need an input stream. The r/w stream is optional ... - return xInputStream.is(); -} - -/*----------------------------------------------- - 10.09.2004 10:51 ------------------------------------------------*/ -::rtl::OUString MediaDescriptor::impl_normalizeURL(const ::rtl::OUString& sURL) -{ - /* Remove Jumpmarks (fragments) of an URL only here. - They are not part of any URL and as a result may be - no ucb content can be created then. - On the other side arguments must exists ... because - they are part of an URL. - - Do not use the URLTransformer service here. Because - it parses the URL in another way. It's main part isnt enough - and it's complete part contains the jumpmark (fragment) parameter ... - */ - static ::rtl::OUString SERVICENAME_URIREFERENCEFACTORY = ::rtl::OUString::createFromAscii("com.sun.star.uri.UriReferenceFactory"); - - try - { - css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); - css::uno::Reference< css::uri::XUriReferenceFactory > xUriFactory(xSMGR->createInstance(SERVICENAME_URIREFERENCEFACTORY), css::uno::UNO_QUERY_THROW); - css::uno::Reference< css::uri::XUriReference > xUriRef = xUriFactory->parse(sURL); - if (xUriRef.is()) - { - xUriRef->clearFragment(); - return xUriRef->getUriReference(); - } - } - catch(const css::uno::RuntimeException& exRun) - { throw exRun; } - catch(const css::uno::Exception&) - {} - - // If an error ocurred ... return the original URL. - // It's a try .-) - return sURL; -} - -} // namespace comphelper - +/*************************************************************************
+ *
+ * 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_comphelper.hxx"
+#include <comphelper/mediadescriptor.hxx>
+#include <comphelper/stillreadwriteinteraction.hxx>
+
+#include <com/sun/star/ucb/XContent.hpp>
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/io/XStream.hpp>
+#include <com/sun/star/io/XActiveDataSink.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/ucb/InteractiveIOException.hpp>
+#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
+#include <com/sun/star/ucb/CommandFailedException.hpp>
+#include <com/sun/star/task/XInteractionAbort.hpp>
+#include <com/sun/star/uri/XUriReferenceFactory.hpp>
+#include <com/sun/star/uri/XUriReference.hpp>
+#include <com/sun/star/ucb/PostCommandArgument2.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+
+#include <ucbhelper/interceptedinteraction.hxx>
+#include <ucbhelper/content.hxx>
+#include <ucbhelper/commandenvironment.hxx>
+#include <ucbhelper/activedatasink.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/configurationhelper.hxx>
+
+#include <rtl/ustrbuf.hxx>
+
+//_______________________________________________
+// namespace
+
+namespace comphelper{
+
+namespace css = ::com::sun::star;
+
+//_______________________________________________
+// definitions
+
+/*-----------------------------------------------
+ 10.03.2004 07:35
+-----------------------------------------------*/
+const ::rtl::OUString& MediaDescriptor::PROP_ABORTED()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Aborted"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_ASTEMPLATE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("AsTemplate"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_CHARACTERSET()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("CharacterSet"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_COMPONENTDATA()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ComponentData"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_DEEPDETECTION()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DeepDetection"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_DETECTSERVICE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DetectService"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTSERVICE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentService"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_EXTENSION()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Extension"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_FILENAME()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FileName"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_FILTERNAME()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FilterName"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_FILTEROPTIONS()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FilterOptions"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_FORMAT()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Format"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_FRAME()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Frame"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_FRAMENAME()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FrameName"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_HIDDEN()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Hidden"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_INPUTSTREAM()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("InputStream"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_INTERACTIONHANDLER()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("InteractionHandler"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_JUMPMARK()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("JumpMark"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_MACROEXECUTIONMODE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_MEDIATYPE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("MediaType"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_MINIMIZED()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Minimized"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_NOAUTOSAVE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("NoAutoSave"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_OPENNEWVIEW()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("OpenNewView"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_OUTPUTSTREAM()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("OutputStream"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_PATTERN()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Pattern"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_POSSIZE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PosSize"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_POSTDATA()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PostData"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_POSTSTRING()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PostString"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_PREVIEW()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Preview"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_READONLY()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ReadOnly"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_REFERRER()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Referer"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_SILENT()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Silent"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_STATUSINDICATOR()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("StatusIndicator"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_STREAM()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Stream"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_STREAMFOROUTPUT()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("StreamForOutput"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_TEMPLATENAME()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TemplateName"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_TEMPLATEREGIONNAME()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TemplateRegionName"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_TYPENAME()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TypeName"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_UCBCONTENT()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("UCBContent"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_UPDATEDOCMODE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("UpdateDocMode"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_URL()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("URL"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_VERSION()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Version"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_VIEWID()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewId"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_REPAIRPACKAGE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("RepairPackage"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTTITLE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentTitle"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_MODEL()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Model"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_PASSWORD()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Password"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_TITLE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Title"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_SALVAGEDFILE()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("SalvagedFile"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_VIEWONLY()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewOnly"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTBASEURL()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentBaseURL"));
+ return sProp;
+}
+
+const ::rtl::OUString& MediaDescriptor::PROP_VIEWCONTROLLERNAME()
+{
+ static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewControllerName"));
+ return sProp;
+}
+/*-----------------------------------------------
+ 10.03.2004 08:09
+-----------------------------------------------*/
+MediaDescriptor::MediaDescriptor()
+ : SequenceAsHashMap()
+{
+}
+
+/*-----------------------------------------------
+ 10.03.2004 08:09
+-----------------------------------------------*/
+MediaDescriptor::MediaDescriptor(const css::uno::Any& aSource)
+ : SequenceAsHashMap(aSource)
+{
+}
+
+/*-----------------------------------------------
+ 10.03.2004 08:09
+-----------------------------------------------*/
+MediaDescriptor::MediaDescriptor(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
+ : SequenceAsHashMap(lSource)
+{
+}
+
+/*-----------------------------------------------
+ 10.03.2004 08:09
+-----------------------------------------------*/
+MediaDescriptor::MediaDescriptor(const css::uno::Sequence< css::beans::NamedValue >& lSource)
+ : SequenceAsHashMap(lSource)
+{
+}
+
+/*-----------------------------------------------
+ 18.11.2004 13:37
+-----------------------------------------------*/
+sal_Bool MediaDescriptor::isStreamReadOnly() const
+{
+ static ::rtl::OUString CONTENTSCHEME_FILE = ::rtl::OUString::createFromAscii("file");
+ static ::rtl::OUString CONTENTPROP_ISREADONLY = ::rtl::OUString::createFromAscii("IsReadOnly");
+ static sal_Bool READONLY_FALLBACK = sal_False;
+
+ sal_Bool bReadOnly = READONLY_FALLBACK;
+
+ // check for explicit readonly state
+ const_iterator pIt = find(MediaDescriptor::PROP_READONLY());
+ if (pIt != end())
+ {
+ pIt->second >>= bReadOnly;
+ return bReadOnly;
+ }
+
+ // streams based on post data are readonly by definition
+ pIt = find(MediaDescriptor::PROP_POSTDATA());
+ if (pIt != end())
+ return sal_True;
+
+ // A XStream capsulate XInputStream and XOutputStream ...
+ // If it exists - the file must be open in read/write mode!
+ pIt = find(MediaDescriptor::PROP_STREAM());
+ if (pIt != end())
+ return sal_False;
+
+ // Only file system content provider is able to provide XStream
+ // so for this content impossibility to create XStream triggers
+ // switch to readonly mode.
+ try
+ {
+ css::uno::Reference< css::ucb::XContent > xContent = getUnpackedValueOrDefault(MediaDescriptor::PROP_UCBCONTENT(), css::uno::Reference< css::ucb::XContent >());
+ if (xContent.is())
+ {
+ css::uno::Reference< css::ucb::XContentIdentifier > xId(xContent->getIdentifier(), css::uno::UNO_QUERY);
+ ::rtl::OUString aScheme;
+ if (xId.is())
+ aScheme = xId->getContentProviderScheme();
+
+ if (aScheme.equalsIgnoreAsciiCase(CONTENTSCHEME_FILE))
+ bReadOnly = sal_True;
+ else
+ {
+ ::ucbhelper::Content aContent(xContent, css::uno::Reference< css::ucb::XCommandEnvironment >());
+ aContent.getPropertyValue(CONTENTPROP_ISREADONLY) >>= bReadOnly;
+ }
+ }
+ }
+ catch(const css::uno::RuntimeException& exRun)
+ { throw exRun; }
+ catch(const css::uno::Exception&)
+ {}
+
+ return bReadOnly;
+}
+
+// ----------------------------------------------------------------------------
+
+css::uno::Any MediaDescriptor::getComponentDataEntry( const ::rtl::OUString& rName ) const
+{
+ SequenceAsHashMap aCompDataMap( getUnpackedValueOrDefault( PROP_COMPONENTDATA(), ComponentDataSequence() ) );
+ SequenceAsHashMap::iterator aIt = aCompDataMap.find( rName );
+ return (aIt == aCompDataMap.end()) ? css::uno::Any() : aIt->second;
+}
+
+void MediaDescriptor::setComponentDataEntry( const ::rtl::OUString& rName, const css::uno::Any& rValue )
+{
+ if( rValue.hasValue() )
+ {
+ // get or craete the 'ComponentData' property entry
+ css::uno::Any& rCompDataAny = operator[]( PROP_COMPONENTDATA() );
+ // check type, insert the value
+ OSL_ENSURE( !rCompDataAny.hasValue() || rCompDataAny.has< ComponentDataSequence >(),
+ "MediaDescriptor::setComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
+ if( !rCompDataAny.hasValue() || rCompDataAny.has< ComponentDataSequence >() )
+ {
+ // insert or overwrite the passed value
+ SequenceAsHashMap aCompDataMap( rCompDataAny );
+ aCompDataMap[ rName ] = rValue;
+ // write back the sequence (sal_False = use NamedValue instead of PropertyValue)
+ rCompDataAny = aCompDataMap.getAsConstAny( sal_False );
+ }
+ }
+ else
+ {
+ // if an empty Any is passed, clear the entry
+ clearComponentDataEntry( rName );
+ }
+}
+
+void MediaDescriptor::clearComponentDataEntry( const ::rtl::OUString& rName )
+{
+ SequenceAsHashMap::iterator aPropertyIter = find( PROP_COMPONENTDATA() );
+ if( aPropertyIter != end() )
+ {
+ OSL_ENSURE( aPropertyIter->second.has< ComponentDataSequence >(),
+ "MediaDescriptor::clearComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
+ if( aPropertyIter->second.has< ComponentDataSequence >() )
+ {
+ // remove the value with the passed name
+ SequenceAsHashMap aCompDataMap( aPropertyIter->second );
+ aCompDataMap.erase( rName );
+ // write back the sequence, or remove it completely if it is empty
+ if( aCompDataMap.empty() )
+ erase( aPropertyIter );
+ else
+ aPropertyIter->second = aCompDataMap.getAsConstAny( sal_False );
+ }
+ }
+}
+
+/*-----------------------------------------------
+ 10.03.2004 09:02
+-----------------------------------------------*/
+sal_Bool MediaDescriptor::addInputStream()
+{
+ return impl_addInputStream( sal_True );
+}
+
+/*-----------------------------------------------*/
+sal_Bool MediaDescriptor::addInputStreamOwnLock()
+{
+ // Own lock file implementation
+
+ sal_Bool bUseLock = sal_True; // the system file locking is used per default
+ try
+ {
+
+ css::uno::Reference< css::uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig(
+ ::comphelper::getProcessServiceFactory(),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
+ ::comphelper::ConfigurationHelper::E_STANDARD );
+ if ( !xCommonConfig.is() )
+ throw css::uno::RuntimeException();
+
+ ::comphelper::ConfigurationHelper::readRelativeKey(
+ xCommonConfig,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentSystemFileLocking" ) ) ) >>= bUseLock;
+ }
+ catch( const css::uno::Exception& )
+ {
+ }
+
+ return impl_addInputStream( bUseLock );
+}
+
+/*-----------------------------------------------*/
+sal_Bool MediaDescriptor::impl_addInputStream( sal_Bool bLockFile )
+{
+ // check for an already existing stream item first
+ const_iterator pIt = find(MediaDescriptor::PROP_INPUTSTREAM());
+ if (pIt != end())
+ return sal_True;
+
+ try
+ {
+ // No stream available - create a new one
+ // a) data comes as PostData ...
+ pIt = find(MediaDescriptor::PROP_POSTDATA());
+ if (pIt != end())
+ {
+ const css::uno::Any& rPostData = pIt->second;
+ css::uno::Reference< css::io::XInputStream > xPostData;
+ rPostData >>= xPostData;
+
+ return impl_openStreamWithPostData( xPostData );
+ }
+
+ // b) ... or we must get it from the given URL
+ ::rtl::OUString sURL = getUnpackedValueOrDefault(MediaDescriptor::PROP_URL(), ::rtl::OUString());
+ if (!sURL.getLength())
+ throw css::uno::Exception(
+ ::rtl::OUString::createFromAscii("Found no URL."),
+ css::uno::Reference< css::uno::XInterface >());
+
+ // Parse URL! Only the main part has to be used further. E.g. a jumpmark can make trouble
+ ::rtl::OUString sNormalizedURL = impl_normalizeURL( sURL );
+ return impl_openStreamWithURL( sNormalizedURL, bLockFile );
+ }
+#if OSL_DEBUG_LEVEL>0
+ catch(const css::uno::Exception& ex)
+ {
+ ::rtl::OUStringBuffer sMsg(256);
+ sMsg.appendAscii("Invalid MediaDescriptor detected:\n");
+ sMsg.append (ex.Message );
+ OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr());
+ }
+#else
+ catch(const css::uno::Exception&)
+ {}
+#endif
+
+ return sal_False;
+}
+
+/*-----------------------------------------------
+ 25.03.2004 12:38
+-----------------------------------------------*/
+sal_Bool MediaDescriptor::impl_openStreamWithPostData( const css::uno::Reference< css::io::XInputStream >& _rxPostData )
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ if ( !_rxPostData.is() )
+ throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii("Found invalid PostData."),
+ css::uno::Reference< css::uno::XInterface >(), 1);
+
+ // PostData can't be used in read/write mode!
+ (*this)[MediaDescriptor::PROP_READONLY()] <<= sal_True;
+
+ // prepare the environment
+ css::uno::Reference< css::task::XInteractionHandler > xInteraction = getUnpackedValueOrDefault(
+ MediaDescriptor::PROP_INTERACTIONHANDLER(),
+ css::uno::Reference< css::task::XInteractionHandler >());
+ css::uno::Reference< css::ucb::XProgressHandler > xProgress;
+ ::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress);
+ css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY);
+
+ // media type
+ ::rtl::OUString sMediaType = getUnpackedValueOrDefault(MediaDescriptor::PROP_MEDIATYPE(), ::rtl::OUString());
+ if (!sMediaType.getLength())
+ {
+ sMediaType = ::rtl::OUString::createFromAscii("application/x-www-form-urlencoded");
+ (*this)[MediaDescriptor::PROP_MEDIATYPE()] <<= sMediaType;
+ }
+
+ // url
+ ::rtl::OUString sURL( getUnpackedValueOrDefault( PROP_URL(), ::rtl::OUString() ) );
+
+ css::uno::Reference< css::io::XInputStream > xResultStream;
+ try
+ {
+ // seek PostData stream to the beginning
+ css::uno::Reference< css::io::XSeekable > xSeek( _rxPostData, css::uno::UNO_QUERY );
+ if ( xSeek.is() )
+ xSeek->seek( 0 );
+
+ // a content for the URL
+ ::ucbhelper::Content aContent( sURL, xCommandEnv );
+
+ // use post command
+ css::ucb::PostCommandArgument2 aPostArgument;
+ aPostArgument.Source = _rxPostData;
+ css::uno::Reference< css::io::XActiveDataSink > xSink( new ucbhelper::ActiveDataSink );
+ aPostArgument.Sink = xSink;
+ aPostArgument.MediaType = sMediaType;
+ aPostArgument.Referer = getUnpackedValueOrDefault( PROP_REFERRER(), ::rtl::OUString() );
+
+ ::rtl::OUString sCommandName( RTL_CONSTASCII_USTRINGPARAM( "post" ) );
+ aContent.executeCommand( sCommandName, css::uno::makeAny( aPostArgument ) );
+
+ // get result
+ xResultStream = xSink->getInputStream();
+ }
+ catch( const css::uno::Exception& )
+ {
+ }
+
+ // success?
+ if ( !xResultStream.is() )
+ {
+ OSL_ENSURE( false, "no valid reply to the HTTP-Post" );
+ return sal_False;
+ }
+
+ (*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xResultStream;
+ return sal_True;
+}
+
+/*-----------------------------------------------*/
+
+/*-----------------------------------------------
+ 25.03.2004 12:29
+-----------------------------------------------*/
+sal_Bool MediaDescriptor::impl_openStreamWithURL( const ::rtl::OUString& sURL, sal_Bool bLockFile )
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ // prepare the environment
+ css::uno::Reference< css::task::XInteractionHandler > xOrgInteraction = getUnpackedValueOrDefault(
+ MediaDescriptor::PROP_INTERACTIONHANDLER(),
+ css::uno::Reference< css::task::XInteractionHandler >());
+
+ StillReadWriteInteraction* pInteraction = new StillReadWriteInteraction(xOrgInteraction);
+ css::uno::Reference< css::task::XInteractionHandler > xInteraction(static_cast< css::task::XInteractionHandler* >(pInteraction), css::uno::UNO_QUERY);
+
+ css::uno::Reference< css::ucb::XProgressHandler > xProgress;
+ ::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress);
+ css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY);
+
+ // try to create the content
+ // no content -> no stream => return immediatly with FALSE
+ ::ucbhelper::Content aContent;
+ css::uno::Reference< css::ucb::XContent > xContent;
+ try
+ {
+ aContent = ::ucbhelper::Content(sURL, xCommandEnv);
+ xContent = aContent.get();
+ }
+ catch(const css::uno::RuntimeException&)
+ { throw; }
+ catch(const css::ucb::ContentCreationException&)
+ { return sal_False; } // TODO error handling
+ catch(const css::uno::Exception&)
+ { return sal_False; } // TODO error handling
+
+ // try to open the file in read/write mode
+ // (if its allowed to do so).
+ // But handle errors in a "hidden mode". Because
+ // we try it readonly later - if read/write isnt an option.
+ css::uno::Reference< css::io::XStream > xStream ;
+ css::uno::Reference< css::io::XInputStream > xInputStream;
+
+ sal_Bool bReadOnly = sal_False;
+ sal_Bool bModeRequestedExplicitly = sal_False;
+ const_iterator pIt = find(MediaDescriptor::PROP_READONLY());
+ if (pIt != end())
+ {
+ pIt->second >>= bReadOnly;
+ bModeRequestedExplicitly = sal_True;
+ }
+
+ if ( !bReadOnly && bLockFile )
+ {
+ try
+ {
+ // TODO: use "special" still interaction to supress error messages
+ xStream = aContent.openWriteableStream();
+ if (xStream.is())
+ xInputStream = xStream->getInputStream();
+ }
+ catch(const css::uno::RuntimeException&)
+ { throw; }
+ catch(const css::uno::Exception&)
+ {
+ // ignore exception, if reason was problem reasoned on
+ // open it in WRITEABLE mode! Then we try it READONLY
+ // later a second time.
+ // All other errors must be handled as real error an
+ // break this method.
+ if (!pInteraction->wasWriteError() || bModeRequestedExplicitly)
+ return sal_False;
+ xStream.clear();
+ xInputStream.clear();
+ }
+ }
+
+ // If opening of the stream in read/write mode wasnt allowed
+ // or failed by an error - we must try it in readonly mode.
+ if (!xInputStream.is())
+ {
+ rtl::OUString aScheme;
+
+ try
+ {
+ css::uno::Reference< css::ucb::XContentIdentifier > xContId(
+ aContent.get().is() ? aContent.get()->getIdentifier() : 0 );
+
+ if ( xContId.is() )
+ aScheme = xContId->getContentProviderScheme();
+
+ // Only file system content provider is able to provide XStream
+ // so for this content impossibility to create XStream triggers
+ // switch to readonly mode in case of opening with locking on
+ if( bLockFile && aScheme.equalsIgnoreAsciiCaseAscii( "file" ) )
+ bReadOnly = sal_True;
+ else
+ {
+ sal_Bool bRequestReadOnly = bReadOnly;
+ aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bReadOnly;
+ if ( bReadOnly && !bRequestReadOnly && bModeRequestedExplicitly )
+ return sal_False; // the document is explicitly requested with WRITEABLE mode
+ }
+ }
+ catch(const css::uno::RuntimeException&)
+ { throw; }
+ catch(const css::uno::Exception&)
+ { /* no error handling if IsReadOnly property does not exist for UCP */ }
+
+ if ( bReadOnly )
+ (*this)[MediaDescriptor::PROP_READONLY()] <<= bReadOnly;
+
+ pInteraction->resetInterceptions();
+ pInteraction->resetErrorStates();
+ try
+ {
+ // all the contents except file-URLs should be opened as usual
+ if ( bLockFile || !aScheme.equalsIgnoreAsciiCaseAscii( "file" ) )
+ xInputStream = aContent.openStream();
+ else
+ xInputStream = aContent.openStreamNoLock();
+ }
+ catch(const css::uno::RuntimeException&)
+ { throw; }
+ catch(const css::uno::Exception&)
+ { return sal_False; }
+ }
+
+ // add streams to the descriptor
+ if (xContent.is())
+ (*this)[MediaDescriptor::PROP_UCBCONTENT()] <<= xContent;
+ if (xStream.is())
+ (*this)[MediaDescriptor::PROP_STREAM()] <<= xStream;
+ if (xInputStream.is())
+ (*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xInputStream;
+
+ // At least we need an input stream. The r/w stream is optional ...
+ return xInputStream.is();
+}
+
+/*-----------------------------------------------
+ 10.09.2004 10:51
+-----------------------------------------------*/
+::rtl::OUString MediaDescriptor::impl_normalizeURL(const ::rtl::OUString& sURL)
+{
+ /* Remove Jumpmarks (fragments) of an URL only here.
+ They are not part of any URL and as a result may be
+ no ucb content can be created then.
+ On the other side arguments must exists ... because
+ they are part of an URL.
+
+ Do not use the URLTransformer service here. Because
+ it parses the URL in another way. It's main part isnt enough
+ and it's complete part contains the jumpmark (fragment) parameter ...
+ */
+ static ::rtl::OUString SERVICENAME_URIREFERENCEFACTORY = ::rtl::OUString::createFromAscii("com.sun.star.uri.UriReferenceFactory");
+
+ try
+ {
+ css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
+ css::uno::Reference< css::uri::XUriReferenceFactory > xUriFactory(xSMGR->createInstance(SERVICENAME_URIREFERENCEFACTORY), css::uno::UNO_QUERY_THROW);
+ css::uno::Reference< css::uri::XUriReference > xUriRef = xUriFactory->parse(sURL);
+ if (xUriRef.is())
+ {
+ xUriRef->clearFragment();
+ return xUriRef->getUriReference();
+ }
+ }
+ catch(const css::uno::RuntimeException& exRun)
+ { throw exRun; }
+ catch(const css::uno::Exception&)
+ {}
+
+ // If an error ocurred ... return the original URL.
+ // It's a try .-)
+ return sURL;
+}
+
+} // namespace comphelper
+
|