List of usage examples for com.google.common.net MediaType PDF
MediaType PDF
To view the source code for com.google.common.net MediaType PDF.
Click Source Link
From source file:helper.ThumbnailGenerator.java
/** * @param ts//from w w w . j a v a 2 s. com * the actual content to create a thumbnail from * @param contentType * the MediaType for the content * @param size * acually the width * @param name * @return a thumbnail file */ public static File createThumbnail(InputStream ts, MediaType contentType, int size, String name) { File result = null; try { if (contentType.is(MediaType.JPEG)) { result = generateThumbnailFromImage(ts, size, "jpeg", name); } else if (contentType.is(MediaType.PNG)) { result = generateThumbnailFromImage(ts, size, "png", name); } else if (contentType.is(MediaType.GIF)) { result = generateThumbnailFromImage(ts, size, "gif", name); } else if (contentType.is(MediaType.PDF)) { result = generateThumbnailFromPdf(ts, size, name); } else { result = generateMimeTypeImage(contentType, size, name); } } catch (Throwable e) { play.Logger.warn("", e); result = generateThumbnailFromImage(Play.application().resourceAsStream(THUMBNAIL_EXCEPTION_PIC), size, "png", name); } return result; }
From source file:ddf.catalog.transformer.input.pdf.PdfInputTransformer.java
private MetacardImpl initializeMetacard(String id) { MetacardImpl metacard = new MetacardImpl(); metacard.setId(id);// ww w . java2 s . c o m metacard.setContentTypeName(MediaType.PDF.subtype()); return metacard; }
From source file:helper.ThumbnailGenerator.java
private static File generateMimeTypeImage(MediaType contentType, int size, String name) { File result = null;//ww w.j av a2 s . c o m try { if (contentType.is(MediaType.ANY_AUDIO_TYPE)) { result = generateThumbnailFromImage(Play.application().resourceAsStream(AUDIO_PIC), size, "png", name); } else if (contentType.is(MediaType.ANY_IMAGE_TYPE)) { result = generateThumbnailFromImage(Play.application().resourceAsStream(IMAGE_PIC), size, "png", name); } else if (contentType.is(MediaType.ANY_TEXT_TYPE) || contentType.is(MediaType.OOXML_DOCUMENT) || contentType.is(MediaType.MICROSOFT_WORD)) { result = generateThumbnailFromImage(Play.application().resourceAsStream(TEXT_PIC), size, "png", name); } else if (contentType.is(MediaType.ANY_VIDEO_TYPE)) { result = generateThumbnailFromImage(Play.application().resourceAsStream(VIDEO_PIC), size, "png", name); } else if (contentType.is(MediaType.ZIP)) { result = generateThumbnailFromImage(Play.application().resourceAsStream(ZIP_PIC), size, "png", name); } else if (contentType.is(MediaType.PDF)) { result = generateThumbnailFromImage(Play.application().resourceAsStream(PDF_PIC), size, "png", name); } else { result = generateThumbnailFromImage(Play.application().resourceAsStream(MIMETYPE_NOT_FOUND_PIC), size, "png", name); } } catch (Throwable e) { play.Logger.warn("", e); result = generateThumbnailFromImage(Play.application().resourceAsStream(EXCEPTION_ON_APPLY_MIMETYPE), size, "png", name); } return result; }
From source file:rapture.elasticsearch.ElasticSearchSearchRepository.java
@SuppressWarnings("rawtypes") @Override//from w w w.j a v a 2 s . co m public void put(AbstractUpdateObject updateObject) { RaptureURI uri = updateObject.getUri(); log.info("URI for indexing is " + uri.toString()); putUriStore(uri); if (updateObject instanceof DocUpdateObject) { DocumentWithMeta docMeta = ((DocUpdateObject) updateObject).getPayload(); ensureClient().prepareIndex(index, uri.getScheme().toString(), uri.toString()) .setSource(docMeta.getContent()).get(); String meta = JacksonUtil.jsonFromObject(docMeta.getMetaData()); ensureClient().prepareIndex(index, SearchRepoType.meta.toString(), uri.toString()).setSource(meta) .get(); } else if (updateObject instanceof SeriesUpdateObject) { Map<String, String> map = ((SeriesUpdateObject) updateObject).asStringMap(); if (!map.isEmpty()) { synchronized (client) { ensureClient().prepareUpdate(index, uri.getScheme().toString(), uri.toString()).setDoc(map) .setUpsert(map).setRetryOnConflict(DEFAULT_RETRY_ON_CONFLICT).get(); } } } else if (updateObject instanceof BlobUpdateObject) { BlobContainer content = ((BlobUpdateObject) updateObject).getPayload(); /** * You have to give ElasticSearch a JSON document. We can determine what it is by checking updateObject.getMimeType() Do we need to index the blob's * mime type and any other metadata too? */ // Tika can handle other types too, but at present all we really care about are blobs and CSVs if (updateObject.getMimeType().equals(MediaType.PDF.toString())) { // Tika can take a while so do it in the background new Thread() { @SuppressWarnings("synthetic-access") @Override public void run() { try { String contentStr = tikaPDF .parseToString(new ByteArrayInputStream(content.getContent())); XContentBuilder source = jsonBuilder().startObject().field("blob", contentStr) .endObject(); ensureClient().prepareIndex(index, Scheme.BLOB.toString(), uri.toString()) .setSource(source).get(); } catch (IOException | TikaException e) { log.error("Cannot index PDF " + e.getMessage()); log.debug(ExceptionToString.format(e)); throw RaptureExceptionFactory.create("Cannot index PDF " + e.getMessage(), e); } } }.start(); } else { try { XContentBuilder source = jsonBuilder().startObject() .field("blob", new String(content.getContent())).endObject(); ensureClient().prepareIndex(index, Scheme.BLOB.toString(), uri.toString()).setSource(source) .get(); } catch (IOException ioe) { log.error("Cannot index CSV " + ioe.getMessage()); log.debug(ExceptionToString.format(ioe)); throw RaptureExceptionFactory.create("Cannot index blob " + ioe.getMessage(), ioe); } } try { Map<String, String> headers = content.getHeaders(); XContentBuilder source = jsonBuilder().startObject(); if (headers != null) { for (Entry<String, String> entry : headers.entrySet()) { source.field(entry.getKey(), entry.getValue()); } } source.field("mimetype", updateObject.getMimeType()).endObject(); ensureClient().prepareIndex(index, SearchRepoType.meta.toString(), uri.toString()).setSource(source) .get(); } catch (IOException ioe) { log.error("Cannot index blob metadata " + ioe.getMessage()); log.debug(ExceptionToString.format(ioe)); throw RaptureExceptionFactory.create("Cannot index blob " + ioe.getMessage(), ioe); } } else { throw new RaptNotSupportedException( String.format("Search update for uri [%s] not supported yet", uri.toString())); } }