merge the formfield patch from ooo-build
[ooovba.git] / javaunohelper / com / sun / star / comp / helper / UnoInfo.java
blobbf89e47a2c5879bec95693856943913aa7138f2c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoInfo.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com.sun.star.comp.helper;
33 import java.net.MalformedURLException;
34 import java.net.URL;
35 import java.net.URLClassLoader;
37 /**
38 * UnoInfo offers functionality to obtain the UNO jar files.
39 */
40 public final class UnoInfo {
42 /**
43 * do not instantiate
45 private UnoInfo() {}
47 /**
48 * Gets the URL base.
50 * @return the URL base
51 */
52 private static String getBase() {
54 final String JUHJAR = "/juh.jar";
56 String base = null;
58 URLClassLoader cl = (URLClassLoader) UnoInfo.class.getClassLoader();
59 URL[] urls = cl.getURLs();
60 for ( int i = 0; i < urls.length; i++ ) {
61 String url = urls[i].toString();
62 if ( url.endsWith( JUHJAR ) )
64 int index = url.lastIndexOf( JUHJAR );
65 if ( index >= 0 ) {
66 base = url.substring( 0, index + 1 );
67 break;
72 return base;
75 /**
76 * Gets a list of URLs for the given jar files.
78 * @return the list of URLs
80 private static URL[] getURLs( String[] jarFileNames ) {
82 URL[] jars = new URL[jarFileNames.length];
83 String base = getBase();
84 for ( int i = 0; i < jarFileNames.length; i++ ) {
85 try {
86 jars[i] = new URL( base + jarFileNames[i] );
87 } catch ( MalformedURLException e ) {
88 return null;
92 return jars;
95 /**
96 * Gets the UNO jar files.
98 * @return the UNO jar files
100 public static URL[] getJars() {
102 String[] jarFileNames = new String[] {
103 "jurt.jar",
104 "ridl.jar",
105 "juh.jar" };
107 return getURLs( jarFileNames );
111 * Gets the extra UNO types.
113 * @return the extra UNO types
115 public static URL[] getExtraTypes() {
116 return new URL[0];