LCOV - code coverage report
Current view: top level - framework/inc/classes - protocolhandlercache.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 4 100.0 %
Date: 2012-08-25 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 6 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_
      30                 :            : #define __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_
      31                 :            : 
      32                 :            : #include <general.h>
      33                 :            : #include <stdtypes.h>
      34                 :            : #include <macros/debug.hxx>
      35                 :            : 
      36                 :            : #include <com/sun/star/util/URL.hpp>
      37                 :            : 
      38                 :            : #include <unotools/configitem.hxx>
      39                 :            : #include <rtl/ustring.hxx>
      40                 :            : #include <fwidllapi.h>
      41                 :            : 
      42                 :            : namespace framework{
      43                 :            : 
      44                 :            : #define PACKAGENAME_PROTOCOLHANDLER                 DECLARE_ASCII("Office.ProtocolHandler"                          )   /// name of our configuration package
      45                 :            : 
      46                 :            : #define CFG_PATH_SEPERATOR                          DECLARE_ASCII("/"                                               )   /// separator for configuration paths
      47                 :            : 
      48                 :            : #define SETNAME_HANDLER                             DECLARE_ASCII("HandlerSet"                                      )   /// name of configuration set inside package
      49                 :            : #define PROPERTY_PROTOCOLS                          DECLARE_ASCII("Protocols"                                       )   /// properties of a protocol handler
      50                 :            : 
      51                 :            : //_________________________________________________________________________________________________________________
      52                 :            : 
      53                 :            : /**
      54                 :            :     Programmer can register his own services to handle different protocols.
      55                 :            :     Don't forget: It doesn't mean "handling of documents" ... these services could handle protocols ...
      56                 :            :     e.g. "mailto:", "file://", ".java:"
      57                 :            :     This struct holds the information about one such registered protocol handler.
      58                 :            :     A list of handler objects is defined as ProtocolHandlerHash. see below
      59                 :            : */
      60 [ +  - ][ +  - ]:      22872 : struct FWI_DLLPUBLIC ProtocolHandler
      61                 :            : {
      62                 :            :     /* member */
      63                 :            :     public:
      64                 :            : 
      65                 :            :         /// the uno implementation name of this handler
      66                 :            :         ::rtl::OUString m_sUNOName;
      67                 :            :         /// list of URL pattern which defines the protocols which this handler is registered for
      68                 :            :         OUStringList m_lProtocols;
      69                 :            : };
      70                 :            : 
      71                 :            : //_________________________________________________________________________________________________________________
      72                 :            : 
      73                 :            : /**
      74                 :            :     This hash use registered pattern of all protocol handlers as keys and provide her
      75                 :            :     uno implementation names as value. Overloading of the index operator makes it possible
      76                 :            :     to search for a key by using a full qualified URL on list of all possible pattern keys.
      77                 :            : */
      78                 :        520 : class FWI_DLLPUBLIC PatternHash : public BaseHash< ::rtl::OUString >
      79                 :            : {
      80                 :            :     /* interface */
      81                 :            :     public:
      82                 :            : 
      83                 :            :         PatternHash::iterator findPatternKey( const ::rtl::OUString& sURL );
      84                 :            : };
      85                 :            : 
      86                 :            : //_________________________________________________________________________________________________________________
      87                 :            : 
      88                 :            : /**
      89                 :            :     This hash holds protocol handler structs by her names.
      90                 :            : */
      91                 :            : typedef BaseHash< ProtocolHandler > HandlerHash;
      92                 :            : 
      93                 :            : //_________________________________________________________________________________________________________________
      94                 :            : 
      95                 :            : /**
      96                 :            :     @short          this hash makes it easy to find a protocol handler by using his uno implementation name.
      97                 :            :     @descr          It holds two lists of informations:
      98                 :            :                         - first holds all handler by her uno implementation names and
      99                 :            :                           can be used to get her other properties
     100                 :            :                         - another one maps her registered pattern to her uno names to
     101                 :            :                           perform search on such data
     102                 :            :                     But this lists a static for all instances of this class. So it's possible to
     103                 :            :                     create new objects without opening configuration twice and free memory automaticly
     104                 :            :                     if last object will gone.
     105                 :            : 
     106                 :            :     @attention      We implement a singleton concept - so we doesn't need any mutex member here.
     107                 :            :                     Because to safe access on static member we must use a static global lock
     108                 :            :                     here too.
     109                 :            : 
     110                 :            :     @devstatus      ready to use
     111                 :            :     @threadsafe     yes
     112                 :            : */
     113                 :            : 
     114                 :            : class HandlerCFGAccess;
     115                 :            : class FWI_DLLPUBLIC HandlerCache
     116                 :            : {
     117                 :            :     /* member */
     118                 :            :     private:
     119                 :            : 
     120                 :            :         /// list of all registered handler registered by her uno implementation names
     121                 :            :         static HandlerHash* m_pHandler;
     122                 :            :         /// maps URL pattern to handler names
     123                 :            :         static PatternHash* m_pPattern;
     124                 :            :         /// informs about config updates
     125                 :            :         static HandlerCFGAccess* m_pConfig;
     126                 :            :         /// ref count to construct/destruct internal member lists on demand by using singleton mechanism
     127                 :            :         static sal_Int32 m_nRefCount;
     128                 :            : 
     129                 :            :     /* interface */
     130                 :            :     public:
     131                 :            : 
     132                 :            :                  HandlerCache();
     133                 :            :         virtual ~HandlerCache();
     134                 :            : 
     135                 :            :         sal_Bool search( const ::rtl::OUString& sURL, ProtocolHandler* pReturn ) const;
     136                 :            :         sal_Bool search( const css::util::URL&  aURL, ProtocolHandler* pReturn ) const;
     137                 :            : 
     138                 :            :         void takeOver(HandlerHash* pHandler, PatternHash* pPattern);
     139                 :            : };
     140                 :            : 
     141                 :            : //_________________________________________________________________________________________________________________
     142                 :            : 
     143                 :            : /**
     144                 :            :     @short          implements configuration access for handler configuration
     145                 :            :     @descr          We use the ConfigItem mechanism to read/write values from/to configuration.
     146                 :            :                     We set a data container pointer for filling or reading ... this class use it temp.
     147                 :            :                     After successfuly calling of read(), we can use filled container directly or merge it with an existing one.
     148                 :            :                     After successfuly calling of write() all values of given data container are flushed to our configuration -
     149                 :            :                     but current implementation doesn't support writeing realy.
     150                 :            : 
     151                 :            :     @base           ::utl::ConfigItem
     152                 :            :                     base mechanism for configuration access
     153                 :            : 
     154                 :            :     @devstatus      ready to use
     155                 :            :     @threadsafe     no
     156                 :            : */
     157         [ -  + ]:        506 : class FWI_DLLPUBLIC HandlerCFGAccess : public ::utl::ConfigItem
     158                 :            : {
     159                 :            :     private:
     160                 :            :         HandlerCache* m_pCache;
     161                 :            : 
     162                 :            :     /* interface */
     163                 :            :     public:
     164                 :            :                  HandlerCFGAccess( const ::rtl::OUString& sPackage  );
     165                 :            :         void     read            (       HandlerHash**    ppHandler ,
     166                 :            :                                          PatternHash**    ppPattern );
     167                 :            : 
     168                 :        520 :         void setCache(HandlerCache* pCache) {m_pCache = pCache;};
     169                 :            :         virtual void Notify(const css::uno::Sequence< rtl::OUString >& lPropertyNames);
     170                 :            :         virtual void Commit();
     171                 :            : };
     172                 :            : 
     173                 :            : } // namespace framework
     174                 :            : 
     175                 :            : #endif // #ifndef __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_
     176                 :            : 
     177                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10