List of usage examples for org.apache.poi.openxml4j.opc PackageRelationshipTypes THUMBNAIL
String THUMBNAIL
To view the source code for org.apache.poi.openxml4j.opc PackageRelationshipTypes THUMBNAIL.
Click Source Link
From source file:org.alfresco.repo.content.transform.OOXMLThumbnailContentTransformer.java
License:Open Source License
@Override protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception { final String sourceMimetype = reader.getMimetype(); final String sourceExtension = getMimetypeService().getExtension(sourceMimetype); final String targetMimetype = writer.getMimetype(); if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Transforming from ").append(sourceMimetype).append(" to ").append(targetMimetype); log.debug(msg.toString());// ww w . j a v a2 s . co m } OPCPackage pkg = null; try { File ooxmlTempFile = TempFileProvider.createTempFile(this.getClass().getSimpleName() + "_ooxml", sourceExtension); reader.getContent(ooxmlTempFile); // Load the file pkg = OPCPackage.open(ooxmlTempFile.getPath()); // Does it have a thumbnail? PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL); if (rels.size() > 0) { // Get the thumbnail part PackageRelationship tRel = rels.getRelationship(0); PackagePart tPart = pkg.getPart(tRel); // Write it to the target InputStream tStream = tPart.getInputStream(); writer.putContent(tStream); tStream.close(); } else { log.debug("No thumbnail present in " + reader.toString()); throw new UnimportantTransformException(NO_THUMBNAIL_PRESENT_IN_FILE + targetMimetype); } } catch (IOException e) { throw new AlfrescoRuntimeException("Unable to transform " + sourceExtension + " file.", e); } finally { if (pkg != null) { pkg.close(); } } }
From source file:org.apache.tika.parser.microsoft.ooxml.AbstractOOXMLExtractor.java
License:Apache License
private void handleThumbnail(ContentHandler handler) { try {//from ww w . j av a 2 s.c o m OPCPackage opcPackage = extractor.getPackage(); for (PackageRelationship rel : opcPackage.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL)) { PackagePart tPart = opcPackage.getPart(rel); InputStream tStream = tPart.getInputStream(); Metadata thumbnailMetadata = new Metadata(); String thumbName = tPart.getPartName().getName(); thumbnailMetadata.set(Metadata.RESOURCE_NAME_KEY, thumbName); AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute(XHTML, "class", "class", "CDATA", "embedded"); attributes.addAttribute(XHTML, "id", "id", "CDATA", thumbName); handler.startElement(XHTML, "div", "div", attributes); handler.endElement(XHTML, "div", "div"); thumbnailMetadata.set(Metadata.EMBEDDED_RELATIONSHIP_ID, thumbName); thumbnailMetadata.set(Metadata.CONTENT_TYPE, tPart.getContentType()); thumbnailMetadata.set(TikaCoreProperties.TITLE, tPart.getPartName().getName()); if (embeddedExtractor.shouldParseEmbedded(thumbnailMetadata)) { embeddedExtractor.parseEmbedded(TikaInputStream.get(tStream), new EmbeddedContentHandler(handler), thumbnailMetadata, false); } tStream.close(); } } catch (Exception ex) { } }