]> source.dussan.org Git - archiva.git/commitdiff
PR: MRM-150
authorMaria Odea B. Ching <oching@apache.org>
Tue, 5 Sep 2006 12:09:18 +0000 (12:09 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Tue, 5 Sep 2006 12:09:18 +0000 (12:09 +0000)
Added validation on the forms.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@440329 13f79535-47bb-0310-9956-ffa450edef68

16 files changed:
archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/IntervalValidator.java [new file with mode: 0644]
archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/SyncedRepositoryValidator.java [new file with mode: 0644]
archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml
archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureRepositoryAction-validation.xml
archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml
archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml
archiva-webapp/src/main/resources/validators.xml [new file with mode: 0644]
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/errorMessages.jsp [new file with mode: 0644]
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf

diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/IntervalValidator.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/IntervalValidator.java
new file mode 100644 (file)
index 0000000..63b9f39
--- /dev/null
@@ -0,0 +1,62 @@
+package org.apache.maven.archiva.web.validator;
+
+/*
+ * Copyright 2006 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.
+ */
+
+import com.opensymphony.xwork.validator.validators.ValidatorSupport;
+import com.opensymphony.xwork.validator.ValidationException;
+import com.opensymphony.xwork.validator.ValidatorContext;
+
+/**
+ *
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ */
+public class IntervalValidator
+    extends ValidatorSupport
+{
+
+    public void validate( Object obj )
+        throws ValidationException
+    {
+        String snapshotsPolicy = ( String ) getFieldValue( "snapshotsPolicy", obj );
+        String releasesPolicy = ( String ) getFieldValue( "releasesPolicy", obj );
+        Integer snapshotsInterval = ( Integer ) getFieldValue( "snapshotsInterval", obj );
+        Integer releasesInterval = ( Integer ) getFieldValue( "releasesInterval", obj );
+
+        ValidatorContext ctxt = getValidatorContext();
+
+        if( !snapshotsPolicy.equals( "interval" ) )
+        {
+            if( snapshotsInterval.intValue() != 0 )
+            {
+                ctxt.addActionError( "Snapshots Interval must be set to zero." );
+            }
+        }
+              
+        if( !releasesPolicy.equals( "interval" ) )
+        {
+            if( releasesInterval.intValue() != 0 )
+            {
+                ctxt.addActionError( "Releases Interval must be set to zero." );
+            }
+        }
+
+        if( ctxt.hasActionErrors() )
+        {
+            return;
+        }
+    }
+}
diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/SyncedRepositoryValidator.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/SyncedRepositoryValidator.java
new file mode 100644 (file)
index 0000000..42977bd
--- /dev/null
@@ -0,0 +1,111 @@
+package org.apache.maven.archiva.web.validator;
+
+/*
+ * Copyright 2006 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.
+ */
+
+import com.opensymphony.xwork.validator.validators.ValidatorSupport;
+import com.opensymphony.xwork.validator.ValidationException;
+import com.opensymphony.xwork.validator.ValidatorContext;
+
+/**
+ * Validator for synced repository form. The values to be validated depends on the
+ * selected sync method to be used.
+ *
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ */
+public class SyncedRepositoryValidator
+    extends ValidatorSupport
+{
+
+    public void validate( Object obj )
+        throws ValidationException
+    {
+
+        String method = ( String ) getFieldValue( "method", obj );
+        ValidatorContext ctxt = getValidatorContext();
+
+        if( method.equals( "rsync" ) )
+        {
+            String rsyncHost = ( String ) getFieldValue( "rsyncHost", obj );
+            if( rsyncHost == null || rsyncHost.equals("") )
+            {
+                ctxt.addActionError( "Rsync host is required." );
+            }
+
+            String rsyncDirectory = ( String ) getFieldValue( "rsyncDirectory", obj );
+            if( rsyncDirectory == null || rsyncDirectory.equals("") )
+            {
+                ctxt.addActionError( "Rsync directory is required." );
+            }
+
+            String rsyncMethod = ( String ) getFieldValue( "rsyncMethod", obj );
+            if( rsyncMethod == null || rsyncMethod.equals("") )
+            {
+                ctxt.addActionError( "Rsync method is required." );
+            }
+            else
+            {
+                if( !rsyncMethod.equals( "anonymous" ) && !rsyncMethod.equals( "ssh" ) )
+                {
+                    ctxt.addActionError( "Invalid rsync method" );
+                }
+            }
+
+            String username = ( String ) getFieldValue( "username", obj );
+            if( username == null || username.equals("") )
+            {
+                ctxt.addActionError( "Username is required." );
+            }
+
+        }
+        else if ( method.equals( "svn" ) )
+        {
+            String svnUrl = ( String ) getFieldValue( "svnUrl", obj );
+            if( svnUrl == null || svnUrl.equals("") )
+            {
+                ctxt.addActionError( "SVN url is required." );
+            }
+
+            String username = ( String ) getFieldValue( "username", obj );
+            if( username == null || username.equals("") )
+            {
+                ctxt.addActionError( "Username is required." );
+            }
+        }
+        else if ( method.equals( "cvs" ) )
+        {
+            String cvsRoot = ( String ) getFieldValue( "cvsRoot", obj );
+            if( cvsRoot == null || cvsRoot.equals("") )
+            {
+                ctxt.addActionError( "CVS root is required." );
+            }
+        }
+        else if ( method.equals( "file" ) )
+        {
+            String directory = ( String ) getFieldValue( "directory", obj );
+            if( directory == null || directory.equals("") )
+            {
+                ctxt.addActionError( "Directory is required." );
+            }
+        }
+
+        if( ctxt.hasActionErrors() )
+        {
+            return;
+        }
+    }
+
+}
index 8eb09009659b468426673b250e568efe81af61ce..f72ec85c8595ff91763f262d1dd9b2ee5a291e61 100644 (file)
     <field-validator type="requiredstring">
       <message>You must enter the repository identifier.</message>
     </field-validator>
+    <!--field-validator type="regex">
+      <param name="expression"><![CDATA[([A-Z][a-z][0-9])]]></param>
+      <message>Id must not have special characters.</message>
+    </field-validator-->
   </field>
   <field name="name">
     <field-validator type="requiredstring">
       <message>You must enter the repository name.</message>
     </field-validator>
   </field>
+
+  <!-- deng todo: check if the entered repo url exists -->
   <field name="url">
     <field-validator type="requiredstring">
       <message>You must enter the repository URL.</message>
     </field-validator>
   </field>
+    <field name="snapshotsInterval">
+    <field-validator type="regex">
+      <param name="expression"><![CDATA[([0-9])]]></param>
+      <message>The value must be numeric</message>
+    </field-validator>
+  </field>
+  <field name="releasesInterval">
+    <field-validator type="regex">
+      <param name="expression"><![CDATA[([0-9])]]></param>
+      <message>The value must be numeric</message>
+    </field-validator>
+  </field>
+
+  <!-- deng todo: check if the interval validator is still valid -->
+  <validator type="interval">
+    <message/>
+  </validator>
+
+  <field name="layout">
+    <field-validator type="required">
+      <message>Repository type is required.</message>
+    </field-validator>
+    <field-validator type="fieldexpression">
+      <param name="expression">layout in {"legacy", "default"} </param>
+      <message>Invalid repository type.</message>
+    </field-validator>
+  </field>
+  <field name="snapshotsPolicy">
+    <field-validator type="fieldexpression">
+      <param name="expression">snapshotsPolicy in { "disabled", "daily", "hourly", "never", "interval" }</param>
+      <message>Invalid snapshot policy.</message>
+    </field-validator>
+  </field>
+    <field name="releasesPolicy">
+    <field-validator type="fieldexpression">
+      <param name="expression">releasesPolicy in { "disabled", "daily", "hourly", "never", "interval" }</param>
+      <message>Invalid releases policy.</message>
+    </field-validator>
+  </field>
+
+  <field name="managedRepository">
+    <field-validator type="requiredstring">
+      <message>A managed repository must be selected.</message>
+    </field-validator>
+  </field>
+
   <!-- TODO: validate managed repository -->
   <!-- TODO: validate layout -->
   <!-- TODO: validate policies -->
index 4028336ca563bfb36f97736a708a52183e347215..8de49142b857cc309555964fa583656ee0d6fee9 100644 (file)
       <message>You must enter the repository name.</message>
     </field-validator>
   </field>
+  <!-- deng todo: validate if the specified directory exists -->
   <field name="directory">
     <field-validator type="requiredstring">
       <message>You must enter the repository directory.</message>
     </field-validator>
   </field>
-  <!-- TODO: validate layout -->
+  <field name="layout">
+    <field-validator type="fieldexpression">
+      <param name="expression">layout in {"legacy", "default"} </param>
+      <message>Invalid repository type.</message>
+    </field-validator>
+  </field>
 </validators>
\ No newline at end of file
index b3697df8d04c5bb60a7e526c22c8cbda669b5d24..10ff70b013263f400b63cf92c6e43184806f336c 100644 (file)
       <message>You must enter the repository name.</message>
     </field-validator>
   </field>
+  <field name="layout">
+    <field-validator type="requiredstring">
+      <message>Select repository type.</message>
+    </field-validator>
+    <field-validator type="fieldexpression">
+      <param name="expression">layout in {"legacy", "default"} </param>
+      <message>Invalid repository type.</message>
+    </field-validator>
+  </field>
+  <field name="managedRepository">
+    <field-validator type="requiredstring">
+      <message>A managed repository must be selected.</message>
+    </field-validator>
+  </field>
+
+  <validator type="syncedrepo">
+    <message/>
+  </validator>
+
   <!-- TODO: validate managed repository -->
   <!-- TODO: validate layout -->
   <!-- TODO: validate sync settings, depending on what method -->
index 214eadcc22474e779b982498d45aba10aa4389d8..43ea651aaa5fafbe6ced13a12c1fe439280df789 100644 (file)
@@ -24,5 +24,9 @@
     <field-validator type="requiredstring">
       <message>You must enter the synchronization method.</message>
     </field-validator>
+    <field-validator type="fieldexpression">
+      <param name="expression">method in { "rsync", "cvs", "svn", "file" }</param>
+      <message>Invalid method.</message>
+    </field-validator>
   </field>
 </validators>
\ No newline at end of file
diff --git a/archiva-webapp/src/main/resources/validators.xml b/archiva-webapp/src/main/resources/validators.xml
new file mode 100644 (file)
index 0000000..758717b
--- /dev/null
@@ -0,0 +1,18 @@
+<validators>
+  <validator name="required" class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/>
+  <validator name="requiredstring" class="com.opensymphony.xwork.validator.validators.RequiredStringValidator"/>
+  <validator name="int" class="com.opensymphony.xwork.validator.validators.IntRangeFieldValidator"/>
+  <validator name="double" class="com.opensymphony.xwork.validator.validators.DoubleRangeFieldValidator"/>
+  <validator name="date" class="com.opensymphony.xwork.validator.validators.DateRangeFieldValidator"/>
+  <validator name="expression" class="com.opensymphony.xwork.validator.validators.ExpressionValidator"/>
+  <validator name="fieldexpression" class="com.opensymphony.xwork.validator.validators.FieldExpressionValidator"/>
+  <validator name="email" class="com.opensymphony.xwork.validator.validators.EmailValidator"/>
+  <validator name="url" class="com.opensymphony.xwork.validator.validators.URLValidator"/>
+  <validator name="visitor" class="com.opensymphony.xwork.validator.validators.VisitorFieldValidator"/>
+  <validator name="conversion" class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator"/>
+  <validator name="stringlength" class="com.opensymphony.xwork.validator.validators.StringLengthFieldValidator"/>
+  <validator name="regex" class="com.opensymphony.xwork.validator.validators.RegexFieldValidator"/>
+  <validator name="interval" class="org.apache.maven.archiva.web.validator.IntervalValidator"/>
+  <validator name="syncedrepo" class="org.apache.maven.archiva.web.validator.SyncedRepositoryValidator"/> 
+</validators>
+
index 801b8464e117391d82ea028ffe792b043b797b7a..a22e74488ab9c04f9be3ee866c65c0165df0bb73 100644 (file)
@@ -30,6 +30,8 @@
 
   <h2>Add Proxied Repository</h2>
 
+  <%@ include file="errorMessages.jsp" %>
+  
   <ww:actionmessage/>
   <ww:form method="post" action="addProxiedRepository" namespace="/admin" validate="true">
     <ww:textfield name="id" label="Identifier" size="10"/>
@@ -45,4 +47,4 @@
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>
index 8a2f06a1084e5f74b23112711a0f7b956fd0bc7a..2ebef043e68d36776aa311f310169e05c4d1bbcd 100644 (file)
@@ -32,7 +32,7 @@
 
   <ww:actionmessage/>
   <ww:form method="post" action="addRepository" namespace="/admin" validate="true">
-    <ww:textfield name="id" label="Identifier" size="10"/>
+    <ww:textfield name="id" label="Identifier" size="10" required="true"/>
     <%@ include file="/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf" %>
     <ww:checkbox name="indexed" fieldValue="true" value="true" label="Indexed"/>
     <ww:submit value="Add Repository"/>
@@ -45,4 +45,4 @@
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>
index bd01492a32f2cee94d749b648e2cfbee5ce50c07..902a4e84e60b3f7e1b4419174b975cf48057d76d 100644 (file)
 
   <h2>Add Synced Repository</h2>
 
+  <%@ include file="errorMessages.jsp" %>
+
   <ww:actionmessage/>
   <ww:form method="post" action="addSelectedSyncedRepository" namespace="/admin" validate="true">
-    <ww:textfield name="id" label="Identifier" size="10"/>
+    <ww:textfield name="id" label="Identifier" size="10" required="true"/>
     <%@ include file="/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf" %>
 
     <ww:submit value="Add Repository"/>
@@ -46,4 +48,4 @@
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>
index 2271c6d4ff69a6a0116d5b7f9b71c5577290d57c..550c9b52339db2d0f493cbd3e942ac1fbcdd635f 100644 (file)
@@ -29,7 +29,7 @@
 <div id="contentArea">
   <ww:actionmessage/>
   <ww:form method="post" action="saveConfiguration" namespace="/admin" validate="true">
-    <ww:textfield name="indexPath" label="Index Directory" size="100"/>
+    <ww:textfield name="indexPath" label="Index Directory" size="100" required="true"/>
     <ww:textfield name="indexerCronExpression" label="Indexing Schedule"/>
     <ww:textfield name="reporterCronExpression" label="Reporting Schedule"/>
     <ww:hidden name="proxy.protocol" value="http"/>
@@ -47,4 +47,4 @@
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>
index b22891c3b9ec85345f7e33e1af1cdbe53f84ea04..f4c99f1ae0be157253139b1e34e27dafb35d5667 100644 (file)
@@ -30,6 +30,8 @@
 
   <h2>Edit Proxied Repository</h2>
 
+  <%@ include file="errorMessages.jsp" %>
+  
   <ww:actionmessage/>
   <ww:form method="post" action="editProxiedRepository" namespace="/admin" validate="true">
     <ww:hidden name="id"/>
@@ -44,4 +46,4 @@
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>
index 905593214d15f0473882cf8cee6bf4f7c4482aa8..52de6da904124c696be03c914a28d71b5d2bc4ee 100644 (file)
@@ -31,6 +31,8 @@
 
   <h2>Edit Synced Repository</h2>
 
+  <%@ include file="errorMessages.jsp" %>
+  
   <ww:actionmessage/>
   <ww:form method="post" action="editSyncedRepository" namespace="/admin" validate="true">
     <ww:hidden name="id"/>
@@ -46,4 +48,4 @@
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>
diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/errorMessages.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/errorMessages.jsp
new file mode 100644 (file)
index 0000000..9184a4e
--- /dev/null
@@ -0,0 +1,8 @@
+<p>
+<ww:if test="hasActionErrors()">
+  <b style="color: red;" >Errors:</b>
+  <ww:iterator value="actionErrors">
+    <li style="color: red;"><ww:property/></li>
+  </ww:iterator>
+</ww:if>
+</p>
\ No newline at end of file
index 2dcbce3be29bb76879aabc9ea1a0963b9c43c319..3bcf34061af102b3569ac3775be9974c2afdfd91 100644 (file)
@@ -16,8 +16,8 @@
 <%@ taglib prefix="ww" uri="/webwork" %>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 
-<ww:textfield name="name" label="Name" size="50" />
-<ww:textfield name="directory" label="Directory" size="100" />
+<ww:textfield name="name" label="Name" size="50" required="true" />
+<ww:textfield name="directory" label="Directory" size="100" required="true"/>
 <ww:select list="#@java.util.LinkedHashMap@{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}"
            name="layout" label="Type" />
 <ww:checkbox name="includeSnapshots" fieldValue="true" label="Snapshots Included" />
index 4b46713e86a104c389b57991f49d72dc9c3bf988..fd6f930439a5ee99280d9148505ef36632d2eed5 100644 (file)
@@ -15,8 +15,8 @@
   --%>
 
 <%@ taglib prefix="ww" uri="/webwork" %>
-<ww:textfield name="name" label="Name" size="50" />
-<ww:textfield name="url" label="URL" size="50" />
+<ww:textfield name="name" label="Name" size="50" required="true"/>
+<ww:textfield name="url" label="URL" size="50" required="true"/>
 <ww:select list="#@java.util.LinkedHashMap@{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}"
            name="layout" label="Type" />
 <ww:select name="snapshotsPolicy" label="Snapshots" list="#@java.util.LinkedHashMap@{