Branch data Line data Source code
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 : : #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>
67 : :
68 : 18 : Lwp9Reader::Lwp9Reader (LwpSvStream* pInputStream, IXFStream* pStream)
69 : 18 : : m_pDocStream(pInputStream), m_pStream(pStream), m_LwpFileHdr()
70 : 18 : {}
71 : :
72 : : /**
73 : : * @descr The entrance of Word Pro 9 import filter.
74 : : **/
75 : 18 : void Lwp9Reader::Read()
76 : : {
77 : 18 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance(m_pDocStream);
78 : : try
79 : : {
80 : 18 : m_pObjMgr = pGlobal->GetLwpObjFactory();
81 : :
82 [ + - ]: 18 : ReadFileHeader();
83 : : //Does not support Word Pro 96 and previous versions
84 [ + - ]: 18 : if(LwpFileHeader::m_nFileRevision>=0x000B)
85 : : {
86 [ + - ]: 18 : ReadIndex();
87 [ + + ]: 18 : ParseDocument();
88 : : }
89 : : }
90 : 18 : catch(...)
91 : : {
92 [ - + ]: 9 : LwpGlobalMgr::DeleteInstance();
93 : 9 : throw;
94 : : }
95 : 9 : LwpGlobalMgr::DeleteInstance();
96 : 9 : }
97 : :
98 : : /**
99 : : * @descr Read the OLE objects.
100 : : */
101 : 0 : void Lwp9Reader::ReadOleObjects()
102 : : {
103 : 0 : }
104 : : /**
105 : : * @descr Read the LWP7 object.
106 : : */
107 : 18 : void Lwp9Reader::ReadFileHeader()
108 : : {
109 [ + - ]: 18 : m_pDocStream->Seek(LwpSvStream::LWP_STREAM_BASE);
110 : :
111 : : //Remember to initialize the LwpFileHeader::m_nFileRevision first.
112 : 18 : LwpFileHeader::m_nFileRevision = 0;
113 : :
114 [ + - ]: 18 : LwpObjectHeader objHdr;
115 [ + - ]: 18 : objHdr.Read(*m_pDocStream);
116 [ + - ]: 18 : sal_Int64 pos = m_pDocStream->Tell();
117 [ + - ]: 18 : m_LwpFileHdr.Read(m_pDocStream);
118 [ + - ]: 18 : m_pDocStream->Seek(pos+objHdr.GetSize());
119 : :
120 : 18 : }
121 : :
122 : : /**
123 : : * @descr Read the index objects at the end of the WordProData stream
124 : : */
125 : 18 : void Lwp9Reader::ReadIndex()
126 : : {
127 : 18 : sal_Int64 oldpos = m_pDocStream->Tell();
128 : 18 : sal_uInt32 rootoffset = m_LwpFileHdr.GetRootIndexOffset();
129 : 18 : m_pDocStream->Seek(rootoffset + LwpSvStream::LWP_STREAM_BASE);
130 : 18 : m_pObjMgr->ReadIndex(m_pDocStream);
131 : 18 : m_pDocStream->Seek(oldpos);
132 : 18 : }
133 : :
134 : : /**
135 : : * @descr Read all objects
136 : : * This function is replaced by the read on demand model
137 : : * Reserverd for future use
138 : : */
139 : 0 : void Lwp9Reader::DumpAllObjects()
140 : : {
141 : 0 : sal_Int64 nFileSize = GetFileSize();
142 : 0 : sal_Int64 nFilePos = m_pDocStream->Tell();
143 : :
144 : 0 : while(true)
145 : : {
146 [ # # ]: 0 : LwpObjectHeader objHdr;
147 [ # # ]: 0 : objHdr.Read(*m_pDocStream);
148 [ # # ]: 0 : nFilePos = m_pDocStream->Tell();
149 : : //Stop when reaching the index object
150 [ # # ]: 0 : if(objHdr.GetTag() >= VO_ROOTLEAFOBJINDEX)
151 : : {
152 : : break;
153 : : }
154 : : //Stop when the length exceeds the file length
155 [ # # ]: 0 : if(nFilePos + objHdr.GetSize() > nFileSize)
156 : : {
157 : : assert(false);
158 : : break;
159 : : }
160 [ # # ]: 0 : m_pObjMgr->CreateObject(objHdr.GetTag(), objHdr);
161 [ # # ]: 0 : m_pDocStream->Seek(nFilePos+objHdr.GetSize());
162 : : }
163 : 0 : }
164 : :
165 : : /**
166 : : * @descr Get file size
167 : : */
168 : 0 : sal_Int64 Lwp9Reader::GetFileSize()
169 : : {
170 : 0 : sal_Int64 pos = m_pDocStream->Tell();
171 : 0 : m_pDocStream->Seek(0);
172 : :
173 : 0 : sal_Int64 size = m_pDocStream->Seek( STREAM_SEEK_TO_END);
174 : 0 : m_pDocStream->Seek(pos);
175 : 0 : return(size);
176 : : }
177 : :
178 : : /**
179 : : * @descr Parse all document content
180 : : */
181 : 18 : void Lwp9Reader::ParseDocument()
182 : : {
183 : 18 : WriteDocHeader();
184 : :
185 : : //Get root document
186 [ - + ]: 18 : LwpDocument* doc = dynamic_cast<LwpDocument*> ( m_LwpFileHdr.GetDocID()->obj() );
187 : :
188 [ - + ]: 12 : if (!doc)
189 : 9 : return;
190 : :
191 : : //Parse Doc Data
192 [ - + ]: 12 : LwpDocData *pDocData = dynamic_cast<LwpDocData*>((doc->GetDocData())->obj());
193 [ + - ]: 12 : if (pDocData!=NULL)
194 : 12 : pDocData->Parse(m_pStream);
195 : :
196 : : //Register Styles
197 : 12 : RegisteArrowStyles();
198 : 12 : doc->RegisterStyle();
199 : 9 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
200 : 9 : pXFStyleManager->ToXml(m_pStream);
201 : :
202 : : //Parse document content
203 : 9 : m_pStream->GetAttrList()->Clear();
204 [ + - ]: 9 : m_pStream->StartElement( A2OUSTR("office:body") );
205 : :
206 : : //Parse change list, add by
207 : 9 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
208 : 9 : LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
209 : 9 : pChangeMgr->ConvertAllChange(m_pStream);
210 : :
211 : 9 : doc->Parse(m_pStream);
212 [ + - ]: 9 : m_pStream->EndElement(::rtl::OUString("office:body"));
213 : :
214 : 9 : WriteDocEnd();
215 : : }
216 : :
217 : : /**
218 : : * @descr Write xml document header
219 : : */
220 : 18 : void Lwp9Reader::WriteDocHeader()
221 : : {
222 : 18 : m_pStream->StartDocument();
223 : :
224 : 18 : IXFAttrList *pAttrList = m_pStream->GetAttrList();
225 : :
226 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:office"), A2OUSTR("http://openoffice.org/2000/office") );
227 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:style"), A2OUSTR("http://openoffice.org/2000/style") );
228 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:text"), A2OUSTR("http://openoffice.org/2000/text") );
229 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:table"), A2OUSTR("http://openoffice.org/2000/table") );
230 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:draw"), A2OUSTR("http://openoffice.org/2000/drawing") );
231 : :
232 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:fo"), A2OUSTR("http://www.w3.org/1999/XSL/Format") );
233 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:xlink"), A2OUSTR("http://www.w3.org/1999/xlink") );
234 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:number"), A2OUSTR("http://openoffice.org/2000/datastyle") );
235 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:svg"), A2OUSTR("http://www.w3.org/2000/svg") );
236 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:chart"), A2OUSTR("http://openoffice.org/2000/chart") );
237 : :
238 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:dr3d"), A2OUSTR("http://openoffice.org/2000/dr3d") );
239 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:math"), A2OUSTR("http://www.w3.org/1998/Math/MathML") );
240 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:form"), A2OUSTR("http://openoffice.org/2000/form") );
241 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:script"), A2OUSTR("http://openoffice.org/2000/script") );
242 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:dc"), A2OUSTR("http://purl.org/dc/elements/1.1/") );
243 : :
244 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("xmlns:meta"), A2OUSTR("http://openoffice.org/2000/meta") );
245 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("office:class"), A2OUSTR("text"));
246 [ + - ]: 18 : pAttrList->AddAttribute( A2OUSTR("office:version"), A2OUSTR("1.0"));
247 : :
248 [ + - ]: 18 : m_pStream->StartElement( ::rtl::OUString("office:document") );
249 : 18 : pAttrList->Clear();
250 : :
251 : 18 : }
252 : : /**
253 : : * @descr Write xml document end
254 : : */
255 : 9 : void Lwp9Reader::WriteDocEnd()
256 : : {
257 [ + - ]: 9 : m_pStream->EndElement(::rtl::OUString("office:document"));
258 : 9 : m_pStream->EndDocument();
259 : 9 : }
260 : :
261 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|