1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _RTL_URI_HXX_ 29*cdf0e10cSrcweir #define _RTL_URI_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "rtl/malformeduriexception.hxx" 32*cdf0e10cSrcweir #include "rtl/uri.h" 33*cdf0e10cSrcweir #include "rtl/textenc.h" 34*cdf0e10cSrcweir #include "rtl/ustring.hxx" 35*cdf0e10cSrcweir #include "sal/types.h" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir namespace rtl { 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir /** A wrapper around the C functions from <rtl/uri.h>. 40*cdf0e10cSrcweir */ 41*cdf0e10cSrcweir class Uri 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir public: 44*cdf0e10cSrcweir /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using 45*cdf0e10cSrcweir an array of 128 booleans as char class. 46*cdf0e10cSrcweir */ 47*cdf0e10cSrcweir static inline rtl::OUString encode(rtl::OUString const & rText, 48*cdf0e10cSrcweir sal_Bool const * pCharClass, 49*cdf0e10cSrcweir rtl_UriEncodeMechanism eMechanism, 50*cdf0e10cSrcweir rtl_TextEncoding eCharset) 51*cdf0e10cSrcweir SAL_THROW(()); 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using 54*cdf0e10cSrcweir a predefined rtl_UriCharClass enumeration member. 55*cdf0e10cSrcweir */ 56*cdf0e10cSrcweir static inline rtl::OUString encode(rtl::OUString const & rText, 57*cdf0e10cSrcweir rtl_UriCharClass eCharClass, 58*cdf0e10cSrcweir rtl_UriEncodeMechanism eMechanism, 59*cdf0e10cSrcweir rtl_TextEncoding eCharset) 60*cdf0e10cSrcweir SAL_THROW(()); 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir /** A wrapper around rtl_uriDecode() from <rtl/uri.h> (see there). 63*cdf0e10cSrcweir */ 64*cdf0e10cSrcweir static inline rtl::OUString decode(rtl::OUString const & rText, 65*cdf0e10cSrcweir rtl_UriDecodeMechanism eMechanism, 66*cdf0e10cSrcweir rtl_TextEncoding eCharset) 67*cdf0e10cSrcweir SAL_THROW(()); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir /** A wrapper around rtl_uriConvertRelToAbs() from <rtl/uri.h> (see there). 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir @exception MalformedUriException 72*cdf0e10cSrcweir Thrown in case rtl_uriConvertRelToAbs() signals an exception due to a 73*cdf0e10cSrcweir malformed base URI. 74*cdf0e10cSrcweir */ 75*cdf0e10cSrcweir static inline rtl::OUString convertRelToAbs( 76*cdf0e10cSrcweir rtl::OUString const & rBaseUriRef, rtl::OUString const & rRelUriRef); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir private: 79*cdf0e10cSrcweir /** not implemented 80*cdf0e10cSrcweir @internal */ 81*cdf0e10cSrcweir Uri(); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /** not implemented 84*cdf0e10cSrcweir @internal */ 85*cdf0e10cSrcweir Uri(Uri &); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir /** not implemented 88*cdf0e10cSrcweir @internal */ 89*cdf0e10cSrcweir ~Uri(); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir /** not implemented 92*cdf0e10cSrcweir @internal */ 93*cdf0e10cSrcweir void operator =(Uri); 94*cdf0e10cSrcweir }; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir inline rtl::OUString Uri::encode(rtl::OUString const & rText, 97*cdf0e10cSrcweir sal_Bool const * pCharClass, 98*cdf0e10cSrcweir rtl_UriEncodeMechanism eMechanism, 99*cdf0e10cSrcweir rtl_TextEncoding eCharset) 100*cdf0e10cSrcweir SAL_THROW(()) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir rtl::OUString aResult; 103*cdf0e10cSrcweir rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData, 104*cdf0e10cSrcweir pCharClass, 105*cdf0e10cSrcweir eMechanism, 106*cdf0e10cSrcweir eCharset, 107*cdf0e10cSrcweir &aResult.pData); 108*cdf0e10cSrcweir return aResult; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir inline rtl::OUString Uri::encode(rtl::OUString const & rText, 112*cdf0e10cSrcweir rtl_UriCharClass eCharClass, 113*cdf0e10cSrcweir rtl_UriEncodeMechanism eMechanism, 114*cdf0e10cSrcweir rtl_TextEncoding eCharset) 115*cdf0e10cSrcweir SAL_THROW(()) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir rtl::OUString aResult; 118*cdf0e10cSrcweir rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData, 119*cdf0e10cSrcweir rtl_getUriCharClass(eCharClass), 120*cdf0e10cSrcweir eMechanism, 121*cdf0e10cSrcweir eCharset, 122*cdf0e10cSrcweir &aResult.pData); 123*cdf0e10cSrcweir return aResult; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir inline rtl::OUString Uri::decode(rtl::OUString const & rText, 127*cdf0e10cSrcweir rtl_UriDecodeMechanism eMechanism, 128*cdf0e10cSrcweir rtl_TextEncoding eCharset) 129*cdf0e10cSrcweir SAL_THROW(()) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir rtl::OUString aResult; 132*cdf0e10cSrcweir rtl_uriDecode(const_cast< rtl::OUString & >(rText).pData, 133*cdf0e10cSrcweir eMechanism, 134*cdf0e10cSrcweir eCharset, 135*cdf0e10cSrcweir &aResult.pData); 136*cdf0e10cSrcweir return aResult; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir inline rtl::OUString Uri::convertRelToAbs(rtl::OUString const & rBaseUriRef, 140*cdf0e10cSrcweir rtl::OUString const & rRelUriRef) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir rtl::OUString aResult; 143*cdf0e10cSrcweir rtl::OUString aException; 144*cdf0e10cSrcweir if (!rtl_uriConvertRelToAbs( 145*cdf0e10cSrcweir const_cast< rtl::OUString & >(rBaseUriRef).pData, 146*cdf0e10cSrcweir const_cast< rtl::OUString & >(rRelUriRef).pData, &aResult.pData, 147*cdf0e10cSrcweir &aException.pData)) 148*cdf0e10cSrcweir throw MalformedUriException(aException); 149*cdf0e10cSrcweir return aResult; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir #endif // _RTL_URI_HXX_ 155