cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/webapp/samples/flow/jxcalc sitemap.xmap calc.js
Date Mon, 13 Oct 2003 13:32:17 GMT
cziegeler    2003/10/13 06:32:17

  Modified:    src/webapp/samples/flow samples.xml
  Added:       src/webapp/samples/flow/jxcalc/screens getNumberA.xml
                        getOperator.xml getNumberB.xml displayResult.xml
               src/webapp/samples/flow/jxcalc sitemap.xmap calc.js
  Log:
  Adding jx based calculator demo
  
  Revision  Changes    Path
  1.5       +4 -1      cocoon-2.1/src/webapp/samples/flow/samples.xml
  
  Index: samples.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/flow/samples.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- samples.xml	1 Aug 2003 09:41:23 -0000	1.4
  +++ samples.xml	13 Oct 2003 13:32:17 -0000	1.5
  @@ -16,6 +16,9 @@
       to describe the web application flow between screens in a coherent 
       unique location and continuations to maintain state between requests.
      </sample>
  +    <sample name="Calculator 2" href="jxcalc/">
  +     Same sample as the calculator but using the JXGenerator instead of XSP.
  +    </sample>
      <sample name="User Preferences" href="prefs/">
       A common portion of an application which requires users to be
   	registered. This example shows how to use java objects from the 
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/jxcalc/screens/getNumberA.xml
  
  Index: getNumberA.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!--+
      | CVS: $Id: getNumberA.xml,v 1.1 2003/10/13 13:32:17 cziegeler Exp $
      | Author: Ovidiu Predescu "ovidiu@cup.hp.com"
      | Date: March 23, 2002
      +-->
  
  <page>
      <resources>
        <resource type="file" href="/samples/flow/calc/calc.js">Flowscript</resource>
      </resources>
      <title>Calculator</title>
      <content>
        <form method="post" action="continue.#{$continuation/id}">
          <para>Enter value of <strong>a</strong>: <input type="text"
name="a"/></para>
          <input type="submit" name="submit" value="Enter"/>
        </form>
      </content>
  </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/jxcalc/screens/getOperator.xml
  
  Index: getOperator.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!--+
      | CVS: $Id: getOperator.xml,v 1.1 2003/10/13 13:32:17 cziegeler Exp $
      | Author: Ovidiu Predescu "ovidiu@cup.hp.com"
      | Date: March 23, 2002
      +-->
  
  <page>
      <resources>
        <resource type="file" href="/samples/flow/calc/calc.js">Flowscript</resource>
      </resources>
      <title>Calculator</title>
      <content>
        <form  method="post" action="continue.#{$continuation/id}">
          <para>a = <strong>#{a}</strong></para>
          <para>b = <strong>#{b}</strong></para>
          <para>Enter operator
            <select name="operator">
              <option>plus</option>
              <option>minus</option>
              <option>multiply</option>
              <option>divide</option>
            </select>
          </para>
          <input type="submit" name="submit" value="Do it!"/>
        </form>
      </content>
    </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/jxcalc/screens/getNumberB.xml
  
  Index: getNumberB.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!--+
      | CVS: $Id: getNumberB.xml,v 1.1 2003/10/13 13:32:17 cziegeler Exp $
      | Author: Ovidiu Predescu "ovidiu@cup.hp.com"
      | Date: March 23, 2002
      +-->
  
  <page>
      <resources>
        <resource type="file" href="/samples/flow/calc/calc.js">Flowscript</resource>
      </resources>
      <title>Calculator</title>
      <content>
        <form method="post" action="continue.#{$continuation/id}">
          <para>a = <strong>#{a}</strong></para>
          <para>Enter value of <strong>b</strong>: <input type="text"
name="b"/></para>
          <input type="submit" name="submit" value="Enter"/>
        </form>
      </content>
  </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/jxcalc/screens/displayResult.xml
  
  Index: displayResult.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!--+
      | CVS: $Id: displayResult.xml,v 1.1 2003/10/13 13:32:17 cziegeler Exp $
      | Author: Ovidiu Predescu "ovidiu@cup.hp.com"
      | Date: March 23, 2002
      +-->
  
  <page>
      <resources>
        <resource type="file" href="/samples/flow/calc/calc.js">Flowscript</resource>
      </resources>
      <title>Calculator</title>
      <content>
        <form action="./" method="post">
          <para>a = <strong>#{a}</strong></para>
          <para>b = <strong>#{b}</strong></para>
          <para>Operator = <strong>#{operator}</strong></para>
          <para>Result = <strong>#{result}</strong></para>
          <input type="submit" name="submit" value="Start over"/>
        </form>
      </content>
  </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/jxcalc/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  <?xml version="1.0"?>
  
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
   <map:components>
  
    <map:generators default="file">   
      <map:generator name="jx" src="org.apache.cocoon.generation.JXTemplateGenerator" label="content"
logger="sitemap.generator.jx"/>
    </map:generators>
  
  </map:components>
  
    <!-- indicates what flowscript to attach to this sitemap -->
    <map:flow language="javascript">
      <map:script src="calc.js"/>
    </map:flow>
  
    <map:pipelines>
      <map:pipeline>
        <!--+
            | produces the screens called by the flowscript
            +-->     
        <map:match pattern="page/*">
          <map:generate type="jx" src="screens/{1}.xml"/>
          <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
            <map:parameter name="servletPath" value="{request:servletPath}"/>
            <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
            <map:parameter name="contextPath" value="{request:contextPath}"/>
            <map:parameter name="file" value="/samples/flow/jxcalc/screens/{1}.xml"/>
            <map:parameter name="remove" value="{0}"/>
          </map:transform>
          <map:serialize/>
        </map:match>
      </map:pipeline>
  
      <map:pipeline>
        <!--+
            | matches the page with the continuation ID and calls the flowscript
            | associated to this sitemap with the given continuation ID. The flow
            | engine will then look into the continuation store, retrieve
            | the correct continuation and resume execution of the flowscript
            | with that continuation. This guarantees transparent state 
            | resumption between requests without the need for anything else
            | (cookies or URL-encoded session IDs)
            +-->
        <map:match pattern="continue.*">
          <map:call continuation="{1}"/>
        </map:match>
  
        <!--+
            | matches the call to the beginning of the flow and calls the flow
            | from its entry point which, in this case is the 'calculator()'
            | javascript function.
            +-->
        <map:match pattern="">
          <map:call function="calculator"/>
        </map:match>
  
      </map:pipeline>
    </map:pipelines>
  </map:sitemap>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/jxcalc/calc.js
  
  Index: calc.js
  ===================================================================
  var a, b, op;
  
  function calculator()
  {
    a = getNumber("a");
    b = getNumber("b", a);
    op = getOperator(a, b);
  
    if (op == "plus")
      sendResult(a, b, op, a + b);
    else if (op == "minus")
      sendResult(a, b, op, a - b);
    else if (op == "multiply")
      sendResult(a, b, op, a * b);
    else if (op == "divide")
      sendResult(a, b, op, a / b);
    else
      sendResult("Error: Unkown operator!");
  }
  
  function getNumber(name, a, b)
  {
    var uri = "page/getNumber" + name.toUpperCase();
    cocoon.sendPageAndWait(uri, { "a" : a, "b" : b });
    return parseFloat(cocoon.request.getParameter(name));
  }
  
  function getOperator(a, b)
  {
    cocoon.sendPageAndWait("page/getOperator", { "a" : a, "b" : b });
    return cocoon.request.operator;
  }
  
  function sendResult(a, b, op, result)
  {
    cocoon.sendPage("page/displayResult",
             { 
                  "a" : a, 
                  "b" : b, 
                  "operator" : op, 
                  "result" : result 
             }
    );
  }
  
  
  

Mime
View raw message