1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #include "precompiled_sw.hxx" 24 #include <retrieveinputstream.hxx> 25 #include <comphelper/mediadescriptor.hxx> 26 #ifndef _COM_SUN_STAR_IO_XSTREAM_HXX_ 27 #include <com/sun/star/io/XStream.hpp> 28 #endif 29 30 /** class for a thread to retrieve an input stream given by an URL 31 32 OD 2007-01-29 #i73788# 33 34 @author OD 35 */ 36 ::rtl::Reference< ObservableThread > SwAsyncRetrieveInputStreamThread::createThread( 37 const SwRetrievedInputStreamDataManager::tDataKey nDataKey, 38 const String& rLinkedURL ) 39 { 40 SwAsyncRetrieveInputStreamThread* pNewThread = 41 new SwAsyncRetrieveInputStreamThread( nDataKey, rLinkedURL ); 42 return pNewThread; 43 } 44 45 SwAsyncRetrieveInputStreamThread::SwAsyncRetrieveInputStreamThread( 46 const SwRetrievedInputStreamDataManager::tDataKey nDataKey, 47 const String& rLinkedURL ) 48 : ObservableThread(), 49 mnDataKey( nDataKey ), 50 mrLinkedURL( rLinkedURL ) 51 { 52 } 53 54 SwAsyncRetrieveInputStreamThread::~SwAsyncRetrieveInputStreamThread() 55 { 56 } 57 58 void SwAsyncRetrieveInputStreamThread::threadFunction() 59 { 60 com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > xProps( 1 ); 61 xProps[0].Name = ::rtl::OUString::createFromAscii( "URL" ); 62 xProps[0].Value <<= ::rtl::OUString( mrLinkedURL ); 63 comphelper::MediaDescriptor aMedium( xProps ); 64 65 aMedium.addInputStream(); 66 67 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream; 68 aMedium[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream; 69 if ( !xInputStream.is() ) 70 { 71 com::sun::star::uno::Reference<com::sun::star::io::XStream> xStream; 72 aMedium[comphelper::MediaDescriptor::PROP_STREAM()] >>= xStream; 73 if ( xStream.is() ) 74 { 75 xInputStream = xStream->getInputStream(); 76 } 77 } 78 79 SwRetrievedInputStreamDataManager::GetManager().PushData( mnDataKey, 80 xInputStream, 81 aMedium.isStreamReadOnly() ); 82 } 83