@Override protected void perform(HttpAction action) { ContentType ct = ActionLib.getContentType(action) ; if ( ct == null ) ct = ctSPARQLUpdate ; if ( matchContentType(ctSPARQLUpdate, ct) ) { executeBody(action) ; return ; } if ( isHtmlForm(ct) ) { executeForm(action) ; return ; } ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + action.request.getContentType()) ; }
private void testCanonicalise(String input, String expected) { String canonical = WebContent.contentTypeCanonical(input); Assert.assertEquals(expected, canonical); }
/** Determine the Lang, given the URI target, any content type header string and a hint */ public static Lang determineLang(String target, String ctStr, Lang hintLang) { ContentType ct = WebContent.determineCT(ctStr, hintLang, target) ; if ( ct == null ) return hintLang ; Lang lang = RDFLanguages.contentTypeToLang(ct) ; if (lang == null ) return hintLang ; return lang ; }
private static boolean isRDF(final MediaType requestContentType) { if (requestContentType == null) { return false; } final ContentType ctRequest = create(requestContentType.toString()); // Text files and CSV files are not considered RDF to Fedora, though CSV is a valid // RDF type to Jena (although deprecated). if (matchContentType(ctRequest, ctTextPlain) || matchContentType(ctRequest, ctTextCSV)) { return false; } // SPARQL updates are done on containers. return isRdfContentType(requestContentType.toString()) || matchContentType(ctRequest, ctSPARQLUpdate); }
StreamRDF dest = StreamRDFLib.graph(model.getGraph()) ; if ( hasParams || WebContent.isHtmlForm(ct) ) assemblerFromForm(action, dest) ; else if ( WebContent.isMultiPartForm(ct) ) assemblerFromUpload(action, dest) ; else
Lang lang = WebContent.contentTypeToLangResultSet(serializationType); if (lang == null ) ServletOps.errorBadRequest("Not recognized for SPARQL results: "+serializationType) ;
/** 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()) ; }
StreamRDF dest = StreamRDFLib.graph(model.getGraph()) ; if ( hasParams || WebContent.isHtmlForm(ct) ) assemblerFromForm(action, dest) ; else if ( WebContent.isMultiPartForm(ct) ) assemblerFromUpload(action, dest) ; else
Lang lang = WebContent.contentTypeToLangResultSet(serializationType); if (lang == null ) ServletOps.errorBadRequest("Not recognized for SPARQL results: "+serializationType) ;
@Override protected void perform(HttpAction action) { ContentType ct = ActionLib.getContentType(action) ; if ( ct == null ) ct = ctSPARQLUpdate ; if ( matchContentType(ctSPARQLUpdate, ct) ) { executeBody(action) ; return ; } if ( isHtmlForm(ct) ) { executeForm(action) ; return ; } ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + action.request.getContentType()) ; }
/** Match content type (ignores charsets and other parameters) */ public static boolean matchContentType(ContentType ct1, ContentType ct2) { return matchContentType(ct1.getContentType(), ct2.getContentType()) ; }
private Lang determinLang(TypedInputStream in, String url) { if ( in == null ) throw new RiotNotFoundException(url); Lang lang = forceLang; if ( lang == null ) { ContentType ct = WebContent.determineCT(in.getContentType(), hintLang, url); lang = RDFLanguages.contentTypeToLang(ct); } if ( lang == null ) throw new RiotException("Can't indentify the result set syntax from "+url); return lang; }
/** Determine the content type to be used, given the target URL, the content-type from * Content Negotiation and a hint language. This is a pragmatic balance. * A content-type of "text/plain" is ignored - it is too often wrong. */ /*package*/ static ContentType determineCT(String target, String ctStr, Lang hintLang) { boolean isTextPlain = WebContent.contentTypeTextPlain.equals(ctStr) ; if ( ctStr != null ) ctStr = WebContent.contentTypeCanonical(ctStr) ; // The decision is: // Content type (but not text/plain) > hint > file extension. // If it's text plain, we ignore it because a lot of naive // server setups return text/plain for any file type. // (It was never registered as being N-triples; // that was only for RDF 2004 testing.) ContentType ct = null ; if ( ! isTextPlain ) // Not guaranteed to be registered as a language here. ct = (ctStr==null) ? null : ContentType.create(ctStr) ; if ( ct == null && hintLang != null ) ct = hintLang.getContentType() ; if ( ct == null ) ct = RDFLanguages.guessContentType(target) ; return ct ; }
Lang lang = WebContent.contentTypeToLangResultSet(actualContentType); if ( lang == null ) throw new QueryException("Endpoint returned Content-Type: " + actualContentType + " which is not rcognized for SELECT queries");
@Override protected final void perform(HttpAction action) { // OPTIONS if ( action.request.getMethod().equals(HttpNames.METHOD_OPTIONS) ) { // Share with update via SPARQL_Protocol. doOptions(action) ; return ; } // GET if ( action.request.getMethod().equals(HttpNames.METHOD_GET) ) { executeWithParameter(action) ; return ; } ContentType ct = ActionLib.getContentType(action) ; // POST application/x-www-form-url // POST ?query= and no Content-Type if ( ct == null || isHtmlForm(ct) ) { // validation checked that if no Content-type, then its a POST with ?query= executeWithParameter(action) ; return ; } // POST application/sparql-query if ( matchContentType(ct, ctSPARQLQuery) ) { executeBody(action) ; return ; } ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + ct.getContentType()) ; }
@Override protected Lang selectLang(String filename, ContentType contentType, Lang dftLang) { if ( modLangParse.getLang() != null ) return modLangParse.getLang() ; if ( contentType != null && ! WebContent.matchContentType(WebContent.ctTextPlain, contentType) ) return RDFLanguages.contentTypeToLang(contentType) ; Lang lang = RDFLanguages.filenameToLang(filename) ; if ( lang == null ) lang = dftLang ; return lang ; }
/** 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); }
contentTypeStr = contentTypeCanonical(contentTypeStr) ;
@Override protected final void perform(HttpAction action) { // OPTIONS if ( action.request.getMethod().equals(HttpNames.METHOD_OPTIONS) ) { // Share with update via SPARQL_Protocol. doOptions(action) ; return ; } // GET if ( action.request.getMethod().equals(HttpNames.METHOD_GET) ) { executeWithParameter(action) ; return ; } ContentType ct = ActionLib.getContentType(action) ; // POST application/x-www-form-url // POST ?query= and no Content-Type if ( ct == null || isHtmlForm(ct) ) { // validation checked that if no Content-type, then its a POST with ?query= executeWithParameter(action) ; return ; } // POST application/sparql-query if ( matchContentType(ct, ctSPARQLQuery) ) { executeBody(action) ; return ; } ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + ct.getContentType()) ; }
String incoming = ct.getContentType() ; if ( matchContentType(ctSPARQLQuery, ct) ) { mustHaveQueryParam = false ; } else if ( matchContentType(ctHTMLForm, ct)) {