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