LCOV - code coverage report
Current view: top level - sfx2/source/doc - objuno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 239 614 38.9 %
Date: 2012-08-25 Functions: 35 69 50.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 262 1461 17.9 %

           Branch data     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                 :            : 
      21                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      22                 :            : #include <com/sun/star/util/DateTime.hpp>
      23                 :            : #include <com/sun/star/util/Date.hpp>
      24                 :            : #include <com/sun/star/util/Time.hpp>
      25                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      26                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      27                 :            : #include <com/sun/star/beans/StringPair.hpp>
      28                 :            : #include <com/sun/star/embed/ElementModes.hpp>
      29                 :            : #include <com/sun/star/xml/sax/XParser.hpp>
      30                 :            : #include <com/sun/star/document/XImporter.hpp>
      31                 :            : #include <com/sun/star/document/XExporter.hpp>
      32                 :            : #include <com/sun/star/io/XActiveDataSource.hpp>
      33                 :            : #include <com/sun/star/document/XFilter.hpp>
      34                 :            : #include <com/sun/star/embed/XTransactedObject.hpp>
      35                 :            : #include <com/sun/star/lang/Locale.hpp>
      36                 :            : #include <com/sun/star/util/XModifiable.hpp>
      37                 :            : #include <com/sun/star/document/XDocumentProperties.hpp>
      38                 :            : #include <com/sun/star/document/XCompatWriterDocProperties.hpp>
      39                 :            : 
      40                 :            : #include <unotools/configmgr.hxx>
      41                 :            : #include <unotools/bootstrap.hxx>
      42                 :            : #include <cppuhelper/interfacecontainer.hxx>
      43                 :            : #include <osl/mutex.hxx>
      44                 :            : #include <rtl/ustrbuf.hxx>
      45                 :            : #include <vcl/svapp.hxx>
      46                 :            : 
      47                 :            : #include <tools/errcode.hxx>
      48                 :            : #include <svl/cntwids.hrc>
      49                 :            : #include <comphelper/string.hxx>
      50                 :            : #include <comphelper/sequenceasvector.hxx>
      51                 :            : #include <comphelper/storagehelper.hxx>
      52                 :            : #include <sot/storage.hxx>
      53                 :            : 
      54                 :            : #include <sfx2/objuno.hxx>
      55                 :            : #include <sfx2/sfx.hrc>
      56                 :            : 
      57                 :            : #include <vector>
      58                 :            : #include <algorithm>
      59                 :            : 
      60                 :            : #include "sfx2/sfxresid.hxx"
      61                 :            : #include "doc.hrc"
      62                 :            : 
      63                 :            : using namespace ::com::sun::star;
      64                 :            : 
      65                 :            : // TODO/REFACTOR: provide service for MS formats
      66                 :            : // TODO/REFACTOR: IsEncrypted is never set nor read
      67                 :            : // Generator is not saved ATM; which value?!
      68                 :            : // Generator handling must be implemented
      69                 :            : // Deprecate "Theme", rework IDL
      70                 :            : // AutoLoadEnabled is deprecated?!
      71                 :            : // Reasonable defaults for DateTime
      72                 :            : // MIMEType readonly?!
      73                 :            : // Announce changes about Theme, Language, Generator, removed entries etc.
      74                 :            : // IsEncrypted is necessary for binary formats!
      75                 :            : // Open: When to call PrepareDocInfoForSave? Currently only called for own formats and HTML/Writer
      76                 :            : // Open: How to load and save EditingTime to MS formats
      77                 :            : // PPT-Export should use SavePropertySet
      78                 :            : 
      79                 :            : //=============================================================================
      80                 :            : 
      81                 :            : // The number of user defined fields handled by the evil XDocumentInfo
      82                 :            : // interface. There are exactly 4. No more, no less.
      83                 :            : #define FOUR 4
      84                 :            : 
      85                 :            : #define PROPERTY_UNBOUND 0
      86                 :            : #define PROPERTY_MAYBEVOID ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
      87                 :            : 
      88                 :        152 : const SfxItemPropertyMapEntry* lcl_GetDocInfoPropertyMap()
      89                 :            : {
      90                 :            :     static SfxItemPropertyMapEntry aDocInfoPropertyMap_Impl[] =
      91                 :            :     {
      92         [ +  - ]:         23 :         { "Author"          , 6 , WID_FROM,           &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
      93         [ +  - ]:         23 :         { "AutoloadEnabled" , 15, MID_DOCINFO_AUTOLOADENABLED, &::getBooleanCppuType(),   PROPERTY_UNBOUND, 0 },
      94         [ +  - ]:         23 :         { "AutoloadSecs"    , 12, MID_DOCINFO_AUTOLOADSECS, &::getCppuType((const sal_Int32*)0),     PROPERTY_UNBOUND, 0 },
      95         [ +  - ]:         23 :         { "AutoloadURL"     , 11, MID_DOCINFO_AUTOLOADURL, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
      96         [ +  - ]:         23 :     { "Category"            , 8 , MID_CATEGORY,           &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
      97         [ +  - ]:         23 :     { "Company"         , 7 , MID_COMPANY,           &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
      98         [ +  - ]:         23 :     { "Manager"         , 7 , MID_MANAGER,           &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
      99         [ +  - ]:         23 :         { "CreationDate"    , 12, WID_DATE_CREATED,   &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 },
     100         [ +  - ]:         23 :         { "DefaultTarget"   , 13, MID_DOCINFO_DEFAULTTARGET, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     101         [ +  - ]:         23 :         { "Description"     , 11, MID_DOCINFO_DESCRIPTION, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     102         [ +  - ]:         23 :         { "DocumentStatistic", 17 , MID_DOCINFO_STATISTIC, &::getCppuType((const uno::Sequence< beans::NamedValue >*)0), PROPERTY_UNBOUND, 0 },
     103         [ +  - ]:         23 :         { "EditingCycles"   , 13, MID_DOCINFO_REVISION, &::getCppuType((const sal_Int16*)0),   PROPERTY_UNBOUND, 0 },
     104         [ +  - ]:         23 :         { "EditingDuration" , 15, MID_DOCINFO_EDITTIME, &::getCppuType((const sal_Int32*)0),   PROPERTY_UNBOUND, 0 },
     105         [ +  - ]:         23 :         { "Generator"       , 9,  SID_APPLICATION, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     106         [ +  - ]:         23 :         { "Keywords"        , 8 , WID_KEYWORDS,       &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     107         [ +  - ]:         23 :         { "Language"        , 8,  MID_DOCINFO_CHARLOCALE, &::getCppuType((const lang::Locale*)0), PROPERTY_UNBOUND, 0 },
     108         [ +  - ]:         23 :         { "MIMEType"        , 8 , WID_CONTENT_TYPE,   &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND | ::com::sun::star::beans::PropertyAttribute::READONLY, 0 },
     109         [ +  - ]:         23 :         { "ModifiedBy"      , 10, MID_DOCINFO_MODIFICATIONAUTHOR, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     110         [ +  - ]:         23 :         { "ModifyDate"      , 10, WID_DATE_MODIFIED,  &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 },
     111         [ +  - ]:         23 :         { "PrintDate"       , 9 , MID_DOCINFO_PRINTDATE, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 },
     112         [ +  - ]:         23 :         { "PrintedBy"       , 9 , MID_DOCINFO_PRINTEDBY, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     113         [ +  - ]:         23 :         { "Subject"         , 7 , MID_DOCINFO_SUBJECT, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     114         [ +  - ]:         23 :         { "Template"        , 8 , MID_DOCINFO_TEMPLATE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     115         [ +  - ]:         23 :         { "TemplateFileName", 16, SID_TEMPLATE_NAME, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     116         [ +  - ]:         23 :         { "TemplateDate"    , 12, MID_DOCINFO_TEMPLATEDATE, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 },
     117         [ +  - ]:         23 :         { "Title"           , 5 , WID_TITLE,          &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
     118                 :            :         {0,0,0,0,0,0}
     119 [ +  + ][ +  - ]:        175 :     };
                 [ #  # ]
     120                 :        152 :     return aDocInfoPropertyMap_Impl;
     121                 :            : }
     122                 :            : 
     123                 :            : static sal_uInt16 aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,
     124                 :            :                                    31, 31, 30, 31, 30, 31 };
     125                 :            : 
     126                 :          0 : inline sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear )
     127                 :            : {
     128         [ #  # ]:          0 :     if ( nMonth != 2 )
     129                 :          0 :         return aDaysInMonth[nMonth-1];
     130                 :            :     else
     131                 :            :     {
     132 [ #  # ][ #  # ]:          0 :         if ( (((nYear % 4) == 0) && ((nYear % 100) != 0)) ||
                 [ #  # ]
     133                 :            :              ((nYear % 400) == 0) )
     134                 :          0 :             return aDaysInMonth[nMonth-1] + 1;
     135                 :            :         else
     136                 :          0 :             return aDaysInMonth[nMonth-1];
     137                 :            :     }
     138                 :            : }
     139                 :            : 
     140                 :          0 : bool IsValidDateTime( const util::DateTime& rDT )
     141                 :            : {
     142 [ #  # ][ #  # ]:          0 :     if ( !rDT.Month || (rDT.Month > 12) )
     143                 :          0 :         return false;
     144 [ #  # ][ #  # ]:          0 :     if ( !rDT.Day || (rDT.Day > DaysInMonth( rDT.Month, rDT.Year )) )
                 [ #  # ]
     145                 :          0 :         return false;
     146         [ #  # ]:          0 :     else if ( rDT.Year <= 1582 )
     147                 :            :     {
     148         [ #  # ]:          0 :         if ( rDT.Year < 1582 )
     149                 :          0 :             return false;
     150         [ #  # ]:          0 :         else if ( rDT.Month < 10 )
     151                 :          0 :             return false;
     152 [ #  # ][ #  # ]:          0 :         else if ( (rDT.Month == 10) && (rDT.Day < 15) )
     153                 :          0 :             return false;
     154                 :            :     }
     155                 :            : 
     156                 :          0 :     return true;
     157                 :            : }
     158                 :            : 
     159                 :            : struct OUStringHashCode
     160                 :            : {
     161                 :            :     size_t operator()( const ::rtl::OUString& sString ) const
     162                 :            :     {
     163                 :            :         return sString.hashCode();
     164                 :            :     }
     165                 :            : };
     166                 :            : 
     167                 :            : struct SfxExtendedItemPropertyMap : public SfxItemPropertyMapEntry
     168                 :            : {
     169                 :            :     ::com::sun::star::uno::Any aValue;
     170                 :            : };
     171                 :            : 
     172                 :          0 : void Copy( const uno::Reference < document::XStandaloneDocumentInfo >& rSource, const uno::Reference < document::XStandaloneDocumentInfo >& rTarget )
     173                 :            : {
     174                 :            :     try
     175                 :            :     {
     176         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xSet( rSource, uno::UNO_QUERY );
     177         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xTarget( rTarget, uno::UNO_QUERY );
     178 [ #  # ][ #  # ]:          0 :         uno::Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
     179         [ #  # ]:          0 :         uno::Reference< beans::XPropertyContainer > xContainer( rTarget, uno::UNO_QUERY );
     180 [ #  # ][ #  # ]:          0 :         uno::Sequence< beans::Property > lProps = xSetInfo->getProperties();
     181                 :          0 :         const beans::Property* pProps = lProps.getConstArray();
     182                 :          0 :         sal_Int32 c = lProps.getLength();
     183                 :          0 :         sal_Int32 i = 0;
     184         [ #  # ]:          0 :         for (i=0; i<c; ++i)
     185                 :            :         {
     186 [ #  # ][ #  # ]:          0 :             uno::Any aValue = xSet->getPropertyValue( pProps[i].Name );
     187         [ #  # ]:          0 :             if ( pProps[i].Attributes & ::com::sun::star::beans::PropertyAttribute::REMOVABLE )
     188                 :            :                 // QUESTION: DefaultValue?!
     189 [ #  # ][ #  # ]:          0 :                 xContainer->addProperty( pProps[i].Name, pProps[i].Attributes, aValue );
     190                 :            :             try
     191                 :            :             {
     192                 :            :                 // it is possible that the propertysets from XML and binary files differ; we shouldn't break then
     193 [ #  # ][ #  # ]:          0 :                 xTarget->setPropertyValue( pProps[i].Name, aValue );
     194                 :            :             }
     195         [ #  # ]:          0 :             catch ( const uno::Exception& ) {}
     196                 :          0 :         }
     197                 :            : 
     198 [ #  # ][ #  # ]:          0 :         sal_Int16 nCount = rSource->getUserFieldCount();
     199 [ #  # ][ #  # ]:          0 :         sal_Int16 nSupportedCount = rTarget->getUserFieldCount();
     200 [ #  # ][ #  # ]:          0 :         for ( sal_Int16 nInd = 0; nInd < nCount && nInd < nSupportedCount; nInd++ )
                 [ #  # ]
     201                 :            :         {
     202 [ #  # ][ #  # ]:          0 :             ::rtl::OUString aPropName = rSource->getUserFieldName( nInd );
     203 [ #  # ][ #  # ]:          0 :             rTarget->setUserFieldName( nInd, aPropName );
     204 [ #  # ][ #  # ]:          0 :             ::rtl::OUString aPropVal = rSource->getUserFieldValue( nInd );
     205 [ #  # ][ #  # ]:          0 :             rTarget->setUserFieldValue( nInd, aPropVal );
     206 [ #  # ][ #  # ]:          0 :         }
     207                 :            :     }
     208                 :          0 :     catch ( const uno::Exception& ) {}
     209         [ #  # ]:          0 : }
     210                 :            : 
     211                 :            : class MixedPropertySetInfo : public ::cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertySetInfo >
     212                 :            : {
     213                 :            :     private:
     214                 :            : 
     215                 :            :         SfxItemPropertyMap  _aPropertyMap;
     216                 :            :         ::rtl::OUString* _pUserKeys;
     217                 :            :         uno::Reference<beans::XPropertySet> _xUDProps;
     218                 :            : 
     219                 :            :     public:
     220                 :            : 
     221                 :            :         MixedPropertySetInfo( const SfxItemPropertyMapEntry* pFixProps,
     222                 :            :                              ::rtl::OUString* pUserKeys,
     223                 :            :                              uno::Reference<beans::XPropertySet> xUDProps);
     224                 :            : 
     225                 :            :         virtual ~MixedPropertySetInfo();
     226                 :            : 
     227                 :            :         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getProperties(  ) throw (::com::sun::star::uno::RuntimeException);
     228                 :            :         virtual ::com::sun::star::beans::Property SAL_CALL getPropertyByName( const ::rtl::OUString& aName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
     229                 :            :         virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name ) throw (::com::sun::star::uno::RuntimeException);
     230                 :            : };
     231                 :            : 
     232                 :            : //-----------------------------------------------------------------------------
     233                 :            : 
     234                 :          6 : MixedPropertySetInfo::MixedPropertySetInfo(const SfxItemPropertyMapEntry* pFixProps,
     235                 :            :                      ::rtl::OUString* pUserKeys,
     236                 :            :                      uno::Reference<beans::XPropertySet> xUDProps)
     237                 :            :     : _aPropertyMap( pFixProps )
     238                 :            :     , _pUserKeys(pUserKeys)
     239         [ +  - ]:          6 :     , _xUDProps(xUDProps)
     240                 :            : {
     241                 :          6 : }
     242                 :            : 
     243                 :            : //-----------------------------------------------------------------------------
     244                 :            : 
     245         [ +  - ]:          6 : MixedPropertySetInfo::~MixedPropertySetInfo()
     246                 :            : {
     247         [ -  + ]:         12 : }
     248                 :            : 
     249                 :            : //-----------------------------------------------------------------------------
     250                 :            : 
     251                 :          6 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL MixedPropertySetInfo::getProperties()
     252                 :            :     throw(::com::sun::star::uno::RuntimeException)
     253                 :            : {
     254         [ +  - ]:          6 :     ::comphelper::SequenceAsVector< ::com::sun::star::beans::Property > lProps;
     255                 :            : 
     256                 :            :     // copy "fix" props
     257                 :            :     //todo: os: this ugly thing should be replaced
     258         [ +  - ]:          6 :     const SfxItemPropertyMapEntry* pFixProp = lcl_GetDocInfoPropertyMap();
     259                 :            : 
     260 [ +  - ][ +  + ]:        162 :     while(pFixProp && pFixProp->pName)
                 [ +  + ]
     261                 :            :     {
     262                 :        156 :         ::com::sun::star::beans::Property aProp;
     263                 :            : 
     264                 :        156 :         aProp.Name       = ::rtl::OUString::createFromAscii(pFixProp->pName);
     265                 :        156 :         aProp.Handle     = pFixProp->nWID;
     266                 :        156 :         aProp.Type       = *(pFixProp->pType);
     267                 :        156 :         aProp.Attributes = (sal_Int16)(pFixProp->nFlags);
     268                 :            : 
     269         [ +  - ]:        156 :         lProps.push_back(aProp);
     270                 :        156 :         ++pFixProp;
     271                 :        156 :     }
     272                 :            : 
     273                 :            :     // copy "dynamic" props
     274                 :            : 
     275                 :            :     // NB: this is really ugly:
     276                 :            :     // The returned properties must _not_ include the 4 user-defined fields!
     277                 :            :     // These are _not_ properties of the XDocumentInfo interface.
     278                 :            :     // Some things rely on this, e.g. Copy would break otherwise.
     279                 :            :     // This will have interesting consequences if someone expects to insert
     280                 :            :     // a property with the same name as an user-defined key, but nobody
     281                 :            :     // sane does that.
     282                 :            :     uno::Sequence<beans::Property> udProps =
     283 [ +  - ][ +  - ]:          6 :         _xUDProps->getPropertySetInfo()->getProperties();
         [ +  - ][ +  - ]
     284         [ +  + ]:         48 :     for (sal_Int32 i = 0; i < udProps.getLength(); ++i) {
     285 [ +  - ][ +  - ]:         42 :         if (std::find(_pUserKeys, _pUserKeys+FOUR, udProps[i].Name)
                 [ +  + ]
     286                 :         42 :             == _pUserKeys+FOUR) {
     287                 :            :                 // #i100027#: handles from udProps are not valid here
     288         [ +  - ]:         18 :                 udProps[i].Handle = -1;
     289 [ +  - ][ +  - ]:         18 :                 lProps.push_back(udProps[i]);
     290                 :            :         }
     291                 :            :     }
     292                 :            : 
     293 [ +  - ][ +  - ]:          6 :     return lProps.getAsConstList();
     294                 :            : }
     295                 :            : 
     296                 :            : //-----------------------------------------------------------------------------
     297                 :            : 
     298                 :          0 : ::com::sun::star::beans::Property SAL_CALL MixedPropertySetInfo::getPropertyByName(
     299                 :            :     const ::rtl::OUString& sName )
     300                 :            :     throw(::com::sun::star::beans::UnknownPropertyException,
     301                 :            :           ::com::sun::star::uno::RuntimeException          )
     302                 :            : {
     303                 :          0 :     ::com::sun::star::beans::Property aProp;
     304                 :            : 
     305                 :            :     // search it as "fix" prop
     306 [ #  # ][ #  # ]:          0 :     if( _aPropertyMap.hasPropertyByName( sName ) )
     307         [ #  # ]:          0 :         return _aPropertyMap.getPropertyByName( sName );
     308                 :            :     else
     309                 :            :     // search it as "dynamic" prop
     310 [ #  # ][ #  # ]:          0 :     return _xUDProps->getPropertySetInfo()->getPropertyByName(sName);
         [ #  # ][ #  # ]
     311                 :            : }
     312                 :            : 
     313                 :            : //-----------------------------------------------------------------------------
     314                 :            : 
     315                 :          0 : ::sal_Bool SAL_CALL MixedPropertySetInfo::hasPropertyByName(const ::rtl::OUString& sName)
     316                 :            :     throw(::com::sun::star::uno::RuntimeException)
     317                 :            : {
     318                 :          0 :     return _aPropertyMap.hasPropertyByName( sName ) ? // "fix" prop?
     319                 :            :         sal_True :
     320 [ #  # ][ #  # ]:          0 :         _xUDProps->getPropertySetInfo()->hasPropertyByName(sName); // "dynamic" prop?
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     321                 :            : }
     322                 :            : 
     323                 :            : //-----------------------------------------------------------------------------
     324                 :            : 
     325 [ +  - ][ +  - ]:        685 : struct SfxDocumentInfoObject_Impl
         [ +  + ][ +  - ]
           [ #  #  #  # ]
     326                 :            : {
     327                 :            :     ::osl::Mutex                        _aMutex;
     328                 :            :     ::cppu::OInterfaceContainerHelper   _aDisposeContainer;
     329                 :            : 
     330                 :            :     sal_Bool            bDisposed;
     331                 :            : 
     332                 :            :     // this contains the names of the 4 user defined properties
     333                 :            :     // which are accessible via the evil XDocumentInfo interface
     334                 :            :     ::rtl::OUString m_UserDefined[FOUR];
     335                 :            : 
     336                 :            :     // the actual contents
     337                 :            :     uno::Reference<document::XDocumentProperties> m_xDocProps;
     338                 :            :     SfxItemPropertyMap      m_aPropertyMap;
     339                 :            : 
     340                 :        140 :     SfxDocumentInfoObject_Impl()
     341                 :            :         : _aDisposeContainer( _aMutex )
     342                 :            :         , bDisposed(sal_False)
     343                 :            :         , m_xDocProps()
     344 [ +  - ][ +  + ]:        700 :         , m_aPropertyMap( lcl_GetDocInfoPropertyMap() )
         [ +  - ][ +  - ]
     345                 :            :     {
     346                 :            :         // the number of user fields is not changeable from the outside
     347                 :            :         // we can't set it too high because every name/value pair will be written to the file (even if empty)
     348                 :            :         // currently our dialog has only 4 user keys so 4 is still a reasonable number
     349   [ #  #  #  # ]:        140 :     }
     350                 :            : 
     351                 :            :     /// the initialization function
     352                 :            :     void Reset(uno::Reference<document::XDocumentProperties> xDocProps, ::rtl::OUString* pUserDefined = 0);
     353                 :            : };
     354                 :            : 
     355                 :        180 : void SfxDocumentInfoObject_Impl::Reset(uno::Reference<document::XDocumentProperties> xDocProps, ::rtl::OUString* pUserDefined)
     356                 :            : {
     357         [ +  + ]:        180 :     if (pUserDefined == 0) {
     358                 :            :         // NB: this is an ugly hack; the "Properties" ui dialog displays
     359                 :            :         //     exactly 4 user-defined fields and expects these to be available
     360                 :            :         //     (should be redesigned), but I do not want to do this in
     361                 :            :         //     DocumentProperties; do it here instead
     362                 :            :         uno::Reference<beans::XPropertyAccess> xPropAccess(
     363 [ +  - ][ +  - ]:        175 :             xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
                 [ +  - ]
     364                 :            :         uno::Reference<beans::XPropertyContainer> xPropContainer(
     365         [ +  - ]:        175 :             xPropAccess, uno::UNO_QUERY_THROW);
     366                 :            :         uno::Sequence< beans::PropertyValue >
     367 [ +  - ][ +  - ]:        175 :             props = xPropAccess->getPropertyValues();
     368                 :        175 :         sal_Int32 oldLength = props.getLength();
     369         [ +  + ]:        175 :         if (oldLength < FOUR) {
     370         [ +  - ]:        173 :             std::vector< ::rtl::OUString > names;
     371         [ -  + ]:        173 :             for (sal_Int32 i = 0; i < oldLength; ++i) {
     372 [ #  # ][ #  # ]:          0 :                 names.push_back(props[i].Name);
     373                 :            :             }
     374                 :            :             const ::rtl::OUString sInfo(
     375 [ +  - ][ +  - ]:        173 :                         SfxResId(STR_DOCINFO_INFOFIELD).toString());
     376         [ +  + ]:        865 :             for (sal_Int32 i = oldLength; i < FOUR; ++i) {
     377                 :        692 :                 ::rtl::OUString sName(sInfo);
     378                 :        692 :                 sal_Int32 idx = sName.indexOfAsciiL("%1", 2);
     379                 :            :                 ::rtl::OUString name = (idx > 0)
     380                 :            :                     ? sName.replaceAt(idx, 2, ::rtl::OUString::valueOf(i+1))
     381 [ -  + ][ +  - ]:        692 :                     : sName + ::rtl::OUString::valueOf(i+1);
                 [ +  - ]
     382 [ +  - ][ -  + ]:       2076 :                 while (std::find(names.begin(), names.end(), name)
     383         [ +  - ]:       1384 :                        != names.end()) {
     384                 :          0 :                     name += ::rtl::OUString("'");
     385                 :            :                 }
     386                 :            :                 // FIXME there is a race condition here
     387                 :            :                 try {
     388         [ +  - ]:        692 :                     xPropContainer->addProperty(name,
     389                 :            :                         beans::PropertyAttribute::REMOVEABLE,
     390 [ +  - ][ +  - ]:        692 :                         uno::makeAny(::rtl::OUString("")));
     391      [ #  #  # ]:          0 :                 } catch (const uno::RuntimeException&) {
     392                 :          0 :                     throw;
     393         [ #  # ]:          0 :                 } catch (const uno::Exception&) {
     394                 :            :                     // ignore
     395                 :            :                 }
     396                 :        865 :             }
     397                 :            :         }
     398 [ +  - ][ +  - ]:        175 :         props = xPropAccess->getPropertyValues();
         [ +  - ][ +  - ]
     399         [ +  + ]:        875 :         for (sal_Int32 i = 0; i < FOUR; ++i) {
     400         [ +  - ]:        700 :             m_UserDefined[i] = props[i].Name;
     401         [ +  - ]:        175 :         }
     402                 :            :     } else {
     403                 :          5 :         std::copy(pUserDefined, pUserDefined+FOUR, m_UserDefined);
     404                 :            :     }
     405                 :        180 :     m_xDocProps = xDocProps;
     406                 :        180 : }
     407                 :            : 
     408                 :            : //-----------------------------------------------------------------------------
     409                 :            : 
     410                 :        140 : SfxDocumentInfoObject::SfxDocumentInfoObject()
     411 [ +  - ][ +  - ]:        140 :     : _pImp( new SfxDocumentInfoObject_Impl() )
     412                 :            : {
     413                 :        140 : }
     414                 :            : 
     415                 :            : //-----------------------------------------------------------------------------
     416                 :            : 
     417                 :        137 : SfxDocumentInfoObject::~SfxDocumentInfoObject()
     418                 :            : {
     419 [ +  - ][ +  - ]:        137 :     delete _pImp;
     420         [ -  + ]:        272 : }
     421                 :            : 
     422                 :            : //-----------------------------------------------------------------------------
     423                 :            : 
     424                 :            : // ::com::sun::star::lang::XInitialization:
     425                 :            : void SAL_CALL
     426                 :        135 : SfxDocumentInfoObject::initialize(const uno::Sequence< uno::Any > & aArguments)
     427                 :            :     throw (uno::RuntimeException, uno::Exception)
     428                 :            : {
     429         [ +  - ]:        135 :     if (aArguments.getLength() >= 1) {
     430                 :        135 :         uno::Any any = aArguments[0];
     431                 :        135 :         uno::Reference<document::XDocumentProperties> xDoc;
     432 [ +  - ][ -  + ]:        135 :         if (!(any >>= xDoc) || !xDoc.is()) throw lang::IllegalArgumentException(
         [ -  + ][ +  - ]
     433                 :            :             ::rtl::OUString(
     434                 :            :                 "SfxDocumentInfoObject::initialize: no XDocumentProperties given"),
     435 [ #  # ][ #  # ]:          0 :                 *this, 0);
     436         [ +  - ]:        135 :         _pImp->Reset(xDoc);
     437                 :            :     } else {
     438                 :            :         throw lang::IllegalArgumentException(
     439                 :            :             ::rtl::OUString(
     440                 :            :                 "SfxDocumentInfoObject::initialize: no argument given"),
     441 [ #  # ][ #  # ]:          0 :                 *this, 0);
     442                 :            :     }
     443                 :        135 : }
     444                 :            : 
     445                 :            : // ::com::sun::star::util::XCloneable:
     446                 :            : uno::Reference<util::XCloneable> SAL_CALL
     447                 :          5 : SfxDocumentInfoObject::createClone() throw (uno::RuntimeException)
     448                 :            : {
     449         [ +  - ]:          5 :     SfxDocumentInfoObject *pNew = new SfxDocumentInfoObject;
     450                 :            :     uno::Reference< util::XCloneable >
     451         [ +  - ]:          5 :         xCloneable(_pImp->m_xDocProps, uno::UNO_QUERY_THROW);
     452                 :            :     uno::Reference<document::XDocumentProperties> xDocProps(
     453 [ +  - ][ +  - ]:          5 :         xCloneable->createClone(), uno::UNO_QUERY_THROW);
                 [ +  - ]
     454         [ +  - ]:          5 :     pNew->_pImp->Reset(xDocProps, _pImp->m_UserDefined);
     455 [ +  - ][ +  - ]:          5 :     return pNew;
     456                 :            : }
     457                 :            : 
     458                 :            : // ::com::sun::star::document::XDocumentProperties:
     459                 :            : uno::Reference< document::XDocumentProperties > SAL_CALL
     460                 :        107 : SfxDocumentInfoObject::getDocumentProperties()
     461                 :            :     throw(::com::sun::star::uno::RuntimeException)
     462                 :            : {
     463                 :        107 :     return _pImp->m_xDocProps;
     464                 :            : }
     465                 :            : 
     466                 :            : //-----------------------------------------------------------------------------
     467                 :            : 
     468                 :          0 : const SfxDocumentInfoObject& SfxDocumentInfoObject::operator=( const SfxDocumentInfoObject & rOther)
     469                 :            : {
     470                 :            :     uno::Reference< util::XCloneable >
     471         [ #  # ]:          0 :         xCloneable(rOther._pImp->m_xDocProps, uno::UNO_QUERY_THROW);
     472                 :            :     uno::Reference<document::XDocumentProperties> xDocProps(
     473 [ #  # ][ #  # ]:          0 :         xCloneable->createClone(), uno::UNO_QUERY_THROW);
                 [ #  # ]
     474         [ #  # ]:          0 :     _pImp->Reset(xDocProps, rOther._pImp->m_UserDefined);
     475                 :          0 :     return *this;
     476                 :            : }
     477                 :            : 
     478                 :            : //-----------------------------------------------------------------------------
     479                 :            : 
     480                 :          0 : void SAL_CALL SfxDocumentInfoObject::dispose() throw( ::com::sun::star::uno::RuntimeException )
     481                 :            : {
     482 [ #  # ][ #  # ]:          0 :     ::com::sun::star::lang::EventObject aEvent( (::cppu::OWeakObject *)this );
     483         [ #  # ]:          0 :     _pImp->_aDisposeContainer.disposeAndClear( aEvent );
     484         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( _pImp->_aMutex );
     485         [ #  # ]:          0 :     _pImp->m_xDocProps = 0;
     486                 :            :     // NB: do not call m_xDocProps->dispose(), there could be other refs
     487 [ #  # ][ #  # ]:          0 :     _pImp->bDisposed = sal_True;
     488                 :          0 : }
     489                 :            : 
     490                 :            : //-----------------------------------------------------------------------------
     491                 :            : 
     492                 :          0 : void SAL_CALL  SfxDocumentInfoObject::addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException )
     493                 :            : {
     494                 :          0 :     _pImp->_aDisposeContainer.addInterface( aListener );
     495                 :          0 : }
     496                 :            : 
     497                 :            : //-----------------------------------------------------------------------------
     498                 :            : 
     499                 :          0 : void SAL_CALL  SfxDocumentInfoObject::removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException )
     500                 :            : {
     501                 :          0 :     _pImp->_aDisposeContainer.removeInterface( aListener );
     502                 :          0 : }
     503                 :            : //-----------------------------------------------------------------------------
     504                 :            : 
     505                 :          6 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >  SAL_CALL  SfxDocumentInfoObject::getPropertySetInfo()  throw( ::com::sun::star::uno::RuntimeException )
     506                 :            : {
     507         [ +  - ]:          6 :     ::osl::MutexGuard aGuard( _pImp->_aMutex );
     508                 :            : 
     509                 :            :     uno::Reference<beans::XPropertySet> xPropSet(
     510 [ +  - ][ +  - ]:          6 :         _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
                 [ +  - ]
     511 [ +  - ][ +  - ]:          6 :     MixedPropertySetInfo* pInfo = new MixedPropertySetInfo( lcl_GetDocInfoPropertyMap(), _pImp->m_UserDefined, xPropSet);
     512                 :            :     uno::Reference< beans::XPropertySetInfo > xInfo(
     513 [ +  - ][ +  - ]:          6 :         static_cast< beans::XPropertySetInfo* >(pInfo), uno::UNO_QUERY_THROW);
     514         [ +  - ]:          6 :     return xInfo;
     515                 :            : }
     516                 :            : 
     517                 :            : //-----------------------------------------------------------------------------
     518                 :            : 
     519                 :         54 : void SAL_CALL  SfxDocumentInfoObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aValue) throw (
     520                 :            :         uno::RuntimeException, beans::UnknownPropertyException,
     521                 :            :         beans::PropertyVetoException, lang::IllegalArgumentException,
     522                 :            :         lang::WrappedTargetException)
     523                 :            : {
     524                 :         54 :     const SfxItemPropertySimpleEntry* pEntry = _pImp->m_aPropertyMap.getByName( aPropertyName );
     525                 :            :     // fix prop!
     526         [ +  + ]:         54 :     if ( pEntry )
     527                 :          8 :         setFastPropertyValue( pEntry->nWID, aValue );
     528                 :            :     else
     529                 :            :     // dynamic prop!
     530                 :            :     {
     531                 :            :         uno::Reference<beans::XPropertySet> xPropSet(
     532 [ +  - ][ +  - ]:         46 :             _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
                 [ +  - ]
     533 [ -  + ][ +  - ]:         54 :         return xPropSet->setPropertyValue(aPropertyName, aValue);
     534                 :            :     }
     535                 :            : }
     536                 :            : 
     537                 :            : //-----------------------------------------------------------------------------
     538                 :            : 
     539                 :         47 : uno::Any  SAL_CALL  SfxDocumentInfoObject::getPropertyValue(const ::rtl::OUString& aPropertyName)  throw(
     540                 :            :         uno::RuntimeException, beans::UnknownPropertyException,
     541                 :            :         lang::WrappedTargetException)
     542                 :            : {
     543                 :         47 :     const SfxItemPropertySimpleEntry* pEntry = _pImp->m_aPropertyMap.getByName( aPropertyName );
     544                 :            :     // fix prop!
     545         [ +  + ]:         47 :     if ( pEntry )
     546                 :         43 :         return getFastPropertyValue( pEntry->nWID );
     547                 :            :     else
     548                 :            :     // dynamic prop!
     549                 :            :     {
     550                 :            :         uno::Reference<beans::XPropertySet> xPropSet(
     551 [ +  - ][ +  - ]:          4 :             _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
                 [ +  - ]
     552 [ +  - ][ +  - ]:         47 :         return xPropSet->getPropertyValue(aPropertyName);
     553                 :            :     }
     554                 :            : }
     555                 :            : 
     556                 :          0 : sal_Bool SAL_CALL SfxDocumentInfoObject::isModified() throw(::com::sun::star::uno::RuntimeException)
     557                 :            : {
     558                 :            :     uno::Reference<util::XModifiable> xModif(
     559         [ #  # ]:          0 :             _pImp->m_xDocProps, uno::UNO_QUERY_THROW);
     560 [ #  # ][ #  # ]:          0 :     return xModif->isModified();
     561                 :            : }
     562                 :            : 
     563                 :          0 : void SAL_CALL SfxDocumentInfoObject::setModified( sal_Bool bModified )
     564                 :            :         throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException)
     565                 :            : {
     566                 :            :     uno::Reference<util::XModifiable> xModif(
     567         [ #  # ]:          0 :             _pImp->m_xDocProps, uno::UNO_QUERY_THROW);
     568 [ #  # ][ #  # ]:          0 :     return xModif->setModified(bModified);
     569                 :            : }
     570                 :            : 
     571                 :          0 : void SAL_CALL SfxDocumentInfoObject::addModifyListener( const uno::Reference< util::XModifyListener >& xListener) throw( uno::RuntimeException )
     572                 :            : {
     573                 :            :     uno::Reference<util::XModifiable> xModif(
     574         [ #  # ]:          0 :             _pImp->m_xDocProps, uno::UNO_QUERY_THROW);
     575 [ #  # ][ #  # ]:          0 :     return xModif->addModifyListener(xListener);
     576                 :            : }
     577                 :            : 
     578                 :          0 : void SAL_CALL SfxDocumentInfoObject::removeModifyListener( const uno::Reference< util::XModifyListener >& xListener) throw( uno::RuntimeException )
     579                 :            : {
     580                 :            :     uno::Reference<util::XModifiable> xModif(
     581         [ #  # ]:          0 :             _pImp->m_xDocProps, uno::UNO_QUERY_THROW);
     582 [ #  # ][ #  # ]:          0 :     return xModif->removeModifyListener(xListener);
     583                 :            : }
     584                 :            : 
     585                 :            : //-----------------------------------------------------------------------------
     586                 :            : 
     587                 :          0 : void SAL_CALL  SfxDocumentInfoObject::addPropertyChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener > & ) throw(
     588                 :            :         uno::RuntimeException, beans::UnknownPropertyException,
     589                 :            :         lang::WrappedTargetException)
     590                 :          0 : {}
     591                 :            : 
     592                 :            : //-----------------------------------------------------------------------------
     593                 :            : 
     594                 :          0 : void SAL_CALL  SfxDocumentInfoObject::removePropertyChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener > & ) throw(
     595                 :            :         uno::RuntimeException, beans::UnknownPropertyException,
     596                 :            :         lang::WrappedTargetException)
     597                 :          0 : {}
     598                 :            : 
     599                 :            : //-----------------------------------------------------------------------------
     600                 :            : 
     601                 :          0 : void SAL_CALL  SfxDocumentInfoObject::addVetoableChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener > & ) throw(
     602                 :            :         uno::RuntimeException, beans::UnknownPropertyException,
     603                 :            :         lang::WrappedTargetException)
     604                 :          0 : {}
     605                 :            : 
     606                 :            : //-----------------------------------------------------------------------------
     607                 :            : 
     608                 :          0 : void SAL_CALL  SfxDocumentInfoObject::removeVetoableChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener > & ) throw(
     609                 :            :         uno::RuntimeException, beans::UnknownPropertyException,
     610                 :            :         lang::WrappedTargetException)
     611                 :          0 : {}
     612                 :            : 
     613                 :          0 : uno::Sequence< beans::PropertyValue > SAL_CALL  SfxDocumentInfoObject::getPropertyValues( void ) throw( uno::RuntimeException )
     614                 :            : {
     615         [ #  # ]:          0 :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >  xInfo = getPropertySetInfo();
     616 [ #  # ][ #  # ]:          0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps = xInfo->getProperties();
     617                 :            : 
     618                 :          0 :     const ::com::sun::star::beans::Property* pProps  = aProps.getConstArray();
     619                 :          0 :     sal_uInt32 nCount = aProps.getLength();
     620                 :            : 
     621         [ #  # ]:          0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >aSeq( nCount );
     622         [ #  # ]:          0 :     ::com::sun::star::beans::PropertyValue*  pValues = aSeq.getArray();
     623                 :            : 
     624         [ #  # ]:          0 :     for ( sal_uInt32 n = 0; n < nCount; ++n )
     625                 :            :     {
     626                 :          0 :         ::com::sun::star::beans::PropertyValue& rCurrValue = pValues[n];
     627                 :          0 :         const ::com::sun::star::beans::Property& rCurrProp = pProps[n];
     628                 :            : 
     629                 :          0 :         rCurrValue.Name = rCurrProp.Name;
     630                 :          0 :         rCurrValue.Handle = rCurrProp.Handle;
     631         [ #  # ]:          0 :         rCurrValue.Value = getPropertyValue( rCurrProp.Name );
     632                 :            :     }
     633                 :            : 
     634         [ #  # ]:          0 :     return aSeq;
     635                 :            : }
     636                 :            : 
     637                 :          0 : void SAL_CALL  SfxDocumentInfoObject::setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps )
     638                 :            :         throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException )
     639                 :            : {
     640                 :          0 :     const ::com::sun::star::beans::PropertyValue* pProps  = aProps.getConstArray();
     641                 :          0 :     sal_uInt32 nCount = aProps.getLength();
     642                 :            : 
     643         [ #  # ]:          0 :     for ( sal_uInt32 n = 0; n < nCount; ++n )
     644                 :            :     {
     645                 :          0 :         const ::com::sun::star::beans::PropertyValue& rProp = pProps[n];
     646                 :          0 :         setPropertyValue( rProp.Name, rProp.Value );
     647                 :            :     }
     648                 :          0 : }
     649                 :            : 
     650                 :         14 : void SAL_CALL SfxDocumentInfoObject::addProperty(const ::rtl::OUString&            sName        ,
     651                 :            :                                                        sal_Int16                   nAttributes  ,
     652                 :            :                                                  const ::com::sun::star::uno::Any& aDefaultValue)
     653                 :            :     throw(::com::sun::star::beans::PropertyExistException ,
     654                 :            :           ::com::sun::star::beans::IllegalTypeException   ,
     655                 :            :           ::com::sun::star::lang::IllegalArgumentException,
     656                 :            :           ::com::sun::star::uno::RuntimeException         )
     657                 :            : {
     658                 :            :     // clash with "fix" properties ?
     659         [ +  - ]:         14 :     sal_Bool bFixProp = _pImp->m_aPropertyMap.getByName( sName ) != 0;
     660         [ +  + ]:         14 :     if ( bFixProp )
     661                 :            :     {
     662                 :          2 :         ::rtl::OUStringBuffer sMsg(256);
     663         [ +  - ]:          2 :         sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM("The property \""));
     664         [ +  - ]:          2 :         sMsg.append(sName);
     665         [ +  - ]:          2 :         sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM("\" "));
     666         [ +  - ]:          2 :         if ( bFixProp )
     667         [ +  - ]:          2 :             sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM(" already exists as a fix property. Please have a look into the IDL documentation of the DocumentInfo service."));
     668                 :            : 
     669                 :            :         throw ::com::sun::star::beans::PropertyExistException(
     670                 :            :                 sMsg.makeStringAndClear(),
     671 [ +  - ][ +  - ]:          2 :                 static_cast< ::cppu::OWeakObject* >(this));
                 [ +  - ]
     672                 :            :     }
     673                 :            : 
     674                 :            :     uno::Reference<beans::XPropertyContainer> xPropSet(
     675 [ +  - ][ +  - ]:         12 :         _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
                 [ +  - ]
     676 [ +  - ][ +  - ]:         14 :     return xPropSet->addProperty(sName, nAttributes, aDefaultValue);
     677                 :            : }
     678                 :            : 
     679                 :         10 : void SAL_CALL SfxDocumentInfoObject::removeProperty(const ::rtl::OUString& sName)
     680                 :            :     throw(::com::sun::star::beans::UnknownPropertyException,
     681                 :            :           ::com::sun::star::beans::NotRemoveableException  ,
     682                 :            :           ::com::sun::star::uno::RuntimeException          )
     683                 :            : {
     684                 :            :     // clash with "fix" properties ?
     685         [ +  - ]:         10 :     sal_Bool bFixProp = _pImp->m_aPropertyMap.getByName( sName ) != 0;
     686         [ +  + ]:         10 :     if ( bFixProp )
     687                 :            :     {
     688                 :          2 :         ::rtl::OUStringBuffer sMsg(256);
     689         [ +  - ]:          2 :         sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM("The property \""));
     690         [ +  - ]:          2 :         sMsg.append(sName);
     691         [ +  - ]:          2 :         sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM("\" cant be removed. Its a fix property of the DocumentInfo service."));
     692                 :            : 
     693                 :            :         throw ::com::sun::star::beans::NotRemoveableException(
     694                 :            :                 sMsg.makeStringAndClear(),
     695 [ +  - ][ +  - ]:          2 :                 static_cast< ::cppu::OWeakObject* >(this));
                 [ +  - ]
     696                 :            :     }
     697                 :            : 
     698                 :            :     uno::Reference<beans::XPropertyContainer> xPropSet(
     699 [ +  - ][ +  - ]:          8 :         _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
                 [ +  - ]
     700 [ +  + ][ +  - ]:         10 :     return xPropSet->removeProperty(sName);
     701                 :            : }
     702                 :            : 
     703                 :          0 : sal_Bool equalsDateTime( const util::DateTime& D1, const util::DateTime& D2 )
     704                 :            : {
     705                 :            :     return D1.HundredthSeconds == D2.HundredthSeconds &&
     706                 :            :            D1.Seconds == D2.Seconds &&
     707                 :            :            D1.Minutes == D2.Minutes &&
     708                 :            :            D1.Hours == D2.Hours &&
     709                 :            :            D1.Day == D2.Day &&
     710                 :            :            D1.Month == D2.Month &&
     711 [ #  # ][ #  # ]:          0 :            D1.Year == D2.Year;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     712                 :            : }
     713                 :            : 
     714                 :          8 : void SAL_CALL  SfxDocumentInfoObject::setFastPropertyValue(sal_Int32 nHandle, const ::com::sun::star::uno::Any& aValue) throw(
     715                 :            :         uno::RuntimeException, beans::UnknownPropertyException,
     716                 :            :         beans::PropertyVetoException, lang::IllegalArgumentException,
     717                 :            :         lang::WrappedTargetException)
     718                 :            : {
     719                 :            :     // Attention: Only fix properties should be provided by this method.
     720                 :            :     // Dynamic properties has no handle in real ... because it cant be used inside multithreaded environments :-)
     721                 :            : 
     722         [ +  - ]:          8 :     ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex );
     723                 :            : 
     724 [ +  - ][ +  - ]:          8 :     if ( aValue.getValueType() == ::getCppuType((const ::rtl::OUString*)0) )
     725                 :            :     {
     726                 :          8 :         ::rtl::OUString sTemp ;
     727                 :          8 :         aValue >>= sTemp ;
     728   [ -  -  -  -  :          8 :         switch ( nHandle )
          +  -  -  -  -  
             -  -  -  -  
                      - ]
     729                 :            :         {
     730                 :            :             case SID_APPLICATION :
     731 [ #  # ][ #  # ]:          0 :                 _pImp->m_xDocProps->setGenerator(sTemp);
     732                 :          0 :                 break;
     733                 :            :             case WID_FROM :
     734                 :            :             {
     735 [ #  # ][ #  # ]:          0 :                 if ( _pImp->m_xDocProps->getAuthor() != sTemp )
                 [ #  # ]
     736 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setAuthor(sTemp);
     737                 :          0 :                 break;
     738                 :            :             }
     739                 :            :             case MID_DOCINFO_PRINTEDBY:
     740 [ #  # ][ #  # ]:          0 :                 if ( _pImp->m_xDocProps->getPrintedBy() != sTemp )
                 [ #  # ]
     741 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setPrintedBy(sTemp);
     742                 :          0 :                 break;
     743                 :            :             case MID_DOCINFO_MODIFICATIONAUTHOR:
     744 [ #  # ][ #  # ]:          0 :                 if ( _pImp->m_xDocProps->getModifiedBy() != sTemp )
                 [ #  # ]
     745 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setModifiedBy(sTemp);
     746                 :          0 :                 break;
     747                 :            :             case WID_TITLE :
     748                 :            :             {
     749 [ +  - ][ +  - ]:          8 :                 if ( _pImp->m_xDocProps->getTitle() != sTemp )
                 [ +  - ]
     750 [ +  - ][ +  - ]:          8 :                     _pImp->m_xDocProps->setTitle(sTemp);
     751                 :          8 :                 break;
     752                 :            :             }
     753                 :            :             case MID_DOCINFO_SUBJECT :
     754 [ #  # ][ #  # ]:          0 :                 if ( _pImp->m_xDocProps->getSubject() != sTemp )
                 [ #  # ]
     755 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setSubject(sTemp);
     756                 :          0 :                 break;
     757                 :            :             case WID_KEYWORDS :
     758                 :            :                 {
     759         [ #  # ]:          0 :                     _pImp->m_xDocProps->setKeywords(
     760 [ #  # ][ #  # ]:          0 :                         ::comphelper::string::convertCommaSeparated(sTemp));
                 [ #  # ]
     761                 :            :                 }
     762                 :          0 :                 break;
     763                 :            :             case MID_DOCINFO_TEMPLATE:
     764 [ #  # ][ #  # ]:          0 :                 if ( _pImp->m_xDocProps->getTemplateName() != sTemp )
                 [ #  # ]
     765 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setTemplateName(sTemp);
     766                 :          0 :                 break;
     767                 :            :             case SID_TEMPLATE_NAME:
     768 [ #  # ][ #  # ]:          0 :                 if ( _pImp->m_xDocProps->getTemplateURL() != sTemp )
                 [ #  # ]
     769 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setTemplateURL(sTemp);
     770                 :          0 :                 break;
     771                 :            :             case MID_DOCINFO_DESCRIPTION:
     772 [ #  # ][ #  # ]:          0 :                 if ( _pImp->m_xDocProps->getDescription() != sTemp )
                 [ #  # ]
     773 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setDescription(sTemp);
     774                 :          0 :                 break;
     775                 :            :             case MID_DOCINFO_AUTOLOADURL:
     776 [ #  # ][ #  # ]:          0 :                 if ( _pImp->m_xDocProps->getAutoloadURL() != sTemp )
                 [ #  # ]
     777 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setAutoloadURL(sTemp);
     778                 :          0 :                 break;
     779                 :            :             case MID_DOCINFO_DEFAULTTARGET:
     780 [ #  # ][ #  # ]:          0 :                 if ( _pImp->m_xDocProps->getDefaultTarget() != sTemp )
                 [ #  # ]
     781 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setDefaultTarget(sTemp);
     782                 :          0 :                 break;
     783                 :            :                case MID_CATEGORY:
     784                 :            :                case MID_MANAGER:
     785                 :            :                case MID_COMPANY:
     786                 :            :                    {
     787         [ #  # ]:          0 :                        uno::Reference< document::XCompatWriterDocProperties > xWriterProps( _pImp->m_xDocProps, uno::UNO_QUERY  );
     788         [ #  # ]:          0 :                        if ( xWriterProps.is() )
     789                 :            :                        {
     790         [ #  # ]:          0 :                            if ( nHandle ==  MID_CATEGORY )
     791 [ #  # ][ #  # ]:          0 :                                xWriterProps->setCategory( sTemp );
     792         [ #  # ]:          0 :                            else if ( nHandle ==  MID_MANAGER )
     793 [ #  # ][ #  # ]:          0 :                                xWriterProps->setManager( sTemp );
     794                 :            :                            else
     795 [ #  # ][ #  # ]:          0 :                                xWriterProps->setCompany( sTemp );
     796                 :            :                            break;
     797         [ #  # ]:          0 :                        }
     798                 :            :                    }
     799                 :            :             default:
     800                 :          0 :                 break;
     801                 :          8 :         }
     802                 :            :     }
     803 [ #  # ][ #  # ]:          0 :     else if ( aValue.getValueType() == ::getCppuType((const ::com::sun::star::util::DateTime*)0) )
     804                 :            :     {
     805                 :          0 :         com::sun::star::util::DateTime aTemp;
     806         [ #  # ]:          0 :         aValue >>= aTemp ;
     807   [ #  #  #  #  :          0 :         switch ( nHandle )
                      # ]
     808                 :            :         {
     809                 :            :             case WID_DATE_CREATED :
     810                 :            :             {
     811 [ #  # ][ #  # ]:          0 :                 if ( !equalsDateTime(_pImp->m_xDocProps->getCreationDate(), aTemp ) )
                 [ #  # ]
     812                 :            :                 {
     813 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setCreationDate(aTemp);
     814                 :            :                 }
     815                 :          0 :                 break;
     816                 :            :             }
     817                 :            :             case WID_DATE_MODIFIED :
     818                 :            :             {
     819 [ #  # ][ #  # ]:          0 :                 if ( !equalsDateTime(_pImp->m_xDocProps->getModificationDate(), aTemp ) )
                 [ #  # ]
     820                 :            :                 {
     821 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setModificationDate(aTemp);
     822                 :            :                 }
     823                 :          0 :                 break;
     824                 :            :             }
     825                 :            :             case MID_DOCINFO_PRINTDATE :
     826                 :            :             {
     827 [ #  # ][ #  # ]:          0 :                 if ( !equalsDateTime(_pImp->m_xDocProps->getPrintDate(), aTemp ) )
                 [ #  # ]
     828                 :            :                 {
     829 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setPrintDate(aTemp);
     830                 :            :                 }
     831                 :          0 :                 break;
     832                 :            :             }
     833                 :            :             case MID_DOCINFO_TEMPLATEDATE :
     834                 :            :             {
     835 [ #  # ][ #  # ]:          0 :                 if ( !equalsDateTime(_pImp->m_xDocProps->getTemplateDate(), aTemp ) )
                 [ #  # ]
     836                 :            :                 {
     837 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setTemplateDate(aTemp);
     838                 :            :                 }
     839                 :          0 :                 break;
     840                 :            :             }
     841                 :            :             default:
     842                 :          0 :                 break;
     843                 :            :         }
     844                 :            :     }
     845                 :            : 
     846 [ #  # ][ #  # ]:          0 :     else if ( aValue.getValueType() == ::getBooleanCppuType() )
     847                 :            :     {
     848                 :          0 :         sal_Bool bBoolVal = false;
     849                 :          0 :         aValue >>= bBoolVal ;
     850         [ #  # ]:          0 :         switch ( nHandle )
     851                 :            :         {
     852                 :            :             case MID_DOCINFO_AUTOLOADENABLED:
     853                 :            :                 // NB: this property does not exist any more
     854                 :            :                 //     it is emulated as enabled iff delay > 0
     855 [ #  # ][ #  # ]:          0 :                 if ( bBoolVal && (0 == _pImp->m_xDocProps->getAutoloadSecs()) ) {
         [ #  # ][ #  # ]
                 [ #  # ]
     856 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setAutoloadSecs(60); // default
     857 [ #  # ][ #  # ]:          0 :                 } else if ( !bBoolVal && (0 != _pImp->m_xDocProps->getAutoloadSecs()) ) {
         [ #  # ][ #  # ]
                 [ #  # ]
     858 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setAutoloadSecs(0);
     859 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setAutoloadURL(::rtl::OUString(""));
     860                 :            :                 }
     861                 :          0 :                 break;
     862                 :            :             default:
     863                 :          0 :                 break;
     864                 :            :         }
     865                 :            :     }
     866 [ #  # ][ #  # ]:          0 :     else if ( aValue.getValueType() == ::getCppuType((const sal_Int32*)0) )
     867                 :            :     {
     868                 :          0 :         sal_Int32 nIntVal = 0;
     869                 :          0 :         aValue >>= nIntVal ;
     870      [ #  #  # ]:          0 :         switch ( nHandle )
     871                 :            :         {
     872                 :            :             case MID_DOCINFO_AUTOLOADSECS:
     873 [ #  # ][ #  # ]:          0 :                 if ( nIntVal != _pImp->m_xDocProps->getAutoloadSecs())
                 [ #  # ]
     874 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setAutoloadSecs(nIntVal);
     875                 :          0 :                 break;
     876                 :            :             case MID_DOCINFO_EDITTIME:
     877 [ #  # ][ #  # ]:          0 :                 if ( nIntVal != _pImp->m_xDocProps->getEditingDuration())
                 [ #  # ]
     878 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setEditingDuration(nIntVal);
     879                 :          0 :                 break;
     880                 :            :             default:
     881                 :          0 :                 break;
     882                 :            :         }
     883                 :            :     }
     884 [ #  # ][ #  # ]:          0 :     else if ( aValue.getValueType() == ::getCppuType((const sal_Int16*)0) )
     885                 :            :     {
     886                 :          0 :         short nIntVal = 0;
     887                 :          0 :         aValue >>= nIntVal ;
     888         [ #  # ]:          0 :         switch ( nHandle )
     889                 :            :         {
     890                 :            :             case MID_DOCINFO_REVISION:
     891 [ #  # ][ #  # ]:          0 :                 if ( nIntVal != _pImp->m_xDocProps->getEditingCycles())
                 [ #  # ]
     892 [ #  # ][ #  # ]:          0 :                     _pImp->m_xDocProps->setEditingCycles(nIntVal);
     893                 :          0 :                 break;
     894                 :            :             default:
     895                 :          0 :                 break;
     896                 :            :         }
     897                 :            :     }
     898 [ #  # ][ #  # ]:          0 :     else if ( aValue.getValueType() == ::getCppuType((const uno::Sequence< beans::NamedValue >*)0) )
     899                 :            :     {
     900         [ #  # ]:          0 :         if ( nHandle == MID_DOCINFO_STATISTIC )
     901                 :            :         {
     902         [ #  # ]:          0 :             uno::Sequence < beans::NamedValue > aData;
     903         [ #  # ]:          0 :             aValue >>= aData;
     904                 :            :             {
     905 [ #  # ][ #  # ]:          0 :                 _pImp->m_xDocProps->setDocumentStatistics(aData);
     906         [ #  # ]:          0 :             }
     907                 :            :         }
     908                 :            :     }
     909 [ #  # ][ #  # ]:          0 :     else if ( aValue.getValueType() == ::getCppuType((const lang::Locale*)0) )
     910                 :            :     {
     911         [ #  # ]:          0 :         if ( nHandle == MID_DOCINFO_CHARLOCALE )
     912                 :            :         {
     913                 :          0 :             lang::Locale aLocale;
     914         [ #  # ]:          0 :             aValue >>= aLocale;
     915 [ #  # ][ #  # ]:          0 :             lang::Locale oldLocale = _pImp->m_xDocProps->getLanguage();
     916   [ #  #  #  #  :          0 :             if ( aLocale.Language != oldLocale.Language ||
           #  # ][ #  # ]
     917                 :          0 :                  aLocale.Country  != oldLocale.Country  ||
     918                 :          0 :                  aLocale.Variant  != oldLocale.Variant   )
     919                 :            :             {
     920 [ #  # ][ #  # ]:          0 :                 _pImp->m_xDocProps->setLanguage(aLocale);
     921                 :          0 :             }
     922                 :            :         }
     923         [ +  - ]:          8 :     }
     924                 :          8 : }
     925                 :            : 
     926                 :            : //-----------------------------------------------------------------------------
     927                 :            : 
     928                 :         43 : ::com::sun::star::uno::Any SAL_CALL  SfxDocumentInfoObject::getFastPropertyValue(sal_Int32 nHandle) throw(
     929                 :            :         uno::RuntimeException, beans::UnknownPropertyException,
     930                 :            :         lang::WrappedTargetException)
     931                 :            : {
     932                 :            :     // Attention: Only fix properties should be provided by this method.
     933                 :            :     // Dynamic properties has no handle in real ... because it cant be used inside multithreaded environments :-)
     934                 :            : 
     935         [ +  - ]:         43 :     ::osl::MutexGuard aGuard( _pImp->_aMutex );
     936                 :         43 :     ::com::sun::star::uno::Any aValue;
     937   [ -  +  -  -  :         43 :     switch ( nHandle )
          -  -  +  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
                      - ]
     938                 :            :     {
     939                 :            :         case SID_APPLICATION :
     940 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getGenerator();
                 [ #  # ]
     941                 :          0 :             break;
     942                 :            :         case WID_CONTENT_TYPE :
     943                 :            : // FIXME this is not available anymore
     944         [ +  - ]:         20 :             aValue <<= ::rtl::OUString();
     945                 :         20 :             break;
     946                 :            :         case MID_DOCINFO_REVISION :
     947 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getEditingCycles();
                 [ #  # ]
     948                 :          0 :             break;
     949                 :            :         case MID_DOCINFO_EDITTIME :
     950 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getEditingDuration();
                 [ #  # ]
     951                 :          0 :             break;
     952                 :            :         case WID_FROM :
     953 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getAuthor();
                 [ #  # ]
     954                 :          0 :             break;
     955                 :            :         case WID_DATE_CREATED :
     956 [ #  # ][ #  # ]:          0 :             if ( IsValidDateTime( _pImp->m_xDocProps->getCreationDate() ) )
                 [ #  # ]
     957 [ #  # ][ #  # ]:          0 :                 aValue <<= _pImp->m_xDocProps->getCreationDate();
                 [ #  # ]
     958                 :          0 :             break;
     959                 :            :         case WID_TITLE :
     960 [ +  - ][ +  - ]:         23 :             aValue <<= _pImp->m_xDocProps->getTitle();
                 [ +  - ]
     961                 :         23 :             break;
     962                 :            :         case MID_DOCINFO_SUBJECT:
     963 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getSubject();
                 [ #  # ]
     964                 :          0 :             break;
     965                 :            :         case MID_DOCINFO_MODIFICATIONAUTHOR:
     966 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getModifiedBy();
                 [ #  # ]
     967                 :          0 :             break;
     968                 :            :         case WID_DATE_MODIFIED :
     969 [ #  # ][ #  # ]:          0 :             if ( IsValidDateTime( _pImp->m_xDocProps->getModificationDate() ) )
                 [ #  # ]
     970 [ #  # ][ #  # ]:          0 :                 aValue <<= _pImp->m_xDocProps->getModificationDate();
                 [ #  # ]
     971                 :          0 :             break;
     972                 :            :         case MID_DOCINFO_PRINTEDBY:
     973 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getPrintedBy();
                 [ #  # ]
     974                 :          0 :             break;
     975                 :            :         case MID_DOCINFO_PRINTDATE:
     976 [ #  # ][ #  # ]:          0 :             if ( IsValidDateTime( _pImp->m_xDocProps->getPrintDate() ) )
                 [ #  # ]
     977 [ #  # ][ #  # ]:          0 :                 aValue <<= _pImp->m_xDocProps->getPrintDate();
                 [ #  # ]
     978                 :          0 :             break;
     979                 :            :         case WID_KEYWORDS :
     980                 :            :             aValue <<= ::comphelper::string::convertCommaSeparated(
     981 [ #  # ][ #  # ]:          0 :                 _pImp->m_xDocProps->getKeywords());
         [ #  # ][ #  # ]
                 [ #  # ]
     982                 :          0 :             break;
     983                 :            :         case MID_DOCINFO_DESCRIPTION:
     984 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getDescription();
                 [ #  # ]
     985                 :          0 :             break;
     986                 :            :         case MID_DOCINFO_TEMPLATE:
     987 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getTemplateName();
                 [ #  # ]
     988                 :          0 :             break;
     989                 :            :         case SID_TEMPLATE_NAME:
     990 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getTemplateURL();
                 [ #  # ]
     991                 :          0 :             break;
     992                 :            :         case MID_DOCINFO_TEMPLATEDATE:
     993 [ #  # ][ #  # ]:          0 :             if ( IsValidDateTime( _pImp->m_xDocProps->getTemplateDate() ) )
                 [ #  # ]
     994 [ #  # ][ #  # ]:          0 :                 aValue <<= _pImp->m_xDocProps->getTemplateDate();
                 [ #  # ]
     995                 :          0 :             break;
     996                 :            :         case MID_DOCINFO_AUTOLOADENABLED:
     997                 :            :             aValue <<= static_cast<sal_Bool>
     998 [ #  # ][ #  # ]:          0 :                         (   (_pImp->m_xDocProps->getAutoloadSecs() != 0)
     999 [ #  # ][ #  # ]:          0 :                         || !_pImp->m_xDocProps->getAutoloadURL().isEmpty());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1000                 :          0 :             break;
    1001                 :            :         case MID_DOCINFO_AUTOLOADURL:
    1002 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getAutoloadURL();
                 [ #  # ]
    1003                 :          0 :             break;
    1004                 :            :         case MID_DOCINFO_AUTOLOADSECS:
    1005 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getAutoloadSecs();
                 [ #  # ]
    1006                 :          0 :             break;
    1007                 :            :         case MID_DOCINFO_DEFAULTTARGET:
    1008 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getDefaultTarget();
                 [ #  # ]
    1009                 :          0 :             break;
    1010                 :            :         case MID_DOCINFO_STATISTIC:
    1011 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getDocumentStatistics();
         [ #  # ][ #  # ]
    1012                 :          0 :             break;
    1013                 :            :         case MID_DOCINFO_CHARLOCALE:
    1014 [ #  # ][ #  # ]:          0 :             aValue <<= _pImp->m_xDocProps->getLanguage();
                 [ #  # ]
    1015                 :          0 :             break;
    1016                 :            :         case MID_CATEGORY:
    1017                 :            :         case MID_MANAGER:
    1018                 :            :         case MID_COMPANY:
    1019                 :            :             {
    1020         [ #  # ]:          0 :                 uno::Reference< document::XCompatWriterDocProperties > xWriterProps( _pImp->m_xDocProps, uno::UNO_QUERY  );
    1021         [ #  # ]:          0 :                 if ( xWriterProps.is() )
    1022                 :            :                 {
    1023         [ #  # ]:          0 :                     if ( nHandle ==  MID_CATEGORY )
    1024 [ #  # ][ #  # ]:          0 :                         aValue <<= xWriterProps->getCategory();
                 [ #  # ]
    1025         [ #  # ]:          0 :                     else if ( nHandle ==  MID_MANAGER )
    1026 [ #  # ][ #  # ]:          0 :                         aValue <<= xWriterProps->getManager();
                 [ #  # ]
    1027                 :            :                     else
    1028 [ #  # ][ #  # ]:          0 :                         aValue <<= xWriterProps->getCompany();
                 [ #  # ]
    1029                 :            :                         break;
    1030         [ #  # ]:          0 :                }
    1031                 :            :            }
    1032                 :            : 
    1033                 :            :         default:
    1034         [ #  # ]:          0 :             aValue <<= ::rtl::OUString();
    1035                 :          0 :             break;
    1036                 :            :     }
    1037                 :            : 
    1038         [ +  - ]:         43 :     return aValue;
    1039                 :            : }
    1040                 :            : 
    1041                 :            : //-----------------------------------------------------------------------------
    1042                 :            : 
    1043                 :          0 : sal_Int16 SAL_CALL  SfxDocumentInfoObject::getUserFieldCount() throw( ::com::sun::star::uno::RuntimeException )
    1044                 :            : {
    1045                 :          0 :     return FOUR;
    1046                 :            : }
    1047                 :            : 
    1048                 :            : //-----------------------------------------------------------------------------
    1049                 :            : 
    1050                 :          0 : ::rtl::OUString SAL_CALL  SfxDocumentInfoObject::getUserFieldName(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException )
    1051                 :            : {
    1052         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( _pImp->_aMutex );
    1053         [ #  # ]:          0 :     if (nIndex < FOUR)
    1054                 :          0 :         return _pImp->m_UserDefined[nIndex];
    1055                 :            :     else
    1056         [ #  # ]:          0 :         return ::rtl::OUString();
    1057                 :            : }
    1058                 :            : 
    1059                 :            : //-----------------------------------------------------------------------------
    1060                 :            : 
    1061                 :          0 : ::rtl::OUString SAL_CALL  SfxDocumentInfoObject::getUserFieldValue(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException )
    1062                 :            : {
    1063         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( _pImp->_aMutex );
    1064         [ #  # ]:          0 :     if (nIndex < FOUR) {
    1065                 :          0 :         ::rtl::OUString name = _pImp->m_UserDefined[nIndex];
    1066                 :            :         uno::Reference<beans::XPropertySet> xPropSet(
    1067 [ #  # ][ #  # ]:          0 :             _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
                 [ #  # ]
    1068                 :          0 :         ::rtl::OUString val;
    1069                 :            :         try {
    1070 [ #  # ][ #  # ]:          0 :             xPropSet->getPropertyValue(name) >>= val;
    1071                 :          0 :             return val;
    1072      [ #  #  # ]:          0 :         } catch (const uno::RuntimeException &) {
    1073                 :          0 :             throw;
    1074         [ #  # ]:          0 :         } catch (const uno::Exception &) {
    1075                 :          0 :             return ::rtl::OUString(); // ignore
    1076                 :          0 :         }
    1077                 :            :     } else
    1078         [ #  # ]:          0 :         return ::rtl::OUString();
    1079                 :            : }
    1080                 :            : 
    1081                 :            : //-----------------------------------------------------------------------------
    1082                 :            : 
    1083                 :          4 : void  SAL_CALL SfxDocumentInfoObject::setUserFieldName(sal_Int16 nIndex, const ::rtl::OUString& aName ) throw( ::com::sun::star::uno::RuntimeException )
    1084                 :            : {
    1085         [ +  - ]:          4 :     ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex );
    1086         [ +  - ]:          4 :     if (nIndex < FOUR) // yes, four!
    1087                 :            :     {
    1088                 :            :         // FIXME this is full of race conditions because the PropertyBag
    1089                 :            :         // can be accessed from clients of the DocumentProperties!
    1090                 :          4 :         ::rtl::OUString name = _pImp->m_UserDefined[nIndex];
    1091         [ +  - ]:          4 :         if (name != aName) {
    1092                 :            :             uno::Reference<beans::XPropertySet> xPropSet(
    1093         [ +  - ]:          4 :                 _pImp->m_xDocProps->getUserDefinedProperties(),
    1094 [ +  - ][ +  - ]:          4 :                 uno::UNO_QUERY_THROW);
    1095                 :            :             uno::Reference<beans::XPropertyContainer> xPropContainer(
    1096         [ +  - ]:          4 :                 _pImp->m_xDocProps->getUserDefinedProperties(),
    1097 [ +  - ][ +  - ]:          4 :                 uno::UNO_QUERY_THROW);
    1098                 :          4 :             uno::Any value;
    1099                 :            :             try {
    1100 [ +  - ][ +  - ]:          4 :                 value = xPropSet->getPropertyValue(name);
    1101 [ +  - ][ +  - ]:          4 :                 xPropContainer->removeProperty(name);
    1102         [ +  - ]:          4 :                 xPropContainer->addProperty(aName,
    1103         [ +  - ]:          4 :                     beans::PropertyAttribute::REMOVEABLE, value);
    1104                 :          4 :                 _pImp->m_UserDefined[nIndex] = aName;
    1105   [ #  #  #  # ]:          0 :             } catch (const beans::UnknownPropertyException&) {
    1106                 :            :                 try {
    1107         [ #  # ]:          0 :                     xPropContainer->addProperty(aName,
    1108                 :            :                         beans::PropertyAttribute::REMOVEABLE,
    1109   [ #  #  #  #  :          0 :                         uno::makeAny(::rtl::OUString("")));
                   #  # ]
    1110                 :          0 :                     _pImp->m_UserDefined[nIndex] = aName;
    1111         [ #  # ]:          0 :                 } catch (const beans::PropertyExistException&) {
    1112                 :          0 :                     _pImp->m_UserDefined[nIndex] = aName;
    1113                 :            :                     // ignore
    1114                 :            :                 }
    1115         [ #  # ]:          0 :             } catch (const beans::PropertyExistException&) {
    1116                 :            :                 try {
    1117         [ #  # ]:          0 :                     xPropContainer->addProperty(name,
    1118         [ #  # ]:          0 :                         beans::PropertyAttribute::REMOVEABLE, value);
    1119         [ #  # ]:          0 :                 } catch (const beans::PropertyExistException&) {
    1120                 :            :                     // bugger...
    1121                 :            :                 }
    1122   [ #  #  #  #  :          0 :             } catch (const uno::RuntimeException &) {
                      # ]
    1123                 :          0 :                 throw;
    1124         [ #  # ]:          0 :             } catch (const uno::Exception &) {
    1125                 :            :                 // ignore everything else; xPropSet _may_ be corrupted
    1126                 :          4 :             }
    1127                 :          4 :         }
    1128         [ +  - ]:          4 :     }
    1129                 :          4 : }
    1130                 :            : 
    1131                 :            : //-----------------------------------------------------------------------------
    1132                 :            : 
    1133                 :          4 : void SAL_CALL  SfxDocumentInfoObject::setUserFieldValue( sal_Int16 nIndex, const ::rtl::OUString& aValue ) throw( ::com::sun::star::uno::RuntimeException )
    1134                 :            : {
    1135         [ +  - ]:          4 :     ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex );
    1136         [ +  - ]:          4 :     if (nIndex < FOUR) // yes, four!
    1137                 :            :     {
    1138                 :          4 :         ::rtl::OUString name = _pImp->m_UserDefined[nIndex];
    1139                 :            :         uno::Reference<beans::XPropertySet> xPropSet(
    1140         [ +  - ]:          4 :             _pImp->m_xDocProps->getUserDefinedProperties(),
    1141 [ +  - ][ +  - ]:          4 :             uno::UNO_QUERY_THROW);
    1142                 :            :         uno::Reference<beans::XPropertyContainer> xPropContainer(
    1143         [ +  - ]:          4 :             _pImp->m_xDocProps->getUserDefinedProperties(),
    1144 [ +  - ][ +  - ]:          4 :             uno::UNO_QUERY_THROW);
    1145                 :          4 :         uno::Any aAny;
    1146         [ +  - ]:          4 :         aAny <<= aValue;
    1147                 :            :         try {
    1148 [ +  - ][ +  - ]:          4 :             uno::Any value = xPropSet->getPropertyValue(name);
    1149         [ +  - ]:          4 :             if (value != aAny) {
    1150 [ +  - ][ +  - ]:          4 :                 xPropSet->setPropertyValue(name, aAny);
    1151                 :          4 :             }
    1152         [ #  # ]:          0 :         } catch (const beans::UnknownPropertyException&) {
    1153                 :            :             try {
    1154                 :            :                 // someone removed it, add it back again
    1155         [ #  # ]:          0 :                 xPropContainer->addProperty(name,
    1156         [ #  # ]:          0 :                     beans::PropertyAttribute::REMOVEABLE, aAny);
    1157      [ #  #  # ]:          0 :             } catch (const uno::RuntimeException &) {
    1158                 :          0 :                 throw;
    1159         [ #  # ]:          0 :             } catch (const uno::Exception &) {
    1160                 :            :                 // ignore everything else
    1161                 :            :             }
    1162   [ #  #  #  # ]:          0 :         } catch (const uno::RuntimeException &) {
    1163                 :          0 :             throw;
    1164         [ #  # ]:          0 :         } catch (const uno::Exception &) {
    1165                 :            :             // ignore everything else
    1166                 :          4 :         }
    1167         [ +  - ]:          4 :     }
    1168                 :          4 : }
    1169                 :            : 
    1170                 :            : //-----------------------------------------------------------------------------
    1171 [ +  - ][ +  + ]:         78 : SFX_IMPL_XINTERFACE_2( SfxStandaloneDocumentInfoObject, SfxDocumentInfoObject, ::com::sun::star::lang::XServiceInfo, ::com::sun::star::document::XStandaloneDocumentInfo  )
                 [ +  - ]
    1172 [ #  # ][ #  # ]:          0 : SFX_IMPL_XTYPEPROVIDER_10( SfxStandaloneDocumentInfoObject, ::com::sun::star::document::XDocumentInfo, ::com::sun::star::lang::XComponent,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1173                 :            :     ::com::sun::star::beans::XPropertySet, ::com::sun::star::beans::XFastPropertySet, ::com::sun::star::beans::XPropertyAccess,
    1174                 :            :     ::com::sun::star::beans::XPropertyContainer, ::com::sun::star::util::XModifiable, ::com::sun::star::util::XModifyBroadcaster,
    1175                 :            :     ::com::sun::star::document::XStandaloneDocumentInfo, ::com::sun::star::lang::XServiceInfo )
    1176                 :            : 
    1177 [ +  - ][ +  - ]:        552 : SFX_IMPL_XSERVICEINFO( SfxStandaloneDocumentInfoObject, "com.sun.star.document.StandaloneDocumentInfo", "com.sun.star.comp.sfx2.StandaloneDocumentInfo" )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1178 [ +  - ][ +  - ]:          2 : SFX_IMPL_SINGLEFACTORY( SfxStandaloneDocumentInfoObject )
    1179                 :            : 
    1180                 :          2 : SfxStandaloneDocumentInfoObject::SfxStandaloneDocumentInfoObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
    1181                 :            :     : SfxDocumentInfoObject()
    1182                 :          2 :     , _xFactory( xFactory )
    1183                 :            : {
    1184                 :            :     uno::Reference< lang::XInitialization > xDocProps(
    1185         [ +  - ]:          2 :         _xFactory->createInstance( ::rtl::OUString(
    1186 [ +  - ][ +  - ]:          2 :             "com.sun.star.document.DocumentProperties")), uno::UNO_QUERY_THROW);
    1187                 :          2 :     uno::Any a;
    1188         [ +  - ]:          2 :     a <<= xDocProps;
    1189         [ +  - ]:          2 :     uno::Sequence<uno::Any> args(1);
    1190         [ +  - ]:          2 :     args[0] = a;
    1191 [ +  - ][ +  - ]:          2 :     initialize(args);
    1192                 :          2 : }
    1193                 :            : 
    1194                 :            : //-----------------------------------------------------------------------------
    1195                 :            : 
    1196                 :          2 : SfxStandaloneDocumentInfoObject::~SfxStandaloneDocumentInfoObject()
    1197                 :            : {
    1198         [ -  + ]:          4 : }
    1199                 :            : 
    1200                 :            : //-----------------------------------------------------------------------------
    1201                 :            : 
    1202                 :         20 : uno::Reference< embed::XStorage > GetStorage_Impl( const ::rtl::OUString& rName, sal_Bool bWrite, uno::Reference < lang::XMultiServiceFactory >& xFactory )
    1203                 :            : {
    1204                 :            :     // catch unexpected exceptions under solaris
    1205                 :            :     // Client code checks the returned reference but is not interested on error details.
    1206                 :            :     try
    1207                 :            :     {
    1208         [ +  - ]:         20 :         SolarMutexGuard aSolarGuard;
    1209                 :            :         return ::comphelper::OStorageHelper::GetStorageFromURL(
    1210                 :            :                         rName,
    1211                 :            :                         bWrite ? embed::ElementModes::READWRITE : embed::ElementModes::READ,
    1212 [ -  + ][ +  - ]:         20 :                         xFactory );
         [ +  - ][ #  # ]
    1213                 :            :     }
    1214                 :          0 :     catch(const uno::Exception&)
    1215                 :            :     {}
    1216                 :            : 
    1217                 :          0 :     return uno::Reference< embed::XStorage >();
    1218                 :            : }
    1219                 :            : 
    1220                 :            : //-----------------------------------------------------------------------------
    1221                 :            : 
    1222                 :          0 : sal_Int16 SAL_CALL SfxStandaloneDocumentInfoObject::getUserFieldCount() throw( ::com::sun::star::uno::RuntimeException )
    1223                 :            : {
    1224                 :          0 :     return SfxDocumentInfoObject::getUserFieldCount();
    1225                 :            : }
    1226                 :            : 
    1227                 :            : //-----------------------------------------------------------------------------
    1228                 :            : 
    1229                 :          0 : ::rtl::OUString SAL_CALL  SfxStandaloneDocumentInfoObject::getUserFieldName(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException )
    1230                 :            : {
    1231                 :          0 :     return SfxDocumentInfoObject::getUserFieldName(nIndex);
    1232                 :            : }
    1233                 :            : 
    1234                 :            : //-----------------------------------------------------------------------------
    1235                 :            : 
    1236                 :          0 : ::rtl::OUString SAL_CALL  SfxStandaloneDocumentInfoObject::getUserFieldValue(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException )
    1237                 :            : {
    1238                 :          0 :     return SfxDocumentInfoObject::getUserFieldValue(nIndex);
    1239                 :            : }
    1240                 :            : 
    1241                 :            : //-----------------------------------------------------------------------------
    1242                 :            : 
    1243                 :          0 : void  SAL_CALL SfxStandaloneDocumentInfoObject::setUserFieldName(sal_Int16 nIndex, const ::rtl::OUString& aName ) throw( ::com::sun::star::uno::RuntimeException )
    1244                 :            : {
    1245                 :          0 :     SfxDocumentInfoObject::setUserFieldName( nIndex, aName );
    1246                 :          0 : }
    1247                 :            : 
    1248                 :            : //-----------------------------------------------------------------------------
    1249                 :            : 
    1250                 :          0 : void SAL_CALL  SfxStandaloneDocumentInfoObject::setUserFieldValue( sal_Int16 nIndex, const ::rtl::OUString& aValue ) throw( ::com::sun::star::uno::RuntimeException )
    1251                 :            : {
    1252                 :          0 :     SfxDocumentInfoObject::setUserFieldValue( nIndex, aValue );
    1253                 :          0 : }
    1254                 :            : 
    1255                 :            : //-----------------------------------------------------------------------------
    1256                 :            : 
    1257                 :         20 : void SAL_CALL  SfxStandaloneDocumentInfoObject::loadFromURL(const ::rtl::OUString& aURL)
    1258                 :            :     throw( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException )
    1259                 :            : {
    1260                 :         20 :     sal_Bool bOK = sal_False;
    1261                 :            : 
    1262         [ +  - ]:         20 :     ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex );
    1263                 :            :     uno::Reference< document::XDocumentProperties > xDocProps(
    1264         [ +  - ]:         20 :         _xFactory->createInstance( ::rtl::OUString(
    1265 [ +  - ][ +  - ]:         20 :             "com.sun.star.document.DocumentProperties")), uno::UNO_QUERY_THROW);
    1266         [ +  - ]:         20 :     _pImp->Reset(xDocProps);
    1267         [ +  - ]:         20 :     aGuard.clear();
    1268                 :            : 
    1269         [ +  - ]:         20 :     uno::Reference< embed::XStorage > xStorage = GetStorage_Impl( aURL, sal_False, _xFactory );
    1270         [ +  - ]:         20 :     if ( xStorage.is() )
    1271                 :            :     {
    1272                 :            :         try
    1273                 :            :         {
    1274         [ +  - ]:         20 :             uno::Sequence<beans::PropertyValue> medium(2);
    1275         [ +  - ]:         20 :             medium[0].Name = ::rtl::OUString("DocumentBaseURL");
    1276 [ +  - ][ +  - ]:         20 :             medium[0].Value <<= aURL;
    1277         [ +  - ]:         20 :             medium[1].Name = ::rtl::OUString("URL");
    1278 [ +  - ][ +  - ]:         20 :             medium[1].Value <<= aURL;
    1279 [ +  - ][ +  - ]:         20 :             _pImp->m_xDocProps->loadFromStorage(xStorage, medium);
    1280         [ +  - ]:         20 :             _pImp->Reset(_pImp->m_xDocProps);
    1281 [ #  # ][ +  - ]:         20 :             bOK = sal_True;
    1282                 :            :         }
    1283         [ #  # ]:          0 :         catch( const uno::Exception& )
    1284                 :            :         {
    1285                 :            :         }
    1286                 :            :     }
    1287                 :            :     else
    1288                 :            :     {
    1289         [ #  # ]:          0 :         uno::Reference < document::XStandaloneDocumentInfo > xBinary( _xFactory->createInstance(
    1290 [ #  # ][ #  # ]:          0 :             ::rtl::OUString("com.sun.star.document.BinaryStandaloneDocumentInfo"  ) ), uno::UNO_QUERY );
    1291         [ #  # ]:          0 :         if ( xBinary.is() )
    1292                 :            :         {
    1293 [ #  # ][ #  # ]:          0 :             xBinary->loadFromURL( aURL );
    1294                 :          0 :             bOK = sal_True;
    1295         [ #  # ]:          0 :             uno::Reference < document::XStandaloneDocumentInfo > xTarget( static_cast < document::XStandaloneDocumentInfo*> (this), uno::UNO_QUERY );
    1296         [ #  # ]:          0 :             Copy( xBinary, xTarget );
    1297                 :          0 :         }
    1298                 :            :     }
    1299                 :            : 
    1300         [ -  + ]:         20 :     if ( !bOK )
    1301 [ #  # ][ +  - ]:         20 :         throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_CANTREAD );
    1302                 :         20 : }
    1303                 :            : 
    1304                 :            : //-----------------------------------------------------------------------------
    1305                 :            : 
    1306                 :          0 : void SAL_CALL  SfxStandaloneDocumentInfoObject::storeIntoURL(const ::rtl::OUString& aURL) throw( ::com::sun::star::io::IOException )
    1307                 :            : {
    1308                 :          0 :     sal_Bool bOK = sal_False;
    1309         [ #  # ]:          0 :     uno::Reference< embed::XStorage > xStorage = GetStorage_Impl( aURL, sal_True, _xFactory );
    1310         [ #  # ]:          0 :     if ( xStorage.is() )
    1311                 :            :     {
    1312                 :            :         try
    1313                 :            :         {
    1314         [ #  # ]:          0 :             uno::Sequence<beans::PropertyValue> medium(2);
    1315         [ #  # ]:          0 :             medium[0].Name = ::rtl::OUString("DocumentBaseURL");
    1316 [ #  # ][ #  # ]:          0 :             medium[0].Value <<= aURL;
    1317         [ #  # ]:          0 :             medium[1].Name = ::rtl::OUString("URL");
    1318 [ #  # ][ #  # ]:          0 :             medium[1].Value <<= aURL;
    1319                 :            : 
    1320 [ #  # ][ #  # ]:          0 :             _pImp->m_xDocProps->storeToStorage(xStorage, medium);
    1321         [ #  # ]:          0 :             bOK = sal_True;
    1322                 :            :         }
    1323                 :          0 :         catch( const io::IOException & )
    1324                 :            :         {
    1325                 :          0 :             throw;
    1326                 :            :         }
    1327   [ #  #  #  # ]:          0 :         catch( const uno::RuntimeException& )
    1328                 :            :         {
    1329                 :          0 :             throw;
    1330                 :            :         }
    1331         [ #  # ]:          0 :         catch( const uno::Exception& )
    1332                 :            :         {
    1333                 :            :         }
    1334                 :            :     }
    1335                 :            :     else
    1336                 :            :     {
    1337         [ #  # ]:          0 :         uno::Reference < document::XStandaloneDocumentInfo > xBinary( _xFactory->createInstance(
    1338 [ #  # ][ #  # ]:          0 :             ::rtl::OUString("com.sun.star.document.BinaryStandaloneDocumentInfo"  ) ), uno::UNO_QUERY );
    1339         [ #  # ]:          0 :         if ( xBinary.is() )
    1340                 :            :         {
    1341 [ #  # ][ #  # ]:          0 :             Copy( this, xBinary );
    1342 [ #  # ][ #  # ]:          0 :             xBinary->storeIntoURL( aURL );
    1343                 :          0 :             bOK = sal_True;
    1344                 :          0 :         }
    1345                 :            :     }
    1346                 :            : 
    1347         [ #  # ]:          0 :     if ( !bOK )
    1348         [ #  # ]:          0 :         throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_CANTWRITE );
    1349                 :          0 : }
    1350                 :            : 
    1351                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10