use of org.b3log.latke.servlet.renderer.TextHTMLRenderer in project solo by b3log.
the class RepairProcessor method removeAllDataGET.
/**
* Shows remove all data page.
*
* @param context the specified context
* @param request the specified HTTP servlet request
*/
@RequestProcessing(value = "/rm-all-data.do", method = HTTPRequestMethod.GET)
public void removeAllDataGET(final HTTPRequestContext context, final HttpServletRequest request) {
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
try {
final StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.append("<html><head><title>WARNING!</title>");
htmlBuilder.append("<script type='text/javascript'");
htmlBuilder.append("src='").append(Latkes.getStaticServer()).append("/js/lib/jquery/jquery.min.js'");
htmlBuilder.append("></script></head><body>");
htmlBuilder.append("<button id='ok' onclick='removeData()'>");
htmlBuilder.append("Continue to delete ALL DATA</button></body>");
htmlBuilder.append("<script type='text/javascript'>");
htmlBuilder.append("function removeData() {");
htmlBuilder.append("$.ajax({type: 'POST',url:'").append(Latkes.getContextPath()).append("/rm-all-data.do',");
htmlBuilder.append("dataType: 'text/html',success: function(result){");
htmlBuilder.append("$('html').html(result);}});}</script></html>");
renderer.setContent(htmlBuilder.toString());
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
try {
context.getResponse().sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
} catch (final IOException ex) {
throw new RuntimeException(ex);
}
}
}
use of org.b3log.latke.servlet.renderer.TextHTMLRenderer in project solo by b3log.
the class RepairProcessor method restoreStat.
/**
* Restores the statistics.
*
* <p>
* <ul>
* <li>Uses the value of {@link Statistic#STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT} for
* {@link Statistic#STATISTIC_BLOG_COMMENT_COUNT}</li>
* <li>Uses the value of {@link Statistic#STATISTIC_PUBLISHED_ARTICLE_COUNT} for
* {@link Statistic#STATISTIC_BLOG_ARTICLE_COUNT}</li>
* </ul>
* </p>
*
* @param context the specified context
*/
@RequestProcessing(value = "/fix/restore-stat.do", method = HTTPRequestMethod.GET)
public void restoreStat(final HTTPRequestContext context) {
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
try {
final JSONObject statistic = statisticQueryService.getStatistic();
if (statistic.has(Statistic.STATISTIC_BLOG_COMMENT_COUNT) && statistic.has(Statistic.STATISTIC_BLOG_ARTICLE_COUNT)) {
LOGGER.info("No need for repairing statistic");
renderer.setContent("No need for repairing statistic.");
return;
}
if (!statistic.has(Statistic.STATISTIC_BLOG_COMMENT_COUNT)) {
statistic.put(Statistic.STATISTIC_BLOG_COMMENT_COUNT, statistic.getInt(Statistic.STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT));
}
if (!statistic.has(Statistic.STATISTIC_BLOG_ARTICLE_COUNT)) {
statistic.put(Statistic.STATISTIC_BLOG_ARTICLE_COUNT, statistic.getInt(Statistic.STATISTIC_PUBLISHED_ARTICLE_COUNT));
}
statisticMgmtService.updateStatistic(statistic);
renderer.setContent("Restores statistic succeeded.");
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
renderer.setContent("Restores statistics failed, error msg[" + e.getMessage() + "]");
}
}
Aggregations