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 : /*************************************************************************
57 : * @file
58 : * Circle object.
59 : ************************************************************************/
60 : #include "lwpfilter.hxx"
61 : #include "lwpresource.hxx"
62 : #include "xfilter/xfsaxstream.hxx"
63 : #include "lwp9reader.hxx"
64 : #include "lwpsvstream.hxx"
65 : #include "xfilter/xffontfactory.hxx"
66 : #include "xfilter/xfstylemanager.hxx"
67 :
68 : #include <osl/file.h>
69 : #include <osl/file.hxx>
70 : #include <vcl/svapp.hxx>
71 : #include <xmloff/attrlist.hxx>
72 : #include <com/sun/star/io/IOException.hpp>
73 : #include <com/sun/star/frame/XDesktop.hpp>
74 : #include <com/sun/star/frame/XController.hpp>
75 : #include <com/sun/star/text/XTextDocument.hpp>
76 : #include <com/sun/star/text/XText.hpp>
77 :
78 : #include <cppuhelper/supportsservice.hxx>
79 :
80 : #include <sfx2/docfile.hxx>
81 :
82 : #include <boost/scoped_ptr.hpp>
83 :
84 : using namespace ::cppu;
85 : using namespace ::com::sun::star::lang;
86 : using namespace ::com::sun::star::frame;
87 : using namespace ::com::sun::star::text;
88 : using namespace ::com::sun::star::io;
89 : using namespace ::com::sun::star::registry;
90 : using namespace ::com::sun::star::document;
91 : using namespace ::com::sun::star::beans;
92 : using namespace ::com::sun::star;
93 : using ::com::sun::star::uno::Sequence;
94 :
95 : /**
96 : * @descr decompressed small file
97 : * @param pCompressed - real file stream
98 : * @param pDecompressed - file decompressed, create inside, caller should delete it
99 : * @return success - sal_True, fail - sal_False
100 : */
101 : #include "bento.hxx"
102 : using namespace OpenStormBento;
103 : #include "explode.hxx"
104 0 : bool Decompress(SvStream *pCompressed, SvStream * & pOutDecompressed)
105 : {
106 0 : pCompressed->Seek(0);
107 0 : std::unique_ptr<SvStream> aDecompressed(new SvMemoryStream(4096, 4096));
108 : unsigned char buffer[512];
109 0 : pCompressed->Read(buffer, 16);
110 0 : aDecompressed->Write(buffer, 16);
111 :
112 0 : boost::scoped_ptr<LwpSvStream> aLwpStream(new LwpSvStream(pCompressed));
113 : LtcBenContainer* pBentoContainer;
114 0 : sal_uLong ulRet = BenOpenContainer(aLwpStream.get(), &pBentoContainer);
115 0 : if (ulRet != BenErr_OK)
116 0 : return false;
117 :
118 0 : boost::scoped_ptr<LtcUtBenValueStream> aWordProData(pBentoContainer->FindValueStreamWithPropertyName("WordProData"));
119 :
120 0 : if (!aWordProData.get())
121 0 : return false;
122 :
123 : // decompressing
124 0 : Decompression decompress(aWordProData.get(), aDecompressed.get());
125 0 : if (0!= decompress.explode())
126 0 : return false;
127 :
128 0 : sal_uInt32 nPos = aWordProData->GetSize();
129 0 : nPos += 0x10;
130 :
131 0 : pCompressed->Seek(nPos);
132 0 : while (sal_uInt32 iRead = pCompressed->Read(buffer, 512))
133 0 : aDecompressed->Write(buffer, iRead);
134 :
135 : //transfer ownership of aDecompressed's ptr
136 0 : pOutDecompressed = aDecompressed.release();
137 0 : return true;
138 : }
139 :
140 : /**
141 : * @descr Get LwpSvStream, if small file, both compressed/decompressed stream
142 : * Otherwise, only normal stream
143 : * @param pStream - real file stream
144 : * @param LwpSvStream * , created inside, deleted outside
145 : * @param sal_Bool, sal_True -
146 : */
147 6 : bool GetLwpSvStream(SvStream *pStream, LwpSvStream * & pLwpSvStream)
148 : {
149 6 : SvStream * pDecompressed = NULL;
150 :
151 : sal_uInt32 nTag;
152 6 : pStream->Seek(0x10);
153 6 : pStream->ReadUInt32( nTag );
154 6 : if (nTag != 0x3750574c) // "LWP7"
155 : {
156 : // small file, needs decompression
157 0 : if (!Decompress(pStream, pDecompressed))
158 : {
159 0 : pLwpSvStream = NULL;
160 0 : return true;
161 : }
162 0 : pStream->Seek(0);
163 0 : pDecompressed->Seek(0);
164 : }
165 :
166 6 : pLwpSvStream = NULL;
167 6 : bool bCompressed = false;
168 6 : if (pDecompressed)
169 : {
170 0 : LwpSvStream *pOriginalLwpSvStream = new LwpSvStream(pStream);
171 0 : pLwpSvStream = new LwpSvStream(pDecompressed, pOriginalLwpSvStream);
172 0 : bCompressed = true;
173 : }
174 : else
175 : {
176 6 : pLwpSvStream = new LwpSvStream(pStream);
177 : }
178 6 : return bCompressed;
179 : }
180 6 : int ReadWordproFile(SvStream &rStream, uno::Reference<css::xml::sax::XDocumentHandler>& xHandler)
181 : {
182 : try
183 : {
184 6 : LwpSvStream *pRawLwpSvStream = NULL;
185 6 : boost::scoped_ptr<LwpSvStream> aLwpSvStream;
186 12 : boost::scoped_ptr<LwpSvStream> aCompressedLwpSvStream;
187 12 : boost::scoped_ptr<SvStream> aDecompressed;
188 6 : if (GetLwpSvStream(&rStream, pRawLwpSvStream) && pRawLwpSvStream)
189 : {
190 0 : SvStream *pDecompressed = pRawLwpSvStream->GetStream();
191 0 : if (pDecompressed)
192 : {
193 0 : aDecompressed.reset(pDecompressed);
194 0 : aCompressedLwpSvStream.reset(pRawLwpSvStream->GetCompressedStream());
195 : }
196 : }
197 :
198 6 : if (!pRawLwpSvStream)
199 : {
200 : // nothing returned, fail when uncompressing
201 0 : return 1;
202 : }
203 :
204 6 : aLwpSvStream.reset(pRawLwpSvStream);
205 :
206 12 : boost::scoped_ptr<IXFStream> pStrm(new XFSaxStream(xHandler));
207 12 : Lwp9Reader reader(aLwpSvStream.get(), pStrm.get());
208 : //Reset all static objects,because this function may be called many times.
209 6 : XFGlobalReset();
210 6 : reader.Read();
211 :
212 9 : return 0;
213 : }
214 6 : catch (...)
215 : {
216 3 : return 1;
217 : }
218 : }
219 :
220 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|