@Override public int compare(final AcceptCharset a1, final AcceptCharset a2) { int compare = a2.getQuality().compareTo(a1.getQuality()); if (compare != 0) { return compare; } return a2.getParameters().size() - a1.getParameters().size(); } });
result.add(new AcceptCharset(value.trim())); } catch (UnsupportedCharsetException e) { exceptionList.add(e); sort(result);
private AcceptCharset(final String charset) { parameters = TypeUtil.createParameterMap(); this.charset = parse(charset, parameters); if (!(UTF8_CHARSET.equalsIgnoreCase(this.charset)) && !(UTF8_CHARSET1.equalsIgnoreCase(this.charset)) && !(TypeUtil.MEDIA_TYPE_WILDCARD.equals(this.charset))) { if (CHARSET_PATTERN.matcher(this.charset).matches()) { throw new UnsupportedCharsetException("Unsupported charset in accept charset header:" + charset); } else { throw new IllegalArgumentException("Illegal charset in accept charset header:" + charset); } } for (Entry<String, String> param : parameters.entrySet()) { if (!param.getKey().equals(TypeUtil.PARAMETER_Q)) { throw new IllegalArgumentException("Illegal parameters in accept charset header:" + charset); } } final String q = parameters.get(TypeUtil.PARAMETER_Q); if (q == null) { quality = 1F; } else if (Q_PATTERN.matcher(q).matches()) { quality = Float.valueOf(q); } else { throw new IllegalArgumentException("Illegal quality parameter '" + q + "' in accept charset header:" + charset); } }
/** * @param acceptCharset * @return * @throws ContentNegotiatorException * @throws AcceptHeaderContentNegotiatorException */ private static List<AcceptCharset> getAcceptCharset(String acceptCharset) throws ContentNegotiatorException, AcceptHeaderContentNegotiatorException { List<AcceptCharset> charsets = null; if (acceptCharset != null) { try { charsets = AcceptCharset.create(acceptCharset); } catch (UnsupportedCharsetException e) { throw new ContentNegotiatorException(e.getMessage(), e, ContentNegotiatorException.MessageKeys.UNSUPPORTED_ACCEPT_CHARSET, e.getMessage().substring(e.getMessage().lastIndexOf(COLON) + 1)); } catch (IllegalArgumentException e) { throw new AcceptHeaderContentNegotiatorException(e.getMessage(), e, AcceptHeaderContentNegotiatorException.MessageKeys.UNSUPPORTED_ACCEPT_CHARSET_HEADER_OPTIONS, e.getMessage().substring(e.getMessage().lastIndexOf(COLON) + 1)); } } return charsets; }
final String charSetValue = acceptedType.getParameter(ContentType.PARAMETER_CHARSET); if (charset != null) { if ("*".equals(charset.toString())) { contentType = ContentType.create(contentType, ContentType.PARAMETER_CHARSET, "utf-8"); } else { contentType = ContentType.create(contentType, ContentType.PARAMETER_CHARSET, charset.toString());
result.add(new AcceptCharset(value.trim())); } catch (UnsupportedCharsetException e) { exceptionList.add(e); sort(result);
private AcceptCharset(final String charset) { parameters = TypeUtil.createParameterMap(); this.charset = parse(charset, parameters); if (!(UTF8_CHARSET.equalsIgnoreCase(this.charset)) && !(UTF8_CHARSET1.equalsIgnoreCase(this.charset)) && !(TypeUtil.MEDIA_TYPE_WILDCARD.equals(this.charset))) { if (CHARSET_PATTERN.matcher(this.charset).matches()) { throw new UnsupportedCharsetException("Unsupported charset in accept charset header:" + charset); } else { throw new IllegalArgumentException("Illegal charset in accept charset header:" + charset); } } for (Entry<String, String> param : parameters.entrySet()) { if (!param.getKey().equals(TypeUtil.PARAMETER_Q)) { throw new IllegalArgumentException("Illegal parameters in accept charset header:" + charset); } } final String q = parameters.get(TypeUtil.PARAMETER_Q); if (q == null) { quality = 1F; } else if (Q_PATTERN.matcher(q).matches()) { quality = Float.valueOf(q); } else { throw new IllegalArgumentException("Illegal quality parameter '" + q + "' in accept charset header:" + charset); } }
/** * @param acceptCharset * @return * @throws ContentNegotiatorException * @throws AcceptHeaderContentNegotiatorException */ private static List<AcceptCharset> getAcceptCharset(String acceptCharset) throws ContentNegotiatorException, AcceptHeaderContentNegotiatorException { List<AcceptCharset> charsets = null; if (acceptCharset != null) { try { charsets = AcceptCharset.create(acceptCharset); } catch (UnsupportedCharsetException e) { throw new ContentNegotiatorException(e.getMessage(), e, ContentNegotiatorException.MessageKeys.UNSUPPORTED_ACCEPT_CHARSET, e.getMessage().substring(e.getMessage().lastIndexOf(COLON) + 1)); } catch (IllegalArgumentException e) { throw new AcceptHeaderContentNegotiatorException(e.getMessage(), e, AcceptHeaderContentNegotiatorException.MessageKeys.UNSUPPORTED_ACCEPT_CHARSET_HEADER_OPTIONS, e.getMessage().substring(e.getMessage().lastIndexOf(COLON) + 1)); } } return charsets; }
final String charSetValue = acceptedType.getParameter(ContentType.PARAMETER_CHARSET); if (charset != null) { if ("*".equals(charset.toString())) { contentType = ContentType.create(contentType, ContentType.PARAMETER_CHARSET, "utf-8"); } else { contentType = ContentType.create(contentType, ContentType.PARAMETER_CHARSET, charset.toString());
@Override public int compare(final AcceptCharset a1, final AcceptCharset a2) { int compare = a2.getQuality().compareTo(a1.getQuality()); if (compare != 0) { return compare; } return a2.getParameters().size() - a1.getParameters().size(); } });