LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/writerperfect/source/writer - MSWorksImportFilter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 81 3.7 %
Date: 2013-07-09 Functions: 3 15 20.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             : /* MSWorksImportFilter: 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 <osl/diagnose.h>
      13             : #include <rtl/tencinfo.h>
      14             : 
      15             : #include <com/sun/star/io/XInputStream.hpp>
      16             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      17             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      18             : #include <com/sun/star/xml/sax/InputSource.hpp>
      19             : #include <com/sun/star/xml/sax/XParser.hpp>
      20             : #include <com/sun/star/io/XSeekable.hpp>
      21             : #include <com/sun/star/uno/Reference.h>
      22             : 
      23             : #include <comphelper/componentcontext.hxx>
      24             : #include <xmloff/attrlist.hxx>
      25             : #include <ucbhelper/content.hxx>
      26             : 
      27             : #include <libwps/libwps.h>
      28             : 
      29             : #include <libodfgen/libodfgen.hxx>
      30             : 
      31             : #include "common/DocumentHandler.hxx"
      32             : #include "common/WPXSvStream.hxx"
      33             : #include "MSWorksImportFilter.hxx"
      34             : 
      35             : #include <iostream>
      36             : 
      37             : using namespace ::com::sun::star::uno;
      38             : using com::sun::star::uno::Sequence;
      39             : using com::sun::star::uno::Reference;
      40             : using com::sun::star::uno::Any;
      41             : using com::sun::star::uno::UNO_QUERY;
      42             : using com::sun::star::uno::XInterface;
      43             : using com::sun::star::uno::Exception;
      44             : using com::sun::star::uno::RuntimeException;
      45             : using com::sun::star::beans::PropertyValue;
      46             : using com::sun::star::document::XFilter;
      47             : using com::sun::star::document::XExtendedFilterDetection;
      48             : using com::sun::star::ucb::XCommandEnvironment;
      49             : 
      50             : using com::sun::star::io::XInputStream;
      51             : using com::sun::star::document::XImporter;
      52             : using com::sun::star::xml::sax::InputSource;
      53             : using com::sun::star::xml::sax::XAttributeList;
      54             : using com::sun::star::xml::sax::XDocumentHandler;
      55             : using com::sun::star::xml::sax::XParser;
      56             : 
      57             : 
      58           0 : sal_Bool SAL_CALL MSWorksImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
      59             : throw (RuntimeException)
      60             : {
      61             :     SAL_INFO("writerperfect", "MSWorksImportFilter::importImpl");
      62             : 
      63           0 :     sal_Int32 nLength = aDescriptor.getLength();
      64           0 :     const PropertyValue *pValue = aDescriptor.getConstArray();
      65           0 :     Reference < XInputStream > xInputStream;
      66           0 :     for ( sal_Int32 i = 0 ; i < nLength; i++)
      67             :     {
      68           0 :         if ( pValue[i].Name == "InputStream" )
      69           0 :             pValue[i].Value >>= xInputStream;
      70             :     }
      71           0 :     if ( !xInputStream.is() )
      72             :     {
      73             :         OSL_ASSERT( 0 );
      74           0 :         return sal_False;
      75             :     }
      76             : 
      77             :     // An XML import service: what we push sax messages to..
      78           0 :     OUString sXMLImportService (  "com.sun.star.comp.Writer.XMLOasisImporter"  );
      79           0 :     Reference < XDocumentHandler > xInternalHandler( comphelper::ComponentContext( mxContext ).createComponent( sXMLImportService ), UNO_QUERY );
      80             : 
      81             :     // The XImporter sets up an empty target document for XDocumentHandler to write to..
      82           0 :     Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
      83           0 :     xImporter->setTargetDocument(mxDoc);
      84             : 
      85             :     // OO Document Handler: abstract class to handle document SAX messages, concrete implementation here
      86             :     // writes to in-memory target doc
      87           0 :     DocumentHandler xHandler(xInternalHandler);
      88             : 
      89           0 :     WPXSvInputStream input( xInputStream );
      90             : 
      91           0 :     OdtGenerator collector(&xHandler, ODF_FLAT_XML);
      92           0 :     if (WPS_OK == WPSDocument::parse(&input, &collector))
      93           0 :         return sal_True;
      94           0 :     return sal_False;
      95             : }
      96             : 
      97           0 : sal_Bool SAL_CALL MSWorksImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
      98             : throw (RuntimeException)
      99             : {
     100             :     SAL_INFO("writerperfect", "MSWorksImportFilter::filter");
     101           0 :     return importImpl ( aDescriptor );
     102             : }
     103           0 : void SAL_CALL MSWorksImportFilter::cancel(  )
     104             : throw (RuntimeException)
     105             : {
     106             :     SAL_INFO("writerperfect", "MSWorksImportFilter::cancel");
     107           0 : }
     108             : 
     109             : // XImporter
     110           0 : void SAL_CALL MSWorksImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
     111             : throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
     112             : {
     113             :     SAL_INFO("writerperfect", "MSWorksImportFilter::getTargetDocument");
     114           0 :     mxDoc = xDoc;
     115           0 : }
     116             : 
     117             : // XExtendedFilterDetection
     118           0 : OUString SAL_CALL MSWorksImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor )
     119             : throw( com::sun::star::uno::RuntimeException )
     120             : {
     121             :     SAL_INFO("writerperfect", "MSWorksImportFilter::detect");
     122             : 
     123           0 :     WPSConfidence confidence = WPS_CONFIDENCE_NONE;
     124           0 :     OUString sTypeName;
     125           0 :     sal_Int32 nLength = Descriptor.getLength();
     126           0 :     sal_Int32 location = nLength;
     127           0 :     const PropertyValue *pValue = Descriptor.getConstArray();
     128           0 :     Reference < XInputStream > xInputStream;
     129           0 :     for ( sal_Int32 i = 0 ; i < nLength; i++)
     130             :     {
     131           0 :         if ( pValue[i].Name == "TypeName" )
     132           0 :             location=i;
     133           0 :         else if ( pValue[i].Name == "InputStream" )
     134           0 :             pValue[i].Value >>= xInputStream;
     135             :     }
     136             : 
     137           0 :     if (!xInputStream.is())
     138           0 :         return OUString();
     139             : 
     140           0 :     WPXSvInputStream input( xInputStream );
     141             : 
     142           0 :     confidence = WPSDocument::isFileFormatSupported(&input);
     143             : 
     144           0 :     if ((confidence == WPS_CONFIDENCE_EXCELLENT) || (confidence == WPS_CONFIDENCE_GOOD))
     145           0 :         sTypeName = "writer_MS_Works_Document";
     146             : 
     147           0 :     if (!sTypeName.isEmpty())
     148             :     {
     149           0 :         if ( location == nLength )
     150             :         {
     151           0 :             Descriptor.realloc(nLength+1);
     152           0 :             Descriptor[location].Name = "TypeName";
     153             :         }
     154             : 
     155           0 :         Descriptor[location].Value <<=sTypeName;
     156             :     }
     157             : 
     158           0 :     return sTypeName;
     159             : }
     160             : 
     161             : 
     162             : // XInitialization
     163           0 : void SAL_CALL MSWorksImportFilter::initialize( const Sequence< Any >& aArguments )
     164             : throw (Exception, RuntimeException)
     165             : {
     166             :     SAL_INFO("writerperfect", "MSWorksImportFilter::initialize");
     167           0 :     Sequence < PropertyValue > aAnySeq;
     168           0 :     sal_Int32 nLength = aArguments.getLength();
     169           0 :     if ( nLength && ( aArguments[0] >>= aAnySeq ) )
     170             :     {
     171           0 :         const PropertyValue *pValue = aAnySeq.getConstArray();
     172           0 :         nLength = aAnySeq.getLength();
     173           0 :         for ( sal_Int32 i = 0 ; i < nLength; i++)
     174             :         {
     175           0 :             if ( pValue[i].Name == "Type" )
     176             :             {
     177           0 :                 pValue[i].Value >>= msFilterName;
     178           0 :                 break;
     179             :             }
     180             :         }
     181           0 :     }
     182           0 : }
     183           2 : OUString MSWorksImportFilter_getImplementationName ()
     184             : throw (RuntimeException)
     185             : {
     186           2 :     return OUString (  "com.sun.star.comp.Writer.MSWorksImportFilter"  );
     187             : }
     188             : 
     189             : #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
     190             : #define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
     191           0 : sal_Bool SAL_CALL MSWorksImportFilter_supportsService( const OUString &ServiceName )
     192             : throw (RuntimeException)
     193             : {
     194           0 :     return ( ServiceName == SERVICE_NAME1 || ServiceName == SERVICE_NAME2 );
     195             : }
     196           0 : Sequence< OUString > SAL_CALL MSWorksImportFilter_getSupportedServiceNames(  )
     197             : throw (RuntimeException)
     198             : {
     199           0 :     Sequence < OUString > aRet(2);
     200           0 :     OUString *pArray = aRet.getArray();
     201           0 :     pArray[0] =  OUString (  SERVICE_NAME1  );
     202           0 :     pArray[1] =  OUString (  SERVICE_NAME2  );
     203           0 :     return aRet;
     204             : }
     205             : #undef SERVICE_NAME2
     206             : #undef SERVICE_NAME1
     207             : 
     208           0 : Reference< XInterface > SAL_CALL MSWorksImportFilter_createInstance( const Reference< XComponentContext > & rContext)
     209             : throw( Exception )
     210             : {
     211           0 :     return (cppu::OWeakObject *) new MSWorksImportFilter( rContext );
     212             : }
     213             : 
     214             : // XServiceInfo
     215           0 : OUString SAL_CALL MSWorksImportFilter::getImplementationName(  )
     216             : throw (RuntimeException)
     217             : {
     218           0 :     return MSWorksImportFilter_getImplementationName();
     219             : }
     220           0 : sal_Bool SAL_CALL MSWorksImportFilter::supportsService( const OUString &rServiceName )
     221             : throw (RuntimeException)
     222             : {
     223           0 :     return MSWorksImportFilter_supportsService( rServiceName );
     224             : }
     225           0 : Sequence< OUString > SAL_CALL MSWorksImportFilter::getSupportedServiceNames(  )
     226             : throw (RuntimeException)
     227             : {
     228           0 :     return MSWorksImportFilter_getSupportedServiceNames();
     229           6 : }
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10