1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.morph.util;
17
18 import java.beans.PropertyEditorSupport;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21
22 import org.springframework.core.io.Resource;
23 import org.springframework.core.io.support.ResourceArrayPropertyEditor;
24 import org.springframework.util.StringUtils;
25
26 /**
27 * Drop-in replacement for Spring's InputStreamEditor
28 * to convert one or more Resources to an InputStream.
29 * @author Matt Benson
30 */
31 public class ResourceArrayInputStreamPropertyEditor extends PropertyEditorSupport {
32
33 private ResourceArrayPropertyEditor resourceArrayPropertyEditor;
34
35 /**
36 * Construct a new ResourceArrayInputStreamPropertyEditor.
37 */
38 public ResourceArrayInputStreamPropertyEditor() {
39 this(new ResourceArrayPropertyEditor());
40 }
41
42 /**
43 * Construct a new ResourceArrayInputStreamPropertyEditor.
44 * @param resourceArrayPropertyEditor
45 */
46 public ResourceArrayInputStreamPropertyEditor(ResourceArrayPropertyEditor resourceArrayPropertyEditor) {
47 this.resourceArrayPropertyEditor = resourceArrayPropertyEditor ;
48 }
49
50
51
52
53 public void setAsText(String text) throws IllegalArgumentException {
54 if (StringUtils.hasLength(text)) {
55 String[] s = StringUtils.commaDelimitedListToStringArray(text);
56 ArrayList l = new ArrayList(s.length);
57 for (int i = 0; i < s.length; i++) {
58 resourceArrayPropertyEditor.setAsText(s[i]);
59 l.addAll(Arrays.asList((Resource[]) resourceArrayPropertyEditor.getValue()));
60 setValue(new ResourceArrayInputStream((Resource[]) l.toArray(new Resource[l.size()])));
61 }
62 } else {
63 setValue(null);
64 }
65 }
66
67 }