Search in sources :

Example 1 with HPSFPropertiesExtractor

use of org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor in project poi by apache.

the class AbstractFileHandler method handleExtractingInternal.

private void handleExtractingInternal(File file) throws Exception {
    long length = file.length();
    long modified = file.lastModified();
    POITextExtractor extractor = ExtractorFactory.createExtractor(file);
    try {
        assertNotNull("Should get a POITextExtractor but had none for file " + file, extractor);
        assertNotNull("Should get some text but had none for file " + file, extractor.getText());
        // also try metadata
        @SuppressWarnings("resource") POITextExtractor metadataExtractor = extractor.getMetadataTextExtractor();
        assertNotNull(metadataExtractor.getText());
        assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!", EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
        assertEquals("File should not be modified by extractor", length, file.length());
        assertEquals("File should not be modified by extractor", modified, file.lastModified());
        handleExtractingAsStream(file);
        if (extractor instanceof POIOLE2TextExtractor) {
            HPSFPropertiesExtractor hpsfExtractor = new HPSFPropertiesExtractor((POIOLE2TextExtractor) extractor);
            try {
                assertNotNull(hpsfExtractor.getDocumentSummaryInformationText());
                assertNotNull(hpsfExtractor.getSummaryInformationText());
                String text = hpsfExtractor.getText();
                //System.out.println(text);
                assertNotNull(text);
            } finally {
                hpsfExtractor.close();
            }
        }
    } catch (IllegalArgumentException e) {
        if (!EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
            throw e;
        }
    } finally {
        extractor.close();
    }
}
Also used : POITextExtractor(org.apache.poi.POITextExtractor) POIOLE2TextExtractor(org.apache.poi.POIOLE2TextExtractor) HPSFPropertiesExtractor(org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor)

Example 2 with HPSFPropertiesExtractor

use of org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor in project poi by apache.

the class POIFSFileHandler method handleHPSFProperties.

private void handleHPSFProperties(POIFSFileSystem fs) throws IOException {
    HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
    try {
        // can be null
        ext.getDocSummaryInformation();
        ext.getSummaryInformation();
        assertNotNull(ext.getDocumentSummaryInformationText());
        assertNotNull(ext.getSummaryInformationText());
        assertNotNull(ext.getText());
    } finally {
        ext.close();
    }
}
Also used : HPSFPropertiesExtractor(org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor)

Aggregations

HPSFPropertiesExtractor (org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor)2 POIOLE2TextExtractor (org.apache.poi.POIOLE2TextExtractor)1 POITextExtractor (org.apache.poi.POITextExtractor)1