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