1*a5b190bfSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a5b190bfSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a5b190bfSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a5b190bfSAndrew Rist * distributed with this work for additional information 6*a5b190bfSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a5b190bfSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a5b190bfSAndrew Rist * "License"); you may not use this file except in compliance 9*a5b190bfSAndrew Rist * with the License. You may obtain a copy of the License at 10*a5b190bfSAndrew Rist * 11*a5b190bfSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a5b190bfSAndrew Rist * 13*a5b190bfSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a5b190bfSAndrew Rist * software distributed under the License is distributed on an 15*a5b190bfSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a5b190bfSAndrew Rist * KIND, either express or implied. See the License for the 17*a5b190bfSAndrew Rist * specific language governing permissions and limitations 18*a5b190bfSAndrew Rist * under the License. 19*a5b190bfSAndrew Rist * 20*a5b190bfSAndrew Rist *************************************************************/ 21*a5b190bfSAndrew Rist 22*a5b190bfSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.comp.helper; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.net.MalformedURLException; 27cdf0e10cSrcweir import java.net.URL; 28cdf0e10cSrcweir import java.net.URLClassLoader; 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** 31cdf0e10cSrcweir * UnoInfo offers functionality to obtain the UNO jar files. 32cdf0e10cSrcweir */ 33cdf0e10cSrcweir public final class UnoInfo { 34cdf0e10cSrcweir 35cdf0e10cSrcweir /** 36cdf0e10cSrcweir * do not instantiate 37cdf0e10cSrcweir */ 38cdf0e10cSrcweir private UnoInfo() {} 39cdf0e10cSrcweir 40cdf0e10cSrcweir /** 41cdf0e10cSrcweir * Gets the URL base. 42cdf0e10cSrcweir * 43cdf0e10cSrcweir * @return the URL base 44cdf0e10cSrcweir */ 45cdf0e10cSrcweir private static String getBase() { 46cdf0e10cSrcweir 47cdf0e10cSrcweir final String JUHJAR = "/juh.jar"; 48cdf0e10cSrcweir 49cdf0e10cSrcweir String base = null; 50cdf0e10cSrcweir 51cdf0e10cSrcweir URLClassLoader cl = (URLClassLoader) UnoInfo.class.getClassLoader(); 52cdf0e10cSrcweir URL[] urls = cl.getURLs(); 53cdf0e10cSrcweir for ( int i = 0; i < urls.length; i++ ) { 54cdf0e10cSrcweir String url = urls[i].toString(); 55cdf0e10cSrcweir if ( url.endsWith( JUHJAR ) ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir int index = url.lastIndexOf( JUHJAR ); 58cdf0e10cSrcweir if ( index >= 0 ) { 59cdf0e10cSrcweir base = url.substring( 0, index + 1 ); 60cdf0e10cSrcweir break; 61cdf0e10cSrcweir } 62cdf0e10cSrcweir } 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir return base; 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir /** 69cdf0e10cSrcweir * Gets a list of URLs for the given jar files. 70cdf0e10cSrcweir * 71cdf0e10cSrcweir * @return the list of URLs 72cdf0e10cSrcweir */ 73cdf0e10cSrcweir private static URL[] getURLs( String[] jarFileNames ) { 74cdf0e10cSrcweir 75cdf0e10cSrcweir URL[] jars = new URL[jarFileNames.length]; 76cdf0e10cSrcweir String base = getBase(); 77cdf0e10cSrcweir for ( int i = 0; i < jarFileNames.length; i++ ) { 78cdf0e10cSrcweir try { 79cdf0e10cSrcweir jars[i] = new URL( base + jarFileNames[i] ); 80cdf0e10cSrcweir } catch ( MalformedURLException e ) { 81cdf0e10cSrcweir return null; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir return jars; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir /** 89cdf0e10cSrcweir * Gets the UNO jar files. 90cdf0e10cSrcweir * 91cdf0e10cSrcweir * @return the UNO jar files 92cdf0e10cSrcweir */ 93cdf0e10cSrcweir public static URL[] getJars() { 94cdf0e10cSrcweir 95cdf0e10cSrcweir String[] jarFileNames = new String[] { 96cdf0e10cSrcweir "jurt.jar", 97cdf0e10cSrcweir "ridl.jar", 98cdf0e10cSrcweir "juh.jar" }; 99cdf0e10cSrcweir 100cdf0e10cSrcweir return getURLs( jarFileNames ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir /** 104cdf0e10cSrcweir * Gets the extra UNO types. 105cdf0e10cSrcweir * 106cdf0e10cSrcweir * @return the extra UNO types 107cdf0e10cSrcweir */ 108cdf0e10cSrcweir public static URL[] getExtraTypes() { 109cdf0e10cSrcweir return new URL[0]; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112