LCOV - code coverage report
Current view: top level - libreoffice/stoc/source/uriproc - UriSchemeParser_vndDOTsunDOTstarDOTexpand.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 69 2.9 %
Date: 2012-12-27 Functions: 1 32 3.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "sal/config.h"
      21             : 
      22             : #include "stocservices.hxx"
      23             : 
      24             : #include <new>
      25             : 
      26             : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      27             : #include "com/sun/star/lang/XServiceInfo.hpp"
      28             : #include "com/sun/star/uno/Reference.hxx"
      29             : #include "com/sun/star/uno/RuntimeException.hpp"
      30             : #include "com/sun/star/uno/Sequence.hxx"
      31             : #include "com/sun/star/uno/XInterface.hpp"
      32             : #include "com/sun/star/uri/XUriReference.hpp"
      33             : #include "com/sun/star/uri/XUriSchemeParser.hpp"
      34             : #include "com/sun/star/uri/XVndSunStarExpandUrlReference.hpp"
      35             : #include "com/sun/star/util/XMacroExpander.hpp"
      36             : #include "cppuhelper/implbase1.hxx"
      37             : #include "cppuhelper/implbase2.hxx"
      38             : #include "cppuhelper/weak.hxx"
      39             : #include "rtl/textenc.h"
      40             : #include "rtl/uri.h"
      41             : #include "rtl/uri.hxx"
      42             : #include "rtl/ustring.h"
      43             : #include "rtl/ustring.hxx"
      44             : #include "sal/types.h"
      45             : 
      46             : #include "UriReference.hxx"
      47             : #include "supportsService.hxx"
      48             : 
      49             : namespace {
      50             : 
      51           0 : bool parseSchemeSpecificPart(::rtl::OUString const & part) {
      52             :     // Liberally accepts both an empty opaque_part and an opaque_part that
      53             :     // starts with a non-escaped "/":
      54           0 :     return part.isEmpty()
      55           0 :         || (!::rtl::Uri::decode(part, ::rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8).isEmpty());
      56             : }
      57             : 
      58             : class UrlReference:
      59             :     public ::cppu::WeakImplHelper1< css::uri::XVndSunStarExpandUrlReference >
      60             : {
      61             : public:
      62           0 :     UrlReference(::rtl::OUString const & scheme, ::rtl::OUString const & path):
      63             :         base_(
      64             :             scheme, false, false, ::rtl::OUString(), path, false,
      65           0 :             ::rtl::OUString())
      66           0 :     {}
      67             : 
      68           0 :     virtual ::rtl::OUString SAL_CALL getUriReference()
      69             :         throw (css::uno::RuntimeException)
      70           0 :     { return base_.getUriReference(); }
      71             : 
      72           0 :     virtual ::sal_Bool SAL_CALL isAbsolute() throw (css::uno::RuntimeException)
      73           0 :     { return base_.isAbsolute(); }
      74             : 
      75           0 :     virtual ::rtl::OUString SAL_CALL getScheme()
      76             :         throw (css::uno::RuntimeException)
      77           0 :     { return base_.getScheme(); }
      78             : 
      79           0 :     virtual ::rtl::OUString SAL_CALL getSchemeSpecificPart()
      80             :         throw (css::uno::RuntimeException)
      81           0 :     { return base_.getSchemeSpecificPart(); }
      82             : 
      83           0 :     virtual ::sal_Bool SAL_CALL isHierarchical()
      84             :         throw (css::uno::RuntimeException)
      85           0 :     { return base_.isHierarchical(); }
      86             : 
      87           0 :     virtual ::sal_Bool SAL_CALL hasAuthority()
      88             :         throw (css::uno::RuntimeException)
      89           0 :     { return base_.hasAuthority(); }
      90             : 
      91           0 :     virtual ::rtl::OUString SAL_CALL getAuthority()
      92             :         throw (css::uno::RuntimeException)
      93           0 :     { return base_.getAuthority(); }
      94             : 
      95           0 :     virtual ::rtl::OUString SAL_CALL getPath()
      96             :         throw (css::uno::RuntimeException)
      97           0 :     { return base_.getPath(); }
      98             : 
      99           0 :     virtual ::sal_Bool SAL_CALL hasRelativePath()
     100             :         throw (css::uno::RuntimeException)
     101           0 :     { return base_.hasRelativePath(); }
     102             : 
     103           0 :     virtual ::sal_Int32 SAL_CALL getPathSegmentCount()
     104             :         throw (css::uno::RuntimeException)
     105           0 :     { return base_.getPathSegmentCount(); }
     106             : 
     107           0 :     virtual ::rtl::OUString SAL_CALL getPathSegment(sal_Int32 index)
     108             :         throw (css::uno::RuntimeException)
     109           0 :     { return base_.getPathSegment(index); }
     110             : 
     111           0 :     virtual ::sal_Bool SAL_CALL hasQuery() throw (css::uno::RuntimeException)
     112           0 :     { return base_.hasQuery(); }
     113             : 
     114           0 :     virtual ::rtl::OUString SAL_CALL getQuery()
     115             :         throw (css::uno::RuntimeException)
     116           0 :     { return base_.getQuery(); }
     117             : 
     118           0 :     virtual ::sal_Bool SAL_CALL hasFragment() throw (css::uno::RuntimeException)
     119           0 :     { return base_.hasFragment(); }
     120             : 
     121           0 :     virtual ::rtl::OUString SAL_CALL getFragment()
     122             :         throw (css::uno::RuntimeException)
     123           0 :     { return base_.getFragment(); }
     124             : 
     125           0 :     virtual void SAL_CALL setFragment(::rtl::OUString const & fragment)
     126             :         throw (css::uno::RuntimeException)
     127           0 :     { base_.setFragment(fragment); }
     128             : 
     129           0 :     virtual void SAL_CALL clearFragment() throw (css::uno::RuntimeException)
     130           0 :     { base_.clearFragment(); }
     131             : 
     132             :     virtual ::rtl::OUString SAL_CALL expand(
     133             :         css::uno::Reference< css::util::XMacroExpander > const & expander)
     134             :         throw (css::lang::IllegalArgumentException, css::uno::RuntimeException);
     135             : 
     136             : private:
     137             :     UrlReference(UrlReference &); // not defined
     138             :     void operator =(UrlReference); // not defined
     139             : 
     140           0 :     virtual ~UrlReference() {}
     141             : 
     142             :     stoc::uriproc::UriReference base_;
     143             : };
     144             : 
     145           0 : ::rtl::OUString UrlReference::expand(
     146             :     css::uno::Reference< css::util::XMacroExpander > const & expander)
     147             :     throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
     148             : {
     149             :     OSL_ASSERT(expander.is());
     150           0 :     return expander->expandMacros(
     151             :         ::rtl::Uri::decode(
     152           0 :             getPath(), ::rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8));
     153             : }
     154             : 
     155             : class Parser: public ::cppu::WeakImplHelper2<
     156             :     css::lang::XServiceInfo, css::uri::XUriSchemeParser >
     157             : {
     158             : public:
     159           0 :     Parser() {}
     160             : 
     161             :     virtual ::rtl::OUString SAL_CALL getImplementationName()
     162             :         throw (css::uno::RuntimeException);
     163             : 
     164             :     virtual ::sal_Bool SAL_CALL supportsService(
     165             :         ::rtl::OUString const & serviceName)
     166             :         throw (css::uno::RuntimeException);
     167             : 
     168             :     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL
     169             :     getSupportedServiceNames() throw (css::uno::RuntimeException);
     170             : 
     171             :     virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
     172             :     parse(
     173             :         ::rtl::OUString const & scheme,
     174             :         ::rtl::OUString const & schemeSpecificPart)
     175             :         throw (css::uno::RuntimeException);
     176             : 
     177             : private:
     178             :     Parser(Parser &); // not defined
     179             :     void operator =(Parser); // not defined
     180             : 
     181           0 :     virtual ~Parser() {}
     182             : };
     183             : 
     184           0 : ::rtl::OUString Parser::getImplementationName()
     185             :     throw (css::uno::RuntimeException)
     186             : {
     187             :     return ::stoc_services::UriSchemeParser_vndDOTsunDOTstarDOTexpand::
     188           0 :         getImplementationName();
     189             : }
     190             : 
     191           0 : ::sal_Bool Parser::supportsService(::rtl::OUString const & serviceName)
     192             :     throw (css::uno::RuntimeException)
     193             : {
     194             :     return ::stoc::uriproc::supportsService(
     195           0 :         getSupportedServiceNames(), serviceName);
     196             : }
     197             : 
     198           0 : css::uno::Sequence< ::rtl::OUString > Parser::getSupportedServiceNames()
     199             :     throw (css::uno::RuntimeException)
     200             : {
     201             :     return ::stoc_services::UriSchemeParser_vndDOTsunDOTstarDOTexpand::
     202           0 :         getSupportedServiceNames();
     203             : }
     204             : 
     205           0 : css::uno::Reference< css::uri::XUriReference > Parser::parse(
     206             :     ::rtl::OUString const & scheme, ::rtl::OUString const & schemeSpecificPart)
     207             :     throw (css::uno::RuntimeException)
     208             : {
     209           0 :     if (!parseSchemeSpecificPart(schemeSpecificPart)) {
     210           0 :         return css::uno::Reference< css::uri::XUriReference >();
     211             :     }
     212             :     try {
     213           0 :         return new UrlReference(scheme, schemeSpecificPart);
     214           0 :     } catch (::std::bad_alloc &) {
     215             :         throw css::uno::RuntimeException(
     216             :             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")),
     217           0 :             css::uno::Reference< css::uno::XInterface >());
     218             :     }
     219             : }
     220             : 
     221             : }
     222             : 
     223             : namespace stoc_services { namespace UriSchemeParser_vndDOTsunDOTstarDOTexpand {
     224             : 
     225           0 : css::uno::Reference< css::uno::XInterface > create(
     226             :     SAL_UNUSED_PARAMETER css::uno::Reference< css::uno::XComponentContext >
     227             :         const &)
     228             :     SAL_THROW((css::uno::Exception))
     229             : {
     230             :     //TODO: single instance
     231             :     try {
     232           0 :         return static_cast< ::cppu::OWeakObject * >(new Parser);
     233           0 :     } catch (::std::bad_alloc &) {
     234             :         throw css::uno::RuntimeException(
     235             :             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")),
     236           0 :             css::uno::Reference< css::uno::XInterface >());
     237             :     }
     238             : }
     239             : 
     240          28 : ::rtl::OUString getImplementationName() {
     241             :     return ::rtl::OUString(
     242             :         RTL_CONSTASCII_USTRINGPARAM(
     243          28 :             "com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand"));
     244             : }
     245             : 
     246           0 : css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames() {
     247           0 :     css::uno::Sequence< ::rtl::OUString > s(1);
     248           0 :     s[0] = ::rtl::OUString(
     249             :         RTL_CONSTASCII_USTRINGPARAM(
     250           0 :             "com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand"));
     251           0 :     return s;
     252             : }
     253             : 
     254             : } }
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10