001/* 002 * (C) Copyright 2002-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 */ 018package org.nuxeo.ecm.core.convert.plugins.text.extractors; 019 020import java.io.File; 021import java.io.FileInputStream; 022import java.io.FileOutputStream; 023import java.io.IOException; 024import java.io.InputStream; 025import java.io.OutputStream; 026import java.io.Serializable; 027import java.util.Map; 028 029import org.apache.commons.logging.Log; 030import org.apache.commons.logging.LogFactory; 031import org.apache.poi.hslf.extractor.PowerPointExtractor; 032import org.nuxeo.ecm.core.api.Blob; 033import org.nuxeo.ecm.core.api.Blobs; 034import org.nuxeo.ecm.core.api.blobholder.BlobHolder; 035import org.nuxeo.ecm.core.convert.api.ConversionException; 036import org.nuxeo.ecm.core.convert.cache.SimpleCachableBlobHolder; 037import org.nuxeo.ecm.core.convert.extension.Converter; 038import org.nuxeo.ecm.core.convert.extension.ConverterDescriptor; 039 040/** 041 * @deprecated subsumed by MSOffice2TextConverter 042 */ 043@Deprecated 044public class PPT2TextConverter implements Converter { 045 046 private static final Log log = LogFactory.getLog(PPT2TextConverter.class); 047 048 @Override 049 public BlobHolder convert(BlobHolder blobHolder, Map<String, Serializable> parameters) throws ConversionException { 050 File f = null; 051 OutputStream fas = null; 052 053 PowerPointExtractor extractor = null; 054 try { 055 extractor = new PowerPointExtractor(blobHolder.getBlob().getStream()); 056 057 byte[] bytes = extractor.getText().getBytes(); 058 f = File.createTempFile("po-ppt2text", ".txt"); 059 fas = new FileOutputStream(f); 060 fas.write(bytes); 061 062 Blob blob; 063 try (InputStream in = new FileInputStream(f)) { 064 blob = Blobs.createBlob(in); 065 } 066 blob.setMimeType("text/plain"); 067 return new SimpleCachableBlobHolder(blob); 068 } catch (IOException e) { 069 throw new ConversionException("Error during PPT2Text conversion", e); 070 } finally { 071 if (extractor != null) { 072 try { 073 extractor.close(); 074 } catch (IOException e) { 075 log.error(e, e); 076 } 077 } 078 if (fas != null) { 079 try { 080 fas.close(); 081 } catch (IOException e) { 082 log.error(e, e); 083 } 084 } 085 if (f != null) { 086 f.delete(); 087 } 088 } 089 } 090 091 @Override 092 public void init(ConverterDescriptor descriptor) { 093 } 094 095}