Ejemplo n.º 1
0
  @Override
  public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {
      String localPath = args[0].getStringValue();
      if (!(localPath.endsWith("/"))) localPath += File.separator;

      //	        Repository localRepo = new FileRepository(localPath + ".git");
      //	        Git git = new Git(localRepo);

      Git git = Git.open(new Resource(localPath), FS);

      MemTreeBuilder builder = context.getDocumentBuilder();

      AttributesImpl attribs = new AttributesImpl();
      attribs.addAttribute(NAMESPACE_URI, "local-path", PREFIX + ":local-path", "CDATA", localPath);

      int nodeNr = builder.startElement(LOG_ELEMENT, attribs);

      for (RevCommit commit : git.log().call()) {
        //                commit.getParentCount();
        //                commit.getParents();

        attribs = new AttributesImpl();
        attribs.addAttribute(NAMESPACE_URI, "id", PREFIX + ":id", "CDATA", commit.name());

        attribs.addAttribute(
            NAMESPACE_URI,
            "time",
            PREFIX + ":time",
            "CDATA",
            String.valueOf(commit.getCommitTime()));

        builder.startElement(COMMIT_ELEMENT, attribs);

        PersonIdent authorIdent = commit.getAuthorIdent();
        builder.startElement(AUTHOR_ELEMENT, null);
        builder.startElement(AUTHOR_NAME_ELEMENT, null);
        builder.characters(authorIdent.getName());
        builder.endElement();
        builder.startElement(AUTHOR_EMAIL_ELEMENT, null);
        builder.characters(authorIdent.getEmailAddress());
        builder.endElement();
        builder.endElement();

        builder.startElement(MESSAGE_ELEMENT, null);
        builder.characters(commit.getFullMessage());
        builder.endElement();

        builder.endElement();
      }

      builder.endElement();

      return builder.getDocument().getNode(nodeNr);
    } catch (Throwable e) {
      throw new XPathException(this, Module.EXGIT001, e);
    }
  }
Ejemplo n.º 2
0
  private NodeImpl writeReport(ValidationReport report, MemTreeBuilder builder) {

    // start root element
    int nodeNr = builder.startElement("", "report", "report", null);

    // validation status: valid or invalid
    builder.startElement("", "status", "status", null);
    if (report.isValid()) {
      builder.characters("valid");
    } else {
      builder.characters("invalid");
    }
    builder.endElement();

    // namespace when available
    if (report.getNamespaceUri() != null) {
      builder.startElement("", "namespace", "namespace", null);
      builder.characters(report.getNamespaceUri());
      builder.endElement();
    }

    // validation duration
    builder.startElement("", "time", "time", null);
    builder.characters("" + report.getValidationDuration());
    builder.endElement();

    // print exceptions if any
    if (report.getThrowable() != null) {
      builder.startElement("", "exception", "exception", null);
      builder.characters("" + report.getThrowable().getMessage());
      builder.endElement();
    }

    // reusable attributes
    AttributesImpl attribs = new AttributesImpl();

    // iterate validation report items, write message
    List cr = report.getValidationReportItemList();
    for (Iterator iter = cr.iterator(); iter.hasNext(); ) {
      ValidationReportItem vri = (ValidationReportItem) iter.next();

      // construct attributes
      attribs.addAttribute("", "level", "level", "CDATA", vri.getTypeText());
      attribs.addAttribute("", "line", "line", "CDATA", Integer.toString(vri.getLineNumber()));
      attribs.addAttribute(
          "", "column", "column", "CDATA", Integer.toString(vri.getColumnNumber()));

      if (vri.getRepeat() > 1) {
        attribs.addAttribute("", "repeat", "repeat", "CDATA", Integer.toString(vri.getRepeat()));
      }

      // write message
      builder.startElement("", "message", "message", attribs);
      builder.characters(vri.getMessage());
      builder.endElement();

      // Reuse attributes
      attribs.clear();
    }

    // finish root element
    builder.endElement();

    // return result
    return ((DocumentImpl) builder.getDocument()).getNode(nodeNr);
  }