Author: craigmcc
Date: Sun Sep  3 17:30:55 2006
New Revision: 439885

URL: http://svn.apache.org/viewvc?view=rev&rev=439885
Log:
Improve parsing of dialog-config.xml files to include any specified in
the META-INF directory of a JAR file included in the application.  For
consistency with the way JSF implementations handle faces-config.xml
files, these resources are parsed first, followed by any explicitly
configured resources in web.xml, followed by the default
(/WEB-INF/dialog-config.xml) resource, if it exists and has not been
parsed yet.

Modified:
    
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java

Modified: 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java?view=diff&rev=439885&r1=439884&r2=439885
==============================================================================
--- 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java
 (original)
+++ 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java
 Sun Sep  3 17:30:55 2006
@@ -18,7 +18,9 @@
 
 import java.io.Serializable;
 import java.net.URL;
+import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import javax.faces.FacesException;
 import javax.faces.context.FacesContext;
@@ -52,6 +54,14 @@
 
 
     /**
+     * <p>Resource name for dialog configuration resource(s) embedded in
+     * JAR files inside the application.</p>
+     */
+    private static final String EMBEDDED_CONFIGURATION_RESOURCE =
+            "META-INF/dialog-config.xml";
+
+
+    /**
      * <p><code>Map</code> of [EMAIL PROTECTED] Dialog} configurations, keyed
      * by dialog name.  This value is lazily instantiated, and is also
      * transient and may need to be regenerated.</p>
@@ -79,7 +89,7 @@
     private int serial = 0;
 
 
-    // ------------------------------------------------------- 
DialogContextManager Methods
+    // -------------------------------------------- DialogContextManager 
Methods
 
 
     /** [EMAIL PROTECTED] */
@@ -141,10 +151,34 @@
             return this.dialogs;
         }
 
-        // Parse our specified configuration resources and cache the results
+        // Set up to parse our specified configuration resources and cache the 
results
         boolean didDefault = false;
         ConfigurationParser parser = new ConfigurationParser();
         parser.setDialogs(new HashMap());
+
+        // Parse implicitly specified resources embedded in JAR files
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        if (loader == null) {
+            loader = this.getClass().getClassLoader();
+        }
+        try {
+            Enumeration resources = 
loader.getResources(EMBEDDED_CONFIGURATION_RESOURCE);
+            while (resources.hasMoreElements()) {
+                URL resource = (URL) resources.nextElement();
+                if (log().isDebugEnabled()) {
+                    log().debug("Parsing configuration resource '"
+                            + resource + "'");
+                }
+                parser.setResource(resource);
+                parser.parse();
+            }
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }
+
+        // Parse explicitly specified resources
         String resources =
           context.getExternalContext().getInitParameter(Globals.CONFIGURATION);
         if (resources == null) {
@@ -169,7 +203,12 @@
                 if (path.length() < 1) {
                     break;
                 }
-                
parser.setResource(context.getExternalContext().getResource(path));
+                URL resource = (URL) 
context.getExternalContext().getResource(path);
+                if (log().isDebugEnabled()) {
+                    log().debug("Parsing configuration resource '"
+                            + resource + "'");
+                }
+                parser.setResource(resource);
                 parser.parse();
                 if (DEFAULT_CONFIGURATION_RESOURCE.equals(path)) {
                     didDefault = true;
@@ -188,6 +227,10 @@
                 URL resource =
                   
context.getExternalContext().getResource(DEFAULT_CONFIGURATION_RESOURCE);
                 if (resource != null) {
+                    if (log().isDebugEnabled()) {
+                        log().debug("Parsing configuration resource '"
+                                + resource + "'");
+                    }
                     parser.setResource(resource);
                     parser.parse();
                 }


Reply via email to