office-gobmx/cppuhelper/source/unourl.cxx
Rüdiger Timm 8a7a710632 CWS-TOOLING: integrate CWS cmcfixes51
2008-12-08 10:12:55 +0100 cmc  r264975 : #i96203# protect with ifdefs to avoid unused symbol on mac
2008-12-05 12:23:47 +0100 cmc  r264898 : CWS-TOOLING: rebase CWS cmcfixes51 to trunk@264807 (milestone: DEV300:m37)
2008-12-01 14:45:17 +0100 cmc  r264606 : #i76655# ehlos apparently required
2008-11-28 17:49:30 +0100 cmc  r264567 : #i96655# remove newly unused method
2008-11-28 10:41:28 +0100 cmc  r264531 : #i96647# better ppc-bridges flushCode impl
2008-11-27 12:58:40 +0100 cmc  r264478 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 12:32:49 +0100 cmc  r264476 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 12:26:02 +0100 cmc  r264475 : #i96655# redundant old table export helpers
2008-11-27 11:49:06 +0100 cmc  r264473 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 11:38:35 +0100 cmc  r264471 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 11:14:21 +0100 cmc  r264467 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 11:06:22 +0100 cmc  r264464 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 10:58:18 +0100 cmc  r264462 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 10:41:44 +0100 cmc  r264461 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 10:19:24 +0100 cmc  r264460 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 10:13:39 +0100 cmc  r264459 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 10:06:14 +0100 cmc  r264458 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 09:59:54 +0100 cmc  r264457 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 09:52:51 +0100 cmc  r264456 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 09:48:26 +0100 cmc  r264454 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 09:40:20 +0100 cmc  r264452 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 09:35:26 +0100 cmc  r264451 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 09:31:00 +0100 cmc  r264450 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 09:24:08 +0100 cmc  r264449 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 00:26:15 +0100 cmc  r264443 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 00:21:01 +0100 cmc  r264442 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-27 00:09:40 +0100 cmc  r264441 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 23:51:56 +0100 cmc  r264440 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 23:49:09 +0100 cmc  r264439 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 18:09:54 +0100 cmc  r264432 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 18:07:40 +0100 cmc  r264431 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 17:28:02 +0100 cmc  r264429 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 17:27:39 +0100 cmc  r264428 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 17:18:36 +0100 cmc  r264426 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 16:22:16 +0100 cmc  r264415 : #i96624# make implicit braces and brackets explicit to avoid warnings
2008-11-26 16:00:23 +0100 cmc  r264409 : #i90426# remove warnings from svtools
2008-11-26 15:59:17 +0100 cmc  r264408 : #i90426# remove warnings
2008-11-26 15:47:32 +0100 cmc  r264404 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 14:46:57 +0100 cmc  r264394 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 14:19:50 +0100 cmc  r264387 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 14:15:26 +0100 cmc  r264386 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 14:11:26 +0100 cmc  r264384 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 13:44:23 +0100 cmc  r264380 : #i96084# comfirm existing logic with explicit brackets to remove new gcc warnings
2008-11-26 13:12:24 +0100 cmc  r264372 : #i96604# silence new warnings
2008-11-26 12:35:02 +0100 cmc  r264369 : #i96203# make qstarter work in 3-layer land
2008-11-26 12:33:04 +0100 cmc  r264368 : #i96170# ensure gtypes are up and running
2008-12-11 07:05:03 +00:00

301 lines
9.5 KiB
C++

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: unourl.cxx,v $
* $Revision: 1.5 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_cppuhelper.hxx"
#include "cppuhelper/unourl.hxx"
#include "osl/diagnose.h"
#include "rtl/malformeduriexception.hxx"
#include "rtl/string.h"
#include "rtl/textenc.h"
#include "rtl/uri.h"
#include "rtl/uri.hxx"
#include "rtl/ustring.h"
#include "rtl/ustring.hxx"
#include "sal/types.h"
#include <map>
using cppu::UnoUrl;
using cppu::UnoUrlDescriptor;
namespace {
inline bool isAlphanum(sal_Unicode c)
{
return (c >= 0x30 && c <= 0x39) // '0'--'9'
|| (c >= 0x41 && c <= 0x5A) // 'A'--'Z'
|| (c >= 0x61 && c <= 0x7A); // 'a'--'z'
}
}
class UnoUrlDescriptor::Impl
{
public:
typedef std::map< rtl::OUString, rtl::OUString > Parameters;
rtl::OUString m_aDescriptor;
rtl::OUString m_aName;
Parameters m_aParameters;
/** @exception rtl::MalformedUriException
*/
explicit inline Impl(rtl::OUString const & m_aDescriptor);
inline Impl * clone() const { return new Impl(*this); }
};
inline UnoUrlDescriptor::Impl::Impl(rtl::OUString const & rDescriptor)
{
m_aDescriptor = rDescriptor;
enum State { STATE_NAME0, STATE_NAME, STATE_KEY0, STATE_KEY, STATE_VALUE };
State eState = STATE_NAME0;
sal_Int32 nStart = 0;
rtl::OUString aKey;
for (sal_Int32 i = 0;; ++i)
{
bool bEnd = i == rDescriptor.getLength();
sal_Unicode c = bEnd ? 0 : rDescriptor.getStr()[i];
switch (eState)
{
case STATE_NAME0:
if (bEnd || !isAlphanum(c))
throw rtl::MalformedUriException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"UNO URL contains bad descriptor name")));
nStart = i;
eState = STATE_NAME;
break;
case STATE_NAME:
if (bEnd || c == 0x2C) // ','
{
m_aName
= rDescriptor.copy(nStart, i - nStart).toAsciiLowerCase();
eState = STATE_KEY0;
}
else if (!isAlphanum(c))
throw rtl::MalformedUriException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"UNO URL contains bad descriptor name")));
break;
case STATE_KEY0:
if (bEnd || !isAlphanum(c))
throw rtl::MalformedUriException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"UNO URL contains bad parameter key")));
nStart = i;
eState = STATE_KEY;
break;
case STATE_KEY:
if (c == 0x3D) // '='
{
aKey = rDescriptor.copy(nStart, i - nStart).toAsciiLowerCase();
nStart = i + 1;
eState = STATE_VALUE;
}
else if (bEnd || !isAlphanum(c))
throw rtl::MalformedUriException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"UNO URL contains bad parameter key")));
break;
case STATE_VALUE:
if (bEnd || c == 0x2C) // ','
{
if (!m_aParameters.insert(
Parameters::value_type(
aKey,
rtl::Uri::decode(rDescriptor.copy(nStart,
i - nStart),
rtl_UriDecodeWithCharset,
RTL_TEXTENCODING_UTF8))).second)
throw rtl::MalformedUriException(
rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
"UNO URL contains duplicated parameter")));
eState = STATE_KEY0;
}
break;
}
if (bEnd)
break;
}
}
UnoUrlDescriptor::UnoUrlDescriptor(rtl::OUString const & rDescriptor):
m_xImpl(new Impl(rDescriptor))
{}
UnoUrlDescriptor::UnoUrlDescriptor(std::auto_ptr< Impl > & rImpl):
m_xImpl(rImpl)
{}
UnoUrlDescriptor::UnoUrlDescriptor(UnoUrlDescriptor const & rOther):
m_xImpl(rOther.m_xImpl->clone())
{}
UnoUrlDescriptor::~UnoUrlDescriptor()
{}
UnoUrlDescriptor & UnoUrlDescriptor::operator =(UnoUrlDescriptor const & rOther)
{
m_xImpl.reset(rOther.m_xImpl->clone());
return *this;
}
rtl::OUString const & UnoUrlDescriptor::getDescriptor() const
{
return m_xImpl->m_aDescriptor;
}
rtl::OUString const & UnoUrlDescriptor::getName() const
{
return m_xImpl->m_aName;
}
bool UnoUrlDescriptor::hasParameter(rtl::OUString const & rKey) const
{
return m_xImpl->m_aParameters.find(rKey.toAsciiLowerCase())
!= m_xImpl->m_aParameters.end();
}
rtl::OUString UnoUrlDescriptor::getParameter(rtl::OUString const & rKey) const
{
Impl::Parameters::const_iterator
aIt(m_xImpl->m_aParameters.find(rKey.toAsciiLowerCase()));
return aIt == m_xImpl->m_aParameters.end() ? rtl::OUString() : aIt->second;
}
class UnoUrl::Impl
{
public:
UnoUrlDescriptor m_aConnection;
UnoUrlDescriptor m_aProtocol;
rtl::OUString m_aObjectName;
inline Impl * clone() const { return new Impl(*this); }
/** @exception rtl::MalformedUriException
*/
static inline Impl * create(rtl::OUString const & rUrl);
private:
inline Impl(std::auto_ptr< UnoUrlDescriptor::Impl > & rConnection,
std::auto_ptr< UnoUrlDescriptor::Impl > & rProtocol,
rtl::OUString const & rObjectName);
};
inline UnoUrl::Impl::Impl(std::auto_ptr< UnoUrlDescriptor::Impl > & rConnection,
std::auto_ptr< UnoUrlDescriptor::Impl > & rProtocol,
rtl::OUString const & rObjectName):
m_aConnection(rConnection),
m_aProtocol(rProtocol),
m_aObjectName(rObjectName)
{}
inline UnoUrl::Impl * UnoUrl::Impl::create(rtl::OUString const & rUrl)
{
if (!rUrl.matchIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("uno:"), 0))
throw rtl::MalformedUriException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"UNO URL does not start with \"uno:\"")));
sal_Int32 i = RTL_CONSTASCII_LENGTH("uno:");
sal_Int32 j = rUrl.indexOf(';', i);
if (j < 0)
throw rtl::MalformedUriException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"UNO URL has too few semicolons")));
std::auto_ptr< UnoUrlDescriptor::Impl >
xConnection(new UnoUrlDescriptor::Impl(rUrl.copy(i, j - i)));
i = j + 1;
j = rUrl.indexOf(0x3B, i); // ';'
if (j < 0)
throw rtl::MalformedUriException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"UNO URL has too few semicolons")));
std::auto_ptr< UnoUrlDescriptor::Impl >
xProtocol(new UnoUrlDescriptor::Impl(rUrl.copy(i, j - i)));
i = j + 1;
if (i == rUrl.getLength())
throw rtl::MalformedUriException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"UNO URL contains empty ObjectName")));
for (j = i; j < rUrl.getLength(); ++j)
{
sal_Unicode c = rUrl.getStr()[j];
if (!isAlphanum(c) && c != 0x21 && c != 0x24 // '!', '$'
&& c != 0x26 && c != 0x27 && c != 0x28 // '&', ''', '('
&& c != 0x28 && c != 0x2A && c != 0x2B // ')', '*', '+'
&& c != 0x2C && c != 0x2D && c != 0x2E // ',', '-', '.'
&& c != 0x2F && c != 0x3A && c != 0x3D // '/', ':', '='
&& c != 0x3F && c != 0x40 && c != 0x5F // '?', '@', '_'
&& c != 0x7E) // '~'
throw rtl::MalformedUriException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"UNO URL contains invalid ObjectName")));
}
return new Impl(xConnection, xProtocol, rUrl.copy(i));
}
UnoUrl::UnoUrl(rtl::OUString const & rUrl): m_xImpl(Impl::create(rUrl))
{}
UnoUrl::UnoUrl(UnoUrl const & rOther): m_xImpl(rOther.m_xImpl->clone())
{}
UnoUrl::~UnoUrl()
{}
UnoUrl & UnoUrl::operator =(UnoUrl const & rOther)
{
m_xImpl.reset(rOther.m_xImpl->clone());
return *this;
}
UnoUrlDescriptor const & UnoUrl::getConnection() const
{
return m_xImpl->m_aConnection;
}
UnoUrlDescriptor const & UnoUrl::getProtocol() const
{
return m_xImpl->m_aProtocol;
}
rtl::OUString const & UnoUrl::getObjectName() const
{
return m_xImpl->m_aObjectName;
}