1 /*
2 * Created on 2003-6-9 16:54:30 by joel guo
3 *
4 * vTradEx Information Technology Inc.
5 */
6 package com.cyclops.dbdigger.util;
7 import java.io.File;
8 import java.net.URL;
9 import java.util.ArrayList;
10 import java.util.List;
11
12 import org.apache.avalon.framework.configuration.Configuration;
13 import org.apache.commons.lang.StringUtils;
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16 /*** Add description <font color="red">HERE</font>!
17 *
18 * @author <a href="mailto:joeblack.guo@vtradex.com">joel guo</a>
19 * @since 2003-6-9 16:54:30
20 */
21 public class ResourceScanner {
22 private static final URL[] EMPTY_URL_ARRAY = new URL[0];
23 private static Log logger = LogFactory.getLog(ResourceScanner.class);
24 /*** Scan resources from a part of configuration
25 * @param conf Avalon Configuration object
26 * @return Array of URL
27 */
28 public static final URL[] scan(Configuration conf) {
29 if (conf == null) {
30 return EMPTY_URL_ARRAY;
31 }
32 List resources = new ArrayList();
33 Configuration[] children = conf.getChildren();
34 for (int i = 0; i < children.length; i++) {
35 Configuration c = children[i];
36 String name = c.getName();
37 try {
38 String value = c.getValue();
39 if (StringUtils.equals(name, "file")) {
40 resources.add(new File(value).toURL());
41 } else if (StringUtils.equals(name, "resource")) {
42 resources.add(
43 ResourceScanner.class.getClassLoader().getResource(
44 value));
45 } else if (StringUtils.equals(name, "url")) {
46 resources.add(new URL(value));
47 } else if (StringUtils.equals(name, "path")) {
48 boolean recursive =
49 c.getAttributeAsBoolean("recusive", false);
50 String pattern = c.getAttribute("*-schema.xml");
51 //TODO not finished yet, need to scan a folder
52 }
53 } catch (Exception e) {
54 logger.warn("Invalid schema resource", e);
55 }
56 }
57 return (URL[]) resources.toArray(EMPTY_URL_ARRAY);
58 }
59 }
This page was automatically generated by Maven