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
24 #include "cppuhelperdllapi.h"
26 namespace rtl
{ class OUString
; }
30 /** A descriptor as part of a UNO URL (connection descriptor or protocol
33 Such a descriptor can also be useful outside the context of a full UNO URL.
34 For example, some functions take a string representing a connection or
35 protocol descriptor as input, and can use this class to parse the string.
37 class CPPUHELPER_DLLPUBLIC UnoUrlDescriptor
42 /** Construct a descriptor from a string representation.
45 The string representation of a descriptor.
47 @exception rtl::MalformedUriException
48 Thrown when the given string representation is invalid.
50 explicit UnoUrlDescriptor(rtl::OUString
const & rDescriptor
);
53 explicit UnoUrlDescriptor(std::auto_ptr
< Impl
> & rImpl
);
56 UnoUrlDescriptor(UnoUrlDescriptor
const & rOther
);
60 UnoUrlDescriptor
& operator =(UnoUrlDescriptor
const & rOther
);
62 /** Return the string representation of the descriptor.
65 A reference to the string representation used to construct this
66 descriptor, without any modifications. The reference is valid for the
67 lifetime of this URL object.
69 rtl::OUString
const & getDescriptor() const;
71 /** Return the name component of the descriptor.
74 A reference to the (case insensitive) name, in lower case form. The
75 reference is valid for the lifetime of this URL object.
77 rtl::OUString
const & getName() const;
79 /** Test whether the parameters contain a key.
82 rKey A (case insensitive) key.
85 True if the parameters contain a matching key/value pair.
87 bool hasParameter(rtl::OUString
const & rKey
) const;
89 /** Return the parameter value for a key.
92 rKey A (case insensitive) key.
95 The (case sensitive) value associated with the given key, or an empty
96 string if there is no matching key/value pair.
98 rtl::OUString
getParameter(rtl::OUString
const & rKey
) const;
101 std::auto_ptr
< Impl
> m_xImpl
;
104 /** Parse UNO URLs into their components.
106 The ABNF for UNO URLs is as follows (see RFCs 2234, 2396, also see
107 <http://udk.openoffice.org/common/man/spec/uno-url.html>):
109 uno-url = "UNO:" connection ";" protocol ";" object-name
110 connection = descriptor
111 protocol = descriptor
112 descriptor = name *("," parameter)
114 parameter = key "=" value
117 valchar = unreserved / escaped / "$" / "&" / "+" / "/" / ":" / "?" / "@"
118 object-name = 1*ochar
119 ochar = unreserved / "$" / "&" / "+" / "," / "/" / ":" / "=" / "?" / "@"
121 Within a descriptor, the name and the keys are case insensitive, and within
122 the parameter list all keys must be distinct.
124 Parameter values are encoded using UTF-8. Note that parsing of parameter
125 values as done by UnoUrl and UnoUrlDescriptor is not strict: Invalid UTF-16
126 entities in the input, as well as broken escape sequences ("%" not followed
127 by two hex digits) are copied verbatim to the output, invalid bytes in the
128 converted UTF-8 data are considered individual Unicode characters, and
129 invalid UTF-16 entities in the resulting output (e.g., a high surrogate not
130 followed by a low surrogate) are not detected.
132 class CPPUHELPER_DLLPUBLIC UnoUrl
135 /** Construct a UNO URL from a string representation.
138 The string representation of a UNO URL.
140 @exception rtl::MalformedUriException
141 Thrown when the given string representation is invalid.
143 explicit UnoUrl(rtl::OUString
const & rUrl
);
145 UnoUrl(UnoUrl
const & rOther
);
149 UnoUrl
& operator =(UnoUrl
const & rOther
);
151 /** Return the connection descriptor component of the URL.
154 A reference to the connection descriptor. The reference is valid for
155 the lifetime of this URL object.
157 UnoUrlDescriptor
const & getConnection() const;
159 /** Return the protocol descriptor component of the URL.
162 A reference to the protocol descriptor. The reference is valid for the
163 lifetime of this URL object.
165 UnoUrlDescriptor
const & getProtocol() const;
167 /** Return the object-name component of the URL.
170 A reference to the (case sensitive) object-name. The reference is valid
171 for the lifetime of this URL object.
173 rtl::OUString
const & getObjectName() const;
178 std::auto_ptr
< Impl
> m_xImpl
;
183 #endif // INCLUDED_RTL_UNOURL_HXX
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */