001: /*
002: * Created on Feb 23, 2004
003: *
004: * To change the template for this generated file go to
005: * Window - Preferences - Java - Code Generation - Code and Comments
006: */
007: package org.vfny.geoserver.servlets;
008:
009: import org.vfny.geoserver.global.UserContainer;
010: import org.vfny.geoserver.util.Requests;
011: import java.io.BufferedReader;
012: import java.io.IOException;
013: import java.io.InputStreamReader;
014: import java.net.HttpURLConnection;
015: import java.net.URL;
016: import java.util.ResourceBundle;
017: import javax.servlet.ServletConfig;
018: import javax.servlet.ServletContext;
019: import javax.servlet.ServletException;
020: import javax.servlet.ServletOutputStream;
021: import javax.servlet.http.HttpServlet;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: /**
026: * JSPCompiler purpose.
027: * <p>
028: * Description of JSPCompiler ...
029: * </p>
030: *
031: * @author dzwiers, Refractions Research, Inc.
032: * @author $Author: dgricci $ (last modification)
033: * @version $Id: JSPCompiler.java 7947 2007-12-05 20:17:13Z aaime $
034: */
035: public class JSPCompiler extends HttpServlet {
036: String[] pages;
037: int spot = 0;
038:
039: public void init(ServletConfig config) throws ServletException {
040: ResourceBundle rb = ResourceBundle.getBundle(getClass()
041: .getName());
042: int n = Integer.parseInt(rb.getString("numURLs"));
043: pages = new String[n];
044:
045: for (int i = 0; i < n; i++) {
046: pages[i] = rb.getString("url." + (i + 1));
047: }
048: }
049:
050: protected void doGet(HttpServletRequest request,
051: HttpServletResponse response) throws ServletException,
052: IOException {
053: if (spot < pages.length) {
054: try {
055: String base = Requests.getBaseUrl(request, null);
056: ServletContext session = request.getSession()
057: .getServletContext();
058:
059: synchronized (session) {
060: UserContainer u2 = new UserContainer();
061: u2.setUsername("compiler");
062: session.setAttribute(UserContainer.SESSION_KEY, u2);
063: }
064:
065: doLoad(base + pages[spot], response);
066:
067: synchronized (session) {
068: session.setAttribute(UserContainer.SESSION_KEY,
069: null);
070: }
071: } catch (Exception e) {
072: e.printStackTrace();
073: }
074:
075: spot = spot + 1;
076: } else {
077: doForward(response);
078: }
079: }
080:
081: private void doForward(HttpServletResponse response)
082: throws ServletException, IOException {
083: response.setContentType("text/html");
084:
085: ServletOutputStream os = response.getOutputStream();
086: os.print("<html>\n");
087: os.print("<head><title>GeoServer - Loading</title>\n");
088: os
089: .print(" <meta content=\"text/css\" http-equiv=\"content-style-type\">\n");
090: os.print(" <style type=\"text/css\">\n");
091: os
092: .print(" <!-- @import url(\"/geoserver/style.css\"); -->\n");
093: os.print(" </style>\n");
094: os
095: .print(" <link type=\"image/gif\" href=\"gs.gif\" rel=\"icon\"><!-- mozilla --> \n");
096: os
097: .print(" <link href=\"gs.ico\" rel=\"SHORTCUT ICON\"><!-- ie -->\n");
098: os.print("</head>\n");
099: os
100: .print("<body onload=\"javascript:window.location.replace('welcome.do')\"><br><center>\n");
101: os.print("<table width=\"60%\" height=\"60%\"><tr><td>\n");
102: os.print("<center>\n");
103: os.print(" <span class=\"project\">\n");
104: os
105: .print(" <a href=\"http://geoserver.org/\">GeoServer</a>\n");
106: os.print(" </span>\n");
107: os.print(" <h1>LOADING ...</h1>\n");
108: os.print("<center><br>\n");
109: os.print("<center><h2>Please Wait</h2><center>\n");
110: os.print("</table></td></tr>\n");
111: os.print("</center></body>\n");
112: os.print("</html>");
113: }
114:
115: private void doLoad(String url, HttpServletResponse response)
116: throws ServletException, IOException {
117: URL u = new URL(url);
118:
119: try {
120: HttpURLConnection con = (HttpURLConnection) u
121: .openConnection();
122: con.connect();
123:
124: String s = con.getResponseMessage();
125: BufferedReader br = new BufferedReader(
126: new InputStreamReader(con.getInputStream()));
127:
128: while (br.ready())
129: br.readLine();
130:
131: con.disconnect();
132: } catch (Exception e) {
133: // should not stop compilation ...
134: System.err.println("ERROR compiling " + url);
135: }
136:
137: response.setContentType("text/html");
138:
139: ServletOutputStream os = response.getOutputStream();
140: os.print("<html>\n");
141: os.print("<head><title>GeoServer - Loading</title>\n");
142: os
143: .print(" <meta content=\"text/css\" http-equiv=\"content-style-type\">\n");
144: os.print(" <style type=\"text/css\">\n");
145: os
146: .print(" <!-- @import url(\"/geoserver/style.css\"); -->\n");
147: os.print(" </style>\n");
148: os
149: .print(" <link type=\"image/gif\" href=\"gs.gif\" rel=\"icon\"><!-- mozilla --> \n");
150: os
151: .print(" <link href=\"gs.ico\" rel=\"SHORTCUT ICON\"><!-- ie -->\n");
152: os.print("</head>\n");
153: os
154: .print("<body onload=\"javascript:window.location.replace('JSPCompiler')\"><br><center>\n");
155: os.print("<table width=\"60%\" height=\"60%\"><tr><td>\n");
156: os.print("<center>\n");
157: os.print(" <span class=\"project\">\n");
158: os
159: .print(" <a href=\"http://geoserver.org/\">GeoServer</a>\n");
160: os.print(" </span>\n");
161: os.print(" <span class=\"license\">\n");
162: os
163: .print(" <a href=\"http://docs.codehaus.org/display/GEOSDOC/License\">©</a>\n");
164: os.print(" </span>\n");
165: os.print(" <h1>LOADING ...</h1>\n");
166: os.print("<center><br>\n");
167: os.print("<center><h2>Please Wait</h2><center>\n");
168: os.print("<center><h2>"
169: + (int) ((100 * (spot * 1.0)) / (pages.length * 1.0))
170: + "% Completed</h2><center>\n");
171: os.print("</table></td></tr>\n");
172: os.print("</center></body>\n");
173: os.print("</html>");
174: }
175: }
|