Example usage for javax.activation MimeType MimeType

List of usage examples for javax.activation MimeType MimeType

Introduction

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

Prototype

public MimeType() 

Source Link

Document

Default constructor.

Usage

From source file:ddf.catalog.cache.impl.ResourceCacheTest.java

/**
 * Verifies that put() method works.//  w  w  w .  ja  v  a  2 s.c o m
 *
 */
@Test
public void testPutThenGet() {
    String fileName = "15bytes.txt";
    String productLocation = System.getProperty("user.dir") + "/src/test/resources/" + fileName;
    File rrCachedFile = new File(productLocation);
    String key = "ddf-1-abc123";
    MetacardImpl metacard = new MetacardImpl();
    ReliableResource reliableResource = new ReliableResource(key, rrCachedFile.getAbsolutePath(),
            new MimeType(), fileName, metacard);

    resourceCache.addPendingCacheEntry(reliableResource);
    assertTrue(resourceCache.isPending(key));
    resourceCache.put(reliableResource);
    assertTrue(assertReliableResourceEquals(reliableResource, resourceCache.getValid(key, metacard)));
    assertFalse(resourceCache.isPending(key));
}

From source file:ddf.catalog.cache.impl.ResourceCacheTest.java

/**
 * Verifies that put() method works even if entry being added was never
 * in the pending cache list.//from   w  w  w  . j av  a  2  s.  com
 *
 */
@Test
public void testPutThenGetNotPending() {
    String fileName = "15bytes.txt";
    String productLocation = System.getProperty("user.dir") + "/src/test/resources/" + fileName;
    File rrCachedFile = new File(productLocation);
    String key = "ddf-1-abc123";
    MetacardImpl metacard = new MetacardImpl();
    ReliableResource reliableResource = new ReliableResource(key, rrCachedFile.getAbsolutePath(),
            new MimeType(), fileName, metacard);

    resourceCache.put(reliableResource);
    assertFalse(resourceCache.isPending(key));
    assertTrue(assertReliableResourceEquals(reliableResource, resourceCache.getValid(key, metacard)));
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.transformer.CswQueryResponseTransformer.java

@Override
public BinaryContent transform(SourceResponse sourceResponse, Map<String, Serializable> arguments)
        throws CatalogTransformerException {

    validateInput(sourceResponse, arguments);

    CswRecordCollection recordCollection = buildCollection(sourceResponse, arguments);

    ByteArrayInputStream bais;//from  w  w w.  jav  a  2  s. c  o m

    if (ResultType.VALIDATE.equals(recordCollection.getResultType())) {
        ByteArrayOutputStream baos = writeAcknowledgement(recordCollection.getRequest());
        bais = new ByteArrayInputStream(baos.toByteArray());
    } else {
        // "catches" recordCollection.getResultType() == null
        List<Result> results = sourceResponse.getResults();
        String xmlString = convert(recordCollection, results, arguments);
        bais = new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8));
    }

    BinaryContent transformedContent = new BinaryContentImpl(bais, new MimeType());
    return transformedContent;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.transformer.GmdTransformer.java

@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments)
        throws CatalogTransformerException {
    StringWriter stringWriter = new StringWriter();
    Boolean omitXmlDec = null;/* ww w. j  av a 2  s .  c om*/
    if (MapUtils.isNotEmpty(arguments)) {
        omitXmlDec = (Boolean) arguments.get(CswConstants.OMIT_XML_DECLARATION);
    }

    if (omitXmlDec == null || !omitXmlDec) {
        stringWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
    }

    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter, new NoNameCoder());

    MarshallingContext context = new TreeMarshaller(writer, null, null);
    copyArgumentsToContext(context, arguments);

    new GmdConverter().marshal(metacard, writer, context);

    BinaryContent transformedContent;

    ByteArrayInputStream bais = new ByteArrayInputStream(
            stringWriter.toString().getBytes(StandardCharsets.UTF_8));
    transformedContent = new BinaryContentImpl(bais, new MimeType());
    return transformedContent;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter.java

@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments)
        throws CatalogTransformerException {
    StringWriter stringWriter = new StringWriter();
    Boolean omitXmlDec = (Boolean) arguments.get(CswConstants.OMIT_XML_DECLARATION);

    if (omitXmlDec == null || !omitXmlDec) {
        stringWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
    }/* ww w.  j  a va2 s  .  c o m*/

    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.WRITE_NAMESPACES, true);
    copyArgumentsToContext(context, arguments);

    this.marshal(metacard, writer, context);

    BinaryContent transformedContent = null;

    ByteArrayInputStream bais = new ByteArrayInputStream(
            stringWriter.toString().getBytes(StandardCharsets.UTF_8));
    transformedContent = new BinaryContentImpl(bais, new MimeType());
    return transformedContent;
}

From source file:ddf.catalog.cache.ResourceCacheImplSizeLimitTest.java

private ReliableResource simulateAddFileToProductCache(String key, String fileName, String destFileName,
        IMap<String, ReliableResource> cacheMap) throws IOException {
    String productOriginalLocation = new File(this.getClass().getClassLoader().getResource(fileName).getPath())
            .getAbsolutePath();//w  w  w. j  a va2 s.com
    File rrCachedFile = new File(productCacheDir + "/" + destFileName);
    FileUtils.copyFile(new File(productOriginalLocation), rrCachedFile);
    ReliableResource rr = new ReliableResource(key, rrCachedFile.getAbsolutePath(), new MimeType(), fileName,
            new MetacardImpl());
    rr.setSize(rrCachedFile.length());
    LOGGER.debug("adding entry to cache: {}", key);
    cacheMap.put(key, rr);
    listener.entryAdded(
            new EntryEvent<Object, Object>(destFileName, null, EntryEventType.ADDED.getType(), key, rr));
    return rr;
}

From source file:ddf.catalog.cache.ResourceCacheSizeLimitTest.java

private ReliableResource simulateAddFileToProductCache(String key, String fileName, String destFileName,
        IMap<String, ReliableResource> cacheMap) throws IOException {
    String productOriginalLocation = this.getClass().getResource("/" + fileName).getFile();
    File rrCachedFile = new File(productCacheDir + "/" + destFileName);
    FileUtils.copyFile(new File(productOriginalLocation), rrCachedFile);
    ReliableResource rr = new ReliableResource(key, rrCachedFile.getAbsolutePath(), new MimeType(), fileName,
            new MetacardImpl());
    rr.setSize(rrCachedFile.length());//from w  ww .j a  v  a 2s .c  o  m
    LOGGER.debug("adding entry to cache: " + key);
    cacheMap.put(key, rr);
    listener.entryAdded(
            new EntryEvent<Object, Object>(destFileName, null, EntryEventType.ADDED.getType(), key, rr));
    return rr;
}

From source file:ddf.catalog.cache.impl.ResourceCacheImplTest.java

private ReliableResource createCachedResource(Metacard metacard) {
    String fileName = "15bytes.txt";
    String productLocation = this.getClass().getResource("/" + fileName).getFile();
    File rrCachedFile = new File(productLocation);
    return new ReliableResource(CACHED_RESOURCE_KEY, rrCachedFile.getAbsolutePath(), new MimeType(), fileName,
            metacard);/*from w  w  w. j  a v  a2 s.c o m*/
}

From source file:org.wso2.carbon.registry.app.RegistryAdapter.java

/**
 * Method to add media content.//from   ww w .ja v a 2  s.  c o  m
 *
 * @param feedIri  the feed IRI.
 * @param entry    the entry.
 * @param entryObj the resource object.
 * @param request  the request context.
 *
 * @return the added media IRI.
 * @throws ResponseContextException
 */
protected String addMediaContent(IRI feedIri, Entry entry, Resource entryObj, RequestContext request)
        throws ResponseContextException {
    String fullUrl;
    if (entry.getAlternateLink() != null && entry.getAlternateLink().getHref() != null) {
        fullUrl = entry.getAlternateLink().getHref().toString();
        if (fullUrl == null || fullUrl.length() == 0 || fullUrl.indexOf(APPConstants.ATOM) <= 0) {
            fullUrl = feedIri.toString();
        }
    } else {
        fullUrl = feedIri.toString();
    }

    String absoluteBase = fullUrl.substring(0, fullUrl.indexOf(APPConstants.ATOM));
    IRI mediaIri = new IRI(
            absoluteBase + APPConstants.RESOURCE + "/" + URLEncoder.encode(getMediaName(entryObj)));
    String mediaLink = mediaIri.toString();
    String mime = getContentType(entryObj);
    if (mime == null) {
        mime = "application/octet-stream";
    }
    try {
        new MimeType().match(mime);
    } catch (MimeTypeParseException e) {
        mime = "application/octet-stream";
    }
    entry.setContent(mediaIri, mime);
    entry.addLink(mediaLink, Link.REL_EDIT_MEDIA);

    return mediaLink;
}