LCOV - code coverage report
Current view: top level - include/unotools - mediadescriptor.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 1 100.0 %
Date: 2014-04-11 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_UNOTOOLS_MEDIADESCRIPTOR_HXX
      21             : #define INCLUDED_UNOTOOLS_MEDIADESCRIPTOR_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : 
      25             : #include <vector>
      26             : 
      27             : #include <comphelper/docpasswordrequest.hxx>
      28             : #include <comphelper/sequenceashashmap.hxx>
      29             : #include <rtl/ustring.hxx>
      30             : #include <unotools/unotoolsdllapi.h>
      31             : 
      32             : namespace com { namespace sun { namespace star { namespace io {
      33             :     class XInputStream;
      34             : } } } }
      35             : namespace comphelper { class IDocPasswordVerifier; }
      36             : 
      37             : namespace utl {
      38             : 
      39             : /** @short  can be used to work with a ::com::sun::star::document::MediaDescriptor
      40             :             struct.
      41             : 
      42             :     @descr  It wraps a ::boost::unordered_map around the Sequence< css::beans::PropertyValue >, which
      43             :             represent the MediaDescriptor item.
      44             :             Further this helper defines often used functions (as e.g. open of the required streams,
      45             :             consistent checks etcpp.) and it defines all useable property names.
      46             : 
      47             :     @attention  This class isnt threadsafe and must be guarded from outside!
      48             :  */
      49       29102 : class UNOTOOLS_DLLPUBLIC MediaDescriptor : public comphelper::SequenceAsHashMap
      50             : {
      51             :     public:
      52             : 
      53             :         /** @short  these methods can be used to get the different property names
      54             :                     as static const OUString values.
      55             : 
      56             :             @descr  Because definition and declaration of static const class members
      57             :                     does not work as expected under windows (under unix it works as well)
      58             :                     these way must be used :-(
      59             :           */
      60             :         static const OUString& PROP_ABORTED();
      61             :         static const OUString& PROP_ASTEMPLATE();
      62             :         static const OUString& PROP_COMPONENTDATA();
      63             :         static const OUString& PROP_DOCUMENTSERVICE();
      64             :         static const OUString& PROP_ENCRYPTIONDATA();
      65             :         static const OUString& PROP_FILENAME();
      66             :         static const OUString& PROP_FILTERNAME();
      67             :         static const OUString& PROP_FILTERPROVIDER();
      68             :         static const OUString& PROP_FILTEROPTIONS();
      69             :         static const OUString& PROP_FRAME();
      70             :         static const OUString& PROP_FRAMENAME();
      71             :         static const OUString& PROP_HIDDEN();
      72             :         static const OUString& PROP_INPUTSTREAM();
      73             :         static const OUString& PROP_INTERACTIONHANDLER();
      74             :         static const OUString& PROP_JUMPMARK();
      75             :         static const OUString& PROP_MACROEXECUTIONMODE();
      76             :         static const OUString& PROP_MEDIATYPE();
      77             :         static const OUString& PROP_MINIMIZED();
      78             :         static const OUString& PROP_NOAUTOSAVE();
      79             :         static const OUString& PROP_OPENNEWVIEW();
      80             :         static const OUString& PROP_OUTPUTSTREAM();
      81             :         static const OUString& PROP_PASSWORD();
      82             :         static const OUString& PROP_POSTDATA();
      83             :         static const OUString& PROP_PREVIEW();
      84             :         static const OUString& PROP_READONLY();
      85             :         static const OUString& PROP_REFERRER();
      86             :         static const OUString& PROP_SALVAGEDFILE();
      87             :         static const OUString& PROP_STATUSINDICATOR();
      88             :         static const OUString& PROP_STREAM();
      89             :         static const OUString& PROP_STREAMFOROUTPUT();
      90             :         static const OUString& PROP_TEMPLATENAME();
      91             :         static const OUString& PROP_TITLE();
      92             :         static const OUString& PROP_TYPENAME();
      93             :         static const OUString& PROP_UCBCONTENT();
      94             :         static const OUString& PROP_UPDATEDOCMODE();
      95             :         static const OUString& PROP_URL();
      96             :         static const OUString& PROP_VERSION();
      97             :         static const OUString& PROP_DOCUMENTTITLE();
      98             :         static const OUString& PROP_MODEL();
      99             :         static const OUString& PROP_VIEWONLY();
     100             :         static const OUString& PROP_DOCUMENTBASEURL();
     101             : 
     102             :     // interface
     103             :     public:
     104             : 
     105             :         /** @short  these ctors do nothing - excepting that they forward
     106             :                     the given parameters to the base class ctors.
     107             : 
     108             :             @descr  The ctros must be overwritten to resolve conflicts with
     109             :                     the default ctors of the compiler :-(.
     110             :          */
     111             :         MediaDescriptor();
     112             :         MediaDescriptor(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lSource);
     113             : 
     114             :         /** @short  it checks if the descriptor already has a valid
     115             :                     InputStream item and creates a new one, if not.
     116             : 
     117             :             @descr  This method uses the current items of this MediaDescriptor,
     118             :                     to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
     119             :                     It creates a seekable stream and put it into the descriptor.
     120             : 
     121             :                     A might existing InteractionHandler will be used automaticly,
     122             :                     to solve problems!
     123             : 
     124             :                     In case of local file the system file locking is used.
     125             : 
     126             :             @return TRUE, if the stream was already part of the descriptor or could
     127             :                     be created as new item. FALSE otherwise.
     128             :          */
     129             :         bool addInputStream();
     130             : 
     131             :         /** @short  it checks if the descriptor already has a valid
     132             :                     InputStream item and creates a new one, if not.
     133             : 
     134             :             @descr  This method uses the current items of this MediaDescriptor,
     135             :                     to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
     136             :                     It creates a seekable stream and put it into the descriptor.
     137             : 
     138             :                     A might existing InteractionHandler will be used automaticly,
     139             :                     to solve problems!
     140             : 
     141             :                     In case of local file the system file locking is used based on
     142             :                     configuration settings.
     143             : 
     144             :             @return TRUE, if the stream was already part of the descriptor or could
     145             :                     be created as new item. FALSE otherwise.
     146             :          */
     147             :         bool addInputStreamOwnLock();
     148             : 
     149             :         /** @short  it checks if the descriptor describes a readonly stream.
     150             : 
     151             :             @descr  The descriptor itself isnt changed doing so.
     152             :                     It's only checked if the stream seems to be based
     153             :                     of a real readonly file.
     154             : 
     155             :             @Attention
     156             :                     We dont check the property "ReadOnly" here. Because
     157             :                     this property can be set from outside and overwrites
     158             :                     the readonly state of  the stream.
     159             :                     If e.g. the stream could be opened read/write ...
     160             :                     but "ReadOnly" property is set to TRUE, this means:
     161             :                     show a readonly UI on top of this read/write stream.
     162             : 
     163             :             @return TRUE, if the stream must be interpreted as readonly ...
     164             :                     FALSE otherwise.
     165             :          */
     166             :         bool isStreamReadOnly() const;
     167             : 
     168             :         /** Returns a value from the sequence contained in the property
     169             :             'ComponentData' of this media descriptor.
     170             : 
     171             :             @descr  The property 'ComponentData' should be empty, or should
     172             :                 contain a value of type sequence<com.sun.star.beans.NamedValue>
     173             :                 or sequence<com.sun.star.beans.PropertyValue>.
     174             : 
     175             :             @return  The value with the specified name, if existing in the
     176             :                 sequence of the 'ComponentData' property, otherwise an empty
     177             :                 Any.
     178             :          */
     179             :         ::com::sun::star::uno::Any getComponentDataEntry(
     180             :             const OUString& rName ) const;
     181             : 
     182             :         /** Inserts a value into the sequence contained in the property
     183             :             'ComponentData' of the media descriptor.
     184             : 
     185             :             @descr  The property 'ComponentData' should be empty, or should
     186             :                 contain a value of type sequence<com.sun.star.beans.NamedValue>
     187             :                 or sequence<com.sun.star.beans.PropertyValue>. The passed value
     188             :                 will be inserted into the sequence, or, if already existing,
     189             :                 will be overwritten.
     190             : 
     191             :             @param rName  The name of the value to be inserted into the
     192             :                 sequence of the 'ComponentData' property.
     193             : 
     194             :             @param rValue  The value to be inserted into the sequence of the
     195             :                 'ComponentData' property.
     196             :          */
     197             :         void setComponentDataEntry(
     198             :             const OUString& rName,
     199             :             const ::com::sun::star::uno::Any& rValue );
     200             : 
     201             :         /** Removes a value from the sequence contained in the property
     202             :             'ComponentData' of the media descriptor.
     203             : 
     204             :             @descr  The property 'ComponentData' should be empty, or should
     205             :                 contain a value of type sequence<com.sun.star.beans.NamedValue>
     206             :                 or sequence<com.sun.star.beans.PropertyValue>. The value with
     207             :                 the passed name will be removed from the sequence, if existing.
     208             : 
     209             :             @param rName  The name of the value to be removed from the sequence
     210             :                 of the 'ComponentData' property.
     211             :          */
     212             :         void clearComponentDataEntry(
     213             :             const OUString& rName );
     214             : 
     215             :         /** This helper function tries to find a password for the document
     216             :             described by this media descriptor.
     217             : 
     218             :             First, the list of default passwords will be tried if provided. This
     219             :             is needed by import filters for external file formats that have to
     220             :             check a predefined password in some cases without asking the user
     221             :             for a password. Every password is checked using the passed password
     222             :             verifier.
     223             : 
     224             :             If not successful, this media descriptor is asked for a password,
     225             :             that has been set e.g. by an API call to load a document. If
     226             :             existing, the password is checked using the passed password
     227             :             verifier.
     228             : 
     229             :             If still not successful, the interaction handler contained in this
     230             :             media descriptor is used to request a password from the user. This
     231             :             will be repeated until the passed password verifier validates the
     232             :             entered password, or if the user chooses to cancel password input.
     233             : 
     234             :             If a valid password (that is not contained in the passed list of
     235             :             default passwords) was found, it will be inserted into the
     236             :             "Password" property of this descriptor.
     237             : 
     238             :             @param rVerifier
     239             :             The password verifier used to check every processed password.
     240             : 
     241             :             @param eRequestType
     242             :             The password request type that will be passed to the
     243             :             DocPasswordRequest object created internally. See
     244             :             docpasswordrequest.hxx for more details.
     245             : 
     246             :             @param pDefaultPasswords
     247             :             If not null, contains default passwords that will be tried before a
     248             :             password will be requested from the media descriptor or the user.
     249             : 
     250             :             @return
     251             :             If not empty, contains the password that has been validated by the
     252             :             passed password verifier. If empty, no valid password has been
     253             :             found, or the user has chossen to cancel password input.
     254             :         */
     255             :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestAndVerifyDocPassword(
     256             :             comphelper::IDocPasswordVerifier& rVerifier,
     257             :             comphelper::DocPasswordRequestType eRequestType,
     258             :             const ::std::vector< OUString >* pDefaultPasswords = 0 );
     259             : 
     260             :     // helper
     261             :     private:
     262             : 
     263             :         /** @short  tries to open a stream by using the given PostData stream.
     264             : 
     265             :             @descr  The stream is used directly ...
     266             : 
     267             :                     The MediaDescriptor itself is changed inside this method.
     268             :                     Means: the stream is added internal and not returned by a value.
     269             : 
     270             :             @param  _rxPostData
     271             :                     the PostData stream.
     272             : 
     273             :             @return TRUE if the stream could be added successfully.
     274             :                     Note: If FALSE is returned, the error was already handled inside!
     275             : 
     276             :             @throw  [css::uno::RuntimeException]
     277             :                     if the MediaDescriptor seems to be invalid!
     278             : 
     279             :             @throw  [css::lang::IllegalArgumentException]
     280             :                     if the given PostData stream is <NULL/>.
     281             :          */
     282             :         SAL_DLLPRIVATE bool impl_openStreamWithPostData(
     283             :             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& _rxPostData
     284             :             )   throw(::com::sun::star::uno::RuntimeException);
     285             : 
     286             :         /** @short  tries to open a stream by using the given URL.
     287             : 
     288             :             @descr  First it tries to open the content in r/w mode (if its
     289             :                     allowed to do so). Only in case its not allowed or it failed
     290             :                     the stream will be tried to open in readonly mode.
     291             : 
     292             :                     The MediaDescriptor itself is changed inside this method.
     293             :                     Means: the stream is added internal and not returned by a value.
     294             : 
     295             :             @param  sURL
     296             :                     the URL for open.
     297             : 
     298             :             @param  bLockFile
     299             :                     specifies whether the file should be locked
     300             : 
     301             :             @return TRUE if the stream could be added successfully.
     302             :                     Note: If FALSE is returned, the error was already handled inside!
     303             : 
     304             :             @throw  [css::uno::RuntimeException]
     305             :                     if the MediaDescriptor seems to be invalid!
     306             :          */
     307             :         SAL_DLLPRIVATE bool impl_openStreamWithURL(
     308             :             const OUString& sURL,
     309             :             bool bLockFile
     310             :             ) throw(::com::sun::star::uno::RuntimeException);
     311             : 
     312             :         /** @short  it checks if the descriptor already has a valid
     313             :                     InputStream item and creates a new one, if not.
     314             : 
     315             :             @descr  This method uses the current items of this MediaDescriptor,
     316             :                     to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
     317             :                     It creates a seekable stream and put it into the descriptor.
     318             : 
     319             :                     A might existing InteractionHandler will be used automaticly,
     320             :                     to solve problems!
     321             : 
     322             :             @param  bLockFile
     323             :                     specifies whether the file should be locked
     324             : 
     325             :             @return TRUE, if the stream was already part of the descriptor or could
     326             :                     be created as new item. FALSE otherwise.
     327             :          */
     328             :         SAL_DLLPRIVATE bool impl_addInputStream( bool bLockFile );
     329             : };
     330             : 
     331             : }
     332             : 
     333             : #endif
     334             : 
     335             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10