org.vfny.geoserver.servlets.JSPCompiler Maven / Gradle / Ivy
The newest version!
/*
* Created on Feb 23, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package org.vfny.geoserver.servlets;
import org.vfny.geoserver.global.UserContainer;
import org.vfny.geoserver.util.Requests;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ResourceBundle;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* JSPCompiler purpose.
*
* Description of JSPCompiler ...
*
*
* @author dzwiers, Refractions Research, Inc.
* @author $Author: dgricci $ (last modification)
* @version $Id: JSPCompiler.java 10430 2008-10-21 18:57:33Z bmmpxf $
*/
public class JSPCompiler extends HttpServlet {
String[] pages;
int spot = 0;
public void init(ServletConfig config) throws ServletException {
ResourceBundle rb = ResourceBundle.getBundle(getClass().getName());
int n = Integer.parseInt(rb.getString("numURLs"));
pages = new String[n];
for (int i = 0; i < n; i++) {
pages[i] = rb.getString("url." + (i + 1));
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (spot < pages.length) {
try {
String base = Requests.getBaseUrl(request, null);
ServletContext session = request.getSession().getServletContext();
synchronized (session) {
UserContainer u2 = new UserContainer();
u2.setUsername("compiler");
session.setAttribute(UserContainer.SESSION_KEY, u2);
}
doLoad(base + pages[spot], response);
synchronized (session) {
session.setAttribute(UserContainer.SESSION_KEY, null);
}
} catch (Exception e) {
e.printStackTrace();
}
spot = spot + 1;
} else {
doForward(response);
}
}
private void doForward(HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
ServletOutputStream os = response.getOutputStream();
os.print("\n");
os.print("GeoServer - Loading \n");
os.print(" \n");
os.print(" \n");
os.print(" \n");
os.print(" \n");
os.print("\n");
os.print("
\n");
os.print("\n");
os.print("\n");
os.print(" \n");
os.print(" GeoServer\n");
os.print(" \n");
os.print(" \n");
os.print(" ©\n");
os.print(" \n");
os.print(" LOADING ...
\n");
os.print("
\n");
os.print("Please Wait
\n");
os.print("
\n");
os.print(" \n");
os.print("");
}
private void doLoad(String url, HttpServletResponse response)
throws ServletException, IOException {
URL u = new URL(url);
try {
HttpURLConnection con = (HttpURLConnection) u.openConnection();
con.connect();
String s = con.getResponseMessage();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
while (br.ready())
br.readLine();
con.disconnect();
} catch (Exception e) {
// should not stop compilation ...
System.err.println("ERROR compiling " + url);
}
response.setContentType("text/html");
ServletOutputStream os = response.getOutputStream();
os.print("\n");
os.print("GeoServer - Loading \n");
os.print(" \n");
os.print(" \n");
os.print(" \n");
os.print(" \n");
os.print("\n");
os.print(
"
\n");
os.print("\n");
os.print("\n");
os.print(" \n");
os.print(" GeoServer\n");
os.print(" \n");
os.print(" \n");
os.print(" ©\n");
os.print(" \n");
os.print(" LOADING ...
\n");
os.print("
\n");
os.print("Please Wait
\n");
os.print("" + (int) ((100 * (spot * 1.0)) / (pages.length * 1.0))
+ "% Completed
\n");
os.print("
\n");
os.print(" \n");
os.print("");
}
}