001: /*
002: * Copyright (c) 1998-2003 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.doc;
030:
031: import com.caucho.server.webapp.WebApp;
032: import com.caucho.server.webapp.WebAppController;
033: import com.caucho.util.L10N;
034: import com.caucho.util.URLUtil;
035:
036: import javax.servlet.ServletException;
037: import javax.servlet.http.HttpServlet;
038: import javax.servlet.http.HttpServletRequest;
039: import javax.servlet.http.HttpServletResponse;
040: import java.io.IOException;
041: import java.io.PrintWriter;
042: import java.util.ArrayList;
043: import java.util.logging.Level;
044: import java.util.logging.Logger;
045:
046: /**
047: *
048: * Find a local javadoc and use it, or present option to use javadoc from
049: * Caucho website.
050: */
051: public class JavadocRedirectServlet extends HttpServlet {
052: static protected final Logger log = Logger
053: .getLogger(JavadocRedirectServlet.class.getName());
054: static final L10N L = new L10N(JavadocRedirectServlet.class);
055:
056: public void service(HttpServletRequest request,
057: HttpServletResponse response) throws ServletException,
058: IOException {
059: String query = request.getParameter("query");
060: if (query == null || query.length() == 0)
061: query = request.getPathInfo();
062: if (query == null)
063: query = "";
064:
065: query = URLUtil.encodeURL(query);
066:
067: // see if the resin-javadoc web-app is available
068: WebApp app = (WebApp) getServletContext();
069:
070: WebApp japp = null;
071:
072: ArrayList appControllers = app.getParent().getWebAppList();
073:
074: for (int i = 0; i < appControllers.size(); i++) {
075: WebAppController appController = (WebAppController) appControllers
076: .get(i);
077:
078: String contextPath = appController.getContextPath();
079:
080: if (contextPath.startsWith("/resin-javadoc")) {
081: japp = appController.getWebApp();
082: break;
083: }
084: }
085:
086: if (japp != null) {
087: String href = japp.getContextPath() + "?query=" + query;
088: if (log.isLoggable(Level.FINER))
089: log.finer(L.l("javadoc redirect to {0}", href));
090: response.sendRedirect(response.encodeRedirectURL(href));
091: } else {
092: if (log.isLoggable(Level.FINER))
093: log.finer(L.l("javadoc no local javadoc"));
094: String href = "http://www.caucho.com/resin-javadoc/?query="
095: + query;
096:
097: PrintWriter out = response.getWriter();
098: out.println("<html>");
099: out
100: .println("<head><title>Resin® Javadoc Not Found</title></head>");
101: out.println("<body>");
102: out
103: .println("<h1 style='background: #ccddff'>Resin® Javadoc Not Found</h1>");
104: out
105: .println("A local copy of the Resin javadoc could not be found.");
106: out.println("<ul>");
107: out.println("<li><a href='" + href
108: + "'>use Caucho website</a>");
109: out.println("</ul>");
110:
111: out.println("</body>");
112: out.println("</html>");
113: out.close();
114: }
115: }
116:
117: }
|