1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package com.sun.star.comp.helper; 29 30 import java.net.MalformedURLException; 31 import java.net.URL; 32 import java.net.URLClassLoader; 33 34 /** 35 * UnoInfo offers functionality to obtain the UNO jar files. 36 */ 37 public final class UnoInfo { 38 39 /** 40 * do not instantiate 41 */ 42 private UnoInfo() {} 43 44 /** 45 * Gets the URL base. 46 * 47 * @return the URL base 48 */ 49 private static String getBase() { 50 51 final String JUHJAR = "/juh.jar"; 52 53 String base = null; 54 55 URLClassLoader cl = (URLClassLoader) UnoInfo.class.getClassLoader(); 56 URL[] urls = cl.getURLs(); 57 for ( int i = 0; i < urls.length; i++ ) { 58 String url = urls[i].toString(); 59 if ( url.endsWith( JUHJAR ) ) 60 { 61 int index = url.lastIndexOf( JUHJAR ); 62 if ( index >= 0 ) { 63 base = url.substring( 0, index + 1 ); 64 break; 65 } 66 } 67 } 68 69 return base; 70 } 71 72 /** 73 * Gets a list of URLs for the given jar files. 74 * 75 * @return the list of URLs 76 */ 77 private static URL[] getURLs( String[] jarFileNames ) { 78 79 URL[] jars = new URL[jarFileNames.length]; 80 String base = getBase(); 81 for ( int i = 0; i < jarFileNames.length; i++ ) { 82 try { 83 jars[i] = new URL( base + jarFileNames[i] ); 84 } catch ( MalformedURLException e ) { 85 return null; 86 } 87 } 88 89 return jars; 90 } 91 92 /** 93 * Gets the UNO jar files. 94 * 95 * @return the UNO jar files 96 */ 97 public static URL[] getJars() { 98 99 String[] jarFileNames = new String[] { 100 "jurt.jar", 101 "ridl.jar", 102 "juh.jar" }; 103 104 return getURLs( jarFileNames ); 105 } 106 107 /** 108 * Gets the extra UNO types. 109 * 110 * @return the extra UNO types 111 */ 112 public static URL[] getExtraTypes() { 113 return new URL[0]; 114 } 115 } 116