View Javadoc
1   /*
2    * Copyright 2006-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.batch.admin.integration;
18  
19  import java.io.IOException;
20  
21  import org.springframework.web.multipart.MultipartFile;
22  
23  /**
24   * @author Dave Syer
25   *
26   */
27  public class MultipartJobConfigurationRequest {
28  	
29  	private MultipartFile file;
30  
31  	/**
32  	 * @param file the file to set
33  	 */
34  	public void setFile(MultipartFile file) {
35  		this.file = file;
36  	}
37  	
38  	/**
39  	 * @return the file
40  	 */
41  	public MultipartFile getFile() {
42  		return file;
43  	}
44  	
45  	/**
46  	 * Extract the relevant data from the multipart and generate a new request.
47  	 * 
48  	 * @return a {@link JobConfigurationRequest}
49  	 */
50  	public JobConfigurationRequest getJobConfigurationRequest() {
51  		JobConfigurationRequest jobConfigurationRequest = new JobConfigurationRequest();
52  		if (file==null) {
53  			jobConfigurationRequest.setXml("");
54  			return jobConfigurationRequest;
55  		}
56  		try {
57  			jobConfigurationRequest.setXml(new String(file.getBytes()));
58  		}
59  		catch (IOException e) {
60  			throw new IllegalArgumentException("Cannot extract file from multipart", e);
61  		}
62  		jobConfigurationRequest.setFileName(file.getOriginalFilename());
63  		return jobConfigurationRequest;
64  	}
65  
66  }