Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "svgfilter.hxx"
22 : #include "svgreader.hxx"
23 :
24 : #include "rtl/ref.hxx"
25 :
26 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 :
28 : #include <com/sun/star/lang/XComponent.hpp>
29 :
30 : #include <com/sun/star/uno/Any.hxx>
31 : #include <com/sun/star/uno/Type.hxx>
32 :
33 : #include <com/sun/star/beans/PropertyValue.hpp>
34 :
35 : #include <com/sun/star/xml/sax/XParser.hpp>
36 : #include <com/sun/star/xml/sax/InputSource.hpp>
37 : #include <com/sun/star/xml/XImportFilter.hpp>
38 :
39 : #include <com/sun/star/io/XActiveDataSource.hpp>
40 : #include <com/sun/star/task/XStatusIndicator.hpp>
41 :
42 : #include <unotools/mediadescriptor.hxx>
43 : #include <tools/zcodec.hxx>
44 :
45 : using namespace ::com::sun::star;
46 : using namespace ::svgi;
47 :
48 0 : sal_Bool SVGFilter::implImport( const Sequence< PropertyValue >& rDescriptor )
49 : throw (RuntimeException)
50 : {
51 0 : utl::MediaDescriptor aMediaDescriptor(rDescriptor);
52 0 : uno::Reference<io::XInputStream> xInputStream;
53 0 : uno::Reference<task::XStatusIndicator> xStatus;
54 :
55 0 : xInputStream = uno::Reference<io::XInputStream>(aMediaDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY);
56 0 : xStatus = uno::Reference<task::XStatusIndicator>(aMediaDescriptor[utl::MediaDescriptor::PROP_STATUSINDICATOR()], UNO_QUERY);
57 :
58 0 : if (isStreamGZip(xInputStream))
59 : {
60 0 : uno::Reference<io::XSeekable> xSeek(xInputStream, uno::UNO_QUERY);
61 0 : if (!xSeek.is())
62 0 : return sal_False;
63 0 : xSeek->seek(0);
64 :
65 0 : boost::scoped_ptr<SvStream> aStream(utl::UcbStreamHelper::CreateStream(xInputStream, true ));
66 0 : if(!aStream.get())
67 0 : return sal_False;
68 :
69 0 : SvStream* pMemoryStream = new SvMemoryStream;
70 0 : GZCodec aCodec;
71 0 : aCodec.BeginCompression();
72 0 : aCodec.Decompress(*aStream.get(), *pMemoryStream);
73 0 : aCodec.EndCompression();
74 0 : pMemoryStream->Seek(STREAM_SEEK_TO_BEGIN);
75 0 : uno::Reference<io::XInputStream> xDecompressedInput(new utl::OSeekableInputStreamWrapper(pMemoryStream, true));
76 0 : if (!xDecompressedInput.is())
77 0 : return sal_False;
78 0 : xInputStream = xDecompressedInput;
79 : }
80 : else
81 : {
82 0 : uno::Reference<io::XSeekable> xSeek(xInputStream, uno::UNO_QUERY);
83 0 : if (xSeek.is())
84 0 : xSeek->seek(0);
85 : }
86 :
87 : OSL_ASSERT(xInputStream.is());
88 0 : if(!xInputStream.is())
89 0 : return sal_False;
90 :
91 0 : OUString sXMLImportService ( "com.sun.star.comp.Draw.XMLOasisImporter" );
92 0 : Reference < XDocumentHandler > xInternalHandler( mxContext->getServiceManager()->createInstanceWithContext( sXMLImportService, mxContext ), UNO_QUERY );
93 :
94 : // The XImporter sets up an empty target document for XDocumentHandler to write to..
95 0 : uno::Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
96 0 : xImporter->setTargetDocument(mxDstDoc);
97 :
98 0 : SVGReader aReader(mxContext, xInputStream, xInternalHandler);
99 0 : return aReader.parseAndConvert();
100 0 : }
101 :
102 :
103 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|