cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r427845 - in /cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java: ./ org/ org/apache/ org/apache/cocoon/ org/apache/cocoon/samples/ org/apache/cocoon/samples/flow/ org/apache/cocoon/samples/flow/java/
Date Wed, 02 Aug 2006 01:35:28 GMT
Author: simoneg
Date: Tue Aug  1 18:35:27 2006
New Revision: 427845

URL: http://svn.apache.org/viewvc?rev=427845&view=rev
Log:
Readded the samples sources, removed 'do' before method names

Added:
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/FormFlow.java

Added: cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java?rev=427845&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java
(added)
+++ cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/CalculatorFlow.java
Tue Aug  1 18:35:27 2006
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.samples.flow.java;
+
+import org.apache.cocoon.components.flow.java.AbstractContinuable;
+import org.apache.cocoon.components.flow.java.VarMap;
+
+public class CalculatorFlow extends AbstractContinuable {
+
+    private int count = 1;
+
+    public void calculator() {
+        float a = getNumber("a", 0f, 0f);
+        float b = getNumber("b", a, 0f);
+        String op = getOperator(a, b);
+
+        if (op.equals("plus")) {
+            sendResult(a, b, op, a + b);
+        } else if (op.equals("minus")) {
+            sendResult(a, b, op, a - b);
+        } else if (op.equals("multiply")) {
+            sendResult(a, b, op, a * b);
+        } else if (op.equals("divide")) {
+            if (b==0f)
+                sendMessage("Error: Cannot divide by zero!");
+            sendResult(a, b, op, a / b);
+        } else {
+            sendMessage("Error: Unkown operator!");
+        }
+
+        count++;
+    }
+
+    private float getNumber(String name, float a, float b) {
+        String uri = "page/calculator-" + name.toLowerCase();
+        sendPageAndWait(uri, new VarMap().add("a", a).add("b", b).add("count", count));
+
+        float value = 0f;
+        try {
+            value = Float.parseFloat(getRequest().getParameter(name));
+        } catch (Exception e) {
+            sendMessage("Error: \""+getRequest().getParameter(name)+"\" is not a correct
number!");
+        }
+        return value;
+    }
+
+    private String getOperator(float a, float b) {
+        sendPageAndWait("page/calculator-operator", new VarMap().add("a", a).add("b", b).add("count",
count));
+        return getRequest().getParameter("operator");
+    }
+
+    private void sendResult(float a, float b, String op, float result) {
+        sendPage("page/calculator-result", new VarMap().add("a", a).add("b", b).add("operator",
op).add("result", result).add("count", count));
+    }
+
+    private void sendMessage(String message) {
+        sendPageAndWait("page/calculator-message", new VarMap().add("message", message).add("count",
count));
+    }
+}

Added: cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/FormFlow.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/FormFlow.java?rev=427845&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/FormFlow.java
(added)
+++ cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-sample/src/main/java/org/apache/cocoon/samples/flow/java/FormFlow.java
Tue Aug  1 18:35:27 2006
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.samples.flow.java;
+
+import java.util.Date;
+
+import org.apache.cocoon.components.flow.java.AbstractContinuable;
+import org.apache.cocoon.components.flow.java.VarMap;
+import org.apache.cocoon.forms.binding.BindingException;
+import org.apache.cocoon.forms.flow.java.FormInstance;
+import org.apache.cocoon.forms.formmodel.BooleanField;
+import org.apache.cocoon.forms.formmodel.Field;
+import org.apache.cocoon.forms.formmodel.Repeater;
+import org.apache.cocoon.forms.samples.Contact;
+import org.apache.cocoon.forms.samples.Form2Bean;
+import org.apache.cocoon.forms.samples.Sex;
+
+public class FormFlow extends AbstractContinuable {
+
+    public void editForm1() {
+
+        FormInstance form = new FormInstance("forms/form1.xml");
+
+        Field birthDate = (Field) form.getChild("birthdate");
+        birthDate.setValue(new Date());
+
+        Repeater repeater = (Repeater) form.getChild("contacts");
+        repeater.addRow();
+        Field field = (Field) repeater.getWidget(0, "firstname");
+        field.setValue("Jules");
+
+        repeater.addRow();
+        field = (Field) repeater.getWidget(1, "firstname");
+        field.setValue("Lucien");
+
+        form.show("form/form1");
+
+        sendPage("page/form1-result", new VarMap().add("email", ((Field)form.getChild("email")).getValue())
+                                                  .add("somebool", ((BooleanField)form.getChild("somebool")).getValue())
+                                                  .add("firstname", ((Field)((Repeater)form.getChild("contacts")).getWidget(1,
"firstname")).getValue()));
+    }
+
+    public void editForm2() throws BindingException {
+        Form2Bean bean = new Form2Bean();
+
+        // fill bean with some data to avoid users having to type to much
+        bean.setEmail("yourname@yourdomain.com");
+        bean.setIpAddress("10.0.0.1");
+        bean.setPhoneCountry("32");
+        bean.setPhoneZone("2");
+        bean.setPhoneNumber("123456");
+        bean.setBirthday(new java.util.Date());
+        bean.setSex(Sex.FEMALE);
+        Contact contact = new Contact();
+        contact.setId(1);
+        contact.setFirstName("Hermann");
+        bean.addContact(contact);
+
+        FormInstance form = new FormInstance("forms/form2.xml", "forms/form2-binding.xml");
+        form.load(bean);
+        form.show("form/form2");
+        form.save(bean);
+                                         
+        sendPage("page/form2-result", new VarMap().add("form2bean", bean));
+    }
+}



Mime
View raw message