LCOV - code coverage report
Current view: top level - ucb/source/core - ucbprops.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 80 82 97.6 %
Date: 2015-06-13 12:38:46 Functions: 29 30 96.7 %
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         290 : static const com::sun::star::uno::Type& OUString_getCppuType()
      63             : {
      64         290 :     return cppu::UnoType<OUString>::get();
      65             : }
      66             : 
      67          50 : static const com::sun::star::uno::Type& sal_uInt16_getCppuType()
      68             : {
      69             :     // ! uInt -> Int, because of Java !!!
      70          50 :     return cppu::UnoType<sal_Int16>::get();
      71             : }
      72             : 
      73          70 : static const com::sun::star::uno::Type& sal_uInt32_getCppuType()
      74             : {
      75             :     // ! uInt -> Int, because of Java !!!
      76          70 :     return cppu::UnoType<sal_Int32>::get();
      77             : }
      78             : 
      79          30 : static const com::sun::star::uno::Type& sal_uInt64_getCppuType()
      80             : {
      81             :     // ! uInt -> Int, because of Java !!!
      82          30 :     return cppu::UnoType<sal_Int64>::get();
      83             : }
      84             : 
      85          90 : static const com::sun::star::uno::Type& enum_getCppuType()
      86             : {
      87             :     // ! enum -> Int, because of Java !!!
      88          90 :     return cppu::UnoType<sal_Int16>::get();
      89             : }
      90             : 
      91         200 : static const com::sun::star::uno::Type& sal_Bool_getCppuType()
      92             : {
      93         200 :     return cppu::UnoType<bool>::get();
      94             : }
      95             : 
      96          10 : static const com::sun::star::uno::Type& byte_getCppuType()
      97             : {
      98          10 :     return cppu::UnoType<sal_Int8>::get();
      99             : }
     100             : 
     101          10 : static const com::sun::star::uno::Type& Sequence_CrossReference_getCppuType()
     102             : {
     103             :     return cppu::UnoType<
     104             :         com::sun::star::uno::Sequence<
     105          10 :                         com::sun::star::ucb::CrossReference >>::get();
     106             : }
     107             : 
     108          20 : static const com::sun::star::uno::Type& DateTime_getCppuType()
     109             : {
     110             :     return cppu::UnoType<
     111          20 :         com::sun::star::util::DateTime>::get();
     112             : }
     113             : 
     114          10 : static const com::sun::star::uno::Type& Sequence_byte_getCppuType()
     115             : {
     116             :     return cppu::UnoType<
     117          10 :         com::sun::star::uno::Sequence< sal_Int8 >>::get();
     118             : }
     119             : 
     120          10 : static const com::sun::star::uno::Type& Sequence_DocumentHeaderField_getCppuType()
     121             : {
     122             :     return cppu::UnoType<
     123             :         com::sun::star::uno::Sequence<
     124          10 :                         com::sun::star::ucb::DocumentHeaderField >>::get();
     125             : }
     126             : 
     127          10 : static const com::sun::star::uno::Type& XDataContainer_getCppuType()
     128             : {
     129             :     return cppu::UnoType<
     130             :         com::sun::star::uno::Reference<
     131          10 :             com::sun::star::ucb::XDataContainer >>::get();
     132             : }
     133             : 
     134          10 : static const com::sun::star::uno::Type& Sequence_RecipientInfo_getCppuType()
     135             : {
     136             :     return cppu::UnoType<
     137             :         com::sun::star::uno::Sequence<
     138          10 :                         com::sun::star::ucb::RecipientInfo >>::get();
     139             : }
     140             : 
     141          20 : static const com::sun::star::uno::Type& RuleSet_getCppuType()
     142             : {
     143          20 :     return cppu::UnoType<com::sun::star::ucb::RuleSet>::get();
     144             : }
     145             : 
     146          60 : static const com::sun::star::uno::Type& Sequence_SendInfo_getCppuType()
     147             : {
     148             :     return cppu::UnoType<
     149             :         com::sun::star::uno::Sequence<
     150          60 :                         com::sun::star::ucb::SendInfo >>::get();
     151             : }
     152             : 
     153          10 : static const com::sun::star::uno::Type& Sequence_SendMediaTypes_getCppuType()
     154             : {
     155             :     return cppu::UnoType<
     156             :         com::sun::star::uno::Sequence<
     157          10 :                         com::sun::star::ucb::SendMediaTypes >>::get();
     158             : }
     159             : 
     160             : 
     161             : // A table with all well-known UCB properties.
     162             : 
     163             : 
     164             : #define ATTR_DEFAULT ( PropertyAttribute::BOUND | PropertyAttribute::MAYBEVOID | PropertyAttribute::MAYBEDEFAULT )
     165             : 
     166             : static const PropertyTableEntry __aPropertyTable[] =
     167             : {
     168             :     { "Account",            -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     169             :     { "AutoUpdateInterval", -1,                                 ATTR_DEFAULT,   &sal_uInt32_getCppuType },
     170             :     { "ConfirmEmpty",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     171             :     { "ConnectionLimit",    -1,                                 ATTR_DEFAULT,   &byte_getCppuType },
     172             :     { "ConnectionMode",     -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     173             :     { "ContentCountLimit",  -1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     174             :     { "ContentType",        -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     175             :     { "Cookie",             -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     176             :     { "CrossReferences",    -1,                                 ATTR_DEFAULT,   &Sequence_CrossReference_getCppuType },
     177             :     { "DateCreated",        -1,                                 ATTR_DEFAULT,   &DateTime_getCppuType },
     178             :     { "DateModified",       -1,                                 ATTR_DEFAULT,   &DateTime_getCppuType },
     179             :     { "DeleteOnServer",     -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     180             :     { "DocumentBody",       -1,                                 ATTR_DEFAULT,   &Sequence_byte_getCppuType },
     181             :     { "DocumentCount",      -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     182             :                                                                                             &sal_uInt32_getCppuType },
     183             :     { "DocumentCountMarked",
     184             :                             -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     185             :                                                                                             &sal_uInt32_getCppuType },
     186             :     { "DocumentHeader",     -1,                                 ATTR_DEFAULT,   &Sequence_DocumentHeaderField_getCppuType },
     187             :     { "DocumentStoreMode",  -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     188             :     { "DocumentViewMode",   -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     189             :     { "FTPAccount",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     190             :     { "Flags",              -1,                                 ATTR_DEFAULT,   &sal_uInt32_getCppuType },
     191             :     { "FolderCount",        -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     192             :                                                                                             &sal_uInt32_getCppuType },
     193             :     { "FolderViewMode",     -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     194             :     { "FreeSpace",          -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     195             :                                                                                             &sal_uInt64_getCppuType },
     196             :     { "HasDocuments",       -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     197             :                                                                                             &sal_Bool_getCppuType },
     198             :     { "HasFolders",         -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     199             :                                                                                             &sal_Bool_getCppuType },
     200             :     { "IsAutoDelete",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     201             :     { "IsAutoUpdate",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     202             :     { "IsDocument",         -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     203             :                                                                                             &sal_Bool_getCppuType },
     204             :     { "IsFolder",           -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     205             :                                                                                             &sal_Bool_getCppuType },
     206             :     { "IsKeepExpired",      -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     207             :     { "IsLimitedContentCount",
     208             :                             -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     209             :     { "IsMarked",           -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     210             :     { "IsRead",             -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     211             :     { "IsReadOnly",         -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     212             :     { "IsSubscribed",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     213             :     { "IsTimeLimitedStore", -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     214             :     { "Keywords",           -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     215             :     { "LocalBase",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     216             :     { "MessageBCC",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     217             :     { "MessageBody",        -1,                                 ATTR_DEFAULT,   &XDataContainer_getCppuType },
     218             :     { "MessageCC",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     219             :     { "MessageFrom",        -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     220             :     { "MessageId",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     221             :     { "MessageInReplyTo",   -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     222             :     { "MessageReplyTo",     -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     223             :     { "MessageTo",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     224             :     { "NewsGroups",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     225             :     { "NoCacheList",        -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     226             :     { "Origin",             -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     227             :                                                                                             &OUString_getCppuType },
     228             :     { "OutgoingMessageRecipients",
     229             :                             -1,                                 ATTR_DEFAULT,   &Sequence_RecipientInfo_getCppuType },
     230             :     { "OutgoingMessageState",
     231             :                             -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     232             :                                                                                             &enum_getCppuType },
     233             :     { "OutgoingMessageViewMode",
     234             :                             -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     235             :     { "Password",           -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     236             :     { "Priority",           -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     237             :     { "References",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     238             :     { "Referer",            -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     239             :     { "Rules",              -1,                                 ATTR_DEFAULT,   &RuleSet_getCppuType },
     240             :     { "SearchCriteria",     -1,                                 ATTR_DEFAULT,   &RuleSet_getCppuType },
     241             :     { "SearchIndirections", -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     242             :     { "SearchLocations",    -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     243             :     { "SearchRecursive",    -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     244             :     { "SeenCount",          -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     245             :                                                                                             &sal_uInt32_getCppuType },
     246             :     { "SendCopyTarget",     -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     247             :     { "SendFormats",        -1,                                 ATTR_DEFAULT,   &Sequence_SendMediaTypes_getCppuType },
     248             :     { "SendFroms",          -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     249             :     { "SendPasswords",      -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     250             :     { "SendProtocolPrivate",-1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     251             :     { "SendProtocolPublic", -1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     252             :     { "SendReplyTos",       -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     253             :     { "SendServerNames",    -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     254             :     { "SendUserNames",      -1,                                 ATTR_DEFAULT,   &Sequence_SendInfo_getCppuType },
     255             :     { "SendVIMPostOfficePath",
     256             :                             -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     257             :     { "ServerBase",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     258             :     { "ServerName",         -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     259             :     { "ServerPort",         -1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     260             :     { "Size",               -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     261             :                                                                                             &sal_uInt64_getCppuType },
     262             :     { "SizeLimit",          -1,                                 ATTR_DEFAULT,   &sal_uInt64_getCppuType },
     263             :     { "SubscribedCount",    -1,                                 ATTR_DEFAULT | PropertyAttribute::READONLY,
     264             :                                                                                             &sal_uInt32_getCppuType },
     265             :     { "SynchronizePolicy",  -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     266             :     { "TargetFrames",       -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     267             :     { "TargetURL",          -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     268             :     { "TimeLimitStore",     -1,                                 ATTR_DEFAULT,   &sal_uInt16_getCppuType },
     269             :     { "Title",              -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     270             :     { "UpdateOnOpen",       -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     271             :     { "UseOutBoxPrivateProtocolSettings",
     272             :                             -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     273             :     { "UseOutBoxPublicProtocolSettings",
     274             :                             -1,                                 ATTR_DEFAULT,   &sal_Bool_getCppuType },
     275             :     { "UserName",           -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     276             :     { "UserSortCriterium",  -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     277             :     { "VIMPostOfficePath",  -1,                                 ATTR_DEFAULT,   &OUString_getCppuType },
     278             :     { "VerificationMode",   -1,                                 ATTR_DEFAULT,   &enum_getCppuType },
     279             : 
     280             : 
     281             :     // EOT.
     282             : 
     283             : 
     284             :     { 0, 0, 0, 0 }
     285             : };
     286             : 
     287             : 
     288             : 
     289             : 
     290             : // UcbPropertiesManager Implementation.
     291             : 
     292             : 
     293             : 
     294             : 
     295          11 : UcbPropertiesManager::UcbPropertiesManager(
     296             :                         const Reference< XMultiServiceFactory >& )
     297          11 : : m_pProps( 0 )
     298             : {
     299          11 : }
     300             : 
     301             : 
     302             : // virtual
     303          33 : UcbPropertiesManager::~UcbPropertiesManager()
     304             : {
     305          11 :     delete m_pProps;
     306          22 : }
     307             : 
     308             : 
     309             : 
     310             : // XServiceInfo methods.
     311             : 
     312             : 
     313             : 
     314         363 : XSERVICEINFO_IMPL_1( UcbPropertiesManager,
     315             :                      OUString( "com.sun.star.comp.ucb.UcbPropertiesManager" ),
     316             :                      PROPERTIES_MANAGER_SERVICE_NAME );
     317             : 
     318             : 
     319             : 
     320             : // Service factory implementation.
     321             : 
     322             : 
     323             : 
     324          11 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbPropertiesManager );
     325             : 
     326             : 
     327             : 
     328             : // XPropertySetInfo methods.
     329             : 
     330             : 
     331             : 
     332             : // virtual
     333          75 : Sequence< Property > SAL_CALL UcbPropertiesManager::getProperties()
     334             :     throw( RuntimeException, std::exception )
     335             : {
     336          75 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     337             : 
     338          75 :     if ( !m_pProps )
     339             :     {
     340          10 :         m_pProps = new Sequence< Property >( 128 );
     341          10 :         Property* pProps = m_pProps->getArray();
     342          10 :         sal_Int32 nPos  = 0;
     343          10 :         sal_Int32 nSize = m_pProps->getLength();
     344             : 
     345             : 
     346             :         // Get info for well-known properties.
     347             : 
     348             : 
     349          10 :         const PropertyTableEntry* pCurr = &__aPropertyTable[ 0 ];
     350         920 :         while ( pCurr->pName )
     351             :         {
     352         900 :             if ( nSize <= nPos )
     353             :             {
     354             :                 OSL_FAIL( "UcbPropertiesManager::getProperties - "
     355             :                             "Initial size of property sequence too small!" );
     356             : 
     357           0 :                 m_pProps->realloc( 128 );
     358           0 :                 nSize += 128;
     359             :             }
     360             : 
     361         900 :             Property& rProp = pProps[ nPos ];
     362             : 
     363         900 :             rProp.Name       = OUString::createFromAscii( pCurr->pName );
     364         900 :             rProp.Handle     = pCurr->nHandle;
     365         900 :             rProp.Type       = pCurr->pGetCppuType();
     366         900 :             rProp.Attributes = pCurr->nAttributes;
     367             : 
     368         900 :             nPos++;
     369         900 :             pCurr++;
     370             :         }
     371             : 
     372          10 :         if ( nPos > 0 )
     373             :         {
     374          10 :             m_pProps->realloc( nPos );
     375          10 :             nSize = m_pProps->getLength();
     376             :         }
     377             :     }
     378          75 :     return *m_pProps;
     379             : }
     380             : 
     381             : 
     382             : // virtual
     383           2 : Property SAL_CALL UcbPropertiesManager::getPropertyByName( const OUString& aName )
     384             :     throw( UnknownPropertyException, RuntimeException, std::exception )
     385             : {
     386           2 :     Property aProp;
     387           2 :     if ( queryProperty( aName, aProp ) )
     388           2 :         return aProp;
     389             : 
     390           1 :     throw UnknownPropertyException();
     391             : }
     392             : 
     393             : 
     394             : // virtual
     395           2 : sal_Bool SAL_CALL UcbPropertiesManager::hasPropertyByName( const OUString& Name )
     396             :     throw( RuntimeException, std::exception )
     397             : {
     398           2 :     Property aProp;
     399           2 :     return queryProperty( Name, aProp );
     400             : }
     401             : 
     402             : 
     403             : 
     404             : // Non-Interface methods.
     405             : 
     406             : 
     407             : 
     408           4 : bool UcbPropertiesManager::queryProperty(
     409             :                                 const OUString& rName, Property& rProp )
     410             : {
     411           4 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     412             : 
     413           4 :     getProperties();
     414             : 
     415           4 :     const Property* pProps = m_pProps->getConstArray();
     416           4 :     sal_Int32 nCount = m_pProps->getLength();
     417         184 :     for ( sal_Int32 n = 0; n < nCount; ++n )
     418             :     {
     419         182 :         const Property& rCurrProp = pProps[ n ];
     420         182 :         if ( rCurrProp.Name == rName )
     421             :         {
     422           2 :             rProp = rCurrProp;
     423           2 :             return true;
     424             :         }
     425             :     }
     426             : 
     427           2 :     return false;
     428             : }
     429             : 
     430             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11