138 lines
3.9 KiB
Java
138 lines
3.9 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.geoportaldataviewer.server;
|
|
|
|
import java.io.IOException;
|
|
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServlet;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* The Class WatingServerActionServlet.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
*
|
|
* Nov 22, 2023
|
|
*/
|
|
public class WatingServerActionServlet extends HttpServlet {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = -1058074450240555475L;
|
|
protected static Logger logger = LoggerFactory.getLogger(WatingServerActionServlet.class);
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
@Override
|
|
public void init() throws ServletException {
|
|
super.init();
|
|
logger.trace("Workspace WatingServerActionServlet ready.");
|
|
}
|
|
|
|
/**
|
|
* Do get.
|
|
*
|
|
* @param req the req
|
|
* @param resp the resp
|
|
* @throws IOException Signals that an I/O exception has occurred.
|
|
*/
|
|
/*
|
|
* (non-Javadoc)
|
|
*
|
|
* @see
|
|
* javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
|
|
* javax.servlet.http.HttpServletResponse)
|
|
*/
|
|
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
|
|
|
String action = req.getParameter(GeoportalDataViewerConstants.ACTION_TITLE_PARAMETER);
|
|
String message = req.getParameter(GeoportalDataViewerConstants.MESSAGE_PARAMETER);
|
|
boolean waiting = req.getParameter(GeoportalDataViewerConstants.WAITING_PARAMETER) == null ? true
|
|
: req.getParameter(GeoportalDataViewerConstants.WAITING_PARAMETER).equals("true");
|
|
|
|
logger.debug("Input Params [action: " + action + ", message: "+ message +", waiting: " + waiting + "]");
|
|
|
|
action = action == null || action.isEmpty() ? "Loading" : action;
|
|
|
|
message = message == null || message.isEmpty() ? "" : message;
|
|
|
|
sendResponse(resp, action, message, waiting);
|
|
}
|
|
|
|
|
|
/**
|
|
* Send response.
|
|
*
|
|
* @param response the response
|
|
* @param action the action
|
|
* @param message the message
|
|
* @param waiting the waiting
|
|
* @throws IOException Signals that an I/O exception has occurred.
|
|
*/
|
|
protected void sendResponse(HttpServletResponse response, String action, String message, boolean waiting) throws IOException {
|
|
response.setStatus(HttpServletResponse.SC_OK);
|
|
response.setContentType("text/html");
|
|
response.getWriter().write(setHTMLMessage(action, message, waiting));
|
|
response.flushBuffer();
|
|
}
|
|
|
|
/**
|
|
* Sets the HTML message.
|
|
*
|
|
* @param action the action
|
|
* @param message the message
|
|
* @param waiting the waiting
|
|
* @return the string
|
|
*/
|
|
protected String setHTMLMessage(String action, String message, boolean waiting) {
|
|
|
|
String html = "<html>" + "<head>" + "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"
|
|
+ "<style>"
|
|
+ "html, body {\n"
|
|
+ " margin: 10px;\n"
|
|
+ " width: 100%;\n"
|
|
+ " height: 100%;\n"
|
|
+ " display: table\n"
|
|
+ "}\n"
|
|
+ "#content {\n"
|
|
+ " position: absolute;\n"
|
|
+ " left: 50%;\n"
|
|
+ " top: 50%;\n"
|
|
+ " -webkit-transform: translate(-50%, -50%);\n"
|
|
+ " transform: translate(-50%, -50%);\n"
|
|
+ " text-align: center;\n"
|
|
+ "}"
|
|
+ "#message {\n"
|
|
+ " color:gray;"
|
|
+ " font-size: 24px;"
|
|
+ "}"
|
|
+ "</style>"
|
|
+ "<title>D4Science Geoportal - Action</title>" + "</head>" + "<body>";
|
|
|
|
|
|
html += "<img alt=\"D4Science Logo\" src=\"https://services.d4science.org/image/layout_set_logo?img_id=32727\"><br />";
|
|
|
|
html += "<div id=\"content\">";
|
|
html += "<p style=\"font-size: 18px;\">" + action + "</p>";
|
|
|
|
if (waiting) {
|
|
html += "<img alt=\"D4Science Geoportal Loading...\" src=\"../img/loading-gears.gif\"><br />";
|
|
}
|
|
|
|
html += "<br/><p id=\"message\">" + message + "</p>";
|
|
html += "</div></body></html>";
|
|
|
|
return html;
|
|
}
|
|
|
|
}
|