LCOV - code coverage report
Current view: top level - writerperfect/source/writer - EBookImportFilter.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 45 57 78.9 %
Date: 2015-06-13 12:38:46 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* EBookImportFilter: Sets up the filter, and calls DocumentCollector
       3             :  * to do the actual filtering
       4             :  *
       5             :  * This file is part of the LibreOffice project.
       6             :  *
       7             :  * This Source Code Form is subject to the terms of the Mozilla Public
       8             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       9             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
      10             :  */
      11             : 
      12             : #include <com/sun/star/uno/Reference.h>
      13             : #include <cppuhelper/supportsservice.hxx>
      14             : 
      15             : #include <libe-book/libe-book.h>
      16             : 
      17             : #include "EBookImportFilter.hxx"
      18             : 
      19             : using com::sun::star::uno::Sequence;
      20             : using com::sun::star::uno::Reference;
      21             : using com::sun::star::uno::Any;
      22             : using com::sun::star::uno::XInterface;
      23             : using com::sun::star::uno::Exception;
      24             : using com::sun::star::uno::RuntimeException;
      25             : using com::sun::star::uno::XComponentContext;
      26             : 
      27             : using libebook::EBOOKDocument;
      28             : 
      29           5 : bool EBookImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdtGenerator &rGenerator, utl::MediaDescriptor &rDescriptor)
      30             : {
      31           5 :     EBOOKDocument::Type type = EBOOKDocument::TYPE_UNKNOWN;
      32             : 
      33           5 :     rtl::OUString aFilterName;
      34             : 
      35           5 :     rDescriptor[utl::MediaDescriptor::PROP_FILTERNAME()] >>= aFilterName;
      36             :     assert(!aFilterName.isEmpty());
      37             : 
      38           5 :     if (aFilterName == "BroadBand eBook")
      39           1 :         type = EBOOKDocument::TYPE_BBEB;
      40           5 :     if (aFilterName == "FictionBook 2")
      41           2 :         type = EBOOKDocument::TYPE_FICTIONBOOK2;
      42           3 :     else if (aFilterName == "PalmDoc")
      43           1 :         type = EBOOKDocument::TYPE_PALMDOC;
      44           2 :     else if (aFilterName == "Plucker eBook")
      45           0 :         type = EBOOKDocument::TYPE_PLUCKER;
      46           2 :     else if (aFilterName == "eReader eBook")
      47           1 :         type = EBOOKDocument::TYPE_PEANUTPRESS;
      48           1 :     else if (aFilterName == "TealDoc")
      49           0 :         type = EBOOKDocument::TYPE_TEALDOC;
      50           1 :     else if (aFilterName == "zTXT")
      51           0 :         type = EBOOKDocument::TYPE_ZTXT;
      52             : 
      53           5 :     if (EBOOKDocument::TYPE_UNKNOWN != type)
      54           5 :         return EBOOKDocument::RESULT_OK == EBOOKDocument::parse(&rInput, &rGenerator, type);
      55             : 
      56           0 :     return false;
      57             : }
      58             : 
      59         615 : bool EBookImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
      60             : {
      61         615 :     rTypeName.clear();
      62             : 
      63         615 :     EBOOKDocument::Type type = EBOOKDocument::TYPE_UNKNOWN;
      64             : 
      65         615 :     if (EBOOKDocument::CONFIDENCE_EXCELLENT == EBOOKDocument::isSupported(&rInput, &type))
      66             :     {
      67           5 :         switch (type)
      68             :         {
      69             :         case EBOOKDocument::TYPE_BBEB :
      70           1 :             rTypeName = "writer_BroadBand_eBook";
      71           1 :             break;
      72             :         case EBOOKDocument::TYPE_FICTIONBOOK2 :
      73           2 :             rTypeName = "writer_FictionBook_2";
      74           2 :             break;
      75             :         case EBOOKDocument::TYPE_PALMDOC :
      76           1 :             rTypeName = "writer_PalmDoc";
      77           1 :             break;
      78             :         case EBOOKDocument::TYPE_PLUCKER :
      79           0 :             rTypeName = "writer_Plucker_eBook";
      80           0 :             break;
      81             :         case EBOOKDocument::TYPE_PEANUTPRESS :
      82           1 :             rTypeName = "writer_eReader_eBook";
      83           1 :             break;
      84             :         case EBOOKDocument::TYPE_TEALDOC :
      85           0 :             rTypeName = "writer_TealDoc";
      86           0 :             break;
      87             :         case EBOOKDocument::TYPE_ZTXT :
      88           0 :             rTypeName = "writer_zTXT";
      89           0 :             break;
      90             :         default :
      91             :             SAL_WARN_IF(type != EBOOKDocument::TYPE_UNKNOWN, "writerperfect", "EBookImportFilter::doDetectFormat: document type " << type << " detected, but ignored");
      92             :         }
      93             :     }
      94             : 
      95         615 :     return !rTypeName.isEmpty();
      96             : }
      97             : 
      98          33 : OUString EBookImportFilter_getImplementationName()
      99             : throw (RuntimeException)
     100             : {
     101          33 :     return OUString("org.libreoffice.comp.Writer.EBookImportFilter");
     102             : }
     103             : 
     104           7 : Sequence< OUString > SAL_CALL EBookImportFilter_getSupportedServiceNames()
     105             : throw (RuntimeException)
     106             : {
     107           7 :     Sequence < OUString > aRet(2);
     108           7 :     OUString *pArray = aRet.getArray();
     109           7 :     pArray[0] =  "com.sun.star.document.ImportFilter";
     110           7 :     pArray[1] =  "com.sun.star.document.ExtendedTypeDetection";
     111           7 :     return aRet;
     112             : }
     113             : #undef SERVICE_NAME2
     114             : #undef SERVICE_NAME1
     115             : 
     116         611 : Reference< XInterface > SAL_CALL EBookImportFilter_createInstance(const Reference< XComponentContext > &rContext)
     117             : throw(Exception)
     118             : {
     119         611 :     return static_cast<cppu::OWeakObject *>(new EBookImportFilter(rContext));
     120             : }
     121             : 
     122             : // XServiceInfo
     123           1 : OUString SAL_CALL EBookImportFilter::getImplementationName()
     124             : throw (RuntimeException, std::exception)
     125             : {
     126           1 :     return EBookImportFilter_getImplementationName();
     127             : }
     128           0 : sal_Bool SAL_CALL EBookImportFilter::supportsService(const OUString &rServiceName)
     129             : throw (RuntimeException, std::exception)
     130             : {
     131           0 :     return cppu::supportsService(this, rServiceName);
     132             : }
     133           1 : Sequence< OUString > SAL_CALL EBookImportFilter::getSupportedServiceNames()
     134             : throw (RuntimeException, std::exception)
     135             : {
     136           1 :     return EBookImportFilter_getSupportedServiceNames();
     137             : }
     138             : 
     139             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11