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 _HWPREADER_HXX_
21 #define _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 <cppuhelper/implbase2.hxx>
35 #include <com/sun/star/io/XActiveDataSink.hpp>
36 #include <com/sun/star/io/XActiveDataControl.hpp>
37 #include <com/sun/star/io/XStreamListener.hpp>
38 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
40 #include <cppuhelper/factory.hxx>
41 #include <cppuhelper/weak.hxx>
42 #include <cppuhelper/implbase1.hxx>
43 #include <cppuhelper/implbase4.hxx>
45 using namespace ::rtl
;
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 <comphelper/mediadescriptor.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
);
88 virtual void SAL_CALL
cancel() throw(RuntimeException
) {}
89 virtual 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
, sal_Bool bParaStart
= sal_False
);
112 void make_text_p0(HWPPara
*para
, sal_Bool bParaStart
= sal_False
);
113 void make_text_p1(HWPPara
*para
, sal_Bool bParaStart
= sal_False
);
114 void make_text_p3(HWPPara
*para
, sal_Bool bParaStart
= sal_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 makeTocMark(TocMark
*hbox
);
138 void makeIndexMark(IndexMark
*hbox
);
139 void makeOutline(Outline
*hbox
);
141 /* --------- Styles Parsing ------------ */
142 void makePageStyle();
143 void makeColumns(ColumnDef
*);
144 void makeTStyle(CharShape
*);
145 void makePStyle(ParaShape
*);
146 void makeFStyle(FBoxStyle
*);
147 void makeCaptionStyle(FBoxStyle
*);
148 void makeDrawStyle(HWPDrawingObject
*,FBoxStyle
*);
149 void makeTableStyle(Table
*);
150 void parseCharShape(CharShape
*);
151 void parseParaShape(ParaShape
*);
152 char* getTStyleName(int, char *);
153 char* getPStyleName(int, char *);
156 class HwpImportFilter
: public WeakImplHelper4
< XFilter
, XImporter
, XServiceInfo
, XExtendedFilterDetection
>
159 HwpImportFilter( const Reference
< XMultiServiceFactory
> xFact
);
163 static Sequence
< OUString
> getSupportedServiceNames_Static() throw();
164 static OUString
getImplementationName_Static() throw();
168 virtual sal_Bool SAL_CALL
filter( const Sequence
< PropertyValue
>& aDescriptor
)
169 throw( RuntimeException
);
170 virtual void SAL_CALL
cancel() throw(RuntimeException
);
173 virtual void SAL_CALL
setTargetDocument( const Reference
< XComponent
>& xDoc
)
174 throw( IllegalArgumentException
, RuntimeException
);
177 OUString SAL_CALL
getImplementationName() throw (RuntimeException
);
178 Sequence
< OUString
> SAL_CALL
getSupportedServiceNames(void) throw (::com::sun::star::uno::RuntimeException
);
179 sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
);
181 //XExtendedFilterDetection
182 virtual OUString SAL_CALL
detect( ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& rDescriptor
) throw (::com::sun::star::uno::RuntimeException
);
185 Reference
< XFilter
> rFilter
;
186 Reference
< XImporter
> rImporter
;
189 Reference
< XInterface
> HwpImportFilter_CreateInstance(
190 const Reference
< XMultiServiceFactory
>& rSMgr
) throw( Exception
)
192 HwpImportFilter
*p
= new HwpImportFilter( rSMgr
);
194 return Reference
< XInterface
> ( (OWeakObject
* )p
);
197 Sequence
< OUString
> HwpImportFilter::getSupportedServiceNames_Static() throw ()
199 Sequence
< OUString
> aRet(1);
200 aRet
.getArray()[0] = HwpImportFilter::getImplementationName_Static();
204 HwpImportFilter::HwpImportFilter( const Reference
< XMultiServiceFactory
> xFact
)
206 OUString
sService( WRITER_IMPORTER_NAME
);
208 Reference
< XDocumentHandler
>
209 xHandler( xFact
->createInstance( sService
), UNO_QUERY
);
211 HwpReader
*p
= new HwpReader
;
212 p
->setDocumentHandler( xHandler
);
214 Reference
< XImporter
> xImporter
= Reference
< XImporter
>( xHandler
, UNO_QUERY
);
215 rImporter
= xImporter
;
216 Reference
< XFilter
> xFilter
= Reference
< XFilter
>( p
);
221 printf(" fail to instanciate %s\n", WRITER_IMPORTER_NAME
);
226 HwpImportFilter::~HwpImportFilter()
230 sal_Bool
HwpImportFilter::filter( const Sequence
< PropertyValue
>& aDescriptor
)
231 throw( RuntimeException
)
233 // delegate to IchitaroImpoter
234 return rFilter
->filter( aDescriptor
);
237 void HwpImportFilter::cancel() throw(::com::sun::star::uno::RuntimeException
)
242 void HwpImportFilter::setTargetDocument( const Reference
< XComponent
>& xDoc
)
243 throw( IllegalArgumentException
, RuntimeException
)
246 rImporter
->setTargetDocument( xDoc
);
249 OUString
HwpImportFilter::getImplementationName_Static() throw()
251 return OUString( IMPLEMENTATION_NAME
);
254 OUString
HwpImportFilter::getImplementationName() throw(::com::sun::star::uno::RuntimeException
)
256 return OUString( IMPLEMENTATION_NAME
);
259 sal_Bool
HwpImportFilter::supportsService( const OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
)
261 Sequence
< OUString
> aSNL
= getSupportedServiceNames();
262 const OUString
*pArray
= aSNL
.getConstArray();
264 for ( sal_Int32 i
= 0; i
< aSNL
.getLength(); i
++ )
265 if ( pArray
[i
] == ServiceName
)
271 //XExtendedFilterDetection
272 OUString
HwpImportFilter::detect( ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& rDescriptor
) throw (::com::sun::star::uno::RuntimeException
)
276 comphelper::MediaDescriptor
aDescriptor(rDescriptor
);
277 aDescriptor
.addInputStream();
279 Reference
< XInputStream
> xInputStream(
280 aDescriptor
[comphelper::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY
);
282 if (xInputStream
.is())
284 Sequence
< sal_Int8
> aData
;
285 sal_Int32 nLen
= HWPIDLen
;
287 nLen
== xInputStream
->readBytes(aData
, nLen
) &&
288 detect_hwp_version(reinterpret_cast<const char*>(aData
.getConstArray()))
291 sTypeName
= OUString("writer_MIZI_Hwp_97");
298 Sequence
< OUString
> HwpImportFilter::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException
)
300 Sequence
< OUString
> aRet(2);
301 OUString
* pArray
= aRet
.getArray();
302 pArray
[0] = OUString(SERVICE_NAME1
);
303 pArray
[1] = OUString(SERVICE_NAME2
);
309 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
hwp_component_getFactory( const sal_Char
* pImplName
, void * pServiceManager
, void * )
313 if (pServiceManager
)
315 Reference
< XSingleServiceFactory
> xRet
;
316 Reference
< XMultiServiceFactory
> xSMgr
= reinterpret_cast< XMultiServiceFactory
* > ( pServiceManager
);
318 OUString aImplementationName
= OUString::createFromAscii( pImplName
);
320 if (aImplementationName
== IMPLEMENTATION_NAME
)
322 xRet
= createSingleFactory( xSMgr
, aImplementationName
,
323 HwpImportFilter_CreateInstance
,
324 HwpImportFilter::getSupportedServiceNames_Static() );
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */