From 25f00ba7c2db9bd897cffa67d12b1cfa31583516 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sun, 28 Aug 2022 13:49:05 +0000 Subject: [PATCH] reuse code git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903737 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java | 2 +- .../org/apache/poi/xslf/model/ParagraphPropertyFetcher.java | 3 ++- .../main/java/org/apache/poi/xslf/usermodel/XSLFRelation.java | 3 ++- .../main/java/org/apache/poi/xslf/usermodel/XSLFShape.java | 3 ++- .../org/apache/poi/xssf/model/ParagraphPropertyFetcher.java | 4 +++- .../java/org/apache/poi/xddf/usermodel/TestXDDFColor.java | 3 ++- .../java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java index a73304da99..243f1d7f18 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java +++ b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java @@ -54,7 +54,7 @@ public class POIXMLTypeLoader { // DEFAULT_XML_OPTIONS.setUnsynchronized(); Map map = new HashMap<>(); - map.put("http://schemas.openxmlformats.org/drawingml/2006/main", "a"); + map.put(XSSFRelation.NS_DRAWINGML, "a"); map.put("http://schemas.openxmlformats.org/drawingml/2006/chart", "c"); map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp"); map.put(PackageNamespaces.MARKUP_COMPATIBILITY, "ve"); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/model/ParagraphPropertyFetcher.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/model/ParagraphPropertyFetcher.java index e74615d4a7..c2731adc6c 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/model/ParagraphPropertyFetcher.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/model/ParagraphPropertyFetcher.java @@ -20,6 +20,7 @@ package org.apache.poi.xslf.model; import static org.apache.poi.ooxml.util.XPathHelper.selectProperty; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_DRAWINGML; import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_PRESENTATIONML; import java.util.function.Consumer; @@ -46,7 +47,7 @@ public final class ParagraphPropertyFetcher extends PropertyFetcher { static final String PML_NS = NS_PRESENTATIONML; - static final String DML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"; + static final String DML_NS = NS_DRAWINGML; private static final QName[] TX_BODY = { new QName(PML_NS, "txBody") }; private static final QName[] LST_STYLE = { new QName(DML_NS, "lstStyle") }; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFRelation.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFRelation.java index c60905b235..cec0e475e1 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFRelation.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFRelation.java @@ -26,12 +26,13 @@ import org.apache.poi.ooxml.POIXMLDocument; import org.apache.poi.ooxml.POIXMLRelation; import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.util.Beta; +import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @SuppressWarnings({"unused", "WeakerAccess"}) @Beta public final class XSLFRelation extends POIXMLRelation { - /* package */ static final String NS_DRAWINGML = "http://schemas.openxmlformats.org/drawingml/2006/main"; + /* package */ static final String NS_DRAWINGML = XSSFRelation.NS_DRAWINGML; /** * A map to lookup POIXMLRelation by its relation type diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java index fe6572d658..1dbaee537f 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java @@ -60,6 +60,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_DRAWINGML; import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_PRESENTATIONML; /** @@ -73,7 +74,7 @@ public abstract class XSLFShape implements Shape { T parse(XMLStreamReader reader) throws XmlException; } - static final String DML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"; + static final String DML_NS = NS_DRAWINGML; static final String PML_NS = NS_PRESENTATIONML; private static final QName[] NV_CONTAINER = { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ParagraphPropertyFetcher.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ParagraphPropertyFetcher.java index 00f40f790c..3e9b1bda63 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ParagraphPropertyFetcher.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ParagraphPropertyFetcher.java @@ -24,6 +24,8 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape; import org.apache.xmlbeans.XmlObject; import org.apache.poi.util.Internal; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_DRAWINGML; + /** * Used internally to navigate the paragraph text style hierarchy within a shape and fetch properties */ @@ -54,7 +56,7 @@ public abstract class ParagraphPropertyFetcher { XmlObject[] o = shape.selectPath( "declare namespace xdr='http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing' " + - "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' " + + "declare namespace a='" + NS_DRAWINGML + "' " + ".//xdr:txBody/a:lstStyle/a:lvl" + (_level + 1) + "pPr" ); if (o.length == 1) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/xddf/usermodel/TestXDDFColor.java b/poi-ooxml/src/test/java/org/apache/poi/xddf/usermodel/TestXDDFColor.java index 7eb01c29a7..e4b7fa0ecd 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xddf/usermodel/TestXDDFColor.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xddf/usermodel/TestXDDFColor.java @@ -17,6 +17,7 @@ package org.apache.poi.xddf.usermodel; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_DRAWINGML; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -38,7 +39,7 @@ import org.xmlunit.builder.Input; import org.xmlunit.diff.Diff; class TestXDDFColor { - private static final String XMLNS = "xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"/>"; + private static final String XMLNS = "xmlns:a=\"" + NS_DRAWINGML + "\"/>"; @Test void testSchemeColor() throws IOException { diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java index 807a6bc3df..d689226fc4 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_DRAWINGML; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -165,7 +166,7 @@ class TestXSSFDrawing { // Ensure it got the right namespaces String xml = ctDrawing.toString(); assertTrue(xml.contains("xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\"")); - assertTrue(xml.contains("xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"")); + assertTrue(xml.contains("xmlns:a=\"" + NS_DRAWINGML + '\"')); checkRewrite(wb2); wb2.close(); -- 2.39.5