1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 #ifndef _LWP9READER_HXX
56 #include "lwp9reader.hxx"
58 #include "lwpglobalmgr.hxx"
59 #include "lwpunoheader.hxx"
60 #include "lwparrowstyles.hxx"
61 #include "lwpobjhdr.hxx"
63 #include "xfilter/xfstylemanager.hxx"
64 #include "lwpdocdata.hxx"
65 #include "lwpbookmarkmgr.hxx"
66 #include "lwpchangemgr.hxx"
67 #include <tools/stream.hxx>
69 Lwp9Reader::Lwp9Reader (LwpSvStream
* pInputStream
, IXFStream
* pStream
)
70 : m_pDocStream(pInputStream
), m_pStream(pStream
), m_LwpFileHdr()
74 * @descr The entrance of Word Pro 9 import filter.
76 void Lwp9Reader::Read()
78 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance(m_pDocStream
);
79 m_pObjMgr
= pGlobal
->GetLwpObjFactory();
81 //Commented out by , 10/26/2005
82 //Read Ole object in LwpOleObject::XFConverter to support Ole in Linux
86 //Does not support Word Pro 96 and previous versions
87 if(LwpFileHeader::m_nFileRevision
>=0x000B)
92 LwpGlobalMgr::DeleteInstance();
96 * @descr Read the OLE objects.
98 void Lwp9Reader::ReadOleObjects()
104 // Get the buffer of the whole file
105 LwpSvStream
* pRawStream
= m_pDocStream
;
106 sal_Int64 nCurPos
= pRawStream
->Tell();
107 sal_uInt32 nSize
= static_cast<sal_uInt32
>(pRawStream
->Seek(STREAM_SEEK_TO_END
));
108 BYTE
* pBuf
= new BYTE
[nSize
];
110 if(pBuf
== NULL
) // this buffer may be too big
115 pRawStream
->Seek(STREAM_SEEK_TO_BEGIN
);
116 pRawStream
->Read(pBuf
,nSize
);
117 pRawStream
->Seek(nCurPos
);
119 // Break the buffer into separate objects by ASWAN lib
122 CBenStorageConverter benConverter
;
123 benConverter
.Convert(pBuf
, nSize
, (void**)&pOut
, &nWritten
);
128 SvStream
* pMemStream
= new SvMemoryStream(pOut
, nWritten
, STREAM_READ
|STREAM_WRITE
);
129 SvStorageRef objStor
= new SvStorage(pMemStream
, true); // set true to let SvStorage free the memstream.
130 m_pObjMgr
->SetOleObjInfo(objStor
);
138 * @descr Read the LWP7 object.
140 void Lwp9Reader::ReadFileHeader()
142 m_pDocStream
->Seek(LwpSvStream::LWP_STREAM_BASE
);
144 //Remember to initialize the LwpFileHeader::m_nFileRevision first.
145 LwpFileHeader::m_nFileRevision
= 0;
147 LwpObjectHeader objHdr
;
148 objHdr
.Read(*m_pDocStream
);
149 sal_Int64 pos
= m_pDocStream
->Tell();
150 m_LwpFileHdr
.Read(m_pDocStream
);
151 m_pDocStream
->Seek(pos
+objHdr
.GetSize());
156 * @descr Read the index objects at the end of the WordProData stream
158 void Lwp9Reader::ReadIndex()
160 sal_Int64 oldpos
= m_pDocStream
->Tell();
161 sal_uInt32 rootoffset
= m_LwpFileHdr
.GetRootIndexOffset();
162 m_pDocStream
->Seek(rootoffset
+ LwpSvStream::LWP_STREAM_BASE
);
163 m_pObjMgr
->ReadIndex(m_pDocStream
);
164 m_pDocStream
->Seek(oldpos
);
168 * @descr Read all objects
169 * This function is replaced by the read on demand model
170 * Reserverd for future use
172 void Lwp9Reader::DumpAllObjects()
174 sal_Int64 nFileSize
= GetFileSize();
175 sal_Int64 nFilePos
= m_pDocStream
->Tell();
179 LwpObjectHeader objHdr
;
180 objHdr
.Read(*m_pDocStream
);
181 nFilePos
= m_pDocStream
->Tell();
182 //Stop when reaching the index object
183 if(objHdr
.GetTag() >= VO_ROOTLEAFOBJINDEX
)
187 //Stop when the length exceeds the file length
188 if(nFilePos
+ objHdr
.GetSize() > nFileSize
)
193 m_pObjMgr
->CreateObject(objHdr
.GetTag(), objHdr
);
194 m_pDocStream
->Seek(nFilePos
+objHdr
.GetSize());
199 * @descr Get file size
201 sal_Int64
Lwp9Reader::GetFileSize()
203 sal_Int64 pos
= m_pDocStream
->Tell();
204 m_pDocStream
->Seek(0);
206 sal_Int64 size
= m_pDocStream
->Seek( STREAM_SEEK_TO_END
);
207 m_pDocStream
->Seek(pos
);
212 * @descr Parse all document content
214 void Lwp9Reader::ParseDocument()
219 LwpDocument
* doc
= static_cast<LwpDocument
*> ( m_LwpFileHdr
.GetDocID()->obj() );
222 LwpDocData
*pDocData
= static_cast<LwpDocData
*>((doc
->GetDocData())->obj());
225 pDocData
->Parse(m_pStream
);
229 RegisteArrowStyles();
230 doc
->RegisterStyle();
231 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
232 pXFStyleManager
->ToXml(m_pStream
);
234 //Parse document content
235 m_pStream
->GetAttrList()->Clear();
236 m_pStream
->StartElement( A2OUSTR("office:body") );
238 //Parse change list, add by
239 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
240 LwpChangeMgr
* pChangeMgr
= pGlobal
->GetLwpChangeMgr();
241 pChangeMgr
->ConvertAllChange(m_pStream
);
243 doc
->Parse(m_pStream
);
244 m_pStream
->EndElement(::rtl::OUString::createFromAscii("office:body"));
250 * @descr Write xml document header
252 void Lwp9Reader::WriteDocHeader()
254 m_pStream
->StartDocument();
256 IXFAttrList
*pAttrList
= m_pStream
->GetAttrList();
258 pAttrList
->AddAttribute( A2OUSTR("xmlns:office"), A2OUSTR("http://openoffice.org/2000/office") );
259 pAttrList
->AddAttribute( A2OUSTR("xmlns:style"), A2OUSTR("http://openoffice.org/2000/style") );
260 pAttrList
->AddAttribute( A2OUSTR("xmlns:text"), A2OUSTR("http://openoffice.org/2000/text") );
261 pAttrList
->AddAttribute( A2OUSTR("xmlns:table"), A2OUSTR("http://openoffice.org/2000/table") );
262 pAttrList
->AddAttribute( A2OUSTR("xmlns:draw"), A2OUSTR("http://openoffice.org/2000/drawing") );
264 pAttrList
->AddAttribute( A2OUSTR("xmlns:fo"), A2OUSTR("http://www.w3.org/1999/XSL/Format") );
265 pAttrList
->AddAttribute( A2OUSTR("xmlns:xlink"), A2OUSTR("http://www.w3.org/1999/xlink") );
266 pAttrList
->AddAttribute( A2OUSTR("xmlns:number"), A2OUSTR("http://openoffice.org/2000/datastyle") );
267 pAttrList
->AddAttribute( A2OUSTR("xmlns:svg"), A2OUSTR("http://www.w3.org/2000/svg") );
268 pAttrList
->AddAttribute( A2OUSTR("xmlns:chart"), A2OUSTR("http://openoffice.org/2000/chart") );
270 pAttrList
->AddAttribute( A2OUSTR("xmlns:dr3d"), A2OUSTR("http://openoffice.org/2000/dr3d") );
271 pAttrList
->AddAttribute( A2OUSTR("xmlns:math"), A2OUSTR("http://www.w3.org/1998/Math/MathML") );
272 pAttrList
->AddAttribute( A2OUSTR("xmlns:form"), A2OUSTR("http://openoffice.org/2000/form") );
273 pAttrList
->AddAttribute( A2OUSTR("xmlns:script"), A2OUSTR("http://openoffice.org/2000/script") );
274 pAttrList
->AddAttribute( A2OUSTR("xmlns:dc"), A2OUSTR("http://purl.org/dc/elements/1.1/") );
276 pAttrList
->AddAttribute( A2OUSTR("xmlns:meta"), A2OUSTR("http://openoffice.org/2000/meta") );
277 pAttrList
->AddAttribute( A2OUSTR("office:class"), A2OUSTR("text"));
278 pAttrList
->AddAttribute( A2OUSTR("office:version"), A2OUSTR("1.0"));
280 m_pStream
->StartElement( ::rtl::OUString::createFromAscii("office:document") );
285 * @descr Write xml document end
287 void Lwp9Reader::WriteDocEnd()
289 m_pStream
->EndElement(::rtl::OUString::createFromAscii("office:document"));
290 m_pStream
->EndDocument();