@Override public String marshallContent(Context context, Iterable<Triple> content, MediaType type) throws ContentTransformationException { try { RDFContext rdfContext = RDFContext.createContext(context.getBase()); rdfContext.setNamespaces(context.getNamespaces()); StringWriter writer = new StringWriter(); rdfContext.serialize(content, Format.JSON_LD, writer); return writer.toString(); } catch (IOException e) { throw new ContentTransformationException("Could not marshall contents",e); } }
@Override public String marshallContent(Context context, Iterable<Triple> content, MediaType type) throws ContentTransformationException { try { RDFContext rdfContext = RDFContext.createContext(context.getBase()); rdfContext.setNamespaces(context.getNamespaces()); StringWriter writer = new StringWriter(); rdfContext.serialize(content, Format.TURTLE, writer); return writer.toString(); } catch (IOException e) { throw new ContentTransformationException("Could not marshall contents",e); } }
@Override public String marshallContent(Context context, Iterable<Triple> content, MediaType type) throws ContentTransformationException { try { RDFContext rdfContext = RDFContext.createContext(context.getBase()); rdfContext.setNamespaces(context.getNamespaces()); StringWriter writer = new StringWriter(); rdfContext.serialize(content, Format.RDF_XML, writer); return writer.toString(); } catch (IOException e) { throw new ContentTransformationException("Could not marshall contents",e); } }
private String serialize(InmutableTripleSet triples, URI baseURI, Namespaces namespaces, Format format) throws IOException { System.out.println( String.format( "Serializing {\n%s,\n%s,\n%s,\n%s\n}", indent("Triples...: {"+LINE_SEPARATOR+indent(triples)+LINE_SEPARATOR+"}"), indent("BaseURI...: "+baseURI), indent("Format....: "+format), indent("Namespaces: "+namespaces) ) ); if(triples==null) { throw new IllegalArgumentException("Object 'triples' cannot be null"); } if(baseURI==null) { throw new IllegalArgumentException("Object 'baseURI' cannot be null"); } if(namespaces==null) { throw new IllegalArgumentException("Object 'namespaces' cannot be null"); } if(format==null) { throw new IllegalArgumentException("Object 'format' cannot be null"); } RDFContext context = RDFContext.createContext(baseURI); context.setNamespaces(namespaces); StringWriter writer = new StringWriter(); context.serialize(triples, format, writer); String serialization = writer.toString(); return serialization; }