bump product version to 4.1.6.2
[LibreOffice.git] / lotuswordpro / source / filter / lwp9reader.cxx
blob43e8a3430253afdb64b269b6129a0c2a76160827
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,
29 * MA 02111-1307 USA
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 ************************************************************************/
56 #include "lwp9reader.hxx"
57 #include "lwpglobalmgr.hxx"
58 #include "lwpunoheader.hxx"
59 #include "lwparrowstyles.hxx"
60 #include "lwpobjhdr.hxx"
61 #include "lwpdoc.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), m_pStream(pStream), m_LwpFileHdr()
72 /**
73 * @descr The entrance of Word Pro 9 import filter.
74 **/
75 void Lwp9Reader::Read()
77 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance(m_pDocStream);
78 try
80 m_pObjMgr = pGlobal->GetLwpObjFactory();
82 ReadFileHeader();
83 //Does not support Word Pro 96 and previous versions
84 if(LwpFileHeader::m_nFileRevision>=0x000B)
86 ReadIndex();
87 ParseDocument();
90 catch(...)
92 LwpGlobalMgr::DeleteInstance();
93 throw;
95 LwpGlobalMgr::DeleteInstance();
98 /**
99 * @descr Read the OLE objects.
101 void Lwp9Reader::ReadOleObjects()
105 * @descr Read the LWP7 object.
107 void Lwp9Reader::ReadFileHeader()
109 m_pDocStream->Seek(LwpSvStream::LWP_STREAM_BASE);
111 //Remember to initialize the LwpFileHeader::m_nFileRevision first.
112 LwpFileHeader::m_nFileRevision = 0;
114 LwpObjectHeader objHdr;
115 objHdr.Read(*m_pDocStream);
116 sal_Int64 pos = m_pDocStream->Tell();
117 m_LwpFileHdr.Read(m_pDocStream);
118 m_pDocStream->Seek(pos+objHdr.GetSize());
123 * @descr Read the index objects at the end of the WordProData stream
125 void Lwp9Reader::ReadIndex()
127 sal_Int64 oldpos = m_pDocStream->Tell();
128 sal_uInt32 rootoffset = m_LwpFileHdr.GetRootIndexOffset();
129 m_pDocStream->Seek(rootoffset + LwpSvStream::LWP_STREAM_BASE);
130 m_pObjMgr->ReadIndex(m_pDocStream);
131 m_pDocStream->Seek(oldpos);
135 * @descr Read all objects
136 * This function is replaced by the read on demand model
137 * Reserverd for future use
139 void Lwp9Reader::DumpAllObjects()
141 sal_Int64 nFileSize = GetFileSize();
142 sal_Int64 nFilePos = m_pDocStream->Tell();
144 while(true)
146 LwpObjectHeader objHdr;
147 objHdr.Read(*m_pDocStream);
148 nFilePos = m_pDocStream->Tell();
149 //Stop when reaching the index object
150 if(objHdr.GetTag() >= VO_ROOTLEAFOBJINDEX)
152 break;
154 //Stop when the length exceeds the file length
155 if(nFilePos + objHdr.GetSize() > nFileSize)
157 assert(false);
158 break;
160 m_pObjMgr->CreateObject(objHdr.GetTag(), objHdr);
161 m_pDocStream->Seek(nFilePos+objHdr.GetSize());
166 * @descr Get file size
168 sal_Int64 Lwp9Reader::GetFileSize()
170 sal_Int64 pos = m_pDocStream->Tell();
171 m_pDocStream->Seek(0);
173 sal_Int64 size = m_pDocStream->Seek( STREAM_SEEK_TO_END);
174 m_pDocStream->Seek(pos);
175 return(size);
179 * @descr Parse all document content
181 void Lwp9Reader::ParseDocument()
183 WriteDocHeader();
185 //Get root document
186 LwpDocument* doc = dynamic_cast<LwpDocument*> ( m_LwpFileHdr.GetDocID()->obj() );
188 if (!doc)
189 return;
191 //Parse Doc Data
192 LwpDocData *pDocData = dynamic_cast<LwpDocData*>((doc->GetDocData())->obj());
193 if (pDocData!=NULL)
194 pDocData->Parse(m_pStream);
196 //Register Styles
197 RegisteArrowStyles();
198 doc->RegisterStyle();
199 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
200 pXFStyleManager->ToXml(m_pStream);
202 //Parse document content
203 m_pStream->GetAttrList()->Clear();
204 m_pStream->StartElement( A2OUSTR("office:body") );
206 //Parse change list, add by
207 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
208 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
209 pChangeMgr->ConvertAllChange(m_pStream);
211 doc->Parse(m_pStream);
212 m_pStream->EndElement(OUString("office:body"));
214 WriteDocEnd();
218 * @descr Write xml document header
220 void Lwp9Reader::WriteDocHeader()
222 m_pStream->StartDocument();
224 IXFAttrList *pAttrList = m_pStream->GetAttrList();
226 pAttrList->AddAttribute( A2OUSTR("xmlns:office"), A2OUSTR("http://openoffice.org/2000/office") );
227 pAttrList->AddAttribute( A2OUSTR("xmlns:style"), A2OUSTR("http://openoffice.org/2000/style") );
228 pAttrList->AddAttribute( A2OUSTR("xmlns:text"), A2OUSTR("http://openoffice.org/2000/text") );
229 pAttrList->AddAttribute( A2OUSTR("xmlns:table"), A2OUSTR("http://openoffice.org/2000/table") );
230 pAttrList->AddAttribute( A2OUSTR("xmlns:draw"), A2OUSTR("http://openoffice.org/2000/drawing") );
232 pAttrList->AddAttribute( A2OUSTR("xmlns:fo"), A2OUSTR("http://www.w3.org/1999/XSL/Format") );
233 pAttrList->AddAttribute( A2OUSTR("xmlns:xlink"), A2OUSTR("http://www.w3.org/1999/xlink") );
234 pAttrList->AddAttribute( A2OUSTR("xmlns:number"), A2OUSTR("http://openoffice.org/2000/datastyle") );
235 pAttrList->AddAttribute( A2OUSTR("xmlns:svg"), A2OUSTR("http://www.w3.org/2000/svg") );
236 pAttrList->AddAttribute( A2OUSTR("xmlns:chart"), A2OUSTR("http://openoffice.org/2000/chart") );
238 pAttrList->AddAttribute( A2OUSTR("xmlns:dr3d"), A2OUSTR("http://openoffice.org/2000/dr3d") );
239 pAttrList->AddAttribute( A2OUSTR("xmlns:math"), A2OUSTR("http://www.w3.org/1998/Math/MathML") );
240 pAttrList->AddAttribute( A2OUSTR("xmlns:form"), A2OUSTR("http://openoffice.org/2000/form") );
241 pAttrList->AddAttribute( A2OUSTR("xmlns:script"), A2OUSTR("http://openoffice.org/2000/script") );
242 pAttrList->AddAttribute( A2OUSTR("xmlns:dc"), A2OUSTR("http://purl.org/dc/elements/1.1/") );
244 pAttrList->AddAttribute( A2OUSTR("xmlns:meta"), A2OUSTR("http://openoffice.org/2000/meta") );
245 pAttrList->AddAttribute( A2OUSTR("office:class"), A2OUSTR("text"));
246 pAttrList->AddAttribute( A2OUSTR("office:version"), A2OUSTR("1.0"));
248 m_pStream->StartElement( OUString("office:document") );
249 pAttrList->Clear();
253 * @descr Write xml document end
255 void Lwp9Reader::WriteDocEnd()
257 m_pStream->EndElement(OUString("office:document"));
258 m_pStream->EndDocument();
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */