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 6 : Lwp9Reader::Lwp9Reader (LwpSvStream* pInputStream, IXFStream* pStream)
69 6 : : m_pDocStream(pInputStream), m_pStream(pStream), m_LwpFileHdr()
70 6 : {}
71 :
72 : /**
73 : * @descr The entrance of Word Pro 9 import filter.
74 : **/
75 6 : void Lwp9Reader::Read()
76 : {
77 6 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance(m_pDocStream);
78 : try
79 : {
80 6 : m_pObjMgr = pGlobal->GetLwpObjFactory();
81 :
82 6 : ReadFileHeader();
83 : //Does not support Word Pro 96 and previous versions
84 6 : if(LwpFileHeader::m_nFileRevision>=0x000B)
85 : {
86 6 : ReadIndex();
87 6 : ParseDocument();
88 : }
89 : }
90 3 : catch(...)
91 : {
92 3 : LwpGlobalMgr::DeleteInstance();
93 3 : throw;
94 : }
95 3 : LwpGlobalMgr::DeleteInstance();
96 3 : }
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 6 : void Lwp9Reader::ReadFileHeader()
108 : {
109 6 : m_pDocStream->Seek(LwpSvStream::LWP_STREAM_BASE);
110 :
111 : //Remember to initialize the LwpFileHeader::m_nFileRevision first.
112 6 : LwpFileHeader::m_nFileRevision = 0;
113 :
114 6 : LwpObjectHeader objHdr;
115 6 : objHdr.Read(*m_pDocStream);
116 6 : sal_Int64 pos = m_pDocStream->Tell();
117 6 : m_LwpFileHdr.Read(m_pDocStream);
118 6 : m_pDocStream->Seek(pos+objHdr.GetSize());
119 :
120 6 : }
121 :
122 : /**
123 : * @descr Read the index objects at the end of the WordProData stream
124 : */
125 6 : void Lwp9Reader::ReadIndex()
126 : {
127 6 : sal_Int64 oldpos = m_pDocStream->Tell();
128 6 : sal_uInt32 rootoffset = m_LwpFileHdr.GetRootIndexOffset();
129 6 : m_pDocStream->Seek(rootoffset + LwpSvStream::LWP_STREAM_BASE);
130 6 : m_pObjMgr->ReadIndex(m_pDocStream);
131 6 : m_pDocStream->Seek(oldpos);
132 6 : }
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 6 : void Lwp9Reader::ParseDocument()
182 : {
183 6 : WriteDocHeader();
184 :
185 : //Get root document
186 6 : LwpDocument* doc = dynamic_cast<LwpDocument*> ( m_LwpFileHdr.GetDocID()->obj() );
187 :
188 4 : if (!doc)
189 3 : return;
190 :
191 : //Parse Doc Data
192 4 : LwpDocData *pDocData = dynamic_cast<LwpDocData*>((doc->GetDocData())->obj());
193 4 : if (pDocData!=NULL)
194 4 : pDocData->Parse(m_pStream);
195 :
196 : //Register Styles
197 4 : RegisteArrowStyles();
198 4 : doc->RegisterStyle();
199 3 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
200 3 : pXFStyleManager->ToXml(m_pStream);
201 :
202 : //Parse document content
203 3 : m_pStream->GetAttrList()->Clear();
204 3 : m_pStream->StartElement( A2OUSTR("office:body") );
205 :
206 : //Parse change list, add by
207 3 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
208 3 : LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
209 3 : pChangeMgr->ConvertAllChange(m_pStream);
210 :
211 3 : doc->Parse(m_pStream);
212 3 : m_pStream->EndElement(::rtl::OUString("office:body"));
213 :
214 3 : WriteDocEnd();
215 : }
216 :
217 : /**
218 : * @descr Write xml document header
219 : */
220 6 : void Lwp9Reader::WriteDocHeader()
221 : {
222 6 : m_pStream->StartDocument();
223 :
224 6 : IXFAttrList *pAttrList = m_pStream->GetAttrList();
225 :
226 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:office"), A2OUSTR("http://openoffice.org/2000/office") );
227 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:style"), A2OUSTR("http://openoffice.org/2000/style") );
228 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:text"), A2OUSTR("http://openoffice.org/2000/text") );
229 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:table"), A2OUSTR("http://openoffice.org/2000/table") );
230 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:draw"), A2OUSTR("http://openoffice.org/2000/drawing") );
231 :
232 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:fo"), A2OUSTR("http://www.w3.org/1999/XSL/Format") );
233 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:xlink"), A2OUSTR("http://www.w3.org/1999/xlink") );
234 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:number"), A2OUSTR("http://openoffice.org/2000/datastyle") );
235 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:svg"), A2OUSTR("http://www.w3.org/2000/svg") );
236 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:chart"), A2OUSTR("http://openoffice.org/2000/chart") );
237 :
238 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:dr3d"), A2OUSTR("http://openoffice.org/2000/dr3d") );
239 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:math"), A2OUSTR("http://www.w3.org/1998/Math/MathML") );
240 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:form"), A2OUSTR("http://openoffice.org/2000/form") );
241 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:script"), A2OUSTR("http://openoffice.org/2000/script") );
242 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:dc"), A2OUSTR("http://purl.org/dc/elements/1.1/") );
243 :
244 6 : pAttrList->AddAttribute( A2OUSTR("xmlns:meta"), A2OUSTR("http://openoffice.org/2000/meta") );
245 6 : pAttrList->AddAttribute( A2OUSTR("office:class"), A2OUSTR("text"));
246 6 : pAttrList->AddAttribute( A2OUSTR("office:version"), A2OUSTR("1.0"));
247 :
248 6 : m_pStream->StartElement( ::rtl::OUString("office:document") );
249 6 : pAttrList->Clear();
250 :
251 6 : }
252 : /**
253 : * @descr Write xml document end
254 : */
255 3 : void Lwp9Reader::WriteDocEnd()
256 : {
257 3 : m_pStream->EndElement(::rtl::OUString("office:document"));
258 3 : m_pStream->EndDocument();
259 3 : }
260 :
261 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|