コード例 #1
0
  /**
   * Returns a String representation of an ObjectNode. Object values do not have to be escaped.
   *
   * @param node Node
   * @throws GraphException
   * @return String
   */
  protected String getNodeString(Node node) throws GraphException {

    // value to be returned
    String object = null;

    // determine type of subject node and create uri from it
    if (node != null) {

      try {

        if (node instanceof URIReference) {
          object = ((URIReference) node).getURI().toString();
        } else if (node instanceof BlankNode) {
          object = new URI("#" + ((BlankNode) node).toString()).toString();
        } else if (node instanceof Literal) {
          object = ((Literal) node).getLexicalForm();
        } else {
          object = node.toString();
        }
      } catch (URISyntaxException uriException) {
        throw new GraphException(
            "Could not get String for ObjectNode: " + node + ".", uriException);
      }
    } else {
      throw new GraphException(
          "Could not get String for ObjectNode: " + node + ". ObjectNode is null.");
    }

    return object;
  }
コード例 #2
0
  /**
   * Returns a URI that represents the Node.
   *
   * @param node the node representing the URI.
   * @throws GraphException
   * @return URI
   */
  protected String getURI(Node node) throws GraphException {

    // value to be returned
    String uri = null;

    // determine type of subject node and create uri from it
    if (node != null) {

      try {

        if (node instanceof URIReference) {
          uri = ((URIReference) node).getURI().toString();
        } else if (node instanceof BlankNode) {
          uri = new URI("#" + ((BlankNode) node).toString()).toString();
        } else {
          uri = node.toString();
        }
      } catch (URISyntaxException uriException) {
        throw new GraphException("Could not get URI for Node: " + node + ".", uriException);
      }
    } else {
      throw new GraphException("Could not get URI for Node: " + node + ". Node is null.");
    }

    // return the URI with any namespaces replaced with prefixes
    return this.replaceNamespace(uri);
  }
コード例 #3
0
 @FixFor("MODE-1254")
 @Test
 public void shouldNotIncludeBinaryContentsInToString() throws Exception {
   altima = cache.findJcrNode(null, path("/Cars/Hybrid/Nissan Altima"));
   Node node = rootNode.addNode("nodeWithBinaryProperty", "nt:unstructured");
   String value = "This is the string value";
   Binary binaryValue =
       cache.session().getValueFactory().createBinary(new ByteArrayInputStream(value.getBytes()));
   node.setProperty("binProp", binaryValue);
   String toString = node.toString();
   assertThat(toString.indexOf("**binary-value") > 0, is(true));
 }