1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef _HWPREADER_HXX_
29 #define _HWPREADER_HXX_
33 #include <sal/alloca.h>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/lang/XComponent.hpp>
37 #include <com/sun/star/io/XInputStream.hpp>
38 #include <com/sun/star/document/XFilter.hpp>
39 #include <com/sun/star/document/XImporter.hpp>
40 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
42 #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
43 #include <com/sun/star/ucb/XContentProvider.hpp>
44 #include <com/sun/star/ucb/XContentIdentifier.hpp>
45 #include <com/sun/star/ucb/XContent.hpp>
46 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
47 #include <com/sun/star/ucb/OpenMode.hpp>
48 #include <com/sun/star/ucb/XCommandProcessor.hpp>
49 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
50 #include <cppuhelper/implbase2.hxx>
51 #include <com/sun/star/io/XActiveDataSink.hpp>
52 #include <com/sun/star/io/XActiveDataControl.hpp>
53 #include <com/sun/star/io/XStreamListener.hpp>
55 #include <cppuhelper/factory.hxx>
56 #include <cppuhelper/weak.hxx>
57 #include <cppuhelper/implbase1.hxx>
58 #include <cppuhelper/implbase3.hxx>
59 #include <cppuhelper/servicefactory.hxx>
61 using namespace ::rtl
;
62 using namespace ::cppu
;
63 using namespace ::com::sun::star::ucb
;
64 using namespace ::com::sun::star::lang
;
65 using namespace ::com::sun::star::uno
;
66 using namespace ::com::sun::star::io
;
67 using namespace ::com::sun::star::registry
;
68 using namespace ::com::sun::star::document
;
69 using namespace ::com::sun::star::beans
;
70 using namespace ::com::sun::star::xml::sax
;
80 #include "attributes.hxx"
83 #define IMPLEMENTATION_NAME "com.sun.comp.hwpimport.HwpImportFilter"
84 #define SERVICE_NAME "com.sun.star.document.ImportFilter"
85 #define WRITER_IMPORTER_NAME "com.sun.star.comp.Writer.XMLImporter"
87 class MyDataSink
: public ::cppu::WeakImplHelper2
< XActiveDataControl
, XActiveDataSink
>
89 Reference
< XInputStream
> m_xInputStream
;
92 // XActiveDataControl.
93 virtual void SAL_CALL
addListener ( const Reference
<XStreamListener
> &)
94 throw(RuntimeException
) {}
95 virtual void SAL_CALL
removeListener ( const Reference
<XStreamListener
> &)
96 throw(RuntimeException
) {}
97 virtual void SAL_CALL
start (void) throw(RuntimeException
) {}
98 virtual void SAL_CALL
terminate (void) throw(RuntimeException
) {}
101 virtual void SAL_CALL
setInputStream ( const Reference
<XInputStream
> &rxInputStream
)
102 throw(RuntimeException
);
103 virtual Reference
<XInputStream
> SAL_CALL
getInputStream (void)
104 throw(RuntimeException
);
107 void SAL_CALL
MyDataSink::setInputStream ( const Reference
<XInputStream
> &rxInputStream
)
108 throw(RuntimeException
)
110 m_xInputStream
= rxInputStream
;
113 Reference
< XInputStream
> SAL_CALL
MyDataSink::getInputStream (void)
114 throw(RuntimeException
)
116 return m_xInputStream
;
119 struct HwpReaderPrivate
;
121 * This class implements the external Parser interface
123 class HwpReader
: public WeakImplHelper1
<XFilter
>
132 * parseStream does Parser-startup initializations
134 virtual sal_Bool SAL_CALL
filter(const Sequence
< PropertyValue
>& aDescriptor
) throw (RuntimeException
);
135 virtual void SAL_CALL
cancel() throw(RuntimeException
) {}
136 virtual void SAL_CALL
setDocumentHandler(Reference
< XDocumentHandler
> xHandler
)
138 rDocumentHandler
= xHandler
;
140 void setUCB( Reference
< XInterface
> xUCB
){
144 Reference
< XDocumentHandler
> rDocumentHandler
;
145 Reference
< XInterface
> rUCB
;
146 Reference
< XAttributeList
> rList
;
147 AttributeListImpl
*pList
;
152 /* -------- Document Parsing --------- */
155 void makeDrawMiscStyle(HWPDrawingObject
*);
156 void makeAutoStyles();
157 void makeMasterStyles();
160 void makeTextDecls();
162 /* -------- Paragraph Parsing --------- */
163 void parsePara(HWPPara
*para
, sal_Bool bParaStart
= sal_False
);
164 void make_text_p0(HWPPara
*para
, sal_Bool bParaStart
= sal_False
);
165 void make_text_p1(HWPPara
*para
, sal_Bool bParaStart
= sal_False
);
166 void make_text_p3(HWPPara
*para
, sal_Bool bParaStart
= sal_False
);
168 /* -------- rDocument->characters(x) --------- */
169 void makeChars(hchar
*, int);
171 /* -------- Special Char Parsing --------- */
172 void makeFieldCode(FieldCode
*hbox
); //6
173 void makeBookmark(Bookmark
*hbox
); //6
174 void makeDateFormat(DateCode
*hbox
); //7
175 void makeDateCode(DateCode
*hbox
); //8
176 void makeTab(Tab
*hbox
); //9
177 void makeTable(TxtBox
*hbox
);
178 void makeTextBox(TxtBox
*hbox
);
179 void makeFormula(TxtBox
*hbox
);
180 void makeHyperText(TxtBox
*hbox
);
181 void makePicture(Picture
*hbox
);
182 void makePictureDRAW(HWPDrawingObject
*drawobj
, Picture
*hbox
);
183 void makeLine(Line
*hbox
);
184 void makeHidden(Hidden
*hbox
);
185 void makeFootnote(Footnote
*hbox
);
186 void makeAutoNum(AutoNum
*hbox
);
187 void makeShowPageNum();
188 void makeMailMerge(MailMerge
*hbox
);
189 void makeTocMark(TocMark
*hbox
);
190 void makeIndexMark(IndexMark
*hbox
);
191 void makeOutline(Outline
*hbox
);
193 /* --------- Styles Parsing ------------ */
194 void makePageStyle();
195 void makeColumns(ColumnDef
*);
196 void makeTStyle(CharShape
*);
197 void makePStyle(ParaShape
*);
198 void makeFStyle(FBoxStyle
*);
199 void makeCaptionStyle(FBoxStyle
*);
200 void makeDrawStyle(HWPDrawingObject
*,FBoxStyle
*);
201 void makeTableStyle(Table
*);
202 void parseCharShape(CharShape
*);
203 void parseParaShape(ParaShape
*);
204 char* getTStyleName(int, char *);
205 char* getPStyleName(int, char *);
208 class HwpImportFilter
: public WeakImplHelper3
< XFilter
, XImporter
, XServiceInfo
>
211 HwpImportFilter( const Reference
< XMultiServiceFactory
> xFact
);
215 static Sequence
< OUString
> getSupportedServiceNames_Static( void ) throw();
216 static OUString
getImplementationName_Static() throw();
220 virtual sal_Bool SAL_CALL
filter( const Sequence
< PropertyValue
>& aDescriptor
)
221 throw( RuntimeException
);
222 virtual void SAL_CALL
cancel() throw(RuntimeException
);
224 virtual void SAL_CALL
setTargetDocument( const Reference
< XComponent
>& xDoc
)
225 throw( IllegalArgumentException
, RuntimeException
);
227 OUString SAL_CALL
getImplementationName() throw (RuntimeException
);
228 Sequence
< OUString
> SAL_CALL
getSupportedServiceNames(void) throw (::com::sun::star::uno::RuntimeException
);
229 sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
);
232 Reference
< XFilter
> rFilter
;
233 Reference
< XImporter
> rImporter
;
236 Reference
< XInterface
> HwpImportFilter_CreateInstance(
237 const Reference
< XMultiServiceFactory
>& rSMgr
) throw( Exception
)
239 HwpImportFilter
*p
= new HwpImportFilter( rSMgr
);
241 return Reference
< XInterface
> ( (OWeakObject
* )p
);
244 Sequence
< OUString
> HwpImportFilter::getSupportedServiceNames_Static( void ) throw ()
246 Sequence
< OUString
> aRet(1);
247 aRet
.getArray()[0] = HwpImportFilter::getImplementationName_Static();
250 HwpImportFilter::HwpImportFilter( const Reference
< XMultiServiceFactory
> xFact
)
252 OUString sService
= OUString::createFromAscii( WRITER_IMPORTER_NAME
);
254 Reference
< XDocumentHandler
>
255 xHandler( xFact
->createInstance( sService
), UNO_QUERY
);
257 HwpReader
*p
= new HwpReader
;
258 p
->setDocumentHandler( xHandler
);
260 Sequence
< Any
> aArgs( 2 );
261 aArgs
[0] <<= OUString::createFromAscii( "Local" );
262 aArgs
[1] <<= OUString::createFromAscii( "Office" );
263 Reference
< XInterface
> xUCB
264 ( xFact
->createInstanceWithArguments
265 (OUString::createFromAscii("com.sun.star.ucb.UniversalContentBroker"),
270 Reference
< XImporter
> xImporter
= Reference
< XImporter
>( xHandler
, UNO_QUERY
);
271 rImporter
= xImporter
;
272 Reference
< XFilter
> xFilter
= Reference
< XFilter
>( p
);
277 printf(" fail to instanciate %s\n", WRITER_IMPORTER_NAME
);
282 HwpImportFilter::~HwpImportFilter()
286 sal_Bool
HwpImportFilter::filter( const Sequence
< PropertyValue
>& aDescriptor
)
287 throw( RuntimeException
)
289 // delegate to IchitaroImpoter
290 rFilter
->filter( aDescriptor
);
295 void HwpImportFilter::cancel() throw(::com::sun::star::uno::RuntimeException
)
300 void HwpImportFilter::setTargetDocument( const Reference
< XComponent
>& xDoc
)
301 throw( IllegalArgumentException
, RuntimeException
)
304 rImporter
->setTargetDocument( xDoc
);
307 OUString
HwpImportFilter::getImplementationName_Static() throw()
309 return OUString::createFromAscii( IMPLEMENTATION_NAME
);
312 OUString
HwpImportFilter::getImplementationName() throw(::com::sun::star::uno::RuntimeException
)
314 return OUString::createFromAscii( IMPLEMENTATION_NAME
);
316 sal_Bool
HwpImportFilter::supportsService( const OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
)
318 Sequence
< OUString
> aSNL
= getSupportedServiceNames();
319 const OUString
*pArray
= aSNL
.getConstArray();
321 for ( sal_Int32 i
= 0; i
< aSNL
.getLength(); i
++ )
322 if ( pArray
[i
] == ServiceName
)
328 Sequence
< OUString
> HwpImportFilter::getSupportedServiceNames( void ) throw(::com::sun::star::uno::RuntimeException
)
330 Sequence
< OUString
> seq(1);
331 seq
.getArray()[0] = OUString::createFromAscii( SERVICE_NAME
);
335 /////////////////////////////////////////////////////////////////////////////////////
336 // The below three C functions are nessesary for this shared library is treaded as
337 // UNO component library.
338 /////////////////////////////////////////////////////////////////////////////////////
342 void SAL_CALL
component_getImplementationEnvironment(
343 const sal_Char
** ppEnvTypeName
, uno_Environment
** )
345 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
348 void * SAL_CALL
component_getFactory( const sal_Char
* pImplName
, void * pServiceManager
, void * )
352 if (pServiceManager
)
354 Reference
< XSingleServiceFactory
> xRet
;
355 Reference
< XMultiServiceFactory
> xSMgr
= reinterpret_cast< XMultiServiceFactory
* > ( pServiceManager
);
357 OUString aImplementationName
= OUString::createFromAscii( pImplName
);
359 if (aImplementationName
== OUString::createFromAscii( IMPLEMENTATION_NAME
) )
361 xRet
= createSingleFactory( xSMgr
, aImplementationName
,
362 HwpImportFilter_CreateInstance
,
363 HwpImportFilter::getSupportedServiceNames_Static() );