private ContentType ensureCharset(final ContentType contentType) { if (ContentType.APPLICATION_ATOM_XML.isCompatible(contentType) || ContentType.APPLICATION_ATOM_SVC.isCompatible(contentType) || ContentType.APPLICATION_XML.isCompatible(contentType)) { return contentType.receiveWithCharsetParameter(DEFAULT_CHARSET); } return contentType; } }
private ContentType ensureCharset(final ContentType contentType) { if (ContentType.APPLICATION_ATOM_XML.isCompatible(contentType) || ContentType.APPLICATION_ATOM_SVC.isCompatible(contentType) || ContentType.APPLICATION_XML.isCompatible(contentType)) { return contentType.receiveWithCharsetParameter(DEFAULT_CHARSET); } return contentType; } }
private ContentType ensureCharset(final ContentType contentType) { if (ContentType.APPLICATION_ATOM_XML.isCompatible(contentType) || ContentType.APPLICATION_ATOM_SVC.isCompatible(contentType) || ContentType.APPLICATION_XML.isCompatible(contentType)) { return contentType.receiveWithCharsetParameter(DEFAULT_CHARSET); } return contentType; } }
/** * Find best match between this {@link ContentType} and the {@link ContentType} in the list ignoring all set * parameters. * If a match (this {@link ContentType} is equal to a {@link ContentType} in list) is found either this or the * {@link ContentType} from the list is returned based on which {@link ContentType} has less "**" characters set * (checked with {@link #compareWildcardCounts(ContentType)}. * If no match (none {@link ContentType} in list is equal to this {@link ContentType}) is found <code>NULL</code> is * returned. * * @param toMatchContentTypes list of {@link ContentType}s which are matches against this {@link ContentType} * @return best matched content type in list or <code>NULL</code> if none content type match to this content type * instance */ public ContentType matchCompatible(final List<ContentType> toMatchContentTypes) { for (ContentType supportedContentType : toMatchContentTypes) { if (isCompatible(supportedContentType)) { if (compareWildcardCounts(supportedContentType) < 0) { return this; } else { return supportedContentType; } } } return null; }
/** * Find best match between this {@link ContentType} and the {@link ContentType} in the list ignoring all set * parameters. * If a match (this {@link ContentType} is equal to a {@link ContentType} in list) is found either this or the * {@link ContentType} from the list is returned based on which {@link ContentType} has less "**" characters set * (checked with {@link #compareWildcardCounts(ContentType)}. * If no match (none {@link ContentType} in list is equal to this {@link ContentType}) is found <code>NULL</code> is * returned. * * @param toMatchContentTypes list of {@link ContentType}s which are matches against this {@link ContentType} * @return best matched content type in list or <code>NULL</code> if none content type match to this content type * instance */ public ContentType matchCompatible(final List<ContentType> toMatchContentTypes) { for (ContentType supportedContentType : toMatchContentTypes) { if (isCompatible(supportedContentType)) { if (compareWildcardCounts(supportedContentType) < 0) { return this; } else { return supportedContentType; } } } return null; }
/** * Find best match between this {@link ContentType} and the {@link ContentType} in the list ignoring all set * parameters. * If a match (this {@link ContentType} is equal to a {@link ContentType} in list) is found either this or the * {@link ContentType} from the list is returned based on which {@link ContentType} has less "**" characters set * (checked with {@link #compareWildcardCounts(ContentType)}. * If no match (none {@link ContentType} in list is equal to this {@link ContentType}) is found <code>NULL</code> is * returned. * * @param toMatchContentTypes list of {@link ContentType}s which are matches against this {@link ContentType} * @return best matched content type in list or <code>NULL</code> if none content type match to this content type * instance */ public ContentType matchCompatible(final List<ContentType> toMatchContentTypes) { for (ContentType supportedContentType : toMatchContentTypes) { if (isCompatible(supportedContentType)) { if (compareWildcardCounts(supportedContentType) < 0) { return this; } else { return supportedContentType; } } } return null; }
private static Charset getCharset(String contentType) { ContentType ct = ContentType.parse(contentType); if(ct != null) { String charsetString = ct.getParameters().get(ContentType.PARAMETER_CHARSET); if (charsetString != null && Charset.isSupported(charsetString)) { setDefaultValues(charsetString); return Charset.forName(charsetString); } else { if (ct.isCompatible(ContentType.APPLICATION_JSON) || ct.getSubtype().contains("xml")) { setDefaultValues(UTF8_ENCODING); return Charset.forName(UTF8_ENCODING); } } } setDefaultValues(ISO_ENCODING); return Charset.forName(ISO_ENCODING); }
public static Charset extractCharset(ContentType contentType) { if (contentType != null) { final String charsetValue = contentType.getParameters().get(ContentType.PARAMETER_CHARSET); if (charsetValue == null) { if (contentType.isCompatible(ContentType.APPLICATION_JSON) || contentType.getSubtype().contains("xml")) { setDefaultValues(UTF8_ENCODING); return Charset.forName(UTF8_ENCODING); } } else { setDefaultValues(charsetValue); return Charset.forName(charsetValue); } } setDefaultValues(ISO_ENCODING); return Charset.forName(ISO_ENCODING); }
public static Charset extractCharset(ContentType contentType) { if (contentType != null) { final String charsetValue = contentType.getParameters().get(ContentType.PARAMETER_CHARSET); if (charsetValue == null) { if (contentType.isCompatible(ContentType.APPLICATION_JSON) || contentType.getSubtype().contains("xml")) { setDefaultValues(UTF8_ENCODING); return Charset.forName(UTF8_ENCODING); } } else { setDefaultValues(charsetValue); return Charset.forName(charsetValue); } } setDefaultValues(ISO_ENCODING); return Charset.forName(ISO_ENCODING); }
private static Charset getCharset(String contentType) { ContentType ct = ContentType.parse(contentType); if(ct != null) { String charsetString = ct.getParameters().get(ContentType.PARAMETER_CHARSET); if (charsetString != null && Charset.isSupported(charsetString)) { setDefaultValues(charsetString); return Charset.forName(charsetString); } else { if (ct.isCompatible(ContentType.APPLICATION_JSON) || ct.getSubtype().contains("xml")) { setDefaultValues(UTF8_ENCODING); return Charset.forName(UTF8_ENCODING); } } } setDefaultValues(ISO_ENCODING); return Charset.forName(ISO_ENCODING); }
private void updateCurrentCharset(String currentLine) { if(currentLine != null) { if(isContentTypeHeaderLine(currentLine)) { currentLine = currentLine.substring(13, currentLine.length() - 2).trim(); ContentType ct = ContentType.parse(currentLine); if (ct != null) { String charsetString = ct.getParameters().get(ContentType.PARAMETER_CHARSET); if (charsetString != null) { currentCharset = Charset.forName(charsetString); } else { if (ct.isCompatible(ContentType.APPLICATION_JSON) || ct.getSubtype().contains(XML_SUBTYPE)) { currentCharset = Charset.forName(UTF8_CHARSET); } else { currentCharset = DEFAULT_CHARSET; } } // boundary String boundary = ct.getParameters().get(BOUNDARY); if (boundary != null) { currentBoundary = DOUBLE_DASH + boundary; } } } else if(CRLF.equals(currentLine)) { readState.foundLinebreak(); } else if(isBoundary(currentLine)) { readState.foundBoundary(); } } }
private void updateCurrentCharset(String currentLine) { if(currentLine != null) { if(isContentTypeHeaderLine(currentLine)) { currentLine = currentLine.substring(13, currentLine.length() - 2).trim(); ContentType ct = ContentType.parse(currentLine); if (ct != null) { String charsetString = ct.getParameters().get(ContentType.PARAMETER_CHARSET); if (charsetString != null) { currentCharset = Charset.forName(charsetString); } else { if (ct.isCompatible(ContentType.APPLICATION_JSON) || ct.getSubtype().contains(XML_SUBTYPE)) { currentCharset = Charset.forName(UTF8_CHARSET); } else { currentCharset = DEFAULT_CHARSET; } } // boundary String boundary = ct.getParameters().get(BOUNDARY); if (boundary != null) { currentBoundary = DOUBLE_DASH + boundary; } } } else if(CRLF.equals(currentLine)) { readState.foundLinebreak(); } else if(isBoundary(currentLine)) { readState.foundBoundary(); } } }