LibreOffice Module lotuswordpro (master) 1
lwp9reader.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
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
16 *
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.
20 *
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.
25 *
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,
29 * MA 02111-1307 USA
30 *
31 *
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.
38 *
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.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56
57#include "lwp9reader.hxx"
58#include <lwpglobalmgr.hxx>
59#include "lwparrowstyles.hxx"
60#include <lwpobjhdr.hxx>
61#include "lwpdoc.hxx"
63#include <lwpdocdata.hxx>
64#include <lwpchangemgr.hxx>
65#include <sal/log.hxx>
66
68 : m_pDocStream(pInputStream)
69 , m_pStream(pStream)
70 , m_pObjMgr(nullptr)
71{
72}
73
78{
79 bool bRet = true;
81 try
82 {
83 m_pObjMgr = pGlobal->GetLwpObjFactory();
84
85 //Does not support Word Pro 96 and previous versions
87 {
88 ReadIndex();
89 bRet = ParseDocument();
90 }
91 else
92 {
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);
95 bRet = false;
96 }
97 }
98 catch (...)
99 {
101 throw;
102 }
104 return bRet;
105}
106
111{
113 return false;
114
115 //Remember to initialize the LwpFileHeader::m_nFileRevision first.
117
118 LwpObjectHeader objHdr;
119 if (!objHdr.Read(*m_pDocStream))
120 return false;
121
122 sal_Int64 pos = m_pDocStream->Tell();
124 return m_pDocStream->CheckSeek(pos + objHdr.GetSize());
125}
126
131{
132 sal_Int64 oldpos = m_pDocStream->Tell();
133 sal_uInt32 rootoffset = m_LwpFileHdr.GetRootIndexOffset();
136 m_pDocStream->Seek(oldpos);
137}
138
143{
145
146 //Get root document
147 LwpDocument* doc = dynamic_cast<LwpDocument*>(m_LwpFileHdr.GetDocID().obj().get());
148
149 if (!doc)
150 return false;
151
152 //Parse Doc Data
153 LwpDocData* pDocData = dynamic_cast<LwpDocData*>(doc->GetDocData().obj().get());
154 if (pDocData != nullptr)
155 pDocData->Parse(m_pStream);
156
157 //Register Styles
159 doc->DoRegisterStyle();
161 pXFStyleManager->ToXml(m_pStream);
162
163 //Parse document content
165 m_pStream->StartElement("office:body");
166
167 //Parse change list
169 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
170 pChangeMgr->ConvertAllChange(m_pStream);
171
172 doc->Parse(m_pStream);
173 m_pStream->EndElement("office:body");
174
175 WriteDocEnd();
176 return true;
177}
178
183{
185
186 IXFAttrList* pAttrList = m_pStream->GetAttrList();
187
188 pAttrList->AddAttribute("xmlns:office", "http://openoffice.org/2000/office");
189 pAttrList->AddAttribute("xmlns:style", "http://openoffice.org/2000/style");
190 pAttrList->AddAttribute("xmlns:text", "http://openoffice.org/2000/text");
191 pAttrList->AddAttribute("xmlns:table", "http://openoffice.org/2000/table");
192 pAttrList->AddAttribute("xmlns:draw", "http://openoffice.org/2000/drawing");
193
194 pAttrList->AddAttribute("xmlns:fo", "http://www.w3.org/1999/XSL/Format");
195 pAttrList->AddAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
196 pAttrList->AddAttribute("xmlns:number", "http://openoffice.org/2000/datastyle");
197 pAttrList->AddAttribute("xmlns:svg", "http://www.w3.org/2000/svg");
198 pAttrList->AddAttribute("xmlns:chart", "http://openoffice.org/2000/chart");
199
200 pAttrList->AddAttribute("xmlns:dr3d", "http://openoffice.org/2000/dr3d");
201 pAttrList->AddAttribute("xmlns:math", "http://www.w3.org/1998/Math/MathML");
202 pAttrList->AddAttribute("xmlns:form", "http://openoffice.org/2000/form");
203 pAttrList->AddAttribute("xmlns:script", "http://openoffice.org/2000/script");
204 pAttrList->AddAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
205
206 pAttrList->AddAttribute("xmlns:meta", "http://openoffice.org/2000/meta");
207 pAttrList->AddAttribute("office:class", "text");
208 pAttrList->AddAttribute("office:version", "1.0");
209
210 m_pStream->StartElement("office:document");
211 pAttrList->Clear();
212}
217{
218 m_pStream->EndElement("office:document");
220}
221
222/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Attribute list interface for sax writer.
Definition: ixfattrlist.hxx:72
virtual void Clear()=0
@descr: Clear all the attributes in the attribute list.
virtual void AddAttribute(const OUString &name, const OUString &value)=0
@descr: Add an attribute to the attribute list.
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
virtual void StartDocument()=0
@descr Called when start write.Usually you can output document type info and xml encoding info.
virtual IXFAttrList * GetAttrList()=0
@descr return the Attribute list interface.
virtual void StartElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::startElement()
virtual void EndDocument()=0
@descr called when end output.
virtual void EndElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::endElement()
IXFStream * m_pStream
Definition: lwp9reader.hxx:75
void WriteDocHeader()
@descr Write xml document header
Definition: lwp9reader.cxx:182
bool Read()
@descr The entrance of Word Pro 9 import filter.
Definition: lwp9reader.cxx:77
LwpFileHeader m_LwpFileHdr
Definition: lwp9reader.hxx:77
LwpObjectFactory * m_pObjMgr
Definition: lwp9reader.hxx:76
bool ReadFileHeader()
@descr Read the LWP7 object.
Definition: lwp9reader.cxx:110
void WriteDocEnd()
@descr Write xml document end
Definition: lwp9reader.cxx:216
void ReadIndex()
@descr Read the index objects at the end of the WordProData stream
Definition: lwp9reader.cxx:130
Lwp9Reader(LwpSvStream *InputStream, IXFStream *pStream)
Definition: lwp9reader.cxx:67
LwpSvStream * m_pDocStream
Definition: lwp9reader.hxx:74
bool ParseDocument()
@descr Parse all document content
Definition: lwp9reader.cxx:142
void ConvertAllChange(IXFStream *pStream)
void Parse(IXFStream *pOutputStream) override
@descr default parse function
Definition: lwpdocdata.cxx:309
Document object, represent document and division.
Definition: lwpdoc.hxx:76
LwpObjectID & GetDocData()
Definition: lwpdoc.hxx:186
void Parse(IXFStream *pOutputStream) override
@descr Parse obj to IXFStream
Definition: lwpdoc.cxx:152
sal_uInt32 GetRootIndexOffset() const
Definition: lwpfilehdr.hxx:82
static sal_uInt16 m_nFileRevision
Definition: lwpfilehdr.hxx:77
LwpObjectID & GetDocID()
Definition: lwpfilehdr.hxx:83
void Read(LwpSvStream *pStrm)
@descr read file header object from svstream
Definition: lwpfilehdr.cxx:73
XFStyleManager * GetXFStyleManager()
LwpChangeMgr * GetLwpChangeMgr()
static void DeleteInstance()
static LwpGlobalMgr * GetInstance(LwpSvStream *pSvStream=nullptr)
LwpObjectFactory * GetLwpObjFactory()
void ReadIndex(LwpSvStream *pStrm)
@descr read the index manager
Base class of all Lwp VO objects.
Definition: lwpobjhdr.hxx:71
bool Read(LwpSvStream &pStrm)
@descr read header from stream
Definition: lwpobjhdr.cxx:74
sal_uInt32 GetSize() const
Definition: lwpobjhdr.hxx:122
rtl::Reference< LwpObject > obj(VO_TYPE tag=VO_INVALID) const
@descr get object from object factory per the object id
Definition: lwpobjid.cxx:183
void DoRegisterStyle()
Definition: lwpobj.hxx:107
encapsulate XInputStream to provide SvStream like interfaces
Definition: lwpsvstream.hxx:69
bool CheckSeek(sal_Int64 pos)
static const sal_uInt32 LWP_STREAM_BASE
Definition: lwpsvstream.hxx:84
sal_Int64 Seek(sal_Int64 pos)
@descr Seek to pos
sal_Int64 Tell()
@descr Get the current position in stream
Style manager for the filter.
void ToXml(IXFStream *strm)
GtkMediaStream * m_pStream
#define SAL_WARN(area, stream)
void RegisteArrowStyles()
@descr Register arrow styles that are not directly support by SODC.
size_t pos