reuse code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903733 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-08-28 13:12:31 +00:00
parent 0edc08a358
commit 98565236dd
11 changed files with 30 additions and 22 deletions

View 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");

View 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") };

View 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

View 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"
;

View 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"),

View 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();

View 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;

View 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";

View 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<>();

View 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');

View 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) {