LCOV - code coverage report
Current view: top level - framework/inc - protocols.h (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 22 26 84.6 %
Date: 2014-11-03 Functions: 1 1 100.0 %
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             : /*TODO outline this implementation :-) */
      21             : 
      22             : #ifndef INCLUDED_FRAMEWORK_INC_PROTOCOLS_H
      23             : #define INCLUDED_FRAMEWORK_INC_PROTOCOLS_H
      24             : 
      25             : #include <rtl/ustring.hxx>
      26             : 
      27             : namespace framework{
      28             : 
      29             : /**
      30             :     some protocols must be checked during loading or dispatching URLs manually
      31             :     It can be necessary to decide, if a URL represent a non visible content or
      32             :     a real visible component.
      33             :  */
      34             : 
      35             : // indicates a loadable content in general!
      36             : #define SPECIALPROTOCOL_PRIVATE           "private:"
      37             : // indicates loading of components using a model directly
      38             : #define SPECIALPROTOCOL_PRIVATE_OBJECT    "private:object"
      39             : // indicates loading of components using a stream only
      40             : #define SPECIALPROTOCOL_PRIVATE_STREAM    "private:stream"
      41             : // indicates creation of empty documents
      42             : #define SPECIALPROTOCOL_PRIVATE_FACTORY   "private:factory"
      43             : // internal protocol of the sfx project for generic dispatch funtionality
      44             : #define SPECIALPROTOCOL_SLOT              "slot:"
      45             : // external representation of the slot protocol using names instead of id's
      46             : #define SPECIALPROTOCOL_UNO               ".uno:"
      47             : // special sfx protocol to execute macros
      48             : #define SPECIALPROTOCOL_MACRO             "macro:"
      49             : // generic way to start uno services during dispatch
      50             : #define SPECIALPROTOCOL_SERVICE           "service:"
      51             : // for sending mails
      52             : #define SPECIALPROTOCOL_MAILTO            "mailto:"
      53             : // for sending news
      54             : #define SPECIALPROTOCOL_NEWS              "news:"
      55             : 
      56             : class ProtocolCheck
      57             : {
      58             :     public:
      59             : 
      60             :     /**
      61             :         enums for well known protocols
      62             :      */
      63             :     enum EProtocol
      64             :     {
      65             :         E_UNKNOWN_PROTOCOL  ,
      66             :         E_PRIVATE           ,
      67             :         E_PRIVATE_OBJECT    ,
      68             :         E_PRIVATE_STREAM    ,
      69             :         E_PRIVATE_FACTORY   ,
      70             :         E_SLOT              ,
      71             :         E_UNO               ,
      72             :         E_MACRO             ,
      73             :         E_SERVICE           ,
      74             :         E_MAILTO            ,
      75             :         E_NEWS
      76             :     };
      77             : 
      78             :     /**
      79             :         it checks, if the given URL string match one of the well known protocols.
      80             :         It returns the right enum value.
      81             :         Protocols are defined above ...
      82             :      */
      83             :     static EProtocol specifyProtocol( const OUString& sURL )
      84             :     {
      85             :         // because "private:" is part of e.g. "private:object" too ...
      86             :         // we must check it before all other ones!!!
      87             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE)))
      88             :             return E_PRIVATE;
      89             :         else
      90             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_OBJECT)))
      91             :             return E_PRIVATE_OBJECT;
      92             :         else
      93             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_STREAM)))
      94             :             return E_PRIVATE_STREAM;
      95             :         else
      96             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_FACTORY)))
      97             :             return E_PRIVATE_FACTORY;
      98             :         else
      99             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_SLOT)))
     100             :             return E_SLOT;
     101             :         else
     102             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_UNO)))
     103             :             return E_UNO;
     104             :         else
     105             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_MACRO)))
     106             :             return E_MACRO;
     107             :         else
     108             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_SERVICE)))
     109             :             return E_SERVICE;
     110             :         else
     111             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_MAILTO)))
     112             :             return E_MAILTO;
     113             :         else
     114             :         if (sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_NEWS)))
     115             :             return E_NEWS;
     116             :         else
     117             :             return E_UNKNOWN_PROTOCOL;
     118             :     }
     119             : 
     120             :     /**
     121             :         it checks if given URL match the required protocol only
     122             :         It should be used instead of specifyProtocol() if only this question
     123             :         is interesting to perform the code. We must not check for all possible protocols here...
     124             :      */
     125      415656 :     static bool isProtocol( const OUString& sURL, EProtocol eRequired )
     126             :     {
     127      415656 :         bool bRet = sal_False;
     128      415656 :         switch(eRequired)
     129             :         {
     130             :             case E_PRIVATE:
     131           0 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE));
     132           0 :                 break;
     133             :             case E_PRIVATE_OBJECT:
     134       50298 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_OBJECT));
     135       50298 :                 break;
     136             :             case E_PRIVATE_STREAM:
     137       50298 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_STREAM));
     138       50298 :                 break;
     139             :             case E_PRIVATE_FACTORY:
     140       47790 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_FACTORY));
     141       47790 :                 break;
     142             :             case E_SLOT:
     143       43822 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_SLOT));
     144       43822 :                 break;
     145             :             case E_UNO:
     146       48160 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_UNO));
     147       48160 :                 break;
     148             :             case E_MACRO:
     149       43822 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_MACRO));
     150       43822 :                 break;
     151             :             case E_SERVICE:
     152       43822 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_SERVICE));
     153       43822 :                 break;
     154             :             case E_MAILTO:
     155       43822 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_MAILTO));
     156       43822 :                 break;
     157             :             case E_NEWS:
     158       43822 :                 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_NEWS));
     159       43822 :                 break;
     160             :             default:
     161           0 :                 bRet = sal_False;
     162           0 :                 break;
     163             :         }
     164      415656 :         return bRet;
     165             :     }
     166             : };
     167             : 
     168             : } // namespace framework
     169             : 
     170             : #endif // INCLUDED_FRAMEWORK_INC_PROTOCOLS_H
     171             : 
     172             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10