/src/libreoffice/framework/inc/protocols.h
Line | Count | Source |
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 | | #pragma once |
23 | | |
24 | | #include <sal/config.h> |
25 | | |
26 | | #include <string_view> |
27 | | |
28 | | #include <o3tl/string_view.hxx> |
29 | | |
30 | | namespace framework{ |
31 | | |
32 | | /** |
33 | | some protocols must be checked during loading or dispatching URLs manually |
34 | | It can be necessary to decide, if a URL represent a non visible content or |
35 | | a real visible component. |
36 | | */ |
37 | | |
38 | | // indicates loading of components using a model directly |
39 | 0 | #define SPECIALPROTOCOL_PRIVATE_OBJECT u"private:object" |
40 | | // indicates loading of components using a stream only |
41 | 0 | #define SPECIALPROTOCOL_PRIVATE_STREAM u"private:stream" |
42 | | // indicates creation of empty documents |
43 | 0 | #define SPECIALPROTOCOL_PRIVATE_FACTORY u"private:factory" |
44 | | // internal protocol of the sfx project for generic dispatch functionality |
45 | 0 | #define SPECIALPROTOCOL_SLOT u"slot:" |
46 | | // external representation of the slot protocol using names instead of id's |
47 | 0 | #define SPECIALPROTOCOL_UNO u".uno:" |
48 | | // special sfx protocol to execute macros |
49 | 0 | #define SPECIALPROTOCOL_MACRO u"macro:" |
50 | | // generic way to start uno services during dispatch |
51 | 0 | #define SPECIALPROTOCOL_SERVICE u"service:" |
52 | | // for sending mails |
53 | 0 | #define SPECIALPROTOCOL_MAILTO u"mailto:" |
54 | | // for sending news |
55 | 0 | #define SPECIALPROTOCOL_NEWS u"news:" |
56 | | |
57 | | /** well known protocols */ |
58 | | enum class EProtocol |
59 | | { |
60 | | PrivateObject, |
61 | | PrivateStream, |
62 | | PrivateFactory, |
63 | | Slot, |
64 | | Uno, |
65 | | Macro, |
66 | | Service, |
67 | | MailTo, |
68 | | News |
69 | | }; |
70 | | |
71 | | class ProtocolCheck |
72 | | { |
73 | | public: |
74 | | |
75 | | /** |
76 | | it checks if given URL match the required protocol only |
77 | | It should be used instead of specifyProtocol() if only this question |
78 | | is interesting to perform the code. We must not check for all possible protocols here... |
79 | | */ |
80 | | static bool isProtocol( std::u16string_view sURL, EProtocol eRequired ) |
81 | 0 | { |
82 | 0 | bool bRet = false; |
83 | 0 | switch(eRequired) |
84 | 0 | { |
85 | 0 | case EProtocol::PrivateObject: |
86 | 0 | bRet = o3tl::starts_with(sURL, SPECIALPROTOCOL_PRIVATE_OBJECT); |
87 | 0 | break; |
88 | 0 | case EProtocol::PrivateStream: |
89 | 0 | bRet = o3tl::starts_with(sURL, SPECIALPROTOCOL_PRIVATE_STREAM); |
90 | 0 | break; |
91 | 0 | case EProtocol::PrivateFactory: |
92 | 0 | bRet = o3tl::starts_with(sURL, SPECIALPROTOCOL_PRIVATE_FACTORY); |
93 | 0 | break; |
94 | 0 | case EProtocol::Slot: |
95 | 0 | bRet = o3tl::starts_with(sURL, SPECIALPROTOCOL_SLOT); |
96 | 0 | break; |
97 | 0 | case EProtocol::Uno: |
98 | 0 | bRet = o3tl::starts_with(sURL, SPECIALPROTOCOL_UNO); |
99 | 0 | break; |
100 | 0 | case EProtocol::Macro: |
101 | 0 | bRet = o3tl::starts_with(sURL, SPECIALPROTOCOL_MACRO); |
102 | 0 | break; |
103 | 0 | case EProtocol::Service: |
104 | 0 | bRet = o3tl::starts_with(sURL, SPECIALPROTOCOL_SERVICE); |
105 | 0 | break; |
106 | 0 | case EProtocol::MailTo: |
107 | 0 | bRet = o3tl::starts_with(sURL, SPECIALPROTOCOL_MAILTO); |
108 | 0 | break; |
109 | 0 | case EProtocol::News: |
110 | 0 | bRet = o3tl::starts_with(sURL, SPECIALPROTOCOL_NEWS); |
111 | 0 | break; |
112 | 0 | default: |
113 | 0 | bRet = false; |
114 | 0 | break; |
115 | 0 | } |
116 | 0 | return bRet; |
117 | 0 | } |
118 | | }; |
119 | | |
120 | | } // namespace framework |
121 | | |
122 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |