]> source.dussan.org Git - poi.git/commitdiff
reuse code
authorPJ Fanning <fanningpj@apache.org>
Sun, 28 Aug 2022 13:12:31 +0000 (13:12 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sun, 28 Aug 2022 13:12:31 +0000 (13:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903733 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java
poi-ooxml/src/main/java/org/apache/poi/xslf/model/ParagraphPropertyFetcher.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSignatureLine.java

index f2b6a721ae9b93f51fd91ced52669f0b89986662..a73304da9971c1893b68d870474599bdcd097ebd 100644 (file)
@@ -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");
index eabe75df112c8105142f97f296768d1d7633cb92..e74615d4a79d836d1d6d5987dc6b80f51cbf90e9 100644 (file)
@@ -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<T> extends PropertyFetcher<T> {
     }
 
 
-    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") };
index dca6fed13158bfe99caec363e6bf0af93e8f1146..ab063a8bcb5eecb282b1a7fc917065b43b600f80 100644 (file)
@@ -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
index 0ab72a074c30776282c28d37b41de5071fdb4021..d159b2841a3262fc6c8d5d1ccb58048527940a6e 100644 (file)
@@ -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<XSLFSh
     @Override
     public XSLFPictureShape getFallbackPicture() {
         String xquery =
-                  "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main'; "
+                  "declare namespace p='" + NS_WORDPROCESSINGML + "'; "
                 + "declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' "
                 + ".//mc:Fallback/*/p:pic"
                 ;
index 0c7a3eb6bb9d14bed48d8edfa32edc4b4c93bca8..fe6572d658bf64a3eece9d4189740e24879c0017 100644 (file)
@@ -60,6 +60,8 @@ 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_PRESENTATIONML;
+
 /**
  * Base super-class class for all shapes in PresentationML
  */
@@ -72,7 +74,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
     }
 
     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"),
index b56dc79062337aa183c68968bebc3e5bbb1a464c..69f0a86ea6fca61e07422e1e3ec67e4eff72870d 100644 (file)
@@ -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<XSLFShape,XSLFTextParagraph> {
         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<XSLFShape,XSLFTextParagraph> {
         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();
index 0eaf4ea775a03c64f675dedb7783c4751bbedb9f..d8bcd25f1de0902b687f28f2b98c8fed1a840849 100644 (file)
@@ -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<XSLFShape,XSLFTextParagr
         int level = getIndentLevel();
 
         // wind up and find the root master sheet which must be slide master
-        final String nsPML = "http://schemas.openxmlformats.org/presentationml/2006/main";
+        final String nsPML = NS_PRESENTATIONML;
         XSLFSheet masterSheet = _shape.getSheet();
         for (XSLFSheet m = masterSheet; m != null; m = (XSLFSheet)m.getMasterSheet()) {
             masterSheet = m;
index a720ba43c6dce9beb5bad9ca31fef1f78fd142d0..60f835e1ed3494fda707c859277dd6a87bc0db44 100644 (file)
@@ -360,6 +360,8 @@ public final class XSSFRelation extends POIXMLRelation {
         "/xl/customProperty#.bin"
     );
 
+    public static final String NS_PRESENTATIONML = "http://schemas.openxmlformats.org/presentationml/2006/main";
+    public static final String NS_WORDPROCESSINGML = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
     public static final String NS_SPREADSHEETML = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
     public static final String NS_DRAWINGML = "http://schemas.openxmlformats.org/drawingml/2006/main";
     public static final String NS_CHART = "http://schemas.openxmlformats.org/drawingml/2006/chart";
index 2066e6ff7443e1ac9cf6b270ab1008fc87b391fa..77886d52e977160eeecf64fd1663fa19a5770be2 100644 (file)
@@ -101,7 +101,6 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
  */
 @SuppressWarnings("unused")
 public class XWPFDocument extends POIXMLDocument implements Document, IBody {
-    public static final String NS_OOXML_WP_MAIN = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
     private static final Logger LOG = LogManager.getLogger(XWPFDocument.class);
 
     protected List<XWPFFooter> footers = new ArrayList<>();
index 5947125249a604c11d732cbae921c48fe8e23f88..56e0c6d8f29f3d0a0672964e6fd0b22df179dda6 100644 (file)
@@ -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');
index 46d66bf196aaa16d207586790acd37d13cb151e1..a549fd78ce65609752614e5e49f0c51f41a59537 100644 (file)
@@ -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) {