[Yanel-commits] rev 59539 - public/yanel/trunk/src/core/java/org/wyona/yanel/core

michi at wyona.com michi at wyona.com
Sat Jul 23 00:56:47 CEST 2011


Author: michi
Date: 2011-07-23 00:56:46 +0200 (Sat, 23 Jul 2011)
New Revision: 59539

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java
Log:
also check resource definitions called resource-*.xml

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java	2011-07-22 15:54:38 UTC (rev 59538)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceTypeRegistry.java	2011-07-22 22:56:46 UTC (rev 59539)
@@ -154,7 +154,7 @@
             Configuration resourceTypes[] = config.getChildren("resource-type");
             
             for (int i = 0; i < resourceTypes.length; i++) {
-                log.debug("Register resource type...");
+                log.debug("Try to register resource type(s)...");
                 boolean hasPackageAttribute = false;
                 String packageName = null;
                 try {
@@ -165,7 +165,7 @@
                     hasPackageAttribute = false;
                 }
                 if (hasPackageAttribute && packageName != null && packageName.trim().length() > 0) {
-                    log.info("Loading resource from package: " + packageName);
+                    log.info("Loading resource(s) from package: " + packageName);
 
                     // TODO: Config itself, e.g. org/wyona/yanel/impl/resources/redirect/my-resource.xml (What does that TODO mean?!)
 
@@ -200,9 +200,13 @@
                             }
                         }
                     } else if (new File(packageURL.getPath()).isDirectory()) {
-                        log.warn("TODO: ...");
+                        log.debug("Library seems to be extracted: " + packageURL.getPath());
+                        String[] resourceFilenames = new File(packageURL.getPath()).list(new ResourceFilenameFilter());
+                        if (resourceFilenames != null && resourceFilenames.length > 0) {
+                            for (int k = 0; k < resourceFilenames.length; k++) {
                                 try {
-                                    ResourceTypeDefinition rtd = new ResourceTypeDefinition(new java.io.FileInputStream(new File(packageURL.getPath(), "resource.xml")));
+                                    ResourceTypeDefinition rtd = new ResourceTypeDefinition(new java.io.FileInputStream(new File(packageURL.getPath(), resourceFilenames[k])));
+                                    log.debug("Register resource type from resource definition: " + rtd.getConfigFile());
                                     log.debug("Universal Name: " + rtd.getResourceTypeUniversalName());
                                     log.debug("Classname: " + rtd.getResourceTypeClassname());
                                     hm.put(rtd.getResourceTypeUniversalName(), rtd);
@@ -210,6 +214,10 @@
                                     log.error("Exception re registring resource with package '" + packageName + "'!");
                                     log.error(exception, exception);
                                 }
+                            }
+                        } else {
+                            log.error("Extracted jar '" +packageURL.getPath() + "' does not seem to contain any resource definitions!");
+                        }
                     } else {
                         log.error("No such file or directory: " + packageURL.getPath());
                     }
@@ -310,3 +318,19 @@
         return CONFIGURATION_FILE;
     }
 }
+
+/**
+ * File name filter in order to get resource definitions
+ */
+class ResourceFilenameFilter implements java.io.FilenameFilter {
+
+    /**
+     * @see java.io.FilenameFilter#accept(File, String)
+     */
+    public boolean accept(File dir, String name) {
+        if (name.equals("resource.xml") || (name.startsWith("resource-") && name.endsWith(".xml"))) {
+            return true;
+        }
+        return false;
+    }
+}



More information about the Yanel-commits mailing list