From 98565236dd798fea6173ac299ae3a1b13de83be4 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sun, 28 Aug 2022 13:12:31 +0000 Subject: [PATCH] reuse code git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903733 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/ooxml/POIXMLTypeLoader.java | 6 +++--- .../poi/xslf/model/ParagraphPropertyFetcher.java | 3 ++- .../org/apache/poi/xslf/usermodel/XSLFDrawing.java | 3 ++- .../apache/poi/xslf/usermodel/XSLFGraphicFrame.java | 3 ++- .../java/org/apache/poi/xslf/usermodel/XSLFShape.java | 4 +++- .../java/org/apache/poi/xslf/usermodel/XSLFSheet.java | 6 +++--- .../apache/poi/xslf/usermodel/XSLFTextParagraph.java | 4 +++- .../org/apache/poi/xssf/usermodel/XSSFRelation.java | 2 ++ .../org/apache/poi/xwpf/usermodel/XWPFDocument.java | 1 - .../java/org/apache/poi/xwpf/usermodel/XWPFRun.java | 10 +++++----- .../apache/poi/xwpf/usermodel/XWPFSignatureLine.java | 10 +++++----- 11 files changed, 30 insertions(+), 22 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 f2b6a721ae..a73304da99 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 @@ -22,7 +22,7 @@ import java.util.HashMap; import java.util.Map; import org.apache.poi.openxml4j.opc.PackageNamespaces; -import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.xmlbeans.XmlOptions; public class POIXMLTypeLoader { @@ -61,8 +61,8 @@ public class POIXMLTypeLoader { map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt"); - map.put("http://schemas.openxmlformats.org/presentationml/2006/main", "p"); - map.put(XWPFDocument.NS_OOXML_WP_MAIN, "w"); + map.put(XSSFRelation.NS_PRESENTATIONML, "p"); + map.put(XSSFRelation.NS_WORDPROCESSINGML, "w"); map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne"); map.put(MS_OFFICE_URN, "o"); map.put(MS_EXCEL_URN, "x"); 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 eabe75df11..e74615d4a7 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_PRESENTATIONML; import java.util.function.Consumer; @@ -44,7 +45,7 @@ public final class ParagraphPropertyFetcher extends PropertyFetcher { } - static final String PML_NS = "http://schemas.openxmlformats.org/presentationml/2006/main"; + static final String PML_NS = NS_PRESENTATIONML; static final String DML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"; private static final QName[] TX_BODY = { new QName(PML_NS, "txBody") }; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java index dca6fed131..ab063a8bcb 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java @@ -28,6 +28,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape; import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture; import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_PRESENTATIONML; @Beta public class XSLFDrawing { @@ -38,7 +39,7 @@ public class XSLFDrawing { _sheet = sheet; _spTree = spTree; XmlObject[] cNvPr = sheet.getSpTree().selectPath( - "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:cNvPr"); + "declare namespace p='" + NS_PRESENTATIONML + "' .//*/p:cNvPr"); for(XmlObject o : cNvPr) { // powerpoint generates AlternateContent elements which cNvPr elements aren't recognized // ignore them for now diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java index 0ab72a074c..d159b2841a 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java @@ -20,6 +20,7 @@ package org.apache.poi.xslf.usermodel; import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_WORDPROCESSINGML; import java.awt.geom.Rectangle2D; import java.io.IOException; @@ -291,7 +292,7 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame { } static final String DML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"; - static final String PML_NS = "http://schemas.openxmlformats.org/presentationml/2006/main"; + static final String PML_NS = NS_PRESENTATIONML; private static final QName[] NV_CONTAINER = { new QName(PML_NS, "nvSpPr"), diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java index b56dc79062..69f0a86ea6 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java @@ -18,6 +18,7 @@ package org.apache.poi.xslf.usermodel; import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_PRESENTATIONML; import java.awt.*; import java.awt.geom.Rectangle2D; @@ -390,7 +391,7 @@ implements XSLFShapeContainer, Sheet { if(_spTree == null) { XmlObject root = getXmlObject(); XmlObject[] sp = root.selectPath( - "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:spTree"); + "declare namespace p='" + NS_PRESENTATIONML + "' .//*/p:spTree"); if(sp.length == 0) { throw new IllegalStateException("CTGroupShape was not found"); } @@ -404,8 +405,7 @@ implements XSLFShapeContainer, Sheet { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); String docName = getRootElementName(); if(docName != null) { - xmlOptions.setSaveSyntheticDocumentElement( - new QName("http://schemas.openxmlformats.org/presentationml/2006/main", docName)); + xmlOptions.setSaveSyntheticDocumentElement(new QName(NS_PRESENTATIONML, docName)); } PackagePart part = getPackagePart(); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java index 0eaf4ea775..d8bcd25f1d 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -44,6 +44,8 @@ import org.openxmlformats.schemas.drawingml.x2006.main.*; import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_PRESENTATIONML; + /** * Represents a paragraph of text within the containing text body. * The paragraph is the highest level text separation mechanism. @@ -743,7 +745,7 @@ public class XSLFTextParagraph implements TextParagraph footers = new ArrayList<>(); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java index 5947125249..56e0c6d8f2 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java @@ -27,7 +27,6 @@ import java.math.RoundingMode; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Locale; import javax.xml.namespace.QName; @@ -38,6 +37,7 @@ import org.apache.poi.ooxml.util.POIXMLUnits; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.util.*; import org.apache.poi.wp.usermodel.CharacterRun; +import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.xmlbeans.*; import org.apache.xmlbeans.impl.values.XmlAnyTypeImpl; import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart; @@ -107,7 +107,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun { pictTextObjs.addAll(Arrays.asList(r.getPictArray())); pictTextObjs.addAll(Arrays.asList(r.getDrawingArray())); for (XmlObject o : pictTextObjs) { - XmlObject[] ts = o.selectPath("declare namespace w='" + XWPFDocument.NS_OOXML_WP_MAIN + "' .//w:t"); + XmlObject[] ts = o.selectPath("declare namespace w='" + XSSFRelation.NS_WORDPROCESSINGML + "' .//w:t"); for (XmlObject t : ts) { NodeList kids = t.getDomNode().getChildNodes(); for (int n = 0; n < kids.getLength(); n++) { @@ -1351,7 +1351,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun { XmlObject o = c.getObject(); if (o instanceof CTRubyContent) { final Node node = o.getDomNode(); - if (XWPFDocument.NS_OOXML_WP_MAIN.equals(node.getNamespaceURI())) { + if (XSSFRelation.NS_WORDPROCESSINGML.equals(node.getNamespaceURI())) { final String tagName = node.getLocalName(); if ("rt".equals(tagName)) { inRT = true; @@ -1378,7 +1378,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun { // Field Codes (w:instrText, defined in spec sec. 17.16.23) // come up as instances of CTText, but we don't want them // in the normal text output - if (!("instrText".equals(node.getLocalName()) && XWPFDocument.NS_OOXML_WP_MAIN.equals(node.getNamespaceURI()))) { + if (!("instrText".equals(node.getLocalName()) && XSSFRelation.NS_WORDPROCESSINGML.equals(node.getNamespaceURI()))) { String textValue = ((CTText) o).getStringValue(); if (textValue != null) { if (isCapitalized() || isSmallCaps()) { @@ -1416,7 +1416,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun { // This bit works around it, and replicates the above // rules for that case final Node node = o.getDomNode(); - if (XWPFDocument.NS_OOXML_WP_MAIN.equals(node.getNamespaceURI())) { + if (XSSFRelation.NS_WORDPROCESSINGML.equals(node.getNamespaceURI())) { switch (node.getLocalName()) { case "tab": text.append('\t'); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSignatureLine.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSignatureLine.java index 46d66bf196..a549fd78ce 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSignatureLine.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSignatureLine.java @@ -29,7 +29,7 @@ import org.apache.poi.poifs.crypt.dsig.SignatureLine; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPicture; -import static org.apache.poi.xwpf.usermodel.XWPFDocument.NS_OOXML_WP_MAIN; +import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_WORDPROCESSINGML; public class XWPFSignatureLine extends SignatureLine { private static final String MS_VML_URN = "urn:schemas-microsoft-com:vml"; @@ -38,10 +38,10 @@ public class XWPFSignatureLine extends SignatureLine { public void parse(XWPFDocument doc) throws XmlException { line = XPathHelper.selectProperty(doc.getDocument(), CTSignatureLine.class, null, - new QName[]{new QName(NS_OOXML_WP_MAIN, "body")}, - new QName[]{new QName(NS_OOXML_WP_MAIN, "p")}, - new QName[]{new QName(NS_OOXML_WP_MAIN, "r")}, - new QName[]{new QName(NS_OOXML_WP_MAIN, "pict")}, + new QName[]{new QName(NS_WORDPROCESSINGML, "body")}, + new QName[]{new QName(NS_WORDPROCESSINGML, "p")}, + new QName[]{new QName(NS_WORDPROCESSINGML, "r")}, + new QName[]{new QName(NS_WORDPROCESSINGML, "pict")}, new QName[]{new QName(MS_VML_URN, "shape")}, new QName[]{QNAME_SIGNATURE_LINE}); if (line != null) { -- 2.39.5