Exemplo n.º 1
0
  private ReportNode parse(Node xmlNode) throws Exception {
    if (!"r".equals(xmlNode.getNodeName())) throw new Exception("The report has errors");

    ReportNode rn;

    String classPath = NODE_CLASS_PATH + XmlUtils.getNodeAttribute(xmlNode, "c");

    Class<?> clazz = Class.forName(classPath);
    rn = (ReportNode) clazz.newInstance();

    rn.setIcon(XmlUtils.getNodeAttribute(xmlNode, "i"));
    rn.setLevel(XmlUtils.getNodeAttribute(xmlNode, "l"));
    rn.setTitle(XmlUtils.getChildNodeText(xmlNode, "t"));
    rn.setHint(XmlUtils.getChildNodeText(xmlNode, "h"));

    String time = XmlUtils.getNodeAttribute(xmlNode, "t");
    if (time != null) {
      rn.setDate(new Date(Long.parseLong(time)));
    }

    String debug = XmlUtils.getNodeAttribute(xmlNode, "d");
    if (debug != null) {
      rn.setDebug(Boolean.parseBoolean(debug));
    }

    if (rn instanceof TextReportNode) {
      TextReportNode textNode = (TextReportNode) rn;
      textNode.setDetails(XmlUtils.getChildNodeText(xmlNode, "d"));
    } else if (rn instanceof BranchReportNode) {
      BranchReportNode branchNode = (BranchReportNode) rn;
      Node childrenNodeContainer = XmlUtils.getChildNode(xmlNode, "c");
      branchNode.setChildNodes(new LinkedList<ReportNode>());

      if (childrenNodeContainer != null) {
        NodeList childNodes = childrenNodeContainer.getChildNodes();

        for (int i = 0; i < childNodes.getLength(); i++) {
          Node childNode = childNodes.item(i);
          if (childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getNodeName().equals("r")) {
            branchNode.getChildNodes().add(parse(childNode));
          }
        }
      }
    }
    if (rn instanceof ExceptionReportNode) {
      ExceptionReportNode exceptionNode = (ExceptionReportNode) rn;
      Node exceptionInfoXmlNode = XmlUtils.getChildNode(xmlNode, "e");
      if (exceptionInfoXmlNode != null) {
        exceptionNode.setException(parseExceptionInfo(exceptionInfoXmlNode));
      }
    }

    return rn;
  }
Exemplo n.º 2
0
  private ExceptionInfo parseExceptionInfo(Node xmlNode) {
    ExceptionInfo info = new ExceptionInfo();
    info.setClassName(XmlUtils.getChildNodeText(xmlNode, "n"));
    info.setMessageName(XmlUtils.getChildNodeText(xmlNode, "m"));
    Node stackTraceNode = XmlUtils.getChildNode(xmlNode, "s");
    if (stackTraceNode != null) {
      String stackMore = XmlUtils.getNodeAttribute(stackTraceNode, "more");
      if (stackMore != null) {
        info.setMoreStackTraceElements(Integer.parseInt(stackMore));
      }
      info.setStackTrace(parseStackTrace(stackTraceNode));
    }

    Node causeNode = XmlUtils.getChildNode(xmlNode, "c");
    if (causeNode != null) {
      info.setCause(parseExceptionInfo(causeNode));
    }
    return info;
  }