1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SVTOOLS_URIHELPER_HXX 29 #define SVTOOLS_URIHELPER_HXX 30 31 #include "svl/svldllapi.h" 32 #include "com/sun/star/uno/Reference.hxx" 33 #include <com/sun/star/uno/RuntimeException.hpp> 34 #include <rtl/textenc.h> 35 #include <tools/link.hxx> 36 #include <tools/solar.h> 37 #include <tools/urlobj.hxx> 38 39 namespace com { namespace sun { namespace star { 40 namespace uno { class XComponentContext; } 41 namespace uri { class XUriReference; } 42 } } } 43 namespace rtl { class OUString; } 44 class ByteString; 45 class CharClass; 46 class UniString; 47 48 //============================================================================ 49 namespace URIHelper { 50 51 /** 52 @ATT 53 Calling this function with defaulted arguments rMaybeFileHdl = Link() and 54 bCheckFileExists = true often leads to results that are not intended: 55 Whenever the given rTheBaseURIRef is a file URL, the given rTheRelURIRef is 56 relative, and rTheRelURIRef could also be smart-parsed as a non-file URL 57 (e.g., the relative URL "foo/bar" can be smart-parsed as "http://foo/bar"), 58 then SmartRel2Abs called with rMaybeFileHdl = Link() and bCheckFileExists = 59 true returns the non-file URL interpretation. To avoid this, either pass 60 some non-null rMaybeFileHdl if you want to check generated file URLs for 61 existence (see URIHelper::GetMaybeFileHdl), or use bCheckFileExists = false 62 if you want to generate file URLs without checking for their existence. 63 */ 64 SVL_DLLPUBLIC UniString 65 SmartRel2Abs(INetURLObject const & rTheBaseURIRef, 66 ByteString const & rTheRelURIRef, 67 Link const & rMaybeFileHdl = Link(), 68 bool bCheckFileExists = true, 69 bool bIgnoreFragment = false, 70 INetURLObject::EncodeMechanism eEncodeMechanism 71 = INetURLObject::WAS_ENCODED, 72 INetURLObject::DecodeMechanism eDecodeMechanism 73 = INetURLObject::DECODE_TO_IURI, 74 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8, 75 bool bRelativeNonURIs = false, 76 INetURLObject::FSysStyle eStyle = INetURLObject::FSYS_DETECT); 77 78 /** 79 @ATT 80 Calling this function with defaulted arguments rMaybeFileHdl = Link() and 81 bCheckFileExists = true often leads to results that are not intended: 82 Whenever the given rTheBaseURIRef is a file URL, the given rTheRelURIRef is 83 relative, and rTheRelURIRef could also be smart-parsed as a non-file URL 84 (e.g., the relative URL "foo/bar" can be smart-parsed as "http://foo/bar"), 85 then SmartRel2Abs called with rMaybeFileHdl = Link() and bCheckFileExists = 86 true returns the non-file URL interpretation. To avoid this, either pass 87 some non-null rMaybeFileHdl if you want to check generated file URLs for 88 existence (see URIHelper::GetMaybeFileHdl), or use bCheckFileExists = false 89 if you want to generate file URLs without checking for their existence. 90 */ 91 SVL_DLLPUBLIC UniString 92 SmartRel2Abs(INetURLObject const & rTheBaseURIRef, 93 UniString const & rTheRelURIRef, 94 Link const & rMaybeFileHdl = Link(), 95 bool bCheckFileExists = true, 96 bool bIgnoreFragment = false, 97 INetURLObject::EncodeMechanism eEncodeMechanism 98 = INetURLObject::WAS_ENCODED, 99 INetURLObject::DecodeMechanism eDecodeMechanism 100 = INetURLObject::DECODE_TO_IURI, 101 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8, 102 bool bRelativeNonURIs = false, 103 INetURLObject::FSysStyle eStyle = INetURLObject::FSYS_DETECT); 104 105 //============================================================================ 106 SVL_DLLPUBLIC void SetMaybeFileHdl(Link const & rTheMaybeFileHdl); 107 108 //============================================================================ 109 SVL_DLLPUBLIC Link GetMaybeFileHdl(); 110 111 /** 112 Converts a URI reference to a relative one, ignoring certain differences (for 113 example, treating file URLs for case-ignoring file systems 114 case-insensitively). 115 116 @param context a component context; must not be null 117 118 @param baseUriReference a base URI reference 119 120 @param uriReference a URI reference 121 122 @return a URI reference representing the given uriReference relative to the 123 given baseUriReference; if the given baseUriReference is not an absolute, 124 hierarchical URI reference, or the given uriReference is not a valid URI 125 reference, null is returned 126 127 @exception std::bad_alloc if an out-of-memory condition occurs 128 129 @exception com::sun::star::uno::RuntimeException if any error occurs 130 */ 131 SVL_DLLPUBLIC com::sun::star::uno::Reference< com::sun::star::uri::XUriReference > 132 normalizedMakeRelative( 133 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > 134 const & context, 135 rtl::OUString const & baseUriReference, rtl::OUString const & uriReference); 136 137 /** 138 A variant of normalizedMakeRelative with a simplified interface. 139 140 Internally calls normalizedMakeRelative with the default component context. 141 142 @param baseUriReference a base URI reference, passed to 143 normalizedMakeRelative 144 145 @param uriReference a URI reference, passed to normalizedMakeRelative 146 147 @return if the XUriReference returnd by normalizedMakeRelative is empty, 148 uriReference is returned unmodified; otherwise, the result of calling 149 XUriReference::getUriReference on the XUriReference returnd by 150 normalizedMakeRelative is returned 151 152 @exception std::bad_alloc if an out-of-memory condition occurs 153 154 @exception com::sun::star::uno::RuntimeException if any error occurs 155 156 @deprecated 157 No code should rely on the default component context. 158 */ 159 SVL_DLLPUBLIC rtl::OUString simpleNormalizedMakeRelative( 160 rtl::OUString const & baseUriReference, rtl::OUString const & uriReference); 161 162 //============================================================================ 163 SVL_DLLPUBLIC UniString 164 FindFirstURLInText(UniString const & rText, 165 xub_StrLen & rBegin, 166 xub_StrLen & rEnd, 167 CharClass const & rCharClass, 168 INetURLObject::EncodeMechanism eMechanism 169 = INetURLObject::WAS_ENCODED, 170 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8, 171 INetURLObject::FSysStyle eStyle 172 = INetURLObject::FSYS_DETECT); 173 174 //============================================================================ 175 /** Remove any password component from both absolute and relative URLs. 176 177 @ATT The current implementation will not remove a password from a 178 relative URL that has an authority component (e.g., the password is not 179 removed from the relative ftp URL <//user:password@domain/path>). But 180 since our functions to translate between absolute and relative URLs never 181 produce relative URLs with authority components, this is no real problem. 182 183 @ATT For relative URLs (or anything not recognized as an absolute URI), 184 the current implementation will return the input unmodified, not applying 185 any translations implied by the encode/decode parameters. 186 187 @param rURI An absolute or relative URI reference. 188 189 @param eEncodeMechanism See the general discussion for INetURLObject set- 190 methods. 191 192 @param eDecodeMechanism See the general discussion for INetURLObject get- 193 methods. 194 195 @param eCharset See the general discussion for INetURLObject get- and 196 set-methods. 197 198 @return The input URI with any password component removed. 199 */ 200 SVL_DLLPUBLIC UniString 201 removePassword(UniString const & rURI, 202 INetURLObject::EncodeMechanism eEncodeMechanism 203 = INetURLObject::WAS_ENCODED, 204 INetURLObject::DecodeMechanism eDecodeMechanism 205 = INetURLObject::DECODE_TO_IURI, 206 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8); 207 208 //============================================================================ 209 /** Query the notational conventions used in the file system provided by some 210 file content provider. 211 212 @param rFileUrl This file URL determines which file content provider is 213 used to query the desired information. (The UCB's usual mapping from URLs 214 to content providers is used.) 215 216 @param bAddConvenienceStyles If true, the return value contains not only 217 the style bit corresponding to the queried content provider's conventions, 218 but may also contain additional style bits that make using this function 219 more convenient in certain situations. Currently, the effect is that 220 FSYS_UNX is extended with FSYS_VOS, and both FSYS_DOS and FSYS_MAC are 221 extended with FSYS_VOS and FSYS_UNX (i.e., the---unambiguous---detection 222 of VOS style and Unix style file system paths is always enabled); also, in 223 case the content provider's conventions cannot be determined, FSYS_DETECT 224 is returned instead of FSysStyle(0). 225 226 @return The style bit corresponding to the queried content provider's 227 conventions, or FSysStyle(0) if these cannot be determined. 228 */ 229 SVL_DLLPUBLIC INetURLObject::FSysStyle queryFSysStyle(UniString const & rFileUrl, 230 bool bAddConvenienceStyles = true) 231 throw (com::sun::star::uno::RuntimeException); 232 233 } 234 235 #endif // SVTOOLS_URIHELPER_HXX 236