Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / javaunohelper / com / sun / star / comp / helper / UnoInfo.java
blobd528f433ba595279aeb44d4afb559b86eac8520e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package com.sun.star.comp.helper;
30 import java.net.MalformedURLException;
31 import java.net.URL;
32 import java.net.URLClassLoader;
34 /**
35 * UnoInfo offers functionality to obtain the UNO jar files.
37 public final class UnoInfo {
39 /**
40 * do not instantiate
42 private UnoInfo() {}
44 /**
45 * Gets the URL base.
47 * @return the URL base
49 private static String getBase() {
51 final String JUHJAR = "/juh.jar";
53 String base = null;
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 ) )
61 int index = url.lastIndexOf( JUHJAR );
62 if ( index >= 0 ) {
63 base = url.substring( 0, index + 1 );
64 break;
69 return base;
72 /**
73 * Gets a list of URLs for the given jar files.
75 * @return the list of URLs
77 private static URL[] getURLs( String[] jarFileNames ) {
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;
89 return jars;
92 /**
93 * Gets the UNO jar files.
95 * @return the UNO jar files
97 public static URL[] getJars() {
99 String[] jarFileNames = new String[] {
100 "jurt.jar",
101 "ridl.jar",
102 "juh.jar" };
104 return getURLs( jarFileNames );
108 * Gets the extra UNO types.
110 * @return the extra UNO types
112 public static URL[] getExtraTypes() {
113 return new URL[0];