LCOV - code coverage report
Current view: top level - stoc/source/uriproc - UriSchemeParser_vndDOTsunDOTstarDOTexpand.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 19 60 31.7 %
Date: 2015-06-13 12:38:46 Functions: 11 30 36.7 %
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 <exception>
      23             : 
      24             : #include <boost/noncopyable.hpp>
      25             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      26             : #include <com/sun/star/lang/XServiceInfo.hpp>
      27             : #include <com/sun/star/uno/Reference.hxx>
      28             : #include <com/sun/star/uno/RuntimeException.hpp>
      29             : #include <com/sun/star/uno/Sequence.hxx>
      30             : #include <com/sun/star/uno/XComponentContext.hpp>
      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/supportsservice.hxx>
      39             : #include <cppuhelper/weak.hxx>
      40             : #include <osl/diagnose.h>
      41             : #include <rtl/textenc.h>
      42             : #include <rtl/uri.h>
      43             : #include <rtl/uri.hxx>
      44             : #include <rtl/ustring.h>
      45             : #include <rtl/ustring.hxx>
      46             : #include <sal/types.h>
      47             : 
      48             : #include "UriReference.hxx"
      49             : 
      50             : namespace {
      51             : 
      52       56058 : bool parseSchemeSpecificPart(OUString const & part) {
      53             :     // Liberally accepts both an empty opaque_part and an opaque_part that
      54             :     // starts with a non-escaped "/":
      55       56058 :     return part.isEmpty()
      56      112116 :         || (!::rtl::Uri::decode(part, ::rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8).isEmpty());
      57             : }
      58             : 
      59             : class UrlReference:
      60             :     public ::cppu::WeakImplHelper1<css::uri::XVndSunStarExpandUrlReference>,
      61             :     private boost::noncopyable
      62             : {
      63             : public:
      64       56058 :     UrlReference(OUString const & scheme, OUString const & path):
      65             :         base_(
      66             :             scheme, false, false, OUString(), path, false,
      67       56058 :             OUString())
      68       56058 :     {}
      69             : 
      70           0 :     virtual OUString SAL_CALL getUriReference()
      71             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      72           0 :     { return base_.getUriReference(); }
      73             : 
      74           0 :     virtual sal_Bool SAL_CALL isAbsolute() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      75           0 :     { return base_.isAbsolute(); }
      76             : 
      77           0 :     virtual OUString SAL_CALL getScheme()
      78             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      79           0 :     { return base_.getScheme(); }
      80             : 
      81           0 :     virtual OUString SAL_CALL getSchemeSpecificPart()
      82             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      83           0 :     { return base_.getSchemeSpecificPart(); }
      84             : 
      85           0 :     virtual sal_Bool SAL_CALL isHierarchical()
      86             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      87           0 :     { return base_.isHierarchical(); }
      88             : 
      89           0 :     virtual sal_Bool SAL_CALL hasAuthority()
      90             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      91           0 :     { return base_.hasAuthority(); }
      92             : 
      93           0 :     virtual OUString SAL_CALL getAuthority()
      94             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      95           0 :     { return base_.getAuthority(); }
      96             : 
      97       56058 :     virtual OUString SAL_CALL getPath()
      98             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      99       56058 :     { return base_.getPath(); }
     100             : 
     101           0 :     virtual sal_Bool SAL_CALL hasRelativePath()
     102             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     103           0 :     { return base_.hasRelativePath(); }
     104             : 
     105           0 :     virtual ::sal_Int32 SAL_CALL getPathSegmentCount()
     106             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     107           0 :     { return base_.getPathSegmentCount(); }
     108             : 
     109           0 :     virtual OUString SAL_CALL getPathSegment(sal_Int32 index)
     110             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     111           0 :     { return base_.getPathSegment(index); }
     112             : 
     113           0 :     virtual sal_Bool SAL_CALL hasQuery() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     114           0 :     { return base_.hasQuery(); }
     115             : 
     116           0 :     virtual OUString SAL_CALL getQuery()
     117             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     118           0 :     { return base_.getQuery(); }
     119             : 
     120           0 :     virtual sal_Bool SAL_CALL hasFragment() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     121           0 :     { return base_.hasFragment(); }
     122             : 
     123           0 :     virtual OUString SAL_CALL getFragment()
     124             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     125           0 :     { return base_.getFragment(); }
     126             : 
     127           0 :     virtual void SAL_CALL setFragment(OUString const & fragment)
     128             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     129           0 :     { base_.setFragment(fragment); }
     130             : 
     131           0 :     virtual void SAL_CALL clearFragment() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     132           0 :     { base_.clearFragment(); }
     133             : 
     134             :     virtual OUString SAL_CALL expand(
     135             :         css::uno::Reference< css::util::XMacroExpander > const & expander)
     136             :         throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     137             : 
     138             : private:
     139      112116 :     virtual ~UrlReference() {}
     140             : 
     141             :     stoc::uriproc::UriReference base_;
     142             : };
     143             : 
     144       56058 : OUString UrlReference::expand(
     145             :     css::uno::Reference< css::util::XMacroExpander > const & expander)
     146             :     throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
     147             : {
     148             :     OSL_ASSERT(expander.is());
     149       56058 :     return expander->expandMacros(
     150             :         ::rtl::Uri::decode(
     151       56058 :             getPath(), ::rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8));
     152             : }
     153             : 
     154             : class Parser:
     155             :     public ::cppu::WeakImplHelper2<
     156             :         css::lang::XServiceInfo, css::uri::XUriSchemeParser>,
     157             :     private boost::noncopyable
     158             : {
     159             : public:
     160       56058 :     Parser() {}
     161             : 
     162             :     virtual OUString SAL_CALL getImplementationName()
     163             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     164             : 
     165             :     virtual sal_Bool SAL_CALL supportsService(
     166             :         OUString const & serviceName)
     167             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     168             : 
     169             :     virtual css::uno::Sequence< OUString > SAL_CALL
     170             :     getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     171             : 
     172             :     virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
     173             :     parse(
     174             :         OUString const & scheme,
     175             :         OUString const & schemeSpecificPart)
     176             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     177             : 
     178             : private:
     179      112116 :     virtual ~Parser() {}
     180             : };
     181             : 
     182           0 : OUString Parser::getImplementationName()
     183             :     throw (css::uno::RuntimeException, std::exception)
     184             : {
     185           0 :     return OUString("com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand");
     186             : }
     187             : 
     188           0 : sal_Bool Parser::supportsService(OUString const & serviceName)
     189             :     throw (css::uno::RuntimeException, std::exception)
     190             : {
     191           0 :     return cppu::supportsService(this, serviceName);
     192             : }
     193             : 
     194           0 : css::uno::Sequence< OUString > Parser::getSupportedServiceNames()
     195             :     throw (css::uno::RuntimeException, std::exception)
     196             : {
     197           0 :     css::uno::Sequence< OUString > s(1);
     198           0 :     s[0] = "com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand";
     199           0 :     return s;
     200             : }
     201             : 
     202       56058 : css::uno::Reference< css::uri::XUriReference > Parser::parse(
     203             :     OUString const & scheme, OUString const & schemeSpecificPart)
     204             :     throw (css::uno::RuntimeException, std::exception)
     205             : {
     206       56058 :     if (!parseSchemeSpecificPart(schemeSpecificPart)) {
     207           0 :         return css::uno::Reference< css::uri::XUriReference >();
     208             :     }
     209       56058 :     return new UrlReference(scheme, schemeSpecificPart);
     210             : }
     211             : 
     212             : }
     213             : 
     214             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
     215       56058 : com_sun_star_comp_uri_UriSchemeParser_vndDOTsunDOTstarDOTexpand_get_implementation(::com::sun::star::uno::XComponentContext*,
     216             :         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
     217             : {
     218             :     //TODO: single instance
     219       56058 :     return ::cppu::acquire(new Parser());
     220             : }
     221             : 
     222             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11