/** * */ 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 = "" + "" + "" + "" + "D4Science Geoportal - Action" + "" + ""; html += "\"D4Science
"; html += "
"; html += "

" + action + "

"; if (waiting) { html += "\"D4Science
"; } html += "

" + message + "

"; html += "
"; return html; } }