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.portal.test.theme;
023:
024: import org.jboss.portal.test.theme.model.RenderedObject;
025:
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028: import java.util.Collections;
029: import java.util.Enumeration;
030: import java.util.HashMap;
031: import java.util.Map;
032: import java.util.Set;
033:
034: /**
035: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
036: * @version $Revision: 8784 $
037: */
038: public class RequestContext {
039:
040: /** . */
041: public static final int ACTION_PHASE = 0;
042:
043: /** . */
044: public static final int RENDER_PHASE = 0;
045:
046: /** . */
047: private final RenderedObject target;
048:
049: /** . */
050: private final TestPhase phase;
051:
052: /** . */
053: private final boolean async;
054:
055: /** . */
056: final HttpServletRequest request;
057:
058: /** . */
059: final HttpServletResponse response;
060:
061: /** . */
062: final Map parameters;
063:
064: public RequestContext(RenderedObject target, TestPhase phase,
065: HttpServletRequest request, HttpServletResponse response) {
066: boolean async = "true".equals(request.getHeader("ajax"));
067: Map parameters = new HashMap();
068: for (Enumeration e = request.getParameterNames(); e
069: .hasMoreElements();) {
070: String name = (String) e.nextElement();
071: String value = request.getParameter(name);
072: parameters.put(name, value);
073: }
074:
075: //
076: this .target = target;
077: this .phase = phase;
078: this .request = request;
079: this .response = response;
080: this .async = async;
081: this .parameters = Collections.unmodifiableMap(parameters);
082: }
083:
084: public String getParameter(String name) {
085: return (String) parameters.get(name);
086: }
087:
088: public Set getParameterNames() {
089: return parameters.keySet();
090: }
091:
092: public Map getParameterMap() {
093: return parameters;
094: }
095:
096: public RenderedObject getTarget() {
097: return target;
098: }
099:
100: public boolean isAsync() {
101: return async;
102: }
103:
104: public TestPhase getPhase() {
105: return phase;
106: }
107:
108: public void end() {
109: }
110:
111: /** @throws IllegalArgumentException if the provided object is null */
112: public ObjectURL createURL(RenderedObject obj)
113: throws IllegalArgumentException {
114: if (obj == null) {
115: throw new IllegalArgumentException("No object provided");
116: }
117: return new ObjectURL(obj, this);
118: }
119: }
|