1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_CPPUHELPER_UNOURL_HXX
21 #define INCLUDED_CPPUHELPER_UNOURL_HXX
23 #include "sal/config.h"
25 #include "cppuhelper/cppuhelperdllapi.h"
27 namespace rtl
{ class OUString
; }
31 /** A descriptor as part of a UNO URL (connection descriptor or protocol
34 Such a descriptor can also be useful outside the context of a full UNO URL.
35 For example, some functions take a string representing a connection or
36 protocol descriptor as input, and can use this class to parse the string.
38 class SAL_WARN_UNUSED CPPUHELPER_DLLPUBLIC UnoUrlDescriptor
43 /** Construct a descriptor from a string representation.
46 The string representation of a descriptor.
48 @exception rtl::MalformedUriException
49 Thrown when the given string representation is invalid.
51 explicit UnoUrlDescriptor(rtl::OUString
const & rDescriptor
);
53 UnoUrlDescriptor(UnoUrlDescriptor
const & rOther
);
57 UnoUrlDescriptor
& operator =(UnoUrlDescriptor
const & rOther
);
59 /** Return the string representation of the descriptor.
62 A reference to the string representation used to construct this
63 descriptor, without any modifications. The reference is valid for the
64 lifetime of this URL object.
66 rtl::OUString
const & getDescriptor() const;
68 /** Return the name component of the descriptor.
71 A reference to the (case insensitive) name, in lower case form. The
72 reference is valid for the lifetime of this URL object.
74 rtl::OUString
const & getName() const;
76 /** Test whether the parameters contain a key.
79 rKey A (case insensitive) key.
82 True if the parameters contain a matching key/value pair.
84 bool hasParameter(rtl::OUString
const & rKey
) const;
86 /** Return the parameter value for a key.
89 rKey A (case insensitive) key.
92 The (case sensitive) value associated with the given key, or an empty
93 string if there is no matching key/value pair.
95 rtl::OUString
getParameter(rtl::OUString
const & rKey
) const;
101 /** Parse UNO URLs into their components.
103 The ABNF for UNO URLs is as follows (see RFCs 2234, 2396, also see
104 <http://udk.openoffice.org/common/man/spec/uno-url.html>):
106 uno-url = "UNO:" connection ";" protocol ";" object-name
107 connection = descriptor
108 protocol = descriptor
109 descriptor = name *("," parameter)
111 parameter = key "=" value
114 valchar = unreserved / escaped / "$" / "&" / "+" / "/" / ":" / "?" / "@"
115 object-name = 1*ochar
116 ochar = unreserved / "$" / "&" / "+" / "," / "/" / ":" / "=" / "?" / "@"
118 Within a descriptor, the name and the keys are case insensitive, and within
119 the parameter list all keys must be distinct.
121 Parameter values are encoded using UTF-8. Note that parsing of parameter
122 values as done by UnoUrl and UnoUrlDescriptor is not strict: Invalid UTF-16
123 entities in the input, as well as broken escape sequences ("%" not followed
124 by two hex digits) are copied verbatim to the output, invalid bytes in the
125 converted UTF-8 data are considered individual Unicode characters, and
126 invalid UTF-16 entities in the resulting output (e.g., a high surrogate not
127 followed by a low surrogate) are not detected.
129 class SAL_WARN_UNUSED CPPUHELPER_DLLPUBLIC UnoUrl
132 /** Construct a UNO URL from a string representation.
135 The string representation of a UNO URL.
137 @exception rtl::MalformedUriException
138 Thrown when the given string representation is invalid.
140 explicit UnoUrl(rtl::OUString
const & rUrl
);
142 UnoUrl(UnoUrl
const & rOther
);
146 UnoUrl
& operator =(UnoUrl
const & rOther
);
148 /** Return the connection descriptor component of the URL.
151 A reference to the connection descriptor. The reference is valid for
152 the lifetime of this URL object.
154 UnoUrlDescriptor
const & getConnection() const;
156 /** Return the protocol descriptor component of the URL.
159 A reference to the protocol descriptor. The reference is valid for the
160 lifetime of this URL object.
162 UnoUrlDescriptor
const & getProtocol() const;
164 /** Return the object-name component of the URL.
167 A reference to the (case sensitive) object-name. The reference is valid
168 for the lifetime of this URL object.
170 rtl::OUString
const & getObjectName() const;
180 #endif // INCLUDED_RTL_UNOURL_HXX
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */