List of usage examples for org.apache.http.message BasicHeaderValueParser parseHeaderElement
public HeaderElement parseHeaderElement(CharArrayBuffer charArrayBuffer, ParserCursor parserCursor)
From source file:org.chaplib.ContentTypeNormalizer.java
public String normalize(String contentType) { HeaderElement elt = BasicHeaderValueParser.parseHeaderElement(contentType, null); if (elt.getParameterByName("charset") == null) contentType += ";charset=iso-8859-1"; return contentType; }
From source file:org.chaplib.TestContentTypeNormalizer.java
@Test public void addsDefaultCharset() { String result = impl.normalize("text/plain"); HeaderElement elt = BasicHeaderValueParser.parseHeaderElement(result, null); assertNotNull(elt.getParameterByName("charset")); }
From source file:org.chaplib.TestContentTypeNormalizer.java
@Test public void defaultCharsetIsIso_8859_1() { String result = impl.normalize("text/plain"); HeaderElement elt = BasicHeaderValueParser.parseHeaderElement(result, null); assertTrue("iso-8859-1".equalsIgnoreCase(elt.getParameterByName("charset").getValue())); }
From source file:org.chaplib.TestContentTypeNormalizer.java
@Test public void doesNotAddCharsetIfOneExists() { String result = impl.normalize("text/plain;charset=utf-8"); HeaderElement elt = BasicHeaderValueParser.parseHeaderElement(result, null); int charsets = 0; for (NameValuePair pair : elt.getParameters()) { if ("charset".equalsIgnoreCase(pair.getName())) charsets++;/*from ww w . j a va2 s . c o m*/ } assertEquals(1, charsets); }
From source file:org.chaplib.TestContentTypeNormalizer.java
@Test public void doesNotModifyExistingCharset() { String result = impl.normalize("text/plain;charset=utf-8"); HeaderElement elt = BasicHeaderValueParser.parseHeaderElement(result, null); assertEquals("utf-8", elt.getParameterByName("charset").getValue()); }