diff options
author | Maria Odea B. Ching <oching@apache.org> | 2008-03-14 01:59:49 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2008-03-14 01:59:49 +0000 |
commit | f40410bae72aae4a7eabb9e5e225048f2179438b (patch) | |
tree | 00bd28a857143ceb2928fa021e0d9b6ec9b5d75f /archiva-web | |
parent | fccb504fc89ff2bfe5324facb184e7e5f72fe585 (diff) | |
download | archiva-f40410bae72aae4a7eabb9e5e225048f2179438b.tar.gz archiva-f40410bae72aae4a7eabb9e5e225048f2179438b.zip |
[MRM-216]
-added form validation and other validation in the action class
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@636953 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-web')
4 files changed, 75 insertions, 27 deletions
diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java index f5afc57aa..045a3203f 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java @@ -55,13 +55,11 @@ import java.util.Collections; import java.util.List; /** - * Upload an artifact using Jakarta file upload in webwork. If set by the user - * a pom will also be generated. Metadata will also be updated if one exists, - * otherwise it would be created. + * Upload an artifact using Jakarta file upload in webwork. If set by the user a pom will also be generated. Metadata + * will also be updated if one exists, otherwise it would be created. * * @author <a href="mailto:wsmoak@apache.org">Wendy Smoak</a> * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> - * * @plexus.component role="com.opensymphony.xwork.Action" role-hint="uploadAction" */ public class UploadAction @@ -117,7 +115,7 @@ public class UploadAction * Flag whether to generate a pom for the artifact or not. */ private boolean generatePom; - + /** * List of managed repositories to deploy to. */ @@ -249,9 +247,8 @@ public class UploadAction new ArrayList<String>( configuration.getConfiguration().getManagedRepositoriesAsMap().keySet() ); } - public String upload() + public String input() { - // TODO form validation return INPUT; } @@ -311,7 +308,10 @@ public class UploadAction } updateMetadata( getMetadata( targetPath.getAbsolutePath() ) ); - + + addActionMessage( "Artifact \'" + groupId + ":" + artifactId + ":" + version + + "\' was successfully deployed to repository \'" + repositoryId + "\'!" ); + return SUCCESS; } catch ( RepositoryNotFoundException re ) @@ -395,19 +395,20 @@ public class UploadAction { availableVersions.add( version ); } - + String latestVersion = availableVersions.get( availableVersions.size() - 1 ); metadata.setLatestVersion( latestVersion ); metadata.setAvailableVersions( availableVersions ); metadata.setLastUpdatedTimestamp( Calendar.getInstance().getTime() ); - - if( !VersionUtil.isSnapshot( version ) ) + + if ( !VersionUtil.isSnapshot( version ) ) { metadata.setReleasedVersion( latestVersion ); - } + } // TODO: - // what about the metadata checksums? re-calculate or - // just leave it to the consumers to fix it? + // what about the metadata checksums? re-calculate or + // just leave it to the consumers to fix it? or just delete it + // and let the consumers create a new checksum file? } else { @@ -418,16 +419,16 @@ public class UploadAction metadata.setLatestVersion( version ); metadata.setLastUpdatedTimestamp( Calendar.getInstance().getTime() ); metadata.setAvailableVersions( availableVersions ); - - if( !VersionUtil.isSnapshot( version ) ) + + if ( !VersionUtil.isSnapshot( version ) ) { metadata.setReleasedVersion( version ); } - } - + } + RepositoryMetadataWriter.write( metadata, metadataFile ); } - + public void validate() { try @@ -438,18 +439,15 @@ public class UploadAction addActionError( "User is not authorized to upload in repository " + repositoryId ); } - // TODO fix validation - /* if ( file == null || file.length() == 0 ) { addActionError( "Please add a file to upload." ); } - + if ( !VersionUtil.isVersion( version ) ) { addActionError( "Invalid version." ); - } - */ + } } catch ( PrincipalNotFoundException pe ) { diff --git a/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml new file mode 100644 index 000000000..b56cf3757 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. + --> + +<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" + "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> + +<validators> + <field name="groupId"> + <field-validator type="requiredstring"> + <message>You must enter a groupId.</message> + </field-validator> + </field> + <field name="artifactId"> + <field-validator type="requiredstring"> + <message>You must enter an artifactId.</message> + </field-validator> + </field> + <field name="version"> + <field-validator type="requiredstring"> + <message>You must enter a version.</message> + </field-validator> + </field> + <field name="packaging"> + <field-validator type="requiredstring"> + <message>You must enter a packaging.</message> + </field-validator> + </field> +</validators>
\ No newline at end of file diff --git a/archiva-web/archiva-webapp/src/main/resources/xwork.xml b/archiva-web/archiva-webapp/src/main/resources/xwork.xml index 18226da13..24933e253 100644 --- a/archiva-web/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-web/archiva-webapp/src/main/resources/xwork.xml @@ -154,9 +154,10 @@ <result name="input">/WEB-INF/jsp/findArtifact.jsp</result> </action> - <action name="upload" class="uploadAction" method="upload"> + <action name="upload" class="uploadAction" method="input"> <result name="input">/WEB-INF/jsp/upload.jsp</result> - <result name="success">/WEB-INF/jsp/upload.jsp</result> + <result name="error">/WEB-INF/jsp/upload.jsp</result> + <result name="success" type="redirect-action">upload</result> <interceptor-ref name="configuredPrepareParamsStack"/> <interceptor-ref name="fileUpload"/> </action> diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp index 9089991dc..c22bccc97 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp @@ -32,7 +32,11 @@ <h1>Upload Artifact</h1> <div id="contentArea"> - <ww:form action="upload!doUpload" method="post" enctype="multipart/form-data" validate="false"> + + <ww:actionerror/> + <ww:actionmessage/> + + <ww:form action="upload!doUpload" method="post" enctype="multipart/form-data" validate="true"> <%@ include file="/WEB-INF/jsp/include/uploadForm.jspf" %> <ww:submit/> </ww:form> |