LCOV - code coverage report
Current view: top level - ucb/source/ucp/ext - ucpext_provider.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 57 0.0 %
Date: 2012-08-25 Functions: 0 12 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       4                 :            :  *
       5                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       6                 :            :  *
       7                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       8                 :            :  *
       9                 :            :  * This file is part of OpenOffice.org.
      10                 :            :  *
      11                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      12                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      13                 :            :  * only, as published by the Free Software Foundation.
      14                 :            :  *
      15                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      16                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18                 :            :  * GNU Lesser General Public License version 3 for more details
      19                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      20                 :            :  *
      21                 :            :  * You should have received a copy of the GNU Lesser General Public License
      22                 :            :  * version 3 along with OpenOffice.org.  If not, see
      23                 :            :  * <http://www.openoffice.org/license.html>
      24                 :            :  * for a copy of the LGPLv3 License.
      25                 :            :  *
      26                 :            : ************************************************************************/
      27                 :            : 
      28                 :            : #include "ucpext_provider.hxx"
      29                 :            : #include "ucpext_content.hxx"
      30                 :            : 
      31                 :            : #include <ucbhelper/contentidentifier.hxx>
      32                 :            : #include <osl/diagnose.h>
      33                 :            : #include <osl/mutex.hxx>
      34                 :            : #include <comphelper/componentcontext.hxx>
      35                 :            : #include <rtl/ustrbuf.hxx>
      36                 :            : 
      37                 :            : //......................................................................................................................
      38                 :            : namespace ucb { namespace ucp { namespace ext
      39                 :            : {
      40                 :            : //......................................................................................................................
      41                 :            : 
      42                 :            :     /** === begin UNO using === **/
      43                 :            :     using ::com::sun::star::uno::Reference;
      44                 :            :     using ::com::sun::star::uno::XInterface;
      45                 :            :     using ::com::sun::star::uno::UNO_QUERY;
      46                 :            :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      47                 :            :     using ::com::sun::star::uno::UNO_SET_THROW;
      48                 :            :     using ::com::sun::star::uno::Exception;
      49                 :            :     using ::com::sun::star::uno::RuntimeException;
      50                 :            :     using ::com::sun::star::uno::Any;
      51                 :            :     using ::com::sun::star::uno::makeAny;
      52                 :            :     using ::com::sun::star::uno::Sequence;
      53                 :            :     using ::com::sun::star::uno::Type;
      54                 :            :     using ::com::sun::star::lang::XMultiServiceFactory;
      55                 :            :     using ::com::sun::star::ucb::XContentIdentifier;
      56                 :            :     using ::com::sun::star::ucb::IllegalIdentifierException;
      57                 :            :     using ::com::sun::star::ucb::XContent;
      58                 :            :     using ::com::sun::star::uno::XComponentContext;
      59                 :            :     /** === end UNO using === **/
      60                 :            : 
      61                 :            :     //==================================================================================================================
      62                 :            :     //= ContentProvider
      63                 :            :     //==================================================================================================================
      64                 :            :     //------------------------------------------------------------------------------------------------------------------
      65                 :          0 :     ContentProvider::ContentProvider( const Reference< XMultiServiceFactory >& i_rServiceManager )
      66                 :          0 :         :ContentProvider_Base( i_rServiceManager )
      67                 :            :     {
      68                 :          0 :     }
      69                 :            : 
      70                 :            :     //------------------------------------------------------------------------------------------------------------------
      71                 :          0 :     ContentProvider::~ContentProvider()
      72                 :            :     {
      73                 :          0 :     }
      74                 :            : 
      75                 :            :     //------------------------------------------------------------------------------------------------------------------
      76                 :          0 :     ::rtl::OUString SAL_CALL ContentProvider::getImplementationName_static() throw (RuntimeException)
      77                 :            :     {
      78                 :          0 :         return ::rtl::OUString(  "org.openoffice.comp.ucp.ext.ContentProvider"  );
      79                 :            :     }
      80                 :            : 
      81                 :            :     //------------------------------------------------------------------------------------------------------------------
      82                 :          0 :     ::rtl::OUString SAL_CALL ContentProvider::getImplementationName() throw (RuntimeException)
      83                 :            :     {
      84                 :          0 :         return getImplementationName_static();
      85                 :            :     }
      86                 :            : 
      87                 :            :     //------------------------------------------------------------------------------------------------------------------
      88                 :          0 :     Sequence< ::rtl::OUString > SAL_CALL ContentProvider::getSupportedServiceNames_static(  ) throw (RuntimeException)
      89                 :            :     {
      90                 :          0 :         Sequence< ::rtl::OUString > aServiceNames(2);
      91                 :          0 :         aServiceNames[0] = ::rtl::OUString(  "com.sun.star.ucb.ContentProvider"  );
      92                 :          0 :         aServiceNames[1] = ::rtl::OUString(  "com.sun.star.ucb.ExtensionContentProvider"  );
      93                 :          0 :         return aServiceNames;
      94                 :            :     }
      95                 :            : 
      96                 :            :     //------------------------------------------------------------------------------------------------------------------
      97                 :          0 :     Sequence< ::rtl::OUString > SAL_CALL ContentProvider::getSupportedServiceNames(  ) throw (RuntimeException)
      98                 :            :     {
      99                 :          0 :         return getSupportedServiceNames_static();
     100                 :            :     }
     101                 :            : 
     102                 :            :     //------------------------------------------------------------------------------------------------------------------
     103                 :          0 :     Reference< XInterface > ContentProvider::Create( const Reference< XComponentContext >& i_rContext )
     104                 :            :     {
     105                 :          0 :         const ::comphelper::ComponentContext aContext( i_rContext );
     106                 :          0 :         return *( new ContentProvider( aContext.getLegacyServiceFactory() ) );
     107                 :            :     }
     108                 :            : 
     109                 :            :     //------------------------------------------------------------------------------------------------------------------
     110                 :          0 :     ::rtl::OUString ContentProvider::getRootURL()
     111                 :            :     {
     112                 :          0 :         return ::rtl::OUString(  "vnd.sun.star.extension://"  );
     113                 :            :     }
     114                 :            : 
     115                 :            :     //------------------------------------------------------------------------------------------------------------------
     116                 :          0 :     ::rtl::OUString ContentProvider::getArtificialNodeContentType()
     117                 :            :     {
     118                 :          0 :         return ::rtl::OUString(  "application/vnd.sun.star.extension-content"  );
     119                 :            :     }
     120                 :            : 
     121                 :            :     //------------------------------------------------------------------------------------------------------------------
     122                 :            :     namespace
     123                 :            :     {
     124                 :          0 :         void lcl_ensureAndTransfer( ::rtl::OUString& io_rIdentifierFragment, ::rtl::OUStringBuffer& o_rNormalization, const sal_Unicode i_nLeadingChar )
     125                 :            :         {
     126                 :          0 :             if ( ( io_rIdentifierFragment.isEmpty() ) || ( io_rIdentifierFragment[0] != i_nLeadingChar ) )
     127                 :          0 :                 throw IllegalIdentifierException();
     128                 :          0 :             io_rIdentifierFragment = io_rIdentifierFragment.copy( 1 );
     129                 :          0 :             o_rNormalization.append( i_nLeadingChar );
     130                 :          0 :         }
     131                 :            :     }
     132                 :            : 
     133                 :            :     //------------------------------------------------------------------------------------------------------------------
     134                 :          0 :     Reference< XContent > SAL_CALL ContentProvider::queryContent( const Reference< XContentIdentifier  >& i_rIdentifier )
     135                 :            :         throw( IllegalIdentifierException, RuntimeException )
     136                 :            :     {
     137                 :            :         // Check URL scheme...
     138                 :          0 :         const ::rtl::OUString sScheme( "vnd.sun.star.extension" );
     139                 :          0 :         if ( !i_rIdentifier->getContentProviderScheme().equalsIgnoreAsciiCase( sScheme ) )
     140                 :          0 :             throw IllegalIdentifierException();
     141                 :            : 
     142                 :            :         // normalize the identifier
     143                 :          0 :         const ::rtl::OUString sIdentifier( i_rIdentifier->getContentIdentifier() );
     144                 :            : 
     145                 :            :         // the scheme needs to be lower-case
     146                 :          0 :         ::rtl::OUStringBuffer aComposer;
     147                 :          0 :         aComposer.append( sIdentifier.copy( 0, sScheme.getLength() ).toAsciiLowerCase() );
     148                 :            : 
     149                 :            :         // one : is required after the scheme
     150                 :          0 :         ::rtl::OUString sRemaining( sIdentifier.copy( sScheme.getLength() ) );
     151                 :          0 :         lcl_ensureAndTransfer( sRemaining, aComposer, ':' );
     152                 :            : 
     153                 :            :         // and at least one /
     154                 :          0 :         lcl_ensureAndTransfer( sRemaining, aComposer, '/' );
     155                 :            : 
     156                 :            :         // the normalized form requires one additional /, but we also accept identifiers which don't have it
     157                 :          0 :         if ( sRemaining.isEmpty() )
     158                 :            :         {
     159                 :            :             // the root content is a special case, it requires ///
     160                 :          0 :             aComposer.appendAscii( "//" );
     161                 :            :         }
     162                 :            :         else
     163                 :            :         {
     164                 :          0 :             if ( sRemaining[0] != '/' )
     165                 :            :             {
     166                 :          0 :                 aComposer.append( sal_Unicode( '/' ) );
     167                 :          0 :                 aComposer.append( sRemaining );
     168                 :            :             }
     169                 :            :             else
     170                 :            :             {
     171                 :          0 :                 lcl_ensureAndTransfer( sRemaining, aComposer, '/' );
     172                 :            :                 // by now, we moved "vnd.sun.star.extension://" from the URL to aComposer
     173                 :          0 :                 if ( sRemaining.isEmpty() )
     174                 :            :                 {
     175                 :            :                     // again, it's the root content, but one / is missing
     176                 :          0 :                     aComposer.append( sal_Unicode( '/' ) );
     177                 :            :                 }
     178                 :            :                 else
     179                 :            :                 {
     180                 :          0 :                     aComposer.append( sRemaining );
     181                 :            :                 }
     182                 :            :             }
     183                 :            :         }
     184                 :          0 :         const Reference< XContentIdentifier > xNormalizedIdentifier( new ::ucbhelper::ContentIdentifier( m_xSMgr, aComposer.makeStringAndClear() ) );
     185                 :            : 
     186                 :          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     187                 :            : 
     188                 :            :         // check if a content with given id already exists...
     189                 :          0 :         Reference< XContent > xContent( queryExistingContent( xNormalizedIdentifier ).get() );
     190                 :          0 :         if ( xContent.is() )
     191                 :            :             return xContent;
     192                 :            : 
     193                 :            :         // create a new content
     194                 :          0 :         xContent = new Content( m_xSMgr, this, xNormalizedIdentifier );
     195                 :          0 :         if ( !xContent->getIdentifier().is() )
     196                 :          0 :             throw IllegalIdentifierException();
     197                 :            : 
     198                 :          0 :         registerNewContent( xContent );
     199                 :          0 :         return xContent;
     200                 :            :     }
     201                 :            : 
     202                 :            : //......................................................................................................................
     203                 :            : } } }   // namespace ucb::ucp::ext
     204                 :            : //......................................................................................................................
     205                 :            : 
     206                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10