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 <lwpchangemgr.hxx>
65 #include <sal/log.hxx>
67 Lwp9Reader::Lwp9Reader(LwpSvStream
* pInputStream
, IXFStream
* pStream
)
68 : m_pDocStream(pInputStream
)
75 * @descr The entrance of Word Pro 9 import filter.
77 bool Lwp9Reader::Read()
80 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance(m_pDocStream
);
83 m_pObjMgr
= pGlobal
->GetLwpObjFactory();
85 //Does not support Word Pro 96 and previous versions
86 if (ReadFileHeader() && LwpFileHeader::m_nFileRevision
>= 0x000B)
89 bRet
= ParseDocument();
93 SAL_WARN("lwp", "Only Lotus Word Pro 97 (version 11) and later is supported.");
94 SAL_WARN("lwp", "You are trying to open version: " << LwpFileHeader::m_nFileRevision
);
100 LwpGlobalMgr::DeleteInstance();
103 LwpGlobalMgr::DeleteInstance();
108 * @descr Read the LWP7 object.
110 bool Lwp9Reader::ReadFileHeader()
112 if (!m_pDocStream
->CheckSeek(LwpSvStream::LWP_STREAM_BASE
))
115 //Remember to initialize the LwpFileHeader::m_nFileRevision first.
116 LwpFileHeader::m_nFileRevision
= 0;
118 LwpObjectHeader objHdr
;
119 if (!objHdr
.Read(*m_pDocStream
))
122 sal_Int64 pos
= m_pDocStream
->Tell();
123 m_LwpFileHdr
.Read(m_pDocStream
);
124 return m_pDocStream
->CheckSeek(pos
+ objHdr
.GetSize());
128 * @descr Read the index objects at the end of the WordProData stream
130 void Lwp9Reader::ReadIndex()
132 sal_Int64 oldpos
= m_pDocStream
->Tell();
133 sal_uInt32 rootoffset
= m_LwpFileHdr
.GetRootIndexOffset();
134 m_pDocStream
->Seek(rootoffset
+ LwpSvStream::LWP_STREAM_BASE
);
135 m_pObjMgr
->ReadIndex(m_pDocStream
);
136 m_pDocStream
->Seek(oldpos
);
140 * @descr Parse all document content
142 bool Lwp9Reader::ParseDocument()
147 LwpDocument
* doc
= dynamic_cast<LwpDocument
*>(m_LwpFileHdr
.GetDocID().obj().get());
153 LwpDocData
* pDocData
= dynamic_cast<LwpDocData
*>(doc
->GetDocData().obj().get());
154 if (pDocData
!= nullptr)
155 pDocData
->Parse(m_pStream
);
158 RegisteArrowStyles();
159 doc
->DoRegisterStyle();
160 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
161 pXFStyleManager
->ToXml(m_pStream
);
163 //Parse document content
164 m_pStream
->GetAttrList()->Clear();
165 m_pStream
->StartElement(u
"office:body"_ustr
);
168 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
169 LwpChangeMgr
* pChangeMgr
= pGlobal
->GetLwpChangeMgr();
170 pChangeMgr
->ConvertAllChange(m_pStream
);
172 doc
->Parse(m_pStream
);
173 m_pStream
->EndElement(u
"office:body"_ustr
);
180 * @descr Write xml document header
182 void Lwp9Reader::WriteDocHeader()
184 m_pStream
->StartDocument();
186 IXFAttrList
* pAttrList
= m_pStream
->GetAttrList();
188 pAttrList
->AddAttribute(u
"xmlns:office"_ustr
, u
"http://openoffice.org/2000/office"_ustr
);
189 pAttrList
->AddAttribute(u
"xmlns:style"_ustr
, u
"http://openoffice.org/2000/style"_ustr
);
190 pAttrList
->AddAttribute(u
"xmlns:text"_ustr
, u
"http://openoffice.org/2000/text"_ustr
);
191 pAttrList
->AddAttribute(u
"xmlns:table"_ustr
, u
"http://openoffice.org/2000/table"_ustr
);
192 pAttrList
->AddAttribute(u
"xmlns:draw"_ustr
, u
"http://openoffice.org/2000/drawing"_ustr
);
194 pAttrList
->AddAttribute(u
"xmlns:fo"_ustr
, u
"http://www.w3.org/1999/XSL/Format"_ustr
);
195 pAttrList
->AddAttribute(u
"xmlns:xlink"_ustr
, u
"http://www.w3.org/1999/xlink"_ustr
);
196 pAttrList
->AddAttribute(u
"xmlns:number"_ustr
, u
"http://openoffice.org/2000/datastyle"_ustr
);
197 pAttrList
->AddAttribute(u
"xmlns:svg"_ustr
, u
"http://www.w3.org/2000/svg"_ustr
);
198 pAttrList
->AddAttribute(u
"xmlns:chart"_ustr
, u
"http://openoffice.org/2000/chart"_ustr
);
200 pAttrList
->AddAttribute(u
"xmlns:dr3d"_ustr
, u
"http://openoffice.org/2000/dr3d"_ustr
);
201 pAttrList
->AddAttribute(u
"xmlns:math"_ustr
, u
"http://www.w3.org/1998/Math/MathML"_ustr
);
202 pAttrList
->AddAttribute(u
"xmlns:form"_ustr
, u
"http://openoffice.org/2000/form"_ustr
);
203 pAttrList
->AddAttribute(u
"xmlns:script"_ustr
, u
"http://openoffice.org/2000/script"_ustr
);
204 pAttrList
->AddAttribute(u
"xmlns:dc"_ustr
, u
"http://purl.org/dc/elements/1.1/"_ustr
);
206 pAttrList
->AddAttribute(u
"xmlns:meta"_ustr
, u
"http://openoffice.org/2000/meta"_ustr
);
207 pAttrList
->AddAttribute(u
"office:class"_ustr
, u
"text"_ustr
);
208 pAttrList
->AddAttribute(u
"office:version"_ustr
, u
"1.0"_ustr
);
210 m_pStream
->StartElement(u
"office:document"_ustr
);
214 * @descr Write xml document end
216 void Lwp9Reader::WriteDocEnd()
218 m_pStream
->EndElement(u
"office:document"_ustr
);
219 m_pStream
->EndDocument();
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */