LCOV - code coverage report
Current view: top level - hwpfilter/source - hwpreader.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 41 75 54.7 %
Date: 2014-04-11 Functions: 9 16 56.2 %
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             : #ifndef _HWPREADER_HXX_
      21             : #define _HWPREADER_HXX_
      22             : #include <errno.h>
      23             : #include <stdio.h>
      24             : #include <string.h>
      25             : #include <sal/alloca.h>
      26             : 
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <com/sun/star/lang/XComponent.hpp>
      29             : #include <com/sun/star/io/XInputStream.hpp>
      30             : #include <com/sun/star/document/XFilter.hpp>
      31             : #include <com/sun/star/document/XImporter.hpp>
      32             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      33             : 
      34             : #include <com/sun/star/io/XActiveDataSink.hpp>
      35             : #include <com/sun/star/io/XActiveDataControl.hpp>
      36             : #include <com/sun/star/io/XStreamListener.hpp>
      37             : #include <com/sun/star/document/XExtendedFilterDetection.hpp>
      38             : 
      39             : #include <cppuhelper/factory.hxx>
      40             : #include <cppuhelper/implbase1.hxx>
      41             : #include <cppuhelper/implbase2.hxx>
      42             : #include <cppuhelper/implbase4.hxx>
      43             : #include <cppuhelper/supportsservice.hxx>
      44             : #include <cppuhelper/weak.hxx>
      45             : 
      46             : using namespace ::rtl;
      47             : using namespace ::cppu;
      48             : using namespace ::com::sun::star::lang;
      49             : using namespace ::com::sun::star::uno;
      50             : using namespace ::com::sun::star::io;
      51             : using namespace ::com::sun::star::registry;
      52             : using namespace ::com::sun::star::document;
      53             : using namespace ::com::sun::star::beans;
      54             : using namespace ::com::sun::star::xml::sax;
      55             : 
      56             : #include <assert.h>
      57             : 
      58             : #include <unotools/mediadescriptor.hxx>
      59             : 
      60             : #include "hwpfile.h"
      61             : #include "hcode.h"
      62             : #include "hbox.h"
      63             : #include "htags.h"
      64             : #include "hstream.h"
      65             : #include "drawdef.h"
      66             : #include "attributes.hxx"
      67             : 
      68             : #define IMPLEMENTATION_NAME "com.sun.comp.hwpimport.HwpImportFilter"
      69             : #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
      70             : #define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
      71             : #define WRITER_IMPORTER_NAME "com.sun.star.comp.Writer.XMLImporter"
      72             : 
      73             : struct HwpReaderPrivate;
      74             : /**
      75             :  * This class implements the external Parser interface
      76             :  */
      77             : class HwpReader : public WeakImplHelper1<XFilter>
      78             : {
      79             : 
      80             : public:
      81             :     HwpReader();
      82             :     virtual ~HwpReader();
      83             : 
      84             : public:
      85             :     /**
      86             :      * parseStream does Parser-startup initializations
      87             :      */
      88             :     virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue >& aDescriptor) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      89           0 :     virtual void SAL_CALL cancel() throw(RuntimeException, std::exception) SAL_OVERRIDE {}
      90           1 :     virtual void SAL_CALL setDocumentHandler(Reference< XDocumentHandler > xHandler)
      91             :     {
      92           1 :         m_rxDocumentHandler = xHandler;
      93           1 :     }
      94             : private:
      95             :     Reference< XDocumentHandler > m_rxDocumentHandler;
      96             :     Reference< XAttributeList > rList;
      97             :     AttributeListImpl *pList;
      98             :     HWPFile hwpfile;
      99             :     HwpReaderPrivate *d;
     100             : private:
     101             :     /* -------- Document Parsing --------- */
     102             :     void makeMeta();
     103             :     void makeStyles();
     104             :     void makeDrawMiscStyle(HWPDrawingObject *);
     105             :     void makeAutoStyles();
     106             :     void makeMasterStyles();
     107             :     void makeBody();
     108             : 
     109             :     void makeTextDecls();
     110             : 
     111             :     /* -------- Paragraph Parsing --------- */
     112             :     void parsePara(HWPPara *para, sal_Bool bParaStart = sal_False);
     113             :     void make_text_p0(HWPPara *para, sal_Bool bParaStart = sal_False);
     114             :     void make_text_p1(HWPPara *para, sal_Bool bParaStart = sal_False);
     115             :     void make_text_p3(HWPPara *para, sal_Bool bParaStart = sal_False);
     116             : 
     117             :     /* -------- rDocument->characters(x) --------- */
     118             :     void makeChars(hchar_string & rStr);
     119             : 
     120             :     /* -------- Special Char Parsing --------- */
     121             :     void makeFieldCode(hchar_string & rStr, FieldCode *hbox); //6
     122             :     void makeBookmark(Bookmark *hbox);      //6
     123             :     void makeDateFormat(DateCode *hbox);    //7
     124             :     void makeDateCode(DateCode *hbox);      //8
     125             :     void makeTab(Tab *hbox);            //9
     126             :     void makeTable(TxtBox *hbox);
     127             :     void makeTextBox(TxtBox *hbox);
     128             :     void makeFormula(TxtBox *hbox);
     129             :     void makeHyperText(TxtBox *hbox);
     130             :     void makePicture(Picture *hbox);
     131             :     void makePictureDRAW(HWPDrawingObject *drawobj, Picture *hbox);
     132             :     void makeLine(Line *hbox);
     133             :     void makeHidden(Hidden *hbox);
     134             :     void makeFootnote(Footnote *hbox);
     135             :     void makeAutoNum(AutoNum *hbox);
     136             :     void makeShowPageNum();
     137             :     void makeMailMerge(MailMerge *hbox);
     138             :     void makeTocMark(TocMark *hbox);
     139             :     void makeIndexMark(IndexMark *hbox);
     140             :     void makeOutline(Outline *hbox);
     141             : 
     142             :     /* --------- Styles Parsing ------------ */
     143             :     void makePageStyle();
     144             :     void makeColumns(ColumnDef *);
     145             :     void makeTStyle(CharShape *);
     146             :     void makePStyle(ParaShape *);
     147             :     void makeFStyle(FBoxStyle *);
     148             :     void makeCaptionStyle(FBoxStyle *);
     149             :     void makeDrawStyle(HWPDrawingObject *,FBoxStyle *);
     150             :     void makeTableStyle(Table *);
     151             :     void parseCharShape(CharShape *);
     152             :     void parseParaShape(ParaShape *);
     153             :     char* getTStyleName(int, char *);
     154             :     char* getPStyleName(int, char *);
     155             : };
     156             : 
     157             : class HwpImportFilter : public WeakImplHelper4< XFilter, XImporter, XServiceInfo, XExtendedFilterDetection >
     158             : {
     159             : public:
     160             :     HwpImportFilter( const Reference< XMultiServiceFactory > xFact );
     161             :     virtual ~HwpImportFilter();
     162             : 
     163             : public:
     164             :     static Sequence< OUString > getSupportedServiceNames_Static() throw();
     165             :     static OUString getImplementationName_Static() throw();
     166             : 
     167             : public:
     168             :     // XFilter
     169             :     virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor )
     170             :         throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     171             :     virtual void SAL_CALL cancel() throw(RuntimeException, std::exception) SAL_OVERRIDE;
     172             : 
     173             :     // XImporter
     174             :     virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc)
     175             :         throw( IllegalArgumentException, RuntimeException, std::exception ) SAL_OVERRIDE;
     176             : 
     177             :     // XServiceInfo
     178             :     OUString SAL_CALL getImplementationName() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     179             :     Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     180             :     sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     181             : 
     182             :     //XExtendedFilterDetection
     183             :     virtual OUString SAL_CALL detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rDescriptor ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     184             : 
     185             : public:
     186             :     Reference< XFilter > rFilter;
     187             :     Reference< XImporter > rImporter;
     188             : };
     189             : 
     190           1 : Reference< XInterface > HwpImportFilter_CreateInstance(
     191             :     const Reference< XMultiServiceFactory >& rSMgr ) throw( Exception )
     192             : {
     193           1 :     HwpImportFilter *p = new HwpImportFilter( rSMgr );
     194             : 
     195           1 :     return Reference< XInterface > ( (OWeakObject* )p );
     196             : }
     197             : 
     198           1 : Sequence< OUString > HwpImportFilter::getSupportedServiceNames_Static() throw ()
     199             : {
     200           1 :     Sequence< OUString > aRet(1);
     201           1 :     aRet.getArray()[0] = HwpImportFilter::getImplementationName_Static();
     202           1 :     return aRet;
     203             : }
     204             : 
     205           1 : HwpImportFilter::HwpImportFilter( const Reference< XMultiServiceFactory > xFact )
     206             : {
     207           1 :     OUString sService( WRITER_IMPORTER_NAME );
     208             :     try {
     209             :         Reference< XDocumentHandler >
     210           1 :             xHandler( xFact->createInstance( sService ), UNO_QUERY );
     211             : 
     212           1 :         HwpReader *p = new HwpReader;
     213           1 :         p->setDocumentHandler( xHandler );
     214             : 
     215           2 :         Reference< XImporter > xImporter = Reference< XImporter >( xHandler, UNO_QUERY );
     216           1 :         rImporter = xImporter;
     217           2 :         Reference< XFilter > xFilter = Reference< XFilter >( p );
     218           2 :         rFilter = xFilter;
     219             :     }
     220           0 :     catch( Exception & )
     221             :     {
     222           0 :         printf(" fail to instanciate %s\n", WRITER_IMPORTER_NAME );
     223           0 :         exit( 1 );
     224           1 :     }
     225           1 : }
     226             : 
     227           2 : HwpImportFilter::~HwpImportFilter()
     228             : {
     229           2 : }
     230             : 
     231           2 : sal_Bool HwpImportFilter::filter( const Sequence< PropertyValue >& aDescriptor )
     232             :     throw( RuntimeException, std::exception )
     233             : {
     234             :     // delegate to IchitaroImpoter
     235           2 :     return rFilter->filter( aDescriptor );
     236             : }
     237             : 
     238           0 : void HwpImportFilter::cancel() throw(::com::sun::star::uno::RuntimeException, std::exception)
     239             : {
     240           0 :     rFilter->cancel();
     241           0 : }
     242             : 
     243           0 : void HwpImportFilter::setTargetDocument( const Reference< XComponent >& xDoc )
     244             :     throw( IllegalArgumentException, RuntimeException, std::exception )
     245             : {
     246             :         // delegate
     247           0 :     rImporter->setTargetDocument( xDoc );
     248           0 : }
     249             : 
     250           1 : OUString HwpImportFilter::getImplementationName_Static() throw()
     251             : {
     252           1 :     return OUString( IMPLEMENTATION_NAME );
     253             : }
     254             : 
     255           0 : OUString HwpImportFilter::getImplementationName() throw(::com::sun::star::uno::RuntimeException, std::exception)
     256             : {
     257           0 :     return OUString( IMPLEMENTATION_NAME );
     258             : }
     259             : 
     260           0 : sal_Bool HwpImportFilter::supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     261             : {
     262           0 :     return cppu::supportsService(this, ServiceName);
     263             : }
     264             : 
     265             : //XExtendedFilterDetection
     266           0 : OUString HwpImportFilter::detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rDescriptor ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     267             : {
     268           0 :     OUString sTypeName;
     269             : 
     270           0 :     utl::MediaDescriptor aDescriptor(rDescriptor);
     271           0 :     aDescriptor.addInputStream();
     272             : 
     273             :     Reference< XInputStream > xInputStream(
     274           0 :         aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY);
     275             : 
     276           0 :     if (xInputStream.is())
     277             :     {
     278           0 :         Sequence< sal_Int8 > aData;
     279           0 :         sal_Int32 nLen = HWPIDLen;
     280           0 :         if (
     281           0 :              nLen == xInputStream->readBytes(aData, nLen) &&
     282           0 :              detect_hwp_version(reinterpret_cast<const char*>(aData.getConstArray()))
     283             :            )
     284             :         {
     285           0 :             sTypeName = OUString("writer_MIZI_Hwp_97");
     286           0 :         }
     287             :     }
     288             : 
     289           0 :     return sTypeName;
     290             : }
     291             : 
     292           0 : Sequence< OUString> HwpImportFilter::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception)
     293             : {
     294           0 :     Sequence < OUString > aRet(2);
     295           0 :     OUString* pArray = aRet.getArray();
     296           0 :     pArray[0] = OUString(SERVICE_NAME1);
     297           0 :     pArray[1] = OUString(SERVICE_NAME2);
     298           0 :     return aRet;
     299             : }
     300             : 
     301             : extern "C"
     302             : {
     303           1 :     SAL_DLLPUBLIC_EXPORT void * SAL_CALL hwp_component_getFactory( const sal_Char * pImplName, void * pServiceManager, void *  )
     304             :     {
     305           1 :         void * pRet = 0;
     306             : 
     307           1 :         if (pServiceManager )
     308             :         {
     309           1 :             Reference< XSingleServiceFactory > xRet;
     310           2 :             Reference< XMultiServiceFactory > xSMgr = reinterpret_cast< XMultiServiceFactory * > ( pServiceManager );
     311             : 
     312           2 :             OUString aImplementationName = OUString::createFromAscii( pImplName );
     313             : 
     314           1 :             if (aImplementationName == IMPLEMENTATION_NAME )
     315             :             {
     316           2 :                 xRet = createSingleFactory( xSMgr, aImplementationName,
     317             :                                             HwpImportFilter_CreateInstance,
     318           1 :                                             HwpImportFilter::getSupportedServiceNames_Static() );
     319             :             }
     320           1 :             if (xRet.is())
     321             :             {
     322           1 :                 xRet->acquire();
     323           1 :                 pRet = xRet.get();
     324           1 :             }
     325             :         }
     326             : 
     327           1 :         return pRet;
     328             :     }
     329             : }
     330             : 
     331             : #endif
     332             : 
     333             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10