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.gui.control.ControlImpl;
38 import info.magnolia.freemarker.FreemarkerUtil;
39
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.Iterator;
43 import java.util.List;
44 import java.util.Map;
45
46 import javax.jcr.RepositoryException;
47 import javax.servlet.http.HttpServletRequest;
48 import javax.servlet.http.HttpServletResponse;
49
50 import org.apache.commons.lang.BooleanUtils;
51 import org.apache.commons.lang.StringUtils;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54
55
56
57
58
59
60 public class FiltersControl extends MultiControl {
61 private static final Logger log = LoggerFactory.getLogger(FiltersControl.class);
62
63 private List<OptionConfiguration> properties;
64
65 private List<OptionConfiguration> conditions;
66
67
68
69
70 public String getInnerHtml() {
71 String name = "/" + StringUtils.replace(FiltersControl.class.getName(), ".", "/") + "Inner.html";
72 Map<String, Object> map = new HashMap<String, Object>();
73 map.put("this", this);
74 return FreemarkerUtil.process(name, map);
75 }
76
77 @Override
78 public String getSaveInfo() {
79 Boolean renderSaveInfo = BooleanUtils.toBooleanObject(this.getConfigValue("saveInfo"));
80 if (BooleanUtils.toBooleanDefaultIfNull(renderSaveInfo, true)) {
81 ControlImpl dummy = new ControlImpl(this.getName(), (String) null);
82
83 return dummy.getHtmlSaveInfo();
84 }
85
86 return "";
87 }
88
89
90
91
92 @Override
93 public String getGetObjectFunction() {
94 return "function(prefix, index){" +
95 " var obj = new Object();" +
96 " obj.condition = document.getElementById(prefix + '_condition').value; " +
97 " obj.property = document.getElementById(prefix + '_property').value; " +
98 " obj.regex = document.getElementById(prefix + '_regex').value; " +
99 " return obj;" +
100 "}";
101 }
102
103
104
105
106 @Override
107 public String getNewObjectFunction() {
108 return "function(){" +
109 " var obj = new Object();" +
110 " obj.condition = ''; " +
111 " obj.property = ''; " +
112 " obj.regex = ''; " +
113 " return obj;" +
114 "}";
115 }
116
117 @Override
118 protected String getEmpty() {
119 return "[{condition:'', property:'',regex:''}]";
120 }
121
122 public List<OptionConfiguration> getConditions() {
123 return conditions;
124 }
125
126 public List<OptionConfiguration> getProperties() {
127 return properties;
128 }
129
130 public void setProperties(List<OptionConfiguration> properties) {
131 this.properties = properties;
132 }
133
134 public void setConditions(List<OptionConfiguration> conditions) {
135 this.conditions = conditions;
136 }
137
138 @Override
139 public void init(HttpServletRequest request, HttpServletResponse response,
140 Content storageNode, Content configNode) throws RepositoryException {
141 super.init(request, response, storageNode, configNode);
142
143 this.conditions = new ArrayList<OptionConfiguration>();
144 for (Iterator<Content> iter = configNode.getContent("options-conditions").getChildren().iterator(); iter.hasNext(); ) {
145 Content child = iter.next();
146 OptionConfiguration bc = new OptionConfiguration();
147 bc.setLabel(child.getNodeData("label").getString());
148 bc.setValue(child.getNodeData("value").getString());
149 this.conditions.add(bc);
150 }
151 this.properties = new ArrayList<OptionConfiguration>();
152 for (Iterator<Content> iter = configNode.getContent("options-properties").getChildren().iterator(); iter.hasNext(); ) {
153 Content child = iter.next();
154 OptionConfiguration bc = new OptionConfiguration();
155 bc.setLabel(child.getNodeData("label").getString());
156 bc.setValue(child.getNodeData("value").getString());
157 this.properties.add(bc);
158 }
159 }
160 }