cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r562896 - in /cocoon/trunk: blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/accessor/ blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ blocks/cocoon-tem...
Date Sun, 05 Aug 2007 15:41:59 GMT
Author: gkossakowski
Date: Sun Aug  5 08:41:58 2007
New Revision: 562896

URL: http://svn.apache.org/viewvc?view=rev&rev=562896
Log:
COCOON-2103:
  * Moved fillContext method from FlowObjectModelHelper to the ObjectModelImpl class and introduced
this method in ObjectModel interface so it becomes official API.
  * Commented out call of fillContext method in FlowAttributeAccessor. This class is not used
so nothing will break.
  * Adapted Import instruction to the new location of fillContext.
  * Adapted JXTemplateGeneratorTestCase to the new initialization of Object Model passed to
the JXTemplateGenerator.

Modified:
    cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/accessor/FlowAttributeAccessor.java
    cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java
    cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/test/java/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/FlowHelper.java

Modified: cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/accessor/FlowAttributeAccessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/accessor/FlowAttributeAccessor.java?view=diff&rev=562896&r1=562895&r2=562896
==============================================================================
--- cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/accessor/FlowAttributeAccessor.java
(original)
+++ cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/accessor/FlowAttributeAccessor.java
Sun Aug  5 08:41:58 2007
@@ -20,7 +20,6 @@
 import java.util.Map;
 
 import org.apache.cocoon.components.flow.FlowHelper;
-import org.apache.cocoon.template.environment.FlowObjectModelHelper;
 
 /**
  * @version $Id$
@@ -37,7 +36,8 @@
         if (contextObject instanceof Map) {
             map.putAll((Map)contextObject);
         } else if (contextObject != null) {
-            FlowObjectModelHelper.fillContext(contextObject, map);
+            //FIXME: I commented out this call to avoid compilation errors, do we need this
class at all? (GK)
+            //ObjectModelImpl.fillContext(contextObject, map);
         }
 
         return map;

Modified: cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java?view=diff&rev=562896&r1=562895&r2=562896
==============================================================================
--- cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java
(original)
+++ cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java
Sun Aug  5 08:41:58 2007
@@ -21,9 +21,9 @@
 
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.objectmodel.ObjectModel;
+import org.apache.cocoon.objectmodel.ObjectModelImpl;
 import org.apache.cocoon.template.environment.ErrorHolder;
 import org.apache.cocoon.template.environment.ExecutionContext;
-import org.apache.cocoon.template.environment.FlowObjectModelHelper;
 import org.apache.cocoon.template.environment.ParsingContext;
 import org.apache.cocoon.template.expression.JXTExpression;
 import org.apache.cocoon.template.expression.Literal;
@@ -126,7 +126,7 @@
             try {
                 Object obj = this.select.getValue(objectModel);
                 objectModel.put(ObjectModel.CONTEXTBEAN, obj);
-                FlowObjectModelHelper.fillContext(obj, objectModel);
+                objectModel.fillContext();
             } catch (Exception exc) {
                 throw new SAXParseException(exc.getMessage(), getLocation(), exc);
             } catch (Error err) {

Modified: cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/test/java/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/test/java/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java?view=diff&rev=562896&r1=562895&r2=562896
==============================================================================
--- cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/test/java/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java
(original)
+++ cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/test/java/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java
Sun Aug  5 08:41:58 2007
@@ -34,6 +34,7 @@
     String docBase = "resource://org/apache/cocoon/template/jxtg/";
     String JX = "jx";
     Map flowContext = new HashMap();
+    ObjectModel newObjectModel;
 
     public class StringContainer {
         private String value;
@@ -54,14 +55,20 @@
     public void setUp() throws Exception {
         super.setUp();
 
-        // Make the FOM objects available to the view layer
-        ObjectModel newObjectModel = (ObjectModel)getBeanFactory().getBean(ObjectModel.ROLE);
-        FlowHelper.setContextObject(getObjectModel(), newObjectModel, flowContext);
+        newObjectModel = (ObjectModel)getBeanFactory().getBean(ObjectModel.ROLE);
     }
 
     public Map getFlowContext() {
         return this.flowContext;
     }
+    
+    public void addFlowContextToObjectModel(ObjectModel newObjectModel) {
+        FlowHelper.setContextObject(getObjectModel(), newObjectModel, flowContext);
+    }
+    
+    public ObjectModel getNewObjectModel() {
+        return this.newObjectModel;
+    }
 
     public void testGenerate() throws Exception {
         String inputURI = docBase + "generate.xml";
@@ -80,10 +87,15 @@
         String inputURI = docBase + "jexlEnvExpression.xml";
         String outputURI = docBase + "jexlEnvExpression-output.xml";
 
+        getNewObjectModel().markLocalContext();
         Parameters parameters = new Parameters();
         parameters.setParameter("test", "foo");
         getFlowContext().put("test", "bar");
+        addFlowContextToObjectModel(getNewObjectModel());
+        
         assertEqual(load(outputURI), generate(JX, inputURI, parameters));
+        
+        getNewObjectModel().cleanupLocalContext();
     }
 
     public void testJXPathExpression() throws Exception {
@@ -97,11 +109,16 @@
         String inputURI = docBase + "jxpathEnvExpression.xml";
         String outputURI = docBase + "jxpathEnvExpression-output.xml";
 
+        getNewObjectModel().markLocalContext();
         Parameters parameters = new Parameters();
         parameters.setParameter("test", "foo");
         getFlowContext().put("test", "bar");
+        addFlowContextToObjectModel(getNewObjectModel());
+        
         assertEquals("HTTP/1.1", getRequest().getProtocol());
         assertEqual(load(outputURI), generate(JX, inputURI, parameters));
+        
+        getNewObjectModel().cleanupLocalContext();
     }
 
     public void testJXChoose() throws Exception {
@@ -115,17 +132,27 @@
         String inputURI = docBase + "jxForEach.xml";
         String outputURI = docBase + "jxForEach-output.xml";
 
+        getNewObjectModel().markLocalContext();
         String[] array = { "one", "two", "three" };
         getFlowContext().put("test", array);
+        addFlowContextToObjectModel(getNewObjectModel());
+        
         assertEqual(load(outputURI), generate(JX, inputURI, EMPTY_PARAMS));
+        
+        getNewObjectModel().cleanupLocalContext();
     }
 
     public void testJXMacro() throws Exception {
         String inputURI = docBase + "jxMacro.xml";
         String outputURI = docBase + "jxMacro-output.xml";
 
+        getNewObjectModel().markLocalContext();
         getFlowContext().put("container", new StringContainer("foobar"));
+        addFlowContextToObjectModel(getNewObjectModel());
+        
         assertEqual(load(outputURI), generate(JX, inputURI, EMPTY_PARAMS));
+        
+        getNewObjectModel().cleanupLocalContext();
     }
 
     public void testJXDynamicMacro() throws Exception {
@@ -146,26 +173,41 @@
         String inputURI = docBase + "jxAttribute.xml";
         String outputURI = docBase + "jxAttribute-output.xml";
 
+        getNewObjectModel().markLocalContext();
         Calendar cal = new GregorianCalendar(1979, 0, 1, 10, 21, 33);
         getFlowContext().put("date", cal.getTime());
+        addFlowContextToObjectModel(getNewObjectModel());
+        
         assertEqual(load(outputURI), generate(JX, inputURI, EMPTY_PARAMS));
+        
+        getNewObjectModel().cleanupLocalContext();
     }
 
     public void testFormatDate() throws Exception {
         String inputURI = docBase + "formatDate.xml";
         String outputURI = docBase + "formatDate-output.xml";
 
+        getNewObjectModel().markLocalContext();
         Calendar cal = new GregorianCalendar(1979, 0, 1, 10, 21, 33);
         getFlowContext().put("date", cal.getTime());
+        addFlowContextToObjectModel(getNewObjectModel());
+        
         assertEqual(load(outputURI), generate(JX, inputURI, EMPTY_PARAMS));
+        
+        getNewObjectModel().cleanupLocalContext();
     }
 
     public void testFormatNumber() throws Exception {
         String inputURI = docBase + "formatNumber.xml";
         String outputURI = docBase + "formatNumber-output.xml";
 
+        getNewObjectModel().markLocalContext();
         getFlowContext().put("value", new Double(979.0101));
+        addFlowContextToObjectModel(getNewObjectModel());
+        
         assertEqual(load(outputURI), generate(JX, inputURI, EMPTY_PARAMS));
+        
+        getNewObjectModel().cleanupLocalContext();
     }
 
     public void testOut() throws Exception {
@@ -173,9 +215,14 @@
         String outputURI = docBase + "jxOut-output.xml";
         String includeURI = docBase + "jxOutInclude.xml";
 
+        getNewObjectModel().markLocalContext();
         getFlowContext().put("value", "simple");
         getFlowContext().put("xml", "<root><node>value</node></root>");
         getFlowContext().put("document", load(includeURI));
+        addFlowContextToObjectModel(getNewObjectModel());
+        
         assertEqual(load(outputURI), generate(JX, inputURI, EMPTY_PARAMS));
+        
+        getNewObjectModel().cleanupLocalContext();
     }
 }

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java?view=diff&rev=562896&r1=562895&r2=562896
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
Sun Aug  5 08:41:58 2007
@@ -55,4 +55,13 @@
      * Cleans up entries put to ObjectModel since last {@link #markLocalContext()} call.
      */
     public void cleanupLocalContext();
+    
+    /**
+     * <p>Copies properties (both static and dynamic) of current context bean to the
Object Model. The method is useful
+     * when you want, for example, to access properties of context bean in JEXL expression
and omit <code>contextBean.</code>
+     * part.</p>
+     * 
+     * @see org.apache.commons.jxpath.JXPathBeanInfo.isDynamic() for description of static
and dynamic properties
+     */
+    public void fillContext();
 }

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java?view=diff&rev=562896&r1=562895&r2=562896
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
Sun Aug  5 08:41:58 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.cocoon.objectmodel;
 
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.ListIterator;
@@ -30,6 +32,9 @@
 import org.apache.commons.collections.map.AbstractMapDecorator;
 import org.apache.commons.collections.map.MultiValueMap;
 import org.apache.commons.collections.map.UnmodifiableMap;
+import org.apache.commons.jxpath.DynamicPropertyHandler;
+import org.apache.commons.jxpath.JXPathBeanInfo;
+import org.apache.commons.jxpath.JXPathIntrospector;
 
 /**
  * Prototype implementation of {@link ObjectModel} interface. It <b>must</b>
be initialized manually for now.
@@ -127,6 +132,46 @@
         for (Iterator keysIterator = initialEntries.keySet().iterator(); keysIterator.hasNext();
) {
             Object key = keysIterator.next();
             put(key, ((ObjectModelProvider)initialEntries.get(key)).getObject());
+        }
+    }
+
+    public void fillContext() {
+        // Hack: I use jxpath to populate the context object's properties
+        // in the jexl context
+        Object contextObject = get(CONTEXTBEAN);
+        final JXPathBeanInfo bi =
+            JXPathIntrospector.getBeanInfo(contextObject.getClass());
+        if (bi.isDynamic()) {
+            Class cl = bi.getDynamicPropertyHandlerClass();
+            try {
+                DynamicPropertyHandler h =
+                    (DynamicPropertyHandler) cl.newInstance();
+                String[] result = h.getPropertyNames(contextObject);
+                int len = result.length;
+                for (int i = 0; i < len; i++) {
+                    try {
+                        put(result[i], h.getProperty(contextObject, result[i]));
+                    } catch (Exception exc) {
+                        exc.printStackTrace();
+                    }
+                }
+            } catch (Exception ignored) {
+                ignored.printStackTrace();
+            }
+        } else {
+            PropertyDescriptor[] props =  bi.getPropertyDescriptors();
+            int len = props.length;
+            for (int i = 0; i < len; i++) {
+                try {
+                    Method read = props[i].getReadMethod();
+                    if (read != null) {
+                        put(props[i].getName(),
+                                read.invoke(contextObject, null));
+                    }
+                } catch (Exception ignored) {
+                    ignored.printStackTrace();
+                }
+            }
         }
     }
     

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java?view=diff&rev=562896&r1=562895&r2=562896
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
Sun Aug  5 08:41:58 2007
@@ -16,16 +16,11 @@
  */
 package org.apache.cocoon.template.environment;
 
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
 import java.util.Map;
 
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.objectmodel.ObjectModel;
 import org.apache.cocoon.objectmodel.helper.ParametersMap;
-import org.apache.commons.jxpath.DynamicPropertyHandler;
-import org.apache.commons.jxpath.JXPathBeanInfo;
-import org.apache.commons.jxpath.JXPathIntrospector;
 
 
 /**
@@ -45,56 +40,7 @@
     public static void fillNewObjectModelWithFOM(ObjectModel newObjectModel, 
                                                             final Map objectModel, final
Parameters parameters) {
         
-        // Now add objects from flow context (if any)
-        final Object contextObject = newObjectModel.get(ObjectModel.CONTEXTBEAN);
-        if (contextObject instanceof Map) {
-            newObjectModel.putAll((Map)contextObject);
-        } else if ( contextObject != null ) {
-            FlowObjectModelHelper.fillContext(contextObject, newObjectModel);
-        }
-        
         ((Map)newObjectModel.get("cocoon")).put("parameters", new ParametersMap(parameters));
-        
-        //newObjectModel.put(org.apache.cocoon.objectmodel.ObjectModel.CONTEXTBEAN, FlowHelper.getContextObject(objectModel));
-    }
-
-    public static void fillContext(Object contextObject, Map map) {
-        // Hack: I use jxpath to populate the context object's properties
-        // in the jexl context
-        final JXPathBeanInfo bi =
-            JXPathIntrospector.getBeanInfo(contextObject.getClass());
-        if (bi.isDynamic()) {
-            Class cl = bi.getDynamicPropertyHandlerClass();
-            try {
-                DynamicPropertyHandler h =
-                    (DynamicPropertyHandler) cl.newInstance();
-                String[] result = h.getPropertyNames(contextObject);
-                int len = result.length;
-                for (int i = 0; i < len; i++) {
-                    try {
-                        map.put(result[i], h.getProperty(contextObject, result[i]));
-                    } catch (Exception exc) {
-                        exc.printStackTrace();
-                    }
-                }
-            } catch (Exception ignored) {
-                ignored.printStackTrace();
-            }
-        } else {
-            PropertyDescriptor[] props =  bi.getPropertyDescriptors();
-            int len = props.length;
-            for (int i = 0; i < len; i++) {
-                try {
-                    Method read = props[i].getReadMethod();
-                    if (read != null) {
-                        map.put(props[i].getName(),
-                                read.invoke(contextObject, null));
-                    }
-                } catch (Exception ignored) {
-                    ignored.printStackTrace();
-                }
-            }
-        }
     }
 
 }

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/FlowHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/FlowHelper.java?view=diff&rev=562896&r1=562895&r2=562896
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/FlowHelper.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/FlowHelper.java
Sun Aug  5 08:41:58 2007
@@ -16,7 +16,6 @@
  */
 package org.apache.cocoon.components.flow;
 
-import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.cocoon.objectmodel.ObjectModel;
@@ -91,5 +90,6 @@
     public final static void setContextObject(Map objectModel, ObjectModel newObjectModel,
Object obj) {
         objectModel.put(CONTEXT_OBJECT, obj);
         newObjectModel.put(ObjectModel.CONTEXTBEAN, obj);
+        newObjectModel.fillContext();
     }
 }



Mime
View raw message