LCOV - code coverage report
Current view: top level - ucb/source/core - ucbprops.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 80 82 97.6 %
Date: 2014-11-03 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         348 : static const com::sun::star::uno::Type& OUString_getCppuType()
      63             : {
      64         348 :     return cppu::UnoType<OUString>::get();
      65             : }
      66             : 
      67          60 : static const com::sun::star::uno::Type& sal_uInt16_getCppuType()
      68             : {
      69             :     // ! uInt -> Int, because of Java !!!
      70          60 :     return cppu::UnoType<sal_Int16>::get();
      71             : }
      72             : 
      73          84 : static const com::sun::star::uno::Type& sal_uInt32_getCppuType()
      74             : {
      75             :     // ! uInt -> Int, because of Java !!!
      76          84 :     return cppu::UnoType<sal_Int32>::get();
      77             : }
      78             : 
      79          36 : static const com::sun::star::uno::Type& sal_uInt64_getCppuType()
      80             : {
      81             :     // ! uInt -> Int, because of Java !!!
      82          36 :     return cppu::UnoType<sal_Int64>::get();
      83             : }
      84             : 
      85         108 : static const com::sun::star::uno::Type& enum_getCppuType()
      86             : {
      87             :     // ! enum -> Int, because of Java !!!
      88         108 :     return cppu::UnoType<sal_Int16>::get();
      89             : }
      90             : 
      91         240 : static const com::sun::star::uno::Type& sal_Bool_getCppuType()
      92             : {
      93         240 :     return getCppuBooleanType();
      94             : }
      95             : 
      96          12 : static const com::sun::star::uno::Type& byte_getCppuType()
      97             : {
      98          12 :     return cppu::UnoType<sal_Int8>::get();
      99             : }
     100             : 
     101          12 : static const com::sun::star::uno::Type& Sequence_CrossReference_getCppuType()
     102             : {
     103             :     return getCppuType(
     104             :         static_cast< com::sun::star::uno::Sequence<
     105          12 :                         com::sun::star::ucb::CrossReference > * >( 0 ) );
     106             : }
     107             : 
     108          24 : static const com::sun::star::uno::Type& DateTime_getCppuType()
     109             : {
     110             :     return getCppuType(
     111          24 :         static_cast< com::sun::star::util::DateTime * >( 0 ) );
     112             : }
     113             : 
     114          12 : static const com::sun::star::uno::Type& Sequence_byte_getCppuType()
     115             : {
     116             :     return getCppuType(
     117          12 :         static_cast< com::sun::star::uno::Sequence< sal_Int8 > * >( 0 ) );
     118             : }
     119             : 
     120          12 : static const com::sun::star::uno::Type& Sequence_DocumentHeaderField_getCppuType()
     121             : {
     122             :     return getCppuType(
     123             :         static_cast< com::sun::star::uno::Sequence<
     124          12 :                         com::sun::star::ucb::DocumentHeaderField > * >( 0 ) );
     125             : }
     126             : 
     127          12 : static const com::sun::star::uno::Type& XDataContainer_getCppuType()
     128             : {
     129             :     return getCppuType(
     130             :         static_cast< com::sun::star::uno::Reference<
     131          12 :             com::sun::star::ucb::XDataContainer > * >( 0 ) );
     132             : }
     133             : 
     134          12 : static const com::sun::star::uno::Type& Sequence_RecipientInfo_getCppuType()
     135             : {
     136             :     return getCppuType(
     137             :         static_cast< com::sun::star::uno::Sequence<
     138          12 :                         com::sun::star::ucb::RecipientInfo > * >( 0 ) );
     139             : }
     140             : 
     141          24 : static const com::sun::star::uno::Type& RuleSet_getCppuType()
     142             : {
     143          24 :     return cppu::UnoType<com::sun::star::ucb::RuleSet>::get();
     144             : }
     145             : 
     146          72 : static const com::sun::star::uno::Type& Sequence_SendInfo_getCppuType()
     147             : {
     148             :     return getCppuType(
     149             :         static_cast< com::sun::star::uno::Sequence<
     150          72 :                         com::sun::star::ucb::SendInfo > * >( 0 ) );
     151             : }
     152             : 
     153          12 : static const com::sun::star::uno::Type& Sequence_SendMediaTypes_getCppuType()
     154             : {
     155             :     return getCppuType(
     156             :         static_cast< com::sun::star::uno::Sequence<
     157          12 :                         com::sun::star::ucb::SendMediaTypes > * >( 0 ) );
     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          14 : UcbPropertiesManager::UcbPropertiesManager(
     296             :                         const Reference< XMultiServiceFactory >& )
     297          14 : : m_pProps( 0 )
     298             : {
     299          14 : }
     300             : 
     301             : 
     302             : // virtual
     303          42 : UcbPropertiesManager::~UcbPropertiesManager()
     304             : {
     305          14 :     delete m_pProps;
     306          28 : }
     307             : 
     308             : 
     309             : 
     310             : // XServiceInfo methods.
     311             : 
     312             : 
     313             : 
     314         503 : XSERVICEINFO_IMPL_1( UcbPropertiesManager,
     315             :                      OUString( "com.sun.star.comp.ucb.UcbPropertiesManager" ),
     316             :                      OUString( PROPERTIES_MANAGER_SERVICE_NAME ) );
     317             : 
     318             : 
     319             : 
     320             : // Service factory implementation.
     321             : 
     322             : 
     323             : 
     324          14 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbPropertiesManager );
     325             : 
     326             : 
     327             : 
     328             : // XPropertySetInfo methods.
     329             : 
     330             : 
     331             : 
     332             : // virtual
     333         150 : Sequence< Property > SAL_CALL UcbPropertiesManager::getProperties()
     334             :     throw( RuntimeException, std::exception )
     335             : {
     336         150 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     337             : 
     338         150 :     if ( !m_pProps )
     339             :     {
     340          12 :         m_pProps = new Sequence< Property >( 128 );
     341          12 :         Property* pProps = m_pProps->getArray();
     342          12 :         sal_Int32 nPos  = 0;
     343          12 :         sal_Int32 nSize = m_pProps->getLength();
     344             : 
     345             : 
     346             :         // Get info for well-known properties.
     347             : 
     348             : 
     349          12 :         const PropertyTableEntry* pCurr = &__aPropertyTable[ 0 ];
     350        1104 :         while ( pCurr->pName )
     351             :         {
     352        1080 :             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        1080 :             Property& rProp = pProps[ nPos ];
     362             : 
     363        1080 :             rProp.Name       = OUString::createFromAscii( pCurr->pName );
     364        1080 :             rProp.Handle     = pCurr->nHandle;
     365        1080 :             rProp.Type       = pCurr->pGetCppuType();
     366        1080 :             rProp.Attributes = pCurr->nAttributes;
     367             : 
     368        1080 :             nPos++;
     369        1080 :             pCurr++;
     370             :         }
     371             : 
     372          12 :         if ( nPos > 0 )
     373             :         {
     374          12 :             m_pProps->realloc( nPos );
     375          12 :             nSize = m_pProps->getLength();
     376             :         }
     377             :     }
     378         150 :     return *m_pProps;
     379             : }
     380             : 
     381             : 
     382             : // virtual
     383           4 : Property SAL_CALL UcbPropertiesManager::getPropertyByName( const OUString& aName )
     384             :     throw( UnknownPropertyException, RuntimeException, std::exception )
     385             : {
     386           4 :     Property aProp;
     387           4 :     if ( queryProperty( aName, aProp ) )
     388           4 :         return aProp;
     389             : 
     390           2 :     throw UnknownPropertyException();
     391             : }
     392             : 
     393             : 
     394             : // virtual
     395           4 : sal_Bool SAL_CALL UcbPropertiesManager::hasPropertyByName( const OUString& Name )
     396             :     throw( RuntimeException, std::exception )
     397             : {
     398           4 :     Property aProp;
     399           4 :     return queryProperty( Name, aProp );
     400             : }
     401             : 
     402             : 
     403             : 
     404             : // Non-Interface methods.
     405             : 
     406             : 
     407             : 
     408           8 : bool UcbPropertiesManager::queryProperty(
     409             :                                 const OUString& rName, Property& rProp )
     410             : {
     411           8 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     412             : 
     413           8 :     getProperties();
     414             : 
     415           8 :     const Property* pProps = m_pProps->getConstArray();
     416           8 :     sal_Int32 nCount = m_pProps->getLength();
     417         368 :     for ( sal_Int32 n = 0; n < nCount; ++n )
     418             :     {
     419         364 :         const Property& rCurrProp = pProps[ n ];
     420         364 :         if ( rCurrProp.Name == rName )
     421             :         {
     422           4 :             rProp = rCurrProp;
     423           4 :             return true;
     424             :         }
     425             :     }
     426             : 
     427           4 :     return false;
     428             : }
     429             : 
     430             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10