private ReaderRIOT createReader(ContentType ct) { Lang lang = RDFLanguages.contentTypeToLang(ct); if ( lang == null ) return null; @SuppressWarnings("deprecation") ReaderRIOTFactory r = RDFParserRegistry.getFactory(lang); if ( r == null ) return null; ReaderRIOT reader = createReader(r, lang); return reader ; }
/** Parse when there is no URI to guide the choice of syntax */ private void parseNotUri(StreamRDF destination) { // parse from bytes or chars, no indication of the syntax from the source. Lang lang = hintLang; if ( forceLang != null ) lang = forceLang; ContentType ct = WebContent.determineCT(null, lang, baseUri); if ( ct == null ) throw new RiotException("Failed to determine the RDF syntax (.lang or .base required)"); ReaderRIOT readerRiot = createReader(ct); if ( readerRiot == null ) throw new RiotException("No parser registered for content type: " + ct.getContentType()); Reader jr = javaReader; if ( content != null ) jr = new StringReader(content); read(readerRiot, inputStream, jr, baseUri, context, ct, destination); }
/** Parse when there is a URI to guide the choice of syntax */ private void parseURI(StreamRDF destination) { // Source by uri or path. try (TypedInputStream input = openTypedInputStream(uri, path)) { ReaderRIOT reader; ContentType ct; if ( forceLang != null ) { @SuppressWarnings("deprecation") ReaderRIOTFactory r = RDFParserRegistry.getFactory(forceLang); if ( r == null ) throw new RiotException("No parser registered for language: " + forceLang); ct = forceLang.getContentType(); reader = createReader(r, forceLang); } else { // No forced language. // Conneg and hint, ignoring text/plain. ct = WebContent.determineCT(input.getContentType(), hintLang, baseUri); if ( ct == null ) throw new RiotException("Failed to determine the content type: (URI=" + baseUri + " : stream=" + input.getContentType()+")"); reader = createReader(ct); if ( reader == null ) throw new RiotException("No parser registered for content type: " + ct.getContentType()); } read(reader, input, null, baseUri, context, ct, destination); } }