xref: /aoo41x/main/framework/inc/protocols.h (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir /*TODO outline this implementation :-) */
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #ifndef __FRAMEWORK_PROTOCOLS_H_
31*cdf0e10cSrcweir #define __FRAMEWORK_PROTOCOLS_H_
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34*cdf0e10cSrcweir //	includes
35*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <macros/generic.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
40*cdf0e10cSrcweir //	namespace
41*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir namespace framework{
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //_______________________________________________________________________
46*cdf0e10cSrcweir /**
47*cdf0e10cSrcweir     some protocols must be checked during loading or dispatching URLs manually
48*cdf0e10cSrcweir     It can be neccessary to decide, if a URL represent a non visible content or
49*cdf0e10cSrcweir     a real visible component.
50*cdf0e10cSrcweir  */
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #define SPECIALPROTOCOL_PRIVATE           DECLARE_ASCII("private:"       )       // indicates a loadable content in general!
53*cdf0e10cSrcweir #define SPECIALPROTOCOL_PRIVATE_OBJECT    DECLARE_ASCII("private:object" )       // indicates loading of components using a model directly
54*cdf0e10cSrcweir #define SPECIALPROTOCOL_PRIVATE_STREAM    DECLARE_ASCII("private:stream" )       // indicates loading of components using a stream only
55*cdf0e10cSrcweir #define SPECIALPROTOCOL_PRIVATE_FACTORY   DECLARE_ASCII("private:factory")       // indicates creation of empty documents
56*cdf0e10cSrcweir #define SPECIALPROTOCOL_SLOT              DECLARE_ASCII("slot:"          )       // internal protocol of the sfx project for generic dispatch funtionality
57*cdf0e10cSrcweir #define SPECIALPROTOCOL_UNO               DECLARE_ASCII(".uno:"          )       // external representation of the slot protocol using names instead of id's
58*cdf0e10cSrcweir #define SPECIALPROTOCOL_MACRO             DECLARE_ASCII("macro:"         )       // special sfx protocol to execute macros
59*cdf0e10cSrcweir #define SPECIALPROTOCOL_SERVICE           DECLARE_ASCII("service:"       )       // generic way to start uno services during dispatch
60*cdf0e10cSrcweir #define SPECIALPROTOCOL_MAILTO            DECLARE_ASCII("mailto:"        )       // for sending mails
61*cdf0e10cSrcweir #define SPECIALPROTOCOL_NEWS              DECLARE_ASCII("news:"          )       // for sending news
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir class ProtocolCheck
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     public:
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     //_______________________________________________________________________
68*cdf0e10cSrcweir     /**
69*cdf0e10cSrcweir         enums for well known protocols
70*cdf0e10cSrcweir      */
71*cdf0e10cSrcweir     enum EProtocol
72*cdf0e10cSrcweir     {
73*cdf0e10cSrcweir         E_UNKNOWN_PROTOCOL  ,
74*cdf0e10cSrcweir         E_PRIVATE           ,
75*cdf0e10cSrcweir         E_PRIVATE_OBJECT    ,
76*cdf0e10cSrcweir         E_PRIVATE_STREAM    ,
77*cdf0e10cSrcweir         E_PRIVATE_FACTORY   ,
78*cdf0e10cSrcweir         E_SLOT              ,
79*cdf0e10cSrcweir         E_UNO               ,
80*cdf0e10cSrcweir         E_MACRO             ,
81*cdf0e10cSrcweir         E_SERVICE           ,
82*cdf0e10cSrcweir         E_MAILTO            ,
83*cdf0e10cSrcweir         E_NEWS
84*cdf0e10cSrcweir     };
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     //_______________________________________________________________________
87*cdf0e10cSrcweir     /**
88*cdf0e10cSrcweir         it checks, if the given URL string match one of the well known protocols.
89*cdf0e10cSrcweir         It returns the right enum value.
90*cdf0e10cSrcweir         Protocols are defined above ...
91*cdf0e10cSrcweir      */
92*cdf0e10cSrcweir     static EProtocol specifyProtocol( const ::rtl::OUString& sURL )
93*cdf0e10cSrcweir     {
94*cdf0e10cSrcweir         // because "private:" is part of e.g. "private:object" too ...
95*cdf0e10cSrcweir         // we must check it before all other ones!!!
96*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_PRIVATE,SPECIALPROTOCOL_PRIVATE.getLength()) == 0)
97*cdf0e10cSrcweir             return E_PRIVATE;
98*cdf0e10cSrcweir         else
99*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_OBJECT,SPECIALPROTOCOL_PRIVATE_OBJECT.getLength()) == 0)
100*cdf0e10cSrcweir             return E_PRIVATE_OBJECT;
101*cdf0e10cSrcweir         else
102*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_STREAM,SPECIALPROTOCOL_PRIVATE_STREAM.getLength()) == 0)
103*cdf0e10cSrcweir             return E_PRIVATE_STREAM;
104*cdf0e10cSrcweir         else
105*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_FACTORY,SPECIALPROTOCOL_PRIVATE_FACTORY.getLength()) == 0)
106*cdf0e10cSrcweir             return E_PRIVATE_FACTORY;
107*cdf0e10cSrcweir         else
108*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_SLOT,SPECIALPROTOCOL_SLOT.getLength()) == 0)
109*cdf0e10cSrcweir             return E_SLOT;
110*cdf0e10cSrcweir         else
111*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_UNO,SPECIALPROTOCOL_UNO.getLength()) == 0)
112*cdf0e10cSrcweir             return E_UNO;
113*cdf0e10cSrcweir         else
114*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_MACRO,SPECIALPROTOCOL_MACRO.getLength()) == 0)
115*cdf0e10cSrcweir             return E_MACRO;
116*cdf0e10cSrcweir         else
117*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_SERVICE,SPECIALPROTOCOL_SERVICE.getLength()) == 0)
118*cdf0e10cSrcweir             return E_SERVICE;
119*cdf0e10cSrcweir         else
120*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_MAILTO,SPECIALPROTOCOL_MAILTO.getLength()) == 0)
121*cdf0e10cSrcweir             return E_MAILTO;
122*cdf0e10cSrcweir         else
123*cdf0e10cSrcweir         if (sURL.compareTo(SPECIALPROTOCOL_NEWS,SPECIALPROTOCOL_NEWS.getLength()) == 0)
124*cdf0e10cSrcweir             return E_NEWS;
125*cdf0e10cSrcweir         else
126*cdf0e10cSrcweir             return E_UNKNOWN_PROTOCOL;
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     //_______________________________________________________________________
130*cdf0e10cSrcweir     /**
131*cdf0e10cSrcweir         it checks if given URL match the required protocol only
132*cdf0e10cSrcweir         It should be used instead of specifyProtocol() if only this question
133*cdf0e10cSrcweir         is interesting to perform the code. We must not check for all possible protocols here...
134*cdf0e10cSrcweir      */
135*cdf0e10cSrcweir     static sal_Bool isProtocol( const ::rtl::OUString& sURL, EProtocol eRequired )
136*cdf0e10cSrcweir     {
137*cdf0e10cSrcweir         switch(eRequired)
138*cdf0e10cSrcweir         {
139*cdf0e10cSrcweir             case E_PRIVATE           : return (sURL.compareTo(SPECIALPROTOCOL_PRIVATE        ,SPECIALPROTOCOL_PRIVATE.getLength()        ) == 0);
140*cdf0e10cSrcweir             case E_PRIVATE_OBJECT    : return (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_OBJECT ,SPECIALPROTOCOL_PRIVATE_OBJECT.getLength() ) == 0);
141*cdf0e10cSrcweir             case E_PRIVATE_STREAM    : return (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_STREAM ,SPECIALPROTOCOL_PRIVATE_STREAM.getLength() ) == 0);
142*cdf0e10cSrcweir             case E_PRIVATE_FACTORY   : return (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_FACTORY,SPECIALPROTOCOL_PRIVATE_FACTORY.getLength()) == 0);
143*cdf0e10cSrcweir             case E_SLOT              : return (sURL.compareTo(SPECIALPROTOCOL_SLOT           ,SPECIALPROTOCOL_SLOT.getLength()           ) == 0);
144*cdf0e10cSrcweir             case E_UNO               : return (sURL.compareTo(SPECIALPROTOCOL_UNO            ,SPECIALPROTOCOL_UNO.getLength()            ) == 0);
145*cdf0e10cSrcweir             case E_MACRO             : return (sURL.compareTo(SPECIALPROTOCOL_MACRO          ,SPECIALPROTOCOL_MACRO.getLength()          ) == 0);
146*cdf0e10cSrcweir             case E_SERVICE           : return (sURL.compareTo(SPECIALPROTOCOL_SERVICE        ,SPECIALPROTOCOL_SERVICE.getLength()        ) == 0);
147*cdf0e10cSrcweir             case E_MAILTO            : return (sURL.compareTo(SPECIALPROTOCOL_MAILTO         ,SPECIALPROTOCOL_MAILTO.getLength()         ) == 0);
148*cdf0e10cSrcweir             case E_NEWS              : return (sURL.compareTo(SPECIALPROTOCOL_NEWS           ,SPECIALPROTOCOL_NEWS.getLength()           ) == 0);
149*cdf0e10cSrcweir             default                  : return sal_False;
150*cdf0e10cSrcweir         }
151*cdf0e10cSrcweir         return sal_False;
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir };
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir } // namespace framework
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_PROTOCOLS_H_
158