Example #1
0
  /**
   * Used to write Resources for a Subject. Resources will use "ObjectNode" method.
   *
   * @param predicate PredicateNode
   * @param object Literal
   * @param writer PrintWriter
   * @throws GraphException
   */
  protected void writeStatement(
      Graph graph, SubjectNode subject, PredicateNode predicate, Literal object, PrintWriter writer)
      throws GraphException {

    // determine if the Literal has a datatype
    URI datatype = object.getDatatypeURI();

    // Get the lexical form of the literal
    String literalObject = object.getLexicalForm();

    // Create the StringBuffer to hold the resultant string
    StringBuffer buffer = new StringBuffer();

    // Escape the XML string
    StringUtil.quoteAV(literalObject, buffer);

    if (datatype != null) {

      // write as:  <predicateURI rdf:datatype="datatype">"Literal value"
      //           </predicateURI>
      writer.println(
          "    <"
              + this.getURI(predicate)
              + " "
              + RDF_PREFIX
              + ":datatype=\""
              + datatype
              + "\">"
              + buffer.toString()
              + "</"
              + this.getURI(predicate)
              + ">");
    } else {

      // write as:  <predicateURI>"Literal value"</predicateURI>
      writer.println(
          "    <"
              + this.getURI(predicate)
              + ">"
              + buffer.toString()
              + "</"
              + this.getURI(predicate)
              + ">");
    }
  }