001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/shared/control/servlet/SakaiComponentDispatchServlet.java $
003: * $Id: SakaiComponentDispatchServlet.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.shared.control.servlet;
021:
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Map;
025:
026: import javax.servlet.ServletConfig;
027: import javax.servlet.ServletException;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030:
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033: import org.sakaiproject.component.cover.ComponentManager;
034: import org.sakaiproject.metaobj.shared.model.Agent;
035: import org.sakaiproject.metaobj.shared.model.Artifact;
036: import org.sakaiproject.metaobj.shared.model.Id;
037: import org.sakaiproject.metaobj.shared.model.IdImpl;
038: import org.sakaiproject.metaobj.shared.model.OspException;
039: import org.sakaiproject.tool.api.Session;
040: import org.sakaiproject.tool.api.ToolSession;
041: import org.sakaiproject.tool.cover.SessionManager;
042: import org.springframework.web.servlet.DispatcherServlet;
043:
044: public class SakaiComponentDispatchServlet extends DispatcherServlet {
045:
046: private class SimpleAgent2 implements Agent {
047:
048: String uid = "";
049: String eid = "";
050:
051: SimpleAgent2(String eid, String uid) {
052: this .eid = eid;
053: this .uid = uid;
054: }
055:
056: public Id getId() {
057: return new IdImpl(uid, null);
058: }
059:
060: public Id getEid() {
061: return new IdImpl(eid, null);
062: }
063:
064: public Artifact getProfile() {
065: return null; //To change body of implemented methods use File | Settings | File Templates.
066: }
067:
068: public Object getProperty(String key) {
069: return null; //To change body of implemented methods use File | Settings | File Templates.
070: }
071:
072: public String getDisplayName() {
073: return this .uid;
074: }
075:
076: public boolean isInRole(String role) {
077: return false; //To change body of implemented methods use File | Settings | File Templates.
078: }
079:
080: public boolean isInitialized() {
081: return false; //To change body of implemented methods use File | Settings | File Templates.
082: }
083:
084: public String getRole() {
085: return null; //To change body of implemented methods use File | Settings | File Templates.
086: }
087:
088: public List getWorksiteRoles(String worksiteId) {
089: return null; //To change body of implemented methods use File | Settings | File Templates.
090: }
091:
092: public List getWorksiteRoles() {
093: return null; //To change body of implemented methods use File | Settings | File Templates.
094: }
095:
096: public boolean isRole() {
097: return false;
098: }
099:
100: public String getName() {
101: return null; //To change body of implemented methods use File | Settings | File Templates.
102: }
103: };
104:
105: protected final transient Log logger = LogFactory
106: .getLog(getClass());
107: public static final String TOOL_STATE_VIEW_KEY = "osp.tool.state.view";
108: public static final String TOOL_STATE_VIEW_REQUEST_PARAMS_KEY = "osp.tool.state.request.params";
109:
110: /**
111: * Obtain and use the handler for this method.
112: * The handler will be obtained by applying the servlet's HandlerMappings in order.
113: * The HandlerAdapter will be obtained by querying the servlet's
114: * installed HandlerAdapters to find the first that supports the handler class.
115: * Both doGet() and doPost() are handled by this method.
116: * It's up to HandlerAdapters to decide which methods are acceptable.
117: */
118: protected void doService(HttpServletRequest req,
119: HttpServletResponse resp) throws Exception {
120: if (/* getFilter().processRequest(req)*/true) {
121: try {
122: //req = getFilter().wrapRequest(req, resp);
123: if (req == null) {
124: return;
125: }
126:
127: if ("Title".equals(req.getParameter("panel"))) {
128: resp.sendRedirect(req.getContextPath()
129: + "/title.osp?pid="
130: + req.getParameter("pid"));
131: return;
132: }
133:
134: Session s = SessionManager.getCurrentSession();
135: if (s == null) {
136: logger.error("can't determine user");
137: }
138:
139: SimpleAgent2 agent = new SimpleAgent2(s.getUserEid(), s
140: .getUserId());
141:
142: //RepositoryManager rm=(RepositoryManager)BeanFactory.getInstance().getBean("repositoryManager");
143:
144: //logger.debug("Global root: "+rm.getGlobalRoot().getDisplayName());
145: //logger.debug("Agent's root: "+rm.getRootNode(agent));
146:
147: logger
148: .error("TOOL STATE IS NOT BEING CONSIDERED. FIX ME!!!");
149: //TODO
150:
151: // workaround to force tools into a certain state
152:
153: //
154:
155: // relies on "osp.tool.view" param being in tool session state
156: ToolSession toolState = SessionManager
157: .getCurrentToolSession();
158: // SessionState toolState = PortalService.getCurrentToolState();
159: if (toolState != null) {
160: String redirectPath = (String) toolState
161: .getAttribute(TOOL_STATE_VIEW_KEY);
162:
163: if (redirectPath != null) {
164: StringBuffer redirectUrl = new StringBuffer(
165: redirectPath + "?pid="
166: + req.getParameter("pid"));
167: Map requestParams = (Map) toolState
168: .getAttribute(TOOL_STATE_VIEW_REQUEST_PARAMS_KEY);
169: for (Iterator i = requestParams.keySet()
170: .iterator(); i.hasNext();) {
171: String name = (String) i.next();
172: redirectUrl.append("&" + name + "="
173: + requestParams.get(name));
174: }
175: toolState.removeAttribute(TOOL_STATE_VIEW_KEY);
176: toolState
177: .removeAttribute(TOOL_STATE_VIEW_REQUEST_PARAMS_KEY);
178: resp.sendRedirect(redirectUrl.toString());
179: return;
180: }
181: }
182:
183: super .doService(req, resp);
184: } catch (Exception e) {
185: logger.error("", e);
186: throw new OspException(e);
187: } finally {
188: getFilter().tearDown(req);
189: }
190: }
191:
192: }
193:
194: /**
195: * Called by the servlet container to indicate to a servlet that the
196: * servlet is being placed into service. See {@link javax.servlet.Servlet#init}.
197: * <p/>
198: * <p>This implementation stores the {@link javax.servlet.ServletConfig}
199: * object it receives from the servlet container for later use.
200: * When overriding this form of the method, call
201: * <code>super.init(config)</code>.
202: *
203: * @param config the <code>ServletConfig</code> object
204: * that contains configutation
205: * information for this servlet
206: * @throws javax.servlet.ServletException if an exception occurs that
207: * interrupts the servlet's normal
208: * operation
209: * @see javax.servlet.UnavailableException
210: */
211:
212: public void init(ServletConfig config) throws ServletException {
213: super .init(config);
214: }
215:
216: protected RequestSetupFilter getFilter() {
217: return (RequestSetupFilter) ComponentManager.getInstance().get(
218: RequestSetupFilter.class.getName());
219: }
220:
221: }
|