Browse Source

remove use of some calls to deprecated cursor dispose()

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902057 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_3
PJ Fanning 2 years ago
parent
commit
b7261c1621
31 changed files with 259 additions and 468 deletions
  1. 5
    12
      poi-ooxml/src/main/java/org/apache/poi/ooxml/util/XPathHelper.java
  2. 16
    19
      poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java
  3. 8
    11
      poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESSignatureFacet.java
  4. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPath.java
  5. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFChart.java
  6. 2
    8
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFColor.java
  7. 2
    5
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
  8. 3
    13
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
  9. 2
    8
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFObjectShape.java
  10. 4
    16
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
  11. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPropertiesDelegate.java
  12. 2
    8
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java
  13. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
  14. 3
    12
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTable.java
  15. 4
    16
      poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
  16. 57
    85
      poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
  17. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java
  18. 2
    8
      poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
  19. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
  20. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
  21. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java
  22. 9
    38
      poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
  23. 3
    9
      poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java
  24. 46
    52
      poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComment.java
  25. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
  26. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
  27. 32
    32
      poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java
  28. 35
    37
      poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContentCell.java
  29. 7
    28
      poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
  30. 1
    4
      poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
  31. 6
    7
      poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFExamples.java

+ 5
- 12
poi-ooxml/src/main/java/org/apache/poi/ooxml/util/XPathHelper.java View File

public static <T extends XmlObject> T selectProperty(XmlObject startObject, Class<T> resultClass, XSLFShape.ReparseFactory<T> factory, QName[]... path) public static <T extends XmlObject> T selectProperty(XmlObject startObject, Class<T> resultClass, XSLFShape.ReparseFactory<T> factory, QName[]... path)
throws XmlException { throws XmlException {
XmlObject xo = startObject; XmlObject xo = startObject;
XmlCursor cur = xo.newCursor();
XmlCursor innerCur = null; XmlCursor innerCur = null;
try {
try (XmlCursor cur = startObject.newCursor()) {
innerCur = selectProperty(cur, path, 0, factory != null, false); innerCur = selectProperty(cur, path, 0, factory != null, false);
if (innerCur == null) { if (innerCur == null) {
return null; return null;


return (T)xo; return (T)xo;
} finally { } finally {
cur.dispose();
if (innerCur != null) { if (innerCur != null) {
innerCur.dispose();
innerCur.close();
} }
} }
} }
for (int i=0; i<choices; i++) { for (int i=0; i<choices; i++) {
// TODO: check [Requires] attribute of [Choice] element, if we can handle the content // TODO: check [Requires] attribute of [Choice] element, if we can handle the content
AlternateContentDocument.AlternateContent.Choice choice = alterCont.getChoiceArray(i); AlternateContentDocument.AlternateContent.Choice choice = alterCont.getChoiceArray(i);
XmlCursor cCur = choice.newCursor();
XmlCursor innerCur = null; XmlCursor innerCur = null;
try {
try (XmlCursor cCur = choice.newCursor()) {
String requiresNS = cCur.namespaceForPrefix(choice.getRequires()); String requiresNS = cCur.namespaceForPrefix(choice.getRequires());
if (MAC_DML_NS.equalsIgnoreCase(requiresNS)) { if (MAC_DML_NS.equalsIgnoreCase(requiresNS)) {
// Mac DML usually contains PDFs ... // Mac DML usually contains PDFs ...
continue; continue;
} }
innerCur = selectProperty(cCur, path, offset, reparseAlternate, true); innerCur = selectProperty(cCur, path, offset, reparseAlternate, true);
if (innerCur != null) {
if (innerCur != null && innerCur != cCur) {
return innerCur; return innerCur;
} }
} finally {
if (innerCur != cCur) {
cCur.dispose();
}
} }
} }


return innerCur; return innerCur;
} finally { } finally {
if (innerCur != fCur) { if (innerCur != fCur) {
fCur.dispose();
fCur.close();
} }
} }
} }

+ 16
- 19
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java View File

} }


public void setSignatureShape(CTSignatureLine signatureLine) { public void setSignatureShape(CTSignatureLine signatureLine) {
XmlCursor cur = signatureLine.newCursor();
cur.toParent();
this.signatureShape = (CTShape)cur.getObject();
cur.dispose();
try (XmlCursor cur = signatureLine.newCursor()) {
cur.toParent();
this.signatureShape = (CTShape)cur.getObject();
}
} }


public void updateSignatureConfig(SignatureConfig config) throws IOException { public void updateSignatureConfig(SignatureConfig config) throws IOException {
setSuggestedSigner(signatureLine.getSuggestedsigner()); setSuggestedSigner(signatureLine.getSuggestedsigner());
setSuggestedSigner2(signatureLine.getSuggestedsigner2()); setSuggestedSigner2(signatureLine.getSuggestedsigner2());
setSuggestedSignerEmail(signatureLine.getSuggestedsigneremail()); setSuggestedSignerEmail(signatureLine.getSuggestedsigneremail());
XmlCursor cur = signatureLine.newCursor();
try {
try (XmlCursor cur = signatureLine.newCursor()) {
// the signinginstructions are actually qualified, but our schema version is too old // the signinginstructions are actually qualified, but our schema version is too old
setSigningInstructions(cur.getAttributeText(new QName(MS_OFFICE_URN, "signinginstructions"))); setSigningInstructions(cur.getAttributeText(new QName(MS_OFFICE_URN, "signinginstructions")));
} finally {
cur.dispose();
} }
} }


CTGroup grp = CTGroup.Factory.newInstance(); CTGroup grp = CTGroup.Factory.newInstance();
grp.addNewShape(); grp.addNewShape();


XmlCursor contCur = signatureContainer.newCursor();
contCur.toEndToken();
XmlCursor otherC = grp.newCursor();
otherC.copyXmlContents(contCur);
otherC.dispose();
contCur.toPrevSibling();
signatureShape = (CTShape)contCur.getObject();
contCur.dispose();
try (XmlCursor contCur = signatureContainer.newCursor()) {
contCur.toEndToken();
try (XmlCursor otherC = grp.newCursor()) {
otherC.copyXmlContents(contCur);
}
contCur.toPrevSibling();
signatureShape = (CTShape)contCur.getObject();
}


signatureShape.setAlt("Microsoft Office Signature Line..."); signatureShape.setAlt("Microsoft Office Signature Line...");
signatureShape.setStyle("width:191.95pt;height:96.05pt"); signatureShape.setStyle("width:191.95pt;height:96.05pt");
xsl.setProvid("{00000000-0000-0000-0000-000000000000}"); xsl.setProvid("{00000000-0000-0000-0000-000000000000}");
xsl.setExt(STExt.EDIT); xsl.setExt(STExt.EDIT);
xsl.setSigninginstructionsset(STTrueFalse.T); xsl.setSigninginstructionsset(STTrueFalse.T);
XmlCursor cur = xsl.newCursor();
cur.setAttributeText(new QName(MS_OFFICE_URN, "signinginstructions"), signingInstructions);
cur.dispose();
try (XmlCursor cur = xsl.newCursor()) {
cur.setAttributeText(new QName(MS_OFFICE_URN, "signinginstructions"), signingInstructions);
}
} catch (IOException | InvalidFormatException e) { } catch (IOException | InvalidFormatException e) {
// shouldn't happen ... // shouldn't happen ...
throw new POIXMLException("Can't generate signature line image", e); throw new POIXMLException("Can't generate signature line image", e);

+ 8
- 11
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESSignatureFacet.java View File

} }


protected static void insertXChild(XmlObject root, XmlObject child) { protected static void insertXChild(XmlObject root, XmlObject child) {
XmlCursor rootCursor = root.newCursor();
rootCursor.toEndToken();
XmlCursor childCursor = child.newCursor();
childCursor.toNextToken();
childCursor.moveXml(rootCursor);
childCursor.dispose();
rootCursor.dispose();
try (XmlCursor rootCursor = root.newCursor()) {
rootCursor.toEndToken();
try (XmlCursor childCursor = child.newCursor()) {
childCursor.toNextToken();
childCursor.moveXml(rootCursor);
}
}
} }


/** /**
* Workaround for Document.importNode, which causes SIGSEGV in JDK14 (Ubuntu) * Workaround for Document.importNode, which causes SIGSEGV in JDK14 (Ubuntu)
*/ */
private static Element importNode(Document document, XmlObject xo) { private static Element importNode(Document document, XmlObject xo) {
XmlCursor cur = xo.newCursor();
try {
try (XmlCursor cur = xo.newCursor()) {
QName elName = cur.getName(); QName elName = cur.getName();
Element lastNode = document.createElementNS(elName.getNamespaceURI(), elName.getLocalPart()); Element lastNode = document.createElementNS(elName.getNamespaceURI(), elName.getLocalPart());
while (cur.hasNextToken()) { while (cur.hasNextToken()) {
} }
} }
return lastNode; return lastNode;
} finally {
cur.dispose();
} }
} }
} }

+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPath.java View File

@Override @Override
public Path2D.Double getPath(Context ctx) { public Path2D.Double getPath(Context ctx) {
Path2D.Double path2D = new Path2D.Double(); Path2D.Double path2D = new Path2D.Double();
XmlCursor cur = pathXml.newCursor();
try {
try (XmlCursor cur = pathXml.newCursor()) {
for (boolean hasNext = cur.toFirstChild(); hasNext; hasNext = cur.toNextSibling()) { for (boolean hasNext = cur.toFirstChild(); hasNext; hasNext = cur.toNextSibling()) {
XmlObject xo = cur.getObject(); XmlObject xo = cur.getObject();
PathCommand pc; PathCommand pc;
} }
pc.execute(path2D, ctx); pc.execute(path2D, ctx);
} }
} finally {
cur.dispose();
} }
return path2D; return path2D;
} }

+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFChart.java View File

xfrm.setOff(off); xfrm.setOff(off);


CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData(); CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData();
XmlCursor grCur = gr.newCursor();
try {
try (XmlCursor grCur = gr.newCursor()) {
grCur.toNextToken(); grCur.toNextToken();
grCur.beginElement(new QName(CHART_URI, "chart")); grCur.beginElement(new QName(CHART_URI, "chart"));
grCur.insertAttributeWithValue("id", PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, rID); grCur.insertAttributeWithValue("id", PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, rID);
} finally {
grCur.dispose();
} }


gr.setUri(CHART_URI); gr.setUri(CHART_URI);

+ 2
- 8
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFColor.java View File

return _phClr == null ? null : toColor(_phClr, theme); return _phClr == null ? null : toColor(_phClr, theme);
} }


final XmlCursor cur = obj.newCursor();
Color color = null; Color color = null;
try {
try (XmlCursor cur = obj.newCursor()) {
XmlObject ch; XmlObject ch;
for (int idx=0; color == null && (ch = nextObject(obj, cur, idx)) != null; idx++) { for (int idx=0; color == null && (ch = nextObject(obj, cur, idx)) != null; idx++) {
if (ch instanceof CTHslColor) { if (ch instanceof CTHslColor) {
throw new IllegalArgumentException("Unexpected color choice: " + ch.getClass()); throw new IllegalArgumentException("Unexpected color choice: " + ch.getClass());
} }
} }
} finally {
cur.dispose();
} }
return color; return color;
} }
if (obj == null) { if (obj == null) {
continue; continue;
} }
XmlCursor cur = obj.newCursor();
try {
try (XmlCursor cur = obj.newCursor()) {
if (!( if (!(
cur.toChild(XSLFRelation.NS_DRAWINGML, elem) || cur.toChild(XSLFRelation.NS_DRAWINGML, elem) ||
(cur.toFirstChild() && cur.toChild(XSLFRelation.NS_DRAWINGML, elem)) (cur.toFirstChild() && cur.toChild(XSLFRelation.NS_DRAWINGML, elem))
if (str != null && !"".equals(str)) { if (str != null && !"".equals(str)) {
return Integer.parseInt(str); return Integer.parseInt(str);
} }
} finally {
cur.dispose();
} }
} }
return -1; return -1;

+ 2
- 5
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java View File

} }


final CTCustomGeometry2D geom = ((CTShapeProperties)xo).getCustGeom(); final CTCustomGeometry2D geom = ((CTShapeProperties)xo).getCustGeom();
for(CTPath2D spPath : geom.getPathLst().getPathArray()){
XmlCursor cursor = spPath.newCursor();
try {
for(CTPath2D spPath : geom.getPathLst().getPathArray()) {
try (XmlCursor cursor = spPath.newCursor()) {
if (cursor.toFirstChild()) { if (cursor.toFirstChild()) {
do { do {
final XmlObject ch = cursor.getObject(); final XmlObject ch = cursor.getObject();
} }
} while (cursor.toNextSibling()); } while (cursor.toNextSibling());
} }
} finally {
cursor.dispose();
} }
} }



+ 3
- 13
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java View File

String xpath = "declare namespace c='" + DRAWINGML_CHART_URI + "' c:chart"; String xpath = "declare namespace c='" + DRAWINGML_CHART_URI + "' c:chart";
XmlObject[] obj = getGraphicalData().selectPath(xpath); XmlObject[] obj = getGraphicalData().selectPath(xpath);
if (obj != null && obj.length == 1) { if (obj != null && obj.length == 1) {
XmlCursor c = obj[0].newCursor();
try {
try (XmlCursor c = obj[0].newCursor()) {
QName idQualifiedName = new QName(CORE_PROPERTIES_ECMA376_NS, "id"); QName idQualifiedName = new QName(CORE_PROPERTIES_ECMA376_NS, "id");
id = c.getAttributeText(idQualifiedName); id = c.getAttributeText(idQualifiedName);
} finally {
c.dispose();
} }
} }
if (id == null) { if (id == null) {
String xpath = "declare namespace c='" + DRAWINGML_CHART_URI + "' c:chart"; String xpath = "declare namespace c='" + DRAWINGML_CHART_URI + "' c:chart";
XmlObject[] obj = objData.selectPath(xpath); XmlObject[] obj = objData.selectPath(xpath);
if (obj != null && obj.length == 1) { if (obj != null && obj.length == 1) {
XmlCursor c = obj[0].newCursor();
try {
try (XmlCursor c = obj[0].newCursor()) {
// duplicate chart with embedded workbook // duplicate chart with embedded workbook
QName idQualifiedName = new QName(CORE_PROPERTIES_ECMA376_NS, "id"); QName idQualifiedName = new QName(CORE_PROPERTIES_ECMA376_NS, "id");
String id = c.getAttributeText(idQualifiedName); String id = c.getAttributeText(idQualifiedName);
} }
} catch (InvalidFormatException | IOException e) { } catch (InvalidFormatException | IOException e) {
throw new POIXMLException(e); throw new POIXMLException(e);
} finally {
c.dispose();
} }
} }
} }
String xpath = "declare namespace dgm='" + DRAWINGML_DIAGRAM_URI + "' $this//dgm:relIds"; String xpath = "declare namespace dgm='" + DRAWINGML_DIAGRAM_URI + "' $this//dgm:relIds";
XmlObject[] obj = objData.selectPath(xpath); XmlObject[] obj = objData.selectPath(xpath);
if(obj != null && obj.length == 1) { if(obj != null && obj.length == 1) {
XmlCursor c = obj[0].newCursor();

XSLFSheet sheet = srcShape.getSheet(); XSLFSheet sheet = srcShape.getSheet();
try {
try (XmlCursor c = obj[0].newCursor()) {
String dm = c.getAttributeText(new QName(CORE_PROPERTIES_ECMA376_NS, "dm")); String dm = c.getAttributeText(new QName(CORE_PROPERTIES_ECMA376_NS, "dm"));
PackageRelationship dmRel = sheet.getPackagePart().getRelationship(dm); PackageRelationship dmRel = sheet.getPackagePart().getRelationship(dm);
PackagePart dmPart = sheet.getPackagePart().getRelatedPart(dmRel); PackagePart dmPart = sheet.getPackagePart().getRelatedPart(dmRel);


} catch (InvalidFormatException e){ } catch (InvalidFormatException e){
throw new POIXMLException(e); throw new POIXMLException(e);
} finally {
c.dispose();
} }
} }
} }

+ 2
- 8
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFObjectShape.java View File

frame.addNewXfrm(); frame.addNewXfrm();
CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData(); CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData();
gr.setUri(OLE_URI); gr.setUri(OLE_URI);
XmlCursor grCur = gr.newCursor();
try {
try (XmlCursor grCur = gr.newCursor()) {
grCur.toEndToken(); grCur.toEndToken();
grCur.beginElement(new QName(PML_NS, "oleObj")); grCur.beginElement(new QName(PML_NS, "oleObj"));
grCur.insertElement(new QName(PML_NS, "embed")); grCur.insertElement(new QName(PML_NS, "embed"));


spPr.addNewPrstGeom().setPrst(STShapeType.RECT); spPr.addNewPrstGeom().setPrst(STShapeType.RECT);


XmlCursor picCur = grpShp.newCursor();
try {
try (XmlCursor picCur = grpShp.newCursor()) {
picCur.toStartDoc(); picCur.toStartDoc();
picCur.moveXmlContents(grCur); picCur.moveXmlContents(grCur);
} finally {
picCur.dispose();
} }
} finally {
grCur.dispose();
} }


return frame; return frame;

+ 4
- 16
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java View File

if (bitmapId == -1) { if (bitmapId == -1) {
extBitmap = extLst.addNewExt(); extBitmap = extLst.addNewExt();
extBitmap.setUri(BITMAP_URI); extBitmap.setUri(BITMAP_URI);
XmlCursor cur = extBitmap.newCursor();
try {
try (XmlCursor cur = extBitmap.newCursor()) {
cur.toEndToken(); cur.toEndToken();
cur.beginElement(new QName(MS_DML_NS, "useLocalDpi", "a14")); cur.beginElement(new QName(MS_DML_NS, "useLocalDpi", "a14"));
cur.insertNamespace("a14", MS_DML_NS); cur.insertNamespace("a14", MS_DML_NS);
cur.insertAttributeWithValue("val", "0"); cur.insertAttributeWithValue("val", "0");
} finally {
cur.dispose();
} }
} }




CTOfficeArtExtension svgBitmap = extLst.addNewExt(); CTOfficeArtExtension svgBitmap = extLst.addNewExt();
svgBitmap.setUri(SVG_URI); svgBitmap.setUri(SVG_URI);
XmlCursor cur = svgBitmap.newCursor();
try {
try (XmlCursor cur = svgBitmap.newCursor()) {
cur.toEndToken(); cur.toEndToken();
cur.beginElement(new QName(MS_SVG_NS, "svgBlip", "asvg")); cur.beginElement(new QName(MS_SVG_NS, "svgBlip", "asvg"));
cur.insertNamespace("asvg", MS_SVG_NS); cur.insertNamespace("asvg", MS_SVG_NS);
cur.insertAttributeWithValue(EMBED_TAG, svgRelId); cur.insertAttributeWithValue(EMBED_TAG, svgRelId);
} finally {
cur.dispose();
} }
} }




int size = extLst.sizeOfExtArray(); int size = extLst.sizeOfExtArray();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
XmlCursor cur = extLst.getExtArray(i).newCursor();
try {
try (XmlCursor cur = extLst.getExtArray(i).newCursor()) {
if (cur.toChild(MS_SVG_NS, "svgBlip")) { if (cur.toChild(MS_SVG_NS, "svgBlip")) {
String svgRelId = cur.getAttributeText(EMBED_TAG); String svgRelId = cur.getAttributeText(EMBED_TAG);
return (svgRelId != null) ? (XSLFPictureData) getSheet().getRelationById(svgRelId) : null; return (svgRelId != null) ? (XSLFPictureData) getSheet().getRelationById(svgRelId) : null;
} }
} finally {
cur.dispose();
} }
} }
return null; return null;
String xpath = "declare namespace a14='"+ MS_DML_NS +"' $this//a14:imgProps/a14:imgLayer"; String xpath = "declare namespace a14='"+ MS_DML_NS +"' $this//a14:imgProps/a14:imgLayer";
XmlObject[] obj = ext.selectPath(xpath); XmlObject[] obj = ext.selectPath(xpath);
if(obj != null && obj.length == 1) { if(obj != null && obj.length == 1) {
XmlCursor c = obj[0].newCursor();
try {
try (XmlCursor c = obj[0].newCursor()) {
String id = c.getAttributeText(EMBED_TAG); String id = c.getAttributeText(EMBED_TAG);
String newId = getSheet().importBlip(id, p.getSheet()); String newId = getSheet().importBlip(id, p.getSheet());
c.setAttributeText(EMBED_TAG, newId); c.setAttributeText(EMBED_TAG, newId);
} finally {
c.dispose();
} }
} }
} }

+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPropertiesDelegate.java View File

@Override @Override
public boolean isLineStyle() { public boolean isLineStyle() {
XmlCursor cur = props.newCursor();
try {
try (XmlCursor cur = props.newCursor()) {
String name = cur.getName().getLocalPart(); String name = cur.getName().getLocalPart();
return "lnRef".equals(name); return "lnRef".equals(name);
} finally {
cur.dispose();
} }
} }
} }

+ 2
- 8
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java View File

@SuppressWarnings({"unchecked", "WeakerAccess", "unused", "SameParameterValue"}) @SuppressWarnings({"unchecked", "WeakerAccess", "unused", "SameParameterValue"})
protected <T extends XmlObject> T getChild(Class<T> childClass, String namespace, String nodename) { protected <T extends XmlObject> T getChild(Class<T> childClass, String namespace, String nodename) {
T child = null; T child = null;
XmlCursor cur = getXmlObject().newCursor();
try {
try (XmlCursor cur = getXmlObject().newCursor()) {
if (cur.toChild(namespace, nodename)) { if (cur.toChild(namespace, nodename)) {
child = (T)cur.getObject(); child = (T)cur.getObject();
} }
if (cur.toChild(XSLFRelation.NS_DRAWINGML, nodename)) { if (cur.toChild(XSLFRelation.NS_DRAWINGML, nodename)) {
child = (T)cur.getObject(); child = (T)cur.getObject();
} }
} finally {
cur.dispose();
} }
return child; return child;
} }
return null; return null;
} }
XSLFFillProperties fp = null; XSLFFillProperties fp = null;
XmlCursor cur = styleLst.newCursor();
try {
try (XmlCursor cur = styleLst.newCursor()) {
if (cur.toChild(Math.toIntExact(childIdx))) { if (cur.toChild(Math.toIntExact(childIdx))) {
fp = XSLFPropertiesDelegate.getFillDelegate(cur.getObject()); fp = XSLFPropertiesDelegate.getFillDelegate(cur.getObject());
} }
} finally {
cur.dispose();
} }


CTSchemeColor phClr = fillRef.getSchemeClr(); CTSchemeColor phClr = fillRef.getSchemeClr();

+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java View File

final XSLFSheet sheet = (parent instanceof XSLFSheet) ? (XSLFSheet)parent : ((XSLFShape)parent).getSheet(); final XSLFSheet sheet = (parent instanceof XSLFSheet) ? (XSLFSheet)parent : ((XSLFShape)parent).getSheet();


List<XSLFShape> shapes = new ArrayList<>(); List<XSLFShape> shapes = new ArrayList<>();
XmlCursor cur = spTree.newCursor();
try {
try (XmlCursor cur = spTree.newCursor()) {
for (boolean b = cur.toFirstChild(); b; b = cur.toNextSibling()) { for (boolean b = cur.toFirstChild(); b; b = cur.toNextSibling()) {
XmlObject ch = cur.getObject(); XmlObject ch = cur.getObject();
if(ch instanceof CTShape){ if(ch instanceof CTShape){
cur.pop(); cur.pop();
} }
} }
} finally {
cur.dispose();
} }


for (final XSLFShape s : shapes) { for (final XSLFShape s : shapes) {

+ 3
- 12
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTable.java View File

super(shape, sheet); super(shape, sheet);


CTGraphicalObjectData god = shape.getGraphic().getGraphicData(); CTGraphicalObjectData god = shape.getGraphic().getGraphicData();
XmlCursor xc = god.newCursor();
try {
try (XmlCursor xc = god.newCursor()) {
if (!xc.toChild(XSLFRelation.NS_DRAWINGML, "tbl")) { if (!xc.toChild(XSLFRelation.NS_DRAWINGML, "tbl")) {
throw new IllegalStateException("a:tbl element was not found in\n " + god); throw new IllegalStateException("a:tbl element was not found in\n " + god);
} }
throw new IllegalStateException(errStr); throw new IllegalStateException(errStr);
} }
_table = (CTTable)xo; _table = (CTTable)xo;
} finally {
xc.dispose();
} }


_rows = new ArrayList<>(_table.sizeOfTrArray()); _rows = new ArrayList<>(_table.sizeOfTrArray());


frame.addNewXfrm(); frame.addNewXfrm();
CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData(); CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData();
XmlCursor grCur = gr.newCursor();
try {
try (XmlCursor grCur = gr.newCursor()) {
grCur.toNextToken(); grCur.toNextToken();
grCur.beginElement(new QName(XSLFRelation.NS_DRAWINGML, "tbl")); grCur.beginElement(new QName(XSLFRelation.NS_DRAWINGML, "tbl"));


CTTable tbl = CTTable.Factory.newInstance(); CTTable tbl = CTTable.Factory.newInstance();
tbl.addNewTblPr(); tbl.addNewTblPr();
tbl.addNewTblGrid(); tbl.addNewTblGrid();
XmlCursor tblCur = tbl.newCursor();
try {
try (XmlCursor tblCur = tbl.newCursor()) {
tblCur.moveXmlContents(grCur); tblCur.moveXmlContents(grCur);
} finally {
tblCur.dispose();
} }
} finally {
grCur.dispose();
} }
gr.setUri(TABLE_URI); gr.setUri(TABLE_URI);
return frame; return frame;

+ 4
- 16
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java View File

_runs = new ArrayList<>(); _runs = new ArrayList<>();
_shape = shape; _shape = shape;


XmlCursor c = _p.newCursor();
try {
try (XmlCursor c = _p.newCursor()) {
if (c.toFirstChild()) { if (c.toFirstChild()) {
do { do {
XmlObject r = c.getObject(); XmlObject r = c.getObject();
} }
} while (c.toNextSibling()); } while (c.toNextSibling());
} }
} finally {
c.dispose();
} }
} }


for (XSLFSheet m = masterSheet; m != null; m = (XSLFSheet)m.getMasterSheet()) { for (XSLFSheet m = masterSheet; m != null; m = (XSLFSheet)m.getMasterSheet()) {
masterSheet = m; masterSheet = m;
XmlObject xo = masterSheet.getXmlObject(); XmlObject xo = masterSheet.getXmlObject();
XmlCursor cur = xo.newCursor();
try {
try (XmlCursor cur = xo.newCursor()) {
cur.push(); cur.push();
if ((cur.toChild(nsPML, "txStyles") && cur.toChild(nsPML, defaultStyleSelector)) || if ((cur.toChild(nsPML, "txStyles") && cur.toChild(nsPML, defaultStyleSelector)) ||
(cur.pop() && cur.toChild(nsPML, "notesStyle"))) { (cur.pop() && cur.toChild(nsPML, "notesStyle"))) {
level--; level--;
} }
} }
} finally {
cur.dispose();
} }
} }


thisP.removeFld(i-1); thisP.removeFld(i-1);
} }


XmlCursor thisC = thisP.newCursor();
try {
try (XmlCursor thisC = thisP.newCursor()) {
thisC.toEndToken(); thisC.toEndToken();
XmlCursor otherC = otherP.newCursor();
try {
try (XmlCursor otherC = otherP.newCursor()) {
otherC.copyXmlContents(thisC); otherC.copyXmlContents(thisC);
} finally {
otherC.dispose();
} }
} finally {
thisC.dispose();
} }


for (XSLFTextRun tr : other.getTextRuns()) { for (XSLFTextRun tr : other.getTextRuns()) {

+ 57
- 85
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java View File

ole1.setId(olePR.getId()); ole1.setId(olePR.getId());


CTTwoCellAnchor ctAnchor; CTTwoCellAnchor ctAnchor;
final XmlCursor cur1 = ole1.newCursor();
try {
try (XmlCursor cur1 = ole1.newCursor()) {
cur1.toEndToken(); cur1.toEndToken();
cur1.beginElement("objectPr", XSSFRelation.NS_SPREADSHEETML); cur1.beginElement("objectPr", XSSFRelation.NS_SPREADSHEETML);
cur1.insertAttributeWithValue("id", PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, imgSheetPR.getId()); cur1.insertAttributeWithValue("id", PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, imgSheetPR.getId());


ctAnchor = createTwoCellAnchor((XSSFClientAnchor) anchor); ctAnchor = createTwoCellAnchor((XSSFClientAnchor) anchor);


final XmlCursor cur2 = ctAnchor.newCursor();
try {
try (XmlCursor cur2 = ctAnchor.newCursor()) {
cur2.copyXmlContents(cur1); cur2.copyXmlContents(cur1);
} finally {
cur2.dispose();
} }


cur1.toParent(); cur1.toParent();
cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "from")); cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "from"));
cur1.toNextSibling(); cur1.toNextSibling();
cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "to")); cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "to"));
} finally {
cur1.dispose();
} }


// add a new shape and link OLE & image part // add a new shape and link OLE & image part
cNvPr.setId(shapeId); cNvPr.setId(shapeId);
cNvPr.setName("Object " + shapeId); cNvPr.setName("Object " + shapeId);


XmlCursor extCur = cNvPr.getExtLst().getExtArray(0).newCursor();
try {
try (XmlCursor extCur = cNvPr.getExtLst().getExtArray(0).newCursor()) {
extCur.toFirstChild(); extCur.toFirstChild();
extCur.setAttributeText(new QName("spid"), "_x0000_s" + shapeId); extCur.setAttributeText(new QName("spid"), "_x0000_s" + shapeId);
} finally {
extCur.dispose();
} }


XSSFObjectData shape = new XSSFObjectData(this, ctShape); XSSFObjectData shape = new XSSFObjectData(this, ctShape);
*/ */
public List<XSSFShape> getShapes() { public List<XSSFShape> getShapes() {
List<XSSFShape> lst = new ArrayList<>(); List<XSSFShape> lst = new ArrayList<>();
XmlCursor cur = drawing.newCursor();
try {
try (XmlCursor cur = drawing.newCursor()) {
if (cur.toFirstChild()) { if (cur.toFirstChild()) {
addShapes(cur, lst); addShapes(cur, lst);
} }
} finally {
cur.dispose();
} }
return lst; return lst;
} }
*/ */
public List<XSSFShape> getShapes(XSSFShapeGroup groupshape) { public List<XSSFShape> getShapes(XSSFShapeGroup groupshape) {
List<XSSFShape> lst = new ArrayList<>(); List<XSSFShape> lst = new ArrayList<>();
XmlCursor cur = groupshape.getCTGroupShape().newCursor();
try {
try (XmlCursor cur = groupshape.getCTGroupShape().newCursor()) {
addShapes(cur, lst); addShapes(cur, lst);
} finally {
cur.dispose();
} }
return lst; return lst;
} }


private void addShapes(XmlCursor cur, List<XSSFShape> lst) { private void addShapes(XmlCursor cur, List<XSSFShape> lst) {
try {
do {
cur.push();
if (cur.toFirstChild()) {
do {
XmlObject obj = cur.getObject();

XSSFShape shape;
if (obj instanceof CTMarker) {
// ignore anchor elements
continue;
} else if (obj instanceof CTPicture) {
shape = new XSSFPicture(this, (CTPicture) obj);
} else if (obj instanceof CTConnector) {
shape = new XSSFConnector(this, (CTConnector) obj);
} else if (obj instanceof CTShape) {
shape = hasOleLink(obj) ? new XSSFObjectData(this, (CTShape) obj)
: new XSSFSimpleShape(this, (CTShape) obj);
} else if (obj instanceof CTGraphicalObjectFrame) {
shape = new XSSFGraphicFrame(this, (CTGraphicalObjectFrame) obj);
} else if (obj instanceof CTGroupShape) {
shape = new XSSFShapeGroup(this, (CTGroupShape) obj);
} else if (obj instanceof XmlAnyTypeImpl) {
LOG.atWarn().log("trying to parse AlternateContent, this unlinks the returned Shapes from the underlying xml content, so those shapes can't be used to modify the drawing, i.e. modifications will be ignored!");

// XmlAnyTypeImpl is returned for AlternateContent
// parts, which might contain a CTDrawing
cur.push();
cur.toFirstChild();
XmlCursor cur2 = null;
try {
// need to parse AlternateContent again,
// otherwise the child elements aren't typed,
// but also XmlAnyTypes
CTDrawing alterWS = CTDrawing.Factory.parse(cur.newXMLStreamReader());
cur2 = alterWS.newCursor();
do {
cur.push();
if (cur.toFirstChild()) {
do {
XmlObject obj = cur.getObject();

XSSFShape shape;
if (obj instanceof CTMarker) {
// ignore anchor elements
continue;
} else if (obj instanceof CTPicture) {
shape = new XSSFPicture(this, (CTPicture) obj);
} else if (obj instanceof CTConnector) {
shape = new XSSFConnector(this, (CTConnector) obj);
} else if (obj instanceof CTShape) {
shape = hasOleLink(obj) ? new XSSFObjectData(this, (CTShape) obj)
: new XSSFSimpleShape(this, (CTShape) obj);
} else if (obj instanceof CTGraphicalObjectFrame) {
shape = new XSSFGraphicFrame(this, (CTGraphicalObjectFrame) obj);
} else if (obj instanceof CTGroupShape) {
shape = new XSSFShapeGroup(this, (CTGroupShape) obj);
} else if (obj instanceof XmlAnyTypeImpl) {
LOG.atWarn().log("trying to parse AlternateContent, this unlinks the returned Shapes from the underlying xml content, so those shapes can't be used to modify the drawing, i.e. modifications will be ignored!");

// XmlAnyTypeImpl is returned for AlternateContent
// parts, which might contain a CTDrawing
cur.push();
cur.toFirstChild();
try {
// need to parse AlternateContent again,
// otherwise the child elements aren't typed,
// but also XmlAnyTypes
CTDrawing alterWS = CTDrawing.Factory.parse(cur.newXMLStreamReader());
try (XmlCursor cur2 = alterWS.newCursor()) {
if (cur2.toFirstChild()) { if (cur2.toFirstChild()) {
addShapes(cur2, lst); addShapes(cur2, lst);
} }
} catch (XmlException e) {
LOG.atWarn().withThrowable(e).log("unable to parse CTDrawing in alternate content.");
} finally {
if (cur2 != null) {
cur2.dispose();
}
cur.pop();
} }
continue;
} else {
// ignore anything else
continue;
} catch (XmlException e) {
LOG.atWarn().withThrowable(e).log("unable to parse CTDrawing in alternate content.");
} finally {
cur.pop();
} }
continue;
} else {
// ignore anything else
continue;
}


assert (shape != null);
shape.anchor = getAnchorFromParent(obj);
lst.add(shape);
assert (shape != null);
shape.anchor = getAnchorFromParent(obj);
lst.add(shape);


} while (cur.toNextSibling());
}
cur.pop();
} while (cur.toNextSibling());
} finally {
cur.dispose();
}
} while (cur.toNextSibling());
}
cur.pop();
} while (cur.toNextSibling());
} }


private boolean hasOleLink(XmlObject shape) { private boolean hasOleLink(XmlObject shape) {
QName uriName = new QName(null, "uri"); QName uriName = new QName(null, "uri");
String xquery = "declare namespace a='" + XSSFRelation.NS_DRAWINGML + "' .//a:extLst/a:ext"; String xquery = "declare namespace a='" + XSSFRelation.NS_DRAWINGML + "' .//a:extLst/a:ext";
XmlCursor cur = shape.newCursor();
try {
try (XmlCursor cur = shape.newCursor()) {
cur.selectPath(xquery); cur.selectPath(xquery);
while (cur.toNextSelection()) { while (cur.toNextSelection()) {
String uri = cur.getAttributeText(uriName); String uri = cur.getAttributeText(uriName);
return true; return true;
} }
} }
} finally {
cur.dispose();
} }
return false; return false;
} }
XSSFAnchor anchor = null; XSSFAnchor anchor = null;


XmlObject parentXbean = null; XmlObject parentXbean = null;
XmlCursor cursor = obj.newCursor();
try {
try (XmlCursor cursor = obj.newCursor()) {
if (cursor.toParent()) { if (cursor.toParent()) {
parentXbean = cursor.getObject(); parentXbean = cursor.getObject();
} }
} finally {
cursor.dispose();
} }
if (parentXbean != null) { if (parentXbean != null) {
if (parentXbean instanceof CTTwoCellAnchor) { if (parentXbean instanceof CTTwoCellAnchor) {

+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java View File

private void appendChartElement(CTGraphicalObjectData data, String id) { private void appendChartElement(CTGraphicalObjectData data, String id) {
String r_namespaceUri = STRelationshipId.type.getName().getNamespaceURI(); String r_namespaceUri = STRelationshipId.type.getName().getNamespaceURI();
String c_namespaceUri = XSSFDrawing.NAMESPACE_C; String c_namespaceUri = XSSFDrawing.NAMESPACE_C;
XmlCursor cursor = data.newCursor();
try {
try (XmlCursor cursor = data.newCursor()) {
cursor.toNextToken(); cursor.toNextToken();
cursor.beginElement(new QName(c_namespaceUri, "chart", "c")); cursor.beginElement(new QName(c_namespaceUri, "chart", "c"));
cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id", "r"), id); cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id", "r"), id);
} finally {
cursor.dispose();
} }
data.setUri(c_namespaceUri); data.setUri(c_namespaceUri);
} }

+ 2
- 8
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java View File

// https://msdn.microsoft.com/en-us/library/dd911027(v=office.12).aspx // https://msdn.microsoft.com/en-us/library/dd911027(v=office.12).aspx
CTOfficeArtExtension ext = extLst.addNewExt(); CTOfficeArtExtension ext = extLst.addNewExt();
ext.setUri("{63B3BB69-23CF-44E3-9099-C40C66FF867C}"); ext.setUri("{63B3BB69-23CF-44E3-9099-C40C66FF867C}");
XmlCursor cur = ext.newCursor();
try {
try (XmlCursor cur = ext.newCursor()) {
cur.toEndToken(); cur.toEndToken();
cur.beginElement(new QName(drawNS, "compatExt", "a14")); cur.beginElement(new QName(drawNS, "compatExt", "a14"));
cur.insertNamespace("a14", drawNS); cur.insertNamespace("a14", drawNS);
cur.insertAttributeWithValue("spid", "_x0000_s1"); cur.insertAttributeWithValue("spid", "_x0000_s1");
} finally {
cur.dispose();
} }


nv.addNewCNvSpPr(); nv.addNewCNvSpPr();


@Override @Override
public XSSFPictureData getPictureData() { public XSSFPictureData getPictureData() {
XmlCursor cur = getOleObject().newCursor();
try {
try (XmlCursor cur = getOleObject().newCursor()) {
if (cur.toChild(XSSFRelation.NS_SPREADSHEETML, "objectPr")) { if (cur.toChild(XSSFRelation.NS_SPREADSHEETML, "objectPr")) {
String blipId = cur.getAttributeText(new QName(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, "id")); String blipId = cur.getAttributeText(new QName(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, "id"));
return (XSSFPictureData)getSheet().getRelationById(blipId); return (XSSFPictureData)getSheet().getRelationById(blipId);
} }
return null; return null;
} finally {
cur.dispose();
} }
} }



+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java View File

char firstChar = text.charAt(0); char firstChar = text.charAt(0);
char lastChar = text.charAt(text.length() - 1); char lastChar = text.charAt(text.length() - 1);
if(Character.isWhitespace(firstChar) || Character.isWhitespace(lastChar)) { if(Character.isWhitespace(firstChar) || Character.isWhitespace(lastChar)) {
XmlCursor c = xs.newCursor();
try {
try (XmlCursor c = xs.newCursor()) {
c.toNextToken(); c.toNextToken();
c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve"); c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve");
} finally {
c.dispose();
} }
} }
} }

+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java View File



// we use a XmlCursor here to handle oleObject with-/out AlternateContent wrappers // we use a XmlCursor here to handle oleObject with-/out AlternateContent wrappers
String xquery = "declare namespace p='"+XSSFRelation.NS_SPREADSHEETML+"' .//p:oleObject"; String xquery = "declare namespace p='"+XSSFRelation.NS_SPREADSHEETML+"' .//p:oleObject";
XmlCursor cur = getCTWorksheet().getOleObjects().newCursor();
try {
try (XmlCursor cur = getCTWorksheet().getOleObjects().newCursor()) {
cur.selectPath(xquery); cur.selectPath(xquery);
CTOleObject coo = null; CTOleObject coo = null;
while (cur.toNextSelection()) { while (cur.toNextSelection()) {
} }
} }
return coo; return coo;
} finally {
cur.dispose();
} }
} }



+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java View File

List<CTDxf> dxfList = new ArrayList<>(); List<CTDxf> dxfList = new ArrayList<>();


// CT* classes don't handle "mc:AlternateContent" elements, so get the Dxf instances manually // CT* classes don't handle "mc:AlternateContent" elements, so get the Dxf instances manually
final XmlCursor cur = dxfs.newCursor();
try {
try (XmlCursor cur = dxfs.newCursor()) {
// sometimes there are namespaces sometimes not. // sometimes there are namespaces sometimes not.
String xquery = "declare namespace x='"+XSSFRelation.NS_SPREADSHEETML+"' .//x:dxf | .//dxf"; String xquery = "declare namespace x='"+XSSFRelation.NS_SPREADSHEETML+"' .//x:dxf | .//dxf";
cur.selectPath(xquery); cur.selectPath(xquery);
} }
} }
} }
} finally {
cur.dispose();
} }


for (CTTableStyleElement element : tableStyle.getTableStyleElementList()) { for (CTTableStyleElement element : tableStyle.getTableStyleElementList()) {

+ 9
- 38
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java View File

" xmlns=\""+NS_SPREADSHEETML+"\"", "") " xmlns=\""+NS_SPREADSHEETML+"\"", "")
, xopt); , xopt);


XmlCursor cur = root.getXml().newCursor();

try {
try (XmlCursor cur = root.getXml().newCursor()) {
for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) { for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) {
XmlObject xo = cur.getObject(); XmlObject xo = cur.getObject();
if (xo instanceof CTShapetype) { if (xo instanceof CTShapetype) {
} }
} }
} }
} finally {
cur.dispose();
} }
} }


protected List<XmlObject> getItems(){ protected List<XmlObject> getItems(){
List<XmlObject> items = new ArrayList<>(); List<XmlObject> items = new ArrayList<>();


XmlCursor cur = root.getXml().newCursor();
try {
try (XmlCursor cur = root.getXml().newCursor()) {
for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) { for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) {
items.add(cur.getObject()); items.add(cur.getObject());
} }
} finally {
cur.dispose();
} }


return items; return items;
*/ */
private void newDrawing(){ private void newDrawing(){
root = XmlDocument.Factory.newInstance(); root = XmlDocument.Factory.newInstance();
final XmlCursor xml = root.addNewXml().newCursor();
try {
try (final XmlCursor xml = root.addNewXml().newCursor()) {
ShapelayoutDocument layDoc = ShapelayoutDocument.Factory.newInstance(); ShapelayoutDocument layDoc = ShapelayoutDocument.Factory.newInstance();
CTShapeLayout layout = layDoc.addNewShapelayout(); CTShapeLayout layout = layDoc.addNewShapelayout();
layout.setExt(STExt.EDIT); layout.setExt(STExt.EDIT);
idmap.setData("1"); idmap.setData("1");


xml.toEndToken(); xml.toEndToken();
final XmlCursor layCur = layDoc.newCursor();
try {
try (XmlCursor layCur = layDoc.newCursor()) {
layCur.copyXmlContents(xml); layCur.copyXmlContents(xml);
} finally {
layCur.dispose();
} }


CTGroup grp = CTGroup.Factory.newInstance(); CTGroup grp = CTGroup.Factory.newInstance();
path.setConnecttype(STConnectType.RECT); path.setConnecttype(STConnectType.RECT);


xml.toEndToken(); xml.toEndToken();
final XmlCursor grpCur = grp.newCursor();
try {
try (XmlCursor grpCur = grp.newCursor()) {
grpCur.copyXmlContents(xml); grpCur.copyXmlContents(xml);
} finally {
grpCur.dispose();
} }
} finally {
xml.dispose();
} }

} }


/** /**
cldata.addNewRow().setBigIntegerValue(BigInteger.valueOf(0)); cldata.addNewRow().setBigIntegerValue(BigInteger.valueOf(0));
cldata.addNewColumn().setBigIntegerValue(BigInteger.valueOf(0)); cldata.addNewColumn().setBigIntegerValue(BigInteger.valueOf(0));


XmlCursor xml = root.getXml().newCursor();
try {
try (final XmlCursor xml = root.getXml().newCursor()){
xml.toEndToken(); xml.toEndToken();
XmlCursor grpCur = grp.newCursor();
try {
try (final XmlCursor grpCur = grp.newCursor()){
grpCur.copyXmlContents(xml); grpCur.copyXmlContents(xml);
xml.toPrevSibling(); xml.toPrevSibling();
shape = (CTShape)xml.getObject(); shape = (CTShape)xml.getObject();
} finally {
grpCur.dispose();
} }
} finally {
xml.dispose();
} }


return shape; return shape;
* @return the comment shape or <code>null</code> * @return the comment shape or <code>null</code>
*/ */
public CTShape findCommentShape(int row, int col){ public CTShape findCommentShape(int row, int col){
XmlCursor cur = root.getXml().newCursor();
try {
try (final XmlCursor cur = root.getXml().newCursor()){
for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) { for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) {
XmlObject itm = cur.getObject(); XmlObject itm = cur.getObject();
if (matchCommentShape(itm, row, col)) { if (matchCommentShape(itm, row, col)) {
return (CTShape)itm; return (CTShape)itm;
} }
} }
} finally {
cur.dispose();
} }
return null; return null;
} }
} }


protected boolean removeCommentShape(int row, int col){ protected boolean removeCommentShape(int row, int col){
XmlCursor cur = root.getXml().newCursor();
try {
try (final XmlCursor cur = root.getXml().newCursor()) {
for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) { for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) {
XmlObject itm = cur.getObject(); XmlObject itm = cur.getObject();
if (matchCommentShape(itm, row, col)) { if (matchCommentShape(itm, row, col)) {
return true; return true;
} }
} }
} finally {
cur.dispose();
} }
return false; return false;
} }

+ 3
- 9
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java View File

* @param prefix the prefix of the password attributes, may be null * @param prefix the prefix of the password attributes, may be null
*/ */
public static void setPassword(XmlObject xobj, String password, HashAlgorithm hashAlgo, String prefix) { public static void setPassword(XmlObject xobj, String password, HashAlgorithm hashAlgo, String prefix) {
XmlCursor cur = xobj.newCursor();
try {
try (final XmlCursor cur = xobj.newCursor()) {
if (password == null) { if (password == null) {
cur.removeAttribute(getAttrName(prefix, "password")); cur.removeAttribute(getAttrName(prefix, "password"));
cur.removeAttribute(getAttrName(prefix, "algorithmName")); cur.removeAttribute(getAttrName(prefix, "algorithmName"));
cur.insertAttributeWithValue(getAttrName(prefix, "saltValue"), enc64.encodeToString(salt)); cur.insertAttributeWithValue(getAttrName(prefix, "saltValue"), enc64.encodeToString(salt));
cur.insertAttributeWithValue(getAttrName(prefix, "spinCount"), ""+spinCount); cur.insertAttributeWithValue(getAttrName(prefix, "spinCount"), ""+spinCount);
} }
} finally {
cur.dispose();
} }
} }


public static boolean validatePassword(XmlObject xobj, String password, String prefix) { public static boolean validatePassword(XmlObject xobj, String password, String prefix) {
// TODO: is "velvetSweatshop" the default password? // TODO: is "velvetSweatshop" the default password?
if (password == null) return false; if (password == null) return false;
XmlCursor cur = xobj.newCursor();
try {

try (final XmlCursor cur = xobj.newCursor()) {
String xorHashVal = cur.getAttributeText(getAttrName(prefix, "password")); String xorHashVal = cur.getAttributeText(getAttrName(prefix, "password"));
String algoName = cur.getAttributeText(getAttrName(prefix, "algorithmName")); String algoName = cur.getAttributeText(getAttrName(prefix, "algorithmName"));
String hashVal = cur.getAttributeText(getAttrName(prefix, "hashValue")); String hashVal = cur.getAttributeText(getAttrName(prefix, "hashValue"));
byte[] hash2 = CryptoFunctions.hashPassword(password, hashAlgo, salt, spinCnt, false); byte[] hash2 = CryptoFunctions.hashPassword(password, hashAlgo, salt, spinCnt, false);
return Arrays.equals(hash1, hash2); return Arrays.equals(hash1, hash2);
} }
} finally {
cur.dispose();
} }
} }

+ 46
- 52
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComment.java View File

} }


protected void init() { protected void init() {
XmlCursor cursor = ctComment.newCursor();
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, this);
bodyElements.add(p);
paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
bodyElements.add(t);
tables.add(t);
} else if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
bodyElements.add(c);
}
try (XmlCursor cursor = ctComment.newCursor()) {
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, this);
bodyElements.add(p);
paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
bodyElements.add(t);
tables.add(t);
} else if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
bodyElements.add(c);
}


}
} }
cursor.dispose();
} }


/** /**
paragraphs.add(pos, newP); paragraphs.add(pos, newP);
} }
int i = 0; int i = 0;
XmlCursor p2 = p.newCursor();
cursor.toCursor(p2);
p2.dispose();
try (XmlCursor p2 = p.newCursor()) {
cursor.toCursor(p2);
}
while (cursor.toPrevSibling()) { while (cursor.toPrevSibling()) {
o = cursor.getObject(); o = cursor.getObject();
if (o instanceof CTP || o instanceof CTTbl) if (o instanceof CTP || o instanceof CTTbl)
i++; i++;
} }
bodyElements.add(i, newP); bodyElements.add(i, newP);
p2 = p.newCursor();
cursor.toCursor(p2);
cursor.toEndToken();
p2.dispose();
try (XmlCursor p2 = p.newCursor()) {
cursor.toCursor(p2);
cursor.toEndToken();
}
return newP; return newP;
} }
return null; return null;
} }


private boolean isCursorInCmt(XmlCursor cursor) { private boolean isCursorInCmt(XmlCursor cursor) {
XmlCursor verify = cursor.newCursor();
verify.toParent();
boolean result = (verify.getObject() == this.ctComment);
verify.dispose();
return result;
try (XmlCursor verify = cursor.newCursor()) {
verify.toParent();
return (verify.getObject() == this.ctComment);
}
} }


@Override @Override
tables.add(pos, newT); tables.add(pos, newT);
} }
int i = 0; int i = 0;
XmlCursor cursor2 = t.newCursor();
while (cursor2.toPrevSibling()) {
o = cursor2.getObject();
if (o instanceof CTP || o instanceof CTTbl) {
i++;
try (XmlCursor cursor2 = t.newCursor()) {
while (cursor2.toPrevSibling()) {
o = cursor2.getObject();
if (o instanceof CTP || o instanceof CTTbl) {
i++;
}
} }
} }
cursor2.dispose();
bodyElements.add(i, newT); bodyElements.add(i, newT);
cursor2 = t.newCursor();
cursor.toCursor(cursor2);
cursor.toEndToken();
cursor2.dispose();
try (XmlCursor cursor2 = t.newCursor()) {
cursor.toCursor(cursor2);
cursor.toEndToken();
}
return newT; return newT;
} }
return null; return null;
public XWPFTableCell getTableCell(CTTc cell) { public XWPFTableCell getTableCell(CTTc cell) {
XmlObject o; XmlObject o;
CTRow row; CTRow row;
final XmlCursor cursor = cell.newCursor();
try {
try (final XmlCursor cursor = cell.newCursor()) {
cursor.toParent(); cursor.toParent();
o = cursor.getObject(); o = cursor.getObject();
if (!(o instanceof CTRow)) { if (!(o instanceof CTRow)) {
cursor.dispose();
return null; return null;
} }
row = (CTRow) o; row = (CTRow) o;
cursor.toParent(); cursor.toParent();
o = cursor.getObject(); o = cursor.getObject();
} finally {
cursor.dispose();
} }
if (!(o instanceof CTTbl)) { if (!(o instanceof CTTbl)) {
return null; return null;
public void removeParagraph(XWPFParagraph paragraph) { public void removeParagraph(XWPFParagraph paragraph) {
if (paragraphs.contains(paragraph)) { if (paragraphs.contains(paragraph)) {
CTP ctP = paragraph.getCTP(); CTP ctP = paragraph.getCTP();
XmlCursor c = ctP.newCursor();
c.removeXml();
c.dispose();
try (XmlCursor c = ctP.newCursor()) {
c.removeXml();
}
paragraphs.remove(paragraph); paragraphs.remove(paragraph);
bodyElements.remove(paragraph); bodyElements.remove(paragraph);
} }
public void removeTable(XWPFTable table) { public void removeTable(XWPFTable table) {
if (tables.contains(table)) { if (tables.contains(table)) {
CTTbl ctTbl = table.getCTTbl(); CTTbl ctTbl = table.getCTTbl();
XmlCursor c = ctTbl.newCursor();
c.removeXml();
c.dispose();
try (XmlCursor c = ctTbl.newCursor()) {
c.removeXml();
}
tables.remove(table); tables.remove(table);
bodyElements.remove(table); bodyElements.remove(table);
} }
} }


public XWPFTable createTable(int rows, int cols) { public XWPFTable createTable(int rows, int cols) {
XWPFTable table = new XWPFTable(ctComment.addNewTbl(), this, rows,
cols);
XWPFTable table = new XWPFTable(ctComment.addNewTbl(), this, rows, cols);
tables.add(table); tables.add(table);
bodyElements.add(table); bodyElements.add(table);
return table; return table;

+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java View File

public XWPFTableCell getTableCell(CTTc cell) { public XWPFTableCell getTableCell(CTTc cell) {
XmlObject o; XmlObject o;
CTRow row; CTRow row;
final XmlCursor cursor = cell.newCursor();
try {
try (XmlCursor cursor = cell.newCursor()) {
cursor.toParent(); cursor.toParent();
o = cursor.getObject(); o = cursor.getObject();
if (!(o instanceof CTRow)) { if (!(o instanceof CTRow)) {
row = (CTRow) o; row = (CTRow) o;
cursor.toParent(); cursor.toParent();
o = cursor.getObject(); o = cursor.getObject();
} finally {
cursor.dispose();
} }
if (!(o instanceof CTTbl)) { if (!(o instanceof CTTbl)) {
return null; return null;

+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java View File

*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void buildRunsInOrderFromXml(XmlObject object) { private void buildRunsInOrderFromXml(XmlObject object) {
XmlCursor c = object.newCursor();
try {
try (XmlCursor c = object.newCursor()) {
c.selectPath("child::*"); c.selectPath("child::*");
while (c.toNextSelection()) { while (c.toNextSelection()) {
XmlObject o = c.getObject(); XmlObject o = c.getObject();
} }
} }
} }
} finally {
c.dispose();
} }
} }



+ 32
- 32
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java View File

if (sdtRun == null) { if (sdtRun == null) {
return; return;
} }
XmlCursor cursor = sdtRun.newCursor();
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTR) {
XWPFRun run = new XWPFRun((CTR) o, parent);
bodyElements.add(run);
} else if (o instanceof CTSdtRun) {
XWPFSDT c = new XWPFSDT(((CTSdtRun) o), part);
bodyElements.add(c);
try (final XmlCursor cursor = sdtRun.newCursor()) {
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTR) {
XWPFRun run = new XWPFRun((CTR) o, parent);
bodyElements.add(run);
} else if (o instanceof CTSdtRun) {
XWPFSDT c = new XWPFSDT(((CTSdtRun) o), part);
bodyElements.add(c);
}
} }
} }
cursor.dispose();
} }


public XWPFSDTContent(CTSdtContentBlock block, IBody part, IRunBody parent) { public XWPFSDTContent(CTSdtContentBlock block, IBody part, IRunBody parent) {
if (block == null) { if (block == null) {
return; return;
} }
XmlCursor cursor = block.newCursor();
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, part);
bodyElements.add(p);
// paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, part);
bodyElements.add(t);
// tables.add(t);
} else if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT(((CTSdtBlock) o), part);
bodyElements.add(c);
// contentControls.add(c);
} else if (o instanceof CTR) {
XWPFRun run = new XWPFRun((CTR) o, parent);
// runs.add(run);
bodyElements.add(run);
try (final XmlCursor cursor = block.newCursor()) {
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, part);
bodyElements.add(p);
// paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, part);
bodyElements.add(t);
// tables.add(t);
} else if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT(((CTSdtBlock) o), part);
bodyElements.add(c);
// contentControls.add(c);
} else if (o instanceof CTR) {
XWPFRun run = new XWPFRun((CTR) o, parent);
// runs.add(run);
bodyElements.add(run);
}
} }
} }
cursor.dispose();
} }


@Override @Override

+ 35
- 37
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContentCell.java View File

return; return;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
XmlCursor cursor = sdtContentCell.newCursor();

//keep track of the following,
//and add "\n" only before the start of a body
//element if it is not the first body element.

//index of cell in row
int tcCnt = 0;
//count of body objects
int iBodyCnt = 0;
int depth = 1;

while (cursor.hasNextToken() && depth > 0) {
TokenType t = cursor.toNextToken();
if (t.isText()) {
sb.append(cursor.getTextValue());
} else if (isStartToken(cursor, "tr")) {
tcCnt = 0;
iBodyCnt = 0;
} else if (isStartToken(cursor, "tc")) {
if (tcCnt++ > 0) {
sb.append("\t");
try (final XmlCursor cursor = sdtContentCell.newCursor()) {
//keep track of the following,
//and add "\n" only before the start of a body
//element if it is not the first body element.

//index of cell in row
int tcCnt = 0;
//count of body objects
int iBodyCnt = 0;
int depth = 1;

while (cursor.hasNextToken() && depth > 0) {
TokenType t = cursor.toNextToken();
if (t.isText()) {
sb.append(cursor.getTextValue());
} else if (isStartToken(cursor, "tr")) {
tcCnt = 0;
iBodyCnt = 0;
} else if (isStartToken(cursor, "tc")) {
if (tcCnt++ > 0) {
sb.append("\t");
}
iBodyCnt = 0;
} else if (isStartToken(cursor, "p") ||
isStartToken(cursor, "tbl") ||
isStartToken(cursor, "sdt")) {
if (iBodyCnt > 0) {
sb.append("\n");
}
iBodyCnt++;
} }
iBodyCnt = 0;
} else if (isStartToken(cursor, "p") ||
isStartToken(cursor, "tbl") ||
isStartToken(cursor, "sdt")) {
if (iBodyCnt > 0) {
sb.append("\n");
if (cursor.isStart()) {
depth++;
} else if (cursor.isEnd()) {
depth--;
} }
iBodyCnt++;
}
if (cursor.isStart()) {
depth++;
} else if (cursor.isEnd()) {
depth--;
} }
text = sb.toString();
} }
text = sb.toString();
cursor.dispose();
} }



private boolean isStartToken(XmlCursor cursor, String string) { private boolean isStartToken(XmlCursor cursor, String string) {
if (!cursor.isStart()) { if (!cursor.isStart()) {
return false; return false;

+ 7
- 28
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java View File

paragraphs = new ArrayList<>(); paragraphs = new ArrayList<>();
tables = new ArrayList<>(); tables = new ArrayList<>();


XmlCursor cursor = ctTc.newCursor();
try {
try (XmlCursor cursor = ctTc.newCursor()) {
cursor.selectPath("./*"); cursor.selectPath("./*");
while (cursor.toNextSelection()) { while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject(); XmlObject o = cursor.getObject();
bodyElements.add(c); bodyElements.add(c);
} }
} }
} finally {
cursor.dispose();
} }
} }


paragraphs.add(pos, newP); paragraphs.add(pos, newP);
} }
int i = 0; int i = 0;
final XmlCursor p2 = p.newCursor();
try {
try (XmlCursor p2 = p.newCursor()) {
cursor.toCursor(p2); cursor.toCursor(p2);
} finally {
p2.dispose();
} }
while (cursor.toPrevSibling()) { while (cursor.toPrevSibling()) {
o = cursor.getObject(); o = cursor.getObject();
i++; i++;
} }
bodyElements.add(i, newP); bodyElements.add(i, newP);
final XmlCursor p3 = p.newCursor();
try {
try (XmlCursor p3 = p.newCursor()) {
cursor.toCursor(p3); cursor.toCursor(p3);
} finally {
p3.dispose();
} }
cursor.toEndToken(); cursor.toEndToken();
return newP; return newP;
tables.add(pos, newT); tables.add(pos, newT);
} }
int i = 0; int i = 0;
final XmlCursor cursor2 = t.newCursor();
try {
try (XmlCursor cursor2 = t.newCursor()) {
while (cursor2.toPrevSibling()) { while (cursor2.toPrevSibling()) {
o = cursor2.getObject(); o = cursor2.getObject();
if (o instanceof CTP || o instanceof CTTbl) if (o instanceof CTP || o instanceof CTTbl)
i++; i++;
} }
} finally {
cursor2.dispose();
} }
bodyElements.add(i, newT); bodyElements.add(i, newT);
final XmlCursor cursor3 = t.newCursor();
try {
try (XmlCursor cursor3 = t.newCursor()) {
cursor.toCursor(cursor3); cursor.toCursor(cursor3);
cursor.toEndToken(); cursor.toEndToken();
} finally {
cursor3.dispose();
} }
return newT; return newT;
} }
* verifies that cursor is on the right position * verifies that cursor is on the right position
*/ */
private boolean isCursorInTableCell(XmlCursor cursor) { private boolean isCursorInTableCell(XmlCursor cursor) {
XmlCursor verify = cursor.newCursor();
try {
try (XmlCursor verify = cursor.newCursor()) {
verify.toParent(); verify.toParent();
boolean result = (verify.getObject() == this.ctTc); boolean result = (verify.getObject() == this.ctTc);
return result; return result;
} finally {
verify.dispose();
} }
} }


public XWPFTableCell getTableCell(CTTc cell) { public XWPFTableCell getTableCell(CTTc cell) {
XmlObject o; XmlObject o;
CTRow row; CTRow row;
final XmlCursor cursor = cell.newCursor();
try {
try (final XmlCursor cursor = cell.newCursor()) {
cursor.toParent(); cursor.toParent();
o = cursor.getObject(); o = cursor.getObject();
if (!(o instanceof CTRow)) { if (!(o instanceof CTRow)) {
row = (CTRow) o; row = (CTRow) o;
cursor.toParent(); cursor.toParent();
o = cursor.getObject(); o = cursor.getObject();
} finally {
cursor.dispose();
} }
if (!(o instanceof CTTbl)) { if (!(o instanceof CTTbl)) {
return null; return null;

+ 1
- 4
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java View File

List<ICell> cells = new ArrayList<>(); List<ICell> cells = new ArrayList<>();
//Can't use ctRow.getTcList because that only gets table cells //Can't use ctRow.getTcList because that only gets table cells
//Can't use ctRow.getSdtList because that only gets sdts that are at cell level //Can't use ctRow.getSdtList because that only gets sdts that are at cell level
XmlCursor cursor = ctRow.newCursor();
try {
try (XmlCursor cursor = ctRow.newCursor()) {
cursor.selectPath("./*"); cursor.selectPath("./*");
while (cursor.toNextSelection()) { while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject(); XmlObject o = cursor.getObject();
cells.add(new XWPFSDTCell((CTSdtCell) o, this, table.getBody())); cells.add(new XWPFSDTCell((CTSdtCell) o, this, table.getBody()));
} }
} }
} finally {
cursor.dispose();
} }
return cells; return cells;
} }

+ 6
- 7
poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFExamples.java View File

ext.setUri("{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}"); ext.setUri("{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}");


String p14Ns = "http://schemas.microsoft.com/office/powerpoint/2010/main"; String p14Ns = "http://schemas.microsoft.com/office/powerpoint/2010/main";
XmlCursor cur = ext.newCursor();
cur.toEndToken();
cur.beginElement(new QName(p14Ns, "media", "p14"));
cur.insertNamespace("p14", p14Ns);
cur.insertAttributeWithValue(new QName(CORE_PROPERTIES_ECMA376_NS, "link"), prsEmbed1.getId());
cur.dispose();

try (XmlCursor cur = ext.newCursor()) {
cur.toEndToken();
cur.beginElement(new QName(p14Ns, "media", "p14"));
cur.insertNamespace("p14", p14Ns);
cur.insertAttributeWithValue(new QName(CORE_PROPERTIES_ECMA376_NS, "link"), prsEmbed1.getId());
}


CTSlide xslide = slide1.getXmlObject(); CTSlide xslide = slide1.getXmlObject();
CTTimeNodeList ctnl; CTTimeNodeList ctnl;

Loading…
Cancel
Save