public String getContentType() { return mediaType == null ? null : mediaType.getContentType() ; } public String getCharset() { return mediaType == null ? null : mediaType.getCharset() ; }
public static boolean isHtmlForm(ContentType ct) { if ( ct == null ) return false ; return contentTypeHTMLForm.equalsIgnoreCase(ct.getContentType()) ; }
public static boolean isMultiPartForm(ContentType ct) { return contentTypeMultipartFormData.equalsIgnoreCase(ct.getContentType()) ; }
/** Match content type (ignores charsets and other parameters) */ public static boolean matchContentType(ContentType ct1, ContentType ct2) { if ( ct1 == null || ct2 == null ) return false ; return matchContentType(ct1.getContentType(), ct2.getContentType()) ; }
/** Map a content type (without charset) to a {@link Lang} */ public static Lang contentTypeToLang(ContentType ct) { if ( ct == null ) return null ; String key = canonicalKey(ct.getContentType()) ; return mapContentTypeToLang.get(key) ; }
/** Map a content type (without charset) to a {@link Lang} */ public static Lang contentTypeToLang(ContentType ct) { if ( ct == null ) return null ; String key = canonicalKey(ct.getContentType()) ; return mapContentTypeToLang.get(key) ; }
protected HttpEntity fileToHttpEntity(String filename, Lang lang) { // Leave RDF/XML to the XML parse, else it's UTF-8. String charset = (lang.equals(Lang.RDFXML) ? null : WebContent.charsetUTF8); // HttpClient Content type. ContentType ct = ContentType.create(lang.getContentType().getContentType(), charset); // Repeatable. return new FileEntity(new File(filename), ct); }
protected HttpEntity fileToHttpEntity(String filename, Lang lang) { // Leave RDF/XML to the XML parse, else it's UTF-8. String charset = (lang.equals(Lang.RDFXML) ? null : WebContent.charsetUTF8); // HttpClient Content type. ContentType ct = ContentType.create(lang.getContentType().getContentType(), charset); // Repeatable. return new FileEntity(new File(filename), ct); }
/** * Return {@link RDFSyntax} corresponding to a Jena {@link Lang}. * * @param lang * {@link Lang} to convert * @return Matched {@link RDFSyntax}, otherwise {@link Optional#empty()} */ public Optional<RDFSyntax> asRDFSyntax(final Lang lang) { return RDFSyntax.byMediaType(lang.getContentType().getContentType()); }
public NeedEvent(String uri, String wonNodeUri, TYPE eventType, long crawlDate, String resource, Lang format) { this.uri = uri; this.wonNodeUri = wonNodeUri; this.eventType = eventType; this.crawlDate = crawlDate; serializedNeedResource = resource; serializationLangName = format.getName(); serializationLangContentType = format.getContentType().getContentType(); }
public NeedEvent(String uri, String wonNodeUri, TYPE eventType, long crawlDate, Dataset ds) { this.uri = uri; this.wonNodeUri = wonNodeUri; this.eventType = eventType; this.crawlDate = crawlDate; StringWriter sw = new StringWriter(); RDFDataMgr.write(sw, ds, RDFFormat.TRIG.getLang()); serializedNeedResource = sw.toString(); serializationLangName = RDFFormat.TRIG.getLang().getName(); serializationLangContentType = RDFFormat.TRIG.getLang().getContentType().getContentType(); }
/** Create an HttpEntity for the graph */ protected HttpEntity graphToHttpEntity(Graph graph, RDFFormat syntax) { EntityTemplate entity = new EntityTemplate((out)->RDFDataMgr.write(out, graph, syntax)); String ct = syntax.getLang().getContentType().getContentType(); entity.setContentType(ct); return entity; }
/** Create an HttpEntity for the dataset */ protected HttpEntity datasetToHttpEntity(DatasetGraph dataset, RDFFormat syntax) { EntityTemplate entity = new EntityTemplate((out)->RDFDataMgr.write(out, dataset, syntax)); String ct = syntax.getLang().getContentType().getContentType(); entity.setContentType(ct); return entity; }
/** Create an HttpEntity for the dataset */ protected HttpEntity datasetToHttpEntity(DatasetGraph dataset, RDFFormat syntax) { EntityTemplate entity = new EntityTemplate((out)->RDFDataMgr.write(out, dataset, syntax)); String ct = syntax.getLang().getContentType().getContentType(); entity.setContentType(ct); return entity; }
/** Create an HttpEntity for the graph */ protected HttpEntity graphToHttpEntity(Graph graph, RDFFormat syntax) { EntityTemplate entity = new EntityTemplate((out)->RDFDataMgr.write(out, graph, syntax)); String ct = syntax.getLang().getContentType().getContentType(); entity.setContentType(ct); return entity; }
private static void process(StreamRDF destination, Reader in, String baseUri, Lang lang, Context context ) { // Not as good as from an InputStream ContentType ct = determineCT(baseUri, null, lang) ; if ( ct == null ) throw new RiotException("Failed to determine the content type: (URI="+baseUri+" : hint="+lang+")") ; ReaderRIOT reader = getReader(ct) ; if ( reader == null ) throw new RiotException("No parser registered for content type: "+ct.getContentType()) ; reader.read(in, baseUri, ct, destination, context) ; }
private static void process(StreamRDF destination, TypedInputStream in, String baseUri, Lang hintLang, Context context) { ContentType ct = determineCT(baseUri, in.getContentType(), hintLang) ; if ( ct == null ) throw new RiotException("Failed to determine the content type: (URI="+baseUri+" : stream="+in.getContentType()+" : hint="+hintLang+")") ; ReaderRIOT reader = getReader(ct) ; if ( reader == null ) throw new RiotException("No parser registered for content type: "+ct.getContentType()) ; reader.read(in, baseUri, ct, destination, context) ; }
/** Create an HttpEntity for the graph */ protected static HttpEntity graphToHttpEntity(final Graph graph) { final RDFFormat syntax = RDFFormat.TURTLE_BLOCKS ; ContentProducer producer = new ContentProducer() { @Override public void writeTo(OutputStream out) { RDFDataMgr.write(out, graph, syntax) ; } } ; EntityTemplate entity = new EntityTemplate(producer) ; ContentType ct = syntax.getLang().getContentType() ; entity.setContentType(ct.getContentType()) ; return entity ; }
/** Create an HttpEntity for the graph */ protected static HttpEntity graphToHttpEntity(final Graph graph) { final RDFFormat syntax = RDFFormat.TURTLE_BLOCKS ; ContentProducer producer = new ContentProducer() { @Override public void writeTo(OutputStream out) { RDFDataMgr.write(out, graph, syntax) ; } } ; EntityTemplate entity = new EntityTemplate(producer) ; ContentType ct = syntax.getLang().getContentType() ; entity.setContentType(ct.getContentType()) ; return entity ; }
@Test public void jenaSystem_basic_1() { assertEquals("name", "JSON-LD", JenaJSONLD.JSONLD.getName()); assertEquals("content-type", "application/ld+json", JenaJSONLD.JSONLD.getContentType() .getContentType()); }