diff options
author | Rüdiger Timm <rt@openoffice.org> | 2008-06-09 11:43:53 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2008-06-09 11:43:53 +0000 |
commit | e4989f06cb5c2c86d3dd88c61eecfce6947d777a (patch) | |
tree | d6aa1645be5e8dc6e41101232478d854fe4ccdab /stoc | |
parent | 6b800cb3f1e39be8927d0dfebedbbe275c7df5c0 (diff) |
INTEGRATION: CWS sb87 (1.6.18); FILE MERGED
2008/04/24 13:17:27 sb 1.6.18.3: RESYNC: (1.6-1.7); FILE MERGED
2008/04/23 15:20:02 sb 1.6.18.2: #i88633# missing include
2008/04/23 12:50:36 fs 1.6.18.1: #i88633# +setName/setParameter
Diffstat (limited to 'stoc')
-rw-r--r-- | stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx index fd34e4be36cd..3c1749594d44 100644 --- a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx +++ b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx,v $ - * $Revision: 1.7 $ + * $Revision: 1.8 $ * * This file is part of OpenOffice.org. * @@ -36,6 +36,7 @@ #include "UriReference.hxx" #include "supportsService.hxx" +#include "com/sun/star/lang/IllegalArgumentException.hpp" #include "com/sun/star/lang/XServiceInfo.hpp" #include "com/sun/star/uno/Reference.hxx" #include "com/sun/star/uno/RuntimeException.hpp" @@ -48,6 +49,7 @@ #include "cppuhelper/implbase2.hxx" #include "cppuhelper/weak.hxx" #include "osl/mutex.hxx" +#include "rtl/uri.hxx" #include "rtl/ustrbuf.hxx" #include "rtl/ustring.hxx" #include "sal/types.h" @@ -151,6 +153,30 @@ rtl::OUString parsePart( return buf.makeStringAndClear(); } +namespace +{ + static rtl::OUString encodeNameOrParamFragment( rtl::OUString const & fragment ) + { + static sal_Bool const aCharClass[] = + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* NameOrParamFragment */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, /* !"#$%&'()*+,-./*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, /*0123456789:;<=>?*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*@ABCDEFGHIJKLMNO*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, /*PQRSTUVWXYZ[\]^_*/ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*`abcdefghijklmno*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 /*pqrstuvwxyz{|}~ */ + }; + + return rtl::Uri::encode( + fragment, + aCharClass, + rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_UTF8 + ); + } +} + bool parseSchemeSpecificPart(rtl::OUString const & part) { sal_Int32 len = part.getLength(); sal_Int32 i = 0; @@ -257,12 +283,18 @@ public: virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName(rtl::OUString const & name) + throw (css::uno::RuntimeException, css::lang::IllegalArgumentException); + virtual sal_Bool SAL_CALL hasParameter(rtl::OUString const & key) throw (css::uno::RuntimeException); virtual rtl::OUString SAL_CALL getParameter(rtl::OUString const & key) throw (css::uno::RuntimeException); + virtual void SAL_CALL setParameter(rtl::OUString const & key, rtl::OUString const & value) + throw (css::uno::RuntimeException, css::lang::IllegalArgumentException); + private: UrlReference(UrlReference &); // not implemented void operator =(UrlReference); // not implemented @@ -280,6 +312,22 @@ rtl::OUString UrlReference::getName() throw (css::uno::RuntimeException) { return parsePart(m_base.m_path, true, &i); } +void SAL_CALL UrlReference::setName(rtl::OUString const & name) throw (css::uno::RuntimeException, css::lang::IllegalArgumentException) +{ + if (name.getLength() == 0) + throw css::lang::IllegalArgumentException( + ::rtl::OUString(), *this, 1); + + osl::MutexGuard g(m_base.m_mutex); + sal_Int32 i = 0; + parsePart(m_base.m_path, true, &i); + + rtl::OUStringBuffer newPath; + newPath.append(encodeNameOrParamFragment(name)); + newPath.append(m_base.m_path.copy(i)); + m_base.m_path = newPath.makeStringAndClear(); +} + sal_Bool UrlReference::hasParameter(rtl::OUString const & key) throw (css::uno::RuntimeException) { @@ -295,6 +343,37 @@ rtl::OUString UrlReference::getParameter(rtl::OUString const & key) return i >= 0 ? parsePart(m_base.m_path, false, &i) : rtl::OUString(); } +void UrlReference::setParameter(rtl::OUString const & key, rtl::OUString const & value) + throw (css::uno::RuntimeException, css::lang::IllegalArgumentException) +{ + if (key.getLength() == 0) + throw css::lang::IllegalArgumentException( + ::rtl::OUString(), *this, 1); + + osl::MutexGuard g(m_base.m_mutex); + sal_Int32 i = findParameter(key); + bool bExistent = ( i>=0 ); + if (!bExistent) { + i = m_base.m_path.getLength(); + } + + rtl::OUStringBuffer newPath; + newPath.append(m_base.m_path.copy(0, i)); + if (!bExistent) { + newPath.append(sal_Unicode(m_base.m_path.indexOf('?') < 0 ? '?' : '&')); + newPath.append(encodeNameOrParamFragment(key)); + newPath.append(sal_Unicode('=')); + } + newPath.append(encodeNameOrParamFragment(value)); + if (bExistent) { + /*oldValue = */ + parsePart(m_base.m_path, false, &i); // skip key + newPath.append(m_base.m_path.copy(i)); + } + + m_base.m_path = newPath.makeStringAndClear(); +} + sal_Int32 UrlReference::findParameter(rtl::OUString const & key) { sal_Int32 i = 0; parsePart(m_base.m_path, true, &i); // skip name |