Пример #1
0
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");

    String input = request.getParameter("input");
    String type = request.getParameter("type");
    String graphId = null;
    String stats = "-1";
    String error = null;

    XDIReader xdiReader = XDIReaderRegistry.getAuto();
    Graph graph = graphFactory.openGraph();

    long start = System.currentTimeMillis();

    try {

      xdiReader.read(graph, new StringReader(input));

      graphId = UUID.randomUUID().toString();

      ImageCache.put(graphId, makeImage(graph, type));
      JSONCache.put(graphId, makeJSON(graph));
    } catch (Exception ex) {

      ex.printStackTrace(System.err);
      error = ex.getMessage();
      if (error == null) error = ex.getClass().getName();
    }

    long stop = System.currentTimeMillis();

    stats = "";
    stats += Long.toString(stop - start) + " ms time. ";
    stats +=
        Long.toString(graph.getRootContextNode(true).getAllContextNodeCount() + 1)
            + " context nodes. ";
    stats += Long.toString(graph.getRootContextNode(true).getAllRelationCount()) + " relations. ";
    stats += Long.toString(graph.getRootContextNode(true).getAllLiteralCount()) + " literals. ";
    stats += Long.toString(graph.getRootContextNode(true).getAllStatementCount()) + " statements. ";
    if (xdiReader != null)
      stats +=
          "Input format: "
              + xdiReader.getFormat()
              + ((xdiReader instanceof AutoReader
                      && ((AutoReader) xdiReader).getLastSuccessfulReader() != null)
                  ? " (" + ((AutoReader) xdiReader).getLastSuccessfulReader().getFormat() + ")"
                  : "")
              + ". ";

    graph.close();

    // display results

    request.setAttribute("sampleInputs", Integer.valueOf(sampleInputs.size()));
    request.setAttribute("input", input);
    request.setAttribute("type", type);
    request.setAttribute("graphId", graphId);
    request.setAttribute("stats", stats);
    request.setAttribute("error", error);

    request.getRequestDispatcher("/XDIGrapher.jsp").forward(request, response);
  }
Пример #2
0
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String from = request.getParameter("from");
    String input = request.getParameter("input");
    String output = "";
    String stats = "-1";
    String error = null;

    XDIReader xdiReader = XDIReaderRegistry.forFormat(from, null);
    Graph graph = graphFactory.openGraph();

    try {

      xdiReader.read(graph, new StringReader(input));

      output = "Success!\n";
      /*			output += Integer.toString(Constraints.getAllConstraintCount(graph)) + " constraints found.\n";
      output += Integer.toString(Versioning.getAllVersionListCount(graph)) + " version lists, ";
      output += Integer.toString(Versioning.getAllVersionSnapshotCount(graph)) + " version snapshots and ";
      output += Integer.toString(Versioning.getAllVersionLogCount(graph)) + " version logs found.\n";
      output += Integer.toString(LinkContracts.getAllLinkContractRootCount(graph)) + " link contract roots found. ";
      output += Integer.toString(LinkContracts.getAllLinkContractCount(graph)) + " link contracts found.\n";
      output += Integer.toString(Signatures.getAllSignatureCount(graph)) + " signatures found.";*/
    } catch (Exception ex) {

      log.error(ex.getMessage(), ex);
      error = ex.getMessage();
      if (error == null) error = ex.getClass().getName();
    }

    stats = "";
    stats +=
        Long.toString(graph.getRootContextNode(true).getAllContextNodeCount() + 1)
            + " context nodes. ";
    stats += Long.toString(graph.getRootContextNode(true).getAllRelationCount()) + " relations. ";
    stats += Long.toString(graph.getRootContextNode(true).getAllLiteralCount()) + " literals. ";
    stats += Long.toString(graph.getRootContextNode(true).getAllStatementCount()) + " statements. ";
    if (xdiReader != null)
      stats +=
          "Input format: "
              + xdiReader.getFormat()
              + ((xdiReader instanceof AutoReader
                      && ((AutoReader) xdiReader).getLastSuccessfulReader() != null)
                  ? " (" + ((AutoReader) xdiReader).getLastSuccessfulReader().getFormat() + ")"
                  : "")
              + ". ";

    graph.close();

    // display results

    request.setAttribute("sampleInputs", Integer.valueOf(sampleInputs.size()));
    request.setAttribute("from", from);
    request.setAttribute("input", input);
    request.setAttribute("output", output);
    request.setAttribute("stats", stats);
    request.setAttribute("error", error);

    request.getRequestDispatcher("/XDIValidator.jsp").forward(request, response);
  }