1 package com.sri.emo.wizard.completion;
2
3 import com.jcorporate.expresso.core.controller.Input;
4 import com.jcorporate.expresso.core.dbobj.ValidValue;
5 import com.jcorporate.expresso.core.misc.StringUtil;
6 import com.sri.emo.wizard.PageMetadata;
7 import com.sri.emo.wizard.WizardException;
8 import com.sri.emo.wizard.defaults.EmoWizardPage;
9 import com.sri.emo.wizard.expressoimpl.WizardController;
10
11 import java.io.Serializable;
12 import java.util.*;
13
14 /***
15 * Custom Part Handler Page.
16 *
17 * @author Michael Rimov
18 */
19 public class CustomPartHandlerPage extends EmoWizardPage {
20 /***
21 *
22 */
23 private static final long serialVersionUID = 1L;
24 public static final String INVALID_MARKER = "INVALID_MARKER";
25
26 /***
27 * Constructor that builds the part handler page.
28 *
29 * @param newId Integer
30 * @param pageMetadata PageMetadata
31 */
32 public CustomPartHandlerPage(Integer newId, PageMetadata pageMetadata) {
33 super(newId, pageMetadata, null);
34 }
35
36 /***
37 * Sets the data associated with the page.
38 * <p/>
39 * intercepting values from form after user clicks 'next'
40 * <p/>
41 * <p/>
42 * Validate, calling
43 * super.addError("Error Message");
44 * for each failed criteria. Sequential wizard logic will automagically
45 * detect errors and revert to original page.
46 *
47 * @param newData Is a Map of all Parameters passed into the wizard
48 * by <tt>CompletionWizardAction</tt>
49 * @throws WizardException upon error.
50 */
51 public void setData(Serializable newData) throws WizardException {
52
53 final Map givenData = (Map) newData;
54 final String searchPrefix = WizardController.WIZ_DATA_ID + "_";
55 CustomPartHandlerMetadata metadata = (CustomPartHandlerMetadata) getMetadata();
56
57
58 HashMap prunedData = new HashMap(givenData.size());
59 for (Iterator i = givenData.keySet().iterator(); i.hasNext();) {
60 String oneKey = (String) i.next();
61 if (oneKey.startsWith(searchPrefix)) {
62 String val = (String) givenData.get(oneKey);
63
64
65 String realKey = oneKey.substring(searchPrefix.length());
66 try {
67
68
69
70 if (metadata.getCustomHandler().validate(realKey, val)) {
71
72 prunedData.put(realKey, val);
73 }
74 } catch (Exception e) {
75 throw new WizardException(e);
76 }
77
78 }
79 }
80
81
82 List inputList = metadata.getInputList();
83
84
85
86
87
88
89
90
91 ArrayList reviewListForOutputOnly = new ArrayList(inputList.size());
92
93
94 for (Iterator iterator = inputList.iterator(); iterator.hasNext();) {
95 Input input = (Input) iterator.next();
96
97 String key = input.getName();
98
99 String entryVal = (String) prunedData.get(key);
100 if (entryVal != null) {
101 input.setDefaultValue(entryVal);
102 }
103
104
105 String str = input.getLabel() + ": ";
106 String defaultValue = input.getDefaultValue();
107 if (!StringUtil.isBlankOrNull(defaultValue)) {
108 if (input.getType().equals(Input.ATTRIBUTE_DROPDOWN)) {
109
110 List vvs = input.getValidValuesList();
111 for (Iterator iterator1 = vvs.iterator(); iterator1.hasNext();) {
112 ValidValue validValue = (ValidValue) iterator1.next();
113 if (validValue.getKey().equals(defaultValue)) {
114 str += validValue.getDescription();
115 break;
116 }
117 }
118 } else {
119 str += input.getDefaultValue();
120 }
121 }
122
123 if (entryVal == null) {
124 str += " <== EMPTY";
125 }
126
127
128 reviewListForOutputOnly.add(str);
129 }
130
131 super.setData(reviewListForOutputOnly);
132 }
133 }