summaryrefslogtreecommitdiff
path: root/stoc/source/uriproc
diff options
context:
space:
mode:
Diffstat (limited to 'stoc/source/uriproc')
-rw-r--r--stoc/source/uriproc/ExternalUriReferenceTranslator.cxx243
-rw-r--r--stoc/source/uriproc/ExternalUriReferenceTranslator.hxx62
-rw-r--r--stoc/source/uriproc/UriReference.cxx209
-rw-r--r--stoc/source/uriproc/UriReference.hxx111
-rw-r--r--stoc/source/uriproc/UriReferenceFactory.cxx727
-rw-r--r--stoc/source/uriproc/UriReferenceFactory.hxx62
-rw-r--r--stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.cxx271
-rw-r--r--stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.hxx65
-rw-r--r--stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx488
-rw-r--r--stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.hxx64
-rw-r--r--stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.cxx170
-rw-r--r--stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.hxx62
-rw-r--r--stoc/source/uriproc/makefile.mk57
-rw-r--r--stoc/source/uriproc/supportsService.cxx54
-rw-r--r--stoc/source/uriproc/supportsService.hxx46
15 files changed, 2691 insertions, 0 deletions
diff --git a/stoc/source/uriproc/ExternalUriReferenceTranslator.cxx b/stoc/source/uriproc/ExternalUriReferenceTranslator.cxx
new file mode 100644
index 000000000000..dd0bd7b44b51
--- /dev/null
+++ b/stoc/source/uriproc/ExternalUriReferenceTranslator.cxx
@@ -0,0 +1,243 @@
+/*************************************************************************
+ *
+ * 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: ExternalUriReferenceTranslator.cxx,v $
+ * $Revision: 1.7 $
+ *
+ * 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_stoc.hxx"
+
+#include "stocservices.hxx"
+
+#include "supportsService.hxx"
+
+#include "com/sun/star/lang/XServiceInfo.hpp"
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/uno/XComponentContext.hpp"
+#include "com/sun/star/uno/XInterface.hpp"
+#include "com/sun/star/uri/XExternalUriReferenceTranslator.hpp"
+#include "cppuhelper/implbase2.hxx"
+#include "cppuhelper/weak.hxx"
+#include "osl/thread.h"
+#include "rtl/string.h"
+#include "rtl/textenc.h"
+#include "rtl/uri.h"
+#include "rtl/uri.hxx"
+#include "rtl/ustrbuf.hxx"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+
+#include <new>
+
+namespace css = com::sun::star;
+
+namespace {
+
+class Translator: public cppu::WeakImplHelper2<
+ css::lang::XServiceInfo, css::uri::XExternalUriReferenceTranslator >
+{
+public:
+ explicit Translator(
+ css::uno::Reference< css::uno::XComponentContext > const & context):
+ m_context(context) {}
+
+ virtual rtl::OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException);
+
+ virtual css::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames() throw (css::uno::RuntimeException);
+
+ virtual rtl::OUString SAL_CALL
+ translateToInternal(rtl::OUString const & externalUriReference)
+ throw (css::uno::RuntimeException);
+
+ virtual rtl::OUString SAL_CALL
+ translateToExternal(rtl::OUString const & internalUriReference)
+ throw (css::uno::RuntimeException);
+
+private:
+ Translator(Translator &); // not implemented
+ void operator =(Translator); // not implemented
+
+ virtual ~Translator() {}
+
+ css::uno::Reference< css::uno::XComponentContext > m_context;
+};
+
+rtl::OUString Translator::getImplementationName()
+ throw (css::uno::RuntimeException)
+{
+ return
+ stoc_services::ExternalUriReferenceTranslator::getImplementationName();
+}
+
+sal_Bool Translator::supportsService(rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException)
+{
+ return stoc::uriproc::supportsService(
+ getSupportedServiceNames(), serviceName);
+}
+
+css::uno::Sequence< rtl::OUString > Translator::getSupportedServiceNames()
+ throw (css::uno::RuntimeException)
+{
+ return stoc_services::ExternalUriReferenceTranslator::
+ getSupportedServiceNames();
+}
+
+rtl::OUString Translator::translateToInternal(
+ rtl::OUString const & externalUriReference)
+ throw (css::uno::RuntimeException)
+{
+ if (!externalUriReference.matchIgnoreAsciiCaseAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("file:/")))
+ {
+ return externalUriReference;
+ }
+ sal_Int32 i = RTL_CONSTASCII_LENGTH("file:");
+ rtl::OUStringBuffer buf;
+ buf.append(externalUriReference.getStr(), i);
+ // Some environments (e.g., Java) produce illegal file URLs without an
+ // authority part; treat them as having an empty authority part:
+ if (!externalUriReference.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("//"), i))
+ {
+ buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
+ }
+ rtl_TextEncoding encoding = osl_getThreadTextEncoding();
+ for (bool path = true;;) {
+ sal_Int32 j = i;
+ while (j != externalUriReference.getLength()
+ && externalUriReference[j] != '#'
+ && (!path || externalUriReference[j] != '/'))
+ {
+ ++j;
+ }
+ if (j != i) {
+ rtl::OUString seg(
+ rtl::Uri::encode(
+ rtl::Uri::decode(
+ externalUriReference.copy(i, j - i),
+ rtl_UriDecodeStrict, encoding),
+ rtl_UriCharClassPchar, rtl_UriEncodeStrict,
+ RTL_TEXTENCODING_UTF8));
+ if (seg.getLength() == 0) {
+ return rtl::OUString();
+ }
+ buf.append(seg);
+ }
+ if (j == externalUriReference.getLength()) {
+ break;
+ }
+ buf.append(externalUriReference[j]);
+ path = externalUriReference[j] == '/';
+ i = j + 1;
+ }
+ return buf.makeStringAndClear();
+}
+
+rtl::OUString Translator::translateToExternal(
+ rtl::OUString const & internalUriReference)
+ throw (css::uno::RuntimeException)
+{
+ if (!internalUriReference.matchIgnoreAsciiCaseAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("file://")))
+ {
+ return internalUriReference;
+ }
+ sal_Int32 i = RTL_CONSTASCII_LENGTH("file://");
+ rtl::OUStringBuffer buf;
+ buf.append(internalUriReference.getStr(), i);
+ rtl_TextEncoding encoding = osl_getThreadTextEncoding();
+ for (bool path = true;;) {
+ sal_Int32 j = i;
+ while (j != internalUriReference.getLength()
+ && internalUriReference[j] != '#'
+ && (!path || internalUriReference[j] != '/'))
+ {
+ ++j;
+ }
+ if (j != i) {
+ // Use rtl_UriDecodeToIuri -> rtl_UriEncodeStrictKeepEscapes instead
+ // of rtl_UriDecodeStrict -> rtl_UriEncodeStrict, so that spurious
+ // non--UTF-8 octets like "%FE" are copied verbatim:
+ rtl::OUString seg(
+ rtl::Uri::encode(
+ rtl::Uri::decode(
+ internalUriReference.copy(i, j - i),
+ rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8),
+ rtl_UriCharClassPchar, rtl_UriEncodeStrictKeepEscapes,
+ encoding));
+ if (seg.getLength() == 0) {
+ return rtl::OUString();
+ }
+ buf.append(seg);
+ }
+ if (j == internalUriReference.getLength()) {
+ break;
+ }
+ buf.append(internalUriReference[j]);
+ path = internalUriReference[j] == '/';
+ i = j + 1;
+ }
+ return buf.makeStringAndClear();
+}
+
+}
+
+namespace stoc_services { namespace ExternalUriReferenceTranslator {
+
+css::uno::Reference< css::uno::XInterface > create(
+ css::uno::Reference< css::uno::XComponentContext > const & context)
+ SAL_THROW((css::uno::Exception))
+{
+ try {
+ return static_cast< cppu::OWeakObject * >(new Translator(context));
+ } catch (std::bad_alloc &) {
+ throw css::uno::RuntimeException(
+ rtl::OUString::createFromAscii("std::bad_alloc"), 0);
+ }
+}
+
+rtl::OUString getImplementationName() {
+ return rtl::OUString::createFromAscii(
+ "com.sun.star.comp.uri.ExternalUriReferenceTranslator");
+}
+
+css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
+ css::uno::Sequence< rtl::OUString > s(1);
+ s[0] = rtl::OUString::createFromAscii(
+ "com.sun.star.uri.ExternalUriReferenceTranslator");
+ return s;
+}
+
+} }
diff --git a/stoc/source/uriproc/ExternalUriReferenceTranslator.hxx b/stoc/source/uriproc/ExternalUriReferenceTranslator.hxx
new file mode 100644
index 000000000000..2d45073cef4b
--- /dev/null
+++ b/stoc/source/uriproc/ExternalUriReferenceTranslator.hxx
@@ -0,0 +1,62 @@
+/*************************************************************************
+ *
+ * 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: ExternalUriReferenceTranslator.hxx,v $
+ * $Revision: 1.4 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_stoc_source_uriproc_ExternalUriReferenceTranslator_hxx
+#define INCLUDED_stoc_source_uriproc_ExternalUriReferenceTranslator_hxx
+
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "sal/types.h"
+
+namespace com { namespace sun { namespace star { namespace uno {
+ class XComponentContext;
+ class XInterface;
+} } } }
+namespace rtl { class OUString; }
+
+namespace stoc { namespace uriproc {
+
+namespace ExternalUriReferenceTranslator {
+ com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL
+ create(
+ com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
+ const & context)
+ SAL_THROW((com::sun::star::uno::Exception));
+
+ rtl::OUString SAL_CALL getImplementationName();
+
+ com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames();
+}
+
+} }
+
+#endif
diff --git a/stoc/source/uriproc/UriReference.cxx b/stoc/source/uriproc/UriReference.cxx
new file mode 100644
index 000000000000..238445aa6b0d
--- /dev/null
+++ b/stoc/source/uriproc/UriReference.cxx
@@ -0,0 +1,209 @@
+/*************************************************************************
+ *
+ * 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: UriReference.cxx,v $
+ * $Revision: 1.7 $
+ *
+ * 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_stoc.hxx"
+
+#include "UriReference.hxx"
+
+#include "osl/diagnose.h"
+#include "osl/mutex.hxx"
+#include "rtl/string.h"
+#include "rtl/ustrbuf.hxx"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+
+namespace css = com::sun::star;
+using stoc::uriproc::UriReference;
+
+UriReference::UriReference(
+ rtl::OUString const & scheme, bool bIsHierarchical, bool bHasAuthority,
+ rtl::OUString const & authority, rtl::OUString const & path,
+ bool bHasQuery, rtl::OUString const & query):
+ m_scheme(scheme),
+ m_authority(authority),
+ m_path(path),
+ m_query(query),
+ m_isHierarchical(bIsHierarchical),
+ m_hasAuthority(bHasAuthority),
+ m_hasQuery(bHasQuery),
+ m_hasFragment(false)
+{
+ OSL_ASSERT(scheme.getLength() != 0 || bIsHierarchical);
+ OSL_ASSERT(!bHasAuthority || bIsHierarchical);
+ OSL_ASSERT(authority.getLength() == 0 || bHasAuthority);
+ OSL_ASSERT(!bHasQuery || bIsHierarchical);
+ OSL_ASSERT(query.getLength() == 0 || bHasQuery);
+}
+
+UriReference::~UriReference() {}
+
+rtl::OUString UriReference::getUriReference() throw (css::uno::RuntimeException)
+{
+ osl::MutexGuard g(m_mutex);
+ rtl::OUStringBuffer buf;
+ if (m_scheme.getLength() != 0) {
+ buf.append(m_scheme);
+ buf.append(static_cast< sal_Unicode >(':'));
+ }
+ appendSchemeSpecificPart(buf);
+ if (m_hasFragment) {
+ buf.append(static_cast< sal_Unicode >('#'));
+ buf.append(m_fragment);
+ }
+ return buf.makeStringAndClear();
+}
+
+sal_Bool UriReference::isAbsolute() throw (css::uno::RuntimeException) {
+ return m_scheme.getLength() != 0;
+}
+
+rtl::OUString UriReference::getScheme() throw (css::uno::RuntimeException) {
+ return m_scheme;
+}
+
+rtl::OUString UriReference::getSchemeSpecificPart()
+ throw (css::uno::RuntimeException)
+{
+ osl::MutexGuard g(m_mutex);
+ rtl::OUStringBuffer buf;
+ appendSchemeSpecificPart(buf);
+ return buf.makeStringAndClear();
+}
+
+sal_Bool UriReference::isHierarchical() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ return m_isHierarchical;
+}
+
+sal_Bool UriReference::hasAuthority() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ return m_hasAuthority;
+}
+
+rtl::OUString UriReference::getAuthority() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ return m_authority;
+}
+
+rtl::OUString UriReference::getPath() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ return m_path;
+}
+
+sal_Bool UriReference::hasRelativePath() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ return m_isHierarchical && !m_hasAuthority
+ && (m_path.getLength() == 0 || m_path[0] != '/');
+}
+
+sal_Int32 UriReference::getPathSegmentCount() throw (css::uno::RuntimeException)
+{
+ osl::MutexGuard g(m_mutex);
+ if (!m_isHierarchical || m_path.getLength() == 0) {
+ return 0;
+ } else {
+ sal_Int32 n = m_path[0] == '/' ? 0 : 1;
+ for (sal_Int32 i = 0;; ++i) {
+ i = m_path.indexOf('/', i);
+ if (i < 0) {
+ break;
+ }
+ ++n;
+ }
+ return n;
+ }
+}
+
+rtl::OUString UriReference::getPathSegment(sal_Int32 index)
+ throw (css::uno::RuntimeException)
+{
+ osl::MutexGuard g(m_mutex);
+ if (m_isHierarchical && m_path.getLength() != 0 && index >= 0) {
+ for (sal_Int32 i = m_path[0] == '/' ? 1 : 0;; ++i) {
+ if (index-- == 0) {
+ sal_Int32 j = m_path.indexOf('/', i);
+ return j < 0 ? m_path.copy(i) : m_path.copy(i, j - i);
+ }
+ i = m_path.indexOf('/', i);
+ if (i < 0) {
+ break;
+ }
+ }
+ }
+ return rtl::OUString();
+}
+
+sal_Bool UriReference::hasQuery() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ return m_hasQuery;
+}
+
+rtl::OUString UriReference::getQuery() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ return m_query;
+}
+
+sal_Bool UriReference::hasFragment() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ return m_hasFragment;
+}
+
+rtl::OUString UriReference::getFragment() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ return m_fragment;
+}
+
+void UriReference::setFragment(rtl::OUString const & fragment)
+ throw (css::uno::RuntimeException)
+{
+ osl::MutexGuard g(m_mutex);
+ m_hasFragment = true;
+ m_fragment = fragment;
+}
+
+void UriReference::clearFragment() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_mutex);
+ m_hasFragment = false;
+ m_fragment = rtl::OUString();
+}
+
+void UriReference::appendSchemeSpecificPart(rtl::OUStringBuffer & buffer) const
+{
+ if (m_hasAuthority) {
+ buffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
+ buffer.append(m_authority);
+ }
+ buffer.append(m_path);
+ if (m_hasQuery) {
+ buffer.append(static_cast< sal_Unicode >('?'));
+ buffer.append(m_query);
+ }
+}
diff --git a/stoc/source/uriproc/UriReference.hxx b/stoc/source/uriproc/UriReference.hxx
new file mode 100644
index 000000000000..f73f310ea066
--- /dev/null
+++ b/stoc/source/uriproc/UriReference.hxx
@@ -0,0 +1,111 @@
+/*************************************************************************
+ *
+ * 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: UriReference.hxx,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.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_stoc_source_uriproc_UriReference_hxx
+#define INCLUDED_stoc_source_uriproc_UriReference_hxx
+
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "osl/mutex.hxx"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+
+namespace rtl { class OUStringBuffer; }
+
+namespace stoc { namespace uriproc {
+
+class UriReference {
+public:
+ UriReference(
+ rtl::OUString const & scheme, bool isHierarchical, bool hasAuthority,
+ rtl::OUString const & authority, rtl::OUString const & path,
+ bool hasQuery, rtl::OUString const & query);
+
+ ~UriReference();
+
+ rtl::OUString getUriReference()
+ throw (com::sun::star::uno::RuntimeException);
+
+ sal_Bool isAbsolute() throw (com::sun::star::uno::RuntimeException);
+
+ rtl::OUString getScheme() throw (com::sun::star::uno::RuntimeException);
+
+ rtl::OUString getSchemeSpecificPart()
+ throw (com::sun::star::uno::RuntimeException);
+
+ sal_Bool isHierarchical() throw (com::sun::star::uno::RuntimeException);
+
+ sal_Bool hasAuthority() throw (com::sun::star::uno::RuntimeException);
+
+ rtl::OUString getAuthority() throw (com::sun::star::uno::RuntimeException);
+
+ rtl::OUString getPath() throw (com::sun::star::uno::RuntimeException);
+
+ sal_Bool hasRelativePath() throw (com::sun::star::uno::RuntimeException);
+
+ sal_Int32 getPathSegmentCount()
+ throw (com::sun::star::uno::RuntimeException);
+
+ rtl::OUString getPathSegment(sal_Int32 index)
+ throw (com::sun::star::uno::RuntimeException);
+
+ sal_Bool hasQuery() throw (com::sun::star::uno::RuntimeException);
+
+ rtl::OUString getQuery() throw (com::sun::star::uno::RuntimeException);
+
+ sal_Bool hasFragment() throw (com::sun::star::uno::RuntimeException);
+
+ rtl::OUString getFragment() throw (com::sun::star::uno::RuntimeException);
+
+ void setFragment(rtl::OUString const & fragment)
+ throw (com::sun::star::uno::RuntimeException);
+
+ void clearFragment() throw (com::sun::star::uno::RuntimeException);
+
+ osl::Mutex m_mutex;
+ rtl::OUString m_scheme;
+ rtl::OUString m_authority;
+ rtl::OUString m_path;
+ rtl::OUString m_query;
+ rtl::OUString m_fragment;
+ bool m_isHierarchical;
+ bool m_hasAuthority;
+ bool m_hasQuery;
+ bool m_hasFragment;
+
+private:
+ UriReference(UriReference &); // not implemented
+ void operator =(UriReference); // not implemented
+
+ void appendSchemeSpecificPart(rtl::OUStringBuffer & buffer) const;
+};
+
+} }
+
+#endif
diff --git a/stoc/source/uriproc/UriReferenceFactory.cxx b/stoc/source/uriproc/UriReferenceFactory.cxx
new file mode 100644
index 000000000000..96863ced36ca
--- /dev/null
+++ b/stoc/source/uriproc/UriReferenceFactory.cxx
@@ -0,0 +1,727 @@
+/*************************************************************************
+ *
+ * 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: UriReferenceFactory.cxx,v $
+ * $Revision: 1.8 $
+ *
+ * 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_stoc.hxx"
+
+#include "stocservices.hxx"
+
+#include "UriReference.hxx"
+#include "supportsService.hxx"
+
+#include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
+#include "com/sun/star/lang/XMultiComponentFactory.hpp"
+#include "com/sun/star/lang/XServiceInfo.hpp"
+#include "com/sun/star/uno/Any.hxx"
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/uno/XComponentContext.hpp"
+#include "com/sun/star/uno/XInterface.hpp"
+#include "com/sun/star/uri/RelativeUriExcessParentSegments.hpp"
+#include "com/sun/star/uri/XUriReference.hpp"
+#include "com/sun/star/uri/XUriReferenceFactory.hpp"
+#include "com/sun/star/uri/XUriSchemeParser.hpp"
+#include "cppuhelper/implbase1.hxx"
+#include "cppuhelper/implbase2.hxx"
+#include "cppuhelper/weak.hxx"
+#include "osl/diagnose.h"
+#include "rtl/string.h"
+#include "rtl/ustrbuf.hxx"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+
+#include <algorithm>
+#include /*MSVC trouble: <cstdlib>*/ <stdlib.h>
+#include <new>
+#include <vector>
+
+namespace css = com::sun::star;
+
+namespace {
+
+bool isDigit(sal_Unicode c) { //TODO: generally available?
+ return c >= '0' && c <= '9';
+}
+
+bool isUpperCase(sal_Unicode c) { //TODO: generally available?
+ return c >= 'A' && c <= 'Z';
+}
+
+bool isLowerCase(sal_Unicode c) { //TODO: generally available?
+ return c >= 'a' && c <= 'z';
+}
+
+bool isAlpha(sal_Unicode c) { //TODO: generally available?
+ return isUpperCase(c) || isLowerCase(c);
+}
+
+bool isHexDigit(sal_Unicode c) { //TODO: generally available?
+ return isDigit(c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');
+}
+
+sal_Unicode toLowerCase(sal_Unicode c) { //TODO: generally available?
+ return isUpperCase(c) ? c + ('a' - 'A') : c;
+}
+
+bool equalIgnoreCase(sal_Unicode c1, sal_Unicode c2) {
+ //TODO: generally available?
+ return toLowerCase(c1) == toLowerCase(c2);
+}
+
+bool equalIgnoreEscapeCase(rtl::OUString const & s1, rtl::OUString const & s2) {
+ if (s1.getLength() == s2.getLength()) {
+ for (sal_Int32 i = 0; i < s1.getLength();) {
+ if (s1[i] == '%' && s2[i] == '%' && s1.getLength() - i > 2
+ && isHexDigit(s1[i + 1]) && isHexDigit(s1[i + 2])
+ && isHexDigit(s2[i + 1]) && isHexDigit(s2[i + 2])
+ && equalIgnoreCase(s1[i + 1], s2[i + 1])
+ && equalIgnoreCase(s1[i + 2], s2[i + 2]))
+ {
+ i += 3;
+ } else if (s1[i] != s2[i]) {
+ return false;
+ } else {
+ ++i;
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+sal_Int32 parseScheme(rtl::OUString const & uriReference) {
+ if (uriReference.getLength() >= 2 && isAlpha(uriReference[0])) {
+ for (sal_Int32 i = 0; i < uriReference.getLength(); ++i) {
+ sal_Unicode c = uriReference[i];
+ if (c == ':') {
+ return i;
+ } else if (!isAlpha(c) && !isDigit(c) && c != '+' && c != '-'
+ && c != '.')
+ {
+ break;
+ }
+ }
+ }
+ return -1;
+}
+
+class UriReference: public cppu::WeakImplHelper1< css::uri::XUriReference > {
+public:
+ UriReference(
+ rtl::OUString const & scheme, bool bIsHierarchical, bool bHasAuthority,
+ rtl::OUString const & authority, rtl::OUString const & path,
+ bool bHasQuery, rtl::OUString const & query):
+ m_base(
+ scheme, bIsHierarchical, bHasAuthority, authority, path, bHasQuery,
+ query)
+ {}
+
+ virtual rtl::OUString SAL_CALL getUriReference()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getUriReference(); }
+
+ virtual sal_Bool SAL_CALL isAbsolute()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.isAbsolute(); }
+
+ virtual rtl::OUString SAL_CALL getScheme()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getScheme(); }
+
+ virtual rtl::OUString SAL_CALL getSchemeSpecificPart()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getSchemeSpecificPart(); }
+
+ virtual sal_Bool SAL_CALL isHierarchical()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.isHierarchical(); }
+
+ virtual sal_Bool SAL_CALL hasAuthority()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.hasAuthority(); }
+
+ virtual rtl::OUString SAL_CALL getAuthority()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getAuthority(); }
+
+ virtual rtl::OUString SAL_CALL getPath()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getPath(); }
+
+ virtual sal_Bool SAL_CALL hasRelativePath()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.hasRelativePath(); }
+
+ virtual sal_Int32 SAL_CALL getPathSegmentCount()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getPathSegmentCount(); }
+
+ virtual rtl::OUString SAL_CALL getPathSegment(sal_Int32 index)
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getPathSegment(index); }
+
+ virtual sal_Bool SAL_CALL hasQuery()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.hasQuery(); }
+
+ virtual rtl::OUString SAL_CALL getQuery()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getQuery(); }
+
+ virtual sal_Bool SAL_CALL hasFragment()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.hasFragment(); }
+
+ virtual rtl::OUString SAL_CALL getFragment()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getFragment(); }
+
+ virtual void SAL_CALL setFragment(rtl::OUString const & fragment)
+ throw (com::sun::star::uno::RuntimeException)
+ { m_base.setFragment(fragment); }
+
+ virtual void SAL_CALL clearFragment()
+ throw (com::sun::star::uno::RuntimeException)
+ { m_base.clearFragment(); }
+
+private:
+ UriReference(UriReference &); // not implemented
+ void operator =(UriReference); // not implemented
+
+ virtual ~UriReference() {}
+
+ stoc::uriproc::UriReference m_base;
+};
+
+// throws std::bad_alloc
+css::uno::Reference< css::uri::XUriReference > parseGeneric(
+ rtl::OUString const & scheme, rtl::OUString const & schemeSpecificPart)
+{
+ bool isAbsolute = scheme.getLength() != 0;
+ bool isHierarchical
+ = !isAbsolute
+ || (schemeSpecificPart.getLength() > 0 && schemeSpecificPart[0] == '/');
+ bool hasAuthority = false;
+ rtl::OUString authority;
+ rtl::OUString path;
+ bool hasQuery = false;
+ rtl::OUString query;
+ if (isHierarchical) {
+ sal_Int32 len = schemeSpecificPart.getLength();
+ sal_Int32 i = 0;
+ if (len - i >= 2 && schemeSpecificPart[i] == '/'
+ && schemeSpecificPart[i + 1] == '/')
+ {
+ i += 2;
+ sal_Int32 n = i;
+ while (i < len && schemeSpecificPart[i] != '/'
+ && schemeSpecificPart[i] != '?') {
+ ++i;
+ }
+ hasAuthority = true;
+ authority = schemeSpecificPart.copy(n, i - n);
+ }
+ sal_Int32 n = i;
+ i = schemeSpecificPart.indexOf('?', i);
+ if (i == -1) {
+ i = len;
+ }
+ path = schemeSpecificPart.copy(n, i - n);
+ if (i != len) {
+ hasQuery = true;
+ query = schemeSpecificPart.copy(i + 1);
+ }
+ } else {
+ if (schemeSpecificPart.getLength() == 0) {
+ // The scheme-specific part of an opaque URI must not be empty:
+ return 0;
+ }
+ path = schemeSpecificPart;
+ }
+ return new UriReference(
+ scheme, isHierarchical, hasAuthority, authority, path, hasQuery, query);
+}
+
+typedef std::vector< sal_Int32 > Segments;
+
+void processSegments(
+ Segments & segments,
+ css::uno::Reference< css::uri::XUriReference > const & uriReference,
+ bool base, bool processSpecialSegments)
+{
+ sal_Int32 count = uriReference->getPathSegmentCount() - (base ? 1 : 0);
+ OSL_ASSERT(count <= SAL_MAX_INT32 - 1 && -count >= SAL_MIN_INT32 + 1);
+ for (sal_Int32 i = 0; i < count; ++i) {
+ if (processSpecialSegments) {
+ rtl::OUString segment(uriReference->getPathSegment(i));
+ if (segment.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("."))) {
+ if (!base && i == count - 1) {
+ segments.push_back(0);
+ }
+ continue;
+ } else if (segment.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(".."))) {
+ if (segments.empty()
+ || /*MSVC trouble: std::*/abs(segments.back()) == 1)
+ {
+ segments.push_back(base ? -1 : 1);
+ } else {
+ segments.pop_back();
+ }
+ continue;
+ }
+ }
+ segments.push_back(base ? -(i + 2) : i + 2);
+ }
+}
+
+class Factory: public cppu::WeakImplHelper2<
+ css::lang::XServiceInfo, css::uri::XUriReferenceFactory >
+{
+public:
+ explicit Factory(
+ css::uno::Reference< css::uno::XComponentContext > const & context):
+ m_context(context) {}
+
+ virtual rtl::OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException);
+
+ virtual css::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames() throw (css::uno::RuntimeException);
+
+ virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
+ parse(rtl::OUString const & uriReference)
+ throw (css::uno::RuntimeException);
+
+ virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
+ makeAbsolute(
+ css::uno::Reference< css::uri::XUriReference > const & baseUriReference,
+ css::uno::Reference< css::uri::XUriReference > const & uriReference,
+ sal_Bool processSpecialBaseSegments,
+ css::uri::RelativeUriExcessParentSegments excessParentSegments)
+ throw (css::uno::RuntimeException);
+
+ virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
+ makeRelative(
+ css::uno::Reference< css::uri::XUriReference > const & baseUriReference,
+ css::uno::Reference< css::uri::XUriReference > const & uriReference,
+ sal_Bool preferAuthorityOverRelativePath,
+ sal_Bool preferAbsoluteOverRelativePath,
+ sal_Bool encodeRetainedSpecialSegments)
+ throw (css::uno::RuntimeException);
+
+private:
+ Factory(Factory &); // not implemented
+ void operator =(Factory); // not implemented
+
+ virtual ~Factory() {}
+
+ css::uno::Reference< css::uri::XUriReference > clone(
+ css::uno::Reference< css::uri::XUriReference > const & uriReference)
+ { return parse(uriReference->getUriReference()); }
+
+ css::uno::Reference< css::uno::XComponentContext > m_context;
+};
+
+rtl::OUString Factory::getImplementationName()
+ throw (css::uno::RuntimeException)
+{
+ return stoc_services::UriReferenceFactory::getImplementationName();
+}
+
+sal_Bool Factory::supportsService(rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException)
+{
+ return stoc::uriproc::supportsService(
+ getSupportedServiceNames(), serviceName);
+}
+
+css::uno::Sequence< rtl::OUString > Factory::getSupportedServiceNames()
+ throw (css::uno::RuntimeException)
+{
+ return stoc_services::UriReferenceFactory::getSupportedServiceNames();
+}
+
+css::uno::Reference< css::uri::XUriReference > Factory::parse(
+ rtl::OUString const & uriReference) throw (css::uno::RuntimeException)
+{
+ sal_Int32 fragment = uriReference.indexOf('#');
+ if (fragment == -1) {
+ fragment = uriReference.getLength();
+ }
+ rtl::OUString scheme;
+ rtl::OUString schemeSpecificPart;
+ rtl::OUString serviceName;
+ sal_Int32 n = parseScheme(uriReference);
+ OSL_ASSERT(n < fragment);
+ if (n >= 0) {
+ scheme = uriReference.copy(0, n);
+ schemeSpecificPart = uriReference.copy(n + 1, fragment - (n + 1));
+ rtl::OUStringBuffer buf;
+ buf.appendAscii(
+ RTL_CONSTASCII_STRINGPARAM("com.sun.star.uri.UriSchemeParser_"));
+ for (sal_Int32 i = 0; i < scheme.getLength(); ++i) {
+ sal_Unicode c = scheme[i];
+ if (isUpperCase(c)) {
+ buf.append(toLowerCase(c));
+ } else if (c == '+') {
+ buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("PLUS"));
+ } else if (c == '-') {
+ buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("HYPHEN"));
+ } else if (c == '.') {
+ buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("DOT"));
+ } else {
+ OSL_ASSERT(isLowerCase(c) || isDigit(c));
+ buf.append(c);
+ }
+ }
+ serviceName = buf.makeStringAndClear();
+ } else {
+ schemeSpecificPart = uriReference.copy(0, fragment);
+ }
+ css::uno::Reference< css::uri::XUriSchemeParser > parser;
+ if (serviceName.getLength() != 0) {
+ css::uno::Reference< css::lang::XMultiComponentFactory > factory(
+ m_context->getServiceManager());
+ if (factory.is()) {
+ css::uno::Reference< css::uno::XInterface > service;
+ try {
+ service = factory->createInstanceWithContext(
+ serviceName, m_context);
+ } catch (css::uno::RuntimeException &) {
+ throw;
+ } catch (css::uno::Exception & e) {
+ throw css::lang::WrappedTargetRuntimeException(
+ rtl::OUString::createFromAscii("creating service ")
+ + serviceName,
+ static_cast< cppu::OWeakObject * >(this),
+ css::uno::makeAny(e)); //TODO: preserve type of e
+ }
+ if (service.is()) {
+ parser = css::uno::Reference< css::uri::XUriSchemeParser >(
+ service, css::uno::UNO_QUERY_THROW);
+ }
+ }
+ }
+ css::uno::Reference< css::uri::XUriReference > uriRef;
+ if (parser.is()) {
+ uriRef = parser->parse(scheme, schemeSpecificPart);
+ } else {
+ try {
+ uriRef = parseGeneric(scheme, schemeSpecificPart);
+ } catch (std::bad_alloc &) {
+ throw css::uno::RuntimeException(
+ rtl::OUString::createFromAscii("std::bad_alloc"),
+ static_cast< cppu::OWeakObject * >(this));
+ }
+ }
+ if (uriRef.is() && fragment != uriReference.getLength()) {
+ uriRef->setFragment(uriReference.copy(fragment + 1));
+ }
+ return uriRef;
+}
+
+css::uno::Reference< css::uri::XUriReference > Factory::makeAbsolute(
+ css::uno::Reference< css::uri::XUriReference > const & baseUriReference,
+ css::uno::Reference< css::uri::XUriReference > const & uriReference,
+ sal_Bool processSpecialBaseSegments,
+ css::uri::RelativeUriExcessParentSegments excessParentSegments)
+ throw (css::uno::RuntimeException)
+{
+ if (!baseUriReference.is() || !baseUriReference->isAbsolute()
+ || !baseUriReference->isHierarchical() || !uriReference.is()) {
+ return 0;
+ } else if (uriReference->isAbsolute()) {
+ return clone(uriReference);
+ } else if (!uriReference->hasAuthority()
+ && uriReference->getPath().getLength() == 0
+ && !uriReference->hasQuery()) {
+ css::uno::Reference< css::uri::XUriReference > abs(
+ clone(baseUriReference));
+ if (uriReference->hasFragment()) {
+ abs->setFragment(uriReference->getFragment());
+ } else {
+ abs->clearFragment();
+ }
+ return abs;
+ } else {
+ rtl::OUStringBuffer abs(baseUriReference->getScheme());
+ abs.append(static_cast< sal_Unicode >(':'));
+ if (uriReference->hasAuthority()) {
+ abs.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
+ abs.append(uriReference->getAuthority());
+ } else if (baseUriReference->hasAuthority()) {
+ abs.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
+ abs.append(baseUriReference->getAuthority());
+ }
+ if (uriReference->hasRelativePath()) {
+ Segments segments;
+ processSegments(
+ segments, baseUriReference, true, processSpecialBaseSegments);
+ processSegments(segments, uriReference, false, true);
+ // If the path component of the base URI reference is empty (which
+ // implies that the base URI reference denotes a "root entity"), and
+ // the resulting URI reference denotes the same root entity, make
+ // sure the path component of the resulting URI reference is also
+ // empty (and not "/"). RFC 2396 is unclear about this, and I chose
+ // these rules for consistent results.
+ bool slash = baseUriReference->getPath().getLength() != 0;
+ if (slash) {
+ abs.append(static_cast< sal_Unicode >('/'));
+ }
+ for (Segments::iterator i(segments.begin()); i != segments.end();
+ ++i)
+ {
+ if (*i < -1) {
+ rtl::OUString segment(
+ baseUriReference->getPathSegment(-(*i + 2)));
+ if (segment.getLength() != 0 || segments.size() > 1) {
+ if (!slash) {
+ abs.append(static_cast< sal_Unicode >('/'));
+ }
+ abs.append(segment);
+ slash = true;
+ abs.append(static_cast< sal_Unicode >('/'));
+ }
+ } else if (*i > 1) {
+ rtl::OUString segment(uriReference->getPathSegment(*i - 2));
+ if (segment.getLength() != 0 || segments.size() > 1) {
+ if (!slash) {
+ abs.append(static_cast< sal_Unicode >('/'));
+ }
+ abs.append(segment);
+ slash = false;
+ }
+ } else if (*i == 0) {
+ if (segments.size() > 1 && !slash) {
+ abs.append(static_cast< sal_Unicode >('/'));
+ }
+ } else {
+ switch (excessParentSegments) {
+ case css::uri::RelativeUriExcessParentSegments_ERROR:
+ return 0;
+
+ case css::uri::RelativeUriExcessParentSegments_RETAIN:
+ if (!slash) {
+ abs.append(static_cast< sal_Unicode >('/'));
+ }
+ abs.appendAscii(RTL_CONSTASCII_STRINGPARAM(".."));
+ slash = *i < 0;
+ if (slash) {
+ abs.append(static_cast< sal_Unicode >('/'));
+ }
+ break;
+
+ case css::uri::RelativeUriExcessParentSegments_REMOVE:
+ break;
+
+ default:
+ OSL_ASSERT(false);
+ break;
+ }
+ }
+ }
+ } else {
+ abs.append(uriReference->getPath());
+ }
+ if (uriReference->hasQuery()) {
+ abs.append(static_cast< sal_Unicode >('?'));
+ abs.append(uriReference->getQuery());
+ }
+ if (uriReference->hasFragment()) {
+ abs.append(static_cast< sal_Unicode >('#'));
+ abs.append(uriReference->getFragment());
+ }
+ return parse(abs.makeStringAndClear());
+ }
+}
+
+css::uno::Reference< css::uri::XUriReference > Factory::makeRelative(
+ css::uno::Reference< css::uri::XUriReference > const & baseUriReference,
+ css::uno::Reference< css::uri::XUriReference > const & uriReference,
+ sal_Bool preferAuthorityOverRelativePath,
+ sal_Bool preferAbsoluteOverRelativePath,
+ sal_Bool encodeRetainedSpecialSegments)
+ throw (css::uno::RuntimeException)
+{
+ if (!baseUriReference.is() || !baseUriReference->isAbsolute()
+ || !baseUriReference->isHierarchical() || !uriReference.is()) {
+ return 0;
+ } else if (!uriReference->isAbsolute() || !uriReference->isHierarchical()
+ || !baseUriReference->getScheme().equalsIgnoreAsciiCase(
+ uriReference->getScheme())) {
+ return clone(uriReference);
+ } else {
+ rtl::OUStringBuffer rel;
+ bool omitQuery = false;
+ if ((baseUriReference->hasAuthority() != uriReference->hasAuthority())
+ || !equalIgnoreEscapeCase(
+ baseUriReference->getAuthority(),
+ uriReference->getAuthority()))
+ {
+ if (uriReference->hasAuthority()) {
+ rel.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
+ rel.append(uriReference->getAuthority());
+ }
+ rel.append(uriReference->getPath());
+ } else if ((equalIgnoreEscapeCase(
+ baseUriReference->getPath(), uriReference->getPath())
+ || (baseUriReference->getPath().getLength() <= 1
+ && uriReference->getPath().getLength() <= 1))
+ && baseUriReference->hasQuery() == uriReference->hasQuery()
+ && equalIgnoreEscapeCase(
+ baseUriReference->getQuery(), uriReference->getQuery()))
+ {
+ omitQuery = true;
+ } else {
+ sal_Int32 count1 = std::max< sal_Int32 >(
+ baseUriReference->getPathSegmentCount(), 1);
+ sal_Int32 count2 = std::max< sal_Int32 >(
+ uriReference->getPathSegmentCount(), 1);
+ sal_Int32 i = 0;
+ for (; i < std::min(count1, count2) - 1; ++i) {
+ if (!equalIgnoreEscapeCase(
+ baseUriReference->getPathSegment(i),
+ uriReference->getPathSegment(i)))
+ {
+ break;
+ }
+ }
+ if (i == 0 && preferAbsoluteOverRelativePath
+ && (preferAuthorityOverRelativePath
+ || !uriReference->getPath().matchAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("//"))))
+ {
+ if (baseUriReference->getPath().getLength() > 1
+ || uriReference->getPath().getLength() > 1)
+ {
+ if (uriReference->getPath().getLength() == 0) {
+ rel.append(static_cast< sal_Unicode >('/'));
+ } else {
+ OSL_ASSERT(uriReference->getPath()[0] == '/');
+ if (uriReference->getPath().matchAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("//"))) {
+ OSL_ASSERT(uriReference->hasAuthority());
+ rel.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
+ rel.append(uriReference->getAuthority());
+ }
+ rel.append(uriReference->getPath());
+ }
+ }
+ } else {
+ bool segments = false;
+ for (sal_Int32 j = i; j < count1 - 1; ++j) {
+ if (segments) {
+ rel.append(static_cast< sal_Unicode >('/'));
+ }
+ rel.appendAscii(RTL_CONSTASCII_STRINGPARAM(".."));
+ segments = true;
+ }
+ if (i < count2 - 1
+ || (uriReference->getPathSegment(count2 - 1).getLength()
+ != 0))
+ {
+ if (!segments
+ && (uriReference->getPathSegment(i).getLength() == 0
+ || (parseScheme(uriReference->getPathSegment(i))
+ >= 0)))
+ {
+ rel.append(static_cast< sal_Unicode >('.'));
+ segments = true;
+ }
+ for (; i < count2; ++i) {
+ if (segments) {
+ rel.append(static_cast< sal_Unicode >('/'));
+ }
+ rtl::OUString s(uriReference->getPathSegment(i));
+ if (encodeRetainedSpecialSegments
+ && s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(".")))
+ {
+ rel.appendAscii(RTL_CONSTASCII_STRINGPARAM("%2E"));
+ } else if (encodeRetainedSpecialSegments
+ && s.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("..")))
+ {
+ rel.appendAscii(
+ RTL_CONSTASCII_STRINGPARAM("%2E%2E"));
+ } else {
+ rel.append(s);
+ }
+ segments = true;
+ }
+ }
+ }
+ }
+ if (!omitQuery && uriReference->hasQuery()) {
+ rel.append(static_cast< sal_Unicode >('?'));
+ rel.append(uriReference->getQuery());
+ }
+ if (uriReference->hasFragment()) {
+ rel.append(static_cast< sal_Unicode >('#'));
+ rel.append(uriReference->getFragment());
+ }
+ return parse(rel.makeStringAndClear());
+ }
+}
+
+}
+
+namespace stoc_services { namespace UriReferenceFactory {
+
+css::uno::Reference< css::uno::XInterface > create(
+ css::uno::Reference< css::uno::XComponentContext > const & context)
+ SAL_THROW((css::uno::Exception))
+{
+ try {
+ return static_cast< cppu::OWeakObject * >(new Factory(context));
+ } catch (std::bad_alloc &) {
+ throw css::uno::RuntimeException(
+ rtl::OUString::createFromAscii("std::bad_alloc"), 0);
+ }
+}
+
+rtl::OUString getImplementationName() {
+ return rtl::OUString::createFromAscii(
+ "com.sun.star.comp.uri.UriReferenceFactory");
+}
+
+css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
+ css::uno::Sequence< rtl::OUString > s(1);
+ s[0] = rtl::OUString::createFromAscii(
+ "com.sun.star.uri.UriReferenceFactory");
+ return s;
+}
+
+} }
diff --git a/stoc/source/uriproc/UriReferenceFactory.hxx b/stoc/source/uriproc/UriReferenceFactory.hxx
new file mode 100644
index 000000000000..6468f5c57856
--- /dev/null
+++ b/stoc/source/uriproc/UriReferenceFactory.hxx
@@ -0,0 +1,62 @@
+/*************************************************************************
+ *
+ * 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: UriReferenceFactory.hxx,v $
+ * $Revision: 1.4 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_stoc_source_uriproc_UriReferenceFactory_hxx
+#define INCLUDED_stoc_source_uriproc_UriReferenceFactory_hxx
+
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "sal/types.h"
+
+namespace com { namespace sun { namespace star { namespace uno {
+ class XComponentContext;
+ class XInterface;
+} } } }
+namespace rtl { class OUString; }
+
+namespace stoc { namespace uriproc {
+
+namespace UriReferenceFactory {
+ com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL
+ create(
+ com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
+ const & context)
+ SAL_THROW((com::sun::star::uno::Exception));
+
+ rtl::OUString SAL_CALL getImplementationName();
+
+ com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames();
+}
+
+} }
+
+#endif
diff --git a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.cxx b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.cxx
new file mode 100644
index 000000000000..92773d8af8ae
--- /dev/null
+++ b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.cxx
@@ -0,0 +1,271 @@
+/*************************************************************************
+ *
+ * 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: UriSchemeParser_vndDOTsunDOTstarDOTexpand.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_stoc.hxx"
+
+#include "sal/config.h"
+
+#include "stocservices.hxx"
+
+#include <new>
+
+#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"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/uno/XInterface.hpp"
+#include "com/sun/star/uri/XUriReference.hpp"
+#include "com/sun/star/uri/XUriSchemeParser.hpp"
+#include "com/sun/star/uri/XVndSunStarExpandUrlReference.hpp"
+#include "com/sun/star/util/XMacroExpander.hpp"
+#include "cppuhelper/implbase1.hxx"
+#include "cppuhelper/implbase2.hxx"
+#include "cppuhelper/weak.hxx"
+#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 "UriReference.hxx"
+#include "supportsService.hxx"
+
+namespace {
+
+namespace css = ::com::sun::star;
+
+bool parseSchemeSpecificPart(::rtl::OUString const & part) {
+ // Liberally accepts both an empty opaque_part and an opaque_part that
+ // starts with a non-escaped "/":
+ return part.getLength() == 0
+ || ((::rtl::Uri::decode(
+ part, ::rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8).
+ getLength())
+ != 0);
+}
+
+class UrlReference:
+ public ::cppu::WeakImplHelper1< css::uri::XVndSunStarExpandUrlReference >
+{
+public:
+ UrlReference(::rtl::OUString const & scheme, ::rtl::OUString const & path):
+ base_(
+ scheme, false, false, ::rtl::OUString(), path, false,
+ ::rtl::OUString())
+ {}
+
+ virtual ::rtl::OUString SAL_CALL getUriReference()
+ throw (css::uno::RuntimeException)
+ { return base_.getUriReference(); }
+
+ virtual ::sal_Bool SAL_CALL isAbsolute() throw (css::uno::RuntimeException)
+ { return base_.isAbsolute(); }
+
+ virtual ::rtl::OUString SAL_CALL getScheme()
+ throw (css::uno::RuntimeException)
+ { return base_.getScheme(); }
+
+ virtual ::rtl::OUString SAL_CALL getSchemeSpecificPart()
+ throw (css::uno::RuntimeException)
+ { return base_.getSchemeSpecificPart(); }
+
+ virtual ::sal_Bool SAL_CALL isHierarchical()
+ throw (css::uno::RuntimeException)
+ { return base_.isHierarchical(); }
+
+ virtual ::sal_Bool SAL_CALL hasAuthority()
+ throw (css::uno::RuntimeException)
+ { return base_.hasAuthority(); }
+
+ virtual ::rtl::OUString SAL_CALL getAuthority()
+ throw (css::uno::RuntimeException)
+ { return base_.getAuthority(); }
+
+ virtual ::rtl::OUString SAL_CALL getPath()
+ throw (css::uno::RuntimeException)
+ { return base_.getPath(); }
+
+ virtual ::sal_Bool SAL_CALL hasRelativePath()
+ throw (css::uno::RuntimeException)
+ { return base_.hasRelativePath(); }
+
+ virtual ::sal_Int32 SAL_CALL getPathSegmentCount()
+ throw (css::uno::RuntimeException)
+ { return base_.getPathSegmentCount(); }
+
+ virtual ::rtl::OUString SAL_CALL getPathSegment(sal_Int32 index)
+ throw (css::uno::RuntimeException)
+ { return base_.getPathSegment(index); }
+
+ virtual ::sal_Bool SAL_CALL hasQuery() throw (css::uno::RuntimeException)
+ { return base_.hasQuery(); }
+
+ virtual ::rtl::OUString SAL_CALL getQuery()
+ throw (css::uno::RuntimeException)
+ { return base_.getQuery(); }
+
+ virtual ::sal_Bool SAL_CALL hasFragment() throw (css::uno::RuntimeException)
+ { return base_.hasFragment(); }
+
+ virtual ::rtl::OUString SAL_CALL getFragment()
+ throw (css::uno::RuntimeException)
+ { return base_.getFragment(); }
+
+ virtual void SAL_CALL setFragment(::rtl::OUString const & fragment)
+ throw (css::uno::RuntimeException)
+ { base_.setFragment(fragment); }
+
+ virtual void SAL_CALL clearFragment() throw (css::uno::RuntimeException)
+ { base_.clearFragment(); }
+
+ virtual ::rtl::OUString SAL_CALL expand(
+ css::uno::Reference< css::util::XMacroExpander > const & expander)
+ throw (css::lang::IllegalArgumentException, css::uno::RuntimeException);
+
+private:
+ UrlReference(UrlReference &); // not defined
+ void operator =(UrlReference); // not defined
+
+ virtual ~UrlReference() {}
+
+ stoc::uriproc::UriReference base_;
+};
+
+::rtl::OUString UrlReference::expand(
+ css::uno::Reference< css::util::XMacroExpander > const & expander)
+ throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
+{
+ OSL_ASSERT(expander.is());
+ return expander->expandMacros(
+ ::rtl::Uri::decode(
+ getPath(), ::rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8));
+}
+
+class Parser: public ::cppu::WeakImplHelper2<
+ css::lang::XServiceInfo, css::uri::XUriSchemeParser >
+{
+public:
+ Parser() {}
+
+ virtual ::rtl::OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException);
+
+ virtual ::sal_Bool SAL_CALL supportsService(
+ ::rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException);
+
+ virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL
+ getSupportedServiceNames() throw (css::uno::RuntimeException);
+
+ virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
+ parse(
+ ::rtl::OUString const & scheme,
+ ::rtl::OUString const & schemeSpecificPart)
+ throw (css::uno::RuntimeException);
+
+private:
+ Parser(Parser &); // not defined
+ void operator =(Parser); // not defined
+
+ virtual ~Parser() {}
+};
+
+::rtl::OUString Parser::getImplementationName()
+ throw (css::uno::RuntimeException)
+{
+ return ::stoc_services::UriSchemeParser_vndDOTsunDOTstarDOTexpand::
+ getImplementationName();
+}
+
+::sal_Bool Parser::supportsService(::rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException)
+{
+ return ::stoc::uriproc::supportsService(
+ getSupportedServiceNames(), serviceName);
+}
+
+css::uno::Sequence< ::rtl::OUString > Parser::getSupportedServiceNames()
+ throw (css::uno::RuntimeException)
+{
+ return ::stoc_services::UriSchemeParser_vndDOTsunDOTstarDOTexpand::
+ getSupportedServiceNames();
+}
+
+css::uno::Reference< css::uri::XUriReference > Parser::parse(
+ ::rtl::OUString const & scheme, ::rtl::OUString const & schemeSpecificPart)
+ throw (css::uno::RuntimeException)
+{
+ if (!parseSchemeSpecificPart(schemeSpecificPart)) {
+ return css::uno::Reference< css::uri::XUriReference >();
+ }
+ try {
+ return new UrlReference(scheme, schemeSpecificPart);
+ } catch (::std::bad_alloc &) {
+ throw css::uno::RuntimeException(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+}
+
+}
+
+namespace stoc_services { namespace UriSchemeParser_vndDOTsunDOTstarDOTexpand {
+
+css::uno::Reference< css::uno::XInterface > create(
+ css::uno::Reference< css::uno::XComponentContext > const &)
+ SAL_THROW((css::uno::Exception))
+{
+ //TODO: single instance
+ try {
+ return static_cast< ::cppu::OWeakObject * >(new Parser);
+ } catch (::std::bad_alloc &) {
+ throw css::uno::RuntimeException(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+}
+
+::rtl::OUString getImplementationName() {
+ return ::rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand"));
+}
+
+css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames() {
+ css::uno::Sequence< ::rtl::OUString > s(1);
+ s[0] = ::rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand"));
+ return s;
+}
+
+} }
diff --git a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.hxx b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.hxx
new file mode 100644
index 000000000000..3c3b1009f99c
--- /dev/null
+++ b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.hxx
@@ -0,0 +1,65 @@
+/*************************************************************************
+ *
+ * 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: UriSchemeParser_vndDOTsunDOTstarDOTexpand.hxx,v $
+ * $Revision: 1.3 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+#ifndef \
+ INCLUDED_STOC_SOURCE_URIPROC_URISCHEMEPARSER_VNDDOTSUNDOTSTARDOTEXPAND_HXX
+#define \
+ INCLUDED_STOC_SOURCE_URIPROC_URISCHEMEPARSER_VNDDOTSUNDOTSTARDOTEXPAND_HXX
+
+#include "sal/config.h"
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "sal/types.h"
+
+namespace com { namespace sun { namespace star { namespace uno {
+ class XComponentContext;
+ class XInterface;
+} } } }
+namespace rtl { class OUString; }
+
+namespace stoc { namespace uriproc {
+
+namespace UriSchemeParser_vndDOTsunDOTstarDOTexpand {
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+ SAL_CALL create(
+ ::com::sun::star::uno::Reference<
+ ::com::sun::star::uno::XComponentContext > const &)
+ SAL_THROW((::com::sun::star::uno::Exception));
+
+ ::rtl::OUString SAL_CALL getImplementationName();
+
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
+ getSupportedServiceNames();
+}
+
+} }
+
+#endif
diff --git a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx
new file mode 100644
index 000000000000..264f4d09d5f2
--- /dev/null
+++ b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx
@@ -0,0 +1,488 @@
+/*************************************************************************
+ *
+ * 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: UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx,v $
+ * $Revision: 1.8 $
+ *
+ * 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_stoc.hxx"
+
+#include "stocservices.hxx"
+
+#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"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/uno/XInterface.hpp"
+#include "com/sun/star/uri/XUriReference.hpp"
+#include "com/sun/star/uri/XUriSchemeParser.hpp"
+#include "com/sun/star/uri/XVndSunStarScriptUrlReference.hpp"
+#include "cppuhelper/implbase1.hxx"
+#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"
+
+#include <new>
+
+namespace css = com::sun::star;
+
+namespace {
+
+int getHexWeight(sal_Unicode c) {
+ return c >= '0' && c <= '9' ? static_cast< int >(c - '0')
+ : c >= 'A' && c <= 'F' ? static_cast< int >(c - 'A' + 10)
+ : c >= 'a' && c <= 'f' ? static_cast< int >(c - 'a' + 10)
+ : -1;
+}
+
+int parseEscaped(rtl::OUString const & part, sal_Int32 * index) {
+ if (part.getLength() - *index < 3 || part[*index] != '%') {
+ return -1;
+ }
+ int n1 = getHexWeight(part[*index + 1]);
+ int n2 = getHexWeight(part[*index + 2]);
+ if (n1 < 0 || n2 < 0) {
+ return -1;
+ }
+ *index += 3;
+ return (n1 << 4) | n2;
+}
+
+rtl::OUString parsePart(
+ rtl::OUString const & part, bool namePart, sal_Int32 * index)
+{
+ rtl::OUStringBuffer buf;
+ while (*index < part.getLength()) {
+ sal_Unicode c = part[*index];
+ if (namePart ? c == '?' : c == '&' || c == '=') {
+ break;
+ } else if (c == '%') {
+ sal_Int32 i = *index;
+ int n = parseEscaped(part, &i);
+ if (n >= 0 && n <= 0x7F) {
+ buf.append(static_cast< sal_Unicode >(n));
+ } else if (n >= 0xC0 && n <= 0xFC) {
+ sal_Int32 encoded;
+ int shift;
+ sal_Int32 min;
+ if (n <= 0xDF) {
+ encoded = (n & 0x1F) << 6;
+ shift = 0;
+ min = 0x80;
+ } else if (n <= 0xEF) {
+ encoded = (n & 0x0F) << 12;
+ shift = 6;
+ min = 0x800;
+ } else if (n <= 0xF7) {
+ encoded = (n & 0x07) << 18;
+ shift = 12;
+ min = 0x10000;
+ } else if (n <= 0xFB) {
+ encoded = (n & 0x03) << 24;
+ shift = 18;
+ min = 0x200000;
+ } else {
+ encoded = 0;
+ shift = 24;
+ min = 0x4000000;
+ }
+ bool utf8 = true;
+ for (; shift >= 0; shift -= 6) {
+ n = parseEscaped(part, &i);
+ if (n < 0x80 || n > 0xBF) {
+ utf8 = false;
+ break;
+ }
+ encoded |= (n & 0x3F) << shift;
+ }
+ if (!utf8 || encoded < min
+ || (encoded >= 0xD800 && encoded <= 0xDFFF)
+ || encoded > 0x10FFFF)
+ {
+ break;
+ }
+ if (encoded <= 0xFFFF) {
+ buf.append(static_cast< sal_Unicode >(encoded));
+ } else {
+ buf.append(static_cast< sal_Unicode >(
+ (encoded >> 10) | 0xD800));
+ buf.append(static_cast< sal_Unicode >(
+ (encoded & 0x3FF) | 0xDC00));
+ }
+ } else {
+ break;
+ }
+ *index = i;
+ } else {
+ buf.append(c);
+ ++*index;
+ }
+ }
+ 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;
+ if (parsePart(part, true, &i).getLength() == 0 || part[0] == '/') {
+ return false;
+ }
+ if (i == len) {
+ return true;
+ }
+ for (;;) {
+ ++i; // skip '?' or '&'
+ if (parsePart(part, false, &i).getLength() == 0 || i == len
+ || part[i] != '=')
+ {
+ return false;
+ }
+ ++i;
+ parsePart(part, false, &i);
+ if (i == len) {
+ return true;
+ }
+ if (part[i] != '&') {
+ return false;
+ }
+ }
+}
+
+class UrlReference:
+ public cppu::WeakImplHelper1< css::uri::XVndSunStarScriptUrlReference >
+{
+public:
+ UrlReference(rtl::OUString const & scheme, rtl::OUString const & path):
+ m_base(
+ scheme, false, false, rtl::OUString(), path, false, rtl::OUString())
+ {}
+
+ virtual rtl::OUString SAL_CALL getUriReference()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getUriReference(); }
+
+ virtual sal_Bool SAL_CALL isAbsolute()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.isAbsolute(); }
+
+ virtual rtl::OUString SAL_CALL getScheme()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getScheme(); }
+
+ virtual rtl::OUString SAL_CALL getSchemeSpecificPart()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getSchemeSpecificPart(); }
+
+ virtual sal_Bool SAL_CALL isHierarchical()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.isHierarchical(); }
+
+ virtual sal_Bool SAL_CALL hasAuthority()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.hasAuthority(); }
+
+ virtual rtl::OUString SAL_CALL getAuthority()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getAuthority(); }
+
+ virtual rtl::OUString SAL_CALL getPath()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getPath(); }
+
+ virtual sal_Bool SAL_CALL hasRelativePath()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.hasRelativePath(); }
+
+ virtual sal_Int32 SAL_CALL getPathSegmentCount()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getPathSegmentCount(); }
+
+ virtual rtl::OUString SAL_CALL getPathSegment(sal_Int32 index)
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getPathSegment(index); }
+
+ virtual sal_Bool SAL_CALL hasQuery()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.hasQuery(); }
+
+ virtual rtl::OUString SAL_CALL getQuery()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getQuery(); }
+
+ virtual sal_Bool SAL_CALL hasFragment()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.hasFragment(); }
+
+ virtual rtl::OUString SAL_CALL getFragment()
+ throw (com::sun::star::uno::RuntimeException)
+ { return m_base.getFragment(); }
+
+ virtual void SAL_CALL setFragment(rtl::OUString const & fragment)
+ throw (com::sun::star::uno::RuntimeException)
+ { m_base.setFragment(fragment); }
+
+ virtual void SAL_CALL clearFragment()
+ throw (com::sun::star::uno::RuntimeException)
+ { m_base.clearFragment(); }
+
+ 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
+
+ virtual ~UrlReference() {}
+
+ sal_Int32 findParameter(rtl::OUString const & key);
+
+ stoc::uriproc::UriReference m_base;
+};
+
+rtl::OUString UrlReference::getName() throw (css::uno::RuntimeException) {
+ osl::MutexGuard g(m_base.m_mutex);
+ sal_Int32 i = 0;
+ 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)
+{
+ osl::MutexGuard g(m_base.m_mutex);
+ return findParameter(key) >= 0;
+}
+
+rtl::OUString UrlReference::getParameter(rtl::OUString const & key)
+ throw (css::uno::RuntimeException)
+{
+ osl::MutexGuard g(m_base.m_mutex);
+ sal_Int32 i = findParameter(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
+ for (;;) {
+ if (i == m_base.m_path.getLength()) {
+ return -1;
+ }
+ ++i; // skip '?' or '&'
+ rtl::OUString k = parsePart(m_base.m_path, false, &i);
+ ++i; // skip '='
+ if (k == key) {
+ return i;
+ }
+ parsePart(m_base.m_path, false, &i); // skip value
+ }
+}
+
+class Parser: public cppu::WeakImplHelper2<
+ css::lang::XServiceInfo, css::uri::XUriSchemeParser >
+{
+public:
+ Parser() {}
+
+ virtual rtl::OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException);
+
+ virtual css::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames() throw (css::uno::RuntimeException);
+
+ virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
+ parse(
+ rtl::OUString const & scheme, rtl::OUString const & schemeSpecificPart)
+ throw (css::uno::RuntimeException);
+
+private:
+ Parser(Parser &); // not implemented
+ void operator =(Parser); // not implemented
+
+ virtual ~Parser() {}
+};
+
+rtl::OUString Parser::getImplementationName()
+ throw (css::uno::RuntimeException)
+{
+ return stoc_services::UriSchemeParser_vndDOTsunDOTstarDOTscript::
+ getImplementationName();
+}
+
+sal_Bool Parser::supportsService(rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException)
+{
+ return stoc::uriproc::supportsService(
+ getSupportedServiceNames(), serviceName);
+}
+
+css::uno::Sequence< rtl::OUString > Parser::getSupportedServiceNames()
+ throw (css::uno::RuntimeException)
+{
+ return stoc_services::UriSchemeParser_vndDOTsunDOTstarDOTscript::
+ getSupportedServiceNames();
+}
+
+css::uno::Reference< css::uri::XUriReference >
+Parser::parse(
+ rtl::OUString const & scheme, rtl::OUString const & schemeSpecificPart)
+ throw (css::uno::RuntimeException)
+{
+ if (!parseSchemeSpecificPart(schemeSpecificPart)) {
+ return 0;
+ }
+ try {
+ return new UrlReference(scheme, schemeSpecificPart);
+ } catch (std::bad_alloc &) {
+ throw css::uno::RuntimeException(
+ rtl::OUString::createFromAscii("std::bad_alloc"), 0);
+ }
+}
+
+}
+
+namespace stoc_services {
+namespace UriSchemeParser_vndDOTsunDOTstarDOTscript {
+
+css::uno::Reference< css::uno::XInterface > create(
+ css::uno::Reference< css::uno::XComponentContext > const &)
+ SAL_THROW((css::uno::Exception))
+{
+ //TODO: single instance
+ try {
+ return static_cast< cppu::OWeakObject * >(new Parser);
+ } catch (std::bad_alloc &) {
+ throw css::uno::RuntimeException(
+ rtl::OUString::createFromAscii("std::bad_alloc"), 0);
+ }
+}
+
+rtl::OUString getImplementationName() {
+ return rtl::OUString::createFromAscii(
+ "com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTscript");
+}
+
+css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
+ css::uno::Sequence< rtl::OUString > s(1);
+ s[0] = rtl::OUString::createFromAscii(
+ "com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTscript");
+ return s;
+}
+
+} }
diff --git a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.hxx b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.hxx
new file mode 100644
index 000000000000..e4ec6c29583e
--- /dev/null
+++ b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.hxx
@@ -0,0 +1,64 @@
+/*************************************************************************
+ *
+ * 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: UriSchemeParser_vndDOTsunDOTstarDOTscript.hxx,v $
+ * $Revision: 1.4 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+#ifndef \
+ INCLUDED_stoc_source_uriproc_UriSchemeParser_vndDOTsunDOTstarDOTscript_hxx
+#define \
+ INCLUDED_stoc_source_uriproc_UriSchemeParser_vndDOTsunDOTstarDOTscript_hxx
+
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "sal/types.h"
+
+namespace com { namespace sun { namespace star { namespace uno {
+ class XComponentContext;
+ class XInterface;
+} } } }
+namespace rtl { class OUString; }
+
+namespace stoc { namespace uriproc {
+
+namespace UriSchemeParser_vndDOTsunDOTstarDOTscript {
+ com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL
+ create(
+ com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
+ const &)
+ SAL_THROW((com::sun::star::uno::Exception));
+
+ rtl::OUString SAL_CALL getImplementationName();
+
+ com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames();
+}
+
+} }
+
+#endif
diff --git a/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.cxx b/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.cxx
new file mode 100644
index 000000000000..feb28c8646ea
--- /dev/null
+++ b/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.cxx
@@ -0,0 +1,170 @@
+/*************************************************************************
+ *
+ * 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: VndSunStarPkgUrlReferenceFactory.cxx,v $
+ * $Revision: 1.6 $
+ *
+ * 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_stoc.hxx"
+
+#include "stocservices.hxx"
+
+#include "supportsService.hxx"
+
+#include "com/sun/star/lang/XServiceInfo.hpp"
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/uno/XComponentContext.hpp"
+#include "com/sun/star/uno/XInterface.hpp"
+#include "com/sun/star/uri/UriReferenceFactory.hpp"
+#include "com/sun/star/uri/XUriReference.hpp"
+#include "com/sun/star/uri/XUriReferenceFactory.hpp"
+#include "com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp"
+#include "cppuhelper/implbase2.hxx"
+#include "cppuhelper/weak.hxx"
+#include "rtl/string.h"
+#include "rtl/textenc.h"
+#include "rtl/uri.h"
+#include "rtl/uri.hxx"
+#include "rtl/ustrbuf.hxx"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+
+#include <new>
+
+namespace css = com::sun::star;
+
+namespace {
+
+class Factory: public cppu::WeakImplHelper2<
+ css::lang::XServiceInfo, css::uri::XVndSunStarPkgUrlReferenceFactory >
+{
+public:
+ explicit Factory(
+ css::uno::Reference< css::uno::XComponentContext > const & context):
+ m_context(context) {}
+
+ virtual rtl::OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException);
+
+ virtual css::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames() throw (css::uno::RuntimeException);
+
+ virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
+ createVndSunStarPkgUrlReference(
+ css::uno::Reference< css::uri::XUriReference > const & authority)
+ throw (css::uno::RuntimeException);
+
+private:
+ Factory(Factory &); // not implemented
+ void operator =(Factory); // not implemented
+
+ virtual ~Factory() {}
+
+ css::uno::Reference< css::uno::XComponentContext > m_context;
+};
+
+rtl::OUString Factory::getImplementationName()
+ throw (css::uno::RuntimeException)
+{
+ return
+ stoc_services::VndSunStarPkgUrlReferenceFactory::
+ getImplementationName();
+}
+
+sal_Bool Factory::supportsService(rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException)
+{
+ return stoc::uriproc::supportsService(
+ getSupportedServiceNames(), serviceName);
+}
+
+css::uno::Sequence< rtl::OUString > Factory::getSupportedServiceNames()
+ throw (css::uno::RuntimeException)
+{
+ return stoc_services::VndSunStarPkgUrlReferenceFactory::
+ getSupportedServiceNames();
+}
+
+css::uno::Reference< css::uri::XUriReference >
+Factory::createVndSunStarPkgUrlReference(
+ css::uno::Reference< css::uri::XUriReference > const & authority)
+ throw (css::uno::RuntimeException)
+{
+ OSL_ASSERT(authority.is());
+ if (authority->isAbsolute() && !authority->hasFragment()) {
+ rtl::OUStringBuffer buf;
+ buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pkg://"));
+ buf.append(
+ rtl::Uri::encode(
+ authority->getUriReference(), rtl_UriCharClassRegName,
+ rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8));
+ css::uno::Reference< css::uri::XUriReference > uriRef(
+ css::uri::UriReferenceFactory::create(m_context)->parse(
+ buf.makeStringAndClear()));
+ OSL_ASSERT(uriRef.is());
+ return uriRef;
+ } else {
+ return css::uno::Reference< css::uri::XUriReference >();
+ }
+}
+
+}
+
+namespace stoc_services { namespace VndSunStarPkgUrlReferenceFactory
+{
+
+css::uno::Reference< css::uno::XInterface > create(
+ css::uno::Reference< css::uno::XComponentContext > const & context)
+ SAL_THROW((css::uno::Exception))
+{
+ try {
+ return static_cast< cppu::OWeakObject * >(new Factory(context));
+ } catch (std::bad_alloc &) {
+ throw css::uno::RuntimeException(
+ rtl::OUString::createFromAscii("std::bad_alloc"), 0);
+ }
+}
+
+rtl::OUString getImplementationName() {
+ return rtl::OUString::createFromAscii(
+ "com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory");
+}
+
+css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
+ css::uno::Sequence< rtl::OUString > s(1);
+ s[0] = rtl::OUString::createFromAscii(
+ "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory");
+ return s;
+}
+
+} }
diff --git a/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.hxx b/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.hxx
new file mode 100644
index 000000000000..18e44017bf67
--- /dev/null
+++ b/stoc/source/uriproc/VndSunStarPkgUrlReferenceFactory.hxx
@@ -0,0 +1,62 @@
+/*************************************************************************
+ *
+ * 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: VndSunStarPkgUrlReferenceFactory.hxx,v $
+ * $Revision: 1.4 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_stoc_source_uriproc_VndSunStarPkgUrlReferenceFactory_hxx
+#define INCLUDED_stoc_source_uriproc_VndSunStarPkgUrlReferenceFactory_hxx
+
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "sal/types.h"
+
+namespace com { namespace sun { namespace star { namespace uno {
+ class XComponentContext;
+ class XInterface;
+} } } }
+namespace rtl { class OUString; }
+
+namespace stoc { namespace uriproc {
+
+namespace VndSunStarPkgUrlReferenceFactory {
+ com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL
+ create(
+ com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
+ const & context)
+ SAL_THROW((com::sun::star::uno::Exception));
+
+ rtl::OUString SAL_CALL getImplementationName();
+
+ com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames();
+}
+
+} }
+
+#endif
diff --git a/stoc/source/uriproc/makefile.mk b/stoc/source/uriproc/makefile.mk
new file mode 100644
index 000000000000..bcc6ffc7572b
--- /dev/null
+++ b/stoc/source/uriproc/makefile.mk
@@ -0,0 +1,57 @@
+#*************************************************************************
+#
+# 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: makefile.mk,v $
+#
+# $Revision: 1.9 $
+#
+# 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.
+#
+#*************************************************************************
+
+PRJ=..$/..
+PRJNAME=stoc
+TARGET=uriproc
+ENABLE_EXCEPTIONS := TRUE
+
+# --- openoffice.org.orig/Settings -----------------------------------------------------
+
+.INCLUDE: settings.mk
+DLLPRE =
+
+# ------------------------------------------------------------------
+
+.INCLUDE : ..$/cppumaker.mk
+
+SLOFILES = \
+ $(SLO)$/ExternalUriReferenceTranslator.obj \
+ $(SLO)$/UriReference.obj \
+ $(SLO)$/UriReferenceFactory.obj \
+ $(SLO)$/UriSchemeParser_vndDOTsunDOTstarDOTexpand.obj \
+ $(SLO)$/UriSchemeParser_vndDOTsunDOTstarDOTscript.obj \
+ $(SLO)$/VndSunStarPkgUrlReferenceFactory.obj \
+ $(SLO)$/supportsService.obj
+
+# ------------------------------------------------------------------
+
+.INCLUDE: target.mk
diff --git a/stoc/source/uriproc/supportsService.cxx b/stoc/source/uriproc/supportsService.cxx
new file mode 100644
index 000000000000..21d6e9c4ed03
--- /dev/null
+++ b/stoc/source/uriproc/supportsService.cxx
@@ -0,0 +1,54 @@
+/*************************************************************************
+ *
+ * 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: supportsService.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_stoc.hxx"
+
+#include "supportsService.hxx"
+
+#include "com/sun/star/uno/Sequence.hxx"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+
+namespace stoc { namespace uriproc {
+
+bool supportsService(
+ com::sun::star::uno::Sequence< rtl::OUString > const & serviceNames,
+ rtl::OUString const & serviceName)
+{
+ for (sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
+ if (serviceNames[i] == serviceName) {
+ return true;
+ }
+ }
+ return false;
+}
+
+} }
diff --git a/stoc/source/uriproc/supportsService.hxx b/stoc/source/uriproc/supportsService.hxx
new file mode 100644
index 000000000000..5a855793a28f
--- /dev/null
+++ b/stoc/source/uriproc/supportsService.hxx
@@ -0,0 +1,46 @@
+/*************************************************************************
+ *
+ * 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: supportsService.hxx,v $
+ * $Revision: 1.4 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_stoc_source_uriproc_supportsService_hxx
+#define INCLUDED_stoc_source_uriproc_supportsService_hxx
+
+#include "com/sun/star/uno/Sequence.hxx"
+
+namespace rtl { class OUString; }
+
+namespace stoc { namespace uriproc {
+
+bool supportsService(
+ com::sun::star::uno::Sequence< rtl::OUString > const & serviceNames,
+ rtl::OUString const & serviceName);
+
+} }
+
+#endif