Package org.openrdf.rio

Examples of org.openrdf.rio.RDFParser


    throws RDFHandlerException, IOException, RDFParseException, NoCompatibleMediaType
  {
    String mimeType = readContentType();
    try {
      RDFFormat format = RDFParserRegistry.getInstance().getFileFormatForMIMEType(mimeType);
      RDFParser parser = Rio.createParser(format, pool.getValueFactory());
      parser.setPreserveBNodeIDs(true);
      parser.setRDFHandler(handler);
      parser.parse(getResponseBodyAsStream(), method.getURI().getURI());
    }
    catch (UnsupportedRDFormatException e) {
      logger.warn(e.toString(), e);
      throw new NoCompatibleMediaType("Server responded with an unsupported file format: " + mimeType);
    }
View Full Code Here


      URL dataURL = new URL(dataPath);
      RDFFormat format = Rio.getParserFormatForFileName(dataPath, RDFFormat.RDFXML);

      writeln("RDF Format is " + format.getName());

      RDFParser parser = Rio.createParser(format);
      VerificationListener listener = new VerificationListener();
      parser.setDatatypeHandling(RDFParser.DatatypeHandling.VERIFY);
      parser.setVerifyData(true);
      parser.setParseErrorListener(listener);
      parser.setRDFHandler(listener);

      writeln("Verifying data...");
      InputStream in = dataURL.openStream();
      try {
        parser.parse(in, "urn://openrdf.org/RioVerifier/");
      }
      finally {
        in.close();
      }
View Full Code Here

   */
  protected void addInputStreamOrReader(Object inputStreamOrReader, String baseURI, RDFFormat dataFormat,
      Resource... contexts)
    throws IOException, RDFParseException, StoreException
  {
    RDFParser rdfParser = Rio.createParser(dataFormat, getValueFactory());

    rdfParser.setVerifyData(true);
    rdfParser.setStopAtFirstError(true);
    rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);

    RDFInserter rdfInserter = new RDFInserter(this);
    rdfInserter.enforceContext(contexts);
    rdfParser.setRDFHandler(rdfInserter);

    boolean autoCommit = isAutoCommit();
    if (autoCommit) {
      // Add the stream in a single transaction
      begin();
    }

    try {
      if (inputStreamOrReader instanceof InputStream) {
        rdfParser.parse((InputStream)inputStreamOrReader, baseURI);
      }
      else if (inputStreamOrReader instanceof Reader) {
        rdfParser.parse((Reader)inputStreamOrReader, baseURI);
      }
      else {
        throw new IllegalArgumentException(
            "inputStreamOrReader must be an InputStream or a Reader, is a: "
                + inputStreamOrReader.getClass());
View Full Code Here

          logger.warn("Unsupported RDF format: {}", url.getFile());
          continue;
        }

        try {
          RDFParser parser = Rio.createParser(format);
          parser.setRDFHandler(new Collector(model, url.toString()));

          InputStream stream = url.openStream();
          try {
            parser.parse(stream, url.toString());
          }
          catch (RDFParseException e) {
            logger.warn(e.toString(), e);
            continue;
          }
View Full Code Here

    if (format == null) {
      throw new IOException("Unsupported file format: " + url.getFile());
    }

    try {
      RDFParser parser = Rio.createParser(format);

      Model statements = new LinkedHashModel();
      parser.setRDFHandler(new StatementCollector(statements));

      InputStream stream = url.openStream();
      try {
        parser.parse(stream, url.toString());
      }
      catch (RDFHandlerException e) {
        throw new AssertionError(e);
      }
      finally {
View Full Code Here

  private Model loadConfig(File file)
    throws StoreConfigException
  {
    try {
      RDFFormat format = Rio.getParserFormatForFileName(file.getName());
      RDFParser parser = Rio.createParser(format);

      Model model = new LinkedHashModel();
      parser.setRDFHandler(new StatementCollector(model));

      InputStream stream = new FileInputStream(file);
      try {
        parser.parse(stream, file.toURI().toString());
      }
      catch (RDFHandlerException e) {
        throw new AssertionError(e);
      }
      finally {
View Full Code Here

    InputStream in = url.openStream();

    try {
      final ValueFactory vf = con.getValueFactory();
      RDFParser rdfParser = new TurtleParser();
      rdfParser.setValueFactory(vf);

      rdfParser.setVerifyData(false);
      rdfParser.setStopAtFirstError(true);
      rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);

      RDFInserter rdfInserter = new RDFInserter(con);
      rdfInserter.enforceContext(contexts);
      rdfParser.setRDFHandler(rdfInserter);

      con.begin();
      try {
        rdfParser.parse(in, baseURI);
        con.commit();
      }
      catch (RDFHandlerException e) {
        con.rollback();
        // RDFInserter only throws wrapped StoreExceptions
View Full Code Here

    RepositoryConnection con = dataRep.getConnection();

    con.begin();
    try {
      RDFFormat rdfFormat = Rio.getParserFormatForFileName(graphURI.toString(), RDFFormat.TURTLE);
      RDFParser rdfParser = Rio.createParser(rdfFormat, con.getValueFactory());
      rdfParser.setVerifyData(false);
      rdfParser.setDatatypeHandling(DatatypeHandling.IGNORE);
      // rdfParser.setPreserveBNodeIDs(true);

      RDFInserter rdfInserter = new RDFInserter(con);
      rdfInserter.enforceContext(context);
      rdfParser.setRDFHandler(rdfInserter);

      URL graphURL = new URL(graphURI.toString());
      InputStream in = graphURL.openStream();
      try {
        rdfParser.parse(in, graphURI.toString());
      }
      finally {
        in.close();
      }
View Full Code Here

    throws Exception
  {
    RDFFormat rdfFormat = Rio.getParserFormatForFileName(resultFileURL);

    if (rdfFormat != null) {
      RDFParser parser = Rio.createParser(rdfFormat);
      parser.setDatatypeHandling(DatatypeHandling.IGNORE);
      parser.setPreserveBNodeIDs(true);

      Set<Statement> result = new LinkedHashSet<Statement>();
      parser.setRDFHandler(new StatementCollector(result));

      InputStream in = new URL(resultFileURL).openStream();
      try {
        parser.parse(in, resultFileURL);
      }
      finally {
        in.close();
      }
View Full Code Here

  {
    String mimeType = entity.getMediaType().getName();
    RDFFormat rdfFormat = Rio.getParserFormatForMIMEType(mimeType);

    try {
      RDFParser parser = Rio.createParser(rdfFormat);

      Model model = new LinkedHashModel();
      parser.setRDFHandler(new StatementCollector(model));

      parser.parse(entity.getStream(), "");

      return model;
    }
    catch (UnsupportedRDFormatException e) {
      throw new ResourceException(CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE,
View Full Code Here

TOP

Related Classes of org.openrdf.rio.RDFParser

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.