org.swisspush.gateleen.routing.ErrorPageCreator Maven / Gradle / Ivy
The newest version!
package org.swisspush.gateleen.routing;
import org.swisspush.gateleen.core.util.StringUtils;
import com.floreysoft.jmte.Engine;
import java.util.HashMap;
import java.util.Map;
/**
* Utility class to static html error pages
*
* @author https://github.com/mcweba [Marc-Andre Weber]
*/
public class ErrorPageCreator {
private static final String ROUTING_BROKEN_TEMPLATE = "\n"
+ "\n"
+ " Routing is broken
\n"
+ " \n"
+ " Message: ${message}
\n"
+ " Fix it under ${urltext}
\n"
+ " \n"
+ "";
/**
* Creates the static 'Routing Broken' HTML error page.
*
* @param message the message to display
* @param url the url for the resource
* @param urltext the text displayed as link text
* @return String
*/
public static String createRoutingBrokenHTMLErrorPage(String message, String url, String urltext) {
if (StringUtils.isEmpty(message)) {
message = "Not provided!";
}
Engine engine = new Engine();
Map model = new HashMap<>();
model.put("message", message);
model.put("url", url);
model.put("urltext", urltext);
String display = "none";
if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(urltext)) {
display = "block";
}
model.put("display", display);
return engine.transform(ROUTING_BROKEN_TEMPLATE, model);
}
}