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 
24 #include <com/sun/star/io/XInputStream.hpp>
25 #include <osl/file.hxx>
26 #include <comphelper/oslfile2streamwrap.hxx>
27 
28 using osl::File;
29 using osl::FileBase;
30 using namespace ::com::sun::star;
31 
32 namespace layoutimpl
33 {
34 
getFileAsStream(const rtl::OUString & rName)35 uno::Reference< io::XInputStream > getFileAsStream( const rtl::OUString &rName )
36 {
37     rtl::OUString sFileURL;
38     if( FileBase::E_None != FileBase::getFileURLFromSystemPath( rName, sFileURL ) )
39         sFileURL = rName; // maybe it already was a file url
40 
41     File * blobFile = new File(sFileURL);
42     File::RC errorCode = blobFile->open(OpenFlag_Read);
43 
44     uno::Reference<io::XInputStream> xResult;
45     switch (errorCode)
46     {
47     case osl::File::E_None: // got it
48         xResult.set( new comphelper::OSLInputStreamWrapper(blobFile,true) );
49         break;
50 
51     case osl::File::E_NOENT: // no file => no stream
52         delete blobFile;
53         break;
54 
55     default:
56         delete blobFile;
57 /*            {
58             rtl::OUStringBuffer sMsg;
59             sMsg.appendAscii("Cannot open output file \"");
60             sMsg.append(aURL);
61             sMsg.appendAscii("\" : ");
62             sMsg.append(configmgr::FileHelper::createOSLErrorString(errorCode));
63 
64             throw io::IOException(sMsg.makeStringAndClear(),NULL);
65         }
66 */
67     }
68 
69     return xResult;
70 }
71 
72 } // namespace layoutimpl
73