2010-10-27 13:03:58 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-22 15:19:32 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2003-10-15 13:44:37 +00:00
|
|
|
|
2014-04-18 22:47:44 +02:00
|
|
|
#ifndef INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX
|
|
|
|
#define INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX
|
2017-01-11 14:19:47 +02:00
|
|
|
|
2003-10-15 13:44:37 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2006-01-16 12:28:53 +00:00
|
|
|
#include <sal/alloca.h>
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
2018-08-18 18:24:16 +02:00
|
|
|
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2003-10-15 13:44:37 +00:00
|
|
|
#include <com/sun/star/io/XInputStream.hpp>
|
|
|
|
#include <com/sun/star/document/XFilter.hpp>
|
|
|
|
#include <com/sun/star/document/XImporter.hpp>
|
|
|
|
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
|
|
|
|
|
|
|
|
#include <com/sun/star/io/XActiveDataSink.hpp>
|
|
|
|
#include <com/sun/star/io/XActiveDataControl.hpp>
|
|
|
|
#include <com/sun/star/io/XStreamListener.hpp>
|
2011-06-13 21:08:00 +01:00
|
|
|
#include <com/sun/star/document/XExtendedFilterDetection.hpp>
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
#include <cppuhelper/factory.hxx>
|
2015-08-15 15:09:19 +09:00
|
|
|
#include <cppuhelper/implbase.hxx>
|
2014-01-31 04:53:17 -02:00
|
|
|
#include <cppuhelper/supportsservice.hxx>
|
|
|
|
#include <cppuhelper/weak.hxx>
|
2017-01-11 14:19:47 +02:00
|
|
|
#include <memory>
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
using namespace ::cppu;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::io;
|
|
|
|
using namespace ::com::sun::star::registry;
|
|
|
|
using namespace ::com::sun::star::document;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::xml::sax;
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2013-11-13 08:52:41 +01:00
|
|
|
#include <unotools/mediadescriptor.hxx>
|
2011-06-13 21:08:00 +01:00
|
|
|
|
2003-10-15 13:44:37 +00:00
|
|
|
#include "hwpfile.h"
|
|
|
|
#include "hcode.h"
|
|
|
|
#include "hbox.h"
|
|
|
|
#include "htags.h"
|
2015-05-04 15:47:07 +01:00
|
|
|
#include "hstream.hxx"
|
2003-10-15 13:44:37 +00:00
|
|
|
#include "drawdef.h"
|
|
|
|
#include "attributes.hxx"
|
|
|
|
|
|
|
|
#define IMPLEMENTATION_NAME "com.sun.comp.hwpimport.HwpImportFilter"
|
2011-06-13 21:08:00 +01:00
|
|
|
#define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
|
|
|
|
#define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
|
|
|
|
#define WRITER_IMPORTER_NAME "com.sun.star.comp.Writer.XMLImporter"
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
struct HwpReaderPrivate;
|
|
|
|
/**
|
|
|
|
* This class implements the external Parser interface
|
|
|
|
*/
|
2015-08-15 15:09:19 +09:00
|
|
|
class HwpReader : public WeakImplHelper<XFilter>
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
HwpReader();
|
2016-09-13 13:09:01 +02:00
|
|
|
virtual ~HwpReader() override;
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* parseStream does Parser-startup initializations
|
|
|
|
*/
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue >& aDescriptor) override;
|
|
|
|
virtual void SAL_CALL cancel() override {}
|
2017-12-04 14:20:26 +02:00
|
|
|
void setDocumentHandler(Reference< XDocumentHandler > const & xHandler)
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
2011-06-13 22:23:07 +01:00
|
|
|
m_rxDocumentHandler = xHandler;
|
2003-10-15 13:44:37 +00:00
|
|
|
}
|
|
|
|
private:
|
2011-06-13 22:23:07 +01:00
|
|
|
Reference< XDocumentHandler > m_rxDocumentHandler;
|
2017-01-18 12:01:50 +02:00
|
|
|
rtl::Reference<AttributeListImpl> mxList;
|
2003-10-15 13:44:37 +00:00
|
|
|
HWPFile hwpfile;
|
2017-01-11 14:19:47 +02:00
|
|
|
std::unique_ptr<HwpReaderPrivate> d;
|
2003-10-15 13:44:37 +00:00
|
|
|
private:
|
|
|
|
/* -------- Document Parsing --------- */
|
|
|
|
void makeMeta();
|
|
|
|
void makeStyles();
|
|
|
|
void makeDrawMiscStyle(HWPDrawingObject *);
|
|
|
|
void makeAutoStyles();
|
|
|
|
void makeMasterStyles();
|
|
|
|
void makeBody();
|
|
|
|
|
|
|
|
void makeTextDecls();
|
|
|
|
|
|
|
|
/* -------- Paragraph Parsing --------- */
|
2016-03-03 13:04:59 +02:00
|
|
|
void parsePara(HWPPara *para);
|
2016-11-11 11:33:26 +02:00
|
|
|
void make_text_p0(HWPPara *para, bool bParaStart);
|
|
|
|
void make_text_p1(HWPPara *para, bool bParaStart);
|
|
|
|
void make_text_p3(HWPPara *para, bool bParaStart);
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
/* -------- rDocument->characters(x) --------- */
|
2012-07-24 11:36:17 +02:00
|
|
|
void makeChars(hchar_string & rStr);
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
/* -------- Special Char Parsing --------- */
|
2017-07-17 11:04:02 +02:00
|
|
|
void makeFieldCode(hchar_string const & rStr, FieldCode const *hbox); //6
|
|
|
|
void makeBookmark(Bookmark const *hbox); //6
|
2003-10-15 13:44:37 +00:00
|
|
|
void makeDateFormat(DateCode *hbox); //7
|
|
|
|
void makeDateCode(DateCode *hbox); //8
|
2017-05-02 11:01:04 +02:00
|
|
|
void makeTab(); //9
|
2003-10-15 13:44:37 +00:00
|
|
|
void makeTable(TxtBox *hbox);
|
|
|
|
void makeTextBox(TxtBox *hbox);
|
|
|
|
void makeFormula(TxtBox *hbox);
|
|
|
|
void makeHyperText(TxtBox *hbox);
|
|
|
|
void makePicture(Picture *hbox);
|
|
|
|
void makePictureDRAW(HWPDrawingObject *drawobj, Picture *hbox);
|
2017-05-02 11:01:04 +02:00
|
|
|
void makeLine();
|
2003-10-15 13:44:37 +00:00
|
|
|
void makeHidden(Hidden *hbox);
|
|
|
|
void makeFootnote(Footnote *hbox);
|
2017-11-03 09:52:08 +02:00
|
|
|
void makeAutoNum(AutoNum const *hbox);
|
2003-10-15 13:44:37 +00:00
|
|
|
void makeShowPageNum();
|
|
|
|
void makeMailMerge(MailMerge *hbox);
|
2017-07-17 11:04:02 +02:00
|
|
|
void makeOutline(Outline const *hbox);
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
/* --------- Styles Parsing ------------ */
|
|
|
|
void makePageStyle();
|
2017-11-03 09:52:08 +02:00
|
|
|
void makeColumns(ColumnDef const *);
|
|
|
|
void makeTStyle(CharShape const *);
|
|
|
|
void makePStyle(ParaShape const *);
|
2003-10-15 13:44:37 +00:00
|
|
|
void makeFStyle(FBoxStyle *);
|
|
|
|
void makeCaptionStyle(FBoxStyle *);
|
|
|
|
void makeDrawStyle(HWPDrawingObject *,FBoxStyle *);
|
|
|
|
void makeTableStyle(Table *);
|
2017-11-03 09:52:08 +02:00
|
|
|
void parseCharShape(CharShape const *);
|
|
|
|
void parseParaShape(ParaShape const *);
|
2015-04-09 08:45:51 +02:00
|
|
|
static char* getTStyleName(int, char *);
|
|
|
|
static char* getPStyleName(int, char *);
|
2003-10-15 13:44:37 +00:00
|
|
|
};
|
|
|
|
|
2015-08-15 15:09:19 +09:00
|
|
|
class HwpImportFilter : public WeakImplHelper< XFilter, XImporter, XServiceInfo, XExtendedFilterDetection >
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-12-29 19:27:43 +00:00
|
|
|
explicit HwpImportFilter(const Reference< XMultiServiceFactory >& rFact);
|
2016-09-13 13:09:01 +02:00
|
|
|
virtual ~HwpImportFilter() override;
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
public:
|
2011-06-13 21:14:31 +01:00
|
|
|
static Sequence< OUString > getSupportedServiceNames_Static() throw();
|
2003-10-15 13:44:37 +00:00
|
|
|
static OUString getImplementationName_Static() throw();
|
|
|
|
|
|
|
|
public:
|
2011-06-13 21:08:00 +01:00
|
|
|
// XFilter
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor ) override;
|
|
|
|
virtual void SAL_CALL cancel() override;
|
2011-06-13 21:08:00 +01:00
|
|
|
|
|
|
|
// XImporter
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc) override;
|
2011-06-13 21:08:00 +01:00
|
|
|
|
|
|
|
// XServiceInfo
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString SAL_CALL getImplementationName() override;
|
|
|
|
Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
|
|
|
|
sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
|
2003-10-15 13:44:37 +00:00
|
|
|
|
2011-06-13 21:08:00 +01:00
|
|
|
//XExtendedFilterDetection
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual OUString SAL_CALL detect( css::uno::Sequence< css::beans::PropertyValue >& rDescriptor ) override;
|
2011-06-13 21:08:00 +01:00
|
|
|
|
2003-10-15 13:44:37 +00:00
|
|
|
public:
|
|
|
|
Reference< XFilter > rFilter;
|
|
|
|
Reference< XImporter > rImporter;
|
|
|
|
};
|
|
|
|
|
2017-01-19 17:56:43 +01:00
|
|
|
/// @throws Exception
|
2003-10-15 13:44:37 +00:00
|
|
|
Reference< XInterface > HwpImportFilter_CreateInstance(
|
2017-01-26 12:28:58 +01:00
|
|
|
const Reference< XMultiServiceFactory >& rSMgr )
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
|
|
|
HwpImportFilter *p = new HwpImportFilter( rSMgr );
|
|
|
|
|
2015-06-08 16:25:38 +02:00
|
|
|
return Reference< XInterface > ( static_cast<OWeakObject*>(p) );
|
2003-10-15 13:44:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 21:14:31 +01:00
|
|
|
Sequence< OUString > HwpImportFilter::getSupportedServiceNames_Static() throw ()
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
2015-11-15 08:43:35 +02:00
|
|
|
Sequence< OUString > aRet { HwpImportFilter::getImplementationName_Static() };
|
2003-10-15 13:44:37 +00:00
|
|
|
return aRet;
|
|
|
|
}
|
2011-06-13 21:08:00 +01:00
|
|
|
|
2015-03-09 21:10:04 +00:00
|
|
|
HwpImportFilter::HwpImportFilter(const Reference< XMultiServiceFactory >& rFact)
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
2012-05-31 19:18:18 -05:00
|
|
|
OUString sService( WRITER_IMPORTER_NAME );
|
2003-10-15 13:44:37 +00:00
|
|
|
try {
|
2015-11-01 09:05:58 +02:00
|
|
|
Reference< XDocumentHandler > xHandler( rFact->createInstance( sService ), UNO_QUERY );
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
HwpReader *p = new HwpReader;
|
|
|
|
p->setDocumentHandler( xHandler );
|
|
|
|
|
2015-11-01 09:05:58 +02:00
|
|
|
Reference< XImporter > xImporter( xHandler, UNO_QUERY );
|
2003-10-15 13:44:37 +00:00
|
|
|
rImporter = xImporter;
|
2015-11-01 09:05:58 +02:00
|
|
|
Reference< XFilter > xFilter( p );
|
2003-10-15 13:44:37 +00:00
|
|
|
rFilter = xFilter;
|
|
|
|
}
|
|
|
|
catch( Exception & )
|
|
|
|
{
|
2017-06-05 09:17:37 +02:00
|
|
|
printf(" fail to instantiate %s\n", WRITER_IMPORTER_NAME );
|
2003-10-15 13:44:37 +00:00
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HwpImportFilter::~HwpImportFilter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool HwpImportFilter::filter( const Sequence< PropertyValue >& aDescriptor )
|
|
|
|
{
|
2011-06-14 00:56:22 +01:00
|
|
|
// delegate to IchitaroImpoter
|
|
|
|
return rFilter->filter( aDescriptor );
|
2003-10-15 13:44:37 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
void HwpImportFilter::cancel()
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
|
|
|
rFilter->cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HwpImportFilter::setTargetDocument( const Reference< XComponent >& xDoc )
|
|
|
|
{
|
|
|
|
// delegate
|
|
|
|
rImporter->setTargetDocument( xDoc );
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString HwpImportFilter::getImplementationName_Static() throw()
|
|
|
|
{
|
2012-05-31 19:18:18 -05:00
|
|
|
return OUString( IMPLEMENTATION_NAME );
|
2003-10-15 13:44:37 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString HwpImportFilter::getImplementationName()
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
2012-05-31 19:18:18 -05:00
|
|
|
return OUString( IMPLEMENTATION_NAME );
|
2003-10-15 13:44:37 +00:00
|
|
|
}
|
2011-06-13 21:08:00 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
sal_Bool HwpImportFilter::supportsService( const OUString& ServiceName )
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
2014-01-31 04:53:17 -02:00
|
|
|
return cppu::supportsService(this, ServiceName);
|
2003-10-15 13:44:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 21:08:00 +01:00
|
|
|
//XExtendedFilterDetection
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString HwpImportFilter::detect( css::uno::Sequence< css::beans::PropertyValue >& rDescriptor )
|
2011-06-13 21:08:00 +01:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sTypeName;
|
2011-06-13 21:08:00 +01:00
|
|
|
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor aDescriptor(rDescriptor);
|
2011-06-13 21:08:00 +01:00
|
|
|
aDescriptor.addInputStream();
|
|
|
|
|
|
|
|
Reference< XInputStream > xInputStream(
|
2013-11-13 08:52:41 +01:00
|
|
|
aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY);
|
2011-06-13 21:08:00 +01:00
|
|
|
|
|
|
|
if (xInputStream.is())
|
|
|
|
{
|
|
|
|
Sequence< sal_Int8 > aData;
|
|
|
|
sal_Int32 nLen = HWPIDLen;
|
|
|
|
if (
|
|
|
|
nLen == xInputStream->readBytes(aData, nLen) &&
|
|
|
|
detect_hwp_version(reinterpret_cast<const char*>(aData.getConstArray()))
|
|
|
|
)
|
|
|
|
{
|
2014-12-18 13:25:42 +01:00
|
|
|
sTypeName = "writer_MIZI_Hwp_97";
|
2011-06-13 21:08:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sTypeName;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
Sequence< OUString> HwpImportFilter::getSupportedServiceNames()
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
2011-06-13 21:08:00 +01:00
|
|
|
Sequence < OUString > aRet(2);
|
|
|
|
OUString* pArray = aRet.getArray();
|
2014-12-18 13:25:42 +01:00
|
|
|
pArray[0] = SERVICE_NAME1;
|
|
|
|
pArray[1] = SERVICE_NAME2;
|
2011-06-13 21:08:00 +01:00
|
|
|
return aRet;
|
2003-10-15 13:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
2017-12-08 15:58:41 +02:00
|
|
|
SAL_DLLPUBLIC_EXPORT void * hwp_component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * )
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
2015-11-10 10:16:36 +01:00
|
|
|
void * pRet = nullptr;
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
if (pServiceManager )
|
|
|
|
{
|
|
|
|
Reference< XSingleServiceFactory > xRet;
|
2015-03-31 13:14:19 +02:00
|
|
|
Reference< XMultiServiceFactory > xSMgr = static_cast< XMultiServiceFactory * > ( pServiceManager );
|
2003-10-15 13:44:37 +00:00
|
|
|
|
|
|
|
OUString aImplementationName = OUString::createFromAscii( pImplName );
|
|
|
|
|
2012-04-06 19:49:53 +02:00
|
|
|
if (aImplementationName == IMPLEMENTATION_NAME )
|
2003-10-15 13:44:37 +00:00
|
|
|
{
|
|
|
|
xRet = createSingleFactory( xSMgr, aImplementationName,
|
|
|
|
HwpImportFilter_CreateInstance,
|
|
|
|
HwpImportFilter::getSupportedServiceNames_Static() );
|
|
|
|
}
|
|
|
|
if (xRet.is())
|
|
|
|
{
|
|
|
|
xRet->acquire();
|
|
|
|
pRet = xRet.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-10-27 13:03:58 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|