2015-12-18 16:20:47 +03:00
|
|
|
/*
|
|
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
|
|
* To change this template file, choose Tools | Templates
|
|
|
|
* and open the template in the editor.
|
|
|
|
*/
|
|
|
|
package inr.numass.server;
|
|
|
|
|
|
|
|
import hep.dataforge.storage.api.StateLoader;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Alexander Nozik
|
|
|
|
*/
|
|
|
|
public class HandlerUtils {
|
|
|
|
|
2016-04-24 22:17:52 +03:00
|
|
|
public static String renderStates(StateLoader states) {
|
|
|
|
StringBuilder b = new StringBuilder();
|
2015-12-18 16:20:47 +03:00
|
|
|
b.append("<div class=\"shifted\">\n");
|
2018-03-06 16:59:09 +03:00
|
|
|
states.getValueStream().forEach(pair->{
|
2015-12-18 16:20:47 +03:00
|
|
|
String color;
|
2018-03-06 16:59:09 +03:00
|
|
|
switch (pair.getSecond().getType()) {
|
2015-12-18 16:20:47 +03:00
|
|
|
case NUMBER:
|
|
|
|
color = "blue";
|
|
|
|
break;
|
|
|
|
case BOOLEAN:
|
|
|
|
color = "red";
|
|
|
|
break;
|
|
|
|
case TIME:
|
|
|
|
color = "magenta";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
color = "brown";
|
|
|
|
|
|
|
|
}
|
|
|
|
b.append(String.format("<p> <strong>%s</strong> : <font color= \"%s\">%s</font> </p>%n",
|
2018-03-06 16:59:09 +03:00
|
|
|
pair.getFirst(), color, pair.getSecond().stringValue()));
|
|
|
|
});
|
2015-12-18 16:20:47 +03:00
|
|
|
b.append("</div>\n");
|
2016-04-24 22:17:52 +03:00
|
|
|
return b.toString();
|
2015-12-18 16:20:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void renderHTMLHeader(StringBuilder b) {
|
|
|
|
b.append("\n<!DOCTYPE html>\n"
|
|
|
|
+ "<html lang=\"en\">\n"
|
|
|
|
+ "<head>\n"
|
|
|
|
+ " <meta charset=\"utf-8\">\n"
|
|
|
|
+ " <meta http-equiv=\"refresh\" content=\"30\">"
|
|
|
|
+ " <title>Numass storage</title>\n"
|
|
|
|
+ "</head>\n"
|
|
|
|
+ " <style>\n"
|
|
|
|
+ " .shifted { \n"
|
|
|
|
+ " margin: 20px;\n"
|
|
|
|
+ " }\n"
|
|
|
|
+ " </style>"
|
|
|
|
+ "<body>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void renderHTMLFooter(StringBuilder b) {
|
|
|
|
b.append("</body>\n"
|
|
|
|
+ "</html>");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void renderHeader(StringBuilder b, String header, int level) {
|
|
|
|
b.append(String.format("<h%d>%s</h%d>%n", level, header, level));
|
|
|
|
}
|
|
|
|
}
|