diff options
author | Philipp Lohmann <Philipp.Lohmann@Sun.COM> | 2009-10-09 15:11:54 +0200 |
---|---|---|
committer | Philipp Lohmann <Philipp.Lohmann@Sun.COM> | 2009-10-09 15:11:54 +0200 |
commit | 834e45248a6fa97d8b0246c2ce8666ffd9c3cf6b (patch) | |
tree | c1222c6e5899327891b31adc93938b9b49a130ac /comphelper | |
parent | 2589f7adbf0066980b8da68355c2d48369465764 (diff) | |
parent | 9b9d44ee50a38180c2451ca527bf7b9f6f46f0fe (diff) |
merge with m61
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/inc/comphelper/docpasswordhelper.hxx | 212 | ||||
-rw-r--r-- | comphelper/inc/comphelper/docpasswordrequest.hxx | 91 | ||||
-rw-r--r-- | comphelper/inc/comphelper/mediadescriptor.hxx | 2 | ||||
-rw-r--r-- | comphelper/inc/comphelper/stlunosequence.hxx | 482 | ||||
-rw-r--r-- | comphelper/source/misc/docpasswordhelper.cxx | 152 | ||||
-rw-r--r-- | comphelper/source/misc/docpasswordrequest.cxx | 153 | ||||
-rw-r--r-- | comphelper/source/misc/makefile.mk | 2 | ||||
-rw-r--r-- | comphelper/source/misc/mediadescriptor.cxx | 12 | ||||
-rw-r--r-- | comphelper/source/misc/uieventslogger.cxx | 14 | ||||
-rw-r--r-- | comphelper/source/property/genericpropertyset.cxx | 3 |
10 files changed, 675 insertions, 448 deletions
diff --git a/comphelper/inc/comphelper/docpasswordhelper.hxx b/comphelper/inc/comphelper/docpasswordhelper.hxx new file mode 100644 index 000000000000..90927a3e9c6c --- /dev/null +++ b/comphelper/inc/comphelper/docpasswordhelper.hxx @@ -0,0 +1,212 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: docpasswordhelper.hxx,v $ + * $Revision: 1.1 $ + * + * 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 COMPHELPER_DOCPASSWORDHELPR_HXX +#define COMPHELPER_DOCPASSWORDHELPR_HXX + +#include "comphelper/comphelperdllapi.h" +#include <vector> +#include "comphelper/docpasswordrequest.hxx" + +namespace com { namespace sun { namespace star { namespace task { class XInteractionHandler; } } } } + +namespace comphelper { + +class MediaDescriptor; + +// ============================================================================ + +enum DocPasswordVerifierResult +{ + DocPasswordVerifierResult_OK, + DocPasswordVerifierResult_WRONG_PASSWORD, + DocPasswordVerifierResult_ABORT +}; + +// ============================================================================ + +/** Base class for a password verifier used by the DocPasswordHelper class + below. + + Users have to implement the virtual function and pass an instance of the + verifier to one of the password request functions. + */ +class COMPHELPER_DLLPUBLIC IDocPasswordVerifier +{ +public: + virtual ~IDocPasswordVerifier(); + + /** Will be called everytime a password needs to be verified. + + @return The result of the verification. + - DocPasswordVerifierResult_OK, if and only if the passed password + is valid and can be used to process the related document. + - DocPasswordVerifierResult_WRONG_PASSWORD, if the password is + wrong. The user may be asked again for a new password. + - DocPasswordVerifierResult_ABORT, if an unrecoverable error + occured while password verification. The password request loop + will be aborted. + */ + virtual DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword ) = 0; + +}; + +// ============================================================================ + +/** Helper that asks for a document password and checks its validity. + */ +class COMPHELPER_DLLPUBLIC DocPasswordHelper +{ +public: + // ------------------------------------------------------------------------ + + /** This helper function tries to request and verify a password to load a + protected document. + + First, the list of default passwords will be tried if provided. This is + needed by import filters for external file formats that have to check a + predefined password in some cases without asking the user for a + password. Every password is checked using the passed password verifier. + + If not successful, the passed password of a medium is tried, that has + been set e.g. by an API call to load a document. If existing, the + password is checked using the passed password verifier. + + If still not successful, the passed interaction handler is used to + request a password from the user. This will be repeated until the + passed password verifier validates the entered password, or if the user + chooses to cancel password input. + + @param rVerifier + The password verifier used to check every processed password. + + @param rMediaPassword + If not empty, will be passed to the password validator before + requesting a password from the user. This password usually should + be querried from a media descriptor. + + @param rxInteractHandler + The interaction handler that will be used to request a password + from the user, e.g. by showing a password input dialog. + + @param rDocumentName + The name of the related document that will be shown in the password + input dialog. + + @param eRequestType + The password request type that will be passed to the + DocPasswordRequest object created internally. See + docpasswordrequest.hxx for more details. + + @param pDefaultPasswords + If not null, contains default passwords that will be tried before a + password will be requested from the media descriptor or the user. + + @param pbIsDefaultPassword + (output parameter) If not null, the type of the found password will + be returned. True means the password has been found in the passed + list of default passwords. False means the password has been taken + from the rMediaPassword parameter or has been entered by the user. + + @return + If not empty, contains the password that has been validated by the + passed password verifier. If empty, no valid password has been + found, or the user has chossen to cancel password input. + */ + static ::rtl::OUString requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + const ::rtl::OUString& rMediaPassword, + const ::com::sun::star::uno::Reference< + ::com::sun::star::task::XInteractionHandler >& rxInteractHandler, + const ::rtl::OUString& rDocumentName, + DocPasswordRequestType eRequestType, + const ::std::vector< ::rtl::OUString >* pDefaultPasswords = 0, + bool* pbIsDefaultPassword = 0 ); + + // ------------------------------------------------------------------------ + + /** This helper function tries to find a password for the document + described by the passed media descriptor. + + First, the list of default passwords will be tried if provided. This is + needed by import filters for external file formats that have to check a + predefined password in some cases without asking the user for a + password. Every password is checked using the passed password verifier. + + If not successful, the passed media descriptor is asked for a password, + that has been set e.g. by an API call to load a document. If existing, + the password is checked using the passed password verifier. + + If still not successful, the interaction handler contained in the + passed nmedia descriptor is used to request a password from the user. + This will be repeated until the passed password verifier validates the + entered password, or if the user chooses to cancel password input. + + @param rVerifier + The password verifier used to check every processed password. + + @param rMediaDesc + The media descriptor of the document that needs to be opened with + a password. If a valid password (that is not contained in the + passed list of default passwords) was found, it will be inserted + into the "Password" property of this descriptor. + + @param eRequestType + The password request type that will be passed to the + DocPasswordRequest object created internally. See + docpasswordrequest.hxx for more details. + + @param pDefaultPasswords + If not null, contains default passwords that will be tried before a + password will be requested from the media descriptor or the user. + + @return + If not empty, contains the password that has been validated by the + passed password verifier. If empty, no valid password has been + found, or the user has chossen to cancel password input. + */ + static ::rtl::OUString requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + MediaDescriptor& rMediaDesc, + DocPasswordRequestType eRequestType, + const ::std::vector< ::rtl::OUString >* pDefaultPasswords = 0 ); + + // ------------------------------------------------------------------------ + +private: + ~DocPasswordHelper(); +}; + +// ============================================================================ + +} // namespace comphelper + +#endif + diff --git a/comphelper/inc/comphelper/docpasswordrequest.hxx b/comphelper/inc/comphelper/docpasswordrequest.hxx new file mode 100644 index 000000000000..b1e042e876bd --- /dev/null +++ b/comphelper/inc/comphelper/docpasswordrequest.hxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: docpasswordrequest.hxx,v $ + * $Revision: 1.1 $ + * + * 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 COMPHELPER_DOCPASSWORDREQUEST_HXX +#define COMPHELPER_DOCPASSWORDREQUEST_HXX + +#include "comphelper/comphelperdllapi.h" +#include <com/sun/star/task/PasswordRequestMode.hpp> +#include <com/sun/star/task/XInteractionRequest.hpp> +#include <cppuhelper/implbase1.hxx> + +namespace comphelper { + +// ============================================================================ + +/** Selects which UNO document password request type to use. */ +enum DocPasswordRequestType +{ + DocPasswordRequestType_STANDARD, /// Uses the standard com.sun.star.task.DocumentPasswordRequest request. + DocPasswordRequestType_MS /// Uses the com.sun.star.task.DocumentMSPasswordRequest request. +}; + +// ============================================================================ + +class AbortContinuation; +class PasswordContinuation; + +/** Implements the task.XInteractionRequest interface for requesting a password + string for a document. + */ +class COMPHELPER_DLLPUBLIC DocPasswordRequest : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest > +{ +public: + explicit DocPasswordRequest( + DocPasswordRequestType eType, + ::com::sun::star::task::PasswordRequestMode eMode, + const ::rtl::OUString& rDocumentName ); + virtual ~DocPasswordRequest(); + + bool isAbort() const; + bool isPassword() const; + ::rtl::OUString getPassword() const; + +private: + virtual ::com::sun::star::uno::Any SAL_CALL + getRequest() throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > SAL_CALL + getContinuations() throw( ::com::sun::star::uno::RuntimeException ); + +private: + ::com::sun::star::uno::Any maRequest; + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > maContinuations; + AbortContinuation* mpAbort; + PasswordContinuation* mpPassword; +}; + +// ============================================================================ + +} // namespace comphelper + +#endif + diff --git a/comphelper/inc/comphelper/mediadescriptor.hxx b/comphelper/inc/comphelper/mediadescriptor.hxx index 5cd36d2e687b..e388c0b4ca3c 100644 --- a/comphelper/inc/comphelper/mediadescriptor.hxx +++ b/comphelper/inc/comphelper/mediadescriptor.hxx @@ -74,8 +74,10 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap does not work as expected under windows (under unix it works as well) these way must be used :-( */ + static const ::rtl::OUString& PROP_ABORTED(); static const ::rtl::OUString& PROP_ASTEMPLATE(); static const ::rtl::OUString& PROP_CHARACTERSET(); + static const ::rtl::OUString& PROP_COMPONENTDATA(); static const ::rtl::OUString& PROP_DEEPDETECTION(); static const ::rtl::OUString& PROP_DETECTSERVICE(); static const ::rtl::OUString& PROP_DOCUMENTSERVICE(); diff --git a/comphelper/inc/comphelper/stlunosequence.hxx b/comphelper/inc/comphelper/stlunosequence.hxx index a0ace84e8a6e..c9bc525cabd6 100644 --- a/comphelper/inc/comphelper/stlunosequence.hxx +++ b/comphelper/inc/comphelper/stlunosequence.hxx @@ -5,9 +5,9 @@ * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: stlunosequence.hxx,v $ + * $RCSfile: $ * - * $Revision: 1.3 $ + * $Revision: $ * * This file is part of OpenOffice.org. * @@ -31,459 +31,59 @@ #define _COMPHELPER_STLUNOITERATOR_HXX #include <com/sun/star/uno/Sequence.hxx> -#include <iterator> #include <sal/types.h> -namespace comphelper { namespace stlunosequence { - template<typename S, typename V> - class StlSequence; - - template<typename S, typename V> - class StlSequenceIterator : public std::iterator<std::random_access_iterator_tag, V, sal_Int32> - { - public: - typedef ::std::random_access_iterator_tag iterator_category; - typedef V& reference; - typedef V value_type; - typedef sal_Int32 difference_type; - typedef V* pointer; - typedef const V& const_reference; - - StlSequenceIterator(); - StlSequenceIterator(S * uno_sequence, typename StlSequenceIterator<S,V>::difference_type index); - - reference operator*() const; - StlSequenceIterator<S,V>& operator++(); - StlSequenceIterator<S,V> operator++(int); - StlSequenceIterator<S,V>& operator--(); - StlSequenceIterator<S,V> operator--(int); - StlSequenceIterator<S,V>& operator+=(const typename StlSequenceIterator<S,V>::difference_type by); - StlSequenceIterator<S,V>& operator-=(const typename StlSequenceIterator<S,V>::difference_type by); - StlSequenceIterator<S,V> operator+(const typename StlSequenceIterator<S,V>::difference_type by) const; - StlSequenceIterator<S,V> operator-(const typename StlSequenceIterator<S,V>::difference_type by) const; - typename StlSequenceIterator<S,V>::difference_type operator-(const StlSequenceIterator<S,V>& to) const; - - bool operator==(const StlSequenceIterator<S,V>& other) const; - bool operator!=(const StlSequenceIterator<S,V>& other) const; - bool operator<(const StlSequenceIterator<S,V>& other) const; - reference operator[](const typename StlSequenceIterator<S,V>::difference_type by) const; - - - protected: - friend class StlSequence<S,V>; - S * m_UnoSequence; - typename StlSequenceIterator<S,V>::difference_type m_Index; - }; - - template<typename S, typename V> - class StlSequenceConstIterator : public StlSequenceIterator<S,V> - { - public: - typedef const V& reference; - StlSequenceConstIterator(); - StlSequenceConstIterator(S * uno_sequence, typename StlSequenceIterator<S,V>::difference_type by); - typename StlSequenceIterator<S,V>::const_reference operator*() const - { - return (*(this->m_UnoSequence))[this->m_Index]; - } - - typename StlSequenceIterator<S,V>::const_reference operator[](const typename StlSequenceIterator<S,V>::difference_type by) const - { - return (*(this->m_UnoSequence))[this->m_Index+by]; - } - }; - - template<typename S, typename V> - class StlSequence - { - public: - typedef sal_Int32 size_type; - typedef V& reference; - typedef const V& const_reference; - typedef sal_Int32 difference_type; - typedef V value_type; - typedef StlSequenceIterator<S,V> iterator; - typedef StlSequenceConstIterator<S,V> const_iterator; - - StlSequence(S& uno_sequence); - - typename StlSequence<S,V>::size_type size() const; - typename StlSequence<S,V>::size_type max_size() const; - bool empty() const; - void swap(StlSequence<S,V>& other); - typename StlSequence<S,V>::iterator begin(); - typename StlSequence<S,V>::iterator end(); - typename StlSequence<S,V>::const_iterator begin() const; - typename StlSequence<S,V>::const_iterator end() const; - - bool operator==(const StlSequence<S,V>& other) const; - bool operator!=(const StlSequence<S,V>& other) const; - bool operator<(const StlSequence<S,V>& other) const; - bool operator>(const StlSequence<S,V>& other) const; - bool operator<=(const StlSequence<S,V>& other) const; - bool operator>=(const StlSequence<S,V>& other) const; - - - private: - friend class StlSequenceIterator<S,V>; - S * m_UnoSequence; - static const typename StlSequence<S,V>::size_type begin_of_sequence; - static const typename StlSequence<S,V>::size_type end_of_sequence; - }; - - //StlSequenceIterator - template<typename S, typename V> - StlSequenceIterator<S,V>::StlSequenceIterator() - : m_UnoSequence(0), m_Index(StlSequence<S,V>::end_of_sequence) - {} - - template<typename S, typename V> - StlSequenceConstIterator<S,V>::StlSequenceConstIterator() - {} - - template<typename S, typename V> - StlSequenceIterator<S, V>::StlSequenceIterator(S * uno_sequence, typename StlSequenceIterator<S,V>::difference_type index) - : m_UnoSequence(uno_sequence), m_Index(index) - {} - - template<typename S, typename V> - StlSequenceConstIterator<S, V>::StlSequenceConstIterator(S * uno_sequence, typename StlSequenceIterator<S,V>::difference_type index) - : StlSequenceIterator<S,V>(uno_sequence, index) - {} - - template<typename S, typename V> - inline typename StlSequenceIterator<S,V>::reference StlSequenceIterator<S, V>::operator*() const - { - return (*m_UnoSequence)[m_Index]; - } - - template<typename S, typename V> - inline StlSequenceIterator<S,V>& StlSequenceIterator<S, V>::operator++() - { - ++m_Index; - if(m_Index>=m_UnoSequence->getLength()) - m_Index = StlSequence<S,V>::end_of_sequence; - return *this; - } - - template<typename S, typename V> - inline StlSequenceIterator<S,V> StlSequenceIterator<S, V>::operator++(int) - { - StlSequenceIterator<S,V> temp = *this; - ++*this; - return temp; - } - - template<typename S, typename V> - inline StlSequenceIterator<S,V>& StlSequenceIterator<S, V>::operator--() - { - if(m_Index==StlSequence<S,V>::end_of_sequence) - m_Index = m_UnoSequence->getLength(); - --m_Index; - return *this; - } - - template<typename S, typename V> - inline StlSequenceIterator<S,V> StlSequenceIterator<S, V>::operator--(int) - { - StlSequenceIterator<S,V> temp = *this; - --*this; - return temp; - } - - template<typename S, typename V> - inline StlSequenceIterator<S,V>& StlSequenceIterator<S, V>::operator+=(const typename StlSequenceIterator<S,V>::difference_type by) - { - if(by<0) - { - this->operator-=(-by); - return *this; - } - if(by==0) - return *this; - m_Index+=by; - if(m_Index>=m_UnoSequence->getLength()) - m_Index=StlSequence<S,V>::end_of_sequence; - return *this; - } - - template<typename S, typename V> - inline StlSequenceIterator<S,V>& StlSequenceIterator<S, V>::operator-=(const typename StlSequenceIterator<S,V>::difference_type by) - { - if(by<0) - { - if(-by==by) return *this; // breaking infinitive loop on MIN_INT - this->operator+=(-by); - return *this; - } - if(by==0) - return *this; - if(m_Index==StlSequence<S,V>::end_of_sequence) - m_Index=m_UnoSequence->getLength(); - m_Index-=by; - return *this; - } - - template<typename S, typename V> - inline StlSequenceIterator<S,V> StlSequenceIterator<S, V>::operator+(const typename StlSequenceIterator<S,V>::difference_type by) const - { - StlSequenceIterator<S,V> result = StlSequenceIterator<S,V>(*this); - result+=by; - return result; - } - - template<typename S, typename V> - inline StlSequenceIterator<S,V> StlSequenceIterator<S, V>::operator-(const typename StlSequenceIterator<S,V>::difference_type by) const - { - StlSequenceIterator<S,V> result = StlSequenceIterator<S,V>(*this); - result-=by; - return result; - } - - template<typename S, typename V> - inline typename StlSequenceIterator<S,V>::difference_type StlSequenceIterator<S, V>::operator-(const StlSequenceIterator<S,V>& to) const - { - if(m_Index==StlSequence<S,V>::end_of_sequence ^ to.m_Index==StlSequence<S,V>::end_of_sequence) - { - if(m_Index==StlSequence<S,V>::end_of_sequence) - return m_UnoSequence->getLength()-to.m_Index; - else - return m_Index-m_UnoSequence->getLength(); - } - return m_Index-to.m_Index; - } - - template<typename S, typename V> - inline bool StlSequenceIterator<S, V>::operator==(const StlSequenceIterator<S,V>& other) const - { - return (m_Index == other.m_Index); - } - - template<typename S, typename V> - inline bool StlSequenceIterator<S, V>::operator!=(const StlSequenceIterator<S,V>& other) const - { - return !this->operator==(other); - } - - template<typename S, typename V> - inline bool StlSequenceIterator<S, V>::operator<(const StlSequenceIterator<S,V>& other) const - { - if(m_Index==StlSequence<S,V>::end_of_sequence ^ other.m_Index==StlSequence<S,V>::end_of_sequence) - return other.m_Index==StlSequence<S,V>::end_of_sequence; - return m_Index<other.m_Index; - } - - template<typename S, typename V> - inline typename StlSequenceIterator<S,V>::reference StlSequenceIterator<S, V>::operator[](const typename StlSequenceIterator<S,V>::difference_type by) const - { - return (*(this->m_UnoSequence))[this->m_Index+by]; - } - - // StlSequence - template<typename S, typename V> - StlSequence<S,V>::StlSequence(S& uno_sequence) - : m_UnoSequence(&uno_sequence) - {} - - template<typename S, typename V> - inline typename StlSequence<S,V>::size_type StlSequence<S,V>::size() const - { - return m_UnoSequence->getLength(); - } - - template<typename S, typename V> - inline typename StlSequence<S,V>::size_type StlSequence<S,V>::max_size() const - { - return this->size(); - } - - template<typename S, typename V> - inline bool StlSequence<S,V>::empty() const - { - return this->size() == 0; - } - - template<typename S, typename V> - inline void StlSequence<S,V>::swap(StlSequence<S,V>& other) - { - ::std::swap(*this, other); - } - - template<typename S, typename V> - inline typename StlSequence<S,V>::iterator StlSequence<S,V>::begin() - { - return typename StlSequence<S,V>::iterator(m_UnoSequence, - size() ? begin_of_sequence : end_of_sequence); - } - - template<typename S, typename V> - inline typename StlSequence<S,V>::iterator StlSequence<S,V>::end() - { - return typename StlSequence<S,V>::iterator(m_UnoSequence, end_of_sequence); - } - - template<typename S, typename V> - inline typename StlSequence<S,V>::const_iterator StlSequence<S,V>::begin() const - { - return typename StlSequence<S,V>::const_iterator(m_UnoSequence, - size() ? begin_of_sequence : end_of_sequence); - } - - template<typename S, typename V> - inline typename StlSequence<S,V>::const_iterator StlSequence<S,V>::end() const - { - return typename StlSequence<S,V>::const_iterator(m_UnoSequence, end_of_sequence); - } - - template<typename S, typename V> - inline bool StlSequence<S,V>::operator==(const StlSequence<S,V>& other) const - { - if(this->size() != other.size()) return false; - return ::std::equal(this->begin(), this->end(), other.begin()); - } - - template<typename S, typename V> - inline bool StlSequence<S,V>::operator<(const StlSequence<S,V>& other) const - { - return ::std::lexicographical_compare(this->begin(), this->end(), other.begin(), other.end()); - } - - template<typename S, typename V> - inline bool StlSequence<S,V>::operator!=(const StlSequence<S,V>& other) const - { return !(*this == other); } - - template<typename S, typename V> - inline bool StlSequence<S,V>::operator>(const StlSequence<S,V>& other) const - { return (other < *this); } - - template<typename S, typename V> - inline bool StlSequence<S,V>::operator<=(const StlSequence<S,V>& other) const - { return !(other < *this); } - - template<typename S, typename V> - inline bool StlSequence<S,V>::operator>=(const StlSequence<S,V>& other) const - { return !(*this < other); } - - template<typename S, typename V> - const typename StlSequence<S,V>::size_type StlSequence<S,V>::begin_of_sequence = 0; - - template<typename S, typename V> - const typename StlSequence<S,V>::size_type StlSequence<S,V>::end_of_sequence = -1; -}} - namespace comphelper { /** - @short a wrapper-class that provides stl-container-like access to an existing - ::com::sun::star::uno::Sequence - @descr This template class allows using an existing ::com::sun::star::uno::Sequence - like any other stl container. It provides standard-compliant mutable random access - iterators. Because random access iterators are the most generic iterators defined - by the stl, any stl algorithm can be applied to the Sequence. - <p> - This is just a basic stl forward container, but _not_ an stl sequence (the size of the - ::com::sun::star::uno::Sequence cannot be changed using the StlUnoSequence interface). - Inserts are expensive operations on ::com::sun::star::uno::Sequence - use - ::std::copy() to a efficient stl container implementing the stl sequence interface - and the available insert iterator adapters you need those. - <p> - @attention There is one requirement of an stl container that this class does not meet: - It is _not_ owner of its contents and thus it does not destroy its contents when destructed. - @attention No additional boundschecking over the requirements of the STL are performed. - E.g. sequence.begin()-- results in undefined behavior. - @attention StlUnoSequence is not threadsafe. - <p> - Example: (creating a ::std::list from a ::com::sun::star::uno::Sequence) - <code> - ::com::sun::star::uno::Sequence<sal_Int32> uno_seq(10); - ::comphelper::StlUnoSequence<sal_Int32> stl_seq(&uno_seq); - ::std::list stl_list(stl_seq.begin(), stl_seq.end()); - </code> - <p> - Example: (sorting ::com::sun::star::uno::Sequence inplace) - <code> - ::com::sun::star::uno::Sequence<sal_Int32> uno_seq(10); - ::comphelper::StlUnoSequence<sal_Int32> stl_seq(&uno_seq); - ::std::sort(stl_seq.begin(), stl_seq.end()); - </code> - <p> - Example: (counting occurrences of 4711 in a ::com::sun::star::uno::Sequence) - <code> - ::com::sun::star::uno::Sequence<sal_Int32> uno_seq(10); - ::comphelper::StlUnoSequence<sal_Int32> stl_seq(&uno_seq); - sal_Int32 count = 0; - ::std::count(stl_seq.begin(), stl_seq.end(), 4711, count); - </code> - <p> - Example: (inserting the second half of one Sequence after the first element of another) - <code> - ::com::sun::star::uno::Sequence<sal_Int32> uno_seq1(10); - ::com::sun::star::uno::Sequence<sal_Int32> uno_seq2(10); - ::com::sun::star::uno::Sequence<sal_Int32> result(15); - ::comphelper::StlUnoSequence<sal_Int32> stl_seq1(&uno_seq1); - ::comphelper::StlUnoSequence<sal_Int32> stl_seq2(&uno_seq1); - ::comphelper::StlUnoSequence<sal_Int32> stl_result(&result); - ::std::list<sal_Int32> temp(uno_seq1.begin(), uno_seq1.end()); - ::std::copy(uno_seq2.begin()+5, uno_seq2.end(), ::std::insert_iterator< ::std::list<sal_Int32> >(temp, ++temp.begin())); - ::std::copy(temp.begin(), temp.end(), result.begin()); - </code> - - @see http://www.sgi.com/tech/stl/Container.html - @see http://www.sgi.com/tech/stl/Sequence.html - @see http://www.sgi.com/tech/stl/RandomAccessIterator.html + @short stl-container-like access to an existing ::com::sun::star::uno::Sequence + @descr These template functions allows using an existing + ::com::sun::star::uno::Sequence using stl algorithms. They provides + standard-compliant mutable random access iterators. Because random access + iterators are the most generic iterators defined by the stl, any stl algorithm + can be applied to the Sequence (excluding algorithms requiring output + iterators). + <p> + Example: (creating a ::std::list from a ::com::sun::star::uno::Sequence) + <code> + ::com::sun::star::uno::Sequence<sal_Int32> aSeq(10); + ::std::list stl_list(stl_begin(aSeq), stl_end(aSeq)); + </code> + <p> + Example: (sorting ::com::sun::star::uno::Sequence inplace) + <code> + ::com::sun::star::uno::Sequence<sal_Int32> aSeq(10); + ::std::sort(stl_begin(aSeq), stl_seq.end(aSeq)); + </code> + <p> + Example: (counting occurrences of 4711 in a ::com::sun::star::uno::Sequence) + <code> + ::com::sun::star::uno::Sequence<sal_Int32> aSeq(10); + sal_Int32 count = 0; + ::std::count(stl_begin(aSeq), stl_end(aSeq), 4711, count); + </code> + <p> + + @see http://www.sgi.com/tech/stl/Container.html + @see http://www.sgi.com/tech/stl/Sequence.html + @see http://www.sgi.com/tech/stl/RandomAccessIterator.html */ template <typename V> - class StlUnoSequence : public stlunosequence::StlSequence< ::com::sun::star::uno::Sequence<V>, V> - { - public: - /* - @short named constructor (these are needed to keep const-correctness) - */ - static StlUnoSequence<V> createInstance(::com::sun::star::uno::Sequence<V>& uno_sequence) - { return StlUnoSequence<V>(uno_sequence); } - /* - @short named constructor (these are needed to keep const-correctness) - */ - static const StlUnoSequence<V> createInstance(const ::com::sun::star::uno::Sequence<V>& uno_sequence) - { return StlUnoSequence<V>(const_cast< ::com::sun::star::uno::Sequence<V>& >(uno_sequence)); } - private: - StlUnoSequence(::com::sun::star::uno::Sequence<V>& uno_sequence) - : stlunosequence::StlSequence< ::com::sun::star::uno::Sequence<V>, V>(uno_sequence) - {} - }; - - /* - @short shortcut for StlUnoSequence<V>::createInstance(uno_sequence).begin() - */ - template <typename V> - typename StlUnoSequence<V>::iterator stl_begin(::com::sun::star::uno::Sequence<V>& uno_sequence) - { return StlUnoSequence<V>::createInstance(uno_sequence).begin(); } + V* stl_begin(::com::sun::star::uno::Sequence<V>& rSeq) + { return rSeq.getArray(); } - /* - @short shortcut for StlUnoSequence<V>::createInstance(uno_sequence).end() - */ template <typename V> - typename StlUnoSequence<V>::iterator stl_end(::com::sun::star::uno::Sequence<V>& uno_sequence) - { return StlUnoSequence<V>::createInstance(uno_sequence).end(); } + V* stl_end(::com::sun::star::uno::Sequence<V>& rSeq) + { return rSeq.getArray() + rSeq.getLength(); } - /* - @short shortcut for StlUnoSequence<V>::createInstance(uno_sequence).begin() - */ template <typename V> - typename StlUnoSequence<V>::const_iterator stl_begin(const ::com::sun::star::uno::Sequence<V>& uno_sequence) - { - return StlUnoSequence<V>::createInstance(uno_sequence).begin(); - } + const V* stl_begin(const ::com::sun::star::uno::Sequence<V>& rSeq) + { return rSeq.getConstArray(); } - /* - @short shortcut for StlUnoSequence<V>::createInstance(uno_sequence).end() - */ template <typename V> - typename StlUnoSequence<V>::const_iterator stl_end(const ::com::sun::star::uno::Sequence<V>& uno_sequence) - { - return StlUnoSequence<V>::createInstance(uno_sequence).end(); - } + const V* stl_end(const ::com::sun::star::uno::Sequence<V>& rSeq) + { return rSeq.getConstArray() + rSeq.getLength(); } } #endif diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx new file mode 100644 index 000000000000..1f362c02f881 --- /dev/null +++ b/comphelper/source/misc/docpasswordhelper.cxx @@ -0,0 +1,152 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: docpasswordhelper.cxx,v $ + * $Revision: 1.1 $ + * + * 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/docpasswordhelper.hxx" +#include <com/sun/star/task/XInteractionHandler.hpp> +#include "comphelper/mediadescriptor.hxx" + +using ::rtl::OUString; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::UNO_SET_THROW; +using ::com::sun::star::task::PasswordRequestMode; +using ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER; +using ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER; +using ::com::sun::star::task::XInteractionHandler; +using ::com::sun::star::task::XInteractionRequest; + +namespace comphelper { + +// ============================================================================ + +IDocPasswordVerifier::~IDocPasswordVerifier() +{ +} + +// ============================================================================ + +/*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + const OUString& rMediaPassword, + const Reference< XInteractionHandler >& rxInteractHandler, + const OUString& rDocumentName, + DocPasswordRequestType eRequestType, + const ::std::vector< OUString >* pDefaultPasswords, + bool* pbIsDefaultPassword ) +{ + OUString aPassword; + DocPasswordVerifierResult eResult = DocPasswordVerifierResult_WRONG_PASSWORD; + + // first, try provided default passwords + if( pbIsDefaultPassword ) + *pbIsDefaultPassword = false; + if( pDefaultPasswords ) + { + for( ::std::vector< OUString >::const_iterator aIt = pDefaultPasswords->begin(), aEnd = pDefaultPasswords->end(); (eResult == DocPasswordVerifierResult_WRONG_PASSWORD) && (aIt != aEnd); ++aIt ) + { + aPassword = *aIt; + OSL_ENSURE( aPassword.getLength() > 0, "DocPasswordHelper::requestAndVerifyDocPassword - unexpected empty default password" ); + if( aPassword.getLength() > 0 ) + { + eResult = rVerifier.verifyPassword( aPassword ); + if( pbIsDefaultPassword ) + *pbIsDefaultPassword = eResult == DocPasswordVerifierResult_OK; + } + } + } + + // try media password (skip, if result is OK or ABORT) + if( eResult == DocPasswordVerifierResult_WRONG_PASSWORD ) + { + aPassword = rMediaPassword; + if( aPassword.getLength() > 0 ) + eResult = rVerifier.verifyPassword( aPassword ); + } + + // request a password (skip, if result is OK or ABORT) + if( (eResult == DocPasswordVerifierResult_WRONG_PASSWORD) && rxInteractHandler.is() ) try + { + PasswordRequestMode eRequestMode = PasswordRequestMode_PASSWORD_ENTER; + while( eResult == DocPasswordVerifierResult_WRONG_PASSWORD ) + { + DocPasswordRequest* pRequest = new DocPasswordRequest( eRequestType, eRequestMode, rDocumentName ); + Reference< XInteractionRequest > xRequest( pRequest ); + rxInteractHandler->handle( xRequest ); + if( pRequest->isPassword() ) + { + aPassword = pRequest->getPassword(); + if( aPassword.getLength() > 0 ) + eResult = rVerifier.verifyPassword( aPassword ); + } + else + { + eResult = DocPasswordVerifierResult_ABORT; + } + eRequestMode = PasswordRequestMode_PASSWORD_REENTER; + } + } + catch( Exception& ) + { + } + + return (eResult == DocPasswordVerifierResult_OK) ? aPassword : OUString(); +} + +/*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + MediaDescriptor& rMediaDesc, + DocPasswordRequestType eRequestType, + const ::std::vector< OUString >* pDefaultPasswords ) +{ + OUString aMediaPassword = rMediaDesc.getUnpackedValueOrDefault( + MediaDescriptor::PROP_PASSWORD(), OUString() ); + Reference< XInteractionHandler > xInteractHandler = rMediaDesc.getUnpackedValueOrDefault( + MediaDescriptor::PROP_INTERACTIONHANDLER(), Reference< XInteractionHandler >() ); + OUString aDocumentName = rMediaDesc.getUnpackedValueOrDefault( + MediaDescriptor::PROP_URL(), OUString() ); + + bool bIsDefaultPassword = false; + OUString aPassword = requestAndVerifyDocPassword( + rVerifier, aMediaPassword, xInteractHandler, aDocumentName, eRequestType, pDefaultPasswords, &bIsDefaultPassword ); + + // insert valid password into media descriptor (but not a default password) + if( (aPassword.getLength() > 0) && !bIsDefaultPassword ) + rMediaDesc[ MediaDescriptor::PROP_PASSWORD() ] <<= aPassword; + + return aPassword; +} + +// ============================================================================ + +} // namespace comphelper + diff --git a/comphelper/source/misc/docpasswordrequest.cxx b/comphelper/source/misc/docpasswordrequest.cxx new file mode 100644 index 000000000000..187642e10fe9 --- /dev/null +++ b/comphelper/source/misc/docpasswordrequest.cxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: docpasswordrequest.cxx,v $ + * $Revision: 1.1 $ + * + * 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/docpasswordrequest.hxx" +#include <com/sun/star/task/DocumentMSPasswordRequest.hpp> +#include <com/sun/star/task/DocumentPasswordRequest.hpp> +#include <com/sun/star/task/XInteractionAbort.hpp> +#include <com/sun/star/task/XInteractionPassword.hpp> + +using ::rtl::OUString; +using ::com::sun::star::uno::Any; +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::PasswordRequestMode; +using ::com::sun::star::task::XInteractionAbort; +using ::com::sun::star::task::XInteractionContinuation; +using ::com::sun::star::task::XInteractionPassword; + +namespace comphelper { + +// ============================================================================ + +class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort > +{ +public: + inline explicit AbortContinuation() : mbSelected( false ) {} + + inline bool isSelected() const { return mbSelected; } + inline void reset() { mbSelected = false; } + + virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; } + +private: + bool mbSelected; +}; + +// ============================================================================ + +class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword > +{ +public: + inline explicit PasswordContinuation() : mbSelected( false ) {} + + inline bool isSelected() const { return mbSelected; } + inline void reset() { mbSelected = false; } + + 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; } + +private: + OUString maPassword; + bool mbSelected; +}; + +// ============================================================================ + +DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType, + PasswordRequestMode eMode, const OUString& rDocumentName ) +{ + switch( eType ) + { + case DocPasswordRequestType_STANDARD: + { + DocumentPasswordRequest aRequest( OUString(), Reference< XInterface >(), + InteractionClassification_QUERY, eMode, rDocumentName ); + maRequest <<= aRequest; + } + break; + case DocPasswordRequestType_MS: + { + DocumentMSPasswordRequest aRequest( OUString(), Reference< XInterface >(), + InteractionClassification_QUERY, eMode, rDocumentName ); + maRequest <<= aRequest; + } + break; + /* no 'default', so compilers will complain about missing + implementation of a new enum value. */ + } + + maContinuations.realloc( 2 ); + maContinuations[ 0 ].set( mpAbort = new AbortContinuation ); + maContinuations[ 1 ].set( mpPassword = new PasswordContinuation ); +} + +DocPasswordRequest::~DocPasswordRequest() +{ +} + +bool DocPasswordRequest::isAbort() const +{ + return mpAbort->isSelected(); +} + +bool DocPasswordRequest::isPassword() const +{ + return mpPassword->isSelected(); +} + +OUString DocPasswordRequest::getPassword() const +{ + return mpPassword->getPassword(); +} + +Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException ) +{ + return maRequest; +} + +Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations() throw( RuntimeException ) +{ + return maContinuations; +} + +// ============================================================================ + +} // namespace comphelper + diff --git a/comphelper/source/misc/makefile.mk b/comphelper/source/misc/makefile.mk index f50f57c47eb3..d0ffc368fd20 100644 --- a/comphelper/source/misc/makefile.mk +++ b/comphelper/source/misc/makefile.mk @@ -57,6 +57,8 @@ SLOFILES= \ $(SLO)$/componentcontext.obj \ $(SLO)$/componentmodule.obj \ $(SLO)$/configurationhelper.obj \ + $(SLO)$/docpasswordhelper.obj \ + $(SLO)$/docpasswordrequest.obj \ $(SLO)$/documentinfo.obj \ $(SLO)$/documentiologring.obj \ $(SLO)$/evtlistenerhlp.obj \ diff --git a/comphelper/source/misc/mediadescriptor.cxx b/comphelper/source/misc/mediadescriptor.cxx index 9f463cdf0380..44578f840da9 100644 --- a/comphelper/source/misc/mediadescriptor.cxx +++ b/comphelper/source/misc/mediadescriptor.cxx @@ -114,6 +114,12 @@ namespace css = ::com::sun::star; /*----------------------------------------------- 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")); @@ -126,6 +132,12 @@ const ::rtl::OUString& MediaDescriptor::PROP_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")); diff --git a/comphelper/source/misc/uieventslogger.cxx b/comphelper/source/misc/uieventslogger.cxx index a55d5b58854d..ae351340bc7a 100644 --- a/comphelper/source/misc/uieventslogger.cxx +++ b/comphelper/source/misc/uieventslogger.cxx @@ -218,11 +218,15 @@ namespace comphelper // public UiEventsLogger interface sal_Bool UiEventsLogger::isEnabled() { - try { - UiEventsLogger_Impl::prepareMutex(); - Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex); - return UiEventsLogger_Impl::getInstance()->m_Active; - } catch(...) { return false; } // never throws + if ( UiEventsLogger_Impl::getEnabledFromCfg() ) + { + try { + UiEventsLogger_Impl::prepareMutex(); + Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex); + return UiEventsLogger_Impl::getInstance()->m_Active; + } catch(...) { return false; } // never throws + } // if ( ) + return sal_False; } sal_Int32 UiEventsLogger::getSessionLogEventCount() diff --git a/comphelper/source/property/genericpropertyset.cxx b/comphelper/source/property/genericpropertyset.cxx index 08dd26dcf0ec..19911709860d 100644 --- a/comphelper/source/property/genericpropertyset.cxx +++ b/comphelper/source/property/genericpropertyset.cxx @@ -180,8 +180,7 @@ void GenericPropertySet::_setPropertyValues( const PropertyMapEntry** ppEntries, aEvt.PropertyName = aPropertyName; aEvt.NewValue = *pValues; aGuard.clear(); - pHelper->forEach<XPropertyChangeListener>( - ::boost::bind(&XPropertyChangeListener::propertyChange,_1,boost::cref(aEvt))); + pHelper->notifyEach( &XPropertyChangeListener::propertyChange, aEvt ); aGuard.reset(); } |