You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ug...@apache.org on 2005/05/17 16:00:03 UTC

svn commit: r170598 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples: ./ captcha/ captcha/flow/ captcha/forms/ messages/ resources/

Author: ugo
Date: Tue May 17 07:00:02 2005
New Revision: 170598

URL: http://svn.apache.org/viewcvs?rev=170598&view=rev
Log:
CAPTCHA validation sample

Added:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml   (with props)
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/flow/
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/flow/captcha.js   (with props)
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml   (with props)
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.tpl.xml   (with props)
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/sitemap.xmap   (with props)
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/success.xml   (with props)
Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages.xml
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages_it_IT.xml
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/welcome.xml

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml?rev=170598&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml Tue May 17 07:00:02 2005
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<svg width="200" height="75">
+    <defs>
+        <filter id="blur2">
+            <feGaussianBlur stdDeviation="2"/>
+        </filter>
+    </defs>
+     <g id="imagegroup">
+        <text style="fill:#0086B3;font-size:42;font-family:Courier;filter:url(#blur2);" x="0" y="48">#{$cocoon/parameters/value}</text>
+     </g>
+</svg>

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml
------------------------------------------------------------------------------
    svn:eol = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/flow/captcha.js
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/flow/captcha.js?rev=170598&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/flow/captcha.js (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/flow/captcha.js Tue May 17 07:00:02 2005
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
+
+function captcha() {
+    var form = new Form("forms/captcha.def.xml");
+    form.showForm("captcha-display-pipeline");
+    cocoon.sendPage("success", {
+        value: form.lookupWidget("/f1").value,
+    });
+}

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/flow/captcha.js
------------------------------------------------------------------------------
    svn:eol = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/flow/captcha.js
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml?rev=170598&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml Tue May 17 07:00:02 2005
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<!--
+  @version $Id$
+-->
+
+<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
+         xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
+
+  <fd:widgets>
+  
+    <fd:captcha id="f1" required="true">
+      <fd:label>Copy the string shown on the right into the input field</fd:label>
+      <fd:datatype base="string"/>
+      <fd:validation>
+        <fd:captcha/>
+      </fd:validation>
+    </fd:captcha>
+
+  </fd:widgets>
+    
+</fd:form>

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml
------------------------------------------------------------------------------
    svn:eol = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.tpl.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.tpl.xml?rev=170598&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.tpl.xml (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.tpl.xml Tue May 17 07:00:02 2005
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+<page xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
+      xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
+      xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
+
+  <title>CAPTCHA validation sample form</title>
+  <content>
+    <p>This is a demonstration of <a href="http://www.captcha.net/">CAPTCHA</a>
+    validation.</p>
+    <ft:form-template action="#{$cocoon/continuation/id}.cont" method="POST">
+      <fi:group>
+        <fi:styling layout="columns"/>
+        <fi:items>
+          <ft:widget id="f1"/>
+        </fi:items>
+      </fi:group>
+    </ft:form-template>
+  </content>
+</page>
+

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.tpl.xml
------------------------------------------------------------------------------
    svn:eol = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.tpl.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/sitemap.xmap?rev=170598&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/sitemap.xmap (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/sitemap.xmap Tue May 17 07:00:02 2005
@@ -0,0 +1,115 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+ 
+ <map:views>
+  <map:view name="content" from-label="content">
+   <map:serialize type="xml"/>
+  </map:view>
+  
+  <map:view name="content1" from-label="content1">
+   <map:serialize type="xml"/>
+  </map:view>  
+
+  <map:view from-label="content" name="pretty-content">
+   <map:transform src="context://stylesheets/system/xml2html.xslt"/>
+   <map:serialize type="html"/>
+  </map:view>
+
+  <map:view name="links" from-position="last">
+   <map:serialize type="links"/>
+  </map:view>
+ </map:views>
+ 
+ <map:resources>
+   <!-- this will later become a virtual transformer -->
+   <map:resource name="simple-page2html">
+     <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
+       <map:parameter name="contextPath" value="{request:contextPath}"/>
+       <map:parameter name="servletPath" value="{request:servletPath}"/>
+       <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
+       <map:parameter name="file" value="{file}"/>
+       <map:parameter name="remove" value="{../0}"/>
+     </map:transform> 
+   </map:resource>
+ </map:resources>
+
+  <!-- indicates what flowscript to attach to this sitemap -->
+  <map:flow language="javascript">
+    <map:script src="flow/captcha.js"/>
+  </map:flow>
+
+ <map:pipelines>
+   <map:pipeline>
+
+     <map:match pattern="">
+       <map:call function="captcha"/>
+     </map:match>
+
+     <map:match pattern="*.cont">
+       <map:call continuation="{1}"/>
+     </map:match>
+
+     <map:match pattern="success">
+       <map:generate type="jx" src="success.xml"/>
+       <map:call resource="simple-page2html">
+         <map:parameter name="file" value="success.xml"/>
+       </map:call>
+       <map:serialize/>
+     </map:match>
+
+     <!--
+        | Show a form, using the forms transformer
+        -->
+     <map:match pattern="*-display-pipeline">
+       <map:generate type="file" src="forms/{1}.tpl.xml"/>
+       <map:transform type="forms" label="content1"/>
+       <map:transform type="i18n">
+         <!--map:parameter name="locale" value="en-US"/-->
+       </map:transform>
+       <map:call resource="simple-page2html">
+         <map:parameter name="file" value="forms/{1}.tpl.xml"/>
+       </map:call>
+       <map:transform src="../resources/forms-samples-styling.xsl">
+         <map:parameter name="resources-uri" value="../resources"/>
+       </map:transform>
+       <map:serialize/>
+     </map:match>
+
+    <!--
+       | Generate the CAPTCHA image. Any type of generator can be used here,
+       | as long as it reads the string to display from the session
+       | attribute named "captcha-{1}".
+       | Using an SVG file as input requires that the Batik block be
+       | included in the build.
+       -->
+    <map:match pattern="captcha-*.jpg">
+      <map:generate type="jx" src="captcha-image.xml">
+        <map:parameter name="value" value="{session-attr:captcha-{1}}"/>
+      </map:generate>
+      <map:serialize type="svg2jpeg"/>
+    </map:match>
+    
+    <map:match pattern="*">
+      <map:redirect-to uri="{1}/"/>
+    </map:match>
+
+   </map:pipeline>
+ </map:pipelines>
+
+</map:sitemap>

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/sitemap.xmap
------------------------------------------------------------------------------
    svn:eol = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/sitemap.xmap
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/success.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/success.xml?rev=170598&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/success.xml (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/success.xml Tue May 17 07:00:02 2005
@@ -0,0 +1,24 @@
+<!--
+  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.
+-->
+<page xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
+      xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
+      xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
+
+  <title>CAPTCHA validation succeeded</title>
+  <content>
+    <p>You guessed ${value}. Correct!</p>
+  </content>
+</page>

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/success.xml
------------------------------------------------------------------------------
    svn:eol = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/success.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages.xml?rev=170598&r1=170597&r2=170598&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages.xml Tue May 17 07:00:02 2005
@@ -48,6 +48,8 @@
 
   <message key="validation.mod10">Mod 10 check failed.</message>
 
+  <message key="validation.captcha.mismatch">CAPTCHA check failed.</message>
+
   <message key="aggregatedfield.split-failed">Content of this field does not match the following regular expression: {0}</message>
   <message key="upload.invalid-type">Invalid content type.</message>
 </catalogue>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages_it_IT.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages_it_IT.xml?rev=170598&r1=170597&r2=170598&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages_it_IT.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/messages/FormsMessages_it_IT.xml Tue May 17 07:00:02 2005
@@ -49,6 +49,7 @@
 
   <message key="validation.mod10">Verifica Mod 10 fallita.</message>
 
+  <message key="validation.captcha.mismatch">Verifica CAPTCHA fallita.</message>
 
   <message key="aggregatedfield.split-failed">Il valore non corrisponde alla seguente espressione regolare: {0}</message>
   <message key="upload.invalid-type">Tipo del contenuto non valido.</message>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl?rev=170598&r1=170597&r2=170598&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl Tue May 17 07:00:02 2005
@@ -48,6 +48,10 @@
       | Generic fi:field : produce an <input>
       +-->
   <xsl:template match="fi:field">
+    <xsl:if test="fi:captcha-image">
+      <img src="captcha-{@id}.jpg" style="vertical-align:middle"/>
+      <xsl:text> </xsl:text>
+    </xsl:if>
     <input name="{@id}" id="{@id}" value="{fi:value}" title="{fi:hint}" type="text">
       <xsl:apply-templates select="." mode="styling"/>
     </input>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/welcome.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/welcome.xml?rev=170598&r1=170597&r2=170598&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/welcome.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/welcome.xml Tue May 17 07:00:02 2005
@@ -44,6 +44,7 @@
   <sample name="HTMLArea" href="htmlarea">A simple form using the HTML editor widget.</sample>
   <sample name="Aggregate" href="aggregate/example">Aggregate field examples</sample>
   <sample name="Multipage wizard" href="do-multipage.flow">A multipage wizard, using widget states and actions to move between pages.</sample>
+  <sample name="CAPTCHA validation" href="captcha/">CAPTCHA validation (requires <a href="/samples/blocks/batik/">Batik block</a>)</sample>
  </group>
 
  <group name="Binding Samples">