LCOV - code coverage report
Current view: top level - ucb/source/core - ucbprops.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 80 82 97.6 %
Date: 2014-04-11 Functions: 28 30 93.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <osl/diagnose.h>
      21             : #include <com/sun/star/uno/Type.hxx>
      22             : #include <com/sun/star/uno/Sequence.hxx>
      23             : #include <com/sun/star/uno/Reference.hxx>
      24             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      25             : #include <com/sun/star/ucb/CrossReference.hpp>
      26             : #include <com/sun/star/util/DateTime.hpp>
      27             : #include <com/sun/star/ucb/DocumentHeaderField.hpp>
      28             : #include <com/sun/star/ucb/RecipientInfo.hpp>
      29             : #include <com/sun/star/ucb/RuleSet.hpp>
      30             : #include <com/sun/star/ucb/SendInfo.hpp>
      31             : #include <com/sun/star/ucb/SendMediaTypes.hpp>
      32             : #include <com/sun/star/ucb/XDataContainer.hpp>
      33             : #include "ucbprops.hxx"
      34             : 
      35             : using namespace com::sun::star::beans;
      36             : using namespace com::sun::star::lang;
      37             : using namespace com::sun::star::ucb;
      38             : using namespace com::sun::star::uno;
      39             : using namespace com::sun::star::util;
      40             : 
      41             : 
      42             : 
      43             : 
      44             : // struct PropertyTableEntry
      45             : 
      46             : 
      47             : 
      48             : struct PropertyTableEntry
      49             : {
      50             :     const char* pName;
      51             :     sal_Int32   nHandle;
      52             :     sal_Int16   nAttributes;
      53             :     const com::sun::star::uno::Type& (*pGetCppuType)();
      54             : };
      55             : 
      56             : 
      57             : 
      58             : // CPPU type access functions.
      59             : 
      60             : 
      61             : 
      62         174 : static const com::sun::star::uno::Type& OUString_getCppuType()
      63             : {
      64         174 :     return getCppuType( static_cast< const OUString * >( 0 ) );
      65             : }
      66             : 
      67          30 : static const com::sun::star::uno::Type& sal_uInt16_getCppuType()
      68             : {
      69             :     // ! uInt -> Int, because of Java !!!
      70          30 :     return getCppuType( static_cast< const sal_Int16 * >( 0 ) );
      71             : }
      72             : 
      73          42 : static const com::sun::star::uno::Type& sal_uInt32_getCppuType()
      74             : {
      75             :     // ! uInt -> Int, because of Java !!!
      76          42 :     return getCppuType( static_cast< const sal_Int32 * >( 0 ) );
      77             : }
      78             : 
      79          18 : static const com::sun::star::uno::Type& sal_uInt64_getCppuType()
      80             : {
      81             :     // ! uInt -> Int, because of Java !!!
      82          18 :     return getCppuType( static_cast< const sal_Int64 * >( 0 ) );
      83             : }
      84             : 
      85          54 : static const com::sun::star::uno::Type& enum_getCppuType()
      86             : {
      87             :     // ! enum -> Int, because of Java !!!
      88          54 :     return getCppuType( static_cast< const sal_Int16 * >( 0 ) );
      89             : }
      90             : 
      91         120 : static const com::sun::star::uno::Type& sal_Bool_getCppuType()
      92             : {
      93         120 :     return getCppuBooleanType();
      94             : }
      95             : 
      96           6 : static const com::sun::star::uno::Type& byte_getCppuType()
      97             : {
      98           6 :     return getCppuType( static_cast< const sal_Int8 * >( 0 ) );
      99             : }
     100             : 
     101           6 : static const com::sun::star::uno::Type& Sequence_CrossReference_getCppuType()
     102             : {
     103             :     return getCppuType(
     104             :         static_cast< com::sun::star::uno::Sequence<
     105           6 :                         com::sun::star::ucb::CrossReference > * >( 0 ) );
     106             : }
     107             : 
     108          12 : static const com::sun::star::uno::Type& DateTime_getCppuType()
     109             : {
     110             :     return getCppuType(
     111          12 :         static_cast< com::sun::star::util::DateTime * >( 0 ) );
     112             : }
     113             : 
     114           6 : static const com::sun::star::uno::Type& Sequence_byte_getCppuType()
     115             : {
     116             :     return getCppuType(
     117           6 :         static_cast< com::sun::star::uno::Sequence< sal_Int8 > * >( 0 ) );
     118             : }
     119             : 
     120           6 : static const com::sun::star::uno::Type& Sequence_DocumentHeaderField_getCppuType()
     121             : {
     122             :     return getCppuType(
     123             :         static_cast< com::sun::star::uno::Sequence<
     124           6 :                         com::sun::star::ucb::DocumentHeaderField > * >( 0 ) );
     125             : }
     126             : 
     127           6 : static const com::sun::star::uno::Type& XDataContainer_getCppuType()
     128             : {
     129             :     return getCppuType(
     130             :         static_cast< com::sun::star::uno::Reference<
     131           6 :             com::sun::star::ucb::XDataContainer > * >( 0 ) );
     132             : }
     133             : 
     134           6 : static const com::sun::star::uno::Type& Sequence_RecipientInfo_getCppuType()
     135             : {
     136             :     return getCppuType(
     137             :         static_cast< com::sun::star::uno::Sequence<
     138           6 :                         com::sun::star::ucb::RecipientInfo > * >( 0 ) );
     139             : }
     140             : 
     141          12 : static const com::sun::star::uno::Type& RuleSet_getCppuType()
     142             : {
     143             :     return getCppuType(
     144          12 :         static_cast< com::sun::star::ucb::RuleSet * >( 0 ) );
     145             : }
     146             : 
     147          36 : static const com::sun::star::uno::Type& Sequence_SendInfo_getCppuType()
     148             : {
     149             :     return getCppuType(
     150             :         static_cast< com::sun::star::uno::Sequence<
     151          36 :                         com::sun::star::ucb::SendInfo > * >( 0 ) );
     152             : }
     153             : 
     154           6 : static const com::sun::star::uno::Type& Sequence_SendMediaTypes_getCppuType()
     155             : {
     156             :     return getCppuType(
     157             :         static_cast< com::sun::star::uno::Sequence<
     158           6 :                         com::sun::star::ucb::SendMediaTypes > * >( 0 ) );
     159             : }
     160             : 
     161             : 
     162             : // A table with all well-known UCB properties.
     163             : 
     164             : 
     165             : #define ATTR_DEFAULT ( PropertyAttribute::BOUND | PropertyAttribute::MAYBEVOID | PropertyAttribute::MAYBEDEFAULT )
     166             : 
     167             : static const PropertyTableEntry __aPropertyTable[] =
     168             : {
     169             :     { "Account",            -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     170             :     { "AutoUpdateInterval", -1,                                 ATTR_DEFAULT,   &sal_uInt32_getCppuType },
     171             :     { "ConfirmEmpty",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     172             :     { "ConnectionLimit",    -1,                                 ATTR_DEFAULT,   &byte_getCppuType },
     173             :     { "ConnectionMode",     -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     174             :     { "ContentCountLimit",  -1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     175             :     { "ContentType",        -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     176             :     { "Cookie",             -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     177             :     { "CrossReferences",    -1,                                 ATTR_DEFAULT,   &Sequence_CrossReference_getCppuType },
     178             :     { "DateCreated",        -1,                                 ATTR_DEFAULT,   &DateTime_getCppuType },
     179             :     { "DateModified",       -1,                                 ATTR_DEFAULT,   &DateTime_getCppuType },
     180             :     { "DeleteOnServer",     -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     181             :     { "DocumentBody",       -1,                                 ATTR_DEFAULT,   &Sequence_byte_getCppuType },
     182             :     { "DocumentCount",      -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     183             :                                                                                             &sal_uInt32_getCppuType },
     184             :     { "DocumentCountMarked",
     185             :                             -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     186             :                                                                                             &sal_uInt32_getCppuType },
     187             :     { "DocumentHeader",     -1,                                 ATTR_DEFAULT,   &Sequence_DocumentHeaderField_getCppuType },
     188             :     { "DocumentStoreMode",  -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     189             :     { "DocumentViewMode",   -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     190             :     { "FTPAccount",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     191             :     { "Flags",              -1,                                 ATTR_DEFAULT,   &sal_uInt32_getCppuType },
     192             :     { "FolderCount",        -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     193             :                                                                                             &sal_uInt32_getCppuType },
     194             :     { "FolderViewMode",     -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     195             :     { "FreeSpace",          -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     196             :                                                                                             &sal_uInt64_getCppuType },
     197             :     { "HasDocuments",       -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     198             :                                                                                             &sal_Bool_getCppuType },
     199             :     { "HasFolders",         -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     200             :                                                                                             &sal_Bool_getCppuType },
     201             :     { "IsAutoDelete",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     202             :     { "IsAutoUpdate",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     203             :     { "IsDocument",         -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     204             :                                                                                             &sal_Bool_getCppuType },
     205             :     { "IsFolder",           -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     206             :                                                                                             &sal_Bool_getCppuType },
     207             :     { "IsKeepExpired",      -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     208             :     { "IsLimitedContentCount",
     209             :                             -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     210             :     { "IsMarked",           -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     211             :     { "IsRead",             -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     212             :     { "IsReadOnly",         -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     213             :     { "IsSubscribed",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     214             :     { "IsTimeLimitedStore", -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     215             :     { "Keywords",           -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     216             :     { "LocalBase",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     217             :     { "MessageBCC",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     218             :     { "MessageBody",        -1,                                 ATTR_DEFAULT,   &XDataContainer_getCppuType },
     219             :     { "MessageCC",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     220             :     { "MessageFrom",        -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     221             :     { "MessageId",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     222             :     { "MessageInReplyTo",   -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     223             :     { "MessageReplyTo",     -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     224             :     { "MessageTo",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     225             :     { "NewsGroups",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     226             :     { "NoCacheList",        -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     227             :     { "Origin",             -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     228             :                                                                                             &OUString_getCppuType },
     229             :     { "OutgoingMessageRecipients",
     230             :                             -1,                                 ATTR_DEFAULT,   &Sequence_RecipientInfo_getCppuType },
     231             :     { "OutgoingMessageState",
     232             :                             -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     233             :                                                                                             &enum_getCppuType },
     234             :     { "OutgoingMessageViewMode",
     235             :                             -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     236             :     { "Password",           -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     237             :     { "Priority",           -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     238             :     { "References",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     239             :     { "Referer",            -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     240             :     { "Rules",              -1,                                 ATTR_DEFAULT,   &RuleSet_getCppuType },
     241             :     { "SearchCriteria",     -1,                                 ATTR_DEFAULT,   &RuleSet_getCppuType },
     242             :     { "SearchIndirections", -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     243             :     { "SearchLocations",    -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     244             :     { "SearchRecursive",    -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     245             :     { "SeenCount",          -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     246             :                                                                                             &sal_uInt32_getCppuType },
     247             :     { "SendCopyTarget",     -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     248             :     { "SendFormats",        -1,                                 ATTR_DEFAULT,   &Sequence_SendMediaTypes_getCppuType },
     249             :     { "SendFroms",          -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     250             :     { "SendPasswords",      -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     251             :     { "SendProtocolPrivate",-1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     252             :     { "SendProtocolPublic", -1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     253             :     { "SendReplyTos",       -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     254             :     { "SendServerNames",    -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     255             :     { "SendUserNames",      -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     256             :     { "SendVIMPostOfficePath",
     257             :                             -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     258             :     { "ServerBase",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     259             :     { "ServerName",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     260             :     { "ServerPort",         -1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     261             :     { "Size",               -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     262             :                                                                                             &sal_uInt64_getCppuType },
     263             :     { "SizeLimit",          -1,                                 ATTR_DEFAULT,   &sal_uInt64_getCppuType },
     264             :     { "SubscribedCount",    -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     265             :                                                                                             &sal_uInt32_getCppuType },
     266             :     { "SynchronizePolicy",  -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     267             :     { "TargetFrames",       -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     268             :     { "TargetURL",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     269             :     { "TimeLimitStore",     -1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     270             :     { "Title",              -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     271             :     { "UpdateOnOpen",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     272             :     { "UseOutBoxPrivateProtocolSettings",
     273             :                             -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     274             :     { "UseOutBoxPublicProtocolSettings",
     275             :                             -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     276             :     { "UserName",           -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     277             :     { "UserSortCriterium",  -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     278             :     { "VIMPostOfficePath",  -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     279             :     { "VerificationMode",   -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     280             : 
     281             : 
     282             :     // EOT.
     283             : 
     284             : 
     285             :     { 0, 0, 0, 0 }
     286             : };
     287             : 
     288             : 
     289             : 
     290             : 
     291             : // UcbPropertiesManager Implementation.
     292             : 
     293             : 
     294             : 
     295             : 
     296           7 : UcbPropertiesManager::UcbPropertiesManager(
     297             :                         const Reference< XMultiServiceFactory >& )
     298           7 : : m_pProps( 0 )
     299             : {
     300           7 : }
     301             : 
     302             : 
     303             : // virtual
     304          21 : UcbPropertiesManager::~UcbPropertiesManager()
     305             : {
     306           7 :     delete m_pProps;
     307          14 : }
     308             : 
     309             : 
     310             : 
     311             : // XServiceInfo methods.
     312             : 
     313             : 
     314             : 
     315         240 : XSERVICEINFO_IMPL_1( UcbPropertiesManager,
     316             :                      OUString( "com.sun.star.comp.ucb.UcbPropertiesManager" ),
     317             :                      OUString( PROPERTIES_MANAGER_SERVICE_NAME ) );
     318             : 
     319             : 
     320             : 
     321             : // Service factory implementation.
     322             : 
     323             : 
     324             : 
     325           7 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbPropertiesManager );
     326             : 
     327             : 
     328             : 
     329             : // XPropertySetInfo methods.
     330             : 
     331             : 
     332             : 
     333             : // virtual
     334          75 : Sequence< Property > SAL_CALL UcbPropertiesManager::getProperties()
     335             :     throw( RuntimeException, std::exception )
     336             : {
     337          75 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     338             : 
     339          75 :     if ( !m_pProps )
     340             :     {
     341           6 :         m_pProps = new Sequence< Property >( 128 );
     342           6 :         Property* pProps = m_pProps->getArray();
     343           6 :         sal_Int32 nPos  = 0;
     344           6 :         sal_Int32 nSize = m_pProps->getLength();
     345             : 
     346             : 
     347             :         // Get info for well-known properties.
     348             : 
     349             : 
     350           6 :         const PropertyTableEntry* pCurr = &__aPropertyTable[ 0 ];
     351         552 :         while ( pCurr->pName )
     352             :         {
     353         540 :             if ( nSize <= nPos )
     354             :             {
     355             :                 OSL_FAIL( "UcbPropertiesManager::getProperties - "
     356             :                             "Initial size of property sequence too small!" );
     357             : 
     358           0 :                 m_pProps->realloc( 128 );
     359           0 :                 nSize += 128;
     360             :             }
     361             : 
     362         540 :             Property& rProp = pProps[ nPos ];
     363             : 
     364         540 :             rProp.Name       = OUString::createFromAscii( pCurr->pName );
     365         540 :             rProp.Handle     = pCurr->nHandle;
     366         540 :             rProp.Type       = pCurr->pGetCppuType();
     367         540 :             rProp.Attributes = pCurr->nAttributes;
     368             : 
     369         540 :             nPos++;
     370         540 :             pCurr++;
     371             :         }
     372             : 
     373           6 :         if ( nPos > 0 )
     374             :         {
     375           6 :             m_pProps->realloc( nPos );
     376           6 :             nSize = m_pProps->getLength();
     377             :         }
     378             :     }
     379          75 :     return *m_pProps;
     380             : }
     381             : 
     382             : 
     383             : // virtual
     384           2 : Property SAL_CALL UcbPropertiesManager::getPropertyByName( const OUString& aName )
     385             :     throw( UnknownPropertyException, RuntimeException, std::exception )
     386             : {
     387           2 :     Property aProp;
     388           2 :     if ( queryProperty( aName, aProp ) )
     389           2 :         return aProp;
     390             : 
     391           1 :     throw UnknownPropertyException();
     392             : }
     393             : 
     394             : 
     395             : // virtual
     396           2 : sal_Bool SAL_CALL UcbPropertiesManager::hasPropertyByName( const OUString& Name )
     397             :     throw( RuntimeException, std::exception )
     398             : {
     399           2 :     Property aProp;
     400           2 :     return queryProperty( Name, aProp );
     401             : }
     402             : 
     403             : 
     404             : 
     405             : // Non-Interface methods.
     406             : 
     407             : 
     408             : 
     409           4 : sal_Bool UcbPropertiesManager::queryProperty(
     410             :                                 const OUString& rName, Property& rProp )
     411             : {
     412           4 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     413             : 
     414           4 :     getProperties();
     415             : 
     416           4 :     const Property* pProps = m_pProps->getConstArray();
     417           4 :     sal_Int32 nCount = m_pProps->getLength();
     418         184 :     for ( sal_Int32 n = 0; n < nCount; ++n )
     419             :     {
     420         182 :         const Property& rCurrProp = pProps[ n ];
     421         182 :         if ( rCurrProp.Name == rName )
     422             :         {
     423           2 :             rProp = rCurrProp;
     424           2 :             return sal_True;
     425             :         }
     426             :     }
     427             : 
     428           2 :     return sal_False;
     429             : }
     430             : 
     431             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10