use of javax.servlet.jsp.JspException in project jstorm by alibaba.
the class CpuTag method doTag.
@Override
public void doTag() throws JspException {
JspWriter out = getJspContext().getOut();
try {
if (!StringUtils.isBlank(ratio)) {
double value = JStormUtils.parseDouble(ratio);
double danger_threshold = workers * 100;
double warn_threshold = danger_threshold * THRESHOLD;
String status_success = "success";
String status_warning = "warning";
String status_danger = "danger";
StringBuilder sb = new StringBuilder();
sb.append("<div class='progress cpu-ratio-bar'>");
if (Double.compare(value, warn_threshold) <= 0) {
double width = value / danger_threshold * 100;
appendBar(sb, width, value, status_success);
} else if (Double.compare(value, danger_threshold) <= 0) {
double width1 = THRESHOLD * 100;
double width2 = (value - warn_threshold) / danger_threshold * 100;
appendBar(sb, width1, value, status_success);
appendBar(sb, width2, value, status_warning);
} else {
double width1 = danger_threshold / value * 100;
double width2 = 100 - width1;
appendBar(sb, width1, value, status_success);
appendBar(sb, width2, value, status_danger);
}
sb.append("</div>");
out.write(sb.toString());
}
} catch (IOException e) {
throw new JspException("Error: " + e.getMessage());
}
}
use of javax.servlet.jsp.JspException in project jstorm by alibaba.
the class PaginationTag method doTag.
@Override
public void doTag() throws JspException {
if (pageSize <= 1)
return;
JspWriter out = getJspContext().getOut();
try {
StringBuilder sb = new StringBuilder();
sb.append("<nav class='netty-pagination'><ul class='pagination'>");
if (curPage > 1) {
sb.append(String.format("<li><a href='%s' class='previous'>", getUrl(curPage - 1)));
sb.append("<span class='glyphicon glyphicon-chevron-left'></span></a>");
sb.append("</li>");
}
if (pageSize <= 10) {
for (int i = 1; i <= pageSize; i++) {
sb.append(createPage(i, i == curPage));
}
} else {
if (curPage <= 5) {
for (int i = 1; i <= curPage; i++) {
sb.append(createPage(i, i == curPage));
}
} else {
sb.append(createPage(curPage - 4, "...", false));
for (int i = curPage - 3; i <= curPage; i++) {
sb.append(createPage(i, i == curPage));
}
}
if (pageSize - curPage <= 5) {
for (int i = curPage + 1; i <= pageSize; i++) {
sb.append(createPage(i, false));
}
} else {
for (int i = curPage + 1; i <= curPage + 3; i++) {
sb.append(createPage(i, false));
}
sb.append(createPage(curPage + 4, "...", false));
}
}
if (curPage < pageSize) {
sb.append(String.format("<li><a href='%s' class='next'>", getUrl(curPage + 1)));
sb.append("<span class='glyphicon glyphicon-chevron-right'></span></a>");
sb.append("</li>");
}
sb.append("</ul></nav>");
out.write(sb.toString());
} catch (IOException e) {
throw new JspException("Error: " + e.getMessage());
}
}
use of javax.servlet.jsp.JspException in project jstorm by alibaba.
the class PrettyTag method doTag.
@Override
public void doTag() throws JspException {
JspWriter out = getJspContext().getOut();
try {
String output;
switch(type) {
case "uptime":
int uptime = JStormUtils.parseInt(input, 0);
output = UIUtils.prettyUptime(uptime);
break;
case "datetime":
output = UIUtils.prettyDateTime(input);
break;
case "filesize":
long size = UIUtils.parseLong(input, 0);
output = UIUtils.prettyFileSize(size);
break;
case "head":
output = prettyHead(input);
break;
default:
output = "Input Error";
break;
}
out.write(output);
} catch (IOException e) {
throw new JspException("Error: " + e.getMessage());
}
}
use of javax.servlet.jsp.JspException in project jstorm by alibaba.
the class SubMetricTag method doTag.
@Override
public void doTag() throws JspException {
JspWriter out = getJspContext().getOut();
try {
StringBuilder sb = new StringBuilder();
if (metric.size() > 0) {
if (isHidden) {
sb.append(String.format("<div class='%s hidden'>", clazz));
} else {
sb.append(String.format("<div class='%s'>", clazz));
}
for (String parent : parentComp) {
String key = metricName + "@" + parent;
String v = metric.get(key);
if (v != null) {
sb.append(v);
}
sb.append("<br/>");
}
sb.append("</div>");
out.write(sb.toString());
}
} catch (IOException e) {
throw new JspException("Error: " + e.getMessage());
}
}
use of javax.servlet.jsp.JspException in project jodd by oblac.
the class FormTag method doAfterBody.
/**
* Performs smart form population.
*/
@Override
public int doAfterBody() throws JspException {
BodyContent body = getBodyContent();
JspWriter out = body.getEnclosingWriter();
String bodytext = populateForm(body.getString(), new FormFieldResolver() {
public Object value(String name) {
return JspResolver.value(name, pageContext);
}
});
try {
out.print(bodytext);
} catch (IOException ioex) {
throw new JspException(ioex);
}
return SKIP_BODY;
}
Aggregations