You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2009/07/20 18:28:06 UTC

svn commit: r795901 [1/2] - in /camel/trunk/components/camel-web/src: main/java/org/apache/camel/web/resources/ main/java/org/apache/camel/web/util/ main/webapp/org/apache/camel/web/resources/RouteResource/ main/webapp/org/apache/camel/web/resources/Ro...

Author: janstey
Date: Mon Jul 20 16:28:04 2009
New Revision: 795901

URL: http://svn.apache.org/viewvc?rev=795901&view=rev
Log:
CAMEL-1392 - add web console support for rendering Groovy routes. 

Thanks to Xueqiang Mi for this!


Added:
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/AggregateDefinitionRenderer.java   (with props)
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ChoiceDefinitionRenderer.java   (with props)
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionNodeRenderer.java   (with props)
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionRenderer.java   (with props)
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/GroovyRenderer.java   (with props)
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/OutputDefinitionRenderer.java   (with props)
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/PredicateRenderer.java   (with props)
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/SendDefinitionRenderer.java   (with props)
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/TextRenderer.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/AggregateDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/ChoiceDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/CovertBodyDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DeadLetterDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DelayDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/EnrichSetBodyDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/FilterDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTestSupport.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/LoadBalanceDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/LoopDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/MarshalDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/NormalizerDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/PipelineDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/RecipientListDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/RemoveHeaderDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/RemovePropertyDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/RoutingSlipDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/SetBodyDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/SetExchangePatternDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/SetHeaderDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/SetPropertyDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/SimpleDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/SortDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/ThrottleDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/TransformDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/WireTapDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/XPathDSLTest.java   (with props)
    camel/trunk/components/camel-web/src/test/resources/route.txt   (with props)
    camel/trunk/components/camel-web/src/test/resources/testedRoutes.txt   (with props)
Modified:
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java
    camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/edit.jsp
    camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/index.jsp
    camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp

Modified: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java?rev=795901&r1=795900&r2=795901&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java (original)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java Mon Jul 20 16:28:04 2009
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.web.resources;
 
+import com.sun.jersey.api.representation.Form;
+import com.sun.jersey.api.view.Viewable;
+import groovy.lang.GroovyClassLoader;
+
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -40,16 +44,14 @@
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 
-import com.sun.jersey.api.representation.Form;
-import com.sun.jersey.api.view.Viewable;
-import groovy.lang.GroovyClassLoader;
-
+import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.ruby.RubyCamel;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.view.RouteDotGenerator;
+import org.apache.camel.web.util.GroovyRenderer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jruby.Main;
@@ -73,12 +75,6 @@
 
     // what language is used to define this route
     private String language = LANGUAGE_XML;
-  
-    // the route configuration: when language is Xml, the routeDefinition is
-    // null; when language is Groovy/Scala/Ruby, the routeDefinition contains
-    // the route definition class. It must be initialized because RouteResource
-    // is stateless.
-    private String routeDefinition = "";
 
     public RouteResource(RoutesResource routesResource, RouteDefinition route) {
         super(routesResource.getContextResource());
@@ -111,25 +107,21 @@
     }
 
     /**
-     * Returns the language
-     */
-    public String getLanguage() {
-        return language;
-    }
-
-    /**
      * Returns the content of the route definition class
      */
     public String getRouteDefinition() {
-        if (language.equals(LANGUAGE_XML)) {
+        if (language.equalsIgnoreCase(LANGUAGE_XML)) {
             try {
                 return getRouteXml();
             } catch (JAXBException e) {
-                // e.printStackTrace();
                 return "Error on marshal the route definition!";
             }
+        } else if (language.equalsIgnoreCase(LANGUAGE_GROOVY)) {
+            StringBuilder buffer = new StringBuilder();
+            new GroovyRenderer().renderRoute(buffer, route);
+            return GroovyRenderer.header + buffer.toString() + GroovyRenderer.footer;
         } else {
-            return routeDefinition;
+            return "Unsupported language!";
         }
     }
 
@@ -163,12 +155,20 @@
      * Allows a routes builder to be updated
      */
     public void postRoutes(RouteBuilder builder) throws Exception {
-        // remove current route
-        DefaultCamelContext camelContext = (DefaultCamelContext)getCamelContext();
-        camelContext.removeRouteDefinition(id);
+        // add the route builder into a temporary camel context
+        CamelContext tempContext = new DefaultCamelContext();
+        tempContext.addRoutes(builder);
+        // get all the added routes and add them into current context
+        List<RouteDefinition> routeDefinitions = tempContext.getRouteDefinitions();
+        for (int i = 0; i < routeDefinitions.size(); i++) {
+            RouteDefinition routeDefinition = routeDefinitions.get(i);
+            // set id only for the first route
+            if (i == 0)
+                routeDefinition.setId(id);
 
-        // lets install the updated routes
-        camelContext.addRoutes(builder);
+            // add or update the route
+            getCamelContext().addRouteDefinitions(Collections.singletonList(routeDefinition));
+        }
     }
 
     /**
@@ -234,11 +234,11 @@
     private Response parseGroovy(String route) {
         try {
             // store the route definition
-            File file = storeRoute(route, LANGUAGE_GROOVY);
+            // File file = storeRoute(route, LANGUAGE_GROOVY);
 
             // load the definition class into a RouteBuilder instance
             GroovyClassLoader classLoader = new GroovyClassLoader();
-            Class clazz = classLoader.parseClass(file);
+            Class clazz = classLoader.parseClass(route);
             RouteBuilder builder = (RouteBuilder)clazz.newInstance();
             LOG.info("Loaded builder: " + builder);
 
@@ -341,6 +341,27 @@
     }
 
     /**
+     * Returns the language
+     */
+    public String getLanguage() {
+        return language;
+    }
+
+    public void setLanguage(String language) {
+        if (language.equalsIgnoreCase(LANGUAGE_GROOVY)) {
+            this.language = LANGUAGE_GROOVY;
+        } else if (language.equalsIgnoreCase(LANGUAGE_GROOVY)) {
+            this.language = LANGUAGE_GROOVY;
+        } else if (language.equalsIgnoreCase(LANGUAGE_RUBY)) {
+            this.language = LANGUAGE_RUBY;
+        } else if (language.equalsIgnoreCase(LANGUAGE_SCALA)) {
+            this.language = LANGUAGE_SCALA;
+        } else {
+            this.language = LANGUAGE_XML;
+        }
+    }
+
+    /**
      * Looks up an individual route
      */
     @Path("status")

Modified: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java?rev=795901&r1=795900&r2=795901&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java (original)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java Mon Jul 20 16:28:04 2009
@@ -30,8 +30,9 @@
 import org.apache.camel.view.RouteDotGenerator;
 
 /**
- * The active routes in Camel which are used to implement one or more
- * <a href="http://camel.apache.org/enterprise-integration-patterns.html">Enterprise Integration Paterns</a>
+ * The active routes in Camel which are used to implement one or more <a
+ * href="http://camel.apache.org/enterprise-integration-patterns.html"
+ * >Enterprise Integration Paterns</a>
  *
  * @version $Revision$
  */
@@ -57,8 +58,9 @@
     }
 
     /**
-     * Returns the Graphviz DOT <a href="http://camel.apache.org/visualisation.html">Visualisation</a>
-     * of the current Camel routes
+     * Returns the Graphviz DOT <a
+     * href="http://camel.apache.org/visualisation.html">Visualisation</a> of
+     * the current Camel routes
      */
     @GET
     @Produces(Constants.DOT_MIMETYPE)
@@ -81,10 +83,21 @@
         return null;
     }
 
+    /**
+     * Looks up an individual route with specified language
+     */
+    @Path("{id}/{language}")
+    public RouteResource getRoute(@PathParam("id") String id, @PathParam("language") String language) {
+        RouteResource routeResource = getRoute(id);
+        if (routeResource != null) {
+            routeResource.setLanguage(language);
+        }
+        return routeResource;
+    }
 
     // Properties
-    //-------------------------------------------------------------------------
+    // -------------------------------------------------------------------------
     public List<RouteDefinition> getRoutes() {
         return getRouteDefinitions().getRoutes();
     }
-}
\ No newline at end of file
+}

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/AggregateDefinitionRenderer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/AggregateDefinitionRenderer.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/AggregateDefinitionRenderer.java (added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/AggregateDefinitionRenderer.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.util;
+
+import org.apache.camel.model.AggregateDefinition;
+import org.apache.camel.model.ExpressionNode;
+import org.apache.camel.model.ProcessorDefinition;
+
+/**
+ * 
+ */
+public class AggregateDefinitionRenderer {
+
+    public static void render(StringBuilder buffer, ProcessorDefinition processor) {
+        AggregateDefinition aggregate = (AggregateDefinition)processor;
+        buffer.append(".").append(aggregate.getShortName()).append("()");
+
+        ExpressionRenderer.render(buffer, aggregate.getExpression());
+
+        if (aggregate.getBatchTimeout() != null) {
+            buffer.append(".batchTimeout(").append(aggregate.getBatchTimeout());
+            buffer.append(aggregate.getBatchTimeout() < 1000L ? "L)" : ")");
+        }
+        if (aggregate.getBatchSize() != null) {
+            buffer.append(".batchSize(").append(aggregate.getBatchSize()).append(")");
+        }
+
+        if (aggregate.getGroupExchanges() != null && aggregate.getGroupExchanges()) {
+            buffer.append(".groupExchanges()");
+        }
+    }
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/AggregateDefinitionRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ChoiceDefinitionRenderer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ChoiceDefinitionRenderer.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ChoiceDefinitionRenderer.java (added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ChoiceDefinitionRenderer.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.util;
+
+import org.apache.camel.model.ProcessorDefinition;
+
+/**
+ * 
+ */
+public class ChoiceDefinitionRenderer {
+
+    public static void render(StringBuilder buffer, ProcessorDefinition processor) {
+
+    }
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ChoiceDefinitionRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionNodeRenderer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionNodeRenderer.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionNodeRenderer.java (added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionNodeRenderer.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,141 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.util;
+
+import org.apache.camel.builder.ExpressionClause;
+import org.apache.camel.model.DelayDefinition;
+import org.apache.camel.model.ExpressionNode;
+import org.apache.camel.model.FilterDefinition;
+import org.apache.camel.model.IdempotentConsumerDefinition;
+import org.apache.camel.model.LoopDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RecipientListDefinition;
+import org.apache.camel.model.SetBodyDefinition;
+import org.apache.camel.model.SetHeaderDefinition;
+import org.apache.camel.model.SetOutHeaderDefinition;
+import org.apache.camel.model.SetPropertyDefinition;
+import org.apache.camel.model.SplitDefinition;
+import org.apache.camel.model.TransformDefinition;
+import org.apache.camel.model.WhenDefinition;
+import org.apache.camel.model.language.ConstantExpression;
+import org.apache.camel.model.language.ExpressionDefinition;
+
+/**
+ * 
+ */
+public class ExpressionNodeRenderer {
+
+    public static void render(StringBuilder buffer, ProcessorDefinition processor) {
+        ExpressionNode expNode = (ExpressionNode)processor;
+        ExpressionDefinition expression = expNode.getExpression();
+
+        buffer.append(".").append(expNode.getShortName());
+        if (expNode instanceof DelayDefinition) {
+            String delay = expression.getExpressionValue().toString();
+            if (!delay.contains("(")) {
+                String delayTime = expression.getExpressionValue().toString();
+                buffer.append("(").append(delayTime).append(")");
+            } else {
+                buffer.append("()");
+                ExpressionRenderer.render(buffer, expression);
+            }
+        } else if (expNode instanceof FilterDefinition) {
+            if (expression.getPredicate() != null) {
+                PredicateRenderer.renderPredicate(buffer, expression.getPredicate());
+            } else if (expression.getLanguage() != null) {
+                buffer.append("()");
+                ExpressionRenderer.render(buffer, expression);
+            } else {
+                buffer.append("()");
+                ExpressionRenderer.render(buffer, expression);
+            }
+        } else if (expNode instanceof IdempotentConsumerDefinition) {
+        } else if (expNode instanceof LoopDefinition) {
+            if (expression instanceof ConstantExpression) {
+                buffer.append("(").append(expression.getExpression()).append(")");
+            } else {
+                buffer.append("()");
+                ExpressionRenderer.render(buffer, expression);
+            }
+        } else if (expNode instanceof RecipientListDefinition) {
+            buffer.append("(");
+            ExpressionRenderer.render(buffer, expression);
+            buffer.append(")");
+        } else if (expNode instanceof SetBodyDefinition) {
+            String expValue = expression.getExpressionValue().toString();
+            if (expValue.startsWith("append")) {
+                buffer.append("(");
+                ExpressionRenderer.render(buffer, expression);
+                buffer.append(")");
+            } else {
+                buffer.append("()");
+                ExpressionRenderer.renderConstant(buffer, expression);
+            }
+        } else if (expNode instanceof SetHeaderDefinition) {
+            SetHeaderDefinition set = (SetHeaderDefinition)expNode;
+            buffer.append("(\"").append(set.getHeaderName()).append("\")");
+            if (expression.getExpressionValue() != null) {
+                ExpressionRenderer.renderConstant(buffer, expression);
+            } else if (expression.getExpressionType() != null) {
+                ExpressionRenderer.render(buffer, expression);
+            }
+        } else if (expNode instanceof SetOutHeaderDefinition) {
+            buffer.append("(\"unspported expressions in SetOutHeaderDefinition\")");
+        } else if (expNode instanceof SetPropertyDefinition) {
+            SetPropertyDefinition set = (SetPropertyDefinition)expNode;
+            buffer.append("(\"").append(set.getPropertyName()).append("\")");
+            if (expression.getExpressionValue() != null) {
+                ExpressionRenderer.renderConstant(buffer, expression);
+            } else if (expression.getExpressionType() != null) {
+                ExpressionRenderer.render(buffer, expression);
+            }
+        } else if (expNode instanceof SplitDefinition) {
+            String expValue = expression.getExpressionValue().toString();
+            if (!expValue.contains("(")) {
+                buffer.append("().").append(expValue).append("()");
+            } else {
+                ExpressionRenderer.render(buffer, expression);
+            }
+        } else if (expNode instanceof TransformDefinition) {
+            String expValue = expression.getExpressionValue().toString();
+            if (expValue.matches("\\w+")) {
+                buffer.append("()");
+                ExpressionRenderer.renderConstant(buffer, expression);
+            } else if (expValue.startsWith("append")) {
+                buffer.append("(");
+                ExpressionRenderer.render(buffer, expression);
+                buffer.append(")");
+            } else if (expValue.startsWith("xpath")) {
+                buffer.append("()");
+                ExpressionRenderer.render(buffer, expression);
+            } else {
+                buffer.append("(");
+                ExpressionRenderer.render(buffer, expression);
+                buffer.append(")");
+            }
+        } else if (expNode instanceof WhenDefinition) {
+            if (expression.getPredicate() != null) {
+                PredicateRenderer.renderPredicate(buffer, expression.getPredicate());
+            }
+            if (expression instanceof ExpressionClause) {
+                buffer.append("()");
+                ExpressionRenderer.render(buffer, (ExpressionClause)expression);
+            }
+        }
+    }
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionNodeRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionRenderer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionRenderer.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionRenderer.java (added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionRenderer.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,141 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.util;
+
+import org.apache.camel.builder.ExpressionClause;
+import org.apache.camel.model.language.ExpressionDefinition;
+import org.apache.camel.model.language.MethodCallExpression;
+import org.apache.camel.model.language.XPathExpression;
+
+/**
+ * 
+ */
+public class ExpressionRenderer {
+
+    /**
+     * a common render method to process the expressionDefinition
+     * 
+     * @param buffer
+     * @param expression
+     */
+    public static void render(StringBuilder buffer, ExpressionDefinition expression) {
+
+        if (buffer.toString().endsWith(")")) {
+            buffer.append(".");
+        }
+
+        if (expression instanceof ExpressionClause) {
+            renderExpressionClause(buffer, (ExpressionClause)expression);
+        } else if (expression.getExpressionValue() instanceof ExpressionClause) {
+            render(buffer, (ExpressionClause)expression.getExpressionValue());
+        } else {
+            if (expression.getExpressionValue() != null) {
+                renderExpression(buffer, expression.getExpressionValue().toString());
+            } else if (expression.getLanguage() != null) {
+                renderLanguageExpression(buffer, expression);
+            }
+        }
+    }
+
+    /**
+     * Render a constant: constant("")
+     * 
+     * @param expression
+     * @param buffer
+     */
+    public static void renderConstant(StringBuilder buffer, ExpressionDefinition expression) {
+        buffer.append(".constant(\"").append(expression.getExpressionValue().toString()).append("\")");
+    }
+
+    /**
+     * Render an expression clause
+     * 
+     * @param buffer
+     * @param expression
+     */
+    private static void renderExpressionClause(StringBuilder buffer, ExpressionClause expression) {
+        if (expression.getLanguage() != null) {
+            // render a language expression
+            renderLanguageExpression(buffer, expression);
+        } else if (expression.getExpressionType() instanceof MethodCallExpression) {
+            // render a methodCall expression
+            String exp = expression.getExpressionType().toString();
+            String bean = exp.substring(exp.indexOf('{') + 1, exp.indexOf(','));
+            String method = exp.substring(exp.indexOf('=') + 1, exp.indexOf('}'));
+            buffer.append("method(\"").append(bean).append("\", \"").append(method).append("\")");
+        } else if (expression.getExpressionType() instanceof XPathExpression) {
+            XPathExpression xpath = (XPathExpression)expression.getExpressionType();
+            buffer.append("xpath(\"").append(xpath.getExpression()).append("\", ").append(xpath.getResultType().getSimpleName()).append(".class)");
+        } else {
+            renderExpression(buffer, expression.getExpressionValue().toString());
+        }
+    }
+
+    /**
+     * Render a language expression
+     * 
+     * @param buffer
+     * @param expression
+     */
+    public static void renderLanguageExpression(StringBuilder buffer, ExpressionDefinition expression) {
+        // render a language expression
+        buffer.append(expression.getLanguage()).append("(\"");
+        if (expression.getExpression() != null) {
+            buffer.append(expression.getExpression()).append("\")");
+        } else if (expression.getExpressionValue() instanceof ExpressionClause) {
+            buffer.append(((ExpressionClause)expression.getExpressionValue()).getExpression()).append("\")");
+        }
+    }
+
+    /**
+     * Render a simple expression: header(foo) -> header("foo")
+     * tokenize(header(foo), ,) -> header("foo").tokenize(",")
+     * 
+     * @param buffer
+     * @param expression
+     */
+    public static void renderExpression(StringBuilder buffer, String expression) {
+        if (!expression.contains(",")) {
+            // header(foo) -> header("foo")
+            expression = expression.replaceAll("\\(", "(\"").replaceAll("\\)", "\")");
+            buffer.append(expression);
+        } else if (expression.startsWith("tokenize")) {
+            String words[] = expression.split("\\(");
+            if (words.length == 2) {
+                // tokenize(body, ,) -> body().tokenize(",")
+                String tokenize = words[1].substring(words[1].indexOf(" ") + 1, words[1].lastIndexOf(")"));
+                words[1] = words[1].substring(0, words[1].indexOf(","));
+
+                buffer.append(words[1]).append("().");
+                buffer.append(words[0]).append("(\"").append(tokenize).append("\")");
+            } else if (words.length == 3) {
+                // tokenize(header(foo), ,) -> header("foo").tokenize(",")
+                String symbolName = words[2].substring(0, words[2].indexOf(")"));
+                String tokenize = words[2].substring(words[2].indexOf(" ") + 1, words[2].lastIndexOf(")"));
+
+                buffer.append(words[1]).append("(\"").append(symbolName).append("\").");
+                buffer.append(words[0]).append("(\"").append(tokenize).append("\")");
+            }
+        } else if (expression.startsWith("append")) {
+            // append(body, World!) -> body().append(" World!")
+            String words[] = expression.split("\\(|, |\\)");
+
+            buffer.append(words[1]).append("().").append("append(\"").append(words[2]).append("\")");
+        }
+    }
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/ExpressionRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/GroovyRenderer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/GroovyRenderer.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/GroovyRenderer.java (added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/GroovyRenderer.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,227 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.camel.web.util;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.builder.DeadLetterChannelBuilder;
+import org.apache.camel.builder.ErrorHandlerBuilderRef;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.builder.ExpressionClause;
+import org.apache.camel.model.AggregateDefinition;
+import org.apache.camel.model.BeanDefinition;
+import org.apache.camel.model.ChoiceDefinition;
+import org.apache.camel.model.ConvertBodyDefinition;
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.model.DelayDefinition;
+import org.apache.camel.model.EnrichDefinition;
+import org.apache.camel.model.ExpressionNode;
+import org.apache.camel.model.FilterDefinition;
+import org.apache.camel.model.FinallyDefinition;
+import org.apache.camel.model.FromDefinition;
+import org.apache.camel.model.IdempotentConsumerDefinition;
+import org.apache.camel.model.InterceptDefinition;
+import org.apache.camel.model.InterceptSendToEndpointDefinition;
+import org.apache.camel.model.LoadBalanceDefinition;
+import org.apache.camel.model.LoopDefinition;
+import org.apache.camel.model.MarshalDefinition;
+import org.apache.camel.model.MulticastDefinition;
+import org.apache.camel.model.OtherwiseDefinition;
+import org.apache.camel.model.OutputDefinition;
+import org.apache.camel.model.PipelineDefinition;
+import org.apache.camel.model.PolicyDefinition;
+import org.apache.camel.model.PollEnrichDefinition;
+import org.apache.camel.model.ProcessDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RecipientListDefinition;
+import org.apache.camel.model.RemoveHeaderDefinition;
+import org.apache.camel.model.RemovePropertyDefinition;
+import org.apache.camel.model.ResequenceDefinition;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.RoutingSlipDefinition;
+import org.apache.camel.model.SendDefinition;
+import org.apache.camel.model.SetBodyDefinition;
+import org.apache.camel.model.SetExchangePatternDefinition;
+import org.apache.camel.model.SetHeaderDefinition;
+import org.apache.camel.model.SetOutHeaderDefinition;
+import org.apache.camel.model.SetPropertyDefinition;
+import org.apache.camel.model.SortDefinition;
+import org.apache.camel.model.SplitDefinition;
+import org.apache.camel.model.StopDefinition;
+import org.apache.camel.model.ThreadsDefinition;
+import org.apache.camel.model.ThrottleDefinition;
+import org.apache.camel.model.TransactedDefinition;
+import org.apache.camel.model.TransformDefinition;
+import org.apache.camel.model.TryDefinition;
+import org.apache.camel.model.UnmarshalDefinition;
+import org.apache.camel.model.WhenDefinition;
+import org.apache.camel.model.language.ConstantExpression;
+import org.apache.camel.model.language.ExpressionDefinition;
+import org.apache.camel.processor.loadbalancer.FailOverLoadBalancer;
+import org.apache.camel.processor.loadbalancer.LoadBalancer;
+import org.apache.camel.processor.loadbalancer.RandomLoadBalancer;
+import org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer;
+import org.apache.camel.processor.loadbalancer.StickyLoadBalancer;
+import org.apache.camel.processor.loadbalancer.TopicLoadBalancer;
+
+/**
+ * Render routes in Groovy language
+ */
+public class GroovyRenderer implements TextRenderer {
+
+    public static final String header = "import org.apache.camel.language.groovy.GroovyRouteBuilder;\nclass GroovyRoute extends GroovyRouteBuilder {\nvoid configure() {\n";
+
+    public static final String footer = "\n}\n}";
+
+    /**
+     * render a RouteDefinition
+     * 
+     * @throws IOException
+     */
+    public void renderRoute(StringBuilder buffer, RouteDefinition route) {
+        // TODO Auto-generated method stub
+        List<FromDefinition> inputs = route.getInputs();
+        List<ProcessorDefinition> outputs = route.getOutputs();
+
+        // render the error handler
+        if (!(route.getErrorHandlerBuilder() instanceof ErrorHandlerBuilderRef)) {
+            if (route.getErrorHandlerBuilder() instanceof DeadLetterChannelBuilder) {
+                DeadLetterChannelBuilder deadLetter = (DeadLetterChannelBuilder)route.getErrorHandlerBuilder();
+                buffer.append("errorHandler(deadLetterChannel(\"").append(deadLetter.getDeadLetterUri()).append("\")");
+                buffer.append(".maximumRedeliveries(").append(deadLetter.getRedeliveryPolicy().getMaximumRedeliveries()).append(")");
+                buffer.append(".redeliverDelay(").append(deadLetter.getRedeliveryPolicy().getRedeliverDelay()).append(")");
+                buffer.append(".handled(").append(deadLetter.getHandledPolicy().toString()).append(")");
+                buffer.append(");");
+            }
+        }
+
+        // render the inputs of the router
+        buffer.append("from(");
+        for (FromDefinition input : inputs) {
+            buffer.append("\"").append(input.getUri()).append("\"");
+            if (input != inputs.get(inputs.size() - 1)) {
+                buffer.append(", ");
+            }
+        }
+        buffer.append(")");
+
+        // render the outputs of the router
+        for (ProcessorDefinition processor : outputs) {
+            renderProcessor(buffer, processor);
+        }
+    }
+
+    /**
+     * render a RoutesDefinition
+     */
+    public void renderRoutes(StringBuilder buffer, RoutesDefinition routes) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * render a ProcessorDefiniton
+     */
+    private void renderProcessor(StringBuilder buffer, ProcessorDefinition processor) {
+        if (processor instanceof AggregateDefinition) {
+            AggregateDefinitionRenderer.render(buffer, processor);
+        } else if (processor instanceof ChoiceDefinition) {
+            ChoiceDefinition choice = (ChoiceDefinition)processor;
+            buffer.append(".").append(choice.getShortName()).append("()");
+            for (WhenDefinition when : choice.getWhenClauses()) {
+                renderProcessor(buffer, when);
+            }
+            OtherwiseDefinition other = choice.getOtherwise();
+            if (other != null) {
+                renderProcessor(buffer, other);
+            }
+            buffer.append(".end()");
+            return;
+        } else if (processor instanceof ConvertBodyDefinition) {
+            ConvertBodyDefinition convertBody = (ConvertBodyDefinition)processor;
+            buffer.append(".").append(convertBody.getShortName()).append("(");
+            if (convertBody.getType().equals("[B")) {
+                buffer.append("byte[].class");
+            } else {
+                buffer.append(convertBody.getType()).append(".class");
+            }
+            if (convertBody.getCharset() != null) {
+                buffer.append(", \"").append(convertBody.getCharset()).append("\"");
+            }
+            buffer.append(")");
+        } else if (processor instanceof ExpressionNode) {
+            ExpressionNodeRenderer.render(buffer, processor);
+        } else if (processor instanceof LoadBalanceDefinition) {
+            LoadBalanceDefinition loadB = (LoadBalanceDefinition)processor;
+            // buffer.append(".").append(output.getShortName()).append("()");
+            buffer.append(".").append("loadBalance").append("()");
+
+            LoadBalancer lb = loadB.getLoadBalancerType().getLoadBalancer(null);
+            if (lb instanceof FailOverLoadBalancer) {
+                buffer.append(".failover()");
+            } else if (lb instanceof RandomLoadBalancer) {
+                buffer.append(".random()");
+            } else if (lb instanceof RoundRobinLoadBalancer) {
+                buffer.append(".roundRobin()");
+            } else if (lb instanceof StickyLoadBalancer) {
+                buffer.append(".sticky()");
+            } else if (lb instanceof TopicLoadBalancer) {
+                buffer.append(".topic()");
+            }
+
+            List<ProcessorDefinition> branches = loadB.getOutputs();
+            for (ProcessorDefinition branch : branches) {
+                renderProcessor(buffer, branch);
+            }
+            return;
+        } else if (processor instanceof OutputDefinition) {
+            OutputDefinitionRenderer.render(buffer, processor);
+        } else if (processor instanceof ResequenceDefinition) {
+            ResequenceDefinition resequence = (ResequenceDefinition)processor;
+            buffer.append(".").append(processor.getShortName()).append("(");
+            List<ExpressionBuilder> exps = null;
+            for (ExpressionBuilder exp : exps) {
+                buffer.append(exp.toString()).append("(),");
+            }
+            buffer.append(")");
+        } else if (processor instanceof RoutingSlipDefinition) {
+            RoutingSlipDefinition routingSlip = (RoutingSlipDefinition)processor;
+            buffer.append(".").append(routingSlip.getShortName()).append("(\"").append(routingSlip.getHeaderName()).append("\", \"").append(routingSlip.getUriDelimiter())
+                .append("\")");
+        } else if (processor instanceof SendDefinition) {
+            SendDefinitionRenderer.render(buffer, processor);
+        } else if (processor instanceof ThrottleDefinition) {
+            ThrottleDefinition throttle = (ThrottleDefinition)processor;
+            buffer.append(".").append(throttle.getShortName()).append("(").append(throttle.getMaximumRequestsPerPeriod()).append(")");
+            if (throttle.getTimePeriodMillis() != 1000) {
+                buffer.append(".timePeriodMillis(").append(throttle.getTimePeriodMillis()).append(")");
+            }
+        } else {
+            buffer.append(".").append(processor.getShortName()).append("()");
+        }
+
+        List<ProcessorDefinition> outputs = processor.getOutputs();
+        for (ProcessorDefinition nextProcessor : outputs) {
+            renderProcessor(buffer, nextProcessor);
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/GroovyRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/OutputDefinitionRenderer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/OutputDefinitionRenderer.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/OutputDefinitionRenderer.java (added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/OutputDefinitionRenderer.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.util;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.BeanDefinition;
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.model.EnrichDefinition;
+import org.apache.camel.model.FinallyDefinition;
+import org.apache.camel.model.InterceptDefinition;
+import org.apache.camel.model.InterceptSendToEndpointDefinition;
+import org.apache.camel.model.MarshalDefinition;
+import org.apache.camel.model.MulticastDefinition;
+import org.apache.camel.model.OtherwiseDefinition;
+import org.apache.camel.model.OutputDefinition;
+import org.apache.camel.model.PipelineDefinition;
+import org.apache.camel.model.PolicyDefinition;
+import org.apache.camel.model.PollEnrichDefinition;
+import org.apache.camel.model.ProcessDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RemoveHeaderDefinition;
+import org.apache.camel.model.RemovePropertyDefinition;
+import org.apache.camel.model.SetExchangePatternDefinition;
+import org.apache.camel.model.SortDefinition;
+import org.apache.camel.model.StopDefinition;
+import org.apache.camel.model.ThreadsDefinition;
+import org.apache.camel.model.TransactedDefinition;
+import org.apache.camel.model.TryDefinition;
+import org.apache.camel.model.UnmarshalDefinition;
+import org.apache.camel.model.language.ExpressionDefinition;
+
+/**
+ * 
+ */
+public class OutputDefinitionRenderer {
+
+    public static void render(StringBuilder buffer, ProcessorDefinition processor) {
+        OutputDefinition out = (OutputDefinition)processor;
+        buffer.append(".").append(out.getShortName());
+        if (out instanceof BeanDefinition) {
+
+        } else if (out instanceof EnrichDefinition) {
+            String enrich = out.toString();
+            String resourceUri = enrich.substring(enrich.indexOf('[') + 1, enrich.indexOf(' '));
+            buffer.append("(\"").append(resourceUri).append("\")");
+        } else if (out instanceof FinallyDefinition) {
+
+        } else if (out instanceof InterceptDefinition) {
+
+        } else if (out instanceof InterceptSendToEndpointDefinition) {
+
+        } else if (out instanceof MarshalDefinition) {
+            DataFormatDefinition dataFormat = ((MarshalDefinition)out).getDataFormatType();
+            buffer.append("().").append(dataFormat.getClass().getAnnotation(XmlRootElement.class).name()).append("()");
+        } else if (out instanceof MulticastDefinition) {
+
+        } else if (out instanceof OtherwiseDefinition) {
+            buffer.append("()");
+        } else if (out instanceof PipelineDefinition) {
+
+        } else if (out instanceof PolicyDefinition) {
+
+        } else if (out instanceof PollEnrichDefinition) {
+
+        } else if (out instanceof ProcessDefinition) {
+
+        } else if (out instanceof RemoveHeaderDefinition) {
+            RemoveHeaderDefinition remove = (RemoveHeaderDefinition)out;
+            buffer.append("(\"").append(remove.getHeaderName()).append("\")");
+        } else if (out instanceof RemovePropertyDefinition) {
+            RemovePropertyDefinition remove = (RemovePropertyDefinition)out;
+            buffer.append("(\"").append(remove.getPropertyName()).append("\")");
+        } else if (out instanceof SetExchangePatternDefinition) {
+
+        } else if (out instanceof SortDefinition) {
+            SortDefinition sort = (SortDefinition)out;
+            buffer.append("(");
+            ExpressionRenderer.renderExpression(buffer, sort.getExpression().toString());
+            buffer.append(")");
+        } else if (out instanceof StopDefinition) {
+
+        } else if (out instanceof ThreadsDefinition) {
+
+        } else if (out instanceof TransactedDefinition) {
+
+        } else if (out instanceof TryDefinition) {
+
+        } else if (out instanceof UnmarshalDefinition) {
+            DataFormatDefinition dataFormat = ((UnmarshalDefinition)out).getDataFormatType();
+            Class clazz = dataFormat.getClass();
+            buffer.append("().").append(dataFormat.getClass().getAnnotation(XmlRootElement.class).name()).append("()");
+        }
+    }
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/OutputDefinitionRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/PredicateRenderer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/PredicateRenderer.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/PredicateRenderer.java (added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/PredicateRenderer.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.util;
+
+import org.apache.camel.Predicate;
+
+/**
+ * 
+ */
+public class PredicateRenderer {
+
+    public static void renderPredicate(StringBuilder buffer, Predicate predicate) {
+        String pre = predicate.toString();
+        if (pre.contains("(")) {
+            pre = pre.replaceAll("\\(", "(\"").replaceAll("\\)", "\")");
+
+            String rightExp = pre.substring(pre.indexOf(" ") + 1);
+            if (rightExp.startsWith("==")) {
+                // replace == with isEqualTo
+                pre = pre.replaceFirst("\\ == ", ".isEqualTo(\"");
+                pre += "\")";
+            } else if (rightExp.startsWith("is not null")) {
+                pre = pre.replaceFirst("\\ is not null", ".isNotNull()");
+            }
+            buffer.append("(").append(pre).append(")");
+        } else {
+            String tmp[] = pre.split("\\s+");
+            buffer.append("(").append(tmp[0]).append("().").append(tmp[1]).append("(\"").append(tmp[2]).append("\"))");
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/PredicateRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/SendDefinitionRenderer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/SendDefinitionRenderer.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/SendDefinitionRenderer.java (added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/SendDefinitionRenderer.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.util;
+
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.SendDefinition;
+import org.apache.camel.model.WireTapDefinition;
+
+/**
+ * 
+ */
+public class SendDefinitionRenderer {
+
+    public static void render(StringBuilder buffer, ProcessorDefinition processor) {
+        buffer.append(".");
+        SendDefinition send = (SendDefinition)processor;
+        if (send instanceof WireTapDefinition || send.getPattern() == null) {
+            // for wireTap and simple to
+            buffer.append(send.getShortName());
+        } else {
+            // for inOnly and inOut
+            if (send.getPattern().name().equals("InOnly")) {
+                buffer.append("inOnly");
+            } else if (send.getPattern().name().equals("InOut")) {
+                buffer.append("inOut");
+            }
+        }
+        buffer.append("(\"").append(send.getUri()).append("\")");
+    }
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/SendDefinitionRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/TextRenderer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/TextRenderer.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/TextRenderer.java (added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/TextRenderer.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.camel.web.util;
+
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.RoutesDefinition;
+
+/**
+ * A Text Renderer which is used to marshal the route in specific language
+ */
+public interface TextRenderer {
+
+    void renderRoute(StringBuilder buffer, RouteDefinition route);
+
+    void renderRoutes(StringBuilder buffer, RoutesDefinition routes);
+
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/TextRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/edit.jsp
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/edit.jsp?rev=795901&r1=795900&r2=795901&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/edit.jsp (original)
+++ camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/edit.jsp Mon Jul 20 16:28:04 2009
@@ -14,13 +14,18 @@
 <table>
 	<tr>
 		<td>
-		<h2>Edit ${it.route.id}</h2>
+		<h2>Edit ${it.route.id} in ${it.language}</h2>
 		</td>
-		<td><input type="submit" value="Save">&nbsp; as &nbsp;<select id="language" name="language">
-			<option value="Xml" selected>XML</option>
-			<option value="Groovy">Groovy</option>
-			<option value="Ruby">Ruby</option>
-			<option value="Scala">Scala</option>
+		<td><input type="submit" value="Save">&nbsp; as &nbsp;<select
+			id="language" name="language">
+			<option value="Xml"
+				<c:if test="${it.language eq 'Xml'}">selected</c:if>>Xml</option>
+			<option value="Groovy"
+				<c:if test="${it.language eq 'Groovy'}">selected</c:if>>Groovy</option>
+			<option value="Ruby"
+				<c:if test="${it.language eq 'Ruby'}">selected</c:if>>Ruby</option>
+			<option value="Scala"
+				<c:if test="${it.language eq 'Scala'}">selected</c:if>>Scala</option>
 		</select></td>
 	</tr>
 	<tr>

Modified: camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/index.jsp
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/index.jsp?rev=795901&r1=795900&r2=795901&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/index.jsp (original)
+++ camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RouteResource/index.jsp Mon Jul 20 16:28:04 2009
@@ -18,7 +18,10 @@
 </div>
 
 <ul>
-<li><a href='<c:url value="/routes/${it.route.id}/edit"/>'>Edit Route</a>
+<li><a href='<c:url value="/routes/${it.route.id}/xml/edit"/>'>Edit Route in Xml</a>
+<li><a href='<c:url value="/routes/${it.route.id}/groovy/edit"/>'>Edit Route in Groovy</a>
+<li>Edit Route in Ruby
+<li>Edit Route in Scala 
 </ul>
 
 

Modified: camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp?rev=795901&r1=795900&r2=795901&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp (original)
+++ camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp Mon Jul 20 16:28:04 2009
@@ -16,7 +16,7 @@
   <c:forEach var="i" items="${it.routes}">
   <tr>
     <td>
-      <a href='<c:url value="/routes/${i.id}/edit"/>'>${i.id}</a> ${i.description.text}
+      <a href='<c:url value="/routes/${i.id}"/>'>${i.id}</a> ${i.description.text}
     </td>
     <td class="${i.status}">
       ${i.status}

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/AggregateDSLTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/AggregateDSLTest.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/AggregateDSLTest.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/AggregateDSLTest.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+import org.apache.camel.CamelException;
+
+/**
+ * a test case for aggregate DSL
+ */
+public class AggregateDSLTest extends GroovyRendererTestSupport {
+
+    public void testAggragate() throws Exception {
+        String DSL = "from(\"direct:start\").aggregate().header(\"cheese\").to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testAggragateCommon() throws Exception {
+        String DSL = "from(\"direct:start\").aggregate(header(\"cheese\")).to(\"mock:result\")";
+        String expectedDSL = "from(\"direct:start\").aggregate().header(\"cheese\").to(\"mock:result\")";
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testAggregateGroupedExchange() throws Exception {
+        String DSL = "from(\"direct:start\").aggregate().simple(\"id\").batchTimeout(500L).groupExchanges().to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testAggregateTimeoutOnly() throws Exception {
+        String DSL = "from(\"direct:start\").aggregate(header(\"id\")).batchTimeout(3000).batchSize(0).to(\"mock:result\")";
+        String expectedDSL = "from(\"direct:start\").aggregate().header(\"id\").batchTimeout(3000).batchSize(0).to(\"mock:result\")";
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    /**
+     * a route involving a external class: CamelException
+     * 
+     * @throws Exception
+     */
+    public void _testAggregateAndOnException() throws Exception {
+        String DSL = "errorHandler(deadLetterChannel(\"mock:error\"));onException(CamelException.class).maximumRedeliveries(2);from(\"direct:start\").aggregate(header(\"id\")).to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    /**
+     * a set of routes that uses aggregate DSL
+     * 
+     * @throws Exception
+     */
+    public void _testAggregateTimerAndTracer() throws Exception {
+        String DSL = "from(\"timer://kickoff?period=9999910000\").setHeader(\"id\").constant(\"foo\").setBody().constant(\"a b c\").split(body().tokenize(\" \")).to(\"seda:splitted\");"
+                     + "from(\"seda:splitted\").aggregate(header(\"id\")).to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/AggregateDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/ChoiceDSLTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/ChoiceDSLTest.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/ChoiceDSLTest.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/ChoiceDSLTest.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+/**
+ * a test case for choice DSL
+ */
+public class ChoiceDSLTest extends GroovyRendererTestSupport {
+
+    public void testChoiceWithMethod() throws Exception {
+        String DSL = "from(\"direct:start\").choice()" +
+        		".when().method(\"controlBean\", \"isDetour\").to(\"mock:detour\")" +
+        		".end()" +
+        		".to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testChoiceWithPredication() throws Exception {
+        String DSL = "from(\"direct:start\").choice()" +
+        		".when(header(\"username\").isNotNull()).to(\"mock:god\")" +
+        		".when(header(\"admin\").isEqualTo(\"true\")).to(\"mock:admin\")" +
+        		".otherwise().to(\"mock:guest\")" +
+        		".end()";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testChoiceWithoutEnd() throws Exception {
+        String DSL = "from(\"direct:start\").split().body().choice()" +
+        		".when().method(\"orderItemHelper\", \"isWidget\").to(\"bean:widgetInventory\", \"seda:aggregate\")" +
+        		".otherwise().to(\"bean:gadgetInventory\", \"seda:aggregate\")";
+        String expectedDSL = "from(\"direct:start\").split().body().choice()" +
+        		".when().method(\"orderItemHelper\", \"isWidget\").to(\"bean:widgetInventory\").to(\"seda:aggregate\")" +
+        		".otherwise().to(\"bean:gadgetInventory\").to(\"seda:aggregate\")" +
+        		".end()";
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/ChoiceDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/CovertBodyDSLTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/CovertBodyDSLTest.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/CovertBodyDSLTest.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/CovertBodyDSLTest.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+/**
+ * a test case for convertBody DSL: from().convertBodyTo().to()
+ */
+public class CovertBodyDSLTest extends GroovyRendererTestSupport {
+
+    public void testConvertBody() throws Exception {
+        String DSL = "from(\"direct:start\").convertBodyTo(Integer.class).to(\"mock:result\")";
+        String expectedDSL = "from(\"direct:start\").convertBodyTo(java.lang.Integer.class).to(\"mock:result\")";
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testConvertBodyWithEncoding() throws Exception {
+        String DSL = "from(\"direct:start\").convertBodyTo(byte[].class, \"iso-8859-1\").to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/CovertBodyDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DeadLetterDSLTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DeadLetterDSLTest.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DeadLetterDSLTest.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DeadLetterDSLTest.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+/**
+ * a test case for some deadLetter DSL: errorhandler(deadLetter()).to()
+ */
+public class DeadLetterDSLTest extends GroovyRendererTestSupport {
+
+    public void testDeadLetterWithDefaultRedeliverDelay() throws Exception {
+        String DSL = "errorHandler(deadLetterChannel(\"mock:failed\").maximumRedeliveries(0).handled(false));from(\"direct:start\").to(\"mock:result\")";
+        String expectedDSL = "errorHandler(deadLetterChannel(\"mock://failed\").maximumRedeliveries(0).redeliverDelay(1000).handled(false));from(\"direct:start\").to(\"mock:result\")";
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testDeadLetterWithDefaultHandled() throws Exception {
+        String DSL = "errorHandler(deadLetterChannel(\"mock:failed\").maximumRedeliveries(3).redeliverDelay(5000));from(\"direct:start\").to(\"mock:result\")";
+        String expectedDSL = "errorHandler(deadLetterChannel(\"mock://failed\").maximumRedeliveries(3).redeliverDelay(5000).handled(true));from(\"direct:start\").to(\"mock:result\")";
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testDeadLetterDSL() throws Exception {
+        String DSL = "errorHandler(deadLetterChannel(\"mock:failed\").maximumRedeliveries(3).redeliverDelay(5000).handled(false));from(\"direct:start\").to(\"mock:result\")";
+        String expectedDSL = "errorHandler(deadLetterChannel(\"mock://failed\").maximumRedeliveries(3).redeliverDelay(5000).handled(false));from(\"direct:start\").to(\"mock:result\")";
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DeadLetterDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DelayDSLTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DelayDSLTest.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DelayDSLTest.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DelayDSLTest.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+/**
+ * a test case for delay DSL: from().delay().to()
+ */
+public class DelayDSLTest extends GroovyRendererTestSupport {
+
+    public void testSimpleDelay() throws Exception {
+        String DSL = "from(\"direct:start\").delay(1000).to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testDelayWithHeaderParameter() throws Exception {
+        String DSL = "from(\"direct:start\").delay(header(\"MyDelay\")).to(\"mock:result\")";
+        String expectedDSL = "from(\"direct:start\").delay().header(\"MyDelay\").to(\"mock:result\")";
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testDelayWithHeaderMehtod() throws Exception {
+        String DSL = "from(\"direct:start\").delay().header(\"MyDelay\").to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/DelayDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/EnrichSetBodyDSLTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/EnrichSetBodyDSLTest.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/EnrichSetBodyDSLTest.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/EnrichSetBodyDSLTest.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+/**
+ * a test case for enricher DSL
+ */
+public class EnrichSetBodyDSLTest extends GroovyRendererTestSupport {
+
+    public void testEnricher() throws Exception {
+        String DSL = "from(\"direct:start\").setBody(body().append(\" World!\")).to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/EnrichSetBodyDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/FilterDSLTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/FilterDSLTest.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/FilterDSLTest.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/FilterDSLTest.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+/**
+ * a test case for filter DSL: from().filter().to()
+ */
+public class FilterDSLTest extends GroovyRendererTestSupport {
+
+    public void testFilterHeader() throws Exception {
+        String DSL = "from(\"direct:start\").filter(header(\"foo\").isEqualTo(\"bar\")).to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testFilterBody() throws Exception {
+        String DSL = "from(\"direct:start\").filter(body().contains(\"World\")).to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+    public void testFilterMethod() throws Exception {
+        String DSL = "from(\"direct:start\").filter().method(\"myBean\", \"matches\").to(\"mock:result\")";
+        String expectedDSL = DSL;
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/FilterDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTest.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTest.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTest.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+
+/**
+ * Test for GroovyRenderer
+ */
+public class GroovyRendererTest extends GroovyRendererTestSupport {
+
+    public void testRoute() throws Exception {
+        FileReader reader = new FileReader("src/test/resources/route.txt");
+        BufferedReader br = new BufferedReader(reader);
+        String dsl = null;
+        while ((dsl = br.readLine()) != null) {
+            System.out.println("dsl: " + dsl);
+            System.out.println("after rendered: \n" + render(dsl));
+            System.out.println();
+        }
+    }
+
+    public void _testRoutes() throws Exception {
+        FileReader reader = new FileReader("src/test/resources/testedRoutes.txt");
+        BufferedReader br = new BufferedReader(reader);
+        String dsl = null;
+        while ((dsl = br.readLine()) != null) {
+            if (dsl.startsWith("#")) {
+                continue;
+            }
+            System.out.println("dsl: " + dsl);
+            System.out.println("after rendered: \n" + render(dsl));
+            System.out.println();
+        }
+    }
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTestSupport.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTestSupport.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTestSupport.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+import groovy.lang.GroovyClassLoader;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.web.util.GroovyRenderer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * An abstract class that provides basic support for GroovyRenderer test
+ */
+public abstract class GroovyRendererTestSupport extends TestCase {
+
+    public final Log LOG = LogFactory.getLog(GroovyRendererTestSupport.class);
+
+    private final String header = GroovyRenderer.header;
+
+    private final String footer = GroovyRenderer.footer;
+
+    private CamelContext context;
+
+    public RouteDefinition createRoute(String dsl) throws Exception {
+        if (context != null) {
+            context.stop();
+        }
+        context = new DefaultCamelContext();
+
+        String routeStr = header + dsl + footer;
+        GroovyClassLoader classLoader = new GroovyClassLoader();
+        Class clazz = classLoader.parseClass(routeStr);
+        RouteBuilder builder = (RouteBuilder)clazz.newInstance();
+
+        context.addRoutes(builder);
+        List<RouteDefinition> list = context.getRouteDefinitions();
+        if (!list.isEmpty()) {
+            return list.get(0);
+        }
+        return null;
+    }
+
+    public String render(String dsl) throws Exception {
+        RouteDefinition route = createRoute(dsl);
+        assertNotNull(route);
+
+        StringBuilder sb = new StringBuilder();
+        new GroovyRenderer().renderRoute(sb, route);
+        return sb.toString();
+    }
+
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/GroovyRendererTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/LoadBalanceDSLTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/LoadBalanceDSLTest.java?rev=795901&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/LoadBalanceDSLTest.java (added)
+++ camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/LoadBalanceDSLTest.java Mon Jul 20 16:28:04 2009
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.web.groovy;
+
+/**
+ * a test case for loadBalance DSL
+ */
+public class LoadBalanceDSLTest extends GroovyRendererTestSupport {
+
+    public void testFromTo() throws Exception {
+        String DSL = "from(\"direct:start\").loadBalance().random().to(\"mock:x\", \"mock:y\", \"mock:z\")";
+        String expectedDSL = "from(\"direct:start\").loadBalance().random().to(\"mock:x\").to(\"mock:y\").to(\"mock:z\")";
+
+        assertEquals(expectedDSL, render(DSL));
+    }
+
+}

Propchange: camel/trunk/components/camel-web/src/test/java/org/apache/camel/web/groovy/LoadBalanceDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native