==================================================================== */
package org.apache.poi.dev;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.*;
import java.util.ArrayList;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
* Useful for seeing what parts are defined, and how
* they're all related to each other.
*/
-public class OOXMLLister {
+public class OOXMLLister implements Closeable {
private final OPCPackage container;
private final PrintStream disp;
displayRelation(rel, "");
}
}
+
private void displayRelation(PackageRelationship rel, String indent) {
disp.println(indent+"Relationship:");
disp.println(indent+"\tFrom: "+ rel.getSourceURI());
disp.println(indent+"\tMode: " + rel.getTargetMode());
disp.println(indent+"\tType: " + rel.getRelationshipType());
}
-
+
+ @Override
+ public void close() throws IOException {
+ container.close();
+ }
+
public static void main(String[] args) throws Exception {
if(args.length == 0) {
System.err.println("Use:");
OOXMLLister lister = new OOXMLLister(
OPCPackage.open(f.toString(), PackageAccess.READ)
);
-
- lister.disp.println(f.toString() + "\n");
- lister.displayParts();
- lister.disp.println();
- lister.displayRelations();
+
+ try {
+ lister.disp.println(f.toString() + "\n");
+ lister.displayParts();
+ lister.disp.println();
+ lister.displayRelations();
+ } finally {
+ lister.close();
+ }
}
}
--- /dev/null
+package org.apache.poi.dev;
+
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
+import org.apache.poi.util.NullOutputStream;
+import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.PrintStream;
+
+public class TestOOXMLLister {
+ @Test
+ public void testMain() throws Exception {
+ File file = XSSFTestDataSamples.getSampleFile("Formatting.xlsx");
+ OOXMLLister.main(new String[] {file.getAbsolutePath()});
+ }
+
+ @Test
+ public void testWithPrintStream() throws Exception {
+ File file = XSSFTestDataSamples.getSampleFile("Formatting.xlsx");
+ OOXMLLister lister = new OOXMLLister(OPCPackage.open(file.getAbsolutePath(), PackageAccess.READ), new PrintStream(new NullOutputStream()));
+ lister.displayParts();
+ lister.displayRelations();
+ lister.close();
+ }
+}
--- /dev/null
+package org.apache.poi.dev;
+
+import org.apache.poi.util.TempFile;
+import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class TestOOXMLPrettyPrint {
+ @Test
+ public void testMain() throws Exception {
+ File file = XSSFTestDataSamples.getSampleFile("Formatting.xlsx");
+ File outFile = TempFile.createTempFile("Formatting", "-pretty.xlsx");
+
+ assertTrue(outFile.delete());
+ assertFalse(outFile.exists());
+
+ OOXMLPrettyPrint.main(new String[] {
+ file.getAbsolutePath(), outFile.getAbsolutePath()
+ });
+
+ assertTrue(outFile.exists());
+ assertTrue(outFile.delete());
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.apache.poi.dev;
+
+import org.apache.poi.util.TempFile;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.io.File;
+
+public class TestRecordGenerator {
+ @Ignore("Could not get this to run, probably the dev-application does not work any more at all")
+ @Test
+ public void testNotEnoughArgs() throws Exception {
+ RecordGenerator.main(new String[] {});
+ }
+
+ @Ignore("Could not get this to run, probably the dev-application does not work any more at all")
+ @Test
+ public void testMainRecords() throws Exception {
+ File dir = TempFile.createTempDirectory("TestRecordGenerator");
+
+ RecordGenerator.main(new String[] {
+ "src/records/definitions/",
+ "src/records/styles/",
+ dir.getAbsolutePath(),
+ dir.getAbsolutePath(),
+ });
+ }
+
+ @Ignore("Could not get this to run, probably the dev-application does not work any more at all")
+ @Test
+ public void testMainTypes() throws Exception {
+ File dir = TempFile.createTempDirectory("TestRecordGenerator");
+
+ RecordGenerator.main(new String[] {
+ "src/types/definitions/",
+ "src/types/styles/",
+ dir.getAbsolutePath(),
+ dir.getAbsolutePath(),
+ });
+ }
+}
\ No newline at end of file
}
NPOIFSFileSystem poifs = new NPOIFSFileSystem(new File(args[0]));
- HDGFDiagram hdgf = new HDGFDiagram(poifs);
-
- PrintStream ps = System.out;
- ps.println("Opened " + args[0]);
- VSDDumper vd = new VSDDumper(ps, hdgf);
- vd.dumpFile();
-
- poifs.close();
+ try {
+ HDGFDiagram hdgf = new HDGFDiagram(poifs);
+
+ PrintStream ps = System.out;
+ ps.println("Opened " + args[0]);
+ VSDDumper vd = new VSDDumper(ps, hdgf);
+ vd.dumpFile();
+ } finally {
+ poifs.close();
+ }
}
public void dumpFile() {
}
boolean truncatePropData = true;
- for(int i=0; i<args.length; i++) {
- if(args[i].equalsIgnoreCase("--full")) {
+ for (String arg : args) {
+ if (arg.equalsIgnoreCase("--full")) {
truncatePropData = false;
continue;
}
-
- HMEFDumper dumper = new HMEFDumper(
- new FileInputStream(args[i])
- );
- dumper.setTruncatePropertyData(truncatePropData);
- dumper.dump();
+
+ InputStream stream = new FileInputStream(arg);
+ try {
+ HMEFDumper dumper = new HMEFDumper(stream);
+ dumper.setTruncatePropertyData(truncatePropData);
+ dumper.dump();
+ } finally {
+ stream.close();
+ }
}
}
-
+
private InputStream inp;
private boolean truncatePropertyData;
--- /dev/null
+package org.apache.poi.hdgf.dev;
+
+import org.apache.poi.POIDataSamples;
+import org.junit.Test;
+
+import java.io.File;
+
+public class TestVSDDumper {
+ @Test
+ public void main() throws Exception {
+ File file = POIDataSamples.getDiagramInstance().getFile("Test_Visio-Some_Random_Text.vsd");
+ VSDDumper.main(new String[] { file.getAbsolutePath() });
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.apache.poi.hmef.dev;
+
+import org.apache.poi.POIDataSamples;
+import org.junit.Test;
+
+import java.io.File;
+
+public class TestHMEFDumper {
+ @Test(expected = IllegalArgumentException.class)
+ public void noArguments() throws Exception {
+ HMEFDumper.main(new String[] {});
+ }
+
+ @Test
+ public void main() throws Exception {
+ File file = POIDataSamples.getHMEFInstance().getFile("quick-winmail.dat");
+ HMEFDumper.main(new String[] {
+ file.getAbsolutePath()
+ });
+ }
+
+ @Test
+ public void mainFull() throws Exception {
+ File file = POIDataSamples.getHMEFInstance().getFile("quick-winmail.dat");
+ HMEFDumper.main(new String[] {
+ "--full",
+ file.getAbsolutePath()
+ });
+ }
+}
\ No newline at end of file