01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.flow.java.test;
18:
19: import org.apache.cocoon.components.flow.java.*;
20:
21: public class CalculatorFlow extends AbstractContinuable {
22:
23: public void run() {
24:
25: float a, b;
26: String op;
27: String uri = "page/";
28:
29: sendPageAndWait(uri + "getNumberA");
30: a = Float.parseFloat(getRequest().getParameter("a"));
31: System.out.println("a=" + a);
32:
33: sendPageAndWait(uri + "getNumberB", new VarMap().add("a", a));
34: b = Float.parseFloat(getRequest().getParameter("b"));
35: System.out.println("b=" + b);
36:
37: sendPageAndWait(uri + "getOperator", new VarMap().add("a", a)
38: .add("b", b));
39: op = getRequest().getParameter("operator");
40: System.out.println("operator=" + op);
41:
42: if ("plus".equals(op)) {
43: System.out.println("result=" + (a + b));
44: sendPage(uri + "displayResult", new VarMap().add("a", a)
45: .add("b", b).add("operator", op).add("result",
46: a + b));
47: } else if ("minus".equals(op)) {
48: System.out.println("result=" + (a - b));
49: sendPage(uri + "displayResult", new VarMap().add("a", a)
50: .add("b", b).add("operator", op).add("result",
51: a - b));
52: } else if ("multiply".equals(op)) {
53: System.out.println("result=" + (a * b));
54: sendPage(uri + "displayResult", new VarMap().add("a", a)
55: .add("b", b).add("operator", op).add("result",
56: a * b));
57: } else if ("divide".equals(op)) {
58: if (b == 0) {
59: //sendPage("Error: Division by zero!");
60: } else {
61: System.out.println("result=" + (a / b));
62: sendPage(uri + "displayResult", new VarMap()
63: .add("a", a).add("b", b).add("operator", op)
64: .add("result", a / b));
65: }
66: } else {
67: //sendPage("Error: Unkown operator!");
68: }
69: }
70: }
|