Example usage for javax.activation MimeType getPrimaryType

List of usage examples for javax.activation MimeType getPrimaryType

Introduction

In this page you can find the example usage for javax.activation MimeType getPrimaryType.

Prototype

public String getPrimaryType() 

Source Link

Document

Retrieve the primary type of this object.

Usage

From source file:eu.fusepool.p3.transformer.client.TransformerClientImpl.java

@Override
public boolean accepts(MimeType type) {
    for (MimeType m : supportedInputFormats) {
        if ((m.match(type)) || m.getPrimaryType().equals("*")
                || (m.getSubType().equals("*") && m.getPrimaryType().equals(type.getPrimaryType()))) {
            return true;
        }/* w  ww  .  ja va  2s .  c o m*/
    }
    return false;
}

From source file:ddf.content.plugin.video.VideoThumbnailPlugin.java

private boolean isVideo(final ContentItem contentItem) {
    final MimeType createdMimeType = contentItem.getMimeType();
    final MediaType createdMediaType = MediaType.create(createdMimeType.getPrimaryType(),
            createdMimeType.getSubType());
    return createdMediaType.is(MediaType.ANY_VIDEO_TYPE);
}

From source file:net.di2e.ecdr.search.transform.atom.response.AtomResponseTransformer.java

private Metacard entryToMetacard(Entry entry, String siteName) {
    CDRMetacard metacard = new CDRMetacard(CDRMetacardType.CDR_METACARD);

    String id = entry.getIdElement().getText();
    // id may be formatted catalog:id:<id>, so we parse out the <id>
    if (StringUtils.isNotBlank(id) && (id.startsWith("urn:uuid:") || id.startsWith("urn:catalog:id:"))) {
        id = id.substring(id.lastIndexOf(':') + 1);
    }// www  . j ava 2  s.co m
    metacard.setId(id);

    metacard.setSourceId(siteName);

    List<Category> categories = entry.getCategories();
    if (categories != null && !categories.isEmpty()) {
        Category category = categories.get(0);
        metacard.setContentTypeName(category.getTerm());
        IRI scheme = category.getScheme();
        if (scheme != null) {
            metacard.setContentTypeVersion(scheme.toString());
        }
    }

    try {
        metacard.setModifiedDate(entry.getUpdated());
    } catch (IllegalArgumentException e) {
        LOGGER.warn("InvalidDate found in atom reponse, setting Metacard modified time to now ");
        metacard.setEffectiveDate(new Date());
    }
    try {
        metacard.setEffectiveDate(entry.getPublished());
    } catch (IllegalArgumentException e) {
        LOGGER.warn("InvalidDate found in atom reponse, setting Metacard Effective time to now ");
        metacard.setEffectiveDate(new Date());
    }

    String createdDate = entry.getSimpleExtension(new QName(AtomResponseConstants.METACARD_ATOM_NAMESPACE,
            AtomResponseConstants.METACARD_CREATED_DATE_ELEMENT));
    if (createdDate != null) {
        metacard.setCreatedDate(new Date(DATE_FORMATTER.parseMillis(createdDate)));
    }

    String expirationDate = entry.getSimpleExtension(new QName(AtomResponseConstants.METACARD_ATOM_NAMESPACE,
            AtomResponseConstants.METADATA_EXPIRATION_DATE_ELEMENT));
    if (expirationDate != null) {
        metacard.setExpirationDate(new Date(DATE_FORMATTER.parseMillis(expirationDate)));
    }

    AtomContentXmlWrapOption wrap = filterConfig.getAtomContentXmlWrapOption();
    String metadata = entry.getContent();
    populateMetadata(entry, metacard, wrap, metadata);

    metacard.setLocation(getWKT(entry));

    Link productLink = entry.getLink(filterConfig.getProductLinkRelation());
    if (productLink != null) {

        metacard.setResourceURI(URI.create(productLink.getHref().toASCIIString()));
        long resourceSize = productLink.getLength();
        if (resourceSize > 0) {
            metacard.setResourceSize(String.valueOf(resourceSize));
        }
        String productTitle = productLink.getTitle();
        if (productTitle != null) {
            metacard.setAttribute(CDRMetacard.RESOURCE_TITLE, productTitle);
        }
        // ECDR-41 figure out MIMEType
        MimeType productType = productLink.getMimeType();
        if (productType != null) {
            metacard.setAttribute(CDRMetacard.RESOURCE_MIME_TYPE, productType.toString());
        }
    }

    String thumbnailLinkRel = filterConfig.getThumbnailLinkRelation();
    if (thumbnailLinkRel != null) {
        List<Link> links = entry.getLinks(thumbnailLinkRel);
        if (links != null && !links.isEmpty()) {
            for (Link link : links) {
                MimeType mimeType = link.getMimeType();
                if (mimeType == null || "image".equals(mimeType.getPrimaryType())) {

                    metacard.setThumbnailLinkURI(URI.create(link.getHref().toASCIIString()));
                    long thumbnailSize = link.getLength();
                    if (thumbnailSize > 0) {
                        metacard.setAttribute(CDRMetacard.THUMBNAIL_LENGTH, Long.valueOf(thumbnailSize));
                    }
                    // ECDR-41 figure out MIMEType
                    metacard.setAttribute(CDRMetacard.THUMBNAIL_MIMETYPE, link.getMimeType());
                    metacard.setAttribute(CDRMetacard.THUMBNAIL_LINK_TITLE, link.getTitle());
                    break;
                }
            }
        }
    }
    metacard.setTitle(entry.getTitle());

    boolean isMetadataSet = false;
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(AtomResponseTransformer.class.getClassLoader());
        List<Element> extensions = entry.getExtensions();
        for (Element element : extensions) {
            if (METADATA_ELEMENT_NAME.equalsIgnoreCase(element.getQName().getLocalPart())) {
                StringWriter writer = new StringWriter();
                try {
                    element.writeTo(writer);
                    metacard.setMetadata(writer.toString());
                    isMetadataSet = true;
                    break;
                } catch (IOException e) {
                    LOGGER.error(
                            "Could not convert Metadata String value from Atom to Metacard.METADATA attribute",
                            e);
                }

            }
        }
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }
    if (!isMetadataSet) {
        String metadataLinkRel = filterConfig.getMetadataLinkRelation();
        if (metadataLinkRel != null) {
            List<Link> metadataLinks = entry.getLinks(metadataLinkRel);
            String metadataLink = null;
            for (Link link : metadataLinks) {
                MimeType mimeType = link.getMimeType();
                if (mimeType != null) {
                    if (mimeType.getSubType().contains("xml")) {
                        metadataLink = link.getHref().toASCIIString();
                        metacard.setMetadataLinkURI(URI.create(metadataLink));
                        metacard.setAttribute(CDRMetacard.WRAP_METADATA, null);
                        break;
                    } else if (mimeType.getBaseType().contains("text")) {
                        metadataLink = link.getHref().toASCIIString();
                        metacard.setMetadataLinkURI(URI.create(metadataLink));
                        metacard.setAttribute(CDRMetacard.WRAP_METADATA, Boolean.TRUE);
                    }
                }
            }
        }
    }
    Metacard returnMetacard = SecurityMarkingParser.addSecurityToMetacard(metacard, entry);
    return new CDRMetacard(returnMetacard);
}

From source file:fi.foyt.fni.materials.MaterialController.java

public Material createMaterial(Folder parentFolder, User user, FileData fileData)
        throws MimeTypeParseException, IOException, GeneralSecurityException {
    MimeType mimeType = parseMimeType(fileData.getContentType());

    if ("image".equals(mimeType.getPrimaryType())) {
        if ("svg".equals(mimeType.getSubType()) || "svg+xml".equals(mimeType.getSubType())) {
            return createVectorImage(parentFolder, user, new String(fileData.getData(), "UTF-8"),
                    fileData.getFileName());
        } else {//  ww w. j av a  2  s . co  m
            if (fileData.getContentType().equals("image/png")) {
                return createImage(parentFolder, user, fileData.getData(), fileData.getContentType(),
                        fileData.getFileName());
            } else {
                return uploadImage(parentFolder, user, fileData);
            }
        }
    } else {
        switch (mimeType.getBaseType()) {
        case "application/pdf":
            return uploadPdf(parentFolder, user, fileData);
        case "text/plain":
            return uploadText(parentFolder, user, fileData);
        case "text/html":
        case "application/xhtml+xml":
            return uploadHtml(parentFolder, user, fileData);
        case "application/vnd.oasis.opendocument.text":
        case "application/vnd.sun.xml.writer":
        case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
        case "application/msword":
        case "application/x-mswrite":
        case "application/rtf":
        case "text/richtext":
            return uploadDocument(parentFolder, user, fileData);
        case "application/vnd.openxmlformats-officedocument.presentationml.slideshow":
        case "application/vnd.ms-powerpoint":
            // TODO: Warning: presentation
            return uploadDocument(parentFolder, user, fileData);
        case "application/vnd.ms-excel":
        case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
        case "application/vnd.oasis.opendocument.spreadsheet":
        case "text/csv":
        case "text/tab-separated-values":
            // TODO: Warning, spreadsheet
            return uploadDocument(parentFolder, user, fileData);
        }
    }

    return createFile(parentFolder, user, fileData.getData(), fileData.getContentType(),
            fileData.getFileName());
}

From source file:org.mule.endpoint.AbstractEndpointBuilder.java

public void setMimeType(String mimeType) {
    if (mimeType == null) {
        this.mimeType = null;
    } else {//from   ww  w .j  av a2 s.  co  m
        MimeType mt;
        try {
            mt = new MimeType(mimeType);
        } catch (MimeTypeParseException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
        this.mimeType = mt.getPrimaryType() + "/" + mt.getSubType();
    }
}

From source file:org.mule.intents.TypeChecker.java

public Object onCall(MuleEventContext eventContext) throws Exception {
    //Check outbound first since this would override the inbound Content-type in the flow
    String contentType = (String) eventContext.getMessage().getOutboundProperty(("Content-Type"));
    if (contentType == null) {
        contentType = (String) eventContext.getMessage().getInboundProperty(("Content-Type"));
        if (contentType == null) {
            logger.error("current message doesn't have a 'Content-Type' header set");
            logger.error(eventContext.getMessage().toString());
            return eventContext;
        }/* ww  w .  j  av a 2  s .c o  m*/
    }

    MimeType mimeType = new MimeType(contentType);
    if (!filter.accept(mimeType.getPrimaryType() + "/" + mimeType.getSubType())) {
        throw new IllegalArgumentException("The current message content type: " + contentType
                + " is not compatible with return data-type for template: " + getTemplate()
                + ". This Template output data type should be: " + getTypes());
    }

    return eventContext.getMessage();
}

From source file:org.mule.transformer.AbstractTransformer.java

public void setMimeType(String mimeType) throws MimeTypeParseException {
    if (mimeType == null) {
        this.mimeType = null;
    } else {/*  w  w  w  .ja va 2  s  .  com*/
        MimeType mt = new MimeType(mimeType);
        this.mimeType = mt.getPrimaryType() + "/" + mt.getSubType();
    }
    if (returnType != null) {
        returnType.setMimeType(mimeType);
    }
}

From source file:org.mule.transformer.types.SimpleDataType.java

public SimpleDataType(Class<?> type, String mimeType) {
    this.type = type;
    if (mimeType == null) {
        this.mimeType = ANY_MIME_TYPE;
    } else {// w w  w . j a  va 2s  . co m
        try {
            MimeType mt = new MimeType(mimeType);
            this.mimeType = mt.getPrimaryType() + "/" + mt.getSubType();
            if (mt.getParameter("charset") != null) {
                encoding = mt.getParameter("charset");
            }
        } catch (MimeTypeParseException e) {
            //TODO, this should really get thrown
            throw new MuleRuntimeException(e);
        }
    }
}

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   www  .  j av a  2  s .  co m*/
    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);
}