001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/rwiki/tags/sakai_2-4-1/rwiki-tool/tool/src/java/uk/ac/cam/caret/sakai/rwiki/tool/MapDispatcher.java $
003: * $Id: MapDispatcher.java 27686 2007-03-23 11:56:40Z ian@caret.cam.ac.uk $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006, 2007 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 uk.ac.cam.caret.sakai.rwiki.tool;
021:
022: import java.io.IOException;
023: import java.util.HashMap;
024: import java.util.Map;
025:
026: import javax.servlet.ServletContext;
027: import javax.servlet.ServletException;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030:
031: import uk.ac.cam.caret.sakai.rwiki.tool.command.Dispatcher;
032:
033: /**
034: * @author ieb
035: *
036: */
037: public class MapDispatcher implements Dispatcher {
038: Map<String, String> targets = new HashMap<String, String>();
039: Map<String, Dispatcher> dispatchers = new HashMap<String, Dispatcher>();
040: private Dispatcher defaultDispatcher = new DefaultRequestDispatcher();
041: private VelocityInlineDispatcher velocityDispatcher = new VelocityInlineDispatcher();
042:
043: public MapDispatcher(ServletContext context)
044: throws ServletException {
045: velocityDispatcher.init(context);
046: targets.put("/WEB-INF/command-pages/diff.jsp",
047: "/WEB-INF/vm/diff");
048: targets.put("/WEB-INF/command-pages/edit.jsp",
049: "/WEB-INF/vm/edit");
050: targets.put("/WEB-INF/command-pages/editRealm-many.jsp",
051: "/WEB-INF/vm/editRealm-many");
052: targets.put("/WEB-INF/command-pages/editRealm-manyv2.jsp",
053: "/WEB-INF/vm/editRealm-manyv2");
054: targets.put("/WEB-INF/command-pages/editRealm.jsp",
055: "/WEB-INF/vm/editRealm");
056: targets.put("/WEB-INF/command-pages/fragmentpreview.jsp",
057: "/WEB-INF/vm/fragmentpreview");
058: targets.put("/WEB-INF/command-pages/fragmentview.jsp",
059: "/WEB-INF/vm/fragmentview");
060: targets.put("/WEB-INF/command-pages/full_search.jsp",
061: "/WEB-INF/vm/full_search");
062: targets.put("/WEB-INF/command-pages/history.jsp",
063: "/WEB-INF/vm/history");
064: targets.put("/WEB-INF/command-pages/info.jsp",
065: "/WEB-INF/vm/info");
066: targets.put("/WEB-INF/command-pages/permission.jsp",
067: "/WEB-INF/vm/permission");
068: targets.put("/WEB-INF/command-pages/preferences.jsp",
069: "/WEB-INF/vm/preferences");
070: targets.put("/WEB-INF/command-pages/preview.jsp",
071: "/WEB-INF/vm/preview");
072: targets.put("/WEB-INF/command-pages/publicview.jsp",
073: "/WEB-INF/vm/publicview");
074: targets.put("/WEB-INF/command-pages/printview.jsp",
075: "/WEB-INF/vm/printview");
076: targets.put("/WEB-INF/command-pages/review.jsp",
077: "/WEB-INF/vm/review");
078: targets.put("/WEB-INF/command-pages/search.jsp",
079: "/WEB-INF/vm/search");
080: targets.put("/WEB-INF/command-pages/title.jsp",
081: "/WEB-INF/vm/title");
082: targets.put("/WEB-INF/command-pages/view.jsp",
083: "/WEB-INF/vm/view");
084:
085: dispatchers.put("/WEB-INF/command-pages/diff.jsp",
086: velocityDispatcher);
087: dispatchers.put("/WEB-INF/command-pages/edit.jsp",
088: velocityDispatcher);
089: dispatchers.put("/WEB-INF/command-pages/editRealm-many.jsp",
090: velocityDispatcher);
091: dispatchers.put("/WEB-INF/command-pages/editRealm-manyv2.jsp",
092: velocityDispatcher);
093: dispatchers.put("/WEB-INF/command-pages/editRealm.jsp",
094: velocityDispatcher);
095: dispatchers.put("/WEB-INF/command-pages/fragmentpreview.jsp",
096: velocityDispatcher);
097: dispatchers.put("/WEB-INF/command-pages/fragmentview.jsp",
098: velocityDispatcher);
099: dispatchers.put("/WEB-INF/command-pages/full_search.jsp",
100: velocityDispatcher);
101: dispatchers.put("/WEB-INF/command-pages/history.jsp",
102: velocityDispatcher);
103: dispatchers.put("/WEB-INF/command-pages/info.jsp",
104: velocityDispatcher);
105: dispatchers.put("/WEB-INF/command-pages/permission.jsp",
106: velocityDispatcher);
107: dispatchers.put("/WEB-INF/command-pages/preferences.jsp",
108: velocityDispatcher);
109: dispatchers.put("/WEB-INF/command-pages/preview.jsp",
110: velocityDispatcher);
111: dispatchers.put("/WEB-INF/command-pages/publicview.jsp",
112: velocityDispatcher);
113: dispatchers.put("/WEB-INF/command-pages/printview.jsp",
114: velocityDispatcher);
115: dispatchers.put("/WEB-INF/command-pages/review.jsp",
116: velocityDispatcher);
117: dispatchers.put("/WEB-INF/command-pages/search.jsp",
118: velocityDispatcher);
119: dispatchers.put("/WEB-INF/command-pages/title.jsp",
120: velocityDispatcher);
121: dispatchers.put("/WEB-INF/command-pages/view.jsp",
122: velocityDispatcher);
123:
124: }
125:
126: /* (non-Javadoc)
127: * @see uk.ac.cam.caret.sakai.rwiki.tool.command.Dispatcher#dispatch(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
128: */
129: public void dispatch(String path, HttpServletRequest request,
130: HttpServletResponse response) throws ServletException,
131: IOException {
132: String targetpath = targets.get(path);
133: if (targetpath == null) {
134: targetpath = path;
135: }
136:
137: Dispatcher dispatcher = dispatchers.get(path);
138: if (dispatcher == null) {
139: dispatcher = defaultDispatcher;
140: }
141: dispatcher.dispatch(targetpath, request, response);
142: }
143:
144: }
|