@Override public List<ReportReason> decodeReasons(String reasonsString) throws Exception { if (reasonsString != null && !reasonsString.isEmpty()) { try { Node xmlNode = getFirstXmlNode(reasonsString); List<ReportReason> reasons = new LinkedList<ReportReason>(); NodeList reasonNodes = xmlNode.getChildNodes(); for (int i = 0; i < reasonNodes.getLength(); i++) { Node reasonNode = reasonNodes.item(i); if (reasonNode.getNodeType() == Node.ELEMENT_NODE && reasonNode.getNodeName().equals("reason")) { ReportReason reason = new ReportReason(); reason.setLevel(XmlUtils.getNodeAttribute(reasonNode, "level")); reason.setReason(reasonNode.getTextContent()); reasons.add(reason); } } return reasons; } catch (Exception e) { return null; } } return null; }
@Override public String renderReasons(List<ReportReason> reasons) { StringBuffer text = new StringBuffer(); text.append("<reasons>"); for (ReportReason reason : reasons) { text.append("<reason level=\"") .append(StringEscapeUtils.escapeXml(reason.getLevel())) .append("\">") .append(StringEscapeUtils.escapeXml(reason.getReason())) .append("</reason>"); } text.append("</reasons>"); return text.toString(); }