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