1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX
21 #define INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX
25 #include <sal/alloca.h>
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>
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>
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>
46 using namespace ::cppu
;
47 using namespace ::com::sun::star::lang
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::io
;
50 using namespace ::com::sun::star::registry
;
51 using namespace ::com::sun::star::document
;
52 using namespace ::com::sun::star::beans
;
53 using namespace ::com::sun::star::xml::sax
;
57 #include <unotools/mediadescriptor.hxx>
63 #include "hstream.hxx"
65 #include "attributes.hxx"
67 #define IMPLEMENTATION_NAME "com.sun.comp.hwpimport.HwpImportFilter"
68 #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
69 #define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
70 #define WRITER_IMPORTER_NAME "com.sun.star.comp.Writer.XMLImporter"
72 struct HwpReaderPrivate
;
74 * This class implements the external Parser interface
76 class HwpReader
: public WeakImplHelper1
<XFilter
>
85 * parseStream does Parser-startup initializations
87 virtual sal_Bool SAL_CALL
filter(const Sequence
< PropertyValue
>& aDescriptor
) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
88 virtual void SAL_CALL
cancel() throw(RuntimeException
, std::exception
) SAL_OVERRIDE
{}
89 void SAL_CALL
setDocumentHandler(Reference
< XDocumentHandler
> xHandler
)
91 m_rxDocumentHandler
= xHandler
;
94 Reference
< XDocumentHandler
> m_rxDocumentHandler
;
95 Reference
< XAttributeList
> rList
;
96 AttributeListImpl
*pList
;
100 /* -------- Document Parsing --------- */
103 void makeDrawMiscStyle(HWPDrawingObject
*);
104 void makeAutoStyles();
105 void makeMasterStyles();
108 void makeTextDecls();
110 /* -------- Paragraph Parsing --------- */
111 void parsePara(HWPPara
*para
, bool bParaStart
= false);
112 void make_text_p0(HWPPara
*para
, bool bParaStart
= false);
113 void make_text_p1(HWPPara
*para
, bool bParaStart
= false);
114 void make_text_p3(HWPPara
*para
, bool bParaStart
= false);
116 /* -------- rDocument->characters(x) --------- */
117 void makeChars(hchar_string
& rStr
);
119 /* -------- Special Char Parsing --------- */
120 void makeFieldCode(hchar_string
& rStr
, FieldCode
*hbox
); //6
121 void makeBookmark(Bookmark
*hbox
); //6
122 void makeDateFormat(DateCode
*hbox
); //7
123 void makeDateCode(DateCode
*hbox
); //8
124 void makeTab(Tab
*hbox
); //9
125 void makeTable(TxtBox
*hbox
);
126 void makeTextBox(TxtBox
*hbox
);
127 void makeFormula(TxtBox
*hbox
);
128 void makeHyperText(TxtBox
*hbox
);
129 void makePicture(Picture
*hbox
);
130 void makePictureDRAW(HWPDrawingObject
*drawobj
, Picture
*hbox
);
131 void makeLine(Line
*hbox
);
132 void makeHidden(Hidden
*hbox
);
133 void makeFootnote(Footnote
*hbox
);
134 void makeAutoNum(AutoNum
*hbox
);
135 void makeShowPageNum();
136 void makeMailMerge(MailMerge
*hbox
);
137 void makeOutline(Outline
*hbox
);
139 /* --------- Styles Parsing ------------ */
140 void makePageStyle();
141 void makeColumns(ColumnDef
*);
142 void makeTStyle(CharShape
*);
143 void makePStyle(ParaShape
*);
144 void makeFStyle(FBoxStyle
*);
145 void makeCaptionStyle(FBoxStyle
*);
146 void makeDrawStyle(HWPDrawingObject
*,FBoxStyle
*);
147 void makeTableStyle(Table
*);
148 void parseCharShape(CharShape
*);
149 void parseParaShape(ParaShape
*);
150 static char* getTStyleName(int, char *);
151 static char* getPStyleName(int, char *);
154 class HwpImportFilter
: public WeakImplHelper4
< XFilter
, XImporter
, XServiceInfo
, XExtendedFilterDetection
>
157 HwpImportFilter(const Reference
< XMultiServiceFactory
>& rFact
);
158 virtual ~HwpImportFilter();
161 static Sequence
< OUString
> getSupportedServiceNames_Static() throw();
162 static OUString
getImplementationName_Static() throw();
166 virtual sal_Bool SAL_CALL
filter( const Sequence
< PropertyValue
>& aDescriptor
)
167 throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
168 virtual void SAL_CALL
cancel() throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
171 virtual void SAL_CALL
setTargetDocument( const Reference
< XComponent
>& xDoc
)
172 throw( IllegalArgumentException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
175 OUString SAL_CALL
getImplementationName() throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
176 Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
177 sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
179 //XExtendedFilterDetection
180 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
;
183 Reference
< XFilter
> rFilter
;
184 Reference
< XImporter
> rImporter
;
187 Reference
< XInterface
> HwpImportFilter_CreateInstance(
188 const Reference
< XMultiServiceFactory
>& rSMgr
) throw( Exception
)
190 HwpImportFilter
*p
= new HwpImportFilter( rSMgr
);
192 return Reference
< XInterface
> ( (OWeakObject
* )p
);
195 Sequence
< OUString
> HwpImportFilter::getSupportedServiceNames_Static() throw ()
197 Sequence
< OUString
> aRet(1);
198 aRet
.getArray()[0] = HwpImportFilter::getImplementationName_Static();
202 HwpImportFilter::HwpImportFilter(const Reference
< XMultiServiceFactory
>& rFact
)
204 OUString
sService( WRITER_IMPORTER_NAME
);
206 Reference
< XDocumentHandler
>
207 xHandler( rFact
->createInstance( sService
), UNO_QUERY
);
209 HwpReader
*p
= new HwpReader
;
210 p
->setDocumentHandler( xHandler
);
212 Reference
< XImporter
> xImporter
= Reference
< XImporter
>( xHandler
, UNO_QUERY
);
213 rImporter
= xImporter
;
214 Reference
< XFilter
> xFilter
= Reference
< XFilter
>( p
);
219 printf(" fail to instanciate %s\n", WRITER_IMPORTER_NAME
);
224 HwpImportFilter::~HwpImportFilter()
228 sal_Bool
HwpImportFilter::filter( const Sequence
< PropertyValue
>& aDescriptor
)
229 throw( RuntimeException
, std::exception
)
231 // delegate to IchitaroImpoter
232 return rFilter
->filter( aDescriptor
);
235 void HwpImportFilter::cancel() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
240 void HwpImportFilter::setTargetDocument( const Reference
< XComponent
>& xDoc
)
241 throw( IllegalArgumentException
, RuntimeException
, std::exception
)
244 rImporter
->setTargetDocument( xDoc
);
247 OUString
HwpImportFilter::getImplementationName_Static() throw()
249 return OUString( IMPLEMENTATION_NAME
);
252 OUString
HwpImportFilter::getImplementationName() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
254 return OUString( IMPLEMENTATION_NAME
);
257 sal_Bool
HwpImportFilter::supportsService( const OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
259 return cppu::supportsService(this, ServiceName
);
262 //XExtendedFilterDetection
263 OUString
HwpImportFilter::detect( ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& rDescriptor
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
267 utl::MediaDescriptor
aDescriptor(rDescriptor
);
268 aDescriptor
.addInputStream();
270 Reference
< XInputStream
> xInputStream(
271 aDescriptor
[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY
);
273 if (xInputStream
.is())
275 Sequence
< sal_Int8
> aData
;
276 sal_Int32 nLen
= HWPIDLen
;
278 nLen
== xInputStream
->readBytes(aData
, nLen
) &&
279 detect_hwp_version(reinterpret_cast<const char*>(aData
.getConstArray()))
282 sTypeName
= "writer_MIZI_Hwp_97";
289 Sequence
< OUString
> HwpImportFilter::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
291 Sequence
< OUString
> aRet(2);
292 OUString
* pArray
= aRet
.getArray();
293 pArray
[0] = SERVICE_NAME1
;
294 pArray
[1] = SERVICE_NAME2
;
300 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
hwp_component_getFactory( const sal_Char
* pImplName
, void * pServiceManager
, void * )
304 if (pServiceManager
)
306 Reference
< XSingleServiceFactory
> xRet
;
307 Reference
< XMultiServiceFactory
> xSMgr
= static_cast< XMultiServiceFactory
* > ( pServiceManager
);
309 OUString aImplementationName
= OUString::createFromAscii( pImplName
);
311 if (aImplementationName
== IMPLEMENTATION_NAME
)
313 xRet
= createSingleFactory( xSMgr
, aImplementationName
,
314 HwpImportFilter_CreateInstance
,
315 HwpImportFilter::getSupportedServiceNames_Static() );
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */