List of usage examples for javax.activation MimeType getSubType
public String 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; }//from ww w.j ava2 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.codice.ddf.catalog.transformer.zip.ZipCompression.java
private String getFileExtensionFromService(ServiceReference<MetacardTransformer> serviceRef) { Object mimeTypeProperty = serviceRef.getProperty("mime-type"); if (mimeTypeProperty == null) { return ""; }//from w w w . j a v a 2 s . c o m String mimeTypeStr = mimeTypeProperty.toString(); try { MimeType exportMimeType = new MimeType(mimeTypeStr); return exportMimeType.getSubType(); } catch (MimeTypeParseException e) { LOGGER.debug("Failed to parse mime type {}", mimeTypeStr, e); return ""; } }
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 {/*from w ww.j a v a2 s.c o 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: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; }/*from w w w . j a v a 2 s.co m*/ } return false; }
From source file:org.mule.transformer.AbstractTransformer.java
public void setMimeType(String mimeType) throws MimeTypeParseException { if (mimeType == null) { this.mimeType = null; } else {// ww w . j ava 2s. com MimeType mt = new MimeType(mimeType); this.mimeType = mt.getPrimaryType() + "/" + mt.getSubType(); } if (returnType != null) { returnType.setMimeType(mimeType); } }
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:org.mule.endpoint.AbstractEndpointBuilder.java
public void setMimeType(String mimeType) { if (mimeType == null) { this.mimeType = null; } else {/*w ww . ja v a 2s .c om*/ 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.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(); }//w w w. j a v a 2 s . com 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); }
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 {/* w ww .jav a2 s.c om*/ 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: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); }/* w w w.j av a2s. 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); }