aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-08-28 12:01:53 +0000
committerPJ Fanning <fanningpj@apache.org>2022-08-28 12:01:53 +0000
commitab5cb372e5175d6ac88b14c7a3a84dcaefff5b6a (patch)
tree7608e751438e54739de135a6cc9340bafa91fec1 /poi-ooxml/src
parent7fd339952b0622eb760f17a0b73077f0b8d269a8 (diff)
downloadpoi-ab5cb372e5175d6ac88b14c7a3a84dcaefff5b6a.tar.gz
poi-ab5cb372e5175d6ac88b14c7a3a84dcaefff5b6a.zip
do not rely on xml namespace prefixes - use the URIs
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903728 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java3
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java1
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java42
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSignatureLine.java3
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java2
5 files changed, 30 insertions, 21 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 b30d4d0e0c..f2b6a721ae 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,6 +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.xmlbeans.XmlOptions;
public class POIXMLTypeLoader {
@@ -61,7 +62,7 @@ public class POIXMLTypeLoader {
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("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
+ map.put(XWPFDocument.NS_OOXML_WP_MAIN, "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/xwpf/usermodel/XWPFDocument.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
index 77886d52e9..2066e6ff74 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
@@ -101,6 +101,7 @@ 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<>();
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 c46229a0cf..13decacd78 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
@@ -63,6 +63,7 @@ import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STHexColorRGB
import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.InputSource;
@@ -108,7 +109,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='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t");
+ XmlObject[] ts = o.selectPath("declare namespace w='" + XWPFDocument.NS_OOXML_WP_MAIN + "' .//w:t");
for (XmlObject t : ts) {
NodeList kids = t.getDomNode().getChildNodes();
for (int n = 0; n < kids.getLength(); n++) {
@@ -1351,12 +1352,15 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
while (c.toNextSelection()) {
XmlObject o = c.getObject();
if (o instanceof CTRubyContent) {
- String tagName = o.getDomNode().getNodeName();
- if ("w:rt".equals(tagName)) {
- inRT = true;
- } else if ("w:rubyBase".equals(tagName)) {
- inRT = false;
- inBase = true;
+ final Node node = o.getDomNode();
+ if (XWPFDocument.NS_OOXML_WP_MAIN.equals(node.getNamespaceURI())) {
+ final String tagName = node.getLocalName();
+ if ("rt".equals(tagName)) {
+ inRT = true;
+ } else if ("rubyBase".equals(tagName)) {
+ inRT = false;
+ inBase = true;
+ }
}
} else {
if (extractPhonetic && inRT) {
@@ -1372,11 +1376,11 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
private void _getText(XmlObject o, StringBuilder text) {
if (o instanceof CTText) {
- String tagName = o.getDomNode().getNodeName();
+ final Node node = o.getDomNode();
// 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 (!"w:instrText".equals(tagName)) {
+ if (!("instrText".equals(node.getLocalName()) && XWPFDocument.NS_OOXML_WP_MAIN.equals(node.getNamespaceURI()))) {
text.append(((CTText) o).getStringValue());
}
}
@@ -1405,15 +1409,17 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
// definitions around line 5642 of the XSDs
// This bit works around it, and replicates the above
// rules for that case
- String tagName = o.getDomNode().getNodeName();
- if ("w:tab".equals(tagName) || "tab".equals(tagName)) {
- text.append('\t');
- }
- if ("w:br".equals(tagName) || "br".equals(tagName)) {
- text.append('\n');
- }
- if ("w:cr".equals(tagName) || "cr".equals(tagName)) {
- text.append('\n');
+ final Node node = o.getDomNode();
+ if (XWPFDocument.NS_OOXML_WP_MAIN.equals(node.getNamespaceURI())) {
+ switch (node.getLocalName()) {
+ case "tab":
+ text.append('\t');
+ break;
+ case "br":
+ case "cr":
+ text.append('\n');
+ break;
+ }
}
}
if (o instanceof CTFtnEdnRef) {
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 9942124470..46d66bf196 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,8 +29,9 @@ 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;
+
public class XWPFSignatureLine extends SignatureLine {
- static final String NS_OOXML_WP_MAIN = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
private static final String MS_VML_URN = "urn:schemas-microsoft-com:vml";
private CTSignatureLine line;
diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java
index e3355b4b6a..e4478a16a9 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java
@@ -22,6 +22,7 @@ import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.getSampleFile;
import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.getSampleFileName;
import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.openSampleStream;
import static org.apache.poi.openxml4j.opc.PackagingURIHelper.createPartName;
+import static org.apache.poi.xwpf.usermodel.XWPFDocument.NS_OOXML_WP_MAIN;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -100,7 +101,6 @@ import org.xml.sax.SAXParseException;
public final class TestPackage {
private static final Logger LOG = LogManager.getLogger(TestPackage.class);
- private static final String NS_OOXML_WP_MAIN = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
private static final String CONTENT_EXT_PROPS = "application/vnd.openxmlformats-officedocument.extended-properties+xml";
private static final POIDataSamples xlsSamples = POIDataSamples.getSpreadSheetInstance();