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 SVTOOLS_URIHELPER_HXX
21 #define SVTOOLS_URIHELPER_HXX
23 #include "svl/svldllapi.h"
24 #include "com/sun/star/uno/Reference.hxx"
25 #include <com/sun/star/uno/RuntimeException.hpp>
26 #include <rtl/textenc.h>
27 #include <tools/link.hxx>
28 #include <tools/solar.h>
29 #include <tools/urlobj.hxx>
31 namespace com
{ namespace sun
{ namespace star
{
32 namespace uno
{ class XComponentContext
; }
33 namespace uri
{ class XUriReference
; }
38 //============================================================================
43 Calling this function with defaulted arguments rMaybeFileHdl = Link() and
44 bCheckFileExists = true often leads to results that are not intended:
45 Whenever the given rTheBaseURIRef is a file URL, the given rTheRelURIRef is
46 relative, and rTheRelURIRef could also be smart-parsed as a non-file URL
47 (e.g., the relative URL "foo/bar" can be smart-parsed as "http://foo/bar"),
48 then SmartRel2Abs called with rMaybeFileHdl = Link() and bCheckFileExists =
49 true returns the non-file URL interpretation. To avoid this, either pass
50 some non-null rMaybeFileHdl if you want to check generated file URLs for
51 existence (see URIHelper::GetMaybeFileHdl), or use bCheckFileExists = false
52 if you want to generate file URLs without checking for their existence.
54 SVL_DLLPUBLIC OUString
SmartRel2Abs(INetURLObject
const & rTheBaseURIRef
,
55 OUString
const & rTheRelURIRef
,
56 Link
const & rMaybeFileHdl
= Link(),
57 bool bCheckFileExists
= true,
58 bool bIgnoreFragment
= false,
59 INetURLObject::EncodeMechanism eEncodeMechanism
= INetURLObject::WAS_ENCODED
,
60 INetURLObject::DecodeMechanism eDecodeMechanism
= INetURLObject::DECODE_TO_IURI
,
61 rtl_TextEncoding eCharset
= RTL_TEXTENCODING_UTF8
,
62 bool bRelativeNonURIs
= false,
63 INetURLObject::FSysStyle eStyle
= INetURLObject::FSYS_DETECT
);
65 //============================================================================
66 SVL_DLLPUBLIC
void SetMaybeFileHdl(Link
const & rTheMaybeFileHdl
);
68 //============================================================================
69 SVL_DLLPUBLIC Link
GetMaybeFileHdl();
72 Converts a URI reference to a relative one, ignoring certain differences (for
73 example, treating file URLs for case-ignoring file systems
76 @param context a component context; must not be null
78 @param baseUriReference a base URI reference
80 @param uriReference a URI reference
82 @return a URI reference representing the given uriReference relative to the
83 given baseUriReference; if the given baseUriReference is not an absolute,
84 hierarchical URI reference, or the given uriReference is not a valid URI
85 reference, null is returned
87 @exception std::bad_alloc if an out-of-memory condition occurs
89 @exception com::sun::star::uno::RuntimeException if any error occurs
91 SVL_DLLPUBLIC
com::sun::star::uno::Reference
< com::sun::star::uri::XUriReference
>
92 normalizedMakeRelative(
93 com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
>
95 OUString
const & baseUriReference
, OUString
const & uriReference
);
98 A variant of normalizedMakeRelative with a simplified interface.
100 Internally calls normalizedMakeRelative with the default component context.
102 @param baseUriReference a base URI reference, passed to
103 normalizedMakeRelative
105 @param uriReference a URI reference, passed to normalizedMakeRelative
107 @return if the XUriReference returnd by normalizedMakeRelative is empty,
108 uriReference is returned unmodified; otherwise, the result of calling
109 XUriReference::getUriReference on the XUriReference returnd by
110 normalizedMakeRelative is returned
112 @exception std::bad_alloc if an out-of-memory condition occurs
114 @exception com::sun::star::uno::RuntimeException if any error occurs
117 No code should rely on the default component context.
119 SVL_DLLPUBLIC OUString
simpleNormalizedMakeRelative( OUString
const & baseUriReference
,
120 OUString
const & uriReference
);
122 //============================================================================
123 SVL_DLLPUBLIC OUString
FindFirstURLInText(OUString
const & rText
,
126 CharClass
const & rCharClass
,
127 INetURLObject::EncodeMechanism eMechanism
= INetURLObject::WAS_ENCODED
,
128 rtl_TextEncoding eCharset
= RTL_TEXTENCODING_UTF8
,
129 INetURLObject::FSysStyle eStyle
= INetURLObject::FSYS_DETECT
);
131 //============================================================================
132 /** Remove any password component from both absolute and relative URLs.
134 @ATT The current implementation will not remove a password from a
135 relative URL that has an authority component (e.g., the password is not
136 removed from the relative ftp URL <//user:password@domain/path>). But
137 since our functions to translate between absolute and relative URLs never
138 produce relative URLs with authority components, this is no real problem.
140 @ATT For relative URLs (or anything not recognized as an absolute URI),
141 the current implementation will return the input unmodified, not applying
142 any translations implied by the encode/decode parameters.
144 @param rURI An absolute or relative URI reference.
146 @param eEncodeMechanism See the general discussion for INetURLObject set-
149 @param eDecodeMechanism See the general discussion for INetURLObject get-
152 @param eCharset See the general discussion for INetURLObject get- and
155 @return The input URI with any password component removed.
157 SVL_DLLPUBLIC OUString
removePassword(OUString
const & rURI
,
158 INetURLObject::EncodeMechanism eEncodeMechanism
= INetURLObject::WAS_ENCODED
,
159 INetURLObject::DecodeMechanism eDecodeMechanism
= INetURLObject::DECODE_TO_IURI
,
160 rtl_TextEncoding eCharset
= RTL_TEXTENCODING_UTF8
);
163 #endif // SVTOOLS_URIHELPER_HXX
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */