KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > PlatformConfigurationUtils


1 /*******************************************************************************
2  * Copyright (c) 2003, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core;
12
13 import java.io.*;
14 import java.net.*;
15 import java.util.*;
16
17 import org.eclipse.core.internal.boot.*;
18
19 public class PlatformConfigurationUtils {
20     private static final String JavaDoc PLUGIN_PATH = ".plugin-path"; //$NON-NLS-1$
21

22     /*
23      * This method is retained for R1.0 compatibility because it is defined as API.
24      * It's function matches the API description (returns <code>null</code> when
25      * argument URL is <code>null</code> or cannot be read).
26      */

27     public static URL[] getPluginPath(URL pluginPathLocation /*R1.0 compatibility*/
28     ) {
29         InputStream input = null;
30         // first try and see if the given plugin path location exists.
31
if (pluginPathLocation == null)
32             return null;
33         try {
34             input = pluginPathLocation.openStream();
35         } catch (IOException e) {
36             //fall through
37
}
38
39         // if the given path was null or did not exist, look for a plugin path
40
// definition in the install location.
41
if (input == null)
42             try {
43                 URL url = new URL(PlatformURLBaseConnection.PLATFORM_URL_STRING + PLUGIN_PATH);
44                 input = url.openStream();
45             } catch (MalformedURLException e) {
46                 //fall through
47
} catch (IOException e) {
48                 //fall through
49
}
50
51         // nothing was found at the supplied location or in the install location
52
if (input == null)
53             return null;
54         // if we found a plugin path definition somewhere so read it and close the location.
55
URL[] result = null;
56         try {
57             try {
58                 result = readPluginPath(input);
59             } finally {
60                 input.close();
61             }
62         } catch (IOException e) {
63             //let it return null on failure to read
64
}
65         return result;
66     }
67
68     private static URL[] readPluginPath(InputStream input) {
69         Properties ini = new Properties();
70         try {
71             ini.load(input);
72         } catch (IOException e) {
73             return null;
74         }
75         Vector result = new Vector(5);
76         for (Enumeration groups = ini.propertyNames(); groups.hasMoreElements();) {
77             String JavaDoc group = (String JavaDoc) groups.nextElement();
78             for (StringTokenizer entries = new StringTokenizer(ini.getProperty(group), ";"); entries.hasMoreElements();) { //$NON-NLS-1$
79
String JavaDoc entry = (String JavaDoc) entries.nextElement();
80                 if (!entry.equals("")) //$NON-NLS-1$
81
try {
82                         result.addElement(new URL(entry));
83                     } catch (MalformedURLException e) {
84                     }
85             }
86         }
87         return (URL[]) result.toArray(new URL[result.size()]);
88     }
89 }
90
Popular Tags