diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2017-05-02 23:27:27 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2017-05-02 23:27:27 +0000 |
commit | c22e972b3dcb4427b1e8c51a4481310bd1be5b9b (patch) | |
tree | 7e54bd8649ffbc56da8affe03e6cdcb435784cbe /src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java | |
parent | 3388787d2cee72b0e1679ec42fa555dc7b77c978 (diff) | |
download | poi-c22e972b3dcb4427b1e8c51a4481310bd1be5b9b.tar.gz poi-c22e972b3dcb4427b1e8c51a4481310bd1be5b9b.zip |
Fix hpsf javadocs and code issues
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1793596 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java')
-rw-r--r-- | src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java | 168 |
1 files changed, 14 insertions, 154 deletions
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java index b47417ec4c..4105c223a8 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java @@ -24,9 +24,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.FileFilter; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -51,7 +49,6 @@ import org.apache.poi.hpsf.Variant; import org.apache.poi.hpsf.VariantSupport; import org.apache.poi.hpsf.WritingNotSupportedException; import org.apache.poi.hpsf.wellknown.SectionIDMap; -import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DocumentInputStream; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.util.IOUtils; @@ -73,70 +70,6 @@ public class TestWriteWellKnown { VariantSupport.setLogUnsupportedTypes(false); } - /** - * <p>This test method checks whether DocumentSummary information streams - * can be read. This is done by opening all "Test*" files in the 'poifs' directrory - * pointed to by the "POI.testdata.path" system property, trying to extract - * the document summary information stream in the root directory and calling - * its get... methods.</p> - */ - @Test - public void testReadDocumentSummaryInformation() - throws FileNotFoundException, IOException, - NoPropertySetStreamException, MarkUnsupportedException, - UnexpectedPropertySetTypeException - { - POIDataSamples _samples = POIDataSamples.getHPSFInstance(); - final File dataDir = _samples.getFile(""); - final File[] docs = dataDir.listFiles(new FileFilter() - { - @Override - public boolean accept(final File file) - { - return file.isFile() && file.getName().startsWith("Test") && TestReadAllFiles.checkExclude(file); - } - }); - - for (final File doc : docs) { - NPOIFSFileSystem poifs = null; - try { - /* Read a test document <em>doc</em> into a POI filesystem. */ - poifs = new NPOIFSFileSystem(doc, true); - final DirectoryEntry dir = poifs.getRoot(); - /* - * If there is a document summry information stream, read it from - * the POI filesystem. - */ - if (dir.hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) { - final DocumentSummaryInformation dsi = getDocumentSummaryInformation(poifs); - - /* Execute the get... methods. */ - dsi.getByteCount(); - dsi.getByteOrder(); - dsi.getCategory(); - dsi.getCompany(); - dsi.getCustomProperties(); - // FIXME dsi.getDocparts(); - // FIXME dsi.getHeadingPair(); - dsi.getHiddenCount(); - dsi.getLineCount(); - dsi.getLinksDirty(); - dsi.getManager(); - dsi.getMMClipCount(); - dsi.getNoteCount(); - dsi.getParCount(); - dsi.getPresentationFormat(); - dsi.getScale(); - dsi.getSlideCount(); - } - } catch (Exception e) { - throw new IOException("While handling file " + doc, e); - } finally { - if (poifs != null) poifs.close(); - } - } - } - static final String P_APPLICATION_NAME = "ApplicationName"; static final String P_AUTHOR = "Author"; static final int P_CHAR_COUNT = 4712; @@ -483,15 +416,12 @@ public class TestWriteWellKnown { dsi.removeScale(); dsi.removeSlideCount(); - /* - * <li><p>Write the summary information stream and the document summary - * information stream to the POI filesystem. */ + // Write the summary information stream and the document summary + // information stream to the POI filesystem. si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME); dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME); - /* - * <li><p>Write the POI filesystem to a (temporary) file <em>doc3</em> - * and close the latter. */ + // Write the POI filesystem to a (temporary) file doc3 and close the latter. FileOutputStream out = new FileOutputStream(fileOut); poifs.writeFilesystem(out); out.close(); @@ -501,9 +431,9 @@ public class TestWriteWellKnown { } /* - * Open <em>doc3</em> for reading and check summary information + * Open {@code doc3} for reading and check summary information * and document summary information. All properties removed before must not - * be found in the property streams of <em>doc3</em>. + * be found in the property streams of {@code doc3}. */ private static CustomProperties write3rdFile(File fileIn, File fileOut) throws Exception { NPOIFSFileSystem poifs = new NPOIFSFileSystem(fileIn, false); @@ -571,7 +501,12 @@ public class TestWriteWellKnown { return si; } - private static DocumentSummaryInformation getDocumentSummaryInformation(NPOIFSFileSystem poifs) throws Exception { + static DocumentSummaryInformation getDocumentSummaryInformation(NPOIFSFileSystem poifs) + throws IOException, NoPropertySetStreamException, UnexpectedPropertySetTypeException, MarkUnsupportedException { + if (!poifs.getRoot().hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) { + return null; + } + DocumentInputStream dis = poifs.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME); PropertySet ps = new PropertySet(dis); DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps); @@ -579,83 +514,8 @@ public class TestWriteWellKnown { return dsi; } - - - /** - * <p>Tests the simplified custom properties by reading them from the - * available test files.</p> - * - * @throws Throwable if anything goes wrong. - */ - @Test - public void testReadCustomPropertiesFromFiles() throws Throwable - { - final AllDataFilesTester.TestTask task = new AllDataFilesTester.TestTask() - { - @Override - public void runTest(final File file) throws FileNotFoundException, - IOException, NoPropertySetStreamException, - MarkUnsupportedException, - UnexpectedPropertySetTypeException - { - /* Read a test document <em>doc</em> into a POI filesystem. */ - NPOIFSFileSystem poifs = null; - try { - poifs = new NPOIFSFileSystem(file); - final DirectoryEntry dir = poifs.getRoot(); - /* - * If there is a document summry information stream, read it from - * the POI filesystem, else create a new one. - */ - DocumentSummaryInformation dsi; - if (dir.hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) { - final DocumentInputStream dis = poifs.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - final PropertySet ps = new PropertySet(dis); - dsi = new DocumentSummaryInformation(ps); - dis.close(); - } else { - dsi = PropertySetFactory.newDocumentSummaryInformation(); - } - final CustomProperties cps = dsi.getCustomProperties(); - - if (cps == null) - /* The document does not have custom properties. */ - return; - - for (CustomProperty cp : cps.values()) { - cp.getName(); - cp.getValue(); - } - } finally { - if (poifs != null) poifs.close(); - } - } - }; - - POIDataSamples _samples = POIDataSamples.getHPSFInstance(); - final File dataDir = _samples.getFile(""); - final File[] docs = dataDir.listFiles(new FileFilter() - { - @Override - public boolean accept(final File file) - { - return file.isFile() && file.getName().startsWith("Test") && TestReadAllFiles.checkExclude(file); - } - }); - - for (File doc : docs) { - try { - task.runTest(doc); - } catch (Exception e) { - throw new IOException("While handling file " + doc, e); - } - } - } - - - /** - * <p>Tests basic custom property features.</p> + * Tests basic custom property features. */ @Test public void testCustomerProperties() @@ -693,8 +553,8 @@ public class TestWriteWellKnown { /** - * <p>Tests reading custom properties from a section including reading - * custom properties which are not pure.</p> + * Tests reading custom properties from a section including reading + * custom properties which are not pure. */ @Test public void testGetCustomerProperties() |