LCOV - code coverage report
Current view: top level - libreoffice/ucb/source/ucp/ext - ucpext_provider.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 56 0.0 %
Date: 2012-12-17 Functions: 0 12 0.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 "ucpext_provider.hxx"
      21             : #include "ucpext_content.hxx"
      22             : 
      23             : #include <ucbhelper/contentidentifier.hxx>
      24             : #include <osl/diagnose.h>
      25             : #include <osl/mutex.hxx>
      26             : #include <comphelper/componentcontext.hxx>
      27             : #include <rtl/ustrbuf.hxx>
      28             : 
      29             : //......................................................................................................................
      30             : namespace ucb { namespace ucp { namespace ext
      31             : {
      32             : //......................................................................................................................
      33             : 
      34             :     /** === begin UNO using === **/
      35             :     using ::com::sun::star::uno::Reference;
      36             :     using ::com::sun::star::uno::XInterface;
      37             :     using ::com::sun::star::uno::UNO_QUERY;
      38             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      39             :     using ::com::sun::star::uno::UNO_SET_THROW;
      40             :     using ::com::sun::star::uno::Exception;
      41             :     using ::com::sun::star::uno::RuntimeException;
      42             :     using ::com::sun::star::uno::Any;
      43             :     using ::com::sun::star::uno::makeAny;
      44             :     using ::com::sun::star::uno::Sequence;
      45             :     using ::com::sun::star::uno::Type;
      46             :     using ::com::sun::star::lang::XMultiServiceFactory;
      47             :     using ::com::sun::star::ucb::XContentIdentifier;
      48             :     using ::com::sun::star::ucb::IllegalIdentifierException;
      49             :     using ::com::sun::star::ucb::XContent;
      50             :     using ::com::sun::star::uno::XComponentContext;
      51             :     /** === end UNO using === **/
      52             : 
      53             :     //==================================================================================================================
      54             :     //= ContentProvider
      55             :     //==================================================================================================================
      56             :     //------------------------------------------------------------------------------------------------------------------
      57           0 :     ContentProvider::ContentProvider( const Reference< XComponentContext >& rxContext )
      58           0 :         :ContentProvider_Base( rxContext )
      59             :     {
      60           0 :     }
      61             : 
      62             :     //------------------------------------------------------------------------------------------------------------------
      63           0 :     ContentProvider::~ContentProvider()
      64             :     {
      65           0 :     }
      66             : 
      67             :     //------------------------------------------------------------------------------------------------------------------
      68           0 :     ::rtl::OUString SAL_CALL ContentProvider::getImplementationName_static() throw (RuntimeException)
      69             :     {
      70           0 :         return ::rtl::OUString(  "org.openoffice.comp.ucp.ext.ContentProvider"  );
      71             :     }
      72             : 
      73             :     //------------------------------------------------------------------------------------------------------------------
      74           0 :     ::rtl::OUString SAL_CALL ContentProvider::getImplementationName() throw (RuntimeException)
      75             :     {
      76           0 :         return getImplementationName_static();
      77             :     }
      78             : 
      79             :     //------------------------------------------------------------------------------------------------------------------
      80           0 :     Sequence< ::rtl::OUString > SAL_CALL ContentProvider::getSupportedServiceNames_static(  ) throw (RuntimeException)
      81             :     {
      82           0 :         Sequence< ::rtl::OUString > aServiceNames(2);
      83           0 :         aServiceNames[0] = ::rtl::OUString(  "com.sun.star.ucb.ContentProvider"  );
      84           0 :         aServiceNames[1] = ::rtl::OUString(  "com.sun.star.ucb.ExtensionContentProvider"  );
      85           0 :         return aServiceNames;
      86             :     }
      87             : 
      88             :     //------------------------------------------------------------------------------------------------------------------
      89           0 :     Sequence< ::rtl::OUString > SAL_CALL ContentProvider::getSupportedServiceNames(  ) throw (RuntimeException)
      90             :     {
      91           0 :         return getSupportedServiceNames_static();
      92             :     }
      93             : 
      94             :     //------------------------------------------------------------------------------------------------------------------
      95           0 :     Reference< XInterface > ContentProvider::Create( const Reference< XComponentContext >& i_rContext )
      96             :     {
      97           0 :         return *( new ContentProvider( i_rContext ) );
      98             :     }
      99             : 
     100             :     //------------------------------------------------------------------------------------------------------------------
     101           0 :     ::rtl::OUString ContentProvider::getRootURL()
     102             :     {
     103           0 :         return ::rtl::OUString(  "vnd.sun.star.extension://"  );
     104             :     }
     105             : 
     106             :     //------------------------------------------------------------------------------------------------------------------
     107           0 :     ::rtl::OUString ContentProvider::getArtificialNodeContentType()
     108             :     {
     109           0 :         return ::rtl::OUString(  "application/vnd.sun.star.extension-content"  );
     110             :     }
     111             : 
     112             :     //------------------------------------------------------------------------------------------------------------------
     113             :     namespace
     114             :     {
     115           0 :         void lcl_ensureAndTransfer( ::rtl::OUString& io_rIdentifierFragment, ::rtl::OUStringBuffer& o_rNormalization, const sal_Unicode i_nLeadingChar )
     116             :         {
     117           0 :             if ( ( io_rIdentifierFragment.isEmpty() ) || ( io_rIdentifierFragment[0] != i_nLeadingChar ) )
     118           0 :                 throw IllegalIdentifierException();
     119           0 :             io_rIdentifierFragment = io_rIdentifierFragment.copy( 1 );
     120           0 :             o_rNormalization.append( i_nLeadingChar );
     121           0 :         }
     122             :     }
     123             : 
     124             :     //------------------------------------------------------------------------------------------------------------------
     125           0 :     Reference< XContent > SAL_CALL ContentProvider::queryContent( const Reference< XContentIdentifier  >& i_rIdentifier )
     126             :         throw( IllegalIdentifierException, RuntimeException )
     127             :     {
     128             :         // Check URL scheme...
     129           0 :         const ::rtl::OUString sScheme( "vnd.sun.star.extension" );
     130           0 :         if ( !i_rIdentifier->getContentProviderScheme().equalsIgnoreAsciiCase( sScheme ) )
     131           0 :             throw IllegalIdentifierException();
     132             : 
     133             :         // normalize the identifier
     134           0 :         const ::rtl::OUString sIdentifier( i_rIdentifier->getContentIdentifier() );
     135             : 
     136             :         // the scheme needs to be lower-case
     137           0 :         ::rtl::OUStringBuffer aComposer;
     138           0 :         aComposer.append( sIdentifier.copy( 0, sScheme.getLength() ).toAsciiLowerCase() );
     139             : 
     140             :         // one : is required after the scheme
     141           0 :         ::rtl::OUString sRemaining( sIdentifier.copy( sScheme.getLength() ) );
     142           0 :         lcl_ensureAndTransfer( sRemaining, aComposer, ':' );
     143             : 
     144             :         // and at least one /
     145           0 :         lcl_ensureAndTransfer( sRemaining, aComposer, '/' );
     146             : 
     147             :         // the normalized form requires one additional /, but we also accept identifiers which don't have it
     148           0 :         if ( sRemaining.isEmpty() )
     149             :         {
     150             :             // the root content is a special case, it requires ///
     151           0 :             aComposer.appendAscii( "//" );
     152             :         }
     153             :         else
     154             :         {
     155           0 :             if ( sRemaining[0] != '/' )
     156             :             {
     157           0 :                 aComposer.append( sal_Unicode( '/' ) );
     158           0 :                 aComposer.append( sRemaining );
     159             :             }
     160             :             else
     161             :             {
     162           0 :                 lcl_ensureAndTransfer( sRemaining, aComposer, '/' );
     163             :                 // by now, we moved "vnd.sun.star.extension://" from the URL to aComposer
     164           0 :                 if ( sRemaining.isEmpty() )
     165             :                 {
     166             :                     // again, it's the root content, but one / is missing
     167           0 :                     aComposer.append( sal_Unicode( '/' ) );
     168             :                 }
     169             :                 else
     170             :                 {
     171           0 :                     aComposer.append( sRemaining );
     172             :                 }
     173             :             }
     174             :         }
     175           0 :         const Reference< XContentIdentifier > xNormalizedIdentifier( new ::ucbhelper::ContentIdentifier( aComposer.makeStringAndClear() ) );
     176             : 
     177           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     178             : 
     179             :         // check if a content with given id already exists...
     180           0 :         Reference< XContent > xContent( queryExistingContent( xNormalizedIdentifier ).get() );
     181           0 :         if ( xContent.is() )
     182             :             return xContent;
     183             : 
     184             :         // create a new content
     185           0 :         xContent = new Content( m_xContext, this, xNormalizedIdentifier );
     186           0 :         if ( !xContent->getIdentifier().is() )
     187           0 :             throw IllegalIdentifierException();
     188             : 
     189           0 :         registerNewContent( xContent );
     190           0 :         return xContent;
     191             :     }
     192             : 
     193             : //......................................................................................................................
     194             : } } }   // namespace ucb::ucp::ext
     195             : //......................................................................................................................
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10