LCOV - code coverage report
Current view: top level - stoc/source/uriproc - VndSunStarPkgUrlReferenceFactory.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 11 23 47.8 %
Date: 2015-06-13 12:38:46 Functions: 6 8 75.0 %
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 <boost/noncopyable.hpp>
      21             : #include <com/sun/star/lang/XServiceInfo.hpp>
      22             : #include <com/sun/star/uno/Exception.hpp>
      23             : #include <com/sun/star/uno/Reference.hxx>
      24             : #include <com/sun/star/uno/RuntimeException.hpp>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <com/sun/star/uno/XComponentContext.hpp>
      27             : #include <com/sun/star/uno/XInterface.hpp>
      28             : #include <com/sun/star/uri/UriReferenceFactory.hpp>
      29             : #include <com/sun/star/uri/XUriReference.hpp>
      30             : #include <com/sun/star/uri/XUriReferenceFactory.hpp>
      31             : #include <com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp>
      32             : #include <cppuhelper/implbase2.hxx>
      33             : #include <cppuhelper/supportsservice.hxx>
      34             : #include <cppuhelper/weak.hxx>
      35             : #include <rtl/string.h>
      36             : #include <rtl/textenc.h>
      37             : #include <rtl/uri.h>
      38             : #include <rtl/uri.hxx>
      39             : #include <rtl/ustrbuf.hxx>
      40             : #include <rtl/ustring.hxx>
      41             : #include <osl/diagnose.h>
      42             : #include <sal/types.h>
      43             : 
      44             : namespace {
      45             : 
      46             : class Factory:
      47             :     public cppu::WeakImplHelper2<
      48             :         css::lang::XServiceInfo, css::uri::XVndSunStarPkgUrlReferenceFactory>,
      49             :     private boost::noncopyable
      50             : {
      51             : public:
      52           1 :     explicit Factory(
      53             :         css::uno::Reference< css::uno::XComponentContext > const & context):
      54           1 :         m_context(context) {}
      55             : 
      56             :     virtual OUString SAL_CALL getImplementationName()
      57             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      58             : 
      59             :     virtual sal_Bool SAL_CALL supportsService(OUString const & serviceName)
      60             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      61             : 
      62             :     virtual css::uno::Sequence< OUString > SAL_CALL
      63             :     getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      64             : 
      65             :     virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
      66             :     createVndSunStarPkgUrlReference(
      67             :         css::uno::Reference< css::uri::XUriReference > const & authority)
      68             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      69             : 
      70             : private:
      71           2 :     virtual ~Factory() {}
      72             : 
      73             :     css::uno::Reference< css::uno::XComponentContext > m_context;
      74             : };
      75             : 
      76           1 : OUString Factory::getImplementationName()
      77             :     throw (css::uno::RuntimeException, std::exception)
      78             : {
      79           1 :     return OUString("com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory");
      80             : }
      81             : 
      82           0 : sal_Bool Factory::supportsService(OUString const & serviceName)
      83             :     throw (css::uno::RuntimeException, std::exception)
      84             : {
      85           0 :     return cppu::supportsService(this, serviceName);
      86             : }
      87             : 
      88           1 : css::uno::Sequence< OUString > Factory::getSupportedServiceNames()
      89             :     throw (css::uno::RuntimeException, std::exception)
      90             : {
      91           1 :     css::uno::Sequence< OUString > s(1);
      92           1 :     s[0] = "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory";
      93           1 :     return s;
      94             : }
      95             : 
      96             : css::uno::Reference< css::uri::XUriReference >
      97           0 : Factory::createVndSunStarPkgUrlReference(
      98             :     css::uno::Reference< css::uri::XUriReference > const & authority)
      99             :     throw (css::uno::RuntimeException, std::exception)
     100             : {
     101             :     OSL_ASSERT(authority.is());
     102           0 :     if (authority->isAbsolute() && !authority->hasFragment()) {
     103           0 :         OUStringBuffer buf;
     104           0 :         buf.append("vnd.sun.star.pkg://");
     105             :         buf.append(
     106             :             rtl::Uri::encode(
     107           0 :                 authority->getUriReference(), rtl_UriCharClassRegName,
     108           0 :                 rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8));
     109             :         css::uno::Reference< css::uri::XUriReference > uriRef(
     110           0 :             css::uri::UriReferenceFactory::create(m_context)->parse(
     111           0 :                 buf.makeStringAndClear()));
     112             :         OSL_ASSERT(uriRef.is());
     113           0 :         return uriRef;
     114             :     } else {
     115           0 :         return css::uno::Reference< css::uri::XUriReference >();
     116             :     }
     117             : }
     118             : 
     119             : }
     120             : 
     121             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
     122           1 : com_sun_star_comp_uri_VndSunStarPkgUrlReferenceFactory_get_implementation(::com::sun::star::uno::XComponentContext* rxContext,
     123             :         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
     124             : {
     125           1 :     return ::cppu::acquire(new Factory(rxContext));
     126             : }
     127             : 
     128             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11