List of usage examples for javax.activation MimeType toString
public String toString()
From source file:eu.openanalytics.rsb.Util.java
/** * Returns the must probable resource type for a MimeType. * /* w w w. j a v a 2 s . c o m*/ * @param mimeType * @return */ public static String getResourceType(final MimeType mimeType) { final String result = DEFAULT_FILE_EXTENSIONS.get(mimeType.toString()); return result != null ? result : DEFAULT_FILE_EXTENSION; }
From source file:org.apache.abdera2.activities.client.ActivityEntity.java
public ActivityEntity(ASBase base, boolean calclen, MimeType contentType) { this(base, calclen, contentType.toString()); }
From source file:org.apache.abdera2.test.client.MultipartRelatedEntityTest.java
License:asdf
@Test public void testMultimediaRelatedContentType() throws Exception { MimeType type = new MimeType("Multipart/Related;boundary=\"35245352345sdfg\""); assertTrue(MimeTypeHelper.isMatch("Multipart/Related", type.toString())); assertEquals("35245352345sdfg", type.getParameter("boundary")); }
From source file:eu.fusepool.p3.transformer.client.TransformerClientImpl.java
@Override public Entity transform(Entity entity, MimeType... acceptedFormats) { HttpURLConnection connection = null; try {//from w w w . j a v a 2 s. c o m final URL transfromerUrl = uri.toURL(); connection = (HttpURLConnection) transfromerUrl.openConnection(); connection.setRequestMethod("POST"); String acceptHeaderValue = null; if (acceptedFormats.length > 0) { final StringWriter acceptString = new StringWriter(); double q = 1; for (MimeType mimeType : acceptedFormats) { acceptString.write(mimeType.toString()); acceptString.write("; q="); acceptString.write(Double.toString(q)); q = q * 0.9; acceptString.write(", "); } acceptHeaderValue = acceptString.toString(); connection.setRequestProperty("Accept", acceptHeaderValue); } connection.setRequestProperty("Content-Type", entity.getType().toString()); if (entity.getContentLocation() != null) { connection.setRequestProperty("Content-Location", entity.getContentLocation().toString()); } connection.setDoOutput(true); connection.setUseCaches(false); try (OutputStream out = connection.getOutputStream()) { entity.writeData(out); } final int responseCode = connection.getResponseCode(); if (responseCode == 200) { return getResponseEntity(connection); } if ((responseCode == 202) || (responseCode == 201)) { final String location = connection.getHeaderField("Location"); if (location == null) { throw new RuntimeException("No location header in first 202 response"); } return getAsyncResponseEntity(new URL(transfromerUrl, location), acceptHeaderValue); } throw new UnexpectedResponseException(responseCode, getResponseEntity(connection)); } catch (IOException e) { throw new RuntimeException("Cannot establish connection to " + uri.toString() + " !", e); } catch (MimeTypeParseException ex) { throw new RuntimeException("Error parsing MediaType returned from Server. ", ex); } finally { if (connection != null) { connection.disconnect(); } } }
From source file:com.googlecode.ddom.frontend.saaj.impl.SwAProfile.java
@Override public String getContentType() { MimeType contentType; try {//from ww w .java2 s.c o m contentType = new MimeType("multipart", "related"); } catch (MimeTypeParseException ex) { throw new Error(ex); } contentType.setParameter("type", getSOAPVersion().getContentType()); contentType.setParameter("boundary", boundary); return contentType.toString(); }
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 ww .java2 s . c o 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:com.haulmont.cuba.restapi.DataServiceController.java
private void writeResponse(HttpServletResponse response, String result, MimeType mimeType) throws IOException { response.setContentType(mimeType.toString()); PrintWriter writer = response.getWriter(); writer.write(result);//ww w .j a v a2 s . c om writer.flush(); }
From source file:fedora.server.storage.translation.AtomDODeserializer.java
private Datastream addInlineDatastreamVersion(Entry entry) throws ObjectIntegrityException, StreamIOException { DatastreamXMLMetadata ds = new DatastreamXMLMetadata(); setDSCommonProperties(ds, entry);//from ww w. java2s . co m String dsId = ds.DatastreamID; String dsvId = ds.DSVersionID; ds.DSLocation = m_obj.getPid() + "+" + dsId + "+" + dsvId; if (ds.DSVersionID.equals("AUDIT.0")) { addAuditDatastream(entry); } else { try { if (m_format.equals(ATOM_ZIP1_1)) { ByteArrayOutputStream bout = new ByteArrayOutputStream(); FileUtils.copy(new FileInputStream(getContentSrcAsFile(entry.getContentSrc())), bout); ds.xmlContent = bout.toByteArray(); } else { ds.xmlContent = entry.getContent().getBytes(m_encoding); //IOUtils.toByteArray(entry.getContentStream()); } } catch (UnsupportedEncodingException e) { throw new StreamIOException(e.getMessage(), e); } catch (FileNotFoundException e) { throw new ObjectIntegrityException(e.getMessage(), e); } } if (ds.xmlContent != null) { ds.DSSize = ds.xmlContent.length; } MimeType mimeType = entry.getContentMimeType(); if (mimeType == null) { ds.DSMIME = "text/xml"; } else { ds.DSMIME = mimeType.toString(); } return ds; }
From source file:ddf.catalog.transformer.resource.ResourceMetacardTransformerTest.java
private void testGetResource(Metacard metacard, String filePath, MimeType mimeType, CatalogFramework framework, boolean expectSuccess) throws Exception { ResourceMetacardTransformer resourceTransformer = new ResourceMetacardTransformer(framework); BinaryContent binaryContent = resourceTransformer.transform(metacard, new HashMap<String, Serializable>()); byte[] fileContents = FileUtils.readFileToByteArray(new File(filePath)); byte[] contentsFromResults = IOUtils.toByteArray(binaryContent.getInputStream()); if (expectSuccess) { assertEquals(binaryContent.getMimeTypeValue(), mimeType.toString()); assertTrue(Arrays.equals(fileContents, contentsFromResults)); }// w ww . jav a 2 s . c o m }
From source file:ddf.catalog.transformer.resource.TestResourceMetacardTransformer.java
private void testGetResource(Metacard metacard, String filePath, MimeType mimeType, CatalogFramework framework, boolean expectSuccess) throws Exception { ResourceMetacardTransformer resourceTransformer = new ResourceMetacardTransformer(framework); BinaryContent binaryContent = resourceTransformer.transform(metacard, new HashMap<String, Serializable>()); byte[] fileContents = FileUtils.readFileToByteArray(new File(filePath)); byte[] contentsFromResults = IOUtils.toByteArray(binaryContent.getInputStream()); if (expectSuccess) { assertEquals(binaryContent.getMimeTypeValue(), mimeType.toString()); assertTrue(Arrays.equals(fileContents, contentsFromResults)); }//from w ww. j av a 2 s.c o m }