예제 #1
0
  static {
    graphFactory = MemoryGraphFactory.getInstance();
    graphFactory.setSortmode(MemoryGraphFactory.SORTMODE_ORDER);

    sampleInputs = new ArrayList<String>();

    while (true) {

      InputStream inputStream =
          XDIGrapher.class.getResourceAsStream("graph" + (sampleInputs.size() + 1) + ".xdi");
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      int i;

      try {

        while ((i = inputStream.read()) != -1) outputStream.write(i);
        sampleInputs.add(new String(outputStream.toByteArray()));
      } catch (Exception ex) {

        break;
      } finally {

        try {
          inputStream.close();
        } catch (Exception ex) {
        }
        try {
          outputStream.close();
        } catch (Exception ex) {
        }
      }
    }
  }
예제 #2
0
  static {
    graphFactory = MemoryGraphFactory.getInstance();
    graphFactory.setSortmode(MemoryGraphFactory.SORTMODE_ORDER);

    sampleInputs = Collections.singletonList("=alice");

    sampleEndpoint = XDIDiscoveryClient.DEFAULT_XDI_CLIENT.getXdiEndpointUri().toString();

    sampleServices =
        XDIClientConstants.WEBSOCKET_ENDPOINT_URI_TYPE.toString()
            + " "
            + XDIClientConstants.CONNECT_ENDPOINT_URI_TYPE.toString();
  }
예제 #3
0
  public void testLocalRoots() throws Exception {

    Graph graph = MemoryGraphFactory.getInstance().openGraph();

    assertEquals(XdiLocalRoot.findLocalRoot(graph).getContextNode(), graph.getRootContextNode());
    assertEquals(
        XdiLocalRoot.findLocalRoot(graph).getContextNode().getXri(), XDIConstants.XRI_S_CONTEXT);

    graph.close();
  }
예제 #4
0
  public void testSubGraph() throws Exception {

    Graph graph = MemoryGraphFactory.getInstance().openGraph();
    XdiCommonRoot localRoot = XdiCommonRoot.findCommonRoot(graph);
    XdiPeerRoot peerRoot =
        localRoot.getPeerRoot(
            XDIAddress.create("=!:uuid:91f28153-f600-ae24-91f2-8153f600ae24"), true);
    XdiInnerRoot innerRoot =
        peerRoot.getInnerRoot(XDIAddress.create("=!1111"), XDIAddress.create("$add"), true);

    assertTrue(
        XdiAbstractContext.fromContextNode(localRoot.getContextNode()) instanceof XdiCommonRoot);
    assertTrue(
        XdiAbstractContext.fromContextNode(peerRoot.getContextNode()) instanceof XdiPeerRoot);
    assertTrue(
        XdiAbstractContext.fromContextNode(innerRoot.getContextNode()) instanceof XdiInnerRoot);

    graph.close();
  }
예제 #5
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);
  }
예제 #6
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);
  }
예제 #7
0
  public void testTypes() throws Exception {

    Graph graph = MemoryGraphFactory.getInstance().openGraph();
    ContextNode contextNode = graph.getRootContextNode().setContextNode(XDIArc.create("=markus"));

    XDIAddress type1 = XDIAddress.create("#employee");
    XDIAddress type2 = XDIAddress.create("#person");
    XDIAddress type3 = XDIAddress.create("#developer");

    Dictionary.setContextNodeType(contextNode, type1);
    assertEquals(Dictionary.getContextNodeType(contextNode), type1);
    assertEquals(new IteratorCounter(Dictionary.getContextNodeTypes(contextNode)).count(), 1);
    assertTrue(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type1)
            .contains());
    assertTrue(Dictionary.isContextNodeType(contextNode, type1));

    Dictionary.setContextNodeType(contextNode, type2);
    assertEquals(new IteratorCounter(Dictionary.getContextNodeTypes(contextNode)).count(), 2);
    assertTrue(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type1)
            .contains());
    assertTrue(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type2)
            .contains());
    assertTrue(Dictionary.isContextNodeType(contextNode, type1));
    assertTrue(Dictionary.isContextNodeType(contextNode, type2));

    Dictionary.setContextNodeType(contextNode, type3);
    assertEquals(new IteratorCounter(Dictionary.getContextNodeTypes(contextNode)).count(), 3);
    assertTrue(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type1)
            .contains());
    assertTrue(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type2)
            .contains());
    assertTrue(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type3)
            .contains());
    assertTrue(Dictionary.isContextNodeType(contextNode, type1));
    assertTrue(Dictionary.isContextNodeType(contextNode, type2));
    assertTrue(Dictionary.isContextNodeType(contextNode, type3));

    Dictionary.delContextNodeType(contextNode, type2);
    assertEquals(new IteratorCounter(Dictionary.getContextNodeTypes(contextNode)).count(), 2);
    assertTrue(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type1)
            .contains());
    assertFalse(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type2)
            .contains());
    assertTrue(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type3)
            .contains());
    assertTrue(Dictionary.isContextNodeType(contextNode, type1));
    assertFalse(Dictionary.isContextNodeType(contextNode, type2));
    assertTrue(Dictionary.isContextNodeType(contextNode, type3));

    Dictionary.replaceContextNodeType(contextNode, type3);
    assertEquals(Dictionary.getContextNodeType(contextNode), type3);
    assertEquals(new IteratorCounter(Dictionary.getContextNodeTypes(contextNode)).count(), 1);
    assertFalse(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type1)
            .contains());
    assertFalse(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type2)
            .contains());
    assertTrue(
        new IteratorContains<XDIAddress>(Dictionary.getContextNodeTypes(contextNode), type3)
            .contains());
    assertFalse(Dictionary.isContextNodeType(contextNode, type1));
    assertFalse(Dictionary.isContextNodeType(contextNode, type2));
    assertTrue(Dictionary.isContextNodeType(contextNode, type3));

    graph.close();
  }