1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.admininterface;
35
36 import java.util.ArrayList;
37
38 import info.magnolia.cms.beans.runtime.MultipartForm;
39 import info.magnolia.cms.core.Content;
40 import info.magnolia.cms.core.NodeData;
41 import info.magnolia.cms.security.AccessDeniedException;
42 import info.magnolia.cms.util.NodeDataUtil;
43
44 import javax.jcr.PathNotFoundException;
45 import javax.jcr.RepositoryException;
46 import javax.jcr.Value;
47
48 import org.apache.commons.lang.StringUtils;
49
50
51
52
53
54
55
56
57 public class MultiValueSaveHandler extends SaveHandlerImpl implements FieldSaveHandler {
58
59 protected void processMultiple(Content node, String name, int type, String[] values) throws RepositoryException,
60 PathNotFoundException, AccessDeniedException {
61
62 ArrayList l = new ArrayList();
63
64 if (values != null && values.length != 0) {
65
66 for (int j = 0; j < values.length; j++) {
67 String valueStr = values[j];
68 if (StringUtils.isNotEmpty(valueStr)) {
69 Value value = getValue(valueStr, type);
70 if (value != null) {
71
72 l.add(value);
73 }
74 }
75 }
76 if(l.size() > 0) {
77 NodeData data = NodeDataUtil.getOrCreateAndSet(node, name, (Value[])l.toArray(new Value[l.size()]));
78 }
79 }
80 }
81
82 public void save(Content parentNode, Content configNode, String name,
83 MultipartForm form, int type, int valueType, int isRichEditValue,
84 int encoding) throws RepositoryException, AccessDeniedException {
85 processMultiple(parentNode, name, type, form.getParameterValues(name));
86
87 }
88
89
90 }
91