1 64 65 package com.jcorporate.expresso.core.controller; 66 67 import com.jcorporate.expresso.core.ExpressoConstants; 68 import com.jcorporate.expresso.core.misc.ConfigManager; 69 import com.jcorporate.expresso.core.misc.StringDOMParser; 70 import com.jcorporate.expresso.core.misc.StringUtil; 71 import com.jcorporate.expresso.core.misc.URLUTF8Encoder; 72 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 73 import org.apache.log4j.Logger; 74 import org.apache.struts.config.ActionConfig; 75 import org.w3c.dom.Document ; 76 import org.w3c.dom.NamedNodeMap ; 77 import org.w3c.dom.Node ; 78 import org.w3c.dom.NodeList ; 79 80 import javax.servlet.RequestDispatcher ; 81 import javax.servlet.http.HttpServletRequest ; 82 import javax.servlet.http.HttpServletResponse ; 83 import java.io.IOException ; 84 import java.util.Enumeration ; 85 import java.util.Hashtable ; 86 import java.util.Map ; 87 import java.util.Vector ; 88 89 90 120 public class Transition 121 extends ControllerElement 122 implements Cloneable , 123 java.io.Serializable { 124 125 private static Logger log = Logger.getLogger(Transition.class); 126 127 130 private String ownerObject = null; 131 132 135 private String controllerObject = null; 136 137 140 private Hashtable params = new Hashtable (1); 141 private String myState = null; 142 private boolean returnToSender = false; 143 144 148 private transient String cacheParamStringSansController = null; 149 150 154 private transient String cacheParamStringWithController = null; 155 156 157 160 private transient HttpServletResponse servletResponse = null; 161 162 165 public Transition() { 166 } 167 168 175 public Transition(String newState, Controller myController) { 176 177 String className = myController.getClass().getName(); 181 myState = newState; 182 setControllerObject(className); 183 setOwnerController(className); 184 setName(newState); 185 186 Hashtable allstates = myController.getStates(); 191 State theState = null; 192 if (allstates != null) { 193 theState = (State) allstates.get(newState); 194 } 195 196 if (theState == null) { 197 throw new IllegalArgumentException ("No such state as '" + 198 newState + "' in controller '" + 199 className + 200 "'"); 201 } 202 203 setLabel(theState.getDescription()); 204 addParam(Controller.STATE_PARAM_KEY, newState); 205 } 206 207 214 public Transition(String newLabel, String newObject) { 215 super(); 216 setName(StringUtil.replace(newLabel, " ", "")); 217 setLabel(newLabel); 218 setControllerObject(newObject); 219 } 220 221 229 public Transition(String newName, String newLabel, String newObject) { 230 super(); 231 setName(newName); 232 setLabel(newLabel); 233 setControllerObject(newObject); 234 } 235 236 244 public Transition(String name, 245 String label, 246 Class controllerClass, 247 String controllerState) { 248 super(); 249 setName(name); 250 setLabel(label); 251 setControllerObject(controllerClass); 252 setState(controllerState); 253 } 254 255 263 public Transition(String label, 264 Class controllerClass, 265 String controllerState) { 266 super(); 267 setName(controllerState); 268 setLabel(label); 269 setControllerObject(controllerClass); 270 setState(controllerState); 271 } 272 273 281 public synchronized void addParam(String paramCode, String paramValue) { 282 clearCache(); 283 if (paramCode.equals(Controller.STATE_PARAM_KEY)) { 284 setState(StringUtil.notNull(paramValue)); 285 286 return; 287 } 288 if (paramCode.equals(Controller.CONTROLLER_PARAM_KEY)) { 289 setControllerObject(StringUtil.notNull(paramValue)); 290 291 return; 292 } 293 294 params.put(paramCode, StringUtil.notNull(paramValue)); 295 } 296 297 private synchronized void clearCache() { 298 cacheParamStringWithController = null; 299 cacheParamStringSansController = null; 300 } 301 302 307 public synchronized void setState(String newState) { 308 clearCache(); 309 myState = newState; 310 } 311 312 317 public String getState() { 318 if (myState == null) { 319 return getParam(Controller.STATE_PARAM_KEY); 320 } 321 322 return myState; 323 } 324 325 332 public Object clone() 333 throws CloneNotSupportedException { 334 Transition t; 335 336 synchronized (this) { 337 t = (Transition) super.clone(); 338 t.params = (Hashtable ) params.clone(); 339 t.controllerObject = controllerObject; 340 t.myState = myState; 341 t.returnToSender = returnToSender; 342 } 343 344 return t; 345 } 346 347 364 public void enableReturnToSender(ControllerResponse response) 365 throws ControllerException { 366 returnToSender = true; 367 String returnToSender = null; 368 if (response != null) { 369 FastStringBuffer fsb = FastStringBuffer.getInstance(); 370 try { 371 Transition t = response.getCurrentState().getReturnToSender(); 372 returnToSender = t.toXML(fsb).toString(); 373 } finally { 374 fsb.release(); 375 fsb = null; 376 } 377 378 if (isExternalTransition(response.getControllerClass())) { 379 if (getParam(Controller.CTL_SUCC_TRAN) == null) { addParam(Controller.CTL_SUCC_TRAN, returnToSender); 381 } 382 } else { 383 if (getParam(Controller.STATE_SUCC_TRAN) == null) { addParam(Controller.STATE_SUCC_TRAN, returnToSender); 385 } 386 } 387 } 388 } 389 390 400 public boolean isExternalTransition(String runningController) { 401 if (controllerObject == null || controllerObject.equals(runningController)) { 402 return false; 403 } else { 404 return true; 405 } 406 } 407 408 416 public String getControllerObject() { 417 if (controllerObject == null) { 418 return getParam(Controller.CONTROLLER_PARAM_KEY); 419 } 420 421 return controllerObject; 422 } 423 424 430 public String getOwnerController() { 431 return this.ownerObject; 432 } 433 434 440 public String getParam(String paramCode) { 441 return (String ) params.get(paramCode); 442 } 443 444 451 public Hashtable getParams() { 452 return params; 453 } 454 455 460 public synchronized String getParamString(boolean includeControllerParameter) { 461 if (includeControllerParameter && cacheParamStringWithController == null) { 462 FastStringBuffer paramString = FastStringBuffer.getInstance(); 463 try { 464 if (controllerObject != null) { 465 paramString.append("controller="); 466 paramString.append(controllerObject); 467 } 468 469 addNonControllerParams(paramString); 470 471 cacheParamStringWithController = paramString.toString(); 472 } finally { 473 paramString.release(); 474 paramString = null; 475 } 476 477 } 478 479 if (!includeControllerParameter && cacheParamStringSansController == null) { 480 FastStringBuffer paramString = FastStringBuffer.getInstance(); 481 try { 482 addNonControllerParams(paramString); 483 484 cacheParamStringSansController = paramString.toString(); 485 } finally { 486 paramString.release(); 487 paramString = null; 488 } 489 490 } 491 492 493 if (includeControllerParameter) { 494 return cacheParamStringWithController; 495 } else { 496 return cacheParamStringSansController; 497 } 498 499 } 500 501 private void addNonControllerParams(FastStringBuffer paramString) { 502 if (this.params != null) { 503 if (!this.params.isEmpty()) { 504 String oneKey = null; 505 506 for (Enumeration e = this.params.keys(); e.hasMoreElements();) { 507 if (paramString.length() != 0) { 508 paramString.append("&"); 509 } 510 oneKey = (String ) e.nextElement(); 511 512 FastStringBuffer fsb = FastStringBuffer.getInstance(); 515 try { 516 fsb.append(oneKey); 517 fsb.append("="); 518 fsb.append(URLUTF8Encoder.encode((String ) this.params.get(oneKey))); 519 paramString.append(fsb.toString()); 520 } finally { 521 fsb.release(); 522 fsb = null; 523 } 524 525 } 526 } 527 } 528 529 String stateString = StringUtil.notNull(getState()); 530 if (stateString.length() != 0) { 531 if (paramString.length() != 0) { 532 paramString.append("&"); 533 } 534 paramString.append("state="); 535 paramString.append(stateString); 536 } 537 } 538 539 545 public String getParamString() { 546 547 return getParamString(true); 548 549 } 550 551 566 protected ControllerResponse newStateDispatch(ControllerRequest request) 567 throws ControllerException, 568 NonHandleableException { 569 ServletControllerRequest servletRequest = (ServletControllerRequest) request; 570 HttpServletRequest httpRequest = (HttpServletRequest ) servletRequest.getServletRequest(); 571 HttpServletResponse httpResponse = (HttpServletResponse ) servletRequest.getServletResponse(); 572 ActionConfig ac = ConfigManager.getActionConfig("", controllerObject, ""); 576 577 if (ac == null) { 578 throw new ControllerException("Cannot transition to controller: " + 579 controllerObject + 580 " controller not defined in Struts configuration"); 581 } 582 583 String apath = ac.getPath(); 584 FastStringBuffer newURL = FastStringBuffer.getInstance(); 585 RequestDispatcher dispatcher = null; 586 try { 587 newURL.append(apath); 588 newURL.append(".do"); 589 newURL.append("?controller=" + getControllerObject()); 590 591 if (getState() != null) { 592 newURL.append("&state=" + getState()); 593 } 594 595 httpRequest.setAttribute(ExpressoConstants.CONTROLLER_REQUEST_KEY, request); 597 String urlValue = newURL.toString(); 598 dispatcher = httpRequest.getRequestDispatcher(urlValue); 599 600 if (dispatcher == null) { 601 throw new ControllerException("Request dispatcher was null - cannot include URL '" + 602 urlValue + "'"); 603 } 604 } finally { 605 newURL.release(); 606 newURL = null; 607 } 608 try { 609 dispatcher.include(httpRequest, httpResponse); 610 } catch (Exception e) { 611 throw new ControllerException(e); 612 } 613 614 Exception newStateException = (Exception ) httpRequest.getAttribute(ExpressoConstants.NEWSTATE_EXCEPTION_KEY); 616 617 if (newStateException != null) { if (newStateException instanceof ControllerException) { 619 throw (ControllerException) newStateException; 620 } else { 621 if (newStateException instanceof NonHandleableException) { 622 throw (NonHandleableException) newStateException; 623 } else { 624 throw (RuntimeException ) newStateException; 625 } 626 } 627 } 628 629 request = (ControllerRequest) httpRequest.getAttribute(ExpressoConstants.CONTROLLER_REQUEST_KEY); 630 httpRequest.removeAttribute(ExpressoConstants.CONTROLLER_REQUEST_KEY); 631 632 ControllerResponse response = (ControllerResponse) httpRequest.getAttribute( 633 ExpressoConstants.CONTROLLER_RESPONSE_KEY); 634 httpRequest.removeAttribute(ExpressoConstants.CONTROLLER_RESPONSE_KEY); 635 636 return response; 637 } 638 639 648 public boolean isRecursiveTransition(String runningState, 649 String runningController) { 650 String targetController = StringUtil.notNull(controllerObject); 651 String targetState = StringUtil.notNull(myState); 652 653 if (targetController.equals(runningController) && 654 targetState.equals(runningState)) { 655 return true; 656 } 657 658 return false; 659 } 660 661 666 public boolean isReturnToSenderEnabled() { 667 return returnToSender; 668 } 669 670 679 public String getHTMLParamString() { 680 String paramString = this.getParamString(); 681 paramString = URLUTF8Encoder.encode(paramString); 682 683 689 FastStringBuffer sb = FastStringBuffer.getInstance(); 690 String returnValue = null; 691 try { 692 sb.append("<input type=\"HIDDEN\" name=\""); 693 sb.append(this.getName()); 694 sb.append("_params"); 695 sb.append("\" value=\""); 696 sb.append(paramString); 697 sb.append("\">"); 698 sb.append("<input type=\"HIDDEN\" name=\""); 699 sb.append(this.getName()); 700 sb.append("_encoding"); 701 sb.append("\" value=\"u\">"); 702 returnValue = sb.toString(); 703 } finally { 704 sb.release(); 705 sb = null; 706 } 707 return returnValue; 708 } 709 710 715 public synchronized void setControllerObject(String newObject) { 716 clearCache(); 717 controllerObject = newObject; 718 } 719 720 730 public synchronized void setControllerObject(Class c) { 731 clearCache(); 732 if (c != null) { 733 setControllerObject(c.getName()); 734 } else { 735 setControllerObject((String ) null); 736 } 737 } 738 739 745 public synchronized void setOwnerController(String newController) { 746 clearCache(); 747 ownerObject = newController; 748 } 749 750 755 public synchronized void setParams(Hashtable newParams) { 756 clearCache(); 757 params = new Hashtable (newParams); 758 } 759 760 768 public synchronized void setReturnToSenderParms(ControllerRequest newReturnToSenderRequest) { 769 clearCache(); 770 String oneParamName = null; 771 Object oneParamValue = null; 772 Hashtable params = newReturnToSenderRequest.getParameters(); 773 Hashtable newParams = new Hashtable (); 774 775 for (Enumeration e = params.keys(); e.hasMoreElements();) { 781 oneParamName = (String ) e.nextElement(); 782 783 if (!oneParamName.endsWith("_params") && 784 !oneParamName.endsWith("_encoding") && 785 !oneParamName.equals(Controller.STATE_PARAM_KEY) && 786 !oneParamName.equals(Controller.CONTROLLER_PARAM_KEY)) { 787 oneParamValue = params.get(oneParamName); 788 newParams.put(oneParamName, oneParamValue); 789 } 790 } 791 792 setParams(newParams); 793 } 794 795 801 public FastStringBuffer toXML(FastStringBuffer stream) { 802 stream.append("<transition"); 803 804 if (this.getName() != null && this.getName().length() > 0) { 805 stream.append(" name=\""); 806 stream.append(StringUtil.xmlEscape(getName())); 807 stream.append("\""); 808 } 809 810 String controllerName = this.getControllerObject(); 811 812 if (controllerName != null && controllerName.length() > 0) { 813 stream.append(" controller=\""); 814 stream.append(StringUtil.xmlEscape(controllerName)); 815 stream.append("\""); 816 } 817 818 String stateName = this.getState(); 819 820 if (stateName != null && stateName.length() > 0) { 821 stream.append(" state=\""); 822 stream.append(StringUtil.xmlEscape(stateName)); 823 stream.append("\""); 824 } 825 826 stream.append(">\n"); 827 828 Hashtable params = this.getParams(); 829 String oneKey = null; 830 831 if (!params.isEmpty()) { 832 stream.append("\t<transition-parameters>\n"); 833 834 for (Enumeration ap = params.keys(); ap.hasMoreElements();) { 835 oneKey = (String ) ap.nextElement(); 836 stream.append("\t\t<transition-param name=\""); 837 stream.append(StringUtil.xmlEscape(oneKey)); 838 stream.append("\" value=\""); 839 stream.append(StringUtil.xmlEscape((String ) params.get(oneKey))); 840 stream.append("\"/>\n"); 841 } 842 843 stream.append("\t</transition-parameters>\n"); 844 } 845 846 stream = super.toXML(stream); 847 stream.append("</transition>\n"); 848 849 return stream; 850 } 851 852 859 public static Transition fromXML(String newTransition) 860 throws ControllerException { 861 StringDOMParser parser = new StringDOMParser(); 862 Document d = parser.parseString(newTransition); 863 864 if (d == null) { 865 throw new ControllerException("Transition returned mal-formed XML document"); 866 } else { 867 parser.dumpDOM(d); 868 } 869 870 return (Transition) fromXML(d); 871 } 872 873 880 public static ControllerElement fromXML(Node n) 881 throws ControllerException { 882 883 if (n.getNodeName().equals("#document")) { 885 return fromXML(n.getChildNodes().item(0)); 886 } 887 if (!n.getNodeName().equals("transition")) { 888 return null; 889 } 890 891 Transition t = new Transition(); 892 893 NamedNodeMap transitionAttributes = n.getAttributes(); 895 Node attributeNode = transitionAttributes.getNamedItem("name"); 896 897 if (attributeNode != null) { 898 String value = attributeNode.getNodeValue(); 899 900 if (value != null) { 901 t.setName(value); 902 } 903 } 904 905 attributeNode = transitionAttributes.getNamedItem(Controller.CONTROLLER_PARAM_KEY); 906 907 if (attributeNode != null) { 908 String value = attributeNode.getNodeValue(); 909 910 if (value != null) { 911 t.setControllerObject(value); 912 } 913 } 914 915 NodeList nl = n.getChildNodes(); 916 917 for (int i = 0; i < nl.getLength(); i++) { 918 Node oneChild = nl.item(i); 919 String nodeName = oneChild.getNodeName(); 920 921 if (nodeName.equals("transition-parameters")) { 922 NodeList parameters = oneChild.getChildNodes(); 923 924 for (int j = 0; j < parameters.getLength(); j++) { 925 if (parameters.item(j).getNodeName().equals("transition-param")) { 926 NamedNodeMap paramAttributes = parameters.item(j).getAttributes(); 927 Node paramAttribute = paramAttributes.getNamedItem("name"); 928 String name = null; 929 String value = null; 930 931 if (paramAttribute != null) { 932 name = paramAttribute.getNodeValue(); 933 } 934 935 paramAttribute = paramAttributes.getNamedItem("value"); 936 937 if (paramAttribute != null) { 938 value = paramAttribute.getNodeValue(); 939 } 940 if (name != null && value != null) { 941 t.addParam(name, value); 942 } 943 } 944 } 945 } else if (nodeName.equals("controller-element")) { 946 t = (Transition) ControllerElement.fromXML(oneChild, t); 947 } 948 } 949 950 return t; 951 } 952 953 963 public String getTheUrl(boolean resolveControllerReference) throws ControllerException { 964 String returnValue = null; 965 FastStringBuffer fsb = FastStringBuffer.getInstance(); 966 try { 967 String paramString = ""; 968 969 if (resolveControllerReference 970 && this.getControllerObject() != null 971 && this.getControllerObject().length() > 0) { 972 973 try { 975 fsb.append(getMapping()); 976 } catch (Exception e) { 977 ControllerResponse myResponse = getControllerResponse(); 979 980 if (myResponse == null) { 981 throw new ControllerException( 982 "No controller object, nor controller response object available - cannot build URL"); 983 } 984 985 fsb.clear(); 986 fsb.append(myResponse.getRequestPath()); 987 } 988 989 paramString = getParamString(false); 990 991 } else { 992 993 ControllerResponse myResponse = getControllerResponse(); 995 996 if (myResponse == null) { 997 try { 998 fsb.append(getMapping()); 999 } catch (Exception e) { 1000 throw new ControllerException( 1001 "No controller param nor ControllerResponse available - cannot build URL"); 1002 } 1003 } else { 1004 fsb.append(myResponse.getRequestPath()); 1005 } 1006 1007 paramString = getParamString(true); 1008 } 1009 1010 if (paramString != null && paramString.length() > 0) { 1011 fsb.append("?"); 1012 fsb.append(paramString); 1013 } 1014 1015 returnValue = fsb.toString(); 1016 if (log.isDebugEnabled()) { 1017 log.debug("transition redirects to: " + returnValue); 1018 } 1019 } finally { 1020 fsb.release(); 1021 fsb = null; 1022 } 1023 return returnValue; 1024 } 1025 1026 1033 public String getUrl() 1034 throws ControllerException { 1035 return getTheUrl(true); 1036 } 1037 1038 1052 public String getFullUrl() throws ControllerException { 1053 HttpServletResponse servResponse = this.getServletResponse(); 1054 if (servResponse != null) { 1055 return servResponse.encodeURL(ConfigManager.getContextPath() + getTheUrl(true)); 1056 } else { 1057 return ConfigManager.getContextPath() + getTheUrl(true); 1058 } 1059 } 1060 1061 1067 public String getMapping() throws ControllerException { 1068 ActionConfig actionConfig = ConfigManager.getActionConfig("", 1069 this.getControllerObject(), this.getState()); 1070 if (actionConfig == null) { 1071 throw new ControllerException("Unable to locate action mapping for: " 1072 + this.getControllerObject() 1073 + " and state " + this.getState()); 1074 } 1075 return actionConfig.getPath() + ".do"; 1076 } 1077 1078 1079 1091 public ControllerResponse transition(ControllerRequest req, 1092 ControllerResponse res) 1093 throws ControllerException, 1094 NonHandleableException { 1095 return transition(req, res, true); 1096 } 1097 1098 1109 public void redirectTransition(ControllerRequest request, 1110 ControllerResponse response) throws ControllerException { 1111 try { 1112 1113 if (isRecursiveTransition(response.getCurrentState().getName(), 1114 response.getControllerClass())) { 1115 throw new ControllerException("State cannot transition to itself."); 1116 } 1117 1118 if (this.getControllerObject() == null) { 1119 throw new ControllerException("Transition.redirectTransition(): " 1120 + " controller object parameter must be set before calling this function"); 1121 } 1122 1123 if (!(request instanceof ServletControllerRequest)) { 1124 log.error("Cannot redirect transition in a non-servlet environment. " + 1125 "Transitioning normally instead"); 1126 try { 1127 this.transition(request, response); 1128 } catch (NonHandleableException ex) { 1129 log.error("Non Handleable Exception during transition", ex); 1130 throw new ControllerException(ex); 1131 } 1132 return; 1133 } 1134 1135 ServletControllerRequest scr = (ServletControllerRequest) request; 1136 HttpServletResponse hserv = (HttpServletResponse ) scr.getServletResponse(); 1137 this.setControllerResponse(response); 1138 1139 1140 ActionConfig actionConfig = ConfigManager.getActionConfig("", 1143 this.getControllerObject(), this.getState()); 1144 response.setRequestPath(actionConfig.getPath()); 1145 1146 hserv.sendRedirect(((HttpServletRequest ) scr.getServletRequest()).getContextPath() + this.getTheUrl(true)); 1147 response.setCustomResponse(true); 1151 } catch (IOException ex) { 1152 log.error("IO Error sending HTTP Redirect. Connection was broken.", ex); 1153 } 1154 } 1155 1156 1157 1182 public ControllerResponse transition(ControllerRequest req, 1183 ControllerResponse res, boolean clear) 1184 throws ControllerException, 1185 NonHandleableException { 1186 if (isRecursiveTransition(res.getCurrentState().getName(), 1187 res.getControllerClass())) { 1188 throw new ControllerException("State cannot transition to itself."); 1189 } 1190 1191 boolean externalTransition = isExternalTransition(res.getControllerClass()); 1192 req.setParameters(null); 1194 1195 if (returnToSender) { 1197 enableReturnToSender(res); 1198 } 1199 1200 String oneParamKey = null; 1201 String oneParamValue = null; 1202 1203 for (Enumeration ep = params.keys(); ep.hasMoreElements();) { 1204 oneParamKey = (String ) ep.nextElement(); 1205 oneParamValue = (String ) params.get(oneParamKey); 1206 1207 if (oneParamValue != null) { 1208 req.setParameter(oneParamKey, oneParamValue); 1209 } 1210 } 1211 1212 ControllerRequest newRequest = (ControllerRequest) req.clone(); 1213 newRequest.setParameters(this.params); 1214 newRequest.setParameter(Controller.STATE_PARAM_KEY, StringUtil.notNull(this.getState())); 1215 newRequest.setParameter(Controller.CONTROLLER_PARAM_KEY, this.getControllerObject()); 1216 1217 ControllerResponse newResponse = null; 1218 1219 if ((externalTransition) && 1220 (req instanceof ServletControllerRequest)) { 1221 newResponse = newStateDispatch(req); 1222 } else { 1223 Controller c = null; 1224 1225 if (this.getControllerObject() == null) { 1226 c = ConfigManager.getControllerFactory().getController(newRequest); 1227 } else { 1228 c = ConfigManager.getControllerFactory().getController(this.getControllerObject()); 1229 } 1230 1231 newResponse = c.newState(getState(), newRequest); 1232 } 1233 if (clear) { 1234 res.clearOutputCache(); 1235 res.clearInputCache(); 1236 res.clearTransitionCache(); 1237 res.clearBlockCache(); 1238 res.clearAttributes(); 1239 } 1240 1241 res.setDBName(newResponse.getDBName()); 1242 res.setCustomResponse(newResponse.isCustomResponse()); 1243 res.setCurrentState(newResponse.getCurrentState()); 1244 res.setStyle(newResponse.getStyle()); 1245 res.setControllerClass(newResponse.getControllerClass()); 1246 res.setSchemaStack(newResponse.getSchemaStack()); 1247 res.setTitle(newResponse.getTitleKey()); 1248 1249 Block oneBlock = null; 1250 Vector newBlocks = newResponse.getBlocks(); 1251 1252 if (newBlocks != null) { 1253 for (Enumeration eb = newBlocks.elements(); eb.hasMoreElements();) { 1254 oneBlock = (Block) eb.nextElement(); 1255 oneBlock.setControllerResponse(res); 1256 res.addBlock(oneBlock); 1257 } 1258 } 1259 1260 Output oneOutput = null; 1261 Vector newOutputs = newResponse.getOutputs(); 1262 1263 if (newOutputs != null) { 1264 for (Enumeration eo = newOutputs.elements(); eo.hasMoreElements();) { 1265 oneOutput = (Output) eo.nextElement(); 1266 oneOutput.setControllerResponse(res); 1267 res.addOutput(oneOutput); 1268 } 1269 } 1270 1271 Input oneInput = null; 1272 Vector newInputs = newResponse.getInputs(); 1273 1274 if (newInputs != null) { 1275 for (Enumeration ei = newInputs.elements(); ei.hasMoreElements();) { 1276 oneInput = (Input) ei.nextElement(); 1277 oneInput.setControllerResponse(res); 1278 res.addInput(oneInput); 1279 } 1280 } 1281 1282 Transition oneTransition = null; 1283 Vector newTransitions = newResponse.getTransitions(); 1284 1285 if (newTransitions != null) { 1286 for (Enumeration et = newTransitions.elements(); 1287 et.hasMoreElements();) { 1288 oneTransition = (Transition) et.nextElement(); 1289 oneTransition.setControllerResponse(res); 1290 res.addTransition(oneTransition); 1291 } 1292 } 1293 if (StringUtil.notNull(res.getControllerClass()).length() == 0) { 1294 res.setControllerClass(getControllerObject()); 1295 } 1296 1297 Map attributes = newResponse.getAttributes(); 1298 if (attributes != null) { 1299 res.setAttributes(attributes); 1300 } 1301 1302 return res; 1303 } 1304 1305 1311 public HttpServletResponse getServletResponse() { 1312 return servletResponse; 1313 } 1314 1315 1322 public void setServletResponse(HttpServletResponse servletResponse) { 1323 this.servletResponse = servletResponse; 1324 } 1325 1326 1332 public synchronized void setControllerResponse(ControllerResponse newResponse) { 1333 super.setControllerResponse(newResponse); 1334 if (newResponse == null) { 1335 log.warn("Null 'newReponse'"); 1336 return; 1337 } 1338 if (newResponse.getRequest() != null && (newResponse.getRequest() instanceof ServletControllerRequest)) { 1339 1340 this.setServletResponse( 1341 (HttpServletResponse ) ((ServletControllerRequest) newResponse.getRequest()).getServletResponse()); 1342 } 1343 } 1344} 1345 | Popular Tags |