Example usage for javax.activation MimeTypeParameterList get

List of usage examples for javax.activation MimeTypeParameterList get

Introduction

In this page you can find the example usage for javax.activation MimeTypeParameterList get.

Prototype

public String get(String name) 

Source Link

Document

Retrieve the value associated with the given name, or null if there is no current association.

Usage

From source file:org.apache.abdera2.common.protocol.ClientResponseImpl.java

@SuppressWarnings("rawtypes")
public String getCharacterEncoding() {
    MimeType mt = this.getContentType();
    if (mt != null) {
        MimeTypeParameterList list = mt.getParameters();
        Enumeration names = list.getNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            if (name.equalsIgnoreCase("charset"))
                return list.get(name);
        }//from w ww.  j ava2 s  .c om
    }
    return "UTF-8";
}

From source file:org.codehaus.httpcache4j.MIMEType.java

@SuppressWarnings("unchecked")
private void convertParamerters(MimeType mimeType) {
    MimeTypeParameterList list = mimeType.getParameters();
    Enumeration names = list.getNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        parameters.add(new Parameter(name, list.get(name)));
    }/*from   w  w w  .j  ava2  s  .co  m*/
}

From source file:org.mulgara.resolver.http.HttpContent.java

/**
 * Read the mime type. Should only be done if the Mime type is not already available
 * as this will close the connection.// w ww  . j  a  v a2 s . c  o m
 * @return The MimeType for the URL.
 * @throws NotModifiedException if the content validates against the cache
 */
@SuppressWarnings("unchecked")
private MimeType readMimeType(HttpMethod method) throws NotModifiedException {
    MimeType result = null;
    String contentType = null;

    try {
        // obtain connection and retrieve the headers
        Header header = method.getResponseHeader("Content-Type");
        if (header != null) {
            contentType = header.getValue();
            // find the parameter separator so we can protect against bad params
            int sep = contentType.indexOf(';');
            // no params, just create the MimeType
            if (sep < 0)
                result = new MimeType(contentType);
            else {
                // create the MimeType from the type/subtype
                result = new MimeType(contentType.substring(0, sep));
                // parse parameters separately and set the result accordingly
                try {
                    MimeTypeParameterList params = new MimeTypeParameterList(contentType.substring(sep + 1));
                    Enumeration<String> names = (Enumeration<String>) params.getNames();
                    while (names.hasMoreElements()) {
                        String name = names.nextElement();
                        result.setParameter(name, params.get(name));
                    }
                } catch (MimeTypeParseException e) {
                    logger.warn("Ignoring bad parameters in '" + contentType.substring(sep + 1)
                            + "' from the content type for " + httpUri);
                }
            }
            if (logger.isInfoEnabled()) {
                logger.info("Obtain content type " + result + "  from " + httpUri);
            }
        }
    } catch (java.lang.IllegalStateException e) {
        logger.info("Unable to obtain content type for " + httpUri);
    } catch (MimeTypeParseException e) {
        logger.warn("Unexpected parameters before ; in '" + contentType + "' as a content type for " + httpUri);
    }
    return result;
}

From source file:org.xcmis.restatom.collections.CmisObjectCollection.java

@SuppressWarnings("unchecked")
protected org.xcmis.spi.utils.MimeType convertMimeType(MimeType abderaMimeType) {
    if (abderaMimeType == null) {
        return new org.xcmis.spi.utils.MimeType();
    }/* ww w.ja  v a  2s .c om*/
    MimeTypeParameterList abderaParameters = abderaMimeType.getParameters();
    Map<String, String> paremeters = new HashMap<String, String>();
    for (Enumeration<String> names = abderaParameters.getNames(); names.hasMoreElements();) {
        String name = names.nextElement();
        paremeters.put(name, abderaParameters.get(name));
    }
    return new org.xcmis.spi.utils.MimeType(abderaMimeType.getPrimaryType(), abderaMimeType.getSubType(),
            paremeters);
}