cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r154092 - in cocoon/trunk/src/blocks/template: WEB-INF/xconf/ conf/ java/org/apache/cocoon/components/expression/ java/org/apache/cocoon/environment/ java/org/apache/cocoon/template/jxtg/instruction/
Date Wed, 16 Feb 2005 22:24:30 GMT
Author: danielf
Date: Wed Feb 16 14:24:28 2005
New Revision: 154092

URL: http://svn.apache.org/viewcvs?view=rev&rev=154092
Log:
Using TemplateObjectModelHelper instead of own copy.
Added configuration files.

Added:
    cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template-expression.xconf
    cocoon/trunk/src/blocks/template/conf/
    cocoon/trunk/src/blocks/template/conf/template.xmap
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/expression.roles
Modified:
    cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template.xconf
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java

Added: cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template-expression.xconf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template-expression.xconf?view=auto&rev=154092
==============================================================================
--- cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template-expression.xconf (added)
+++ cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template-expression.xconf Wed Feb
16 14:24:28 2005
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--+
+    |
+    | SVN $Id$
+    +-->
+<components>
+  <!-- Include roles -->
+  <include src="resource://org/apache/cocoon/components/expression/expression.roles"/>
+
+  <expression-compilers>
+    <component-instance class="org.apache.cocoon.components.expression.jxpath.JXPathCompiler"
name="default"/>
+    <component-instance class="org.apache.cocoon.components.expression.jexl.JexlCompiler"
name="jexl"/>
+    <component-instance class="org.apache.cocoon.components.expression.jxpath.JXPathCompiler"
name="jxpath"/>
+  </expression-compilers>
+</components>

Modified: cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template.xconf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template.xconf?view=diff&r1=154091&r2=154092
==============================================================================
--- cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template.xconf (original)
+++ cocoon/trunk/src/blocks/template/WEB-INF/xconf/cocoon-template.xconf Wed Feb 16 14:24:28
2005
@@ -20,5 +20,5 @@
     | SVN $Id$
     +-->
 <components>
-  <!-- Dummy config that other blocks can import -->
+  <include src="context://WEB-INF/xconf/cocoon-template-expression.xconf"/>
 </components>

Added: cocoon/trunk/src/blocks/template/conf/template.xmap
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/conf/template.xmap?view=auto&rev=154092
==============================================================================
--- cocoon/trunk/src/blocks/template/conf/template.xmap (added)
+++ cocoon/trunk/src/blocks/template/conf/template.xmap Wed Feb 16 14:24:28 2005
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--+
+    |
+    | SVN $Id$
+    +-->
+<xmap xpath="/sitemap/components/generators"
+      unless="generator[@name='jx2']">
+
+    <map:generator name="jx2"
+                   logger="sitemap.generator.jx2"
+                   src="org.apache.cocoon.template.jxtg.JXTemplateGenerator"
+                   label="content">
+    </map:generator>
+</xmap>

Added: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/expression.roles
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/expression.roles?view=auto&rev=154092
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/expression.roles
(added)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/expression.roles
Wed Feb 16 14:24:28 2005
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id$ -->
+<role-list>
+  <role name="org.apache.cocoon.components.expression.ExpressionCompilerSelector"
+        shorthand="expression-compilers"
+        default-class="org.apache.cocoon.core.container.DefaultServiceSelector"/>
+  <role name="org.apache.cocoon.components.expression.ExpressionFactory"
+        shorthand="expression-factory"
+        default-class="org.apache.cocoon.components.expression.ExpressionFactory"/>
+</role-list>
\ No newline at end of file

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java?view=diff&r1=154091&r2=154092
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java
(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java
Wed Feb 16 14:24:28 2005
@@ -15,197 +15,30 @@
  */
 package org.apache.cocoon.environment;
 
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.components.flow.FlowHelper;
-import org.apache.cocoon.components.flow.WebContinuation;
-import org.apache.cocoon.components.flow.javascript.fom.FOM_WebContinuation;
-import org.apache.commons.beanutils.MethodUtils;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.jxpath.DynamicPropertyHandler;
-import org.apache.commons.jxpath.JXPathBeanInfo;
-import org.apache.commons.jxpath.JXPathIntrospector;
+import org.apache.cocoon.environment.TemplateObjectModelHelper;
 
 
 /**
- * This is an utility class to create an object model which is similar to the one
- * used in flow, that can be used from every component.
- * 
- * Work-in-progress, derived from JXTemplateGenerator
- * Copy of TemplateObjectModelHelper from scratchpad
- * plus creation of an Expression context
+ * Creation of an Expression context from the TemplateObjectModelHelper
  * 
  * @version CVS $Id$
  */
 public class FlowObjectModelHelper {
 
-    /** Avoid instantiation */
-    private FlowObjectModelHelper() {}
-
-    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();
-                }
-            }
-        }
-    }
-
-    /**
-     * Create the object model.
-     * Currently the object model is a map with one single entry:
-     *  cocoon + request         The Request Object
-     *         + session         The Session (if available)
-     *         + context         The Context
-     *         + continuation    The Continuation (if available)
-     *         + parameters      The parameters (if provided)
-     */
-    public static Object getTemplateObjectModel(final Map objectModel, 
-                                                final Parameters parameters) {
-
-        // first create the "cocoon object":
-        final Map cocoon = new HashMap();
-        
-        // cocoon.request
-        final Request request = ObjectModelHelper.getRequest( objectModel );
-        cocoon.put("request", new DynamicMap(request));
-        
-        // cocoon.session
-        final Session session = request.getSession(false);
-        if (session != null) {
-            cocoon.put("session", new DynamicMap(session));
-        }
-        
-        // cocoon.context
-        cocoon.put("context", ObjectModelHelper.getContext(objectModel));
-        
-        // cocoon.continuation
-        final WebContinuation cont = FlowHelper.getWebContinuation(objectModel);
-        if ( cont != null ) {
-            // Changed compared to scratchpad version, using FOM_WebContinuation
-            // to stay compatible with JXTemplateGenerator
-            cocoon.put("continuation", new FOM_WebContinuation(cont));
-        }
-        
-        // cocoon.parameters
-        if ( parameters != null ) {
-            cocoon.put("parameters", Parameters.toProperties(parameters));
-        }
-
-        final Map map = new HashMap();
-        map.put("cocoon", cocoon);
-
-        // Now add objects from flow context (if any)
-        final Object contextObject = FlowHelper.getContextObject(objectModel);
-        if (contextObject instanceof Map) {
-            map.putAll((Map)contextObject);
-        } else if ( contextObject != null ) {
-            fillContext(contextObject, map);
-        }
-        
-        return map;
-    }
-
     /**
      * Create an expression context that contains the object model
      */
     public static ExpressionContext getFOMExpressionContext(final Map objectModel, 
                                                             final Parameters parameters)
{
         ExpressionContext context = new ExpressionContext();
-        context.setVars((Map)getTemplateObjectModel(objectModel, parameters));
+        context.setVars((Map)TemplateObjectModelHelper.getTemplateObjectModel(objectModel,
parameters));
         context.setContextBean(FlowHelper.getContextObject(objectModel));
 
         return context;
-    }
-
-    /**
-     * This is a dynamic map that should provide the same functionality as the
-     * FOM wrappers for objects.
-     */
-    public static class DynamicMap extends HashMap {
-        
-        protected final Object information;
-        
-        public DynamicMap(Object info) {
-            this.information = info;
-        }
-        
-        /* (non-Javadoc)
-         * @see java.util.Map#get(java.lang.Object)
-         */
-        public Object get(Object key) {
-            Object result = super.get(key);
-            if ( result == null ) {
-                result = this.getDynamicInfo(key);
-            }
-            return result;
-        }
-        
-        
-        /* (non-Javadoc)
-         * @see java.util.Map#containsKey(java.lang.Object)
-         */
-        public boolean containsKey(Object key) {
-            boolean result = super.containsKey(key);
-            if ( result == false ) {
-                result = (this.getDynamicInfo(key) != null);
-            }
-            return result;
-        }
-        
-        protected Object getDynamicInfo(Object key) {
-            Object result = null;
-            try {
-                result = PropertyUtils.getProperty(this.information, key.toString());
-            } catch (Exception ignore) {                    
-            }
-            if ( result == null ) {
-                try {
-                    result = MethodUtils.invokeMethod(this.information, 
-                                                      "getAttribute", 
-                                                      key.toString());
-                } catch (Exception ignore) {                    
-                }                        
-            }
-            if ( result != null ) {
-                this.put(key, result);
-            }
-            return result;
-        }
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java?view=diff&r1=154091&r2=154092
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java
(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java
Wed Feb 16 14:24:28 2005
@@ -20,7 +20,7 @@
 
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.components.expression.ExpressionContext;
-import org.apache.cocoon.environment.FlowObjectModelHelper;
+import org.apache.cocoon.environment.TemplateObjectModelHelper;
 import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
 import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
@@ -122,7 +122,7 @@
                 Object obj = this.select.getValue(expressionContext);
                 selectExpressionContext = new ExpressionContext(expressionContext);
                 selectExpressionContext.setContextBean(obj);
-                FlowObjectModelHelper.fillContext(obj, selectExpressionContext);
+                TemplateObjectModelHelper.fillContext(obj, selectExpressionContext);
             } catch (Exception exc) {
                 throw new SAXParseException(exc.getMessage(), getLocation(), exc);
             } catch (Error err) {



Mime
View raw message