diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/build.properties.jboss b/genapp/src/plugin-resources/struts-validation/template-resources/build.properties.jboss new file mode 100644 index 00000000..936f4802 Binary files /dev/null and b/genapp/src/plugin-resources/struts-validation/template-resources/build.properties.jboss differ diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/maven.xml b/genapp/src/plugin-resources/struts-validation/template-resources/maven.xml new file mode 100644 index 00000000..73bbfb59 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/maven.xml @@ -0,0 +1,26 @@ + + + + + + + + + + diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/project.properties b/genapp/src/plugin-resources/struts-validation/template-resources/project.properties new file mode 100644 index 00000000..e086a626 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/project.properties @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------- +# Copyright 2001-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. +# ------------------------------------------------------------------- + +maven.xdoc.date=left +maven.eclipse.classpath.include=src/test-cactus,src/conf +maven.war.webapp.dir=${maven.build.dir}/xdoclet/webdoclet +maven.xdoclet.webdoclet.0=true +maven.xdoclet.webdoclet.0.destDir=${maven.build.dir}/xdoclet/webdoclet/WEB-INF +maven.xdoclet.webdoclet.0.mergeDir=src/merge +maven.xdoclet.webdoclet.strutsconfigxml.0=true +maven.xdoclet.webdoclet.strutsconfigxml.0.validateXML=true +maven.xdoclet.webdoclet.strutsconfigxml.0.Version=1.1 +maven.xdoclet.webdoclet.strutsconfigxml.0.destDir=${maven.build.dir}/xdoclet/webdoclet/WEB-INF +maven.xdoclet.webdoclet.strutsconfigxml.0.mergeDir=src/merge +maven.xdoclet.webdoclet.strutsvalidationxml.0=true +maven.xdoclet.webdoclet.strutsvalidationxml.0.destDir=${maven.build.dir}/xdoclet/webdoclet/WEB-INF +maven.xdoclet.webdoclet.strutsvalidationxml.0.mergeDir=src/merge +maven.xdoclet.webdoclet.jbosswebxml.0=true +maven.xdoclet.webdoclet.jbosswebxml.0.destDir=${maven.build.dir}/xdoclet/webdoclet/WEB-INF +maven.xdoclet.webdoclet.deploymentdescriptor.0.destDir=${maven.build.dir}/xdoclet/webdoclet/WEB-INF +maven.xdoclet.webdoclet.deploymentdescriptor.0.mergeDir=src/merge +maven.xdoclet.webdoclet.fileset.0.include=**/*.java +maven.xdoclet.webdoclet.jsptaglib.0.destDir=${maven.build.dir}/xdoclet/webdoclet/WEB-INF/tld +cactus.src.mergewebxml = src/conf/cactus-web.xml diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/project.xml b/genapp/src/plugin-resources/struts-validation/template-resources/project.xml new file mode 100644 index 00000000..e065be3e --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/project.xml @@ -0,0 +1,288 @@ + + + + + + + + 3 + + + @ID@ + @ID@ + + + @NAME@ + + + 1.0 + + + + Apache Software Foundation + http://www.apache.org/ + http://maven.apache.org/images/jakarta-logo-blue.gif + + + + 2004 + @PACKAGE@ + http://maven.apache.org/images/maven.jpg + A collection of example projects showing how to use maven in different situations + + + How to use maven in different situations + + + http://maven.apache.org/reference/plugins/examples/ + http://nagoya.apache.org/scarab/servlet/scarab/ + jakarta.apache.org + /www/maven.apache.org/reference/plugins/examples/ + /www/maven.apache.org/builds/ + + + + scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven-plugins/examples + http://cvs.apache.org/viewcvs/maven-plugins/examples/ + + + + + + + + + + + + + junit + 3.8.1 + + + + servletapi + 2.3 + + + + jstl + 1.0.2 + + true + + + + + taglibs + standard + 1.0.4 + + true + + + + + cactus + cactus + 13-1.6dev-20040115 + + + + commons-logging + commons-logging + 1.0.3 + + true + + + + + + struts + struts + 1.1 + + true + + + + + struts + struts-bean + 1.1 + tld + + true + + + + + struts + struts-html + 1.1 + tld + + true + + + + + struts + struts-logic + 1.1 + tld + + true + + + + + strutstestcase + strutstestcase + 2.1-1.1-2.3 + + true + + + + + commons-beanutils + commons-beanutils + 1.6 + + true + + + + + commons-digester + commons-digester + 1.5 + + true + + + + + commons-collections + commons-collections + 3.0 + + true + + + + + commons-validator + commons-validator + 1.1.1 + + true + + + + + + xdoclet + 1.2 + + + + xdoclet + xdoclet-web-module + 1.2 + http://xdoclet.sf.net/ + + + + xdoclet + xdoclet-ejb-module + 1.2 + http://xdoclet.sf.net/ + + + + xdoclet + xdoclet-apache-module + 1.2 + http://xdoclet.sf.net/ + + + + xdoclet + xjavadoc + 1.0.2 + http://xdoclet.sf.net/ + + + + xdoclet + maven-xdoclet-plugin + 1.2 + plugin + http://xdoclet.sf.net/ + + + + + httpunit + httpunit + 1.5.4 + + true + + + + + jtidy + jtidy + 4aug2000r7-dev + + true + + + + + + + turbine-maven-dev@jakarta.apache.org + src/java + src/test + + + **/*Test.java + + + **/NaughtyTest.java + + + + + src/conf + + *.properties + + + + + diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/conf/ApplicationResources.properties b/genapp/src/plugin-resources/struts-validation/template-resources/src/conf/ApplicationResources.properties new file mode 100644 index 00000000..f3d7bb94 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/conf/ApplicationResources.properties @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------- +# Copyright 2001-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. +# ------------------------------------------------------------------- + +title.page=The title @NAME@ +error.givenname=Given name must be provided + +errors.required={0} is required. +errors.minlength={0} can not be less than {1} characters. +errors.maxlength={0} can not be greater than {1} characters. +errors.invalid={0} is invalid. + +errors.byte={0} must be a byte. +errors.short={0} must be a short. +errors.integer={0} must be an integer. +errors.long={0} must be a long. +errors.float={0} must be a float. +errors.double={0} must be a double. + +errors.date={0} is not a date. +errors.range={0} is not in the range {1} through {2}. +errors.creditcard={0} is an invalid credit card number. +errors.email={0} is an invalid e-mail address. diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/conf/cactus-web.xml b/genapp/src/plugin-resources/struts-validation/template-resources/src/conf/cactus-web.xml new file mode 100644 index 00000000..0e955f23 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/conf/cactus-web.xml @@ -0,0 +1,23 @@ + + + + + + + diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/java/InputAction.java b/genapp/src/plugin-resources/struts-validation/template-resources/src/java/InputAction.java new file mode 100644 index 00000000..63a0da21 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/java/InputAction.java @@ -0,0 +1,64 @@ +package @PACKAGE@; + +import java.io.IOException; +import java.util.Date; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.DynaActionForm; +import org.apache.struts.validator.DynaValidatorActionForm; +import org.apache.struts.validator.DynaValidatorForm; + +/** + * This is a simple struts action that simply redirects the input back to itself. It + * also sets a bean value to the current date. + * + * @struts.action + * name="TestForm" + * path="/TestInput" + * input="/WEB-INF/jsp/input.jsp" + * validate="true" + * @struts.action + * name="TestForm" + * path="/TestInputStart" + * validate="false" + * @struts.action-forward + * name="success" + * path="/WEB-INF/jsp/input.jsp" + * + * @author Archimedes Trajano + * @version $Id$ + */ +public class InputAction extends Action { + + /** + * Performs the simple action + * + * @param mapping + * the action mappings where you find the return value of the + * forward + * @param actionForm + * the action form used, in this example it will be an instance + * of the DynaActionForm class + * @param request + * the HTTP servlet request + * @param response + * the HTTP servlet response + */ + public ActionForward execute(ActionMapping mapping, ActionForm actionForm, + HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + if (actionForm != null) { + System.out.println(actionForm.getClass()); + DynaActionForm form = (DynaActionForm) actionForm; + form.set("theDate", new Date()); + } + return (mapping.findForward("success")); + } +} \ No newline at end of file diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/servlet-mappings.xml b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/servlet-mappings.xml new file mode 100644 index 00000000..12c94e4b --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/servlet-mappings.xml @@ -0,0 +1,21 @@ + + + action + *.do + diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/servlets.xml b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/servlets.xml new file mode 100644 index 00000000..a1af8769 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/servlets.xml @@ -0,0 +1,26 @@ + + + action + org.apache.struts.action.ActionServlet + + config + /WEB-INF/struts-config.xml + + 1 + diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/struts-forms.xml b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/struts-forms.xml new file mode 100644 index 00000000..02809bfc --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/struts-forms.xml @@ -0,0 +1,30 @@ + + + + + + diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/struts-message-resources.xml b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/struts-message-resources.xml new file mode 100644 index 00000000..a0ceabbe --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/struts-message-resources.xml @@ -0,0 +1,18 @@ + + diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/struts-plugins.xml b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/struts-plugins.xml new file mode 100644 index 00000000..38224dbf --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/struts-plugins.xml @@ -0,0 +1,3 @@ + + + diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/validation-global.xml b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/validation-global.xml new file mode 100644 index 00000000..00cd1633 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/merge/validation-global.xml @@ -0,0 +1,12 @@ + +
+ + + +
+
+ + + +
+
diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/test-cactus/HttpUnitTest.java b/genapp/src/plugin-resources/struts-validation/template-resources/src/test-cactus/HttpUnitTest.java new file mode 100644 index 00000000..2ae545dc --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/test-cactus/HttpUnitTest.java @@ -0,0 +1,51 @@ +package @PACKAGE@; + +import org.apache.cactus.ServletTestCase; + +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebForm; + +/** + * This tests the site using HttpUnit + * + * @author Archimedes Trajano + * @version $Id$ + */ +public class HttpUnitTest extends ServletTestCase { + /** + * This is a helper method to create the URL string for the initial web + * conversation request + * + * @param relativeUrl + * the relative URL including the leading"/" + * @return the context url with the relative URL appended to it + */ + private String requestUrl(String relativeUrl) { + StringBuffer url = request.getRequestURL(); + url.delete(url.lastIndexOf("/"), url.length()); + url.append(relativeUrl); + return url.toString(); + } + + /** + * This tests if the sample struts form works properly + * + * @throws Exception + * thrown when there is a problem with the test + */ + public void testStrutsPages() throws Exception { + WebConversation wc = new WebConversation(); + wc.getResponse(requestUrl("/TestInput.do")); + { + WebForm form = wc.getCurrentPage().getForms()[0]; + form.setParameter("givenName", "Archie"); + form.setParameter("familyName", "Trajano"); + form.submit(); + } + { + WebForm form = wc.getCurrentPage().getForms()[0]; + assertEquals("Archie", form.getParameterValue("givenName")); + assertEquals("Trajano", form.getParameterValue("familyName")); + } + } +}; \ No newline at end of file diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/test-cactus/StrutsTest.java b/genapp/src/plugin-resources/struts-validation/template-resources/src/test-cactus/StrutsTest.java new file mode 100644 index 00000000..63ff0a99 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/test-cactus/StrutsTest.java @@ -0,0 +1,31 @@ +package @PACKAGE@; + +import servletunit.struts.CactusStrutsTestCase; + +/** + * This tests the functionality of the StrutsTestCase + * + * @author Archimedes Trajano + * @version $Id$ + */ +public class StrutsTest extends CactusStrutsTestCase { + + /** + * Required constructor for CactusStrutsTestCase + * + * @param name + * name of the test + */ + public StrutsTest(String name) { + super(name); + } + + public void testInputForm() throws Exception { + setRequestPathInfo("/TestInput.do"); + addRequestParameter("givenName", "Archie"); + addRequestParameter("familyName", "Trajano"); + actionPerform(); + verifyForward("success"); + verifyNoActionErrors(); + } +} diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/test/SanityTest.java b/genapp/src/plugin-resources/struts-validation/template-resources/src/test/SanityTest.java new file mode 100644 index 00000000..7e2a2195 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/test/SanityTest.java @@ -0,0 +1,15 @@ +package @PACKAGE@; + +import junit.framework.TestCase; + +/** + * This is a simple JUnit test case to ensure that the environment is okay. + * + * @author Archimedes Trajano + * @version $Id$ + */ +public class SanityTest extends TestCase { + public void testSanity() { + assertEquals( "test", "test" ); + } +} diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/webapp/WEB-INF/jsp/input.jsp b/genapp/src/plugin-resources/struts-validation/template-resources/src/webapp/WEB-INF/jsp/input.jsp new file mode 100644 index 00000000..fa95dc85 --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/webapp/WEB-INF/jsp/input.jsp @@ -0,0 +1,30 @@ +<%@ page contentType="text/html; charset=utf-8" %> + +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> +<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %> +<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %> + +<%@ taglib uri="/WEB-INF/tld/struts-bean-1.1.tld" prefix="bean" %> +<%@ taglib uri="/WEB-INF/tld/struts-html-1.1.tld" prefix="html" %> +<%@ taglib uri="/WEB-INF/tld/struts-logic-1.1.tld" prefix="logic" %> + + + + + <bean:message key="title.page"/> + + + + +

The name is , on

+ + + + + + + +
diff --git a/genapp/src/plugin-resources/struts-validation/template-resources/src/webapp/WEB-INF/validator-rules.xml b/genapp/src/plugin-resources/struts-validation/template-resources/src/webapp/WEB-INF/validator-rules.xml new file mode 100644 index 00000000..de8e3faf --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template-resources/src/webapp/WEB-INF/validator-rules.xml @@ -0,0 +1,1044 @@ + + + + + + + + + + = 0) { + value = field.options[si].value; + } + } else { + value = field.value; + } + + if (trim(value).length == 0) { + + if (i == 0) { + focusField = field; + } + fields[i++] = oRequired[x][1]; + isValid = false; + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return isValid; + } + + // Trim whitespace from left and right sides of s. + function trim(s) { + return s.replace( /^\s*/, "" ).replace( /\s*$/, "" ); + } + + ]]> + + + + + + + + + + 0) && (field.value.length < iMin)) { + if (i == 0) { + focusField = field; + } + fields[i++] = oMinLength[x][1]; + isValid = false; + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return isValid; + }]]> + + + + + + + + iMax) { + if (i == 0) { + focusField = field; + } + fields[i++] = oMaxLength[x][1]; + isValid = false; + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return isValid; + }]]> + + + + + + + + 0)) { + + if (!matchPattern(field.value, oMasked[x][2]("mask"))) { + if (i == 0) { + focusField = field; + } + fields[i++] = oMasked[x][1]; + isValid = false; + } + } + } + + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return isValid; + } + + function matchPattern(value, mask) { + return mask.exec(value); + }]]> + + + + + + + + = 0) { + value = field.options[si].value; + } + } else { + value = field.value; + } + + if (value.length > 0) { + if (!isAllDigits(value)) { + bValid = false; + if (i == 0) { + focusField = field; + } + fields[i++] = oByte[x][1]; + + } else { + + var iValue = parseInt(value); + if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) { + if (i == 0) { + focusField = field; + } + fields[i++] = oByte[x][1]; + bValid = false; + } + } + } + + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return bValid; + }]]> + + + + + + + + = 0) { + value = field.options[si].value; + } + } else { + value = field.value; + } + + if (value.length > 0) { + if (!isAllDigits(value)) { + bValid = false; + if (i == 0) { + focusField = field; + } + fields[i++] = oShort[x][1]; + + } else { + + var iValue = parseInt(value); + if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) { + if (i == 0) { + focusField = field; + } + fields[i++] = oShort[x][1]; + bValid = false; + } + } + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return bValid; + }]]> + + + + + + + + = 0) { + value = field.options[si].value; + } + } else { + value = field.value; + } + + if (value.length > 0) { + + if (!isAllDigits(value)) { + bValid = false; + if (i == 0) { + focusField = field; + } + fields[i++] = oInteger[x][1]; + + } else { + var iValue = parseInt(value); + if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) { + if (i == 0) { + focusField = field; + } + fields[i++] = oInteger[x][1]; + bValid = false; + } + } + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return bValid; + } + + function isAllDigits(argvalue) { + argvalue = argvalue.toString(); + var validChars = "0123456789"; + var startFrom = 0; + if (argvalue.substring(0, 2) == "0x") { + validChars = "0123456789abcdefABCDEF"; + startFrom = 2; + } else if (argvalue.charAt(0) == "0") { + validChars = "01234567"; + startFrom = 1; + } else if (argvalue.charAt(0) == "-") { + startFrom = 1; + } + + for (var n = startFrom; n < argvalue.length; n++) { + if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false; + } + return true; + }]]> + + + + + + + + + + + = 0) { + value = field.options[si].value; + } + } else { + value = field.value; + } + + if (value.length > 0) { + // remove '.' before checking digits + var tempArray = value.split('.'); + var joinedString= tempArray.join(''); + + if (!isAllDigits(joinedString)) { + bValid = false; + if (i == 0) { + focusField = field; + } + fields[i++] = oFloat[x][1]; + + } else { + var iValue = parseFloat(value); + if (isNaN(iValue)) { + if (i == 0) { + focusField = field; + } + fields[i++] = oFloat[x][1]; + bValid = false; + } + } + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return bValid; + }]]> + + + + + + + + + + + 0) && + (datePattern.length > 0)) { + var MONTH = "MM"; + var DAY = "dd"; + var YEAR = "yyyy"; + var orderMonth = datePattern.indexOf(MONTH); + var orderDay = datePattern.indexOf(DAY); + var orderYear = datePattern.indexOf(YEAR); + if ((orderDay < orderYear && orderDay > orderMonth)) { + var iDelim1 = orderMonth + MONTH.length; + var iDelim2 = orderDay + DAY.length; + var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); + var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); + if (iDelim1 == orderDay && iDelim2 == orderYear) { + dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); + } else if (iDelim1 == orderDay) { + dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$"); + } else if (iDelim2 == orderYear) { + dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$"); + } else { + dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$"); + } + var matched = dateRegexp.exec(value); + if(matched != null) { + if (!isValidDate(matched[2], matched[1], matched[3])) { + if (i == 0) { + focusField = form[oDate[x][0]]; + } + fields[i++] = oDate[x][1]; + bValid = false; + } + } else { + if (i == 0) { + focusField = form[oDate[x][0]]; + } + fields[i++] = oDate[x][1]; + bValid = false; + } + } else if ((orderMonth < orderYear && orderMonth > orderDay)) { + var iDelim1 = orderDay + DAY.length; + var iDelim2 = orderMonth + MONTH.length; + var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); + var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); + if (iDelim1 == orderMonth && iDelim2 == orderYear) { + dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); + } else if (iDelim1 == orderMonth) { + dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$"); + } else if (iDelim2 == orderYear) { + dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$"); + } else { + dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$"); + } + var matched = dateRegexp.exec(value); + if(matched != null) { + if (!isValidDate(matched[1], matched[2], matched[3])) { + if (i == 0) { + focusField = form[oDate[x][0]]; + } + fields[i++] = oDate[x][1]; + bValid = false; + } + } else { + if (i == 0) { + focusField = form[oDate[x][0]]; + } + fields[i++] = oDate[x][1]; + bValid = false; + } + } else if ((orderMonth > orderYear && orderMonth < orderDay)) { + var iDelim1 = orderYear + YEAR.length; + var iDelim2 = orderMonth + MONTH.length; + var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); + var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); + if (iDelim1 == orderMonth && iDelim2 == orderDay) { + dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$"); + } else if (iDelim1 == orderMonth) { + dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$"); + } else if (iDelim2 == orderDay) { + dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$"); + } else { + dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$"); + } + var matched = dateRegexp.exec(value); + if(matched != null) { + if (!isValidDate(matched[3], matched[2], matched[1])) { + if (i == 0) { + focusField = form[oDate[x][0]]; + } + fields[i++] = oDate[x][1]; + bValid = false; + } + } else { + if (i == 0) { + focusField = form[oDate[x][0]]; + } + fields[i++] = oDate[x][1]; + bValid = false; + } + } else { + if (i == 0) { + focusField = form[oDate[x][0]]; + } + fields[i++] = oDate[x][1]; + bValid = false; + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return bValid; + } + + function isValidDate(day, month, year) { + if (month < 1 || month > 12) { + return false; + } + if (day < 1 || day > 31) { + return false; + } + if ((month == 4 || month == 6 || month == 9 || month == 11) && + (day == 31)) { + return false; + } + if (month == 2) { + var leap = (year % 4 == 0 && + (year % 100 != 0 || year % 400 == 0)); + if (day>29 || (day == 29 && !leap)) { + return false; + } + } + return true; + }]]> + + + + + + + + + + + + + + + 0)) { + + var iMin = parseInt(oRange[x][2]("min")); + var iMax = parseInt(oRange[x][2]("max")); + var iValue = parseInt(field.value); + if (!(iValue >= iMin && iValue <= iMax)) { + if (i == 0) { + focusField = field; + } + fields[i++] = oRange[x][1]; + isValid = false; + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return isValid; + }]]> + + + + + + + 0)) { + + var fMin = parseFloat(oRange[x][2]("min")); + var fMax = parseFloat(oRange[x][2]("max")); + var fValue = parseFloat(field.value); + if (!(fValue >= fMin && fValue <= fMax)) { + if (i == 0) { + focusField = field; + } + fields[i++] = oRange[x][1]; + isValid = false; + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return isValid; + }]]> + + + + + + + 0)) { + if (!luhnCheck(form[oCreditCard[x][0]].value)) { + if (i == 0) { + focusField = form[oCreditCard[x][0]]; + } + fields[i++] = oCreditCard[x][1]; + bValid = false; + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return bValid; + } + + /** + * Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl + */ + function luhnCheck(cardNumber) { + if (isLuhnNum(cardNumber)) { + var no_digit = cardNumber.length; + var oddoeven = no_digit & 1; + var sum = 0; + for (var count = 0; count < no_digit; count++) { + var digit = parseInt(cardNumber.charAt(count)); + if (!((count & 1) ^ oddoeven)) { + digit *= 2; + if (digit > 9) digit -= 9; + }; + sum += digit; + }; + if (sum == 0) return false; + if (sum % 10 == 0) return true; + }; + return false; + } + + function isLuhnNum(argvalue) { + argvalue = argvalue.toString(); + if (argvalue.length == 0) { + return false; + } + for (var n = 0; n < argvalue.length; n++) { + if ((argvalue.substring(n, n+1) < "0") || + (argvalue.substring(n,n+1) > "9")) { + return false; + } + } + return true; + }]]> + + + + + + + + 0)) { + if (!checkEmail(form[oEmail[x][0]].value)) { + if (i == 0) { + focusField = form[oEmail[x][0]]; + } + fields[i++] = oEmail[x][1]; + bValid = false; + } + } + } + if (fields.length > 0) { + focusField.focus(); + alert(fields.join('\n')); + } + return bValid; + } + + /** + * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com), + * http://javascript.internet.com + */ + function checkEmail(emailStr) { + if (emailStr.length == 0) { + return true; + } + var emailPat=/^(.+)@(.+)$/; + var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; + var validChars="\[^\\s" + specialChars + "\]"; + var quotedUser="(\"[^\"]*\")"; + var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/; + var atom=validChars + '+'; + var word="(" + atom + "|" + quotedUser + ")"; + var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); + var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$"); + var matchArray=emailStr.match(emailPat); + if (matchArray == null) { + return false; + } + var user=matchArray[1]; + var domain=matchArray[2]; + if (user.match(userPat) == null) { + return false; + } + var IPArray = domain.match(ipDomainPat); + if (IPArray != null) { + for (var i = 1; i <= 4; i++) { + if (IPArray[i] > 255) { + return false; + } + } + return true; + } + var domainArray=domain.match(domainPat); + if (domainArray == null) { + return false; + } + var atomPat=new RegExp(atom,"g"); + var domArr=domain.match(atomPat); + var len=domArr.length; + if ((domArr[domArr.length-1].length < 2) || + (domArr[domArr.length-1].length > 3)) { + return false; + } + if (len < 2) { + return false; + } + return true; + }]]> + + + + + + + diff --git a/genapp/src/plugin-resources/struts-validation/template.properties b/genapp/src/plugin-resources/struts-validation/template.properties new file mode 100644 index 00000000..afd112ac --- /dev/null +++ b/genapp/src/plugin-resources/struts-validation/template.properties @@ -0,0 +1,20 @@ +# ------------------------------------------------------------------- +# Copyright 2001-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. +# ------------------------------------------------------------------- + +maven.genapp.repackage=java,test,test-cactus +maven.genapp.filter=project.xml,src/conf/cactus-web.xml,src/merge/**,src/conf/ApplicationResources.properties + +maven.genapp.default.package=example.web diff --git a/genapp/src/plugin-test/templatesTest/project.properties b/genapp/src/plugin-test/templatesTest/project.properties index b2dc11fb..f550b6a5 100644 --- a/genapp/src/plugin-test/templatesTest/project.properties +++ b/genapp/src/plugin-test/templatesTest/project.properties @@ -14,7 +14,7 @@ # limitations under the License. # ------------------------------------------------------------------- #templates to test -templates=complex,default,ejb,struts,struts-jstl,tapestry,web,web-jstl,web-velocity +templates=complex,default,ejb,struts,struts-jstl,struts-validation,tapestry,web,web-jstl,web-velocity #artifact genarated by a template template.tapestry.artifact=${maven.genapp.basedir}/target/${maven.genapp.template.id}.war # directory where it should be generated diff --git a/genapp/xdocs/changes.xml b/genapp/xdocs/changes.xml index ae7d08d1..2a73c014 100644 --- a/genapp/xdocs/changes.xml +++ b/genapp/xdocs/changes.xml @@ -31,6 +31,7 @@ Using ${maven.home.local} instead of ${user.home}/.maven for templates. An error "Artifact strutstest-2.1.0.jar doesn't exist" is thrown by struts projects generated by the plugin. Added Tapestry template. + Added Struts with validation template. Added prompt for project root. Update dependencies to match ones in maven 1.1 core and to unify them between plugins. The following dependencies are updated :