KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > appserver > DevClassPathHelper


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

11 package org.eclipse.help.internal.appserver;
12
13 import java.io.*;
14 import java.net.*;
15 import java.util.*;
16
17 /**
18  * Class copied from org.eclipse.osgi.framework.internal.defaultadaptor
19  */

20 public class DevClassPathHelper {
21     static protected boolean inDevelopmentMode = false;
22     static protected String JavaDoc[] devDefaultClasspath;
23     static protected Properties devProperties = null;
24
25     static {
26         // Check the osgi.dev property to see if dev classpath entries have been
27
// defined.
28
String JavaDoc osgiDev = System.getProperty("osgi.dev"); //$NON-NLS-1$
29
if (osgiDev != null) {
30             try {
31                 inDevelopmentMode = true;
32                 URL location = new URL(osgiDev);
33                 devProperties = load(location);
34                 if (devProperties != null)
35                     devDefaultClasspath = getArrayFromList(devProperties
36                             .getProperty("*")); //$NON-NLS-1$
37
} catch (MalformedURLException e) {
38                 devDefaultClasspath = getArrayFromList(osgiDev);
39             }
40         }
41     }
42
43     public static String JavaDoc[] getDevClassPath(String JavaDoc id) {
44         String JavaDoc[] result = null;
45         if (id != null && devProperties != null) {
46             String JavaDoc entry = devProperties.getProperty(id);
47             if (entry != null)
48                 result = getArrayFromList(entry);
49         }
50         if (result == null)
51             result = devDefaultClasspath;
52         return result;
53     }
54
55     /**
56      * Returns the result of converting a list of comma-separated tokens into an
57      * array
58      *
59      * @return the array of string tokens
60      * @param prop
61      * the initial comma-separated string
62      */

63     public static String JavaDoc[] getArrayFromList(String JavaDoc prop) {
64         if (prop == null || prop.trim().equals("")) //$NON-NLS-1$
65
return new String JavaDoc[0];
66         Vector list = new Vector();
67         StringTokenizer tokens = new StringTokenizer(prop, ","); //$NON-NLS-1$
68
while (tokens.hasMoreTokens()) {
69             String JavaDoc token = tokens.nextToken().trim();
70             if (!token.equals("")) //$NON-NLS-1$
71
list.addElement(token);
72         }
73         return list.isEmpty() ? new String JavaDoc[0] : (String JavaDoc[]) list
74                 .toArray(new String JavaDoc[list.size()]);
75     }
76
77     public static boolean inDevelopmentMode() {
78         return inDevelopmentMode;
79     }
80
81     /*
82      * Load the given properties file
83      */

84     private static Properties load(URL url) {
85         Properties props = new Properties();
86         try {
87             InputStream is = null;
88             try {
89                 is = url.openStream();
90                 props.load(is);
91             } finally {
92                 if (is != null)
93                     is.close();
94             }
95         } catch (IOException e) {
96             AppserverPlugin.logError("Help failed to load properties file " + url, e); //$NON-NLS-1$
97
}
98         return props;
99     }
100 }
101
Popular Tags