1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
57 #include "lwp9reader.hxx"
58 #include "lwpglobalmgr.hxx"
59 #include "lwparrowstyles.hxx"
60 #include "lwpobjhdr.hxx"
62 #include "xfilter/xfstylemanager.hxx"
63 #include "lwpdocdata.hxx"
64 #include "lwpbookmarkmgr.hxx"
65 #include "lwpchangemgr.hxx"
66 #include <tools/stream.hxx>
68 Lwp9Reader::Lwp9Reader (LwpSvStream
* pInputStream
, IXFStream
* pStream
)
69 : m_pDocStream(pInputStream
)
76 * @descr The entrance of Word Pro 9 import filter.
78 void Lwp9Reader::Read()
80 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance(m_pDocStream
);
83 m_pObjMgr
= pGlobal
->GetLwpObjFactory();
86 //Does not support Word Pro 96 and previous versions
87 if(LwpFileHeader::m_nFileRevision
>=0x000B)
95 LwpGlobalMgr::DeleteInstance();
98 LwpGlobalMgr::DeleteInstance();
102 * @descr Read the LWP7 object.
104 void Lwp9Reader::ReadFileHeader()
106 m_pDocStream
->Seek(LwpSvStream::LWP_STREAM_BASE
);
108 //Remember to initialize the LwpFileHeader::m_nFileRevision first.
109 LwpFileHeader::m_nFileRevision
= 0;
111 LwpObjectHeader objHdr
;
112 objHdr
.Read(*m_pDocStream
);
113 sal_Int64 pos
= m_pDocStream
->Tell();
114 m_LwpFileHdr
.Read(m_pDocStream
);
115 m_pDocStream
->Seek(pos
+objHdr
.GetSize());
120 * @descr Read the index objects at the end of the WordProData stream
122 void Lwp9Reader::ReadIndex()
124 sal_Int64 oldpos
= m_pDocStream
->Tell();
125 sal_uInt32 rootoffset
= m_LwpFileHdr
.GetRootIndexOffset();
126 m_pDocStream
->Seek(rootoffset
+ LwpSvStream::LWP_STREAM_BASE
);
127 m_pObjMgr
->ReadIndex(m_pDocStream
);
128 m_pDocStream
->Seek(oldpos
);
132 * @descr Read all objects
133 * This function is replaced by the read on demand model
134 * Reserverd for future use
136 void Lwp9Reader::DumpAllObjects()
138 sal_Int64 nFileSize
= GetFileSize();
139 sal_Int64 nFilePos
= m_pDocStream
->Tell();
143 LwpObjectHeader objHdr
;
144 objHdr
.Read(*m_pDocStream
);
145 nFilePos
= m_pDocStream
->Tell();
146 //Stop when reaching the index object
147 if(objHdr
.GetTag() >= VO_ROOTLEAFOBJINDEX
)
151 //Stop when the length exceeds the file length
152 if(nFilePos
+ objHdr
.GetSize() > nFileSize
)
157 m_pObjMgr
->CreateObject(objHdr
.GetTag(), objHdr
);
158 m_pDocStream
->Seek(nFilePos
+objHdr
.GetSize());
163 * @descr Get file size
165 sal_Int64
Lwp9Reader::GetFileSize()
167 sal_Int64 pos
= m_pDocStream
->Tell();
168 m_pDocStream
->Seek(0);
170 sal_Int64 size
= m_pDocStream
->Seek( STREAM_SEEK_TO_END
);
171 m_pDocStream
->Seek(pos
);
176 * @descr Parse all document content
178 void Lwp9Reader::ParseDocument()
183 LwpDocument
* doc
= dynamic_cast<LwpDocument
*> ( m_LwpFileHdr
.GetDocID().obj().get() );
189 LwpDocData
*pDocData
= dynamic_cast<LwpDocData
*>(doc
->GetDocData().obj().get());
191 pDocData
->Parse(m_pStream
);
194 RegisteArrowStyles();
195 doc
->RegisterStyle();
196 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
197 pXFStyleManager
->ToXml(m_pStream
);
199 //Parse document content
200 m_pStream
->GetAttrList()->Clear();
201 m_pStream
->StartElement( "office:body" );
203 //Parse change list, add by
204 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
205 LwpChangeMgr
* pChangeMgr
= pGlobal
->GetLwpChangeMgr();
206 pChangeMgr
->ConvertAllChange(m_pStream
);
208 doc
->Parse(m_pStream
);
209 m_pStream
->EndElement("office:body");
215 * @descr Write xml document header
217 void Lwp9Reader::WriteDocHeader()
219 m_pStream
->StartDocument();
221 IXFAttrList
*pAttrList
= m_pStream
->GetAttrList();
223 pAttrList
->AddAttribute( "xmlns:office", "http://openoffice.org/2000/office" );
224 pAttrList
->AddAttribute( "xmlns:style", "http://openoffice.org/2000/style" );
225 pAttrList
->AddAttribute( "xmlns:text", "http://openoffice.org/2000/text" );
226 pAttrList
->AddAttribute( "xmlns:table", "http://openoffice.org/2000/table" );
227 pAttrList
->AddAttribute( "xmlns:draw", "http://openoffice.org/2000/drawing" );
229 pAttrList
->AddAttribute( "xmlns:fo", "http://www.w3.org/1999/XSL/Format" );
230 pAttrList
->AddAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
231 pAttrList
->AddAttribute( "xmlns:number", "http://openoffice.org/2000/datastyle" );
232 pAttrList
->AddAttribute( "xmlns:svg", "http://www.w3.org/2000/svg" );
233 pAttrList
->AddAttribute( "xmlns:chart", "http://openoffice.org/2000/chart" );
235 pAttrList
->AddAttribute( "xmlns:dr3d", "http://openoffice.org/2000/dr3d" );
236 pAttrList
->AddAttribute( "xmlns:math", "http://www.w3.org/1998/Math/MathML" );
237 pAttrList
->AddAttribute( "xmlns:form", "http://openoffice.org/2000/form" );
238 pAttrList
->AddAttribute( "xmlns:script", "http://openoffice.org/2000/script" );
239 pAttrList
->AddAttribute( "xmlns:dc", "http://purl.org/dc/elements/1.1/" );
241 pAttrList
->AddAttribute( "xmlns:meta", "http://openoffice.org/2000/meta" );
242 pAttrList
->AddAttribute( "office:class", "text");
243 pAttrList
->AddAttribute( "office:version", "1.0");
245 m_pStream
->StartElement( "office:document" );
250 * @descr Write xml document end
252 void Lwp9Reader::WriteDocEnd()
254 m_pStream
->EndElement("office:document");
255 m_pStream
->EndDocument();
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */