Source Code Cross Referenced for ControllerServlet.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » search » tool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.search.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/search/tags/sakai_2-4-1/search-tool/tool/src/java/org/sakaiproject/search/tool/ControllerServlet.java $
003:         * $Id: ControllerServlet.java 29315 2007-04-20 14:28:12Z ajpoland@iupui.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 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.search.tool;
021:
022:        import java.io.IOException;
023:
024:        import javax.servlet.RequestDispatcher;
025:        import javax.servlet.ServletConfig;
026:        import javax.servlet.ServletContext;
027:        import javax.servlet.ServletException;
028:        import javax.servlet.http.HttpServlet;
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpServletResponse;
031:
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.sakaiproject.search.tool.api.SearchBeanFactory;
035:        import org.sakaiproject.tool.api.SessionManager;
036:        import org.sakaiproject.tool.api.Tool;
037:        import org.sakaiproject.tool.api.ToolSession;
038:        import org.springframework.web.context.WebApplicationContext;
039:        import org.springframework.web.context.support.WebApplicationContextUtils;
040:
041:        /**
042:         * @author Ian Boston
043:         */
044:        public class ControllerServlet extends HttpServlet {
045:            public static Log log = LogFactory.getLog(ControllerServlet.class);
046:
047:            /**
048:             * Required for serialization... also to stop eclipse from giving me a
049:             * warning!
050:             */
051:            private static final long serialVersionUID = 676743152200357708L;
052:
053:            public static final String SAVED_REQUEST_URL = "org.sakaiproject.search.api.last-request-url";
054:
055:            private static final String PANEL = "panel";
056:
057:            private static final Object TITLE_PANEL = "Title";
058:
059:            private WebApplicationContext wac;
060:
061:            private SearchBeanFactory searchBeanFactory = null;
062:
063:            private SessionManager sessionManager;
064:
065:            public void init(ServletConfig servletConfig)
066:                    throws ServletException {
067:
068:                super .init(servletConfig);
069:
070:                ServletContext sc = servletConfig.getServletContext();
071:
072:                wac = WebApplicationContextUtils.getWebApplicationContext(sc);
073:                try {
074:                    searchBeanFactory = (SearchBeanFactory) wac
075:                            .getBean("search-searchBeanFactory");
076:                    ServletContext context = getServletContext();
077:                    searchBeanFactory.setContext(context);
078:                } catch (Exception ex) {
079:                }
080:                if (sessionManager == null) {
081:                    sessionManager = (SessionManager) wac
082:                            .getBean(SessionManager.class.getName());
083:                }
084:
085:            }
086:
087:            protected void doGet(final HttpServletRequest request,
088:                    HttpServletResponse response) throws ServletException,
089:                    IOException {
090:
091:                execute(request, response);
092:            }
093:
094:            protected void doPost(HttpServletRequest request,
095:                    HttpServletResponse response) throws ServletException,
096:                    IOException {
097:                execute(request, response);
098:            }
099:
100:            public void execute(HttpServletRequest request,
101:                    HttpServletResponse response) throws ServletException,
102:                    IOException {
103:                if (wac == null) {
104:                    wac = WebApplicationContextUtils
105:                            .getRequiredWebApplicationContext(this 
106:                                    .getServletContext());
107:                    if (wac == null) {
108:                        response.sendError(
109:                                HttpServletResponse.SC_SERVICE_UNAVAILABLE,
110:                                "Cannot get WebApplicationContext");
111:                        return;
112:                    }
113:
114:                }
115:                request.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL);
116:
117:                if (searchBeanFactory == null) {
118:                    searchBeanFactory = (SearchBeanFactory) wac
119:                            .getBean("search-searchBeanFactory");
120:                    ServletContext context = getServletContext();
121:                    searchBeanFactory.setContext(context);
122:                }
123:                if (sessionManager == null) {
124:                    sessionManager = (SessionManager) wac
125:                            .getBean(SessionManager.class.getName());
126:                }
127:
128:                addLocalHeaders(request);
129:
130:                String targetURL = persistState(request);
131:                if (targetURL != null && targetURL.trim().length() > 0) {
132:                    response.sendRedirect(targetURL);
133:                    return;
134:                }
135:                if (TITLE_PANEL.equals(request.getParameter(PANEL))) {
136:
137:                    String targetPage = "/WEB-INF/pages/title.jsp";
138:                    RequestDispatcher rd = request
139:                            .getRequestDispatcher(targetPage);
140:                    rd.forward(request, response);
141:
142:                } else {
143:                    String path = request.getPathInfo();
144:                    if (path == null || path.length() == 0) {
145:                        path = "/index";
146:                    }
147:                    if (!path.startsWith("/")) {
148:                        path = "/" + path;
149:                    }
150:
151:                    String targetPage = "/WEB-INF/pages" + path + ".jsp";
152:
153:                    request.setAttribute(
154:                            SearchBeanFactory.SEARCH_BEAN_FACTORY_ATTR,
155:                            searchBeanFactory);
156:                    RequestDispatcher rd = request
157:                            .getRequestDispatcher(targetPage);
158:                    rd.forward(request, response);
159:                }
160:
161:                request.removeAttribute(Tool.NATIVE_URL);
162:            }
163:
164:            public void addLocalHeaders(HttpServletRequest request) {
165:                String sakaiHeader = (String) request
166:                        .getAttribute("sakai.html.head");
167:                String skin = "default/"; // this could be changed in the future to
168:                // make search skin awaire
169:                String localStylesheet = "<link href=\"/sakai-search-tool/styles/"
170:                        + skin
171:                        + "searchStyle.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />";
172:                String localJavascript = "<script type=\"text/javascript\" src=\"/sakai-search-tool/scripts/search.js\"> </script>";
173:                request.setAttribute("sakai.html.head", localStylesheet
174:                        + sakaiHeader + localJavascript);
175:            }
176:
177:            /**
178:             * returns the request state for the tool. If the state is restored, we set
179:             * the request attribute RWikiServlet.REQUEST_STATE_RESTORED to Boolean.TRUE
180:             * and a Thread local named RWikiServlet.REQUEST_STATE_RESTORED to
181:             * Boolean.TRUE. These MUST be checked by anything that modifies state, to
182:             * ensure that a reinitialisation of Tool state does not result in a repost
183:             * of data.
184:             * 
185:             * @param request
186:             * @return
187:             */
188:            private String persistState(HttpServletRequest request) {
189:                ToolSession ts = sessionManager.getCurrentToolSession();
190:                if (isPageToolDefault(request)) {
191:                    log.debug("Incomming URL is "
192:                            + request.getRequestURL().toString() + "?"
193:                            + request.getQueryString());
194:                    log.debug("Restore " + ts.getAttribute(SAVED_REQUEST_URL));
195:                    return (String) ts.getAttribute(SAVED_REQUEST_URL);
196:                }
197:                if (isPageRestorable(request)) {
198:                    ts.setAttribute(SAVED_REQUEST_URL, request.getRequestURL()
199:                            .toString()
200:                            + "?" + request.getQueryString());
201:                    log.debug("Saved " + ts.getAttribute(SAVED_REQUEST_URL));
202:                }
203:                return null;
204:            }
205:
206:            /**
207:             * Check to see if the reques represents the Tool default page. This is not
208:             * the same as the view Home. It is the same as first entry into a Tool or
209:             * when the page is refreshed
210:             * 
211:             * @param request
212:             * @return true if the page is the Tool default page
213:             */
214:            private boolean isPageToolDefault(HttpServletRequest request) {
215:                if (TITLE_PANEL.equals(request.getParameter(PANEL)))
216:                    return false;
217:                String pathInfo = request.getPathInfo();
218:                String queryString = request.getQueryString();
219:                String method = request.getMethod();
220:                return ("GET".equalsIgnoreCase(method)
221:                        && (pathInfo == null || request.getPathInfo().length() == 0) && (queryString == null || queryString
222:                        .length() == 0));
223:            }
224:
225:            /**
226:             * Check to see if the request represents a page that can act as a restor
227:             * point.
228:             * 
229:             * @param request
230:             * @return true if it is possible to restore to this point.
231:             */
232:            private boolean isPageRestorable(HttpServletRequest request) {
233:
234:                if (TITLE_PANEL.equals(request.getParameter(PANEL)))
235:                    return false;
236:                String pathInfo = request.getPathInfo();
237:                if (pathInfo != null) {
238:                    if (request.getPathInfo().endsWith(".gif")) {
239:                        return false;
240:                    }
241:                    if (request.getPathInfo().endsWith(".src")) {
242:                        return false;
243:                    }
244:                }
245:
246:                if ("GET".equalsIgnoreCase(request.getMethod()))
247:                    return true;
248:
249:                return false;
250:            }
251:
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.