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); }
/** 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()) ; }
/** Match content type (ignores charsets and other parameters) */ public static boolean matchContentType(ContentType ct1, ContentType ct2) { return matchContentType(ct1.getContentType(), ct2.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 ; }
@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()) ; }
@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()) ; }
String incoming = ct.getContentType() ; if ( matchContentType(ctSPARQLQuery, ct) ) { mustHaveQueryParam = false ; } else if ( matchContentType(ctHTMLForm, ct)) {
String incoming = ct.getContentType() ; if ( matchContentType(ctSPARQLQuery, ct) ) { mustHaveQueryParam = false ; } else if ( matchContentType(ctHTMLForm, ct)) {
@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 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()) ; }
ct = ctSPARQLUpdate ; if ( matchContentType(ctSPARQLUpdate, ct) ) { String charset = request.getCharacterEncoding() ; if ( charset != null && !charset.equalsIgnoreCase(charsetUTF8) )
ct = ctSPARQLUpdate ; if ( matchContentType(ctSPARQLUpdate, ct) ) { String charset = request.getCharacterEncoding() ; if ( charset != null && !charset.equalsIgnoreCase(charsetUTF8) )
if ( matchContentType(ctMultipartFormData, ct) ) { return fileUploadWorker(action, dest) ;
if ( matchContentType(ctMultipartFormData, ct) ) { return fileUploadWorker(action, dest) ;
ContentType ct = ContentType.create(contentTypeHeader) ; Lang lang = null ; if ( ! matchContentType(ctTextPlain, ct) ) lang = RDFLanguages.contentTypeToLang(ct.getContentType()) ;
ContentType ct = ContentType.create(contentTypeHeader) ; Lang lang = null ; if ( ! matchContentType(ctTextPlain, ct) ) lang = RDFLanguages.contentTypeToLang(ct.getContentType()) ;
private void doPutPost(HttpAction action, boolean overwrite) { ContentType ct = ActionLib.getContentType(action) ; if ( ct == null ) ServletOps.errorBadRequest("No Content-Type:") ; if ( matchContentType(ctMultipartMixed, ct) ) { ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "multipart/mixed not supported") ; } UploadDetails details ; if ( action.isTransactional() ) details = addDataIntoTxn(action, overwrite) ; else details = addDataIntoNonTxn(action, overwrite) ; MediaType mt = ConNeg.chooseCharset(action.request, DEF.jsonOffer, DEF.acceptJSON) ; if ( mt == null ) { // No return body. if ( details.getExistedBefore().equals(PreState.ABSENT) ) ServletOps.successCreated(action) ; else ServletOps.successNoContent(action) ; return ; } ServletOps.uploadResponse(action, details) ; }
private void doPutPost(HttpAction action, boolean overwrite) { ContentType ct = ActionLib.getContentType(action) ; if ( ct == null ) ServletOps.errorBadRequest("No Content-Type:") ; if ( matchContentType(ctMultipartMixed, ct) ) { ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "multipart/mixed not supported") ; } UploadDetails details ; if ( action.isTransactional() ) details = addDataIntoTxn(action, overwrite) ; else details = addDataIntoNonTxn(action, overwrite) ; MediaType mt = ConNeg.chooseCharset(action.request, DEF.jsonOffer, DEF.acceptJSON) ; if ( mt == null ) { // No return body. if ( details.getExistedBefore().equals(PreState.ABSENT) ) ServletOps.successCreated(action) ; else ServletOps.successNoContent(action) ; return ; } ServletOps.uploadResponse(action, details) ; }