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/lang/WrappedTargetRuntimeException.hpp>
41 : #include <com/sun/star/task/XStatusIndicator.hpp>
42 :
43 : #include <unotools/mediadescriptor.hxx>
44 : #include <tools/zcodec.hxx>
45 :
46 : using namespace ::com::sun::star;
47 : using namespace ::svgi;
48 :
49 0 : bool SVGFilter::implImport(const Sequence< PropertyValue >& rDescriptor)
50 : throw (RuntimeException, std::exception)
51 : {
52 0 : utl::MediaDescriptor aMediaDescriptor(rDescriptor);
53 0 : uno::Reference<io::XInputStream> xInputStream;
54 0 : uno::Reference<task::XStatusIndicator> xStatus;
55 :
56 0 : xInputStream = uno::Reference<io::XInputStream>(aMediaDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY);
57 0 : xStatus = uno::Reference<task::XStatusIndicator>(aMediaDescriptor[utl::MediaDescriptor::PROP_STATUSINDICATOR()], UNO_QUERY);
58 :
59 0 : if (isStreamGZip(xInputStream))
60 : {
61 0 : uno::Reference<io::XSeekable> xSeek(xInputStream, uno::UNO_QUERY);
62 0 : if (!xSeek.is())
63 0 : return false;
64 0 : xSeek->seek(0);
65 :
66 0 : boost::scoped_ptr<SvStream> aStream(utl::UcbStreamHelper::CreateStream(xInputStream, true ));
67 0 : if(!aStream.get())
68 0 : return false;
69 :
70 0 : SvStream* pMemoryStream = new SvMemoryStream;
71 0 : ZCodec aCodec;
72 0 : aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, false, true);
73 0 : aCodec.Decompress(*aStream.get(), *pMemoryStream);
74 0 : aCodec.EndCompression();
75 0 : pMemoryStream->Seek(STREAM_SEEK_TO_BEGIN);
76 0 : uno::Reference<io::XInputStream> xDecompressedInput(new utl::OSeekableInputStreamWrapper(pMemoryStream, true));
77 0 : if (!xDecompressedInput.is())
78 0 : return false;
79 0 : xInputStream = xDecompressedInput;
80 : }
81 : else
82 : {
83 0 : uno::Reference<io::XSeekable> xSeek(xInputStream, uno::UNO_QUERY);
84 0 : if (xSeek.is())
85 0 : xSeek->seek(0);
86 : }
87 :
88 : OSL_ASSERT(xInputStream.is());
89 0 : if(!xInputStream.is())
90 0 : return false;
91 :
92 0 : OUString sXMLImportService ( "com.sun.star.comp.Draw.XMLOasisImporter" );
93 0 : Reference < XDocumentHandler > xInternalHandler( mxContext->getServiceManager()->createInstanceWithContext( sXMLImportService, mxContext ), UNO_QUERY );
94 :
95 : // The XImporter sets up an empty target document for XDocumentHandler to write to..
96 0 : uno::Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
97 0 : xImporter->setTargetDocument(mxDstDoc);
98 :
99 0 : bool bRet = false;
100 0 : SVGReader aReader(mxContext, xInputStream, xInternalHandler);
101 : try
102 : {
103 0 : bRet = aReader.parseAndConvert();
104 : }
105 0 : catch (const RuntimeException&)
106 : {
107 0 : throw;
108 : }
109 0 : catch (const Exception& e)
110 : {
111 : throw css::lang::WrappedTargetRuntimeException("SVGFilter::implImport non-RuntimeException",
112 0 : static_cast<uno::XWeak*>(this), uno::makeAny(e));
113 : }
114 0 : return bRet;
115 9 : }
116 :
117 :
118 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|