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_SVL_URIHELPER_HXX
21 #define INCLUDED_SVL_URIHELPER_HXX
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/uno/RuntimeException.hpp>
25 #include <rtl/textenc.h>
26 #include <svl/svldllapi.h>
27 #include <tools/link.hxx>
28 #include <tools/urlobj.hxx>
30 namespace com
{ namespace sun
{ namespace star
{
31 namespace uno
{ class XComponentContext
; }
32 namespace uri
{ class XUriReference
; }
41 Calling this function with defaulted arguments rMaybeFileHdl = Link() and
42 bCheckFileExists = true often leads to results that are not intended:
43 Whenever the given rTheBaseURIRef is a file URL, the given rTheRelURIRef is
44 relative, and rTheRelURIRef could also be smart-parsed as a non-file URL
45 (e.g., the relative URL "foo/bar" can be smart-parsed as "http://foo/bar"),
46 then SmartRel2Abs called with rMaybeFileHdl = Link() and bCheckFileExists =
47 true returns the non-file URL interpretation. To avoid this, either pass
48 some non-null rMaybeFileHdl if you want to check generated file URLs for
49 existence (see URIHelper::GetMaybeFileHdl), or use bCheckFileExists = false
50 if you want to generate file URLs without checking for their existence.
52 SVL_DLLPUBLIC OUString
SmartRel2Abs(INetURLObject
const & rTheBaseURIRef
,
53 OUString
const & rTheRelURIRef
,
54 Link
<OUString
*, bool> const & rMaybeFileHdl
= Link
<OUString
*, bool>(),
55 bool bCheckFileExists
= true,
56 bool bIgnoreFragment
= false,
57 INetURLObject::EncodeMechanism eEncodeMechanism
= INetURLObject::EncodeMechanism::WasEncoded
,
58 INetURLObject::DecodeMechanism eDecodeMechanism
= INetURLObject::DecodeMechanism::ToIUri
,
59 rtl_TextEncoding eCharset
= RTL_TEXTENCODING_UTF8
,
60 bool bRelativeNonURIs
= false,
61 FSysStyle eStyle
= FSysStyle::Detect
);
63 SVL_DLLPUBLIC
void SetMaybeFileHdl(Link
<OUString
*, bool> const & rTheMaybeFileHdl
);
65 SVL_DLLPUBLIC Link
<OUString
*, bool> GetMaybeFileHdl();
68 Converts a URI reference to a relative one, ignoring certain differences (for
69 example, treating file URLs for case-ignoring file systems
72 @param context a component context; must not be null
74 @param baseUriReference a base URI reference
76 @param uriReference a URI reference
78 @return a URI reference representing the given uriReference relative to the
79 given baseUriReference; if the given baseUriReference is not an absolute,
80 hierarchical URI reference, or the given uriReference is not a valid URI
81 reference, null is returned
83 @exception std::bad_alloc if an out-of-memory condition occurs
85 @exception css::uno::RuntimeException if any error occurs
87 SVL_DLLPUBLIC
css::uno::Reference
< css::uri::XUriReference
>
88 normalizedMakeRelative(
89 css::uno::Reference
< css::uno::XComponentContext
> const & context
,
90 OUString
const & baseUriReference
,
91 OUString
const & uriReference
);
94 A variant of normalizedMakeRelative with a simplified interface.
96 Internally calls normalizedMakeRelative with the default component context.
98 @param baseUriReference a base URI reference, passed to
99 normalizedMakeRelative
101 @param uriReference a URI reference, passed to normalizedMakeRelative
103 @return if the XUriReference returned by normalizedMakeRelative is empty,
104 uriReference is returned unmodified; otherwise, the result of calling
105 XUriReference::getUriReference on the XUriReference returned by
106 normalizedMakeRelative is returned
108 @exception std::bad_alloc if an out-of-memory condition occurs
110 @exception css::uno::RuntimeException if any error occurs
113 No code should rely on the default component context.
115 SVL_DLLPUBLIC OUString
simpleNormalizedMakeRelative( OUString
const & baseUriReference
,
116 OUString
const & uriReference
);
118 SVL_DLLPUBLIC OUString
FindFirstURLInText(OUString
const & rText
,
121 CharClass
const & rCharClass
,
122 INetURLObject::EncodeMechanism eMechanism
= INetURLObject::EncodeMechanism::WasEncoded
,
123 rtl_TextEncoding eCharset
= RTL_TEXTENCODING_UTF8
);
125 /** Remove any password component from both absolute and relative URLs.
127 @ATT The current implementation will not remove a password from a
128 relative URL that has an authority component (e.g., the password is not
129 removed from the relative ftp URL <//user:password@domain/path>). But
130 since our functions to translate between absolute and relative URLs never
131 produce relative URLs with authority components, this is no real problem.
133 @ATT For relative URLs (or anything not recognized as an absolute URI),
134 the current implementation will return the input unmodified, not applying
135 any translations implied by the encode/decode parameters.
137 @param rURI An absolute or relative URI reference.
139 @param eEncodeMechanism See the general discussion for INetURLObject set-
142 @param eDecodeMechanism See the general discussion for INetURLObject get-
145 @param eCharset See the general discussion for INetURLObject get- and
148 @return The input URI with any password component removed.
150 SVL_DLLPUBLIC OUString
removePassword(OUString
const & rURI
,
151 INetURLObject::EncodeMechanism eEncodeMechanism
= INetURLObject::EncodeMechanism::WasEncoded
,
152 INetURLObject::DecodeMechanism eDecodeMechanism
= INetURLObject::DecodeMechanism::ToIUri
,
153 rtl_TextEncoding eCharset
= RTL_TEXTENCODING_UTF8
);
155 /** Resolve a URL's host component domain name in IDNA syntax to plain DNS
158 For details, see RFC 5890 "Internationalized Domain Names for Applications
159 (IDNA): Definitions and Document Framework."
161 @param: url An arbitrary string, should be a URI.
163 @return If the input matches the syntax of a hierarchical URL, and it has
164 a host component that matches the IDNA2008 domain name syntax, and that
165 domain name contains any U-labels, return a version of the input URL with
166 the host component resolved to plain DNS syntax. Otherwise, return the
169 SVL_DLLPUBLIC OUString
resolveIdnaHost(OUString
const & url
);
173 #endif // INCLUDED_SVL_URIHELPER_HXX
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */