Author: gvanmatre
Date: Thu Dec 29 21:06:39 2005
New Revision: 359989

URL: http://svn.apache.org/viewcvs?rev=359989&view=rev
Log:
Applied a fix for bug #38058 and an enhancement that allows full clay XML views 
to be loaded on startup.  

Added:
    
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address-fullxml.xml
   (with props)
Modified:
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
    
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
    
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.xml
    struts/shale/trunk/use-cases/src/web/WEB-INF/web.xml

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties?rev=359989&r1=359988&r2=359989&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties 
(original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties 
Thu Dec 29 21:06:39 2005
@@ -21,6 +21,7 @@
 config.load.begin=Begin loading config files.
 config.load.done=Done loading config file(s).
 config.destroy=Unloading config cache.
+config.deprecated.param=Initialization parameter "{0}" has been deprecated.  
Use initialization parameter "{1}" going forward.
 
 #org.apache.shale.clay.config.ClayXmlParser
 parser.load.file=Loading file "{0}".

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java?rev=359989&r1=359988&r2=359989&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java
 Thu Dec 29 21:06:39 2005
@@ -39,8 +39,35 @@
      * <br>
      * The configuration files should conform to the clay-config_x_x.dtd
      *</p>
+     * @deprecated use CLAY_COMMON_CONFIG_FILES 
      */
     public static final String CLAY_CONFIG_FILES = "clay-config-files";
+
+    /**
+     *<p>Name of the initialization parameter in the web deployment descriptor 
+     *containing additional registered configuration files.  These files 
represent 
+     *common component definitions that are not full view XML templates.   
Common 
+     *component definitions should have jsfid's that don't have a ".xml" or 
+     *".html" suffix.  The list of files should be comma delimited and the 
path 
+     *relative to the context root.
+     *<br>
+     *The configuration files should conform to the clay-config_x_x.dtd.
+     *</p>
+     */
+    public static final String CLAY_COMMON_CONFIG_FILES = 
"org.apache.shale.clay.COMMON_CONFIG_FILES";
+   
+
+    /**
+     *<p>Name of the initialization parameter in the web deployment descriptor 
+     *containing additional registered configuration files.  These files 
represent 
+     *common component definitions that are full view XML templates.   
+     *The list of files should be comma delimited and the path relative to the 
context root.
+     *<br>
+     *The configuration files should conform to the clay-config_x_x.dtd.
+     *</p>
+     */
+    public static final String CLAY_FULLXML_CONFIG_FILES = 
"org.apache.shale.clay.FULLXML_CONFIG_FILES";
+
     
     /**
      * <p>The name of the initialization parameter defined in the
@@ -49,7 +76,7 @@
      * This suffix identifies a jsfid that uses HTML to define page 
composition.
      * </p>
      */
-    public static final String CLAY_HTML_TEMPLATE_SUFFIX = 
"clay-html-template-suffix";
+    public static final String CLAY_HTML_TEMPLATE_SUFFIX = 
"org.apache.shale.clay.HTML_TEMPLATE_SUFFIX";
 
     
     /**
@@ -59,7 +86,7 @@
      * This suffix identifies a jsfid that uses full XML views to define page 
composition.
      * </p>
      */
-    public static final String CLAY_XML_TEMPLATE_SUFFIX = 
"clay-xml-template-suffix";
+    public static final String CLAY_XML_TEMPLATE_SUFFIX = 
"org.apache.shale.clay.XML_TEMPLATE_SUFFIX";
     
    
     /**
@@ -71,7 +98,7 @@
      * a change occures.
      * </p>
      */
-    public static final String AUTO_RELOAD_CLAY_FILES = 
"auto-reload-clay-files";
+    public static final String AUTO_RELOAD_CLAY_FILES = 
"org.apache.shale.clay.AUTO_RELOAD_CONFIG_FILES";
     
     
     /**
@@ -201,7 +228,8 @@
     public static final String CLAY_FULL_VIEW_RESTORE_IND = 
"org.apache.shale.clay.forward";
     
     /**
-     * 
+     * <p>The clay component attribute name that will capture the 
ComponentBean representing the root 
+     * of the subtree.  The root is capture for enhanced error reporting.</p> 
      */
     public static final String CLAY_RESERVED_ATTRIBUTE = 
"org.apache.shale.clay";
     

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java?rev=359989&r1=359988&r2=359989&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
 Thu Dec 29 21:06:39 2005
@@ -163,9 +163,21 @@
         String param = context.getInitParameter(Globals.CLAY_CONFIG_FILES);
         
         // add the default config file
+        if (param != null && param.trim().length() > 0) {
+            configFiles.append(", ").append(param);
+            
+            log.warn(messages.getMessage("config.deprecated.param", 
+                     new Object[] {Globals.CLAY_CONFIG_FILES, 
+                                   Globals.CLAY_COMMON_CONFIG_FILES}));
+        }
+
+        // a comma delimited value list of config files
+        param = context.getInitParameter(Globals.CLAY_COMMON_CONFIG_FILES);
         if (param != null && param.trim().length() > 0)
             configFiles.append(", ").append(param);
 
+    
+    
         // pass the config bean to the parser
         parser.setConfig(this);
         

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java?rev=359989&r1=359988&r2=359989&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java
 Thu Dec 29 21:06:39 2005
@@ -18,9 +18,12 @@
 
 package org.apache.shale.clay.config.beans;
 
+import java.util.Iterator;
+import java.util.Map;
 import java.util.TreeMap;
 
 import org.apache.shale.clay.config.ClayXmlParser;
+import org.apache.shale.clay.config.Globals;
 
 /**
  * <This ConfigBean is responsible for handling full XML views.  For full XML 
views, 
@@ -47,10 +50,86 @@
      * [EMAIL PROTECTED] 
org.apache.shale.clay.config.beans.ComponentConfigBean$WatchDog}'s.</p>
      */
     protected void loadConfigFiles() {
-        parser = new ClayXmlParser(); 
+        
+        parser = new ClayXmlParser();
         parser.setConfig(this);
         
+        // a comma delimited value list of config files
+        String param = 
context.getInitParameter(Globals.CLAY_FULLXML_CONFIG_FILES);
+    
+        // pass the config bean to the parser
+        parser.setConfig(this);
+        
+        // map holding the resource watchers
         watchDogs = new TreeMap();
+
+        
+        if (param != null && param.length() > 0) {
+            // create the watch dog with a list of config files to look for 
changes
+            WatchDog watchDog = new WatchDog(getConfigDefinitions(param),
+                    Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG);
+
+            // adds the watcher to a map identified by name
+            watchDogs.put(watchDog.getName(), watchDog);
+
+            // loads the config files
+            watchDog.refresh(true);
+        }
+        
+        param = null;
+    }
+    
+    
+    /**
+     * <p>If the <code>forceReload</code> is <code>true</code>,
+     * the <code>displayElements</code> cache is invalidated.
+     * A <code>true</code> value is returned if cache has
+     * been cleared.
+     * <br/><br/>
+     * All files loaded on-demand are purged.  Full view definitions 
+     * loaded using the <code>Globals.CLAY_FULLXML_CONFIG_FILES</code> 
+     * initialization parameter are reloaded if modified or if a 
+     * <code>forceReload</code> is specified.</p>
+     * 
+     */
+    public boolean refresh(boolean forceReload) {
+        boolean wasDirty = forceReload;
+        
+        //look for a default watch of full view config files
+        WatchDog defaultWatchDog = (WatchDog) 
watchDogs.get(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG);
+                
+        //clear out all the on-demand beans
+        if (forceReload) {
+
+            //remove from the list without the clean-up
+            if (defaultWatchDog != null)
+               watchDogs.remove(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG);
+
+            // remove all old templates
+            Iterator wi = watchDogs.entrySet().iterator();
+            while (wi.hasNext()) {
+                Map.Entry e = (Map.Entry) wi.next();
+                WatchDog watchDog = (WatchDog) e.getValue();
+                clear(watchDog.getName());
+                if (watchDog != null)
+                    watchDog.destroy(); 
+            }
+            watchDogs.clear();
+            
+            //push back into the list
+            if (defaultWatchDog != null)
+               watchDogs.put(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG, 
defaultWatchDog);
+
+        }
+        
+        //check for dirty cache
+        if (defaultWatchDog != null) {
+           synchronized (displayElements) {
+               wasDirty = defaultWatchDog.refresh(forceReload);
+           }
+        }
+
+        return wasDirty;
     }
     
     

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java?rev=359989&r1=359988&r2=359989&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
 Thu Dec 29 21:06:39 2005
@@ -61,6 +61,11 @@
 
         // look for a watcher identified by the template name
         WatchDog watchDog = (WatchDog) watchDogs.get(jsfid.toString());
+        
+        //if a watcher doesn't exist, check for a common 
+        if (watchDog == null)
+            watchDog = (WatchDog) 
watchDogs.get(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG);
+        
         if (watchDog == null || super.getElement(jsfid.toString()) == null) {
            //The first time the page is created, create a watcher 
               
@@ -68,11 +73,11 @@
            
            // register by name
            watchDogs.put(watchDog.getName(), watchDog);
+           
+           //loads the HTML template the first time and when file 
+           //has been modified
+           watchDog.refresh(false);
         }
-        
-        //loads the HTML template the first time and when file 
-        //has been modified
-        watchDog.refresh(false);
         
         // returns the cached element
         return super.getElement(jsfid.toString());

Modified: 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java?rev=359989&r1=359988&r2=359989&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
 Thu Dec 29 21:06:39 2005
@@ -122,8 +122,13 @@
         super.setUp();
 
         // Configure document root for tests
-        servletContext.setDocumentRoot
-            (new File(System.getProperty("documentRoot")));
+        String documentRoot = System.getProperty("documentRoot");
+        if (documentRoot == null) {
+            documentRoot = System.getProperty("user.dir") + 
"\\WebContent\\WEB-INF\\classes";           
+        }
+        servletContext.setDocumentRoot(new File(documentRoot));
+        
+        
 
         //load the mock config data
         loadComponents();
@@ -138,16 +143,13 @@
        
         // creates the component metadata container from the xml config files
         standardConfigBean = new ComponentConfigBean();
-        standardConfigBean.init(servletContext);
-        
         // creates a container that builds the component metadata from an HTML 
 
         // template configuration.
         htmlTemplateConfigBean = new TemplateConfigBean();
-        htmlTemplateConfigBean.init(servletContext);
-
+        // full xml view support
         xmlTemplateConfigBean = new TemplateComponentConfigBean();
-        xmlTemplateConfigBean.init(servletContext);
 
+        
         // register with the factory
         ConfigBeanFactory.register(standardConfigBean);
         ConfigBeanFactory.register(htmlTemplateConfigBean);
@@ -165,11 +167,23 @@
         xmlTemplateConfigBean = null;
     }
 
+    
+    // loads the config files
+    protected void loadConfigFile(String commonConfigFiles) {
+        loadConfigFiles(commonConfigFiles, null);
+    }
+    
     // loads the config files
-    protected void loadConfigFile(String configFiles) {
+    protected void loadConfigFiles(String commonConfigFiles, String 
fullXmlConfigFiles) {
         // this would be done in the ClayConfigureListener
         
-        servletContext.addInitParameter(Globals.CLAY_CONFIG_FILES, 
configFiles);        
+        if (commonConfigFiles !=  null)
+           servletContext.addInitParameter(Globals.CLAY_COMMON_CONFIG_FILES, 
commonConfigFiles);  
+        
+        if (fullXmlConfigFiles != null) {
+           servletContext.addInitParameter(Globals.CLAY_FULLXML_CONFIG_FILES, 
fullXmlConfigFiles);  
+        }
+        
         standardConfigBean.init(servletContext);
         htmlTemplateConfigBean.init(servletContext);
         xmlTemplateConfigBean.init(servletContext);
@@ -392,13 +406,13 @@
         
     }
 
-    //test a full xml view including a html template
-    public void testLoadXMLFile() {
+    //test a full xml view including a html template (on-demand)
+    public void testLoadXMLFileOnDemand() {
         
         //loads the default and the custom address config file
         loadConfigFile("/org/apache/shale/clay/config/address-config.xml");
         
-        ComponentBean bean = 
xmlTemplateConfigBean.getElement("org/apache/shale/clay/config/address.xml"); 
+        ComponentBean bean = 
xmlTemplateConfigBean.getElement("/org/apache/shale/clay/config/address.xml"); 
         assertNotNull(bean);
         
         Iterator ci = bean.getChildrenIterator();
@@ -426,9 +440,52 @@
                 checkComponent(child, CUSTOM_HTML_COMPONENTS); 
             }
         } 
-        
     }
    
+    
+    //test a full xml view centralized config loaded on startup that 
+    //includes a html template (global template file)
+    public void testLoadXMLFileGlobal() {
+        
+        // loads the default and the custom address config file.
+        // loads a centralized full view config file.   
+        loadConfigFiles("/org/apache/shale/clay/config/address-config.xml", 
+                        "/org/apache/shale/clay/config/address-fullxml.xml");
+        
+        //loaded on startup, this call will just retrieve a loaded definitions
+        //the jsfid doesn't match the name of the config file, a requirement
+        //for on-demand full xml views
+        ComponentBean bean = 
xmlTemplateConfigBean.getElement("/address2.xml"); 
+        assertNotNull(bean);
+        
+        Iterator ci = bean.getChildrenIterator();
+        while (ci.hasNext()) {
+            ElementBean child = (ElementBean) ci.next();
+            
+            AttributeBean attr = null;
+            if (child.getId().equals("htmlBegin")) {
+                attr = child.getAttribute("value");
+                assertEquals(attr.getValue(), "<html>");
+            } else if (child.getId().equals("htmlEnd")) {
+                attr = child.getAttribute("value");
+                assertEquals(attr.getValue(), "</html>");
+            } else if (child.getId().equals("header")) {
+                attr = child.getAttribute("value");
+                assertEquals(attr.getValue(), 
"<head><title>Testing</title></head>");
+            } else if (child.getId().equals("bodyBegin")) {
+                attr = child.getAttribute("value");
+                assertEquals(attr.getValue(), "<body>");
+            } else if (child.getId().equals("bodyEnd")) {
+                attr = child.getAttribute("value");
+                assertEquals(attr.getValue(), "</body>");
+            } else if (child.getId().equals("content")) {
+                //look for a component that we have setup to test
+                checkComponent(child, CUSTOM_HTML_COMPONENTS); 
+            }
+        } 
+        
+    }
+    
  
     // checks a meta components realized state against the assumed values
     protected void checkComponent(ComponentBean bean, Object[] 
knownGoodStates) {
@@ -747,7 +804,7 @@
     public void testDuplicateComponentIds() {
         
         // loads the default and the custom address config file
-        loadConfigFile("org/apache/shale/clay/config/address-config.xml");
+        loadConfigFile("/org/apache/shale/clay/config/address-config.xml");
         
         try {
             ComponentBean bean = 
htmlTemplateConfigBean.getElement("org/apache/shale/clay/config/duplicate1.html");

Added: 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address-fullxml.xml
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address-fullxml.xml?rev=359989&view=auto
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address-fullxml.xml
 (added)
+++ 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address-fullxml.xml
 Thu Dec 29 21:06:39 2005
@@ -0,0 +1,20 @@
+<?xml version='1.0' encoding="UTF-8"?>
+
+  <!DOCTYPE view PUBLIC
+      "-//Apache Software Foundation//DTD Shale Clay View Configuration 
1.0//EN"
+      "http://struts.apache.org/dtds/shale-clay-config_1_0.dtd";>
+
+<view>
+
+  <component jsfid="/address.xml" extends="layout" >
+        <!--  override body content -->   
+        <element id="content" renderId="10" jsfid="clay"> 
+            <attributes>
+               <set name="clayJsfid" 
value="/org/apache/shale/clay/config/address.xml"/>
+            </attributes>
+        </element>     
+  </component> 
+  
+  <component jsfid="/address2.xml" extends="/address.xml"/>  
+
+</view>
\ No newline at end of file

Propchange: 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address-fullxml.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address-fullxml.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.xml
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.xml?rev=359989&r1=359988&r2=359989&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.xml
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.xml
 Thu Dec 29 21:06:39 2005
@@ -14,5 +14,5 @@
             </attributes>
         </element>     
   </component> 
-
+  
 </view>

Modified: struts/shale/trunk/use-cases/src/web/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/web/WEB-INF/web.xml?rev=359989&r1=359988&r2=359989&view=diff
==============================================================================
--- struts/shale/trunk/use-cases/src/web/WEB-INF/web.xml (original)
+++ struts/shale/trunk/use-cases/src/web/WEB-INF/web.xml Thu Dec 29 21:06:39 
2005
@@ -46,7 +46,7 @@
   
    <!-- Clay Configuration Resources -->
    <context-param>
-      <param-name>clay-config-files</param-name>
+      <param-name>org.apache.shale.clay.COMMON_CONFIG_FILES</param-name>
       <param-value>/WEB-INF/clay-config.xml</param-value>
    </context-param>
   



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to