001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/search/tags/sakai_2-4-1/search-tool/tool/src/java/org/sakaiproject/search/tool/RestSearchServlet.java $
003: * $Id: RestSearchServlet.java 22723 2007-03-16 01:35:32Z ian@caret.cam.ac.uk $
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: import java.io.Writer;
024:
025: import javax.servlet.ServletException;
026: import javax.servlet.http.HttpServlet;
027: import javax.servlet.http.HttpServletRequest;
028: import javax.servlet.http.HttpServletResponse;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.sakaiproject.component.api.ComponentManager;
033: import org.sakaiproject.search.api.SearchService;
034:
035: /**
036: * Serializes a search result out to the requesting service
037: *
038: * @author ieb
039: */
040: public class RestSearchServlet extends HttpServlet {
041:
042: private static final Log log = LogFactory
043: .getLog(RestSearchServlet.class);
044:
045: private SearchService searchService;
046:
047: public void init() {
048: ComponentManager cm = org.sakaiproject.component.cover.ComponentManager
049: .getInstance();
050:
051: searchService = (SearchService) load(cm, SearchService.class
052: .getName());
053:
054: }
055:
056: private Object load(ComponentManager cm, String name) {
057: Object o = cm.get(name);
058: if (o == null) {
059: log.error("Cant find Spring component named " + name);
060: }
061: return o;
062: }
063:
064: protected void doGet(HttpServletRequest request,
065: HttpServletResponse response) throws ServletException,
066: IOException {
067: execute(request, response);
068: }
069:
070: protected void doPost(HttpServletRequest request,
071: HttpServletResponse response) throws ServletException,
072: IOException {
073: execute(request, response);
074: }
075:
076: public void execute(HttpServletRequest request,
077: HttpServletResponse response) throws IOException {
078: /*
079: String test = (String) request.getParameter("test");
080: if ( "true".equals(test) ) {
081: StringBuffer sb = new StringBuffer();
082: sb.append("<html><head></head><body><form method=\"post\" action=\"?\" >");
083: sb.append("CheckSum <input type=\"text\" name=\"").append(SearchService.REST_CHECKSUM).append("\" /> <br />");
084: sb.append("Contexts <input type=\"text\" name=\"").append(SearchService.REST_CONTEXTS).append("\" /> <br />");
085: sb.append("Start <input type=\"text\" name=\"").append(SearchService.REST_START).append("\" /> <br />");
086: sb.append("End <input type=\"text\" name=\"").append(SearchService.REST_END).append("\" /> <br />");
087: sb.append("Terms <input type=\"text\" name=\"").append(SearchService.REST_TERMS).append("\" /> <br />");
088: sb.append("UserID <input type=\"text\" name=\"").append(SearchService.REST_USERID).append("\" /> <br />");
089: sb.append("<input type=\"hidden\" name=\"test\" value=\"act1\" /> <br />");
090: sb.append("<input type=\"submit\" name=\"submit\" value=\" Go \" />");
091: sb.append("</form></body>");
092: response.setContentType("text/html");
093: Writer out = response.getWriter();
094: out.write(sb.toString());
095: } else {
096: */
097: String result = searchService.searchXML(request
098: .getParameterMap());
099: response.setContentType("text/xml");
100: Writer out = response.getWriter();
101: out.write(result);
102: // }
103:
104: }
105:
106: }
|