Package org.openrdf.rio

Examples of org.openrdf.rio.RDFHandlerException


      flush();

      writer.endRDF();
    }
    catch (IOException e) {
      throw new RDFHandlerException(e);
    }
    finally {
      writingStarted = false;
      headerWritten = false;
    }
View Full Code Here


      flush();

      writer.handleComment(comment);
    }
    catch (IOException e) {
      throw new RDFHandlerException(e);
    }
  }
View Full Code Here

  public void startRDF()
    throws RDFHandlerException
  {
    if (writingStarted) {
      throw new RDFHandlerException("Document writing has already started");
    }

    try {
      xmlWriter.startDocument();

      xmlWriter.setAttribute("xmlns", NAMESPACE);
      xmlWriter.startTag(ROOT_TAG);
    }
    catch (IOException e) {
      throw new RDFHandlerException(e);
    }
    finally {
      writingStarted = true;
    }
  }
View Full Code Here

  public void endRDF()
    throws RDFHandlerException
  {
    if (!writingStarted) {
      throw new RDFHandlerException("Document writing has not yet started");
    }

    try {
      if (inActiveContext) {
        xmlWriter.endTag(CONTEXT_TAG);
        inActiveContext = false;
        currentContext = null;
      }
      xmlWriter.endTag(ROOT_TAG);
      xmlWriter.endDocument();
    }
    catch (IOException e) {
      throw new RDFHandlerException(e);
    }
    finally {
      writingStarted = false;
    }
  }
View Full Code Here

  public void handleStatement(Statement st)
    throws RDFHandlerException
  {
    if (!writingStarted) {
      throw new RDFHandlerException("Document writing has not yet been started");
    }

    try {
      Resource context = st.getContext();

      if (inActiveContext && !contextsEquals(context, currentContext)) {
        // Close currently active context
        xmlWriter.endTag(CONTEXT_TAG);
        inActiveContext = false;
      }

      if (!inActiveContext) {
        // Open new context
        xmlWriter.startTag(CONTEXT_TAG);

        if (context != null) {
          writeValue(context);
        }

        currentContext = context;
        inActiveContext = true;
      }

      xmlWriter.startTag(TRIPLE_TAG);

      writeValue(st.getSubject());
      writeValue(st.getPredicate());
      writeValue(st.getObject());

      xmlWriter.endTag(TRIPLE_TAG);
    }
    catch (IOException e) {
      throw new RDFHandlerException(e);
    }
  }
View Full Code Here

  {
    try {
      xmlWriter.comment(comment);
    }
    catch (IOException e) {
      throw new RDFHandlerException(e);
    }
  }
View Full Code Here

        }
        xmlWriter.textElement(PLAIN_LITERAL_TAG, literal.getLabel());
      }
    }
    else {
      throw new RDFHandlerException("Unknown value type: " + value.getClass());
    }
  }
View Full Code Here

      writeEndTag(RDF.NAMESPACE, "RDF");

      writer.flush();
    }
    catch (IOException e) {
      throw new RDFHandlerException(e);
    }
    finally {
      writingStarted = false;
      headerWritten = false;
    }
View Full Code Here

    // Verify that an XML namespace-qualified name can be created for the
    // predicate
    String predString = pred.toString();
    int predSplitIdx = XMLUtil.findURISplitIndex(predString);
    if (predSplitIdx == -1) {
      throw new RDFHandlerException("Unable to create XML namespace-qualified name for predicate: "
          + predString);
    }

    String predNamespace = predString.substring(0, predSplitIdx);
    String predLocalName = predString.substring(predSplitIdx);

    try {
      if (!headerWritten) {
        writeHeader();
      }

      // SUBJECT
      if (!subj.equals(lastWrittenSubject)) {
        flushPendingStatements();

        // Write new subject:
        writeNewLine();
        writeStartOfStartTag(RDF.NAMESPACE, "Description");
        if (subj instanceof BNode) {
          BNode bNode = (BNode)subj;
          writeAttribute(RDF.NAMESPACE, "nodeID", bNode.getID());
        }
        else {
          URI uri = (URI)subj;
          writeAttribute(RDF.NAMESPACE, "about", uri.toString());
        }
        writeEndOfStartTag();
        writeNewLine();

        lastWrittenSubject = subj;
      }

      // PREDICATE
      writeIndent();
      writeStartOfStartTag(predNamespace, predLocalName);

      // OBJECT
      if (obj instanceof Resource) {
        Resource objRes = (Resource)obj;

        if (objRes instanceof BNode) {
          BNode bNode = (BNode)objRes;
          writeAttribute(RDF.NAMESPACE, "nodeID", bNode.getID());
        }
        else {
          URI uri = (URI)objRes;
          writeAttribute(RDF.NAMESPACE, "resource", uri.toString());
        }

        writeEndOfEmptyTag();
      }
      else if (obj instanceof Literal) {
        Literal objLit = (Literal)obj;

        // language attribute
        if (objLit.getLanguage() != null) {
          writeAttribute("xml:lang", objLit.getLanguage());
        }

        // datatype attribute
        boolean isXMLLiteral = false;
        URI datatype = objLit.getDatatype();
        if (datatype != null) {
          // Check if datatype is rdf:XMLLiteral
          isXMLLiteral = datatype.equals(RDF.XMLLITERAL);

          if (isXMLLiteral) {
            writeAttribute(RDF.NAMESPACE, "parseType", "Literal");
          }
          else {
            writeAttribute(RDF.NAMESPACE, "datatype", datatype.toString());
          }
        }

        writeEndOfStartTag();

        // label
        if (isXMLLiteral) {
          // Write XML literal as plain XML
          writer.write(objLit.getLabel());
        }
        else {
          writeCharacterData(objLit.getLabel());
        }

        writeEndTag(predNamespace, predLocalName);
      }

      writeNewLine();

      // Don't write </rdf:Description> yet, maybe the next statement
      // has the same subject.
    }
    catch (IOException e) {
      throw new RDFHandlerException(e);
    }
  }
View Full Code Here

      writer.write(comment);
      writer.write(" -->");
      writeNewLine();
    }
    catch (IOException e) {
      throw new RDFHandlerException(e);
    }
  }
View Full Code Here

TOP

Related Classes of org.openrdf.rio.RDFHandlerException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.