reuse code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903737 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-08-28 13:49:05 +00:00
parent f6751ef514
commit 25f00ba7c2
7 changed files with 14 additions and 7 deletions

View File

@ -54,7 +54,7 @@ public class POIXMLTypeLoader {
// DEFAULT_XML_OPTIONS.setUnsynchronized(); // DEFAULT_XML_OPTIONS.setUnsynchronized();
Map<String, String> map = new HashMap<>(); Map<String, String> 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/chart", "c");
map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp"); map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
map.put(PackageNamespaces.MARKUP_COMPATIBILITY, "ve"); map.put(PackageNamespaces.MARKUP_COMPATIBILITY, "ve");

View File

@ -20,6 +20,7 @@
package org.apache.poi.xslf.model; package org.apache.poi.xslf.model;
import static org.apache.poi.ooxml.util.XPathHelper.selectProperty; 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 static org.apache.poi.xssf.usermodel.XSSFRelation.NS_PRESENTATIONML;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -46,7 +47,7 @@ public final class ParagraphPropertyFetcher<T> extends PropertyFetcher<T> {
static final String PML_NS = NS_PRESENTATIONML; 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[] TX_BODY = { new QName(PML_NS, "txBody") };
private static final QName[] LST_STYLE = { new QName(DML_NS, "lstStyle") }; private static final QName[] LST_STYLE = { new QName(DML_NS, "lstStyle") };

View File

@ -26,12 +26,13 @@ import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.POIXMLRelation; import org.apache.poi.ooxml.POIXMLRelation;
import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@SuppressWarnings({"unused", "WeakerAccess"}) @SuppressWarnings({"unused", "WeakerAccess"})
@Beta @Beta
public final class XSLFRelation extends POIXMLRelation { 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 * A map to lookup POIXMLRelation by its relation type

View File

@ -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.CTShape;
import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; 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; import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_PRESENTATIONML;
/** /**
@ -73,7 +74,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
T parse(XMLStreamReader reader) throws XmlException; 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; static final String PML_NS = NS_PRESENTATIONML;
private static final QName[] NV_CONTAINER = { private static final QName[] NV_CONTAINER = {

View File

@ -24,6 +24,8 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
import org.apache.poi.util.Internal; 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 * Used internally to navigate the paragraph text style hierarchy within a shape and fetch properties
*/ */
@ -54,7 +56,7 @@ public abstract class ParagraphPropertyFetcher<T> {
XmlObject[] o = shape.selectPath( XmlObject[] o = shape.selectPath(
"declare namespace xdr='http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing' " + "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" ".//xdr:txBody/a:lstStyle/a:lvl" + (_level + 1) + "pPr"
); );
if (o.length == 1) { if (o.length == 1) {

View File

@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel; 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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -38,7 +39,7 @@ import org.xmlunit.builder.Input;
import org.xmlunit.diff.Diff; import org.xmlunit.diff.Diff;
class TestXDDFColor { 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 @Test
void testSchemeColor() throws IOException { void testSchemeColor() throws IOException {

View File

@ -16,6 +16,7 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.usermodel; 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.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -165,7 +166,7 @@ class TestXSSFDrawing {
// Ensure it got the right namespaces // Ensure it got the right namespaces
String xml = ctDrawing.toString(); String xml = ctDrawing.toString();
assertTrue(xml.contains("xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\"")); 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); checkRewrite(wb2);
wb2.close(); wb2.close();