コード例 #1
0
  /**
   * Writes the opening RDF tag (with namespaces) to the print Writer.
   *
   * @param out PrintWriter
   * @throws IOException
   */
  protected void writeRDFHeader(PrintWriter out) throws IOException {

    // validate
    if (out != null) {

      // print opening RDF tag (including namespaces)
      out.print("<rdf:RDF ");

      // print namespaces
      Set<String> keys = namespaces.keySet();

      if (keys != null) {

        for (String currentKey : keys) {
          String currentValue = namespaces.get(currentKey);

          if ((currentKey != null) && (currentValue != null)) {

            // use entities: xmlns:ns="&ns;"
            out.print(NEWLINE + "  xmlns:" + currentKey + "=\"&" + currentKey + ";\"");
          }
        }
      }

      // close the opening tag (add a space for readability)
      out.print(">" + NEWLINE + NEWLINE);
    } else {

      throw new IllegalArgumentException("Cannot write to null Writer.");
    }
  }
コード例 #2
0
  /**
   * Writes the XML Entities (used for namespaces) to the print Writer.
   *
   * @param out PrintWriter
   * @throws IOException
   */
  protected void writeXMLEntities(PrintWriter out) throws IOException {

    // validate
    if (out != null) {

      // print opening DOCTYPE DECLARATION tag
      out.print(NEWLINE + "<!DOCTYPE rdf:RDF [");

      // print namespaces
      Set<String> keys = namespaces.keySet();

      if (keys != null) {

        for (String currentKey : keys) {
          String currentValue = namespaces.get(currentKey);

          if ((currentKey != null) && (currentValue != null)) {

            // write as: <!ENTITY ns 'http://example.org/abc#'>
            out.print(NEWLINE + "  <!ENTITY " + currentKey + " '" + currentValue + "'>");
          }
        }
      }

      // close the opening tag (add a space for readability)
      out.print("]>" + NEWLINE + NEWLINE);
    } else {

      throw new IllegalArgumentException("Cannot write to null Writer.");
    }
  }
コード例 #3
0
  /**
   * Writes the opening tag for the subject
   *
   * @param graph JRDFGraph
   * @param subject SubjectNode
   * @param writer PrintWriter
   * @throws GraphException
   */
  protected void writeClosingTag(Graph graph, BlankNode subject, PrintWriter writer)
      throws GraphException {

    ObjectNode subjectType = this.getSubjectType(graph, subject);

    // only display as a subject if it can be found
    if (subjectType != null) {

      // closing tag
      writer.print("  </" + this.getURI(subjectType) + ">" + NEWLINE);
    } else {

      // closing tag
      writer.print("  </" + RDF_PREFIX + ":Description>" + NEWLINE);
    }
  }
コード例 #4
0
  /**
   * Writes the opening tag for the subject
   *
   * @param graph JRDFGraph
   * @param subject SubjectNode
   * @param writer PrintWriter
   * @throws GraphException
   */
  protected void writeOpeningTag(Graph graph, SubjectNode subject, PrintWriter writer)
      throws GraphException {

    if (writer != null) {

      // write the subject type and rdf:about
      if (subject != null) {

        // open tag - BlankNodes are a special case
        if (subject instanceof BlankNode) {

          this.writeOpeningTag(graph, (BlankNode) subject, writer);
        } else {

          writer.print(
              "  <"
                  + RDF_PREFIX
                  + ":Description "
                  + RDF_PREFIX
                  + ":about=\""
                  + this.getNodeString(subject)
                  + "\">"
                  + NEWLINE);
        }
      } else {
        throw new IllegalArgumentException(
            "Could not write opening tag for subject. Subject Node is null.");
      }
    }
  }
コード例 #5
0
  /**
   * Writes the opening tag for the subject
   *
   * @param graph JRDFGraph
   * @param subject SubjectNode
   * @param writer PrintWriter
   * @throws GraphException
   */
  protected void writeClosingTag(Graph graph, SubjectNode subject, PrintWriter writer)
      throws GraphException {

    // Blank Nodes are written differently
    if (subject instanceof BlankNode) {

      this.writeClosingTag(graph, (BlankNode) subject, writer);
    } else {

      // closing tag
      writer.print("  </" + RDF_PREFIX + ":Description>" + NEWLINE);
    }
  }