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.rssaggregator;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.cms.core.ItemType;
38 import info.magnolia.cms.core.Path;
39 import info.magnolia.cms.security.AccessDeniedException;
40 import info.magnolia.jcr.util.SessionUtil;
41 import info.magnolia.module.admininterface.UUIDSaveHandler;
42 import info.magnolia.module.data.DataConsts;
43
44 import java.util.Iterator;
45
46 import javax.jcr.Node;
47 import javax.jcr.PathNotFoundException;
48 import javax.jcr.RepositoryException;
49
50 import org.apache.commons.lang.StringUtils;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54 import net.sf.json.JSONArray;
55 import net.sf.json.JSONObject;
56
57
58
59
60
61
62 public class MultiControlSaveHandler extends UUIDSaveHandler {
63
64 private static final Logger log = LoggerFactory.getLogger(MultiControlSaveHandler.class);
65 private static final String IMAGE_PROPERTY = "img";
66
67 @Override
68 protected void processString(Content node, String name, int type,
69 int encoding, String[] values, String valueStr)
70 throws PathNotFoundException, RepositoryException,
71 AccessDeniedException {
72 Object control = this.getDialog().getSub(name);
73
74 if (control instanceof MultiValueControl) {
75 try {
76
77 node.delete(name);
78 } catch (PathNotFoundException e) {
79
80 }
81 Content filters = node.createContent(name, new ItemType(DataConsts.MODULE_DATA_CONTENT_NODE_TYPE));
82 new JSONArray();
83 JSONArray json = JSONArray.fromObject(valueStr);
84 for (int i = 0; i < json.size(); i++) {
85 Content content = filters.createContent(Path.getUniqueLabel(filters, "00"), new ItemType(DataConsts.MODULE_DATA_CONTENT_NODE_TYPE));
86 JSONObject value = json.getJSONObject(i);
87 Iterator<String> iter = value.keys();
88 while (iter.hasNext()) {
89 String key = iter.next();
90
91 if (StringUtils.equals(IMAGE_PROPERTY, key)) {
92 try {
93 if (value.get(key) != null && StringUtils.isNotBlank(value.get(key).toString())) {
94 Node fn = SessionUtil.getNode("dms", value.get(key).toString());
95 if (fn != null) {
96 content.createNodeData("imgUUID", fn.getIdentifier());
97 }
98 }
99 } catch (Exception e) {
100 log.error("Could not get UUID for image stored in DMS: " + e.getMessage());
101 }
102 }
103 content.createNodeData(key, value.get(key));
104 }
105 }
106 } else {
107 super.processString(node, name, type, encoding, values, valueStr);
108 }
109 }
110 }