sync master with lastest vba changes
[ooovba.git] / binfilter / inc / bf_svtools / urihelper.hxx
blob12383ee29aeceefa50534a4915fdc613506e03c1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: urihelper.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SVTOOLS_URIHELPER_HXX
32 #define SVTOOLS_URIHELPER_HXX
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <com/sun/star/uri/XUriReference.hpp>
36 #include <com/sun/star/uno/RuntimeException.hpp>
38 #include <rtl/textenc.h>
39 #include <rtl/ustring.hxx>
41 #include <unotools/charclass.hxx>
42 #include <tools/link.hxx>
43 #include <tools/solar.h>
44 #include <tools/urlobj.hxx>
45 #include <tools/string.hxx>
48 //============================================================================
49 namespace binfilter
52 /**
53 @ATT
54 Calling this function with defaulted arguments rMaybeFileHdl = Link() and
55 bCheckFileExists = true often leads to results that are not intended:
56 Whenever the given rTheBaseURIRef is a file URL, the given rTheRelURIRef is
57 relative, and rTheRelURIRef could also be smart-parsed as a non-file URL
58 (e.g., the relative URL "foo/bar" can be smart-parsed as "http://foo/bar"),
59 then SmartRel2Abs called with rMaybeFileHdl = Link() and bCheckFileExists =
60 true returns the non-file URL interpretation. To avoid this, either pass
61 some non-null rMaybeFileHdl if you want to check generated file URLs for
62 existence (see GetMaybeFileHdl), or use bCheckFileExists = false
63 if you want to generate file URLs without checking for their existence.
65 UniString
66 SmartRel2Abs(INetURLObject const & rTheBaseURIRef,
67 UniString const & rTheRelURIRef,
68 Link const & rMaybeFileHdl = Link(),
69 bool bCheckFileExists = true,
70 bool bIgnoreFragment = false,
71 INetURLObject::EncodeMechanism eEncodeMechanism
72 = INetURLObject::WAS_ENCODED,
73 INetURLObject::DecodeMechanism eDecodeMechanism
74 = INetURLObject::DECODE_TO_IURI,
75 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
76 bool bRelativeNonURIs = false,
77 INetURLObject::FSysStyle eStyle = INetURLObject::FSYS_DETECT);
79 //============================================================================
80 void SetMaybeFileHdl(Link const & rTheMaybeFileHdl);
82 //============================================================================
83 Link GetMaybeFileHdl();
85 /**
86 Converts a URI reference to a relative one, ignoring certain differences (for
87 example, treating file URLs for case-ignoring file systems
88 case-insensitively).
90 @param context a component context; must not be null
92 @param baseUriReference a base URI reference
94 @param uriReference a URI reference
96 @return a URI reference representing the given uriReference relative to the
97 given baseUriReference; if the given baseUriReference is not an absolute,
98 hierarchical URI reference, or the given uriReference is not a valid URI
99 reference, null is returned
101 @exception std::bad_alloc if an out-of-memory condition occurs
103 @exception com::sun::star::uno::RuntimeException if any error occurs
105 com::sun::star::uno::Reference< com::sun::star::uri::XUriReference >
106 normalizedMakeRelative(
107 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
108 const & context,
109 rtl::OUString const & baseUriReference, rtl::OUString const & uriReference);
112 A variant of normalizedMakeRelative with a simplified interface.
114 Internally calls normalizedMakeRelative with the default component context.
116 @param baseUriReference a base URI reference, passed to
117 normalizedMakeRelative
119 @param uriReference a URI reference, passed to normalizedMakeRelative
121 @return if the XUriReference returnd by normalizedMakeRelative is empty,
122 uriReference is returned unmodified; otherwise, the result of calling
123 XUriReference::getUriReference on the XUriReference returnd by
124 normalizedMakeRelative is returned
126 @exception std::bad_alloc if an out-of-memory condition occurs
128 @exception com::sun::star::uno::RuntimeException if any error occurs
130 @deprecated
131 No code should rely on the default component context.
133 rtl::OUString simpleNormalizedMakeRelative(
134 rtl::OUString const & baseUriReference, rtl::OUString const & uriReference);
136 //============================================================================
137 UniString
138 FindFirstURLInText(UniString const & rText,
139 xub_StrLen & rBegin,
140 xub_StrLen & rEnd,
141 CharClass const & rCharClass,
142 INetURLObject::EncodeMechanism eMechanism
143 = INetURLObject::WAS_ENCODED,
144 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
145 INetURLObject::FSysStyle eStyle
146 = INetURLObject::FSYS_DETECT);
148 //============================================================================
149 /** Remove any password component from both absolute and relative URLs.
151 @ATT The current implementation will not remove a password from a
152 relative URL that has an authority component (e.g., the password is not
153 removed from the relative ftp URL <//user:password@domain/path>). But
154 since our functions to translate between absolute and relative URLs never
155 produce relative URLs with authority components, this is no real problem.
157 @ATT For relative URLs (or anything not recognized as an absolute URI),
158 the current implementation will return the input unmodified, not applying
159 any translations implied by the encode/decode parameters.
161 @param rURI An absolute or relative URI reference.
163 @param eEncodeMechanism See the general discussion for INetURLObject set-
164 methods.
166 @param eDecodeMechanism See the general discussion for INetURLObject get-
167 methods.
169 @param eCharset See the general discussion for INetURLObject get- and
170 set-methods.
172 @return The input URI with any password component removed.
174 UniString
175 removePassword(UniString const & rURI,
176 INetURLObject::EncodeMechanism eEncodeMechanism
177 = INetURLObject::WAS_ENCODED,
178 INetURLObject::DecodeMechanism eDecodeMechanism
179 = INetURLObject::DECODE_TO_IURI,
180 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
183 #endif // SVTOOLS_URIHELPER_HXX