|
From: <tr...@us...> - 2003-09-17 16:40:51
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core
In directory sc8-pr-cvs1:/tmp/cvs-serv25560
Modified Files:
ResourceLoader.java
Log Message:
changed the classpath to searched first when getting resources. Did a little clean-up.
Index: ResourceLoader.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/ResourceLoader.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ResourceLoader.java 16 Sep 2003 05:19:00 -0000 1.8
--- ResourceLoader.java 17 Sep 2003 16:40:44 -0000 1.9
***************
*** 76,79 ****
--- 76,80 ----
import java.util.ArrayList;
import java.util.Iterator;
+ import java.util.List;
import java.util.jar.JarFile;
***************
*** 118,122 ****
*/
public static URL getFirstMatchingUrlInSearchPath(String name,
! ArrayList searchPath) {
URL[] urls = getN_MatchingUrlsInSearchPath(name, searchPath, 1);
--- 119,123 ----
*/
public static URL getFirstMatchingUrlInSearchPath(String name,
! List searchPath) {
URL[] urls = getN_MatchingUrlsInSearchPath(name, searchPath, 1);
***************
*** 137,141 ****
*/
public static URL[] getMatchingUrlsInSearchPath(String name,
! ArrayList searchPath) {
return getN_MatchingUrlsInSearchPath(name, searchPath, Integer.MAX_VALUE);
}
--- 138,142 ----
*/
public static URL[] getMatchingUrlsInSearchPath(String name,
! List searchPath) {
return getN_MatchingUrlsInSearchPath(name, searchPath, Integer.MAX_VALUE);
}
***************
*** 301,315 ****
/**
- * Simple tester
- *
- * @param args DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
- public static void main(String[] args) throws IOException {
- System.out.println(getResourceString(getUrl(args[0])));
- }
-
- /**
* Convert the file to a url
*
--- 302,305 ----
***************
*** 333,349 ****
/**
* Utility method to load at least number entries into the array of urls to
! * return. Note that it may return number+1 because it searches in the
! * classpath.
*
! * @param name
! * @param searchPath
! * @param number
*
* @return
*/
private static URL[] getN_MatchingUrlsInSearchPath(String name,
! ArrayList searchPath, int number) {
! ArrayList list = new ArrayList();
if (searchPath.size() > 0) {
for (Iterator i = searchPath.iterator(); i.hasNext() && (number > 0);) {
--- 323,388 ----
/**
* Utility method to load at least number entries into the array of urls to
! * return.
*
! * @param name of the resource to search for
! * @param searchPath the babeldoc module search path
! * @param number maximum number of matches to find.
*
* @return
*/
private static URL[] getN_MatchingUrlsInSearchPath(String name,
! List searchPath, int number) {
! List list = new ArrayList();
+ if(number > 0) {
+ number = getN_ResourceInClassPath(name, list, number);
+ }
+
+ if(number>0) {
+ number = getN_ResourceInSearchPath(searchPath, number, name, list);
+ }
+
+ if(number>0) {
+ number = getN_ResourceInModules(name, list, number);
+ }
+
+ return (URL[]) list.toArray(new URL[0]);
+ }
+
+ /**
+ * Search the babeldoc modules for at least a number of matches.
+ *
+ * @param name of the resource to search for
+ * @param list the list to add entries
+ * @param number maximum number of matches to find.
+ * @return
+ */
+ private static int getN_ResourceInModules(String name, List list, int number) {
+ // Now getChild the name from the modules
+ BabeldocModule[] modules = BabeldocModuleList.getInstance()
+ .getSortedModules();
+
+ for (int i = modules.length - 1; i >= 0 && (number > 0); --i) {
+ String moduleConfig = modules[i].getName() + "/" + name;
+
+ URL url = Thread.currentThread().getContextClassLoader().getResource(moduleConfig);
+ if(url!=null) {
+ list.add(url);
+ --number;
+ }
+ }
+ return number;
+ }
+
+ /**
+ * Search for a resource in the search path
+ *
+ * @param searchPath
+ * @param number
+ * @param name
+ * @param list
+ * @return
+ */
+ private static int getN_ResourceInSearchPath(List searchPath, int number, String name, List list) {
if (searchPath.size() > 0) {
for (Iterator i = searchPath.iterator(); i.hasNext() && (number > 0);) {
***************
*** 391,416 ****
}
}
! // Now get the name from the modules
! BabeldocModule[] modules = BabeldocModuleList.getInstance()
! .getSortedModules();
!
! for (int i = modules.length - 1; i >= 0; --i) {
! String moduleConfig = modules[i].getName() + "/" + name;
!
! URL url = Thread.currentThread().getContextClassLoader().getResource(moduleConfig);
! if(url!=null) {
! list.add(url);
! }
! }
!
! // Add the classpath url to the search path.
URL cpUrl = Thread.currentThread().getContextClassLoader().getResource(name);
if (cpUrl != null) {
list.add(cpUrl);
}
! return (URL[]) list.toArray(new URL[0]);
}
}
--- 430,463 ----
}
}
+ return number;
+ }
! /**
! * Search for resource in the classpath
! *
! * @param name
! * @param list
! * @param number
! * @return
! */
! private static int getN_ResourceInClassPath(String name, List list, int number) {
URL cpUrl = Thread.currentThread().getContextClassLoader().getResource(name);
if (cpUrl != null) {
list.add(cpUrl);
+ number--;
}
+ return number;
+ }
! /**
! * Simple test
! *
! * @param args
! *
! * @throws IOException
! */
! public static void main(String[] args) throws IOException {
! System.out.println(getResourceString(getUrl(args[0])));
}
}
|