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 package com.sun.star.comp.helper;
25 
26 import java.net.MalformedURLException;
27 import java.net.URL;
28 import java.net.URLClassLoader;
29 
30 /**
31  * UnoInfo offers functionality to obtain the UNO jar files.
32  */
33 public final class UnoInfo {
34 
35     /**
36      * do not instantiate
37      */
UnoInfo()38     private UnoInfo() {}
39 
40     /**
41      * Gets the URL base.
42      *
43      * @return the URL base
44      */
getBase()45     private static String getBase() {
46 
47         final String JUHJAR = "/juh.jar";
48 
49         String base = null;
50 
51         URLClassLoader cl = (URLClassLoader) UnoInfo.class.getClassLoader();
52         URL[] urls = cl.getURLs();
53         for ( int i = 0; i < urls.length; i++ ) {
54             String url = urls[i].toString();
55             if ( url.endsWith( JUHJAR ) )
56             {
57                 int index = url.lastIndexOf( JUHJAR );
58                 if ( index >= 0 ) {
59                     base = url.substring( 0, index + 1 );
60                     break;
61                 }
62             }
63         }
64 
65         return base;
66     }
67 
68     /**
69      * Gets a list of URLs for the given jar files.
70      *
71      * @return the list of URLs
72      */
getURLs( String[] jarFileNames )73     private static URL[] getURLs( String[] jarFileNames ) {
74 
75         URL[] jars = new URL[jarFileNames.length];
76         String base = getBase();
77         for ( int i = 0; i < jarFileNames.length; i++ ) {
78             try {
79                 jars[i] = new URL( base + jarFileNames[i] );
80             } catch ( MalformedURLException e ) {
81                 return null;
82             }
83         }
84 
85         return jars;
86     }
87 
88     /**
89      * Gets the UNO jar files.
90      *
91      * @return the UNO jar files
92      */
getJars()93     public static URL[] getJars() {
94 
95         String[] jarFileNames = new String[] {
96             "jurt.jar",
97             "ridl.jar",
98             "juh.jar",
99 	    "unoil.jar" };
100 
101         return getURLs( jarFileNames );
102     }
103 
104     /**
105      * Gets the extra UNO types.
106      *
107      * @return the extra UNO types
108      */
getExtraTypes()109     public static URL[] getExtraTypes() {
110         return new URL[0];
111     }
112 }
113