source: trunk/docx4j/src/main/java/org/docx4j/utils/ResourceUtils.java @ 1377

Revision 1377, 1.6 KB checked in by jharrop, 17 months ago (diff)

Patrick's patch, so classloader is set in IKVM environment

Line 
1/*
2 *  Copyright 2007-2008, Plutext Pty Ltd.
3 *   
4 *  This file is part of docx4j.
5
6    docx4j is licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8
9    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, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18
19 */
20
21package org.docx4j.utils;
22
23import org.apache.log4j.Logger;
24
25public class ResourceUtils {
26       
27        protected static Logger log = Logger.getLogger(ResourceUtils.class);   
28       
29    public static java.io.InputStream getResource(String filename) throws java.io.IOException
30    {
31        // Try to load resource from jar.
32        ClassLoader loader = Thread.currentThread().getContextClassLoader();
33        if (loader == null) {  // IKVM (v.0.44.0.5) doesn't set context classloader
34            loader = ResourceUtils.class.getClassLoader();
35        }
36       
37        java.net.URL url = loader.getResource(filename);
38               
39        if (url == null) {
40                log.error("Couldn't get resource: " + filename);
41        }
42       
43        // Get the jar file
44//      JarURLConnection conn = (JarURLConnection) url.openConnection();
45        java.io.InputStream is = url.openConnection().getInputStream();
46        return is;
47    }
48       
49
50}
Note: See TracBrowser for help on using the repository browser.