public TypedInputStream(InputStream in, String contentType) { this(in, ContentType.create(contentType), null) ; }
public TypedInputStream(InputStream in, String mediaType, String charset, String baseURI) { this(in, ContentType.create(mediaType, charset), baseURI) ; }
public TypedInputStream(InputStream in, String mediaType, String charset, String baseURI) { this(in, ContentType.create(mediaType, charset), baseURI) ; }
public TypedInputStream(InputStream in, String contentType) { this(in, ContentType.create(contentType), null) ; }
/** Get the content type of an action or return the default. * @param request * @return ContentType */ public static ContentType getContentType(HttpServletRequest request) { String contentTypeHeader = request.getContentType() ; if ( contentTypeHeader == null ) return null ; return ContentType.create(contentTypeHeader) ; }
/** Get the content type of an action or return the default. * @param request * @return ContentType */ public static ContentType getContentType(HttpServletRequest request) { String contentTypeHeader = request.getContentType() ; if ( contentTypeHeader == null ) return null ; return ContentType.create(contentTypeHeader) ; }
/** @deprecated use {@linkplain #create(String)} */ @Deprecated public static ContentType parse(String string) { return create(string) ; }
protected Lang(String langlabel, String mainContentType, List<String> altLangLabels, List<String> otherContentTypes, List<String> fileExt) { if ( langlabel == null ) throw new IllegalArgumentException("Null not allowed for language name") ; else langlabel = langlabel.intern() ; label = langlabel ; String mediaType = mainContentType ; contentType = mediaType == null ? null : ContentType.create(mediaType) ; List<String> _altContentTypes = copy(otherContentTypes) ; if ( !_altContentTypes.contains(mainContentType) ) _altContentTypes.add(mainContentType) ; altContentTypes = Collections.unmodifiableList(_altContentTypes) ; List<String> _altLabels = copy(altLangLabels) ; if ( !_altLabels.contains(label) ) _altLabels.add(label) ; altLabels = Collections.unmodifiableList(_altLabels) ; List<String> _fileExtensions = copy(fileExt) ; fileExtensions = Collections.unmodifiableList(_fileExtensions) ; }
protected Lang(String langlabel, String mainContentType, List<String> altLangLabels, List<String> otherContentTypes, List<String> fileExt) { if ( langlabel == null ) throw new IllegalArgumentException("Null not allowed for language name") ; else langlabel = langlabel.intern() ; label = langlabel ; String mediaType = mainContentType ; contentType = mediaType == null ? null : ContentType.create(mediaType) ; List<String> _altContentTypes = copy(otherContentTypes) ; if ( !_altContentTypes.contains(mainContentType) ) _altContentTypes.add(mainContentType) ; altContentTypes = Collections.unmodifiableList(_altContentTypes) ; List<String> _altLabels = copy(altLangLabels) ; if ( !_altLabels.contains(label) ) _altLabels.add(label) ; altLabels = Collections.unmodifiableList(_altLabels) ; List<String> _fileExtensions = copy(fileExt) ; fileExtensions = Collections.unmodifiableList(_fileExtensions) ; }
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); }
/** 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 ; }
if ( ! isTextPlain ) ct = (contentTypeStr==null) ? null : ContentType.create(contentTypeStr) ;
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"); }
@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"); }
ct = ContentType.create(contentTypeHeader) ;
ct = ContentType.create(contentTypeHeader) ;
ContentType ct = ContentType.create(contentTypeHeader) ; Lang lang = null ; if ( ! matchContentType(ctTextPlain, ct) )
ContentType ct = ContentType.create(contentTypeHeader) ; Lang lang = null ; if ( ! matchContentType(ctTextPlain, ct) )