stefano     2003/03/25 07:11:32

  Modified:    src/webapp/samples/flow sitemap.xmap
  Added:       src/webapp/samples/flow samples.xml invalidContinuation.xml
                        README.txt
               src/webapp/samples/flow/calc/screens getNumberB.xsp
                        displayResult.xsp getOperator.xsp getNumberA.xsp
               src/webapp/samples/flow/prefs/screens welcome.xsp login.xsp
                        userInfo.xsp registrationSuccessful.xsp
               src/webapp/samples/flow/prefs prefs.js sitemap.xmap
               src/webapp/samples/flow/test sendpage.js sitemap.xmap
               src/webapp/samples/flow/calc calc.js sitemap.xmap
               src/webapp/samples/flow/test/screens showString.xsp
  Removed:     src/webapp/samples/flow/docs .cvsignore continuations.xml
                        samples.xml invalidContinuation.xml index.xml
                        book.xml how-does-it-work.xml
               src/webapp/samples/flow/examples/calc/pages getNumberB.xsp
                        displayResult.xsp getNumberA.xsp getOperator.xsp
               src/webapp/samples/flow/examples/test/pages showString.xsp
               src/webapp/samples/flow/examples/prefs/pages
                        registrationSuccessful.xsp login.xsp userInfo.xsp
                        welcome.xsp
               src/webapp/samples/flow/examples/prefs sitemap.xmap prefs.js
               src/webapp/samples/flow/examples/test sitemap.xmap
                        README.txt sendpage.js
               src/webapp/samples/flow/examples/calc calc.js sitemap.xmap
               src/webapp/samples/flow/stylesheets
                        extended-document2html.xsl
  Log:
  refactored flow samples
  
  Revision  Changes    Path
  1.5       +11 -116   cocoon-2.1/src/webapp/samples/flow/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/flow/sitemap.xmap,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- sitemap.xmap      20 Mar 2003 02:42:57 -0000      1.4
  +++ sitemap.xmap      25 Mar 2003 15:11:27 -0000      1.5
  @@ -3,137 +3,32 @@
   <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0";>
   
     <map:components>
  -    <map:generators default="file">
  -        <map:generator label="content,data" 
logger="sitemap.generator.flow_velocity" name="flow_velocity" 
src="org.apache.cocoon.generation.FlowVelocityGenerator"/>
  -    </map:generators>
  -    <map:transformers default="xslt">
  -     <map:transformer name="augment"
  -                      src="org.apache.cocoon.transformation.AugmentTransformer"
  -                      mime-type="text/xml"
  -                      logger="sitemap.transformer.augment"/>
  -    </map:transformers>
  +    <map:generators default="file"/>
  +    <map:transformers default="xslt"/>
       <map:readers default="resource"/>
       <map:serializers default="html"/>
       <map:matchers default="wildcard"/>
       <map:flow-interpreters default="JavaScript"/>
     </map:components>
   
  -  <map:resources>
  -    <map:resource name="show-page">
  -      <map:aggregate element="site">
  -        <map:part src="cocoon:/book-{full-filename}.xml"/>
  -        <map:part src="cocoon:/body-{full-filename}.xml"/>
  -      </map:aggregate>
  -      <map:transform src="context://docs/stylesheets/site2xhtml.xsl">
  -        <map:parameter name="use-request-parameters" value="true"/>
  -        <map:parameter name="header" value="graphics/{filename}-header.jpg"/>
  -      </map:transform>
  -      <map:serialize/>
  -    </map:resource>
  -  </map:resources>
  -
     <map:pipelines>
   
  -    <!-- Flow documentation pipeline -->
       <map:pipeline>
  -      <map:match pattern="">
  -        <map:redirect-to uri="index.html"/>
  -      </map:match>
   
  -      <map:match pattern="**book-**.xml">
  -        <map:generate src="docs/{1}book.xml"/>
  -        <map:transform type="augment">
  -          <map:parameter name="mount" value="samples/flow/"/>
  -        </map:transform>
  -        <map:transform src="context://docs/stylesheets/book2menu.xsl">
  -          <map:parameter name="use-request-parameters" value="true"/>
  -          <map:parameter name="resource" value="{2}.html"/>
  +      <map:match pattern="">
  +        <map:generate src="samples.xml"/>
  +        <map:transform 
src="context://samples/common/style/xsl/html/simple-samples2html.xsl">
  +           <map:parameter name="contextPath" value="{request:contextPath}"/>
           </map:transform>
  -        <map:serialize type="xml"/>
  -      </map:match>
  -
  -      <map:match pattern="body-examples/*/**.xml">
  -        <map:generate src="examples/{1}/pages/{2}.xsp" type="serverpages"/>
  -        <map:transform src="stylesheets/extended-document2html.xsl"/>
  -        <map:serialize type="xml"/>
  -      </map:match>
  -
  -      <map:match pattern="body-**.xml">
  -        <map:generate src="docs/{1}.xml"/>
  -        <map:transform src="context://docs/stylesheets/document2html.xsl"/>
           <map:serialize/>
         </map:match>
   
  -      <map:match pattern="*.html">
  -        <map:call resource="show-page">
  -          <map:parameter name="filename" value="{1}"/>
  -          <map:parameter name="full-filename" value="{1}"/>
  -        </map:call>
  -      </map:match>
  -
  -      <map:match pattern="**/*.html">
  -        <map:call resource="show-page">
  -          <map:parameter name="filename" value="{2}"/>
  -          <map:parameter name="full-filename" value="{1}/{2}"/>
  -        </map:call>
  -      </map:match>
  -
  -      <map:match pattern="**resources/script.js">
  -        <map:read src="context://docs/stylesheets/script-cli.js"
  -                  mime-type="application/javascript"/>
  -      </map:match>
  -
  -      <map:match pattern="**resources/**.js">
  -        <map:read src="context://docs/stylesheets/{2}.js"
  -                  mime-type="application/javascript"/>
  -      </map:match>
  -
  -      <map:match pattern="**.css">
  -       <map:read src="context://docs/{1}.css" mime-type="text/css"/>
  -      </map:match>
  -
  -      <map:match pattern="**images/*.png">
  -       <map:read src="context://docs/images/{2}.png"
  -                 mime-type="image/png"/>
  -      </map:match>
  -
  -      <map:match pattern="**images/*.jpg">
  -       <map:read src="context://docs/images/{2}.jpg"
  -                 mime-type="image/jpeg"/>
  -      </map:match>
  -
  -      <map:match pattern="**images/*.gif">
  -       <map:read src="context://docs/images/{2}.gif"
  -                 mime-type="image/gif"/>
  -      </map:match>
  -
  -      <map:match pattern="**graphics/**-*.jpg">
  -        <map:generate src="svg/{3}.xml"/>
  -        <map:transform src="svg/addlabel.xsl">
  -          <map:parameter name="use-request-parameters" value="true"/>
  -          <map:parameter name="label" value="{2}"/>
  -        </map:transform>
  -        <map:serialize type="svg2jpeg"/>
  -      </map:match>
  -    </map:pipeline>
  -
  -     <!-- All examples are located under the examples/ directory, and
  -     are standalone samples, with their own sitemap. The following
  -     generic mount operation loads them on demand. -->
  -    <map:pipeline>
  -      <map:match pattern="examples/**/invalidContinuation.xml">
  -        <map:call resource="show-page">
  -          <map:parameter name="filename" value="invalidContinuation"/>
  -          <map:parameter name="full-filename" value="invalidContinuation"/>
  -        </map:call>
  -      </map:match>
  -
  -      <map:match pattern="examples/*/**">
  -        <map:mount uri-prefix="examples/{1}"
  -                   src="examples/{1}/sitemap.xmap"
  -                   check-reload="yes"/>
  +      <map:match pattern="*/**">
  +        <map:mount uri-prefix="{1}" src="{1}/" check-reload="yes"/>
         </map:match>
  +      
       </map:pipeline>
  -
  +    
     </map:pipelines>
  +  
   </map:sitemap>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/samples.xml
  
  Index: samples.xml
  ===================================================================
  <?xml version="1.0" encoding="iso-8859-1"?>
  
  <!-- CVS $Id: samples.xml,v 1.1 2003/03/25 15:11:27 stefano Exp $ -->
  
  <samples>
  
    <group name="Flowscript">
      <sample name="Calculator" href="calc/">
      A simple web-based calculator that uses javascript on the server side
      to describe the web application flow between screens in a coherent 
      unique location and continuations to maintain state between requests.
     </sample>
     <sample name="User Preferences" href="pref/">
      A common portion of an application which requires users to be
        registered. This example shows how to use java objects from the 
        javascript flow as it is best practice to put business logic into
        strongly-typed java objects and use javascript to describe only the
        page flow.
     </sample>
    </group>
    
  </samples>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/invalidContinuation.xml
  
  Index: invalidContinuation.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" 
"../../WEB-INF/entities/document-v10.dtd">
  
  <document>
    <header>
      <title>404 Error</title>
      <authors>
        <person name="Ovidiu Predescu" email="[EMAIL PROTECTED]"/>
      </authors>
    </header>
  
    <body>
      <s1 title="Error">
        <p>You have reached an inexistent page: either your session has
        expired or the page you were referred to was invalid.</p>
      </s1>
    </body>
  </document>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/README.txt
  
  Index: README.txt
  ===================================================================
  These samples are being tested with the anteater webapp automated testing scripts. 
  
  Please don't modify things in this directory without modifying
  the appropriate Anteater scripts in src/test/anteater/.
  
  Thanks.
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/calc/screens/getNumberB.xsp
  
  Index: getNumberB.xsp
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    Author: Ovidiu Predescu "[EMAIL PROTECTED]"
  
    Date: March 23, 2002
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    >
    
    <document>
      <header>
        <title>Calculator</title>
      </header>
      <body>
        <s1 title="Calculator">
          <form><xsp:attribute 
name="action"><xsp:expr><jpath:continuation/></xsp:expr></xsp:attribute>
            <p>a = <strong><jpath:value-of select="a"/></strong></p>
            <p>Enter value of <strong>b</strong>: <input type="text" name="b"/></p>
            <input type="submit" name="submit" value="Enter"/>
          </form>
        </s1>
      </body>
    </document>
  </xsp:page>
  
  
  
  
  1.1                  
cocoon-2.1/src/webapp/samples/flow/calc/screens/displayResult.xsp
  
  Index: displayResult.xsp
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    Author: Ovidiu Predescu "[EMAIL PROTECTED]"
  
    Date: March 23, 2002
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    >
    
    <document>
      <header>
        <title>Calculator</title>
      </header>
      <body>
        <s1 title="Calculator">
          <form action="../calc/">
            <p>a = <strong><jpath:value-of select="a"/></strong></p>
            <p>b = <strong><jpath:value-of select="b"/></strong></p>
            <p>Operator = <strong><jpath:value-of select="operator"/></strong></p>
            <p>Result = <strong><jpath:value-of select="result"/></strong></p>
            <input type="submit" name="submit" value="Start over"/>
          </form>
        </s1>
      </body>
    </document>
  </xsp:page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/calc/screens/getOperator.xsp
  
  Index: getOperator.xsp
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    Author: Ovidiu Predescu "[EMAIL PROTECTED]"
  
    Date: March 23, 2002
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    >
    
    <document>
      <header>
        <title>Calculator</title>
      </header>
      <body>
        <s1 title="Calculator">
          <form><xsp:attribute 
name="action"><xsp:expr><jpath:continuation/></xsp:expr></xsp:attribute>
            <p>a = <strong><jpath:value-of select="a"/></strong></p>
            <p>b = <strong><jpath:value-of select="b"/></strong></p>
            <p>Enter operator
              <select name="operator">
                <option>plus</option>
                <option>minus</option>
                <option>multiply</option>
                <option>divide</option>
              </select>
            </p>
            <input type="submit" name="submit" value="Do it!"/>
          </form>
        </s1>
      </body>
    </document>
  </xsp:page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/calc/screens/getNumberA.xsp
  
  Index: getNumberA.xsp
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    Author: Ovidiu Predescu "[EMAIL PROTECTED]"
  
    Date: March 23, 2002
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    >
  
    <document>
      <header>
        <title>Calculator</title>
      </header>
      <body>
        <s1 title="Calculator">
          <form><xsp:attribute name="action"><xsp:expr>"kont/" + 
<jpath:continuation/></xsp:expr></xsp:attribute>
            <p>Enter value of <strong>a</strong>: <input type="text" name="a"/></p>
            <input type="submit" name="submit" value="Enter"/>
          </form>
        </s1>
      </body>
    </document>
  </xsp:page>
  
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/prefs/screens/welcome.xsp
  
  Index: welcome.xsp
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    Author: Ovidiu Predescu "[EMAIL PROTECTED]"
  
    Date: August 30, 2002
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    >
    
    <document>
      <header>
        <title>Welcome!</title>
      </header>
      <body>
        <s1 title="Welcome back!">
          <p>Welcome back, <strong><jpath:value-of select="user/firstName"/> 
<jpath:value-of select="user/lastName"/></strong>!</p>
          <p>| <link href="../edit">Edit my preferences</link> | <link 
href="../logout">Logout</link> |</p>
        </s1>
      </body>
    </document>
    
  </xsp:page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/prefs/screens/login.xsp
  
  Index: login.xsp
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    Author: Ovidiu Predescu "[EMAIL PROTECTED]"
  
    Date: August 30, 2002
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    >
    
    <document>
      <header>
        <title>Login</title>
      </header>
      <body>
        <s1 title="Login">
          <jpath:if test="errorMsg">
            <strong><jpath:value-of select="errorMsg"/></strong>
          </jpath:if>
          <form><xsp:attribute name="action"><xsp:expr>"../kont/" + 
<jpath:continuation/></xsp:expr></xsp:attribute>
            <p>Login name:
              <input type="text" name="login">
                <xsp:attribute name="value"><jpath:value-of 
select="login"/></xsp:attribute>
              </input>
            </p>
            <p>Password: <input type="password" name="password"/></p>
            <input type="submit" name="submit" value="Login"/>
            <p>Not yet registered? <link href="../register">Register now!</link></p>
          </form>
        </s1>
      </body>
    </document>
    
  </xsp:page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/prefs/screens/userInfo.xsp
  
  Index: userInfo.xsp
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    Author: Ovidiu Predescu "[EMAIL PROTECTED]"
  
    Page to show the user information.
  
    This page is used for both user registration and editing the user
    information, depending on the information passed down in the page.
  
    Date: August 30, 2002
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    >
    
    <document>
      <header>
        <title><jpath:value-of select="title"/></title>
      </header>
      <body>
        <s1>
          <xsp:attribute name="title"><jpath:value-of select="title"/></xsp:attribute>
          <jpath:choose>
            <jpath:when test="errorMsg">
              <p><strong><jpath:value-of select="errorMsg"/></strong></p>
            </jpath:when>
            <jpath:otherwise>
              <p>Please enter the following data</p>
            </jpath:otherwise>
          </jpath:choose>
  
          <form><xsp:attribute name="action"><xsp:expr>"../kont/" + 
<jpath:continuation/></xsp:expr></xsp:attribute>
  
            <p>
              <jpath:choose>
                <jpath:when test="check and firstName = ''">
                  <strong>First name cannot be empty</strong>
                </jpath:when>
                <jpath:otherwise>
                  First name:
                </jpath:otherwise>
              </jpath:choose>
              <input type="text" name="firstName">
                <xsp:attribute name="value"><jpath:value-of 
select="firstName"/></xsp:attribute>
              </input>
            </p>
  
            <p>
              <jpath:choose>
                <jpath:when test="check and lastName = ''">
                  <strong>Last name cannot be empty</strong>
                </jpath:when>
                <jpath:otherwise>
                  Last name:
                </jpath:otherwise>
              </jpath:choose>
              <input type="text" name="lastName">
                <xsp:attribute name="value"><jpath:value-of 
select="lastName"/></xsp:attribute>
              </input>
            </p>
  
            <p>
              <jpath:choose>
                <jpath:when test="check and email = ''">
                  <strong>Email address cannot be empty</strong>
                </jpath:when>
                <jpath:otherwise>
                  Email address:
                </jpath:otherwise>
              </jpath:choose>
              <input type="text" name="email">
                <xsp:attribute name="value"><jpath:value-of 
select="email"/></xsp:attribute>
              </input>
            </p>
  
            <p>
              <jpath:choose>
                <jpath:when test="check and login = ''">
                  <strong>Login name cannot be empty</strong>
                </jpath:when>
                <jpath:otherwise>
                  Login name:
                </jpath:otherwise>
              </jpath:choose>
              <input type="text" name="login">
                <xsp:attribute name="value"><jpath:value-of 
select="login"/></xsp:attribute>
              </input>
            </p>
  
  
            <p>
              <jpath:choose>
                <jpath:when test="check and password = ''">
                  <strong>Password cannot be empty</strong>
                </jpath:when>
                <jpath:otherwise>
                  Password:
                </jpath:otherwise>
              </jpath:choose>
              <input type="password" name="password">
                <xsp:attribute name="value"><jpath:value-of 
select="password"/></xsp:attribute>
              </input>
            </p>
  
  
            <input type="submit" name="submit">
              <xsp:attribute name="value"><jpath:value-of 
select="button"/></xsp:attribute>
            </input>
  
            <jpath:if test="cancel">
              <input type="submit" name="cancel" value="Cancel"/>
            </jpath:if>
  
          </form>
        </s1>
      </body>
  
    </document>
  
  </xsp:page>
  
  
  
  1.1                  
cocoon-2.1/src/webapp/samples/flow/prefs/screens/registrationSuccessful.xsp
  
  Index: registrationSuccessful.xsp
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    Author: Ovidiu Predescu "[EMAIL PROTECTED]"
  
    Date: August 30, 2002
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    >
    
    <document>
      <header>
        <title>New User Registration</title>
      </header>
      <body>
        <s1 title="Registration successful!">
          <p>Congratulations <strong><jpath:value-of select="user/firstName"/> 
<jpath:value-of select="user/lastName"/></strong>! You've successfully registered as a 
new user.</p>
          <p>| <link href="../edit">Edit my preferences</link> | <link 
href="../logout">Logout</link> |</p>
        </s1>
      </body>
    </document>
  
  </xsp:page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/prefs/prefs.js
  
  Index: prefs.js
  ===================================================================
  /*
      prefs.js
  
      This file is the central controller piece in the preferences
      application. It receives the requests from the client browser (the
      View in the MVC pattern), and coordinates with the Model (written
      in Java, in the logic/ directory) to do the business logic.
  
      Author: Ovidiu Predescu <[EMAIL PROTECTED]>
      Date: August 30, 2002
  
   */
  
  // The global user registry, through which we add new users or access
  // existing ones.
  var userRegistry = 
Packages.org.apache.cocoon.samples.flow.prefs.UserRegistry.getUserRegistry();
  
  var user;
  
  // This top-level function is called from the sitemap to start the
  // process of registering a user.
  // 
  // This function takes care of all the steps required during the
  // registration of a new user. It is the controller is the MVC
  // pattern, an intermediary between the View, in our case the client's
  // browser, and the Model, in the case of this particular function the
  // code that maintains the registered users.
  //
  // The function collects the necessary information from the View, and
  // calls the Model to do the necessary work of checking whether the
  // user exists or not, and registering the new user.
  function registerUser()
  {
    var check = false;
    var errorMsg = null;
    
    var login = "";
    var password = "";
    var firstName = "";
    var lastName = "";
    var email = "";
  
    while (true) {
      // Present the user with addUser page. `check' indicates the XSP
      // template that it needs to check the registration parameters,
      // and print an indicator close to where the errors
      // are. `errorMsg' if not null is printed at the top of the page
      // as an error message.
      sendPageAndWait("userInfo",
                      { "check" : check, "errorMsg" : errorMsg,
                      "title": "New User Registration",
                      "button" : "Register",
                      "login" : login, "password" : password,
                      "firstName" : firstName, "lastName" : lastName,
                      "email" : email});
  
      check = false;
      errorMsg = null;
  
      login = cocoon.request.get("login");
      password = cocoon.request.get("password");
      firstName = cocoon.request.get("firstName");
      lastName = cocoon.request.get("lastName");
      email = cocoon.request.get("email");
  
      if (login == "" || password == ""
          || firstName == "" || lastName == ""
          || email == "") {
        check = true;
        errorMsg = "Please correct the marked errors before continuing";
        continue;
      }
  
      // Check for the existence of an already registered user with the
      // same login name. There is a possibility of a race condition
      // here, with another user registering with the same login id
      // between this check and the creation of a new user few lines
      // below. We ignore this problem in this example.
      var existingUser = userRegistry.isLoginNameTaken(login);
      if (!existingUser) {
        user = new Packages.org.apache.cocoon.samples.flow.prefs.User(login, password,
                                                                      firstName, 
lastName,
                                                                      email);
        userRegistry.addUser(user);
        break;
      } else {
        errorMsg = "Login name '" + login
          + "' is already in use, please choose another name";
      }
    }
  
    // The user has successfully registered, so we consider (s)he to be
    // already logged in. At this point we want to create a session, so
    // that all the JavaScript global variables are shared among
    // invocations of top-level functions. Up until this point, each
    // invocation had a separate global scope for the variables.
    cocoon.createSession();
  
    // Here we just send a response to the client browser and we don't
    // wait for any response. This is the last page generated by this
    // top-level function. In general is good to make sure a top-level
    // function, e.g. one that's invoked directly from the sitemap using
    // <map:call function="..."> sends a response page to the client at
    // all the exit points. Otherwise the user will get a blank page and
    // will be really confused.
    //
    // In the case of this particular function, this is the only exit
    // point.
    sendPage("registrationSuccessful", {"user" : user});
  }
  
  
  // This top-level function is used for user login.
  function login(errorMsg)
  {
    var login = "";
    var password = "";
  
    while (true) {
      sendPageAndWait("login",
                      {"errorMsg" : errorMsg, "login" : login, "password" : password});
  
      errorMsg = null;
    
      login = cocoon.request.getParameter("login");
      password = cocoon.request.getParameter("password");
  
      user = userRegistry.getUserWithLogin(login, password);
  
      if (user != undefined) {
        break;
      } else {
        errorMsg = "No such user or bad password";
      }
    }
  
    // The user has successfully signed in. At this point we want to
    // create a session, so that all the JavaScript global variables are
    // shared among invocations of top-level functions. Up until this
    // point, each invocation had a separate global scope for the
    // variables.
    cocoon.createSession();
  
    // We send to the user a welcome page which contains links back to
    // what (s)he can do. These links essentially point to other top
    // level functions in this script.
    sendPage("welcome", {"user" : user});
  }
  
  // This function is called to edit the preferences of an already
  // registered user. If this function was called without the user being
  // logged in first, the 'user' global variable is null. When this
  // happens the user is redirected to the login page first.
  function edit()
  {
    if (user == undefined)
      login("Please login before continuing");
  
    var login = user.login;
    var password = user.password;
    var firstName = user.firstName;
    var lastName = user.lastName;
    var email = user.email;
    var errorMsg = "";
    var check = false;
  
    while (true) {
      // Present the user with addUser page. `check' indicates the XSP
      // template that it needs to check the registration parameters,
      // and print an indicator close to where the errors
      // are. `errorMsg' if not null is printed at the top of the page
      // as an error message.
      sendPageAndWait("userInf",
                      { "check" : check, "errorMsg" : errorMsg,
                      "title": "Edit account",
                      "button" : "Change", "cancel" : true,
                      "login" : login, "password" : password,
                      "firstName" : firstName, "lastName" : lastName,
                      "email" : email});
  
      if (cocoon.request.get("cancel"))
        break;
  
      check = false;
      errorMsg = null;
  
      login = cocoon.request.get("login");
      password = cocoon.request.get("password");
      firstName = cocoon.request.get("firstName");
      lastName = cocoon.request.get("lastName");
      email = cocoon.request.get("email");
  
      if (login == "" || password == ""
          || firstName == "" || lastName == ""
          || email == "") {
        check = true;
        errorMsg = "Please correct the marked errors before continuing";
        continue;
      } else {
        // Save the changes the user made in the User object
        user.login = login;
        user.password = password;
        user.firstName = firstName;
        user.lastName = lastName;
        user.email = email;
        break;
      }
    }
  
    sendPage("welcome", {"user" : user});
  }
  
  function logout()
  {
    user = undefined;
    login("You're successfully logged out. Please log in to continue");
  }
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/prefs/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS $Id: sitemap.xmap,v 1.1 2003/03/25 15:11:28 stefano Exp $ -->
  
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0";>
  
    <map:components>
      <map:generators default="file"/>
      <map:transformers default="xslt"/>
      <map:readers default="resource"/>
      <map:serializers default="html"/>
      <map:matchers default="wildcard"/>
    </map:components>
  
    <!-- indicates what flowscript to attach to this sitemap -->
    <map:flow language="JavaScript">
      <map:script src="prefs.js"/>
    </map:flow>
  
    <map:pipelines>
    
      <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="kont/*">
          <map:call continuation="{1}"/>
        </map:match>
  
        <!--+
            | this call is transparently triggered by the flow engine if 
            | the requested continuation is invalid (either not available
            | or expired).
            +-->            
        <map:match pattern="invalidContinuation">
          <map:generate src="../invalidContinuation.xml"/>
          <map:transform 
src="context://samples/common/style/xsl/html/simple-page2html.xsl"/>
          <map:serialize/>
        </map:match>
  
        <!--+
            | unlike the calculator example, this flow has many different
            | entry points, each indicated by its own matcher
            +-->
        <map:match pattern="">
          <map:call function="login"/>
        </map:match>
        <map:match pattern="register">
          <map:call function="registerUser"/>
        </map:match>
        <map:match pattern="edit">
          <map:call function="edit"/>
        </map:match>
        <map:match pattern="logout">
          <map:call function="logout"/>
        </map:match>
  
        <!--+
            | produces the views called by the flowscript
            +-->      
        <map:match pattern="*">
          <map:generate type="server-pages" src="screens/{1}.xsp"/>
          <map:transform 
src="context://samples/common/style/xsl/html/simple-page2html.xsl"/>
          <map:serialize/>
        </map:match>
  
      </map:pipeline>
      
    </map:pipelines>
  
  </map:sitemap>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/test/sendpage.js
  
  Index: sendpage.js
  ===================================================================
  function showString(parameter)
  {
    print ("parameter = " + parameter);
    sendPageAndContinue("showString", { "parameter" : parameter, "replaceme" : 
"@REPLACEME@" });
  }
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/test/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:transformers default="xslt"/>
      <map:readers default="resource"/>
      <map:serializers default="html"/>
      <map:matchers default="wildcard"/>
    </map:components>
  
    <map:flow language="JavaScript">
      <map:script src="sendpage.js"/>
    </map:flow>
  
    <map:pipelines>
  
      <map:pipeline>
        <map:match pattern="kont/*">
          <map:call continuation="{1}"/>
        </map:match>
     
        <map:match pattern="invalidContinuation">
          <map:generate src="../invalidContinuation.xml"/>
          <map:transform 
src="context://samples/common/style/xsl/html/simple-page2html.xsl"/>
          <map:serialize/>
        </map:match>
        
        <map:match pattern="showString">
          <map:call function="showString">
            <map:parameter name="parameter" value="@PARAMETER@"/>
                </map:call>
        </map:match>
  
        <map:match pattern="*">
          <map:generate type="server-pages" src="screens/{1}.xsp"/>
          <map:transform 
src="context://samples/common/style/xsl/html/simple-page2html.xsl"/>
          <map:serialize/>
        </map:match>
        
      </map:pipeline>
  
    </map:pipelines>
  
  </map:sitemap>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/calc/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 = "getNumber" + name.toUpperCase();
    sendPageAndWait(uri, { "a" : a, "b" : b });
    return parseFloat(cocoon.request.getParameter(name));
  }
  
  function getOperator(a, b)
  {
    sendPageAndWait("getOperator", { "a" : a, "b" : b });
    return cocoon.request.getParameter("operator");
  }
  
  function sendResult(a, b, op, result)
  {
    sendPage("displayResult",
             { "a" : a, "b" : b, "operator" : op, "result" : result });
  }
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/calc/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:transformers default="xslt"/>
      <map:readers default="resource"/>
      <map:serializers default="html"/>
      <map:matchers default="wildcard"/>
    </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>
      
        <!--+
            | 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="kont/*">
          <map:call continuation="{1}"/>
        </map:match>
  
        <!--+
            | this call is transparently triggered by the flow engine if 
            | the requested continuation is invalid (either not available
            | or expired).
            +-->            
        <map:match pattern="invalidContinuation">
          <map:generate src="../invalidContinuation.xml"/>
          <map:transform 
src="context://samples/common/style/xsl/html/simple-page2html.xsl"/>
          <map:serialize/>
        </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>
  
        <!--+
            | produces the screens called by the flowscript
            +-->     
        <map:match pattern="*">
          <map:generate type="server-pages" src="screens/{1}.xsp"/>
          <map:transform 
src="context://samples/common/style/xsl/html/simple-page2html.xsl"/>
          <map:serialize/>
        </map:match>
        
      </map:pipeline>
  
    </map:pipelines>
  
  </map:sitemap>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/flow/test/screens/showString.xsp
  
  Index: showString.xsp
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    Author: Ovidiu Predescu "[EMAIL PROTECTED]"
  
    Date: October 1, 2002
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    >
    
    <document>
      <header>
        <title>Show String</title>
      </header>
      <body>
        <s1 title="String">
          <p><jpath:value-of select="replaceme"/></p>
          <p><jpath:value-of select="parameter"/></p>
        </s1>
      </body>
    </document>
  
  </xsp:page>
  
  
  

Reply via email to