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

Generated by: LCOV version 1.10