xref: /aoo4110/main/framework/inc/protocols.h (revision b1cdbd2c)
1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski /*TODO outline this implementation :-) */
25*b1cdbd2cSJim Jagielski 
26*b1cdbd2cSJim Jagielski #ifndef __FRAMEWORK_PROTOCOLS_H_
27*b1cdbd2cSJim Jagielski #define __FRAMEWORK_PROTOCOLS_H_
28*b1cdbd2cSJim Jagielski 
29*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
30*b1cdbd2cSJim Jagielski //	includes
31*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
32*b1cdbd2cSJim Jagielski 
33*b1cdbd2cSJim Jagielski #include <macros/generic.hxx>
34*b1cdbd2cSJim Jagielski 
35*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
36*b1cdbd2cSJim Jagielski //	namespace
37*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
38*b1cdbd2cSJim Jagielski 
39*b1cdbd2cSJim Jagielski namespace framework{
40*b1cdbd2cSJim Jagielski 
41*b1cdbd2cSJim Jagielski //_______________________________________________________________________
42*b1cdbd2cSJim Jagielski /**
43*b1cdbd2cSJim Jagielski     some protocols must be checked during loading or dispatching URLs manually
44*b1cdbd2cSJim Jagielski     It can be neccessary to decide, if a URL represent a non visible content or
45*b1cdbd2cSJim Jagielski     a real visible component.
46*b1cdbd2cSJim Jagielski  */
47*b1cdbd2cSJim Jagielski 
48*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_PRIVATE           DECLARE_ASCII("private:"       )       // indicates a loadable content in general!
49*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_PRIVATE_OBJECT    DECLARE_ASCII("private:object" )       // indicates loading of components using a model directly
50*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_PRIVATE_STREAM    DECLARE_ASCII("private:stream" )       // indicates loading of components using a stream only
51*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_PRIVATE_FACTORY   DECLARE_ASCII("private:factory")       // indicates creation of empty documents
52*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_SLOT              DECLARE_ASCII("slot:"          )       // internal protocol of the sfx project for generic dispatch funtionality
53*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_UNO               DECLARE_ASCII(".uno:"          )       // external representation of the slot protocol using names instead of id's
54*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_MACRO             DECLARE_ASCII("macro:"         )       // special sfx protocol to execute macros
55*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_SERVICE           DECLARE_ASCII("service:"       )       // generic way to start uno services during dispatch
56*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_MAILTO            DECLARE_ASCII("mailto:"        )       // for sending mails
57*b1cdbd2cSJim Jagielski #define SPECIALPROTOCOL_NEWS              DECLARE_ASCII("news:"          )       // for sending news
58*b1cdbd2cSJim Jagielski 
59*b1cdbd2cSJim Jagielski class ProtocolCheck
60*b1cdbd2cSJim Jagielski {
61*b1cdbd2cSJim Jagielski     public:
62*b1cdbd2cSJim Jagielski 
63*b1cdbd2cSJim Jagielski     //_______________________________________________________________________
64*b1cdbd2cSJim Jagielski     /**
65*b1cdbd2cSJim Jagielski         enums for well known protocols
66*b1cdbd2cSJim Jagielski      */
67*b1cdbd2cSJim Jagielski     enum EProtocol
68*b1cdbd2cSJim Jagielski     {
69*b1cdbd2cSJim Jagielski         E_UNKNOWN_PROTOCOL  ,
70*b1cdbd2cSJim Jagielski         E_PRIVATE           ,
71*b1cdbd2cSJim Jagielski         E_PRIVATE_OBJECT    ,
72*b1cdbd2cSJim Jagielski         E_PRIVATE_STREAM    ,
73*b1cdbd2cSJim Jagielski         E_PRIVATE_FACTORY   ,
74*b1cdbd2cSJim Jagielski         E_SLOT              ,
75*b1cdbd2cSJim Jagielski         E_UNO               ,
76*b1cdbd2cSJim Jagielski         E_MACRO             ,
77*b1cdbd2cSJim Jagielski         E_SERVICE           ,
78*b1cdbd2cSJim Jagielski         E_MAILTO            ,
79*b1cdbd2cSJim Jagielski         E_NEWS
80*b1cdbd2cSJim Jagielski     };
81*b1cdbd2cSJim Jagielski 
82*b1cdbd2cSJim Jagielski     //_______________________________________________________________________
83*b1cdbd2cSJim Jagielski     /**
84*b1cdbd2cSJim Jagielski         it checks, if the given URL string match one of the well known protocols.
85*b1cdbd2cSJim Jagielski         It returns the right enum value.
86*b1cdbd2cSJim Jagielski         Protocols are defined above ...
87*b1cdbd2cSJim Jagielski      */
specifyProtocol(const::rtl::OUString & sURL)88*b1cdbd2cSJim Jagielski     static EProtocol specifyProtocol( const ::rtl::OUString& sURL )
89*b1cdbd2cSJim Jagielski     {
90*b1cdbd2cSJim Jagielski         // because "private:" is part of e.g. "private:object" too ...
91*b1cdbd2cSJim Jagielski         // we must check it before all other ones!!!
92*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_PRIVATE,SPECIALPROTOCOL_PRIVATE.getLength()) == 0)
93*b1cdbd2cSJim Jagielski             return E_PRIVATE;
94*b1cdbd2cSJim Jagielski         else
95*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_OBJECT,SPECIALPROTOCOL_PRIVATE_OBJECT.getLength()) == 0)
96*b1cdbd2cSJim Jagielski             return E_PRIVATE_OBJECT;
97*b1cdbd2cSJim Jagielski         else
98*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_STREAM,SPECIALPROTOCOL_PRIVATE_STREAM.getLength()) == 0)
99*b1cdbd2cSJim Jagielski             return E_PRIVATE_STREAM;
100*b1cdbd2cSJim Jagielski         else
101*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_FACTORY,SPECIALPROTOCOL_PRIVATE_FACTORY.getLength()) == 0)
102*b1cdbd2cSJim Jagielski             return E_PRIVATE_FACTORY;
103*b1cdbd2cSJim Jagielski         else
104*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_SLOT,SPECIALPROTOCOL_SLOT.getLength()) == 0)
105*b1cdbd2cSJim Jagielski             return E_SLOT;
106*b1cdbd2cSJim Jagielski         else
107*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_UNO,SPECIALPROTOCOL_UNO.getLength()) == 0)
108*b1cdbd2cSJim Jagielski             return E_UNO;
109*b1cdbd2cSJim Jagielski         else
110*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_MACRO,SPECIALPROTOCOL_MACRO.getLength()) == 0)
111*b1cdbd2cSJim Jagielski             return E_MACRO;
112*b1cdbd2cSJim Jagielski         else
113*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_SERVICE,SPECIALPROTOCOL_SERVICE.getLength()) == 0)
114*b1cdbd2cSJim Jagielski             return E_SERVICE;
115*b1cdbd2cSJim Jagielski         else
116*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_MAILTO,SPECIALPROTOCOL_MAILTO.getLength()) == 0)
117*b1cdbd2cSJim Jagielski             return E_MAILTO;
118*b1cdbd2cSJim Jagielski         else
119*b1cdbd2cSJim Jagielski         if (sURL.compareTo(SPECIALPROTOCOL_NEWS,SPECIALPROTOCOL_NEWS.getLength()) == 0)
120*b1cdbd2cSJim Jagielski             return E_NEWS;
121*b1cdbd2cSJim Jagielski         else
122*b1cdbd2cSJim Jagielski             return E_UNKNOWN_PROTOCOL;
123*b1cdbd2cSJim Jagielski     }
124*b1cdbd2cSJim Jagielski 
125*b1cdbd2cSJim Jagielski     //_______________________________________________________________________
126*b1cdbd2cSJim Jagielski     /**
127*b1cdbd2cSJim Jagielski         it checks if given URL match the required protocol only
128*b1cdbd2cSJim Jagielski         It should be used instead of specifyProtocol() if only this question
129*b1cdbd2cSJim Jagielski         is interesting to perform the code. We must not check for all possible protocols here...
130*b1cdbd2cSJim Jagielski      */
isProtocol(const::rtl::OUString & sURL,EProtocol eRequired)131*b1cdbd2cSJim Jagielski     static sal_Bool isProtocol( const ::rtl::OUString& sURL, EProtocol eRequired )
132*b1cdbd2cSJim Jagielski     {
133*b1cdbd2cSJim Jagielski         switch(eRequired)
134*b1cdbd2cSJim Jagielski         {
135*b1cdbd2cSJim Jagielski             case E_PRIVATE           : return (sURL.compareTo(SPECIALPROTOCOL_PRIVATE        ,SPECIALPROTOCOL_PRIVATE.getLength()        ) == 0);
136*b1cdbd2cSJim Jagielski             case E_PRIVATE_OBJECT    : return (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_OBJECT ,SPECIALPROTOCOL_PRIVATE_OBJECT.getLength() ) == 0);
137*b1cdbd2cSJim Jagielski             case E_PRIVATE_STREAM    : return (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_STREAM ,SPECIALPROTOCOL_PRIVATE_STREAM.getLength() ) == 0);
138*b1cdbd2cSJim Jagielski             case E_PRIVATE_FACTORY   : return (sURL.compareTo(SPECIALPROTOCOL_PRIVATE_FACTORY,SPECIALPROTOCOL_PRIVATE_FACTORY.getLength()) == 0);
139*b1cdbd2cSJim Jagielski             case E_SLOT              : return (sURL.compareTo(SPECIALPROTOCOL_SLOT           ,SPECIALPROTOCOL_SLOT.getLength()           ) == 0);
140*b1cdbd2cSJim Jagielski             case E_UNO               : return (sURL.compareTo(SPECIALPROTOCOL_UNO            ,SPECIALPROTOCOL_UNO.getLength()            ) == 0);
141*b1cdbd2cSJim Jagielski             case E_MACRO             : return (sURL.compareTo(SPECIALPROTOCOL_MACRO          ,SPECIALPROTOCOL_MACRO.getLength()          ) == 0);
142*b1cdbd2cSJim Jagielski             case E_SERVICE           : return (sURL.compareTo(SPECIALPROTOCOL_SERVICE        ,SPECIALPROTOCOL_SERVICE.getLength()        ) == 0);
143*b1cdbd2cSJim Jagielski             case E_MAILTO            : return (sURL.compareTo(SPECIALPROTOCOL_MAILTO         ,SPECIALPROTOCOL_MAILTO.getLength()         ) == 0);
144*b1cdbd2cSJim Jagielski             case E_NEWS              : return (sURL.compareTo(SPECIALPROTOCOL_NEWS           ,SPECIALPROTOCOL_NEWS.getLength()           ) == 0);
145*b1cdbd2cSJim Jagielski             default                  : return sal_False;
146*b1cdbd2cSJim Jagielski         }
147*b1cdbd2cSJim Jagielski         return sal_False;
148*b1cdbd2cSJim Jagielski     }
149*b1cdbd2cSJim Jagielski };
150*b1cdbd2cSJim Jagielski 
151*b1cdbd2cSJim Jagielski } // namespace framework
152*b1cdbd2cSJim Jagielski 
153*b1cdbd2cSJim Jagielski #endif // #ifndef __FRAMEWORK_PROTOCOLS_H_
154