1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "precompiled_sw.hxx"
28 #include <retrieveinputstream.hxx>
29 #include <comphelper/mediadescriptor.hxx>
30 #ifndef _COM_SUN_STAR_IO_XSTREAM_HXX_
31 #include <com/sun/star/io/XStream.hpp>
32 #endif
33 
34 /** class for a thread to retrieve an input stream given by an URL
35 
36     OD 2007-01-29 #i73788#
37 
38     @author OD
39 */
40 ::rtl::Reference< ObservableThread > SwAsyncRetrieveInputStreamThread::createThread(
41                         const SwRetrievedInputStreamDataManager::tDataKey nDataKey,
42                         const String& rLinkedURL )
43 {
44     SwAsyncRetrieveInputStreamThread* pNewThread =
45             new SwAsyncRetrieveInputStreamThread( nDataKey, rLinkedURL );
46     return pNewThread;
47 }
48 
49 SwAsyncRetrieveInputStreamThread::SwAsyncRetrieveInputStreamThread(
50                             const SwRetrievedInputStreamDataManager::tDataKey nDataKey,
51                             const String& rLinkedURL )
52     : ObservableThread(),
53       mnDataKey( nDataKey ),
54       mrLinkedURL( rLinkedURL )
55 {
56 }
57 
58 SwAsyncRetrieveInputStreamThread::~SwAsyncRetrieveInputStreamThread()
59 {
60 }
61 
62 void SwAsyncRetrieveInputStreamThread::threadFunction()
63 {
64     com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > xProps( 1 );
65     xProps[0].Name = ::rtl::OUString::createFromAscii( "URL" );
66     xProps[0].Value <<= ::rtl::OUString( mrLinkedURL );
67     comphelper::MediaDescriptor aMedium( xProps );
68 
69     aMedium.addInputStream();
70 
71     com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream;
72     aMedium[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream;
73     if ( !xInputStream.is() )
74     {
75         com::sun::star::uno::Reference<com::sun::star::io::XStream> xStream;
76         aMedium[comphelper::MediaDescriptor::PROP_STREAM()] >>= xStream;
77         if ( xStream.is() )
78         {
79             xInputStream = xStream->getInputStream();
80         }
81     }
82 
83     SwRetrievedInputStreamDataManager::GetManager().PushData( mnDataKey,
84                                                               xInputStream,
85                                                               aMedium.isStreamReadOnly() );
86 }
87