001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portlet;
023:
024: import org.jboss.portal.api.PortalRuntimeContext;
025: import org.jboss.portal.api.node.PortalNode;
026: import org.jboss.portal.api.node.PortalNodeURL;
027: import org.jboss.portal.common.net.URLTools;
028: import org.jboss.portal.core.aspects.controller.node.Navigation;
029: import org.jboss.portal.core.controller.portlet.SignOutResponse;
030: import org.jboss.portal.portlet.impl.jsr168.api.ActionResponseImpl;
031: import org.jboss.portal.portlet.impl.jsr168.api.PortletRequestImpl;
032: import org.jboss.portal.portlet.invocation.ActionInvocation;
033:
034: import javax.portlet.PortletRequest;
035:
036: /**
037: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
038: * @version $Revision: 8786 $
039: */
040: public class JBossActionResponse extends ActionResponseImpl {
041:
042: public JBossActionResponse(ActionInvocation invocation,
043: PortletRequestImpl preq) {
044: super (invocation, preq);
045: }
046:
047: // /**
048: // * The component wants the user to be authenticated to perform the task.
049: // * After this has been called all subsequent actions should not be
050: // * possible (getWriter()/sendRedirect()/etc...).
051: // *
052: // * @throws IllegalStateException
053: // */
054: // public void sendAuthenticate() throws IllegalStateException
055: // {
056: ///*
057: // if (result instanceof NoResult || result instanceof AuthenticateResult)
058: // {
059: // if (result instanceof NoResult)
060: // {
061: // ServerURL url = PortletUtils.createWindowActionURL(resp, window);
062: // result = new AuthenticateResult(portletWindowContext, url);
063: // }
064: // }
065: // else
066: // {
067: // throw new IllegalStateException("Cannot call send authenticate");
068: // }
069: //*/
070: // }
071:
072: // public void sendBytes(String contentType, byte[] bytes)
073: // {
074: ///*
075: // if (result instanceof NoResult)
076: // {
077: // result = new StreamResult(portletWindowContext, contentType, bytes);
078: // }
079: // else
080: // {
081: // throw new IllegalStateException("Cannot call send bytes");
082: // }
083: //*/
084: // }
085:
086: public PortalNodeURL createActionURL(PortalNode node)
087: throws IllegalArgumentException, IllegalStateException {
088: PortalRuntimeContext context = Navigation
089: .getPortalRuntimeContext();
090:
091: //
092: if (context == null) {
093: throw new IllegalStateException(
094: "Not in a controller context");
095: }
096:
097: //
098: return node.createURL(context);
099: }
100:
101: public PortalNodeURL createRenderURL(PortalNode node)
102: throws IllegalArgumentException, IllegalStateException {
103: PortalRuntimeContext context = Navigation
104: .getPortalRuntimeContext();
105:
106: //
107: if (context == null) {
108: throw new IllegalStateException(
109: "Not in a controller context");
110: }
111:
112: //
113: return node.createURL(context);
114: }
115:
116: /**
117: * Perform a programmatic sign out.
118: *
119: * @throws IllegalStateException if programmatic signout cannot be done
120: */
121: public void signOut() throws IllegalStateException {
122: if (!PortletRequest.FORM_AUTH.equals(preq.getAuthType())) {
123: throw new IllegalStateException(
124: "Cannot perform programmatic signout");
125: }
126: sendRedirect(new SignOutResponse());
127: }
128:
129: /**
130: * Perform a programmatic sign out and navigate to the URL specified by the location parameter.
131: *
132: * @param location URL to redirect to after signout; can be null to indicate default behavior.
133: * @throws IllegalStateException if programmatic signout cannot be done
134: * @throws IllegalArgumentException if the location is not valid
135: */
136: public void signOut(String location) throws IllegalStateException {
137: if (!PortletRequest.FORM_AUTH.equals(preq.getAuthType())) {
138: throw new IllegalStateException(
139: "Cannot perform programmatic signout");
140: }
141: if (location == null) {
142: throw new IllegalArgumentException(
143: "Null location is not accepted");
144: }
145: URLTools.enforceAbsoluteURL(location);
146: sendRedirect(new SignOutResponse(location));
147: }
148: }
|