LibreOffice Module framework (master) 1
joburl.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <cstring>
23
24#include <jobs/joburl.hxx>
25
26#include <vcl/svapp.hxx>
27#include <o3tl/string_view.hxx>
28
29namespace framework{
30
42JobURL::JobURL( /*IN*/ const OUString& sURL )
43{
45
46 // syntax: vnd.sun.star.job:{[event=<name>],[alias=<name>],[service=<name>]}
47
48 // check for "vnd.sun.star.job:"
49 if (!sURL.startsWithIgnoreAsciiCase("vnd.sun.star.job:"))
50 return;
51
52 sal_Int32 t = std::strlen("vnd.sun.star.job:");
53 do
54 {
55 // separate all token of "{[event=<name>],[alias=<name>],[service=<name>]}"
56 OUString sToken = sURL.getToken(0, JOBURL_PART_SEPARATOR, t);
57 OUString sPartValue;
58 OUString sPartArguments;
59
60 // check for "event="
61 if (
62 (JobURL::implst_split(sToken,JOBURL_EVENT_STR,JOBURL_EVENT_LEN,sPartValue,sPartArguments)) &&
63 (!sPartValue.isEmpty())
64 )
65 {
66 // set the part value
67 m_sEvent = sPartValue;
69 }
70 else
71 // check for "alias="
72 if (
73 (JobURL::implst_split(sToken,JOBURL_ALIAS_STR,JOBURL_ALIAS_LEN,sPartValue,sPartArguments)) &&
74 (!sPartValue.isEmpty())
75 )
76 {
77 // set the part value
78 m_sAlias = sPartValue;
80 }
81 else
82 // check for "service="
83 if (
84 (JobURL::implst_split(sToken,JOBURL_SERVICE_STR,JOBURL_SERVICE_LEN,sPartValue,sPartArguments)) &&
85 (!sPartValue.isEmpty())
86 )
87 {
88 // set the part value
89 m_sService = sPartValue;
91 }
92 }
93 while(t!=-1);
94}
95
101bool JobURL::isValid() const
102{
103 return (m_eRequest!=E_UNKNOWN);
104}
105
122bool JobURL::getEvent( /*OUT*/ OUString& sEvent ) const
123{
124 sEvent.clear();
125 bool bSet = ((m_eRequest & E_EVENT) == E_EVENT);
126 if (bSet)
127 sEvent = m_sEvent;
128
129 return bSet;
130}
131
148bool JobURL::getAlias( /*OUT*/ OUString& sAlias ) const
149{
150 sAlias.clear();
151 bool bSet = ((m_eRequest & E_ALIAS) == E_ALIAS);
152 if (bSet)
153 sAlias = m_sAlias;
154
155 return bSet;
156}
157
174bool JobURL::getService( /*OUT*/ OUString& sService ) const
175{
176 sService.clear();
177 bool bSet = ((m_eRequest & E_SERVICE) == E_SERVICE);
178 if (bSet)
179 sService = m_sService;
180
181 return bSet;
182}
183
209bool JobURL::implst_split( /*IN*/ std::u16string_view sPart ,
210 /*IN*/ const char* pPartIdentifier ,
211 /*IN*/ sal_Int32 nPartLength ,
212 /*OUT*/ OUString& rPartValue ,
213 /*OUT*/ OUString& rPartArguments )
214{
215 // first search for the given identifier
216 bool bPartFound = o3tl::matchIgnoreAsciiCase(sPart, std::string_view(pPartIdentifier,nPartLength));
217
218 // If it exist - we can split the part and return sal_True.
219 // Otherwise we do nothing and return sal_False.
220 if (bPartFound)
221 {
222 // But may the part has optional arguments - separated by a "?".
223 // Do so - we set the return value with the whole part string.
224 // Arguments will be set to an empty string as default.
225 // If we detect the right sign - we split the arguments and overwrite the default.
226 std::u16string_view sValueAndArguments = sPart.substr(nPartLength);
227 std::u16string_view sValue = sValueAndArguments;
228 OUString sArguments;
229
230 size_t nArgStart = sValueAndArguments.find('?');
231 if (nArgStart != std::u16string_view::npos)
232 {
233 sValue = sValueAndArguments.substr(0,nArgStart);
234 ++nArgStart; // ignore '?'!
235 sArguments = sValueAndArguments.substr(nArgStart);
236 }
237
238 rPartValue = sValue;
239 rPartArguments = sArguments;
240 }
241
242 return bPartFound;
243}
244
245} // namespace framework
246
247/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
bool getService(OUString &sService) const
get the service item of this job URL @descr Because the three possible parts of such URL (event,...
Definition: joburl.cxx:174
bool isValid() const
knows, if this job URL object hold a valid URL inside
Definition: joburl.cxx:101
bool getEvent(OUString &sEvent) const
get the event item of this job URL @descr Because the three possible parts of such URL (event,...
Definition: joburl.cxx:122
OUString m_sAlias
holds the alias part of a job URL
Definition: joburl.hxx:80
@ E_ALIAS
it's an alias
Definition: joburl.hxx:64
@ E_EVENT
it's an event
Definition: joburl.hxx:62
@ E_SERVICE
it's a service
Definition: joburl.hxx:66
@ E_UNKNOWN
mark a job URL as not valid
Definition: joburl.hxx:60
bool getAlias(OUString &sAlias) const
get the alias item of this job URL @descr Because the three possible parts of such URL (event,...
Definition: joburl.cxx:148
OUString m_sEvent
holds the event part of a job URL
Definition: joburl.hxx:77
static bool implst_split(std::u16string_view sPart, const char *pPartIdentifier, sal_Int32 nPartLength, OUString &rPartValue, OUString &rPartArguments)
searches for a special identifier in the given string and split it @descr If the given identifier cou...
Definition: joburl.cxx:209
JobURL(const OUString &sURL)
special ctor @descr It initialize this new instance with a (hopefully) valid job URL.
Definition: joburl.cxx:42
OUString m_sService
holds the service part of a job URL
Definition: joburl.hxx:83
sal_uInt32 m_eRequest
knows the state of this URL instance
Definition: joburl.hxx:74
#define JOBURL_SERVICE_STR
Definition: joburl.hxx:32
#define JOBURL_EVENT_LEN
Definition: joburl.hxx:27
#define JOBURL_PART_SEPARATOR
Definition: joburl.hxx:35
#define JOBURL_ALIAS_LEN
Definition: joburl.hxx:30
#define JOBURL_SERVICE_LEN
Definition: joburl.hxx:33
#define JOBURL_ALIAS_STR
Definition: joburl.hxx:29
#define JOBURL_EVENT_STR
Definition: joburl.hxx:26
bool matchIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2, sal_Int32 fromIndex=0)