Example usage for org.apache.poi.poifs.eventfilesystem POIFSReader registerListener

List of usage examples for org.apache.poi.poifs.eventfilesystem POIFSReader registerListener

Introduction

In this page you can find the example usage for org.apache.poi.poifs.eventfilesystem POIFSReader registerListener.

Prototype


public void registerListener(final POIFSReaderListener listener) 

Source Link

Document

Register a POIFSReaderListener for all documents

Usage

From source file:com.bluecubs.xinco.index.filetypes.XincoIndexMicrosoftPowerpoint.java

License:Apache License

public String getFileContentString(File f) {
    String text = null;/*  w w  w  .  j a  va2 s . co  m*/
    try {
        POIFSReader r = new POIFSReader();
        XincoIndexMicrosoftPowerpointPOIFSReaderListener ximpprl = new XincoIndexMicrosoftPowerpointPOIFSReaderListener();
        r.registerListener(ximpprl);
        r.read(new FileInputStream(f));
        text = ximpprl.getEventText();
    } catch (Exception e) {
        text = null;
    }
    return text;
}

From source file:com.duroty.lucene.parser.MSPowerPointParser.java

License:Open Source License

/**
 * DOCUMENT ME!/*from   w w  w . ja va2  s.c  o  m*/
 *
 * @return DOCUMENT ME!
 *
 * @throws ParserException DOCUMENT ME!
 */
private String getContents() throws ParserException {
    String contents = "";

    try {
        POIFSReader reader = new POIFSReader();
        writer = new ByteArrayOutputStream();
        reader.registerListener(this);
        reader.read(in);
        contents = writer.toString();
    } catch (Exception ex) {
        throw new ParserException(ex);
    }

    return contents;
}

From source file:com.flexive.extractor.PowerpointExtractor.java

License:Open Source License

/**
 * Extracts the text informations from the powerpoint file.
 *
 * @param in the input stream to read from
 * @return the extraxted informations, or null if no text extraction was possible
 *///  www. ja v  a 2s  .c o m
public ExtractedData extract(final InputStream in) {
    try {
        writer = new ByteArrayOutputStream();
        POIFSReader reader = new POIFSReader();
        reader.registerListener(this);
        //FxSummaryInformation.getSummaryInformation(fileName);
        reader.read(in);
        if (fxsi != null) {
            writer.write(FxSharedUtils.getBytes(fxsi.getFTIndexInformations()));
        }
        writer.flush();
        return new ExtractedData(fxsi, writer.toString());
    } catch (Exception ex) {
        return null;
    } finally {
        try {
            writer.close();
        } catch (Exception exc) {
            /*ignore*/}
    }
}

From source file:com.villemos.ispace.aperture.enricher.MicrosoftPropertyReader.java

License:Open Source License

@Handler
public void addMSProperties(@Body InformationObject io, @Headers Map<String, Object> headers) {

    File file = new File(io.hasUri);

    if (file.exists() && io.hasUri.endsWith(".doc")) {
        POIFSReader r = new POIFSReader();
        r.registerListener(this);
        try {//from   w w  w  . j av  a2  s  .c o  m
            FileInputStream inStream = new FileInputStream(file);
            r.read(inStream);

            Iterator<Entry<String, String>> it = msProperties.entrySet().iterator();
            while (it.hasNext()) {
                Entry<String, String> entry = it.next();
                io.metadata.put(entry.getKey(), entry.getValue());
            }
            inStream.close();
        } catch (Exception e) {
            e.printStackTrace();
            LOG.error("Failed to get properties for .doc file '" + file.getName() + "'.");
        }
    }
}

From source file:lius.index.powerpoint.PPTIndexer.java

License:Apache License

public String getContent() {
    String contents = "";
    try {/*from w  ww.  j  a v a  2s.  c om*/
        POIFSReader reader = new POIFSReader();
        writer = new ByteArrayOutputStream();
        reader.registerListener(this);
        reader.read(getStreamToIndex());
        contents = writer.toString();
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }
    return contents;
}

From source file:org.apache.slide.extractor.MSPowerPointExtractor.java

License:Apache License

public Reader extract(InputStream content) throws ExtractorException {
    try {//ww  w  .jav a  2s .c o  m
        POIFSReader reader = new POIFSReader();
        reader.registerListener(this);
        reader.read(content);

        return new InputStreamReader(new ByteArrayInputStream(writer.toByteArray()));
    } catch (Exception e) {
        throw new ExtractorException(e.getMessage());
    }
}

From source file:org.ddt.listener.ole.OleStreamListenerTest.java

License:Apache License

/**
 * Test of processPOIFSReaderEvent method, of class OleStreamListener.
 *//*from  ww w.  java2 s  .co m*/
@Test
public void test2003XLSInsertAsObject() throws IOException {
    File f = new File(this.getClass().getResource("/xls/2003/insert-as-object.xls").getFile());
    //        POIFSFileSystem pfs = new POIFSFileSystem(new )
    POIFSReader r = new POIFSReader();
    OleStreamListener l = new OleStreamListener();
    r.registerListener(l);
    r.read(new FileInputStream(f));

    List<String> collectedPaths = new ArrayList<String>();
    for (Link link : l) {
        collectedPaths.addAll(link.getPaths());
        //            System.out.println(l.toString());
    }
    assertTrue("Contains 2007 link", containsFileNameString("2007-normalsource.xls", collectedPaths));
    assertTrue("Contains 2010 link", containsFileNameString("2010-normalsource.xls", collectedPaths));
    assertTrue("Contains 2003 link", containsFileNameString("2003-normalsource.xls", collectedPaths));

}

From source file:org.ddt.listener.ole.OleStreamListenerTest.java

License:Apache License

/**
 * Test of processPOIFSReaderEvent method, of class OleStreamListener.
 *///from  w ww . j a  v a2s.co m
@Test
public void test2007XLSInsertAsObject() throws IOException {
    File f = new File(this.getClass().getResource("/xls/2003/insert-as-object.xls").getFile());

    //        POIFSFileSystem pfs = new POIFSFileSystem(new )
    POIFSReader r = new POIFSReader();
    OleStreamListener l = new OleStreamListener();
    r.registerListener(l);
    r.read(new FileInputStream(f));

    List<String> collectedPaths = new ArrayList<String>();
    for (Link link : l) {
        collectedPaths.addAll(link.getPaths());
        //            System.out.println(l.toString());
    }
    assertTrue("Contains 2007 link", containsFileNameString("2007-normalsource.xls", collectedPaths));
    assertTrue("Contains 2010 link", containsFileNameString("2010-normalsource.xls", collectedPaths));
    assertTrue("Contains 2003 link", containsFileNameString("2003-normalsource.xls", collectedPaths));

}

From source file:org.elbe.relations.biblio.meta.internal.extract.AbstractMSOfficeExtractor.java

License:Open Source License

public ExtractedData process(File inFile) throws IOException {
    ExtractedData outExtracted = extractGenericData(inFile);

    FileInputStream lStream = null;

    POIFSReader lReader = new POIFSReader();
    SummaryReader lListener = new SummaryReader(outExtracted);
    lReader.registerListener(lListener);

    try {/*from  w  ww. java  2  s .c  o  m*/
        lStream = new FileInputStream(inFile);
        lReader.read(lStream);
    } finally {
        if (lStream != null) {
            lStream.close();
        }
    }

    return outExtracted;
}

From source file:org.jlibrary.core.search.extraction.ExcelExtractor.java

License:Open Source License

/**
 * @see org.jlibrary.core.search.extraction.Extractor#extractHeader(java.io.InputStream)
 *//*from   w w w.ja v a  2 s .  c o m*/
public HeaderMetaData extractHeader(InputStream is) throws ExtractionException {

    try {
        POIFSReader reader = new POIFSReader();
        reader.registerListener(this);
        reader.read(getStreamCopy(is));

        // extract all information
        return extractMetaInformation();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new ExtractionException(e);
    }

}