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