public DataSourceSource(DataSource source) throws MimeTypeParseException { this.source = source; String ct = source.getContentType(); if(ct==null) { charset = null; } else { MimeType mimeType = new MimeType(ct); this.charset = mimeType.getParameter("charset"); } }
charset = mt.getParameter("charset"); if(charset==null) charset = "UTF-8";
public DataSourceSource(DataSource source) throws MimeTypeParseException { this.source = source; String ct = source.getContentType(); if(ct==null) { charset = null; } else { MimeType mimeType = new MimeType(ct); this.charset = mimeType.getParameter("charset"); } }
public static VariableValueDto fromFormPart(String type, FormPart binaryDataFormPart) { VariableValueDto dto = new VariableValueDto(); dto.type = type; dto.value = binaryDataFormPart.getBinaryContent(); if (ValueType.FILE.getName().equals(fromRestApiTypeName(type))) { String contentType = binaryDataFormPart.getContentType(); if (contentType == null) { contentType = MediaType.APPLICATION_OCTET_STREAM; } dto.valueInfo = new HashMap<String, Object>(); dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_NAME, binaryDataFormPart.getFileName()); MimeType mimeType = null; try { mimeType = new MimeType(contentType); } catch (MimeTypeParseException e) { throw new RestException(Status.BAD_REQUEST, "Invalid mime type given"); } dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_MIME_TYPE, mimeType.getBaseType()); String encoding = mimeType.getParameter("encoding"); if (encoding != null) { dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_ENCODING, encoding); } String transientString = mimeType.getParameter("transient"); boolean isTransient = Boolean.parseBoolean(transientString); if (isTransient) { dto.valueInfo.put(AbstractValueTypeImpl.VALUE_INFO_TRANSIENT, isTransient); } } return dto; }
public static VariableValueDto fromFormPart(String type, FormPart binaryDataFormPart) { VariableValueDto dto = new VariableValueDto(); dto.type = type; dto.value = binaryDataFormPart.getBinaryContent(); if (ValueType.FILE.getName().equals(fromRestApiTypeName(type))) { String contentType = binaryDataFormPart.getContentType(); if (contentType == null) { contentType = MediaType.APPLICATION_OCTET_STREAM; } dto.valueInfo = new HashMap<String, Object>(); dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_NAME, binaryDataFormPart.getFileName()); MimeType mimeType = null; try { mimeType = new MimeType(contentType); } catch (MimeTypeParseException e) { throw new RestException(Status.BAD_REQUEST, "Invalid mime type given"); } dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_MIME_TYPE, mimeType.getBaseType()); String encoding = mimeType.getParameter("encoding"); if (encoding != null) { dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_ENCODING, encoding); } String transientString = mimeType.getParameter("transient"); boolean isTransient = Boolean.parseBoolean(transientString); if (isTransient) { dto.valueInfo.put(AbstractValueTypeImpl.VALUE_INFO_TRANSIENT, isTransient); } } return dto; }
charset = mt.getParameter("charset"); if(charset==null) charset = "UTF-8";
public static String getCharset( final MimeType type, String defaultCharset ) { String charset = null; if( type != null ) { charset = type.getParameter( CHARSET_PARAMETER_NAME ); } if( charset == null ) { charset = defaultCharset; } return charset; }
public static String getCharset( final MimeType type, String defaultCharset ) { String charset = null; if( type != null ) { charset = type.getParameter( CHARSET_PARAMETER_NAME ); } if( charset == null ) { charset = defaultCharset; } return charset; }
public String getParameter(String name) { return mimeType.getParameter(name); }
@Nullable public static Charset findCharSetOf(@Nullable MimeType mimeType) throws IOException { final String charsetName = mimeType != null ? mimeType.getParameter("charset") : null; try { return charsetName != null ? forName(charsetName) : null; } catch (final UnsupportedCharsetException e) { throw new IOException("In contentType '" + mimeType + "' was an unsupported charset provided.", e); } }
public static String getCharset(String mediatype) { try { MimeType mt = new MimeType(mediatype); return mt.getParameter("charset"); } catch (Exception e) { return null; } }
/** * Get the character set encoding specified by the server in the Content-Type header */ public String getCharacterEncoding() { String charset = null; try { MimeType mt = getContentType(); if (mt != null) charset = mt.getParameter("charset"); } catch (Exception e) { } return charset; }
private ContentType createContentType(String contentType) { try { MimeType mimeType = new MimeType(contentType); String mediaType = mimeType.getBaseType(); String charset = defaultString(mimeType.getParameter("charset"), DEFAULT_CONTENT_ENCODING); return ContentType.create(mediaType, charset); } catch (MimeTypeParseException e) { throw new IllegalArgumentException("Invalid content type: " + contentType, e); } }
public Document<T> setContentType(String contentType) { try { this.contentType = new MimeType(contentType); if (this.contentType.getParameter("charset") != null) setCharset(this.contentType.getParameter("charset")); } catch (javax.activation.MimeTypeParseException e) { throw new org.apache.abdera.util.MimeTypeParseException(e); } return this; }
private ContentType createContentType(String contentType) { try { MimeType mimeType = new MimeType(contentType); String mediaType = mimeType.getBaseType(); String charset = defaultString(mimeType.getParameter("charset"), DEFAULT_CONTENT_ENCODING); return ContentType.create(mediaType, charset); } catch (MimeTypeParseException e) { throw new IllegalArgumentException("Invalid content type: " + contentType, e); } }
public DataSourceSource(DataSource source) throws MimeTypeParseException { this.source = source; String ct = source.getContentType(); if(ct==null) { charset = null; } else { MimeType mimeType = new MimeType(ct); this.charset = mimeType.getParameter("charset"); } }
public DataSourceSource(DataSource source) throws MimeTypeParseException { this.source = source; String ct = source.getContentType(); if(ct==null) { charset = null; } else { MimeType mimeType = new MimeType(ct); this.charset = mimeType.getParameter("charset"); } }
/** * Returns true if media type a explicitly identifies an Atom feed document */ public static boolean isFeed(String a) { try { MimeType mta = new MimeType(a.toLowerCase()); MimeType mtb = new MimeType(Constants.ATOM_MEDIA_TYPE); if (isMatch(mta,mtb)) { String type = mta.getParameter("type"); return type != null ? type.equalsIgnoreCase("feed") : true; } } catch (Exception e) {} return false; }
/** * Returns true if media type a explicitly identifies an Atom feed document */ public static boolean isFeed(String a) { try { MimeType mta = new MimeType(a.toLowerCase()); MimeType mtb = new MimeType(Constants.ATOM_MEDIA_TYPE); MimeType mtc = new MimeType(Constants.FEED_MEDIA_TYPE); return isMatch(mta, mtc) || (isMatch(mta, mtb) && isMatchType(mta.getParameter("type"), "feed")); } catch (Exception e) { } return false; }
/** * Returns true if media type a specifically identifies an Atom entry document */ public static boolean isEntry(String a) { try { MimeType mta = new MimeType(a.toLowerCase()); MimeType mtb = new MimeType(Constants.ATOM_MEDIA_TYPE); MimeType mtc = new MimeType(Constants.ENTRY_MEDIA_TYPE); return isMatch(mta, mtc) || (isMatch(mta, mtb) && isMatchType(mta.getParameter("type"), "entry")); } catch (Exception e) { } return false; }