public String getContentType() { return mediaType == null ? null : mediaType.getContentType() ; } public String getCharset() { return mediaType == null ? null : mediaType.getCharset() ; }
public TypedInputStream(InputStream in, String contentType) { this(in, ContentType.create(contentType), null) ; }
/** As an HTTP Content-Type field value */ public String getHeaderString() { return contentType.toHeaderString() ; } public String getLabel() { return label ; }
protected void validate(HttpAction action) { String method = action.getRequest().getMethod(); switch(method) { case HttpNames.METHOD_POST: break; default: ServletOps.errorMethodNotAllowed(method+" : Patch must use POST"); } String ctStr = action.request.getContentType(); // Must be UTF-8 or unset. But this is wrong so often, // it is less trouble to just force UTF-8. String charset = action.request.getCharacterEncoding(); if ( charset != null && ! WebContent.charsetUTF8.equals(charset) ) ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Charset must be omitted or must be UTF-8, not "+charset); // If no header Content-type - assume patch-text. ContentType contentType = ( ctStr != null ) ? ContentType.create(ctStr) : ctPatchText; if ( ! ctPatchText.equals(contentType) && ! ctPatchBinary.equals(contentType) ) ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Allowed Content-types are "+ctPatchText+" or "+ctPatchBinary+", not "+ctStr); if ( ctPatchBinary.equals(contentType) ) ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, contentTypePatchBinary+" not supported yet"); }
ContentType ct = ContentType.create(contentTypeHeader) ; Lang lang = null ; if ( ! matchContentType(ctTextPlain, ct) ) lang = RDFLanguages.contentTypeToLang(ct.getContentType()) ; UploadDetails details1 = new UploadDetails(countingDest2.count(), countingDest2.countTriples(),countingDest2.countQuads()) ; action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s : %s", action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName(), details1.detailsStr())) ; } catch (RiotParseException ex) { action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s : %s", action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName(), ex.getMessage())) ; throw ex ;
Lang lang = RDFLanguages.contentTypeToLang(ct.getContentType()) ; if ( lang == null ) { ServletOps.errorBadRequest("Unknown content type for triples: " + ct) ; UploadDetails details = new UploadDetails(countingDest.count(), countingDest.countTriples(),countingDest.countQuads()) ; action.log.info(format("[%d] Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s : %s", action.id, len, ct.getContentType(), ct.getCharset(), lang.getName(), details.detailsStr())) ; return details ; } catch (RiotParseException ex) { action.log.info(format("[%d] Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s : %s", action.id, len, ct.getContentType(), ct.getCharset(), lang.getName(), ex.getMessage())) ; throw ex ;
@Override public boolean equals(Object other) { if ( this == other ) return true ; if ( other == null ) return false ; if ( ! ( other instanceof Lang ) ) return false ; Lang otherLang = (Lang)other ; // Just label should be enough. return this.label == otherLang.label && this.contentType.equals(otherLang.contentType) && this.altContentTypes.equals(otherLang.altContentTypes) && this.fileExtensions.equals(otherLang.fileExtensions) ; // File extensions and alt }
public String getCharset() { return mediaType == null ? null : mediaType.getCharset() ; } public ContentType getMediaType() { return mediaType ; }
public static ContentType create(String string) { if ( string == null ) return null ; ContentType ct = new ContentType(MediaType.create(string)) ; return ct ; }
ContentType ct = ContentType.create(contentTypeHeader) ; Lang lang = null ; if ( ! matchContentType(ctTextPlain, ct) ) lang = RDFLanguages.contentTypeToLang(ct.getContentType()) ; UploadDetails details1 = new UploadDetails(countingDest2.count(), countingDest2.countTriples(),countingDest2.countQuads()) ; action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s : %s", action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName(), details1.detailsStr())) ; } catch (RiotParseException ex) { action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s : %s", action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName(), ex.getMessage())) ; throw ex ;
Lang lang = RDFLanguages.contentTypeToLang(ct.getContentType()) ; if ( lang == null ) { ServletOps.errorBadRequest("Unknown content type for triples: " + ct) ; UploadDetails details = new UploadDetails(countingDest.count(), countingDest.countTriples(),countingDest.countQuads()) ; action.log.info(format("[%d] Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s : %s", action.id, len, ct.getContentType(), ct.getCharset(), lang.getName(), details.detailsStr())) ; return details ; } catch (RiotParseException ex) { action.log.info(format("[%d] Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s : %s", action.id, len, ct.getContentType(), ct.getCharset(), lang.getName(), ex.getMessage())) ; throw ex ;
@Override protected void validate(HttpAction action) { String method = action.getRequest().getMethod(); switch(method) { case HttpNames.METHOD_POST: case HttpNames.METHOD_PATCH: break; default: ServletOps.errorMethodNotAllowed(method+" : Patch must use POST or PATCH"); } String ctStr = action.request.getContentType(); // Must be UTF-8 or unset. But this is wrong so often, // it is less trouble to just force UTF-8. String charset = action.request.getCharacterEncoding(); if ( charset != null && ! WebContent.charsetUTF8.equals(charset) ) ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Charset must be omitted or UTF-8, not "+charset); // If no header Content-type - assume patch-text. ContentType contentType = ( ctStr != null ) ? ContentType.create(ctStr) : ctPatchText; if ( ! ctPatchText.equals(contentType) && ! ctPatchBinary.equals(contentType) ) ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Allowed Content-types are "+ctPatchText+" or "+ctPatchBinary+", not "+ctStr); if ( ctPatchBinary.equals(contentType) ) ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, contentTypePatchBinary+" not supported yet"); }
@Override public boolean equals(Object other) { if ( this == other ) return true ; if ( other == null ) return false ; if ( ! ( other instanceof Lang ) ) return false ; Lang otherLang = (Lang)other ; // Just label should be enough. return this.label == otherLang.label && this.contentType.equals(otherLang.contentType) && this.altContentTypes.equals(otherLang.altContentTypes) && this.fileExtensions.equals(otherLang.fileExtensions) ; // File extensions and alt }
public String getCharset() { return mediaType == null ? null : mediaType.getCharset() ; } public ContentType getMediaType() { return mediaType ; }
public static ContentType create(String string) { if ( string == null ) return null ; ContentType ct = new ContentType(MediaType.create(string)) ; return ct ; }
public String getContentType() { return mediaType == null ? null : mediaType.getContentType() ; } public String getCharset() { return mediaType == null ? null : mediaType.getCharset() ; }
ct = ContentType.create(contentTypeHeader) ; lang = RDFLanguages.contentTypeToLang(ct.getContentType()) ; if ( lang == null ) { lang = RDFLanguages.filenameToLang(name) ; ct.getContentType(), ct.getCharset(), lang.getName())) ;
public TypedInputStream(InputStream in, String mediaType, String charset, String baseURI) { this(in, ContentType.create(mediaType, charset), baseURI) ; }
/** As an HTTP Content-Type field value */ public String getHeaderString() { return contentType.toHeaderString() ; } public String getLabel() { return label ; }
public static ContentType create(String ctString, String charset) { MediaType.ParsedMediaType x = MediaType.parse(ctString) ; x.params.put(charsetParamName, charset) ; return new ContentType(new MediaType(x)) ; }