Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.RDFWriter


    }

    private void write (Model parsed, Model expected)
    {
      // This is temporary, until the plumbing with Jena gets released (or ARQ depends on the jena-core SNAPSHOT). See: JENA-135
      RDFWriter writer = new JenaWriterRdfJson() ;
        System.out.println("---- Parsed");
        // parsed.write(System.out, "RDF/JSON") ;
        writer.write(parsed, System.out, baseIRI) ;
        System.out.println("---- Expected");
        // expected.write(System.out, "RDF/JSON") ;
        writer.write(expected, System.out, baseIRI) ;
        System.out.println("--------");
    }
View Full Code Here


    private void testJenaWriterRdfJson()
    {
      Model results = FileManager.get().loadModel(output) ;

        RDFWriter writer = new JenaWriterRdfJson() ;
        ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
        writer.write(results, baos, baseIRI) ;

        // Parse the JSON back to make sure we always write valid JSON
        JSON.parse(new ByteArrayInputStream(baos.toByteArray())) ;

        InputStream in = new ByteArrayInputStream(baos.toByteArray()) ;
        Model model = ModelFactory.createDefaultModel() ;
        RDFReader reader = new JenaReaderRdfJson() ;
        try {
            if ( baseIRI != null )
            {
                Reader r = PeekReader.makeUTF8(in) ;
                reader.read(model, r, baseIRI) ;
            }
            else
                reader.read(model, in, null)

            boolean b = model.isIsomorphicWith(results) ;
            if ( !b )
            {
              write ( model, results ) ;
                System.out.println("---- Parsed");
                // model.write(System.out, "RDF/JSON") ;
                writer.write(model, System.out, baseIRI) ; // for now, until the plumbing with Jena gets released. See JENA-135
                System.out.println("---- Expected");
                // results.write(System.out, "RDF/JSON") ;
                writer.write(results, System.out, baseIRI) ;
                System.out.println("--------");
            }
           
            assertTrue("Models not isomorphic", b) ;
        } catch (RiotParseException ex)
View Full Code Here

      super("save results");
    }
    @Override
        public void runTest()  throws IOException {
      if (logging) {     
        RDFWriter w = testResults.getWriter("RDF/XML-ABBREV");
        w.setProperty("xmlbase",BASE_RESULTS_URI );
        OutputStream out;
        try {
        out = new FileOutputStream("/tmp/rdf-results.rdf");
        }
        catch (Exception e){
          out = System.out;
        }
        w.write(testResults,out,BASE_RESULTS_URI);
        out.close();
      }
    }
View Full Code Here

                SPARQL_ServletBase.error(HttpSC.NOT_ACCEPTABLE_406, msg) ;
            }
           
            TypedInputStream ts = new TypedInputStream(null, mimeType, WebContent.charsetUTF8) ;
            Lang lang = FusekiLib.langFromContentType(ts.getMediaType()) ;
            RDFWriter rdfw = FusekiLib.chooseWriter(lang) ;
                
            if ( rdfw instanceof RDFXMLWriterI )
                rdfw.setProperty("showXmlDeclaration", "true") ;
           
    //        // Write locally to check it's possible.
    //        // Time/space tradeoff.
    //        try {
    //            OutputStream out = new NullOutputStream() ;
    //            rdfw.write(model, out, null) ;
    //            IO.flush(out) ;
    //        } catch (JenaException ex)
    //        {
    //            SPARQL_ServletBase.errorOccurred(ex) ;
    //        }
           
            // Managed to write it locally
            try {
                ResponseResultSet.setHttpResponse(request, response, ts.getMediaType(), ts.getCharset()) ;
                response.setStatus(HttpSC.OK_200) ;
                rdfw.write(model, response.getOutputStream(), null) ;
                response.getOutputStream().flush() ;
            }
            catch (Exception ex) { SPARQL_ServletBase.errorOccurred(ex) ; }
        }
View Full Code Here

            boolean exists = action.getTarget().exists() ;
            if ( ! exists )
                errorNotFound("No such graph: <"+action.getTarget().name+">") ;
            // If we want to set the Content-Length, we need to buffer.
            //response.setContentLength(??) ;
            RDFWriter writer = FusekiLib.chooseWriter(lang) ;
            //action.response.setContentType(getServletInfo())
           
            Model model = ModelFactory.createModelForGraph(action.getTarget().graph()) ;
            writer.write(model, out, null) ;
            success(action) ;
        } finally { action.endRead() ; }
    }
View Full Code Here

    @Test public void ntriples0()
    {
        Model m = ModelFactory.createDefaultModel() ;
        m.getGraph().add(t1) ;
        OutputStream out = new ByteArrayOutputStream() ;
        RDFWriter w = new JenaWriterNTriples2() ;
        w.write(m, out, null) ;
    }
View Full Code Here

            contentType = WebContent.contentTypeTextPlain ;
            charset = WebContent.charsetUTF8 ;
        }

        Lang lang = WebContent.contentTypeToLang(contentType) ;
        RDFWriter rdfw = FusekiLib.chooseWriter(lang) ;

        if ( rdfw instanceof RDFXMLWriterI )
            rdfw.setProperty("showXmlDeclaration", "true") ;

    //        // Write locally to check it's possible.
    //        // Time/space tradeoff.
    //        try {
    //            OutputStream out = new NullOutputStream() ;
    //            rdfw.write(model, out, null) ;
    //            IO.flush(out) ;
    //        } catch (JenaException ex)
    //        {
    //            SPARQL_ServletBase.errorOccurred(ex) ;
    //        }

        try {
            ResponseResultSet.setHttpResponse(request, response, contentType, charset) ;
            response.setStatus(HttpSC.OK_200) ;
            ServletOutputStream out = response.getOutputStream() ;
            rdfw.write(model, out, null) ;
            out.flush() ;
        }
        catch (Exception ex) { SPARQL_ServletBase.errorOccurred(ex) ; }
    }
View Full Code Here

            boolean exists = action.getTarget().exists() ;
            if ( ! exists )
                errorNotFound("No such graph: <"+action.getTarget().name+">") ;
            // If we want to set the Content-Length, we need to buffer.
            //response.setContentLength(??) ;
            RDFWriter writer = FusekiLib.chooseWriter(lang) ;
            String ct = WebContent.mapLangToContentType(lang) ;
            action.response.setContentType(ct) ;
            Graph g = action.getTarget().graph() ;
            Model model = ModelFactory.createModelForGraph(g) ;
            writer.write(model, out, null) ;
            success(action) ;
        } finally { action.endRead() ; }
    }
View Full Code Here

      super("save results");
    }
    @Override
        public void runTest()  throws IOException {
      if (logging) {     
        RDFWriter w = testResults.getWriter("RDF/XML-ABBREV");
        w.setProperty("xmlbase",BASE_RESULTS_URI );
        OutputStream out = System.out ;
        out = new FileOutputStream("/tmp/rdf-results.rdf");
        w.write(testResults,out,BASE_RESULTS_URI);
        out.close();
      }
    }
View Full Code Here

             outputFormat.equals(ResultsFormat.FMT_RDF_N3) ||
             outputFormat.equals(ResultsFormat.FMT_RDF_TTL) )
        {
            Model m = ResultSetFormatter.toModel(results) ;
            m.setNsPrefixes(prologue.getPrefixMapping()) ;
            RDFWriter rdfw = m.getWriter("TURTLE") ;
            m.setNsPrefix("rs", ResultSetGraphVocab.getURI()) ;
            rdfw.write(m, System.out, null) ;
            done = true ;
        }

        if ( outputFormat.equals(ResultsFormat.FMT_RS_XML) )
        {
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.RDFWriter

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.