LCOV - code coverage report
Current view: top level - svx/source/form - fmdocumentclassification.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 52 82.7 %
Date: 2012-08-25 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 64 48.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "fmdocumentclassification.hxx"
      31                 :            : #include "svx/dbtoolsclient.hxx"
      32                 :            : 
      33                 :            : #include <com/sun/star/container/XChild.hpp>
      34                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      35                 :            : #include <com/sun/star/xforms/XFormsSupplier.hpp>
      36                 :            : #include <com/sun/star/sdbc/XConnection.hpp>
      37                 :            : #include <com/sun/star/frame/XModule.hpp>
      38                 :            : 
      39                 :            : #include <tools/diagnose_ex.h>
      40                 :            : 
      41                 :            : //........................................................................
      42                 :            : namespace svxform
      43                 :            : {
      44                 :            : //........................................................................
      45                 :            : 
      46                 :            :     namespace
      47                 :            :     {
      48                 :            :         using ::com::sun::star::uno::Reference;
      49                 :            :         using ::com::sun::star::uno::XInterface;
      50                 :            :         using ::com::sun::star::container::XChild;
      51                 :            :         using ::com::sun::star::frame::XModel;
      52                 :            :         using ::com::sun::star::uno::UNO_QUERY;
      53                 :            :         using ::com::sun::star::frame::XModule;
      54                 :            : 
      55                 :            :         //....................................................................
      56                 :            :         template< class TYPE >
      57                 :        328 :         Reference< TYPE > getTypedModelNode( const Reference< XInterface >& _rxModelNode )
      58                 :            :         {
      59         [ +  - ]:        328 :             Reference< TYPE > xTypedNode( _rxModelNode, UNO_QUERY );
      60         [ +  + ]:        328 :             if ( xTypedNode.is() )
      61                 :        285 :                 return xTypedNode;
      62                 :            :             else
      63                 :            :             {
      64         [ +  - ]:         43 :                 Reference< XChild > xChild( _rxModelNode, UNO_QUERY );
      65         [ +  + ]:         43 :                 if ( xChild.is() )
      66 [ +  - ][ +  - ]:         40 :                     return getTypedModelNode< TYPE >( xChild->getParent() );
                 [ +  - ]
      67                 :            :                 else
      68                 :        328 :                     return Reference< TYPE >();
      69                 :            :             }
      70                 :            :         }
      71                 :            : 
      72                 :            :         //....................................................................
      73                 :        288 :         Reference< XModel > getDocument( const Reference< XInterface >& _rxModelNode )
      74                 :            :         {
      75                 :        288 :             return getTypedModelNode< XModel >( _rxModelNode );
      76                 :            :         }
      77                 :            :     }
      78                 :            : 
      79                 :            :     using namespace ::com::sun::star::uno;
      80                 :            :     using namespace ::com::sun::star::frame;
      81                 :            :     using namespace ::com::sun::star::lang;
      82                 :            :     using namespace ::com::sun::star::xforms;
      83                 :            :     using namespace ::com::sun::star::container;
      84                 :            :     using namespace ::com::sun::star::sdbc;
      85                 :            : 
      86                 :            :     //====================================================================
      87                 :            :     //====================================================================
      88                 :            :     namespace
      89                 :            :     {
      90                 :            :         //----------------------------------------------------------------
      91                 :            :         struct ModuleInfo
      92                 :            :         {
      93                 :            :             const sal_Char* pAsciiModuleOrServiceName;
      94                 :            :             DocumentType    eType;
      95                 :            :         };
      96                 :            : 
      97                 :            :         //----------------------------------------------------------------
      98                 :       2230 :         const ModuleInfo* lcl_getModuleInfo()
      99                 :            :         {
     100                 :            :             static const ModuleInfo aModuleInfo[] =
     101                 :            :             {
     102                 :            :                 { "com.sun.star.text.TextDocument", eTextDocument },
     103                 :            :                 { "com.sun.star.text.WebDocument", eWebDocument },
     104                 :            :                 { "com.sun.star.sheet.SpreadsheetDocument", eSpreadsheetDocument },
     105                 :            :                 { "com.sun.star.drawing.DrawingDocument", eDrawingDocument },
     106                 :            :                 { "com.sun.star.presentation.PresentationDocument", ePresentationDocument },
     107                 :            :                 { "com.sun.star.xforms.XMLFormDocument", eEnhancedForm },
     108                 :            :                 { "com.sun.star.sdb.FormDesign", eDatabaseForm },
     109                 :            :                 { "com.sun.star.sdb.TextReportDesign", eDatabaseReport },
     110                 :            :                 { "com.sun.star.text.GlobalDocument", eTextDocument },
     111                 :            :                 { NULL, eUnknownDocumentType }
     112                 :            :             };
     113                 :       2230 :             return aModuleInfo;
     114                 :            :         }
     115                 :            :     }
     116                 :            : 
     117                 :            :     //====================================================================
     118                 :            :     //= DocumentClassification
     119                 :            :     //====================================================================
     120                 :            :     //--------------------------------------------------------------------
     121                 :       1942 :     DocumentType DocumentClassification::classifyDocument( const Reference< XModel >& _rxDocumentModel ) SAL_THROW(())
     122                 :            :     {
     123                 :       1942 :         DocumentType eType( eUnknownDocumentType );
     124                 :            : 
     125                 :            :         OSL_ENSURE( _rxDocumentModel.is(), "DocumentClassification::classifyDocument: invalid document!" );
     126         [ -  + ]:       1942 :         if ( !_rxDocumentModel.is() )
     127                 :          0 :             return eType;
     128                 :            : 
     129                 :            :         try
     130                 :            :         {
     131                 :            :             // first, check whether the document has a ModuleIdentifier which we know
     132         [ +  - ]:       1942 :             Reference< XModule > xModule( _rxDocumentModel, UNO_QUERY );
     133         [ +  - ]:       1942 :             if ( xModule.is() )
     134 [ +  - ][ +  - ]:       1942 :                 eType = getDocumentTypeForModuleIdentifier( xModule->getIdentifier() );
     135         [ +  - ]:       1942 :             if ( eType != eUnknownDocumentType )
     136                 :       1942 :                 return eType;
     137                 :            : 
     138                 :            :             // second, check whether it supports one of the services we know
     139         [ #  # ]:          0 :             Reference< XServiceInfo > xSI( _rxDocumentModel, UNO_QUERY_THROW );
     140                 :          0 :             const ModuleInfo* pModuleInfo = lcl_getModuleInfo();
     141         [ #  # ]:          0 :             while ( pModuleInfo->pAsciiModuleOrServiceName )
     142                 :            :             {
     143 [ #  # ][ #  # ]:          0 :                 if ( xSI->supportsService( ::rtl::OUString::createFromAscii( pModuleInfo->pAsciiModuleOrServiceName ) ) )
                 [ #  # ]
     144                 :          0 :                     return pModuleInfo->eType;
     145                 :          0 :                 ++pModuleInfo;
     146                 :            :             }
     147                 :            : 
     148                 :            :             // last: uhm, there is no last resort
     149 [ #  # ][ -  + ]:       1942 :             OSL_FAIL( "DocumentClassification::classifyDocument: unknown document!" );
                 [ #  # ]
     150                 :            :         }
     151                 :          0 :         catch( const Exception& )
     152                 :            :         {
     153                 :            :             DBG_UNHANDLED_EXCEPTION();
     154                 :            :         }
     155                 :            : 
     156                 :       1942 :         return eType;
     157                 :            :     }
     158                 :            : 
     159                 :            :     //--------------------------------------------------------------------
     160                 :        288 :     DocumentType DocumentClassification::classifyHostDocument( const Reference< XInterface >& _rxFormComponent ) SAL_THROW(())
     161                 :            :     {
     162                 :        288 :         DocumentType eType( eUnknownDocumentType );
     163                 :            : 
     164                 :            :         try
     165                 :            :         {
     166 [ +  - ][ +  - ]:        288 :             Reference< XModel > xDocument( getDocument( _rxFormComponent.get() ) );
                 [ +  - ]
     167         [ +  + ]:        288 :             if ( !xDocument.is() )
     168                 :          3 :                 return eUnknownDocumentType;
     169 [ +  - ][ +  + ]:        288 :             eType = classifyDocument( xDocument );
                 [ #  # ]
     170                 :            :         }
     171                 :          0 :         catch( const Exception& )
     172                 :            :         {
     173                 :            :             OSL_FAIL( "DocumentClassification::classifyHostDocument: caught an exception!" );
     174                 :            :         }
     175                 :            : 
     176                 :        288 :         return eType;
     177                 :            :     }
     178                 :            : 
     179                 :            :     //--------------------------------------------------------------------
     180                 :       1942 :     DocumentType DocumentClassification::getDocumentTypeForModuleIdentifier( const ::rtl::OUString& _rModuleIdentifier )
     181                 :            :     {
     182                 :       1942 :         const ModuleInfo* pModuleInfo = lcl_getModuleInfo();
     183         [ +  - ]:       2888 :         while ( pModuleInfo->pAsciiModuleOrServiceName )
     184                 :            :         {
     185         [ +  + ]:       2888 :             if ( _rModuleIdentifier.equalsAscii( pModuleInfo->pAsciiModuleOrServiceName ) )
     186                 :       1942 :                 return pModuleInfo->eType;
     187                 :        946 :             ++pModuleInfo;
     188                 :            :         }
     189                 :       1942 :         return eUnknownDocumentType;
     190                 :            :     }
     191                 :            : 
     192                 :            :     //--------------------------------------------------------------------
     193                 :        288 :     ::rtl::OUString DocumentClassification::getModuleIdentifierForDocumentType( DocumentType _eType )
     194                 :            :     {
     195                 :        288 :         const ModuleInfo* pModuleInfo = lcl_getModuleInfo();
     196         [ +  + ]:        383 :         while ( pModuleInfo->pAsciiModuleOrServiceName )
     197                 :            :         {
     198         [ +  + ]:        380 :             if ( pModuleInfo->eType == _eType )
     199                 :        285 :                 return ::rtl::OUString::createFromAscii( pModuleInfo->pAsciiModuleOrServiceName );
     200                 :         95 :             ++pModuleInfo;
     201                 :            :         }
     202                 :        288 :         return ::rtl::OUString();
     203                 :            :     }
     204                 :            : 
     205                 :            : //........................................................................
     206                 :            : } // namespace svxform
     207                 :            : //........................................................................
     208                 :            : 
     209                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10