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,
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 /*************************************************************************
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"
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>
78 #include <cppuhelper/supportsservice.hxx>
80 #include <sfx2/docfile.hxx>
82 #include <boost/scoped_ptr.hpp>
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
;
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
102 using namespace OpenStormBento
;
103 #include "explode.hxx"
104 bool Decompress(SvStream
*pCompressed
, SvStream
* & pOutDecompressed
)
106 pCompressed
->Seek(0);
107 std::auto_ptr
<SvStream
> aDecompressed(new SvMemoryStream(4096, 4096));
108 unsigned char buffer
[512];
109 pCompressed
->Read(buffer
, 16);
110 aDecompressed
->Write(buffer
, 16);
112 boost::scoped_ptr
<LwpSvStream
> aLwpStream(new LwpSvStream(pCompressed
));
113 LtcBenContainer
* pBentoContainer
;
114 sal_uLong ulRet
= BenOpenContainer(aLwpStream
.get(), &pBentoContainer
);
115 if (ulRet
!= BenErr_OK
)
118 boost::scoped_ptr
<LtcUtBenValueStream
> aWordProData((LtcUtBenValueStream
*)pBentoContainer
->FindValueStreamWithPropertyName("WordProData"));
120 if (!aWordProData
.get())
124 Decompression
decompress(aWordProData
.get(), aDecompressed
.get());
125 if (0!= decompress
.explode())
128 sal_uInt32 nPos
= aWordProData
->GetSize();
131 pCompressed
->Seek(nPos
);
132 while (sal_uInt32 iRead
= pCompressed
->Read(buffer
, 512))
133 aDecompressed
->Write(buffer
, iRead
);
135 //transfer ownership of aDecompressed's ptr
136 pOutDecompressed
= aDecompressed
.release();
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 -
147 bool GetLwpSvStream(SvStream
*pStream
, LwpSvStream
* & pLwpSvStream
)
149 SvStream
* pDecompressed
= NULL
;
153 pStream
->ReadUInt32( nTag
);
154 if (nTag
!= 0x3750574c) // "LWP7"
156 // small file, needs decompression
157 if (!Decompress(pStream
, pDecompressed
))
163 pDecompressed
->Seek(0);
167 bool bCompressed
= false;
170 LwpSvStream
*pOriginalLwpSvStream
= new LwpSvStream(pStream
);
171 pLwpSvStream
= new LwpSvStream(pDecompressed
, pOriginalLwpSvStream
);
176 pLwpSvStream
= new LwpSvStream(pStream
);
180 int ReadWordproFile(SvStream
&rStream
, uno::Reference
<css::xml::sax::XDocumentHandler
>& xHandler
)
184 LwpSvStream
*pRawLwpSvStream
= NULL
;
185 boost::scoped_ptr
<LwpSvStream
> aLwpSvStream
;
186 boost::scoped_ptr
<LwpSvStream
> aCompressedLwpSvStream
;
187 boost::scoped_ptr
<SvStream
> aDecompressed
;
188 if (GetLwpSvStream(&rStream
, pRawLwpSvStream
) && pRawLwpSvStream
)
190 SvStream
*pDecompressed
= pRawLwpSvStream
->GetStream();
193 aDecompressed
.reset(pDecompressed
);
194 aCompressedLwpSvStream
.reset(pRawLwpSvStream
->GetCompressedStream());
198 if (!pRawLwpSvStream
)
200 // nothing returned, fail when uncompressing
204 aLwpSvStream
.reset(pRawLwpSvStream
);
206 boost::scoped_ptr
<IXFStream
> pStrm(new XFSaxStream(xHandler
));
207 Lwp9Reader
reader(aLwpSvStream
.get(), pStrm
.get());
208 //Reset all static objects,because this function may be called many times.
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */