use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.
the class BBSController method showMessage.
@Secured("ROLE_USER")
@GetMapping("showmessage")
public String showMessage(@RequestParam("message_id") long messageId, Model model) {
Message message = messageMapper.findOne(messageId);
if (message == null) {
throw new BusinessException(BusinessCode.MESSAGE_NOT_FOUND);
}
final DateTimeFormatter formatter = dtf.withZone(ZoneId.systemDefault());
final Instant inDate = message.getInDate();
final Long parentId = message.getParent();
final String uid = message.getUser();
final String title = message.getTitle();
final Long pid = message.getProblem();
final long depth = message.getDepth() + 1;
final long thread = message.getThread();
final long order = message.getOrder();
model.addAttribute("title", "Detail of message");
StringBuilder sb = new StringBuilder("<table border=\"0\" width=\"980\" class=\"table-back\">" + "<tr><td>" + "<center><h2><font color=\"blue\">").append(HtmlEscape.escapeHtml4Xml(title)).append("</font></h2></center>" + "Posted by <b><a href=\"userstatus?user_id=").append(uid).append("\"><font color=\"black\">").append(uid).append("</font></a></b>" + "at ").append(formatter.format(inDate));
if (pid != null && pid != 0) {
sb.append("on <b><a href=\"showproblem?problem_id=").append(pid).append("\"><font color=\"black\">Problem ").append(pid).append("</font></a></b>");
}
if (parentId != null && parentId != 0) {
Message parent = messageMapper.findOne(parentId);
if (parent != null) {
String title1 = parent.getTitle();
Instant inDate1 = parent.getInDate();
sb.append("<br/>In Reply To:<a href=\"showmessage?message_id=").append(parentId).append("\"><font color=\"blue\">").append(HtmlEscape.escapeHtml4Xml(title1)).append("</font></a>" + "Posted by:<b><a href=\"userstatus?user_id=").append(parent.getUser()).append("\"><font color=\"black\">").append(parent.getUser()).append("</font></a></b>" + "at ").append(formatter.format(inDate1));
}
}
sb.append("<HR noshade color=#FFF><pre>");
sb.append(HtmlEscape.escapeHtml4Xml(message.getContent()));
sb.append("</pre><HR noshade color=\"#FFF\"><b>Followed by:</b><br/><ul>");
long dep = depth;
List<Message> messages = messageMapper.findAllByThreadIdAndOrderNumGreaterThanOrderByOrderNum(thread, order);
for (Message m : messages) {
String user = m.getUser();
long id = m.getId();
String title1 = m.getTitle();
Instant inDate1 = m.getInDate();
final long depth1 = m.getDepth();
if (depth1 < depth) {
break;
}
for (long i = dep; i < depth1; ++i) {
sb.append("<ul>");
}
for (long i = depth1; i < dep; i++) {
sb.append("</ul>");
}
sb.append("<li><a href=\"showmessage?message_id=").append(id).append("\"><font color=\"blue\">").append(HtmlEscape.escapeHtml4Xml(title1)).append("</font></a>" + " -- <b><a href=\"userstatus?user_id=").append(user).append("\"><font color=\"black\">").append(user).append("</font></a></b> ");
sb.append(formatter.format(inDate1));
dep = depth1;
}
for (long i = depth; i < dep; ++i) {
sb.append("</ul>");
}
sb.append("</ul>" + "<HR noshade color=\"#FFF\">" + "<font color=\"blue\">Post your reply here:</font><br/>" + "<form method=\"POST\" action=\"post\">");
if (pid != null) {
sb.append("<input type=\"hidden\" name=\"problem_id\" value=\"").append(pid).append("\"/>");
}
sb.append("<input type=\"hidden\" name=\"parent_id\" value=\"").append(messageId).append("\"/>");
sb.append("Title:<br/><input type=\"text\" name=\"title\" value=\"").append(HtmlEscape.escapeHtml4Xml(!title.regionMatches(true, 0, "re:", 0, 3) ? "Reply:" + title : title)).append("\" size=75><br/>" + "Content:<br/><textarea rows=\"15\" name=\"content\" cols=\"75\">").append(JudgeUtils.INSTANCE.getReplyString(message.getContent())).append("</textarea><br/><button type=\"submit\">reply</button></td></tr></table>");
model.addAttribute("content", sb.toString());
return "legacy";
}
use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.
the class ExcelUtil method parse.
public static <T> List<T> parse(InputStream inputStream, Class<T> type, @Nonnull Locale locale) {
Objects.requireNonNull(locale, "locale");
boolean support = inputStream.markSupported();
InputStream is = support ? inputStream : new BufferedInputStream(inputStream);
try (Workbook workbook = WorkbookFactory.create(is)) {
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
return parse(workbook, evaluator, type, locale);
} catch (IOException | IllegalStateException ex) {
throw new BusinessException(BusinessCode.INVALID_EXCEL);
}
}
Aggregations