Class RDFJSONModWriter


  • public class RDFJSONModWriter
    extends Object

    Support for serializing sets of RDF resources and whole models in JSON.

    In lieu of the W3C standard we are mostly following the Talis format. Unfortunately that doesn't cater for lists in a usable fashion and our primary use case is outputting lists of results. So we extend the Talis format with a value type "list" which is rendered in JSON as an array.

    Author:
    Dave Reynolds
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Set<org.apache.jena.graph.Node> visited  
      protected org.apache.jena.atlas.json.io.JSWriter writer  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void finish()
      Finish the write.
      protected boolean isListNode​(org.apache.jena.graph.Graph g, org.apache.jena.graph.Node n)  
      protected String nodeLabel​(org.apache.jena.graph.Node node)  
      protected void start()  
      void write​(org.apache.jena.graph.Graph graph)
      Write the given graph, not including a resources that have already been visited
      void write​(org.apache.jena.rdf.model.Model model)
      Write the given model, not including a resources that have already been visited
      void write​(org.apache.jena.rdf.model.Resource root, org.apache.jena.rdf.model.Resource page, Iterable<org.apache.jena.rdf.model.Resource> items)
      Write the given ResultPage out with a wrapper object round the graph data showing the root, page and results list.
      protected void writeKeyValue​(String key, long value)  
      protected void writeKeyValue​(String key, String value)  
      protected void writeLiteral​(org.apache.jena.graph.impl.LiteralLabel literal, boolean isFirst)  
      protected void writeNodeValue​(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node node, boolean isFirst)  
      void writeResource​(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node node, boolean recordVisit)
      Write a single graph node
      void writeResource​(org.apache.jena.rdf.model.Resource resource)
      Write a single resource
    • Field Detail

      • visited

        protected Set<org.apache.jena.graph.Node> visited
      • writer

        protected org.apache.jena.atlas.json.io.JSWriter writer
    • Constructor Detail

      • RDFJSONModWriter

        public RDFJSONModWriter​(OutputStream out)
    • Method Detail

      • start

        protected void start()
      • writeResource

        public void writeResource​(org.apache.jena.rdf.model.Resource resource)
        Write a single resource
      • writeResource

        public void writeResource​(org.apache.jena.graph.Graph graph,
                                  org.apache.jena.graph.Node node,
                                  boolean recordVisit)
        Write a single graph node
        Parameters:
        graph - the graph from which to write
        node - the specific node to write out properties for
        recordVisit - if true then this visit will be record to be blocked from an subsequent full write
      • writeNodeValue

        protected void writeNodeValue​(org.apache.jena.graph.Graph graph,
                                      org.apache.jena.graph.Node node,
                                      boolean isFirst)
      • writeLiteral

        protected void writeLiteral​(org.apache.jena.graph.impl.LiteralLabel literal,
                                    boolean isFirst)
      • isListNode

        protected boolean isListNode​(org.apache.jena.graph.Graph g,
                                     org.apache.jena.graph.Node n)
      • writeKeyValue

        protected void writeKeyValue​(String key,
                                     String value)
      • writeKeyValue

        protected void writeKeyValue​(String key,
                                     long value)
      • nodeLabel

        protected String nodeLabel​(org.apache.jena.graph.Node node)
      • write

        public void write​(org.apache.jena.rdf.model.Model model)
        Write the given model, not including a resources that have already been visited
      • write

        public void write​(org.apache.jena.graph.Graph graph)
        Write the given graph, not including a resources that have already been visited
      • write

        public void write​(org.apache.jena.rdf.model.Resource root,
                          org.apache.jena.rdf.model.Resource page,
                          Iterable<org.apache.jena.rdf.model.Resource> items)
        Write the given ResultPage out with a wrapper object round the graph data showing the root, page and results list.
      • finish

        public void finish()
        Finish the write. Not called "close" because it doesn't not close the underlying output stream.