1 17 package org.alfresco.web.config; 18 19 import java.util.HashMap ; 20 import java.util.List ; 21 22 import org.alfresco.config.ConfigElement; 23 import org.alfresco.config.element.ConfigElementAdapter; 24 import org.alfresco.config.element.GenericConfigElement; 25 26 31 public class NavigationConfigElement extends ConfigElementAdapter 32 { 33 private HashMap <String , NavigationResult> viewIds = new HashMap <String , NavigationResult>(); 34 private HashMap <String , NavigationResult> outcomes = new HashMap <String , NavigationResult>(); 35 36 private boolean kidsPopulated = false; 37 38 41 public NavigationConfigElement() 42 { 43 super("navigation"); 44 } 45 46 51 public NavigationConfigElement(String name) 52 { 53 super(name); 54 } 55 56 59 public List <ConfigElement> getChildren() 60 { 61 64 List <ConfigElement> kids = null; 65 66 if (this.viewIds.size() > 0 || this.outcomes.size() > 0) 67 { 68 if (this.kidsPopulated == false) 69 { 70 for (String fromViewId : this.viewIds.keySet()) 72 { 73 GenericConfigElement ce = new GenericConfigElement(NavigationElementReader.ELEMENT_OVERRIDE); 74 ce.addAttribute(NavigationElementReader.ATTR_FROM_VIEWID, fromViewId); 75 76 NavigationResult navRes = this.viewIds.get(fromViewId); 77 String result = navRes.getResult(); 78 if (navRes.isOutcome()) 79 { 80 ce.addAttribute(NavigationElementReader.ATTR_TO_OUTCOME, result); 81 } 82 else 83 { 84 ce.addAttribute(NavigationElementReader.ATTR_TO_VIEWID, result); 85 } 86 87 this.children.add(ce); 89 } 90 91 for (String fromOutcome : this.outcomes.keySet()) 93 { 94 GenericConfigElement ce = new GenericConfigElement(NavigationElementReader.ELEMENT_OVERRIDE); 95 ce.addAttribute(NavigationElementReader.ATTR_FROM_OUTCOME, fromOutcome); 96 97 NavigationResult navRes = this.outcomes.get(fromOutcome); 98 String result = navRes.getResult(); 99 if (navRes.isOutcome()) 100 { 101 ce.addAttribute(NavigationElementReader.ATTR_TO_OUTCOME, result); 102 } 103 else 104 { 105 ce.addAttribute(NavigationElementReader.ATTR_TO_VIEWID, result); 106 } 107 108 this.children.add(ce); 110 } 111 112 this.kidsPopulated = true; 113 } 114 115 kids = super.getChildren(); 116 } 117 118 return kids; 119 } 120 121 124 public ConfigElement combine(ConfigElement configElement) 125 { 126 NavigationConfigElement combined = new NavigationConfigElement(); 127 128 for (String fromViewId : this.viewIds.keySet()) 130 { 131 combined.addOverride(fromViewId, null, this.viewIds.get(fromViewId)); 132 } 133 134 for (String fromOutcome : this.outcomes.keySet()) 136 { 137 combined.addOverride(null, fromOutcome, this.outcomes.get(fromOutcome)); 138 } 139 140 NavigationConfigElement navCfg = (NavigationConfigElement)configElement; 142 HashMap <String , NavigationResult> viewIds = navCfg.getViewIds(); 143 for (String fromViewId : viewIds.keySet()) 144 { 145 combined.addOverride(fromViewId, null, viewIds.get(fromViewId)); 146 } 147 148 HashMap <String , NavigationResult> outcomes = navCfg.getOutcomes(); 150 for (String fromOutcome : outcomes.keySet()) 151 { 152 combined.addOverride(null, fromOutcome, outcomes.get(fromOutcome)); 153 } 154 155 return combined; 156 } 157 158 163 public HashMap <String , NavigationResult> getViewIds() 164 { 165 return this.viewIds; 166 } 167 168 173 public HashMap <String , NavigationResult> getOutcomes() 174 { 175 return this.outcomes; 176 } 177 178 186 public void addOverride(String fromViewId, String fromOutcome, 187 String toViewId, String toOutcome) 188 { 189 NavigationResult result = new NavigationResult(toViewId, toOutcome); 191 addOverride(fromViewId, fromOutcome, result); 192 } 193 194 201 public void addOverride(String fromViewId, String fromOutcome, 202 NavigationResult result) 203 { 204 if (fromViewId != null && fromOutcome != null) 205 { 206 throw new IllegalStateException ("You can not have both a from-view-id and from-outcome"); 207 } 208 209 if (fromViewId != null) 210 { 211 this.viewIds.put(fromViewId, result); 212 } 213 else if (fromOutcome != null) 214 { 215 this.outcomes.put(fromOutcome, result); 216 } 217 } 218 219 230 public NavigationResult getOverride(String fromViewId, String fromOutcome) 231 { 232 NavigationResult result = null; 233 234 if (fromOutcome != null) 236 { 237 result = this.outcomes.get(fromOutcome); 238 } 239 else if (fromViewId != null) 240 { 241 result = this.viewIds.get(fromViewId); 242 } 243 244 return result; 245 } 246 } 247 | Popular Tags |