1 9 package org.jboss.portal.portlet.impl; 10 11 import java.io.IOException ; 12 import java.util.Map ; 13 14 import javax.portlet.ActionResponse; 15 import javax.portlet.PortletMode; 16 import javax.portlet.PortletModeException; 17 import javax.portlet.WindowState; 18 import javax.portlet.WindowStateException; 19 20 import org.jboss.portal.server.PortalRequest; 21 import org.jboss.portal.server.PortalResponse; 22 import org.jboss.portal.server.Window; 23 import org.jboss.portal.server.WindowContext; 24 import org.jboss.portal.server.output.ActionResult; 25 import org.jboss.portal.server.output.HTTPRedirectionResult; 26 import org.jboss.portal.server.output.NoResult; 27 import org.jboss.portal.server.output.Result; 28 import org.jboss.portal.server.plugins.mode.Mode; 29 import org.jboss.portal.server.util.Properties; 30 import org.apache.log4j.Logger; 31 32 36 public class ActionResponseImpl extends PortletResponseImpl implements ActionResponse 37 { 38 39 private static final Logger log = Logger.getLogger(ActionResponseImpl.class); 40 41 protected WindowContext portletWindowContext; 42 protected Result result; 43 protected Window window; 44 45 public Result getResult() 46 { 47 return result; 48 } 49 50 public ActionResponseImpl( 51 WindowContext portletWindowContext, 52 Window window, 53 PortalRequest req, 54 PortalResponse resp, 55 Properties properties) 56 { 57 super(req, resp, properties); 58 this.window = window; 59 this.portletWindowContext = portletWindowContext; 60 this.result = new NoResult(portletWindowContext); 61 } 62 63 public void setWindowState(WindowState windowState) throws WindowStateException 64 { 65 if (result instanceof NoResult || result instanceof ActionResult) 66 { 67 if (!window.isSupportedWindowState(org.jboss.portal.server.plugins.windowstate.WindowState.create(windowState.toString()))) 68 { 69 throw new WindowStateException("Not supported", windowState); 70 } 71 if (result instanceof NoResult) 72 { 73 result = new ActionResult(portletWindowContext); 74 } 75 ((ActionResult)result).setWindowState(org.jboss.portal.server.plugins.windowstate.WindowState.create(windowState.toString())); 76 } 77 else 78 { 79 throw new IllegalStateException ("Window state cannot be set after redirect"); 80 } 81 } 82 83 public void setPortletMode(PortletMode portletMode) throws PortletModeException 84 { 85 if (result instanceof NoResult || result instanceof ActionResult) 86 { 87 if (portletMode == null) 88 { 89 log.warn("Set null portlet mode"); 92 } 93 else 94 { 95 if (!window.isSupportedMode(resp.getContentType(), Mode.create(portletMode.toString()))) 96 { 97 throw new PortletModeException("Not supported", portletMode); 98 } 99 if (result instanceof NoResult) 100 { 101 result = new ActionResult(portletWindowContext); 102 } 103 Mode mode = Mode.create(portletMode.toString()); 104 ((ActionResult)result).setMode(mode); 105 } 106 } 107 else 108 { 109 throw new IllegalStateException ("Portlet mode cannot be set after redirect"); 110 } 111 } 112 113 public void sendRedirect(String location) throws IOException 114 { 115 if (result instanceof NoResult || result instanceof HTTPRedirectionResult) 116 { 117 if (location == null) 118 { 119 return; 121 } 122 if (!location.startsWith("http://") && !location.startsWith("/")) 123 { 124 throw new IllegalArgumentException ("No relative urls are accepted"); 125 } 126 result = new HTTPRedirectionResult(portletWindowContext, location); 127 } 128 else 129 { 130 throw new IllegalStateException ("sendRedirect cannot be called after " + 131 "setPortletMode/setWindowState/setRenderParameter/setRenderParameters " + 132 "has been called previously"); 133 } 134 } 135 136 public void setRenderParameters(Map map) 137 { 138 if (result instanceof NoResult || result instanceof ActionResult) 139 { 140 if (result instanceof NoResult) 141 { 142 result = new ActionResult(portletWindowContext); 143 } 144 ((ActionResult)result).setRenderParameters(map); 145 } 146 else 147 { 148 throw new IllegalStateException ("setRenderParameters cannot be called after redirect"); 149 } 150 } 151 152 public void setRenderParameter(String name, String value) 153 { 154 if (result instanceof NoResult || result instanceof ActionResult) 155 { 156 if (result instanceof NoResult) 157 { 158 result = new ActionResult(portletWindowContext); 159 } 160 ((ActionResult)result).setRenderParameter(name, value); 161 } 162 else 163 { 164 throw new IllegalStateException ("setRenderParameter cannot be called after redirect"); 165 } 166 } 167 168 public void setRenderParameter(String name, String [] values) 169 { 170 if (result instanceof NoResult || result instanceof ActionResult) 171 { 172 if (result instanceof NoResult) 173 { 174 result = new ActionResult(portletWindowContext); 175 } 176 ((ActionResult)result).setRenderParameter(name, values); 177 } 178 else 179 { 180 throw new IllegalStateException ("setRenderParameter cannot be called after redirect"); 181 } 182 } 183 } 184 | Popular Tags |