cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From coli...@apache.org
Subject cvs commit: cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/xmlform EditAccountForm.xml
Date Sat, 22 Mar 2003 22:52:55 GMT
coliver     2003/03/22 14:52:55

  Modified:    src/scratchpad/webapp/samples/petstore sitemap.xmap
               src/scratchpad/webapp/samples/petstore/flow petstore.js
               src/scratchpad/webapp/samples/petstore/stylesheets
                        site2html.xsl
  Added:       src/scratchpad/webapp/samples/petstore/stylesheets
                        form2html.xsl
               src/scratchpad/webapp/samples/petstore/view/xmlform
                        EditAccountForm.xml
  Log:
  first attempt at including XMLForm in this sample
  
  Revision  Changes    Path
  1.8       +43 -2     cocoon-2.1/src/scratchpad/webapp/samples/petstore/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/sitemap.xmap,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- sitemap.xmap	20 Mar 2003 06:37:58 -0000	1.7
  +++ sitemap.xmap	22 Mar 2003 22:52:55 -0000	1.8
  @@ -3,6 +3,9 @@
   
     <!-- =========================== Components ================================ -->
     <map:components> 
  +    <map:transformers default="xslt">
  +      <map:transformer name="xmlform" src="org.apache.cocoon.transformation.XMLFormTransformer"
logger="xmlform.sitemap.transformer"/>
  +    </map:transformers>
       <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>
  @@ -46,18 +49,56 @@
   
       <map:pipeline>
         <map:match pattern="*.kont">
  -        <map:call continuation="{1}"/>
  +        <map:call continuation="{1}"/> <!-- 
  +               This handles sendPage*() continuations.
  +           -->
         </map:match>
         <map:match pattern="*.do">
           <map:call function="main">
             <map:parameter name="page" value="{1}"/>
           </map:call>
         </map:match>
  +      <map:match pattern="petstore"> 
  +        <map:call function="xmlForm"/> <!-- 
  +              Without parameters xmlForm() handles XMLForm continuations:
  +	      The pattern I'm matching here, "petstore", must match the value 
  +              of the "action" attribute in the view's <xf:submit> elements
  +           -->
  +      </map:match>
         <map:match pattern="">
           <map:call function="index"/>
         </map:match>
  -  </map:pipeline>
  +      <map:match pattern="editAccount.form">
  +        <map:call function="xmlForm">
  +          <map:parameter name="xmlform-function" value="editAccountForm"/>
  +	  <map:parameter name="xmlform-id" value="petstore-edit-account"/> <!--
  +                  The value I supply here, "petstore-edit-account", must match 
  +                  the "id" attribute of the view's <xf:form> element
  +             -->
  +          <map:parameter name="xmlform-validator-schema-ns"/> <!-- no validator
-->
  +          <map:parameter name="xmlform-validator-schema"/> <!-- no validator -->
  +          <map:parameter name="xmlform-scope" value="session"/>
  +        </map:call>
  +      </map:match>
   
  +      <map:match pattern="view/xmlform/*.xml">
  +	      <!-- original XMLForm document -->
  +	      <map:generate src="view/xmlform/{1}.xml"/>
  +	      
  +	      <!-- populating the document with model instance data -->
  +	      <map:transform type="xmlform"  label="xml"/>
  +	
  +
  +	      <map:transform type="xalan" src="stylesheets/form2html.xsl" />
  +
  +	      <!-- Transforming the XMLForm controls to HTML controls -->
  +	      <map:transform src="context://samples/stylesheets/xmlform/xmlform2html.xsl" />
  +
  +	      
  +	      <!-- sending the HTML back to the browser -->
  +	      <map:serialize type="html" label="debug"/>
  +	</map:match>	      
  +    </map:pipeline>
      <map:pipeline>
        <map:match pattern="view/*.xsp">
           <map:generate src="view/xsp/{1}.xsp" type="serverpages"/>
  
  
  
  1.8       +77 -13    cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/petstore.js
  
  Index: petstore.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/petstore.js,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- petstore.js	20 Mar 2003 06:37:58 -0000	1.7
  +++ petstore.js	22 Mar 2003 22:52:55 -0000	1.8
  @@ -46,6 +46,9 @@
   
   // Page Flow for PetStore Application
   
  +// load xml form support
  +cocoon.load("resource://org/apache/cocoon/components/flow/javascript/xmlForm.js");
  +
   var MAX_RESULTS = 5;
   
   var VIEW = "Velocity";
  @@ -96,9 +99,9 @@
       VIEW = cocoon.request.get("view");
       print("setView: VIEW="+VIEW);
       if (VIEW == "Velocity") {
  -	EXT = ".vm";
  +        EXT = ".vm";
       } else if (VIEW == "Xsp") {
  -	EXT = ".xsp";
  +        EXT = ".xsp";
       }
       print("EXT="+EXT);
   }
  @@ -194,7 +197,12 @@
       var category = getPetStore().getCategory(categoryId);
       var skipResults = 0;
       var maxResults = MAX_RESULTS;
  +    var foo = new Object();
  +    foo.skip = skipResults + 0;
       while (true) {
  +        print("foo before=" + foo.skip);
  +        print("skipResults = " + skipResults);
  +        foo.skip = skipResults + 0;
           var productList = 
               getPetStore().getProductListByCategory(categoryId,
                                                      skipResults, 
  @@ -333,18 +341,74 @@
       });
   }
   
  -function editAccountForm() {
  -    if (accountForm.signOn) {
  -        newAccountForm();
  -    } else {
  -        sendPageAndWait("/view/EditAccountForm" + EXT, {
  -                        accountForm: accountForm,
  -                        account: accountForm.account,
  -                        categoryList: categoryList
  -        });
  +//
  +// Edit Account page: example of using XMLForm in a flow script
  +//
  +
  +
  +function validateZIP(field) {
  +    var valid = "0123456789-";
  +    var hyphencount = 0;
  +    if (field.length!=5 && field.length!=10) {
  +        throw "Please enter your 5 digit or 5 digit+4 zip code.";
  +    }
  +    for (var i=0; i < field.length; i++) {
  +        temp = "" + field.substring(i, i+1);
  +        if (temp == "-") hyphencount++;
  +        if (valid.indexOf(temp) == "-1") {
  +            throw "Invalid characters in your zip code";
  +        }
  +    }
  +    if (hyphencount > 1 || (field.length==10 && ""+field.charAt(5)!="-")) {
  +        throw "The hyphen character should be used with a properly formatted 5 digit+four
zip code, like '12345-6789'";
       }
   }
   
  +function validateEmail(value) {
  +    var reg  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  +    return reg.test(value);
  +}
  +
  +function editAccountForm(form) {
  +    var model = {accountForm: accountForm,
  +                 account: accountForm.account,
  +                 categoryList: categoryList, 
  +                 username: accountForm.account.userid,
  +                 password: "",
  +                 password2: ""};
  +    form.setModel(model);
  +    form.sendView("editAccountForm", 
  +                  "view/xmlform/EditAccountForm.xml", 
  +                  function(form) {
  +        for (var i in model.account) {
  +            print(i+"="+model.account[i]);
  +        }
  +        if (model.userName == "") {
  +            form.addViolation("/userName", "User ID is required");
  +        } else {
  +            if (model.password != model.password2) {
  +                form.addViolation("/password2", "Passwords don't match");
  +            }
  +        }
  +        if (account.firstName == "") {
  +            form.addViolation("/account/firstName", "First name is required");
  +        }
  +        if (account.lastName == "") {
  +            form.addViolation("/account/lastName", "Last name is required");
  +        }
  +        if (!validateEmail(account.email)) {
  +            form.addViolation("/account/email", "Email address is invalid");
  +        }
  +        try {
  +            validateZIP(account.zip);
  +        } catch (e) {
  +            form.addViolation("/account/zip", e);
  +        }
  +
  +    });
  +    index();
  +}
  +
   // Search
   
   function searchProducts() {
  @@ -393,8 +457,8 @@
                       view: VIEW,
                       accountForm: accountForm,
                       cartForm: cartForm, 
  -		    yoshi: yoshi,
  -		    cartItems: cartItems
  +                    yoshi: yoshi,
  +                    cartItems: cartItems
       });
       if (accountForm.signOn) {
           signOn();
  
  
  
  1.5       +1 -1      cocoon-2.1/src/scratchpad/webapp/samples/petstore/stylesheets/site2html.xsl
  
  Index: site2html.xsl
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/stylesheets/site2html.xsl,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- site2html.xsl	20 Mar 2003 15:21:16 -0000	1.4
  +++ site2html.xsl	22 Mar 2003 22:52:55 -0000	1.5
  @@ -34,7 +34,7 @@
                                       </xsl:when>
                                       <xsl:otherwise>
                                           <a href="signonForm.do?signoff=true"><img
border="0" name="img_signout" src="images/sign-out.gif" /></a><img border="0"
src="images/separator.gif" hspace="4" />
  -                                        <a href="editAccountForm.do"><img border="0"
name="img_myaccount" src="images/my_account.gif" /></a>
  +                                        <a href="editAccount.form"><img border="0"
name="img_myaccount" src="images/my_account.gif" /></a>
                                       </xsl:otherwise>
                                   </xsl:choose>
                                   <img border="0" src="images/separator.gif" hspace="4"
/><a href="../help.html"><img border="0" name="img_help" src="images/help.gif"
/></a>
  
  
  
  1.1                  cocoon-2.1/src/scratchpad/webapp/samples/petstore/stylesheets/form2html.xsl
  
  Index: form2html.xsl
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
  	Cocoon Feedback Wizard XMLForm processing and displaying stylesheet.	
    
    This stylesheet merges an XMLForm document into 
    a final document. It includes other presentational
    parts of a page orthogonal to the xmlform.
  
    author: Ivelin Ivanov, ivelin@apache.org, May 2002
    author: Konstantin Piroumian <kpiroumian@protek.com>, September 2002
    author: Simon Price <price@bristol.ac.uk>, September 2002
  
  -->
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  	xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002"
  	exclude-result-prefixes="xalan" >
  	<xsl:template match="document">
  		<html>
  			<head>
  				<title>XMLForm - Cocoon Feedback Wizard</title>
  
  			</head>
  			<body>
  				<xsl:apply-templates />
  			</body>
  		</html>
  	</xsl:template>
  	<xsl:template match="xf:form">
  		<xf:form method="post">
  			<xsl:copy-of select="@*" />
  			<br/>
  			<br/>
  			<br/>
  			<br/>
  			<table align="center" border="0">
  				<tr>
  					<td align="center" colspan="3">
  						<h1>
  							<xsl:value-of select="xf:caption"/>
  							<hr/>
  						</h1>
  					</td>
  				</tr>
  				<xsl:if test="count(error/xf:violation) > 0">
  					<tr>
  						<td align="left" colspan="3"
  							class="{error/xf:violation[1]/@class}">
  							<p>* There are [<b><xsl:value-of
  								select="count(error/xf:violation)"/></b>] 
  								errors. Please fix these errors and submit the
  								form again.</p>
  							<p>
  								<xsl:variable name="localViolations"
  									select=".//xf:*[ child::xf:violation ]"/>
  								<xsl:for-each select="error/xf:violation">
  									<xsl:variable name="eref" select="./@ref"/>
  									<xsl:if
  										test="count ($localViolations[ @ref=$eref ]) = 0"
  										>* <xsl:value-of select="." /> <br/> </xsl:if>
  								</xsl:for-each>
  							</p>
  							<p/>
  						</td>
  					</tr>
  				</xsl:if>
  				<xsl:for-each select="*[name() != 'xf:submit']">
  					<xsl:choose>
  						<xsl:when test="name() = 'error'"/>
  						<xsl:when test="name() = 'xf:caption'"/>
  						<xsl:when test="xf:*">
  							<xsl:apply-templates select="."/>
  						</xsl:when>
  						<xsl:otherwise>
  							<xsl:copy-of select="."/>
  						</xsl:otherwise>
  					</xsl:choose>
  				</xsl:for-each>
  				<tr>
  					<td align="center" colspan="3">
  						<xsl:for-each select="*[name() = 'xf:submit']">
  							<xsl:copy-of select="." />
  							<xsl:text>
  							</xsl:text>
  						</xsl:for-each>
  					</td>
  				</tr>
  			</table>
  		</xf:form>
  	</xsl:template>
  	<xsl:template match="xf:repeat">
  		<tr width="100%">
  			<td colspan="3" width="100%">
  				<table class="repeat">
  					<xsl:apply-templates select="*"/>
  				</table>
  			</td>
  		</tr>
  	</xsl:template>
  	<xsl:template match="xf:group">
  		<tr width="100%">
  			<td width="100%" colspan="2">
  				<table class="group" border="0">
  					<tr>
  						<td align="left">
  							<xsl:value-of select="xf:caption" />
  						</td>
  					</tr>
  					<xsl:apply-templates select="*"/>
  				</table>
  			</td>
  		</tr>
  	</xsl:template>
  	<xsl:template match="xf:output[@form]">
  		<div align="center">
  			<hr width="30%"/>
  			<br/>
  			<font size="-1">
  				<code> <xsl:value-of select="xf:caption" /> : <xsl:copy-of
  					select="." /> </code>
  			</font>
  			<br/>
  		</div>
  	</xsl:template>
  	<xsl:template match="xf:caption"/>
  	<xsl:template match="xf:*">
  		<tr>
  			<td align="left" valign="top">
  				<p class="caption">
  					<xsl:value-of select="xf:caption" />
  				</p>
  			</td>
  			<td align="left">
  				<table class="plaintable">
  					<tr>
  						<td align="left">
  							<xsl:copy-of select="." />
  						</td>
  						<xsl:if test="xf:violation">
  							<td align="left" class="{xf:violation[1]/@class}"
  								width="100%">
  								<xsl:for-each select="xf:violation">* 
  									<xsl:value-of select="." /> <br/> </xsl:for-each>
  							</td>
  						</xsl:if>
  					</tr>
  				</table>
  				<xsl:if test="xf:help">
  					<div class="help">
  						<xsl:value-of select="xf:help" />
  					</div>
  					<br />
  				</xsl:if>
  			</td>
  		</tr>
  	</xsl:template>
  	<xsl:template match="*">
  		<xsl:copy-of select="." />
  	</xsl:template>
  </xsl:stylesheet>
  
  
  
  1.1                  cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/xmlform/EditAccountForm.xml
  
  Index: EditAccountForm.xml
  ===================================================================
  <?xml version="1.0"?>
  <document xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002">
  	<xf:form id="petstore-edit-account" view="edit-account" action="petstore" method="GET">
  		<xf:caption>User Information</xf:caption>
  		<error>
  			<xf:violations class="error"/>
  		</error>
  		<xf:textbox ref="/username">
  			<xf:caption>User ID:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:password ref="/password">
  			<xf:caption>Password:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:password>
  		<xf:password ref="/password2">
  			<xf:caption>Repeat Password:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:password>
  		<xf:textbox ref="/account/firstName">
  			<xf:caption>First Name:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/account/lastName">
  			<xf:caption>Last Name:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/account/email">
  			<xf:caption>Email:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/account/phone">
  			<xf:caption>Phone:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/account/address1">
  			<xf:caption>Address 1:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/account/address2">
  			<xf:caption>Address 2:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/account/city">
  			<xf:caption>City:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/account/state">
  			<xf:caption>State:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/account/zip">
  			<xf:caption>Zip:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/account/country">
  			<xf:caption>Country:</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:selectOne ref="/account/favCategory">
  		   <xf:caption>Favorite Category:</xf:caption>
  		   <xf:itemset nodeset="/categoryList">
  			<xf:caption><xf:output ref="name"/></xf:caption>
  			<xf:value><xf:output ref="name"/></xf:value>
  		   </xf:itemset>
  		</xf:selectOne>
  		<xf:selectBoolean ref="/account/listOption">
  			<xf:caption>Enable MyList</xf:caption>
  		</xf:selectBoolean>
  		<xf:selectBoolean ref="/account/bannerOption">
  			<xf:caption>Enable MyBanner</xf:caption>
  		</xf:selectBoolean>
  		<xf:submit id="next" continuation="forward" class="button">
  			<xf:caption>Submit</xf:caption>
  			<xf:hint>Submit Account Information</xf:hint>
  		</xf:submit>
  	</xf:form>
  </document>
  
  
  

Mime
View raw message