Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java?rev=1873190&r1=1873189&r2=1873190&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java Mon Jan 27 00:31:01 2020 @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.Map; import org.apache.poi.ooxml.POIXMLDocument; -import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLRelation; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -39,197 +38,213 @@ public final class XWPFRelation extends public static final XWPFRelation DOCUMENT = new XWPFRelation( "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", PackageRelationshipTypes.CORE_DOCUMENT, - "/word/document.xml", - null + "/word/document.xml" ); + public static final XWPFRelation TEMPLATE = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml", - PackageRelationshipTypes.CORE_DOCUMENT, - "/word/document.xml", - null + "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml", + PackageRelationshipTypes.CORE_DOCUMENT, + "/word/document.xml" ); + public static final XWPFRelation MACRO_DOCUMENT = new XWPFRelation( - "application/vnd.ms-word.document.macroEnabled.main+xml", - PackageRelationshipTypes.CORE_DOCUMENT, - "/word/document.xml", - null + "application/vnd.ms-word.document.macroEnabled.main+xml", + PackageRelationshipTypes.CORE_DOCUMENT, + "/word/document.xml" ); + public static final XWPFRelation MACRO_TEMPLATE_DOCUMENT = new XWPFRelation( - "application/vnd.ms-word.template.macroEnabledTemplate.main+xml", - PackageRelationshipTypes.CORE_DOCUMENT, - "/word/document.xml", - null + "application/vnd.ms-word.template.macroEnabledTemplate.main+xml", + PackageRelationshipTypes.CORE_DOCUMENT, + "/word/document.xml" ); + public static final XWPFRelation GLOSSARY_DOCUMENT = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument", - "/word/glossary/document.xml", - null + "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument", + "/word/glossary/document.xml" ); + public static final XWPFRelation NUMBERING = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", - "/word/numbering.xml", - XWPFNumbering.class + "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", + "/word/numbering.xml", + XWPFNumbering::new, XWPFNumbering::new ); + public static final XWPFRelation FONT_TABLE = new XWPFRelation( "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable", - "/word/fontTable.xml", - null + "/word/fontTable.xml" ); + public static final XWPFRelation SETTINGS = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", - "/word/settings.xml", - XWPFSettings.class + "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", + "/word/settings.xml", + XWPFSettings::new, XWPFSettings::new ); + public static final XWPFRelation STYLES = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", - "/word/styles.xml", - XWPFStyles.class + "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", + "/word/styles.xml", + XWPFStyles::new, XWPFStyles::new ); + public static final XWPFRelation WEB_SETTINGS = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings", - "/word/webSettings.xml", - null + "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings", + "/word/webSettings.xml" ); + public static final XWPFRelation HEADER = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", - "/word/header#.xml", - XWPFHeader.class + "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", + "/word/header#.xml", + XWPFHeader::new, XWPFHeader::new ); + public static final XWPFRelation FOOTER = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", - "/word/footer#.xml", - XWPFFooter.class + "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", + "/word/footer#.xml", + XWPFFooter::new, XWPFFooter::new ); + public static final XWPFRelation THEME = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.theme+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", - "/word/theme/theme#.xml", - null + "application/vnd.openxmlformats-officedocument.theme+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", + "/word/theme/theme#.xml" ); public static final XWPFRelation WORKBOOK = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - POIXMLDocument.PACK_OBJECT_REL_TYPE, - "/word/embeddings/Microsoft_Excel_Worksheet#.xlsx", - XSSFWorkbook.class + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + POIXMLDocument.PACK_OBJECT_REL_TYPE, + "/word/embeddings/Microsoft_Excel_Worksheet#.xlsx", + XSSFWorkbook::new, (PackagePartConstructor)XSSFWorkbook::new ); public static final XWPFRelation CHART = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.drawingml.chart+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", - "/word/charts/chart#.xml", - XWPFChart.class + "application/vnd.openxmlformats-officedocument.drawingml.chart+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", + "/word/charts/chart#.xml", + XWPFChart::new, XWPFChart::new ); public static final XWPFRelation HYPERLINK = new XWPFRelation( - null, - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", - null, - null + null, + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", + null ); public static final XWPFRelation COMMENT = new XWPFRelation( - null, - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", - null, - null + null, + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", + null ); public static final XWPFRelation FOOTNOTE = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", - "/word/footnotes.xml", - XWPFFootnotes.class + "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", + "/word/footnotes.xml", + XWPFFootnotes::new, XWPFFootnotes::new ); public static final XWPFRelation ENDNOTE = new XWPFRelation( - "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes", - "/word/endnotes.xml", - XWPFEndnotes.class + "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes", + "/word/endnotes.xml", + XWPFEndnotes::new, XWPFEndnotes::new ); /** * Supported image formats */ public static final XWPFRelation IMAGE_EMF = new XWPFRelation( - "image/x-emf", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.emf", - XWPFPictureData.class + "image/x-emf", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.emf", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_WMF = new XWPFRelation( - "image/x-wmf", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.wmf", - XWPFPictureData.class + "image/x-wmf", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.wmf", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_PICT = new XWPFRelation( - "image/pict", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.pict", - XWPFPictureData.class + "image/pict", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.pict", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_JPEG = new XWPFRelation( - "image/jpeg", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.jpeg", - XWPFPictureData.class + "image/jpeg", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.jpeg", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_PNG = new XWPFRelation( - "image/png", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.png", - XWPFPictureData.class + "image/png", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.png", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_DIB = new XWPFRelation( - "image/dib", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.dib", - XWPFPictureData.class + "image/dib", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.dib", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_GIF = new XWPFRelation( - "image/gif", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.gif", - XWPFPictureData.class + "image/gif", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.gif", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_TIFF = new XWPFRelation( - "image/tiff", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.tiff", - XWPFPictureData.class + "image/tiff", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.tiff", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_EPS = new XWPFRelation( - "image/x-eps", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.eps", - XWPFPictureData.class + "image/x-eps", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.eps", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_BMP = new XWPFRelation( - "image/x-ms-bmp", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.bmp", - XWPFPictureData.class + "image/x-ms-bmp", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.bmp", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGE_WPG = new XWPFRelation( - "image/x-wpg", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - "/word/media/image#.wpg", - XWPFPictureData.class + "image/x-wpg", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/word/media/image#.wpg", + XWPFPictureData::new, XWPFPictureData::new ); public static final XWPFRelation IMAGES = new XWPFRelation( - null, - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", - null, - XWPFPictureData.class + null, + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + null, + XWPFPictureData::new, XWPFPictureData::new ); - private XWPFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) { - super(type, rel, defaultName, cls); + private XWPFRelation(String type, String rel, String defaultName) { + super(type, rel, defaultName); + _table.put(rel, this); + } + + private XWPFRelation(String type, String rel, String defaultName, + NoArgConstructor noArgConstructor, + PackagePartConstructor packagePartConstructor) { + super(type, rel, defaultName, noArgConstructor, packagePartConstructor, null); + _table.put(rel, this); + } + + private XWPFRelation(String type, String rel, String defaultName, + NoArgConstructor noArgConstructor, + ParentPartConstructor parentPartConstructor) { + super(type, rel, defaultName, noArgConstructor, null, parentPartConstructor); _table.put(rel, this); }
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java?rev=1873190&r1=1873189&r2=1873190&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java Mon Jan 27 00:31:01 2020 @@ -29,7 +29,6 @@ import javax.xml.namespace.QName; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLException; -import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlOptions; @@ -61,13 +60,13 @@ public class XWPFStyles extends POIXMLDo * Construct XWPFStyles from a package part * * @param part the package part holding the data of the styles, - * + * * @since POI 3.14-Beta1 */ - public XWPFStyles(PackagePart part) throws IOException, OpenXML4JException { + public XWPFStyles(PackagePart part) { super(part); } - + /** * Construct XWPFStyles from scratch for a new document. */ Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java?rev=1873190&r1=1873189&r2=1873190&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java Mon Jan 27 00:31:01 2020 @@ -29,7 +29,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.Thread.UncaughtExceptionHandler; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -37,6 +36,7 @@ import java.util.List; import org.apache.poi.POIDataSamples; import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart; +import org.apache.poi.ooxml.util.PackageHelper; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -44,7 +44,6 @@ import org.apache.poi.openxml4j.opc.Pack import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.util.IOUtils; import org.apache.poi.util.NullOutputStream; -import org.apache.poi.ooxml.util.PackageHelper; import org.apache.poi.util.TempFile; import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xssf.usermodel.XSSFRelation; @@ -61,7 +60,7 @@ public final class TestPOIXMLDocument { public OPCParser(OPCPackage pkg) { super(pkg); } - + public OPCParser(OPCPackage pkg, String coreDocumentRel) { super(pkg, coreDocumentRel); } @@ -86,16 +85,6 @@ public final class TestPOIXMLDocument { protected POIXMLRelation getDescriptor(String relationshipType) { return null; } - - /** - * @since POI 3.14-Beta1 - */ - @Override - protected POIXMLDocumentPart createDocumentPart - (Class<? extends POIXMLDocumentPart> cls, Class<?>[] classes, Object[] values) - throws SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { - return null; - } } private static void traverse(POIXMLDocument doc) throws IOException{ @@ -104,18 +93,18 @@ public final class TestPOIXMLDocument { traverse(p, context); } } - + /** * Recursively traverse a OOXML document and assert that same logical parts have the same physical instances */ private static void traverse(RelationPart rp, HashMap<String,POIXMLDocumentPart> context) throws IOException{ POIXMLDocumentPart dp = rp.getDocumentPart(); assertEquals(rp.getRelationship().getTargetURI().toString(), dp.getPackagePart().getPartName().getName()); - + context.put(dp.getPackagePart().getPartName().getName(), dp); for(RelationPart p : dp.getRelationParts()){ assertNotNull(p.getRelationship().toString()); - + String uri = p.getDocumentPart().getPackagePart().getPartName().getURI().toString(); assertEquals(uri, p.getRelationship().getTargetURI().toString()); if (!context.containsKey(uri)) { @@ -138,7 +127,7 @@ public final class TestPOIXMLDocument { FileOutputStream out = new FileOutputStream(tmp); doc.write(out); out.close(); - + // Should not be able to write to an output stream that has been closed try { doc.write(out); @@ -166,7 +155,7 @@ public final class TestPOIXMLDocument { throw e; } } - + // Should be able to close a document multiple times, though subsequent closes will have no effect. doc.close(); @@ -177,17 +166,17 @@ public final class TestPOIXMLDocument { try { doc.parse(new TestFactory()); traverse(doc); - + assertEquals(pkg1.getRelationships().size(), pkg2.getRelationships().size()); - + ArrayList<PackagePart> l1 = pkg1.getParts(); ArrayList<PackagePart> l2 = pkg2.getParts(); - + assertEquals(l1.size(), l2.size()); for (int i=0; i < l1.size(); i++){ PackagePart p1 = l1.get(i); PackagePart p2 = l2.get(i); - + assertEquals(p1.getContentType(), p2.getContentType()); assertEquals(p1.hasRelationships(), p2.hasRelationships()); if(p1.hasRelationships()){ @@ -234,7 +223,7 @@ public final class TestPOIXMLDocument { } } } - + @Test public void testGetNextPartNumber() throws Exception { POIDataSamples pds = POIDataSamples.getDocumentInstance(); @@ -280,32 +269,32 @@ public final class TestPOIXMLDocument { part.onDocumentCreate(); //part.getTargetPart(null); } - + @Test public void testVSDX() throws Exception { POIDataSamples pds = POIDataSamples.getDiagramInstance(); @SuppressWarnings("resource") OPCPackage open = PackageHelper.open(pds.openResourceAsStream("test.vsdx")); POIXMLDocument part = new OPCParser(open, PackageRelationshipTypes.VISIO_CORE_DOCUMENT); - + assertNotNull(part); assertEquals(0, part.getRelationCounter()); part.close(); } - + @Test public void testVSDXPart() throws IOException { POIDataSamples pds = POIDataSamples.getDiagramInstance(); OPCPackage open = PackageHelper.open(pds.openResourceAsStream("test.vsdx")); - + POIXMLDocumentPart part = new POIXMLDocumentPart(open, PackageRelationshipTypes.VISIO_CORE_DOCUMENT); - + assertNotNull(part); assertEquals(0, part.getRelationCounter()); - + open.close(); } - + @Test(expected=POIXMLException.class) public void testInvalidCoreRel() throws IOException { POIDataSamples pds = POIDataSamples.getDiagramInstance(); @@ -349,7 +338,7 @@ public final class TestPOIXMLDocument { ClassLoader cl = getClass().getClassLoader(); UncaughtHandler uh = new UncaughtHandler(); - + // check schema type loading and check if we could run in an OOM Thread[] ta = new Thread[30]; for (int j=0; j<10; j++) { @@ -372,12 +361,12 @@ public final class TestPOIXMLDocument { private static class UncaughtHandler implements UncaughtExceptionHandler { Throwable e; - + public synchronized void uncaughtException(Thread t, Throwable e) { this.e = e; - + } - + public synchronized boolean hasException() { return e != null; } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org