/** * Returns the character set from the <tt>Content-Type</tt> header. * * @param contentheader The content header. * @return String The character set. */ protected String getContentCharSet(Header contentheader) { LOG.trace("enter getContentCharSet( Header contentheader )"); String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); // I expect only one header element to be there // No more. no less if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { // If I get anything "funny" // UnsupportedEncondingException will result charset = param.getValue(); } } } if (charset == null) { charset = getParams().getContentCharset(); if (LOG.isDebugEnabled()) { LOG.debug("Default charset used: " + charset); } } return charset; }
HeaderElement[] encodings = transferEncodingHeader.getElements();
@Override public Map<String,String> getCookies() { Map<String,String> cookies = null; for (String name : COOKIE_HEADER_NAMES) { for (org.apache.commons.httpclient.Header header : method.getResponseHeaders(name)) { for (HeaderElement element : header.getElements()) { if (cookies == null) { cookies = new HashMap<String,String>(); } cookies.put(element.getName(), element.getValue()); } } } return cookies; }
protected String getContentCharSet(Header contentheader) { String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } if (charset == null) { charset = "UTF-8"; } return charset; } }
protected String getContentCharSet(Header contentheader) { String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } if (charset == null) { charset = "UTF-8"; } return charset; } }
private String getEncoding(Map<String, Object> headers) { String encoding = DEFAULT_ENCODING; Object contentType = headers.get(HttpConstants.HEADER_CONTENT_TYPE); if (contentType != null) { // use HttpClient classes to parse the charset part from the Content-Type // header (e.g. "text/html; charset=UTF-16BE") Header contentTypeHeader = new Header(HttpConstants.HEADER_CONTENT_TYPE, contentType.toString()); HeaderElement values[] = contentTypeHeader.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { encoding = param.getValue(); } } } return encoding; }
protected String getContentCharSet(Header contentheader) { String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } if (charset == null) { charset = "UTF-8"; } return charset; } }
protected String getContentCharSet(Header contentheader) { String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } if (charset == null) { charset = "UTF-8"; } return charset; } }
/** * Gets the MIME type specified in the response headers of the supplied * method, if any. For example, if the response headers contain * <tt>Content-Type: application/xml;charset=UTF-8</tt>, this method will * return <tt>application/xml</tt> as the MIME type. * * @param method the method to get the reponse MIME type from * @return the response MIME type, or <tt>null</tt> if not available */ protected String getResponseMIMEType(HttpMethod method) throws IOException { Header[] headers = method.getResponseHeaders("Content-Type"); for (Header header : headers) { HeaderElement[] headerElements = header.getElements(); for (HeaderElement headerEl : headerElements) { String mimeType = headerEl.getName(); if (mimeType != null) { // TODO: logger.debug("response MIME type is {}", mimeType); return mimeType; } } } return null; }
private void insertToCache(HttpMethodBase method, String key, String value) { HeaderElement[] cacheControlHeaderElements = method.getResponseHeader( "Cache-Control").getElements(); int maxAge = getMaxAge(cacheControlHeaderElements); if (maxAge > 0) { Element element = new Element(key, value); element.setTimeToLive(maxAge); cache.put(element); } }
/** * Returns the character set from the <tt>Content-Type</tt> header. * * @param contentheader The content header. * @return String The character set. */ protected String getContentCharSet(Header contentheader) { LOG.trace("enter getContentCharSet( Header contentheader )"); String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); // I expect only one header element to be there // No more. no less if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { // If I get anything "funny" // UnsupportedEncondingException will result charset = param.getValue(); } } } if (charset == null) { charset = getParams().getContentCharset(); if (LOG.isDebugEnabled()) { LOG.debug("Default charset used: " + charset); } } return charset; }
/** * Returns the character set from the <tt>Content-Type</tt> header. * * @param contentheader The content header. * @return String The character set. */ protected String getContentCharSet(Header contentheader) { LOG.trace("enter getContentCharSet( Header contentheader )"); String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); // I expect only one header element to be there // No more. no less if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { // If I get anything "funny" // UnsupportedEncondingException will result charset = param.getValue(); } } } if (charset == null) { charset = getParams().getContentCharset(); if (LOG.isDebugEnabled()) { LOG.debug("Default charset used: " + charset); } } return charset; }
/** * Returns the character set from the <tt>Content-Type</tt> header. * * @param contentheader The content header. * @return String The character set. */ protected String getContentCharSet(Header contentheader) { LOG.trace("enter getContentCharSet( Header contentheader )"); String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); // I expect only one header element to be there // No more. no less if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { // If I get anything "funny" // UnsupportedEncondingException will result charset = param.getValue(); } } } if (charset == null) { charset = getParams().getContentCharset(); if (LOG.isDebugEnabled()) { LOG.debug("Default charset used: " + charset); } } return charset; }
/** * Returns the character set from the <tt>Content-Type</tt> header. * * @param contentheader The content header. * @return String The character set. */ protected String getContentCharSet(Header contentheader) { LOG.trace("enter getContentCharSet( Header contentheader )"); String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); // I expect only one header element to be there // No more. no less if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { // If I get anything "funny" // UnsupportedEncondingException will result charset = param.getValue(); } } } if (charset == null) { charset = getParams().getContentCharset(); if (LOG.isDebugEnabled()) { LOG.debug("Default charset used: " + charset); } } return charset; }
public String getCharset() { String charset = null; Header contenttype = this.headers.getFirstHeader(HttpConstants.HEADER_CONTENT_TYPE); if (contenttype != null) { HeaderElement values[] = contenttype.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } if (charset != null) { return charset; } else { return defaultEncoding; } }
public String getCharset() { String charset = getFallbackCharset(); Header contenttype = this.headers.getFirstHeader(HttpConstants.HEADER_CONTENT_TYPE); if (contenttype != null) { HeaderElement values[] = contenttype.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } return charset; }
private RDFParser getParser(HttpMethod response) { for (Header header : response.getResponseHeaders("Content-Type")) { for (HeaderElement headerEl : header.getElements()) { String mimeType = headerEl.getName(); if (mimeType != null) { RDFFormat format = registry .getFileFormatForMIMEType(mimeType); RDFParserFactory factory = registry.get(format); if (factory != null) return factory.getParser(); } } } throw new UnsupportedQueryResultFormatException( "No parser factory available for this graph query result format"); } }
@Override public FileContentInfo create(final FileContent fileContent) throws FileSystemException { final HttpFileObject httpFile = (HttpFileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile()); String contentType = null; String contentEncoding = null; HeadMethod headMethod; try { headMethod = httpFile.getHeadMethod(); } catch (final IOException e) { throw new FileSystemException(e); } final Header header = headMethod.getResponseHeader("content-type"); if (header != null) { final HeaderElement[] element = header.getElements(); if (element != null && element.length > 0) { contentType = element[0].getName(); } } contentEncoding = headMethod.getResponseCharSet(); return new DefaultFileContentInfo(contentType, contentEncoding); } }
@Override public FileContentInfo create(final FileContent fileContent) throws FileSystemException { final HttpFileObject httpFile = (HttpFileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile()); String contentType = null; String contentEncoding = null; HeadMethod headMethod; try { headMethod = httpFile.getHeadMethod(); } catch (final IOException e) { throw new FileSystemException(e); } final Header header = headMethod.getResponseHeader("content-type"); if (header != null) { final HeaderElement[] element = header.getElements(); if (element != null && element.length > 0) { contentType = element[0].getName(); } } contentEncoding = headMethod.getResponseCharSet(); return new DefaultFileContentInfo(contentType, contentEncoding); } }
@Override public FileContentInfo create(final FileContent fileContent) throws FileSystemException { String contentType = null; String contentEncoding = null; HeadMethod headMethod; try (final HttpFileObject<HttpFileSystem> httpFile = (HttpFileObject<HttpFileSystem>) FileObjectUtils .getAbstractFileObject(fileContent.getFile())) { headMethod = httpFile.getHeadMethod(); } catch (final IOException e) { throw new FileSystemException(e); } final Header header = headMethod.getResponseHeader("content-type"); if (header != null) { final HeaderElement[] element = header.getElements(); if (element != null && element.length > 0) { contentType = element[0].getName(); } } contentEncoding = headMethod.getResponseCharSet(); return new DefaultFileContentInfo(contentType, contentEncoding); } }