Example usage for javax.activation MimetypesFileTypeMap addMimeTypes

List of usage examples for javax.activation MimetypesFileTypeMap addMimeTypes

Introduction

In this page you can find the example usage for javax.activation MimetypesFileTypeMap addMimeTypes.

Prototype

public synchronized void addMimeTypes(String mime_types) 

Source Link

Document

Prepend the MIME type values to the registry.

Usage

From source file:eu.planets_project.tb.gui.backing.data.DigitalObjectTreeNode.java

/**
 * @return/* w ww.j  a  v a2s.co  m*/
 */
public String getMimeType() {
    String mimetype = null;

    // Lookup in this:
    MimetypesFileTypeMap mimeMap = new MimetypesFileTypeMap();
    // Ensure the image/png mapping is present, as it appears to be broken in Java 6
    // See http://furiouspurpose.blogspot.com/2009/01/what-does-java-6-have-against-imagepng.html
    mimeMap.addMimeTypes("image/png png");

    // Based only on URI:
    if (getUri() != null)
        mimetype = mimeMap.getContentType(getUri().getPath());

    // Return this if it worked.
    if (mimetype != null)
        return mimetype;

    // Otherwise, inspect content of the Digital Object: Title:
    if (getDob() != null && getDob().getTitle() != null)
        mimetype = mimeMap.getContentType(getDob().getTitle());

    return mimetype;
}