continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r357171 - in /maven/continuum/trunk/continuum-webapp/src/main: java/org/apache/maven/continuum/web/action/ resources/ resources/org/apache/maven/continuum/web/action/
Date Fri, 16 Dec 2005 15:04:04 GMT
Author: evenisse
Date: Fri Dec 16 07:03:43 2005
New Revision: 357171

URL: http://svn.apache.org/viewcvs?rev=357171&view=rev
Log:
Externalize validation, so execute methods are more simple

Added:
    maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/ConfigurationAction-validation.xml
  (with props)
    maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction-validation.xml
  (with props)
    maven/continuum/trunk/continuum-webapp/src/main/resources/validators.xml   (with props)
Modified:
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/LoginAction.java
    maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction.properties
    maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml

Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java?rev=357171&r1=357170&r2=357171&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java
(original)
+++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ConfigurationAction.java
Fri Dec 16 07:03:43 2005
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.continuum.Continuum;
+import org.apache.maven.continuum.configuration.ConfigurationStoringException;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
@@ -24,9 +25,11 @@
 import java.net.URL;
 
 import com.opensymphony.xwork.ActionSupport;
+import com.opensymphony.xwork.Preparable;
 
 public class ConfigurationAction
     extends ActionSupport
+    implements Preparable
 {
     private Continuum continuum;
 
@@ -44,68 +47,52 @@
 
     private String companyUrl;
 
-    public String execute()
-        throws Exception
+    public void prepare()
     {
-        boolean hasErrors = false;
+        guestAccountEnabled = continuum.getConfiguration().isGuestAccountEnabled();
 
-        // TODO : Using WebWork Validators
-        if ( StringUtils.isEmpty( workingDirectory ) )
-        {
-            addFieldError( "workingDirectory", getText( "configuration.missing.workingDirectory"
) );
+        workingDirectory = continuum.getConfiguration().getWorkingDirectory().getAbsolutePath();
 
-            hasErrors = true;
-        }
+        buildOutputDirectory = continuum.getConfiguration().getBuildOutputDirectory().getAbsolutePath();
 
-        if ( StringUtils.isEmpty( buildOutputDirectory ) )
-        {
-            addFieldError( "buildOutputDirectory", getText( "configuration.missing.buildOutputDirectory"
) );
+        baseUrl = continuum.getConfiguration().getUrl();
 
-            hasErrors = true;
-        }
+        companyLogo = continuum.getConfiguration().getCompanyLogo();
 
-        if ( StringUtils.isEmpty( baseUrl ) )
-        {
-            addFieldError( "baseUrl", getText( "configuration.missing.baseUrl" ) );
+        companyName = continuum.getConfiguration().getCompanyName();
 
-            hasErrors = true;
-        }
-        else
-        {
-            try
-            {
-                URL url = new URL( baseUrl );
-            }
-            catch ( MalformedURLException e )
-            {
-                addFieldError( "baseUrl", getText( "configuration.invalid.baseUrl" ) );
+        companyUrl = continuum.getConfiguration().getCompanyUrl();
+    }
 
-                hasErrors = true;
-            }
-        }
+    public String execute()
+        throws Exception
+    {
+        continuum.getConfiguration().setGuestAccountEnabled( guestAccountEnabled );
 
-        if ( hasErrors )
-        {
-            return INPUT;
-        }
-        else
-        {
-            continuum.getConfiguration().setGuestAccountEnabled( guestAccountEnabled );
+        continuum.getConfiguration().setWorkingDirectory( new File( workingDirectory ) );
 
-            continuum.getConfiguration().setWorkingDirectory( new File( workingDirectory
) );
+        continuum.getConfiguration().setBuildOutputDirectory( new File( buildOutputDirectory
) );
 
-            continuum.getConfiguration().setBuildOutputDirectory( new File( buildOutputDirectory
) );
+        continuum.getConfiguration().setUrl( baseUrl );
 
-            continuum.getConfiguration().setUrl( baseUrl );
+        continuum.getConfiguration().setCompanyLogo( companyLogo );
 
-            continuum.getConfiguration().setCompanyLogo( companyLogo );
+        continuum.getConfiguration().setCompanyName( companyName );
 
-            continuum.getConfiguration().setCompanyName( companyName );
+        continuum.getConfiguration().setCompanyUrl( companyUrl );
 
-            continuum.getConfiguration().setCompanyUrl( companyUrl );
+        try
+        {
+            continuum.getConfiguration().store();
+        }
+        catch ( ConfigurationStoringException e )
+        {
+            addActionError( "Can't store configuration :" + e.getMessage() );
 
-            return SUCCESS;
+            return INPUT;
         }
+
+        return SUCCESS;
     }
 
     public String doDefault()
@@ -122,7 +109,7 @@
 
     public boolean isGuestAccountEnabled()
     {
-        return continuum.getConfiguration().isGuestAccountEnabled();
+        return guestAccountEnabled;
     }
 
     public void setGuestAccountEnabled( boolean guestAccountEnabled )
@@ -132,7 +119,7 @@
 
     public String getWorkingDirectory()
     {
-        return continuum.getConfiguration().getWorkingDirectory().getAbsolutePath();
+        return workingDirectory;
     }
 
     public void setWorkingDirectory( String workingDirectory )
@@ -142,7 +129,7 @@
 
     public String getBuildOutputDirectory()
     {
-        return continuum.getConfiguration().getBuildOutputDirectory().getAbsolutePath();
+        return buildOutputDirectory;
     }
 
     public void setBuildOutputDirectory( String buildOutputDirectory )
@@ -152,7 +139,7 @@
 
     public String getBaseUrl()
     {
-        return continuum.getConfiguration().getUrl();
+        return baseUrl;
     }
 
     public void setBaseUrl( String baseUrl )
@@ -162,7 +149,7 @@
 
     public String getCompanyLogo()
     {
-        return continuum.getConfiguration().getCompanyLogo();
+        return companyLogo;
     }
 
     public void setCompanyLogo( String companyLogo )
@@ -172,7 +159,7 @@
 
     public String getCompanyName()
     {
-        return continuum.getConfiguration().getCompanyName();
+        return companyName;
     }
 
     public void setCompanyName( String companyName )
@@ -182,7 +169,7 @@
 
     public String getCompanyUrl()
     {
-        return continuum.getConfiguration().getCompanyUrl();
+        return companyUrl;
     }
 
     public void setCompanyUrl( String companyUrl )

Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/LoginAction.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/LoginAction.java?rev=357171&r1=357170&r2=357171&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/LoginAction.java
(original)
+++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/LoginAction.java
Fri Dec 16 07:03:43 2005
@@ -22,25 +22,22 @@
 public class LoginAction
     extends ActionSupport
 {
-    private String username;
+    private String username = "";
 
-    private String password;
+    private String password = "";
 
+    /**
+     * Execute the login action
+     */
     public String execute()
         throws Exception
     {
-        //TODO
-        if ( StringUtils.isEmpty( username ) || StringUtils.isEmpty( password ) || !"testuser".equals(
username ) )
-        {
-            //TODO : i18n
-            addFieldError( "username", getText( "login.bad_login_password" ) );
-
-            return INPUT;
-        }
-
         return SUCCESS;
     }
 
+    /**
+     * Redirect to login view
+     */
     public String doDefault()
     {
         return INPUT;
@@ -49,6 +46,11 @@
     public String getUsername()
     {
         return username;
+    }
+
+    public String getPassword()
+    {
+        return password;
     }
 
     public void setUsername( String username )

Added: maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/ConfigurationAction-validation.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/ConfigurationAction-validation.xml?rev=357171&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/ConfigurationAction-validation.xml
(added)
+++ maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/ConfigurationAction-validation.xml
Fri Dec 16 07:03:43 2005
@@ -0,0 +1,22 @@
+<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork Validator 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+
+<validators>
+    <field name="workingDirectory">
+        <field-validator type="requiredstring">
+            <message key="configuration.missing.workingDirectory"/>
+        </field-validator>
+    </field>
+    <field name="buildOutputDirectory">
+        <field-validator type="requiredstring">
+            <message key="configuration.missing.buildOutputDirectory"/>
+        </field-validator>
+    </field>
+    <field name="baseUrl">
+        <field-validator type="requiredstring" short-circuit="true">
+            <message key="configuration.missing.baseUrl"/>
+        </field-validator>
+        <field-validator type="url">
+            <message key="configuration.invalid.baseUrl"/>
+        </field-validator>
+    </field>
+</validators>

Propchange: maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/ConfigurationAction-validation.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/ConfigurationAction-validation.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction-validation.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction-validation.xml?rev=357171&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction-validation.xml
(added)
+++ maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction-validation.xml
Fri Dec 16 07:03:43 2005
@@ -0,0 +1,14 @@
+<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork Validator 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+
+<validators>
+    <field name="username">
+        <field-validator type="required">
+            <message key="login.username.required"/>
+        </field-validator>
+    </field>
+    <field name="password">
+        <field-validator type="required">
+            <message key="login.password.required"/>
+        </field-validator>
+    </field>
+</validators>

Propchange: maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction-validation.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction-validation.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction.properties
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction.properties?rev=357171&r1=357170&r2=357171&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction.properties
(original)
+++ maven/continuum/trunk/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/LoginAction.properties
Fri Dec 16 07:03:43 2005
@@ -1 +1,3 @@
+login.username.required = Username is required!
+login.password.required = Password is required!
 login.bad_login_password = Username/password incorrect

Added: maven/continuum/trunk/continuum-webapp/src/main/resources/validators.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-webapp/src/main/resources/validators.xml?rev=357171&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/resources/validators.xml (added)
+++ maven/continuum/trunk/continuum-webapp/src/main/resources/validators.xml Fri Dec 16 07:03:43
2005
@@ -0,0 +1,13 @@
+<validators>
+    <validator name="required" class="com.opensymphony.webwork.validators.JavaScriptRequiredFieldValidator"/>
+    <validator name="requiredstring" class="com.opensymphony.webwork.validators.JavaScriptRequiredStringValidator"/>
+    <validator name="int" class="com.opensymphony.webwork.validators.JavaScriptIntRangeFieldValidator"/>
+    <validator name="date" class="com.opensymphony.webwork.validators.JavaScriptDateRangeFieldValidator"/>
+    <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.webwork.validators.JavaScriptEmailValidator"/>
+    <validator name="url" class="com.opensymphony.webwork.validators.JavaScriptURLValidator"/>
+    <validator name="visitor" class="com.opensymphony.webwork.validators.JavaScriptVisitorFieldValidator"/>
+    <validator name="conversion" class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator"/>
+    <validator name="stringlength" class="com.opensymphony.xwork.validator.validators.StringLengthFieldValidator"/>
+</validators>
\ No newline at end of file

Propchange: maven/continuum/trunk/continuum-webapp/src/main/resources/validators.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-webapp/src/main/resources/validators.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml?rev=357171&r1=357170&r2=357171&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml (original)
+++ maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml Fri Dec 16 07:03:43
2005
@@ -5,7 +5,23 @@
     <include file="webwork-default.xml"/>
 
     <package name="default" extends="webwork-default">
-        <default-interceptor-ref name="completeStack"/>
+        <interceptors>
+            <interceptor-stack name="defaultContinuumStack">
+                <interceptor-ref name="prepare"/>
+                <interceptor-ref name="servlet-config"/>
+                <interceptor-ref name="chain"/>
+                <interceptor-ref name="model-driven"/>
+                <interceptor-ref name="component"/>
+                <interceptor-ref name="fileUpload"/>
+                <interceptor-ref name="static-params"/>
+                <interceptor-ref name="params"/>
+                <!-- interceptor-ref name="conversionError"/ -->
+                <interceptor-ref name="validation"/>
+                <interceptor-ref name="workflow"/>
+            </interceptor-stack>
+        </interceptors>
+
+        <default-interceptor-ref name="defaultContinuumStack"/>
 
         <action name="configuration"
                 class="configurationAction">



Mime
View raw message