update credits
[LibreOffice.git] / framework / inc / protocols.h
blobee393b44789e474b76849952b993952b5c44bd97
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 /*TODO outline this implementation :-) */
22 #ifndef __FRAMEWORK_PROTOCOLS_H_
23 #define __FRAMEWORK_PROTOCOLS_H_
25 #include <rtl/ustring.hxx>
27 namespace framework{
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.
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:"
57 class ProtocolCheck
59 public:
61 //_______________________________________________________________________
62 /**
63 enums for well known protocols
65 enum EProtocol
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
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 ...
86 static EProtocol specifyProtocol( const OUString& sURL )
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;
123 //_______________________________________________________________________
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...
129 static sal_Bool isProtocol( const OUString& sURL, EProtocol eRequired )
131 sal_Bool bRet = sal_False;
132 switch(eRequired)
134 case E_PRIVATE:
135 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE));
136 break;
137 case E_PRIVATE_OBJECT:
138 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_OBJECT));
139 break;
140 case E_PRIVATE_STREAM:
141 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_STREAM));
142 break;
143 case E_PRIVATE_FACTORY:
144 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_FACTORY));
145 break;
146 case E_SLOT:
147 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_SLOT));
148 break;
149 case E_UNO:
150 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_UNO));
151 break;
152 case E_MACRO:
153 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_MACRO));
154 break;
155 case E_SERVICE:
156 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_SERVICE));
157 break;
158 case E_MAILTO:
159 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_MAILTO));
160 break;
161 case E_NEWS:
162 bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_NEWS));
163 break;
164 default:
165 bRet = sal_False;
166 break;
168 return bRet;
172 } // namespace framework
174 #endif // #ifndef __FRAMEWORK_PROTOCOLS_H_
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */