Example usage for javax.activation MimeTypeParameterList getNames

List of usage examples for javax.activation MimeTypeParameterList getNames

Introduction

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

Prototype

public Enumeration getNames() 

Source Link

Document

Retrieve an enumeration of all the names in this list.

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 ww w  .j a v  a  2 s  .c  o  m
    }
    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  a  va  2  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./*from   w w  w . j a  v  a2 s  . co 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();
    }//from ww w .  ja  va2s  .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);
}