1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.webui.form;
18
19 import java.util.HashMap;
20
21 import org.exoplatform.services.cms.JcrInputProperty;
22 import org.exoplatform.webui.form.UIFormInputBase;
23
24
25
26
27
28
29
30 public abstract class DialogFormField {
31
32 protected final String SEPARATOR = "=";
33 protected final String JCR_PATH = "jcrPath" + SEPARATOR;
34 protected final String EDITABLE = "editable" + SEPARATOR;
35 protected final String ONCHANGE = "onchange" + SEPARATOR;
36 protected final String OPTIONS = "options" + SEPARATOR;
37 protected final String TYPE = "type" + SEPARATOR ;
38 protected final String VISIBLE = "visible" + SEPARATOR;
39 protected final String NODETYPE = "nodetype" + SEPARATOR;
40 protected final String MIXINTYPE = "mixintype" + SEPARATOR;
41 protected final String MIMETYPE = "mimetype" + SEPARATOR;
42 protected final String VALIDATE = "validate" + SEPARATOR;
43 protected final String SELECTOR_ACTION = "selectorAction" + SEPARATOR;
44 protected final String SELECTOR_CLASS = "selectorClass" + SEPARATOR;
45 protected final String SELECTOR_ICON = "selectorIcon" + SEPARATOR;
46 protected final String SELECTOR_PARAMS = "selectorParams" + SEPARATOR;
47 protected final String WORKSPACE_FIELD = "workspaceField" + SEPARATOR;
48 protected final String SCRIPT = "script" + SEPARATOR;
49 protected final String SCRIPT_PARAMS = "scriptParams" + SEPARATOR;
50 protected final String MULTI_VALUES = "multiValues" + SEPARATOR;
51 protected final String REFERENCE = "reference" + SEPARATOR;
52 protected final String REPOSITORY = "repository";
53 protected final String DEFAULT_VALUES = "defaultValues" + SEPARATOR ;
54 protected final String ROW_SIZE = "rows" + SEPARATOR ;
55 protected final String COL_SIZE = "columns" + SEPARATOR ;
56 protected final String SIZE = "size" + SEPARATOR ;
57 protected final String CHANGE_IN_JCR_PATH_PARAM = "changeInJcrPathParam" + SEPARATOR;
58 protected final String FILL_JCR_DATA_OF_FILE = "fillJcrDataOfFile" + SEPARATOR;
59
60 protected String editable;
61 protected String defaultValue;
62 protected String rowSize;
63 protected String colSize;
64 protected String jcrPath;
65 protected String selectorAction;
66 protected String selectorClass;
67 protected String workspaceField;
68 protected String selectorIcon;
69 protected String multiValues;
70 protected String reference;
71 protected String validateType;
72 protected String selectorParams;
73 protected String name;
74 protected String label;
75 protected String options;
76 protected String visible;
77 protected String nodeType;
78 protected String mixinTypes;
79 protected String mimeTypes;
80 protected String onchange;
81 protected String groovyScript;
82 protected String[] scriptParams;
83 protected String type;
84 protected String size;
85 protected String changeInJcrPathParam;
86 protected String fillJcrDataOfFile = "true";
87
88 public DialogFormField(String name, String label, String[] arguments) {
89 HashMap<String,String> parsedArguments = parseArguments(arguments) ;
90 this.editable = parsedArguments.get(EDITABLE);
91 this.defaultValue = parsedArguments.get(DEFAULT_VALUES);
92 this.rowSize = parsedArguments.get(ROW_SIZE);
93 this.colSize = parsedArguments.get(COL_SIZE);
94 this.jcrPath = parsedArguments.get(JCR_PATH);
95 this.selectorAction = parsedArguments.get(SELECTOR_ACTION);
96 this.selectorClass = parsedArguments.get(SELECTOR_CLASS);
97 this.workspaceField = parsedArguments.get(WORKSPACE_FIELD);
98 this.selectorIcon = parsedArguments.get(SELECTOR_ICON);
99 this.multiValues = parsedArguments.get(MULTI_VALUES);
100 this.reference = parsedArguments.get(REFERENCE);
101 this.validateType = parsedArguments.get(VALIDATE);
102 this.selectorParams = parsedArguments.get(SELECTOR_PARAMS) ;
103 this.options = parsedArguments.get(OPTIONS);
104 this.visible = parsedArguments.get(VISIBLE);
105 this.nodeType = parsedArguments.get(NODETYPE);
106 this.mixinTypes = parsedArguments.get(MIXINTYPE);
107 this.mimeTypes = parsedArguments.get(MIMETYPE);
108 this.onchange = parsedArguments.get(ONCHANGE);
109 this.groovyScript = parsedArguments.get(SCRIPT);
110 this.type = parsedArguments.get(TYPE);
111 this.size = parsedArguments.get(SIZE);
112 this.changeInJcrPathParam = parsedArguments.get(CHANGE_IN_JCR_PATH_PARAM);
113 this.fillJcrDataOfFile = parsedArguments.get(FILL_JCR_DATA_OF_FILE);
114 String scriptParam = parsedArguments.get(SCRIPT_PARAMS);
115 if(scriptParam != null) {
116 scriptParams = scriptParam.split(",");
117 }
118 this.name = name;
119 this.label = label;
120 }
121
122 @SuppressWarnings("unchecked")
123 public abstract <T extends UIFormInputBase> T createUIFormInput() throws Exception;
124
125 public JcrInputProperty createJcrInputProperty (){
126 JcrInputProperty inputProperty = new JcrInputProperty();
127 inputProperty.setJcrPath(jcrPath);
128 return inputProperty;
129 }
130
131 public String getEditable() { return editable; }
132 public void setEditable(String editable) { this.editable = editable; }
133
134 public String getDefaultValue() { return defaultValue; }
135 public void setDefaultValue(String defaultValue) { this.defaultValue = defaultValue; }
136
137 public String getRowSize() { return rowSize; }
138 public void setRowSize(String rowSize) { this.rowSize = rowSize; }
139
140 public String getColSize() { return colSize; }
141 public void setColSize(String colSize) { this.colSize = colSize; }
142
143 public String getJcrPath() { return jcrPath; }
144 public void setJcrPath(String jcrPath) { this.jcrPath = jcrPath; }
145
146 public String getSelectorAction() { return selectorAction; }
147 public void setSelectorAction(String selectorAction) {
148 this.selectorAction = selectorAction;
149 }
150
151 public String getSelectorClass() { return selectorClass; }
152 public void setSelectorClass(String selectorClass) {
153 this.selectorClass = selectorClass;
154 }
155
156 public String getWorkspaceField() { return workspaceField; }
157 public void setWorkspaceField(String workspaceField) {
158 this.workspaceField = workspaceField;
159 }
160
161 public String getSelectorIcon() { return selectorIcon; }
162 public void setSelectorIcon(String selectorIcon) {
163 this.selectorIcon = selectorIcon;
164 }
165
166 public String getMultiValues() { return multiValues; }
167 public void setMultiValues(String multiValues) {
168 this.multiValues = multiValues;
169 }
170
171 public String getReference() { return reference; }
172 public void setReferenceType(String reference) {
173 this.reference = reference;
174 }
175
176 public String getValidateType() { return validateType; }
177 public void setValidateType(String validateType) {
178 this.validateType = validateType;
179 }
180
181 public String[] getSelectorParams() {
182 if(selectorParams != null) {
183 return selectorParams.split(",");
184 }
185 return null;
186 }
187
188 public String getSelectorParam() { return selectorParams; }
189 public void setSelectorParam(String param) { this.selectorParams = param; }
190
191 public String getName() { return name; }
192 public void setName(String name) { this.name = name; }
193
194 public String getLabel() { return label; }
195 public void setLabel(String label) {this.label = label;}
196
197 public String getOptions() { return options; }
198 public void setOptions(String options) { this.options = options; }
199
200 public String getVisible() { return visible;}
201 public void setVisible(String visible) {this.visible = visible; }
202
203 public String getNodeType() { return nodeType; }
204 public void setNodeType(String nodeType) { this.nodeType = nodeType; }
205
206 public String getMixinTypes() { return mixinTypes; }
207 public void setMixinTypes(String mixinTypes) { this.mixinTypes = mixinTypes; }
208
209 public String getMimeTypes() { return mimeTypes; }
210 public void setMimeTypes(String mimeTypes) { this.mimeTypes = mimeTypes; }
211
212 public String getOnchange() { return onchange; }
213 public void setOnchange(String onchange) { this.onchange = onchange; }
214
215 public String getGroovyScript() { return groovyScript; }
216 public void setGroovyScript(String groovyScript) { this.groovyScript = groovyScript; }
217
218 public String[] getScriptParams() { return scriptParams; }
219 public void setScriptParams(String[] scriptParams) { this.scriptParams = scriptParams; }
220
221 public String getType() { return type; }
222 public void setType(String type) { this.type = type;}
223
224 public String getSize() { return size; }
225 public void setSize(String size) { this.size = size;}
226
227 public String getChangeInJcrPathParam() { return changeInJcrPathParam; }
228 public void setChangeInJcrPathParam(String value) { this.changeInJcrPathParam = value; }
229
230 public String getFillJcrDataFile() { return fillJcrDataOfFile; }
231 public void setFillJcrDataFile(String value) { fillJcrDataOfFile = value; }
232
233 public boolean isMultiValues() { return "true".equalsIgnoreCase(multiValues); }
234 public boolean isReference() { return "true".equalsIgnoreCase(reference); }
235 public boolean isEditable() { return !"false".equalsIgnoreCase(editable); }
236 public boolean isEditableIfNull() { return "if-null".equalsIgnoreCase(editable); }
237 public boolean isVisibleIfNotNull() { return "if-not-null".equals(visible); }
238 public boolean isFillJcrDataFile() {
239 return "true".equals(fillJcrDataOfFile) || fillJcrDataOfFile == null;
240 }
241
242 private HashMap<String,String> parseArguments(String[] arguments) {
243 HashMap<String,String> map = new HashMap<String,String>() ;
244 for(String argument:arguments) {
245 String value = null;
246 if(argument.indexOf(SEPARATOR)>0) {
247 value = argument.substring(argument.indexOf(SEPARATOR)+1) ;
248 }else {
249 value = argument;
250 map.put(DEFAULT_VALUES,value) ; continue;
251 }
252 if (argument.startsWith(JCR_PATH)) {
253 map.put(JCR_PATH,value); continue;
254 } else if (argument.startsWith(EDITABLE)) {
255 map.put(EDITABLE,value); continue;
256 } else if (argument.startsWith(SELECTOR_ACTION)) {
257 map.put(SELECTOR_ACTION,value) ; continue;
258 } else if (argument.startsWith(SELECTOR_CLASS)) {
259 map.put(SELECTOR_CLASS,value); continue;
260 } else if (argument.startsWith(MULTI_VALUES)) {
261 map.put(MULTI_VALUES,value); continue;
262 } else if (argument.startsWith(SELECTOR_ICON)) {
263 map.put(SELECTOR_ICON,value); continue;
264 } else if (argument.startsWith(SELECTOR_PARAMS)) {
265 map.put(SELECTOR_PARAMS,value); continue;
266 }else if (argument.startsWith(WORKSPACE_FIELD)) {
267 map.put(WORKSPACE_FIELD,value); continue;
268 } else if (argument.startsWith(VALIDATE)) {
269 map.put(VALIDATE,value); continue;
270 } else if (argument.startsWith(REFERENCE)) {
271 map.put(REFERENCE, value); continue;
272 } else if(argument.startsWith(DEFAULT_VALUES)) {
273 map.put(DEFAULT_VALUES,value); continue;
274 } else if(argument.startsWith(ROW_SIZE)) {
275 map.put(ROW_SIZE,value); continue;
276 } else if(argument.startsWith(COL_SIZE)) {
277 map.put(COL_SIZE,value); continue;
278 } else if(argument.startsWith(OPTIONS)){
279 map.put(OPTIONS,value); continue;
280 } else if(argument.startsWith(SCRIPT)) {
281 map.put(SCRIPT,value); continue;
282 } else if(argument.startsWith(SCRIPT_PARAMS)){
283 map.put(SCRIPT_PARAMS,value); continue;
284 } else if(argument.startsWith(VISIBLE)){
285 map.put(VISIBLE,value); continue;
286 } else if(argument.startsWith(TYPE)){
287 map.put(TYPE,value) ; continue;
288 } else if(argument.startsWith(ONCHANGE)){
289 map.put(ONCHANGE,value); continue;
290 } else if (argument.startsWith(MIXINTYPE)) {
291 map.put(MIXINTYPE, value); continue;
292 } else if (argument.startsWith(MIMETYPE)) {
293 map.put(MIMETYPE, value); continue;
294 } else if(argument.startsWith(NODETYPE)) {
295 map.put(NODETYPE, value) ;
296 continue ;
297 } else if(argument.startsWith(SIZE)) {
298 map.put(SIZE, value) ;
299 continue ;
300 } else if (argument.startsWith(CHANGE_IN_JCR_PATH_PARAM)) {
301 map.put(CHANGE_IN_JCR_PATH_PARAM, value);
302 continue;
303 } else if (argument.startsWith(FILL_JCR_DATA_OF_FILE)) {
304 map.put(FILL_JCR_DATA_OF_FILE, value);
305 continue;
306 } else {
307 map.put(DEFAULT_VALUES,argument);
308 }
309 }
310 return map;
311 }
312 }