Author: fanningpj
Date: Tue Dec 28 10:41:06 2021
New Revision: 1896471
URL: http://svn.apache.org/viewvc?rev=1896471&view=rev
Log:
close cursors in finally blocks
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java?rev=1896471&r1=1896470&r2=1896471&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java
Tue Dec 28 10:41:06 2021
@@ -193,10 +193,13 @@ public final class XSSFGraphicFrame exte
String r_namespaceUri =
STRelationshipId.type.getName().getNamespaceURI();
String c_namespaceUri = XSSFDrawing.NAMESPACE_C;
XmlCursor cursor = data.newCursor();
- cursor.toNextToken();
- cursor.beginElement(new QName(c_namespaceUri, "chart", "c"));
- cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id", "r"),
id);
- cursor.dispose();
+ try {
+ cursor.toNextToken();
+ cursor.beginElement(new QName(c_namespaceUri, "chart", "c"));
+ cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id",
"r"), id);
+ } finally {
+ cursor.dispose();
+ }
data.setUri(c_namespaceUri);
}
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java?rev=1896471&r1=1896470&r2=1896471&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
Tue Dec 28 10:41:06 2021
@@ -83,11 +83,14 @@ public class XSSFObjectData extends XSSF
CTOfficeArtExtension ext = extLst.addNewExt();
ext.setUri("{63B3BB69-23CF-44E3-9099-C40C66FF867C}");
XmlCursor cur = ext.newCursor();
- cur.toEndToken();
- cur.beginElement(new QName(drawNS, "compatExt", "a14"));
- cur.insertNamespace("a14", drawNS);
- cur.insertAttributeWithValue("spid", "_x0000_s1");
- cur.dispose();
+ try {
+ cur.toEndToken();
+ cur.beginElement(new QName(drawNS, "compatExt", "a14"));
+ cur.insertNamespace("a14", drawNS);
+ cur.insertAttributeWithValue("spid", "_x0000_s1");
+ } finally {
+ cur.dispose();
+ }
nv.addNewCNvSpPr();
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java?rev=1896471&r1=1896470&r2=1896471&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
Tue Dec 28 10:41:06 2021
@@ -490,9 +490,12 @@ public class XSSFRichTextString implemen
char lastChar = text.charAt(text.length() - 1);
if(Character.isWhitespace(firstChar) ||
Character.isWhitespace(lastChar)) {
XmlCursor c = xs.newCursor();
- c.toNextToken();
- c.insertAttributeWithValue(new
QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve");
- c.dispose();
+ try {
+ c.toNextToken();
+ c.insertAttributeWithValue(new
QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve");
+ } finally {
+ c.dispose();
+ }
}
}
}
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java?rev=1896471&r1=1896470&r2=1896471&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java
Tue Dec 28 10:41:06 2021
@@ -59,27 +59,31 @@ public class XSSFTableStyle implements T
List<CTDxf> dxfList = new ArrayList<>();
// CT* classes don't handle "mc:AlternateContent" elements, so get the
Dxf instances manually
- XmlCursor cur = dxfs.newCursor();
- // sometimes there are namespaces sometimes not.
- String xquery = "declare namespace
x='"+XSSFRelation.NS_SPREADSHEETML+"' .//x:dxf | .//dxf";
- cur.selectPath(xquery);
- while (cur.toNextSelection()) {
- XmlObject obj = cur.getObject();
- String parentName = obj.getDomNode().getParentNode().getNodeName();
- // ignore alternate content choices, we won't know anything about
their namespaces
- if (parentName.equals("mc:Fallback") ||
parentName.equals("x:dxfs") || parentName.contentEquals("dxfs")) {
- CTDxf dxf;
- try {
- if (obj instanceof CTDxf) {
- dxf = (CTDxf) obj;
- } else {
- dxf = CTDxf.Factory.parse(obj.newXMLStreamReader(),
new XmlOptions().setDocumentType(CTDxf.type));
+ final XmlCursor cur = dxfs.newCursor();
+ try {
+ // sometimes there are namespaces sometimes not.
+ String xquery = "declare namespace
x='"+XSSFRelation.NS_SPREADSHEETML+"' .//x:dxf | .//dxf";
+ cur.selectPath(xquery);
+ while (cur.toNextSelection()) {
+ XmlObject obj = cur.getObject();
+ String parentName =
obj.getDomNode().getParentNode().getNodeName();
+ // ignore alternate content choices, we won't know anything
about their namespaces
+ if (parentName.equals("mc:Fallback") ||
parentName.equals("x:dxfs") || parentName.contentEquals("dxfs")) {
+ CTDxf dxf;
+ try {
+ if (obj instanceof CTDxf) {
+ dxf = (CTDxf) obj;
+ } else {
+ dxf =
CTDxf.Factory.parse(obj.newXMLStreamReader(), new
XmlOptions().setDocumentType(CTDxf.type));
+ }
+ if (dxf != null) dxfList.add(dxf);
+ } catch (XmlException e) {
+ LOG.atWarn().withThrowable(e).log("Error parsing
XSSFTableStyle");
}
- if (dxf != null) dxfList.add(dxf);
- } catch (XmlException e) {
- LOG.atWarn().withThrowable(e).log("Error parsing
XSSFTableStyle");
}
}
+ } finally {
+ cur.dispose();
}
for (CTTableStyleElement element :
tableStyle.getTableStyleElementList()) {
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java?rev=1896471&r1=1896470&r2=1896471&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
Tue Dec 28 10:41:06 2021
@@ -207,36 +207,46 @@ public final class XSSFVMLDrawing extend
*/
private void newDrawing(){
root = XmlDocument.Factory.newInstance();
- XmlCursor xml = root.addNewXml().newCursor();
+ final XmlCursor xml = root.addNewXml().newCursor();
+ try {
+ ShapelayoutDocument layDoc =
ShapelayoutDocument.Factory.newInstance();
+ CTShapeLayout layout = layDoc.addNewShapelayout();
+ layout.setExt(STExt.EDIT);
+ CTIdMap idmap = layout.addNewIdmap();
+ idmap.setExt(STExt.EDIT);
+ idmap.setData("1");
+
+ xml.toEndToken();
+ final XmlCursor layCur = layDoc.newCursor();
+ try {
+ layCur.copyXmlContents(xml);
+ } finally {
+ layCur.dispose();
+ }
- ShapelayoutDocument layDoc = ShapelayoutDocument.Factory.newInstance();
- CTShapeLayout layout = layDoc.addNewShapelayout();
- layout.setExt(STExt.EDIT);
- CTIdMap idmap = layout.addNewIdmap();
- idmap.setExt(STExt.EDIT);
- idmap.setData("1");
-
- xml.toEndToken();
- XmlCursor layCur = layDoc.newCursor();
- layCur.copyXmlContents(xml);
- layCur.dispose();
+ CTGroup grp = CTGroup.Factory.newInstance();
+ CTShapetype shapetype = grp.addNewShapetype();
+ _shapeTypeId = COMMENT_SHAPE_TYPE_ID;
+ shapetype.setId(_shapeTypeId);
+ shapetype.setCoordsize("21600,21600");
+ shapetype.setSpt(202);
+ shapetype.setPath2("m,l,21600r21600,l21600,xe");
+ shapetype.addNewStroke().setJoinstyle(STStrokeJoinStyle.MITER);
+ CTPath path = shapetype.addNewPath();
+ path.setGradientshapeok(STTrueFalse.T);
+ path.setConnecttype(STConnectType.RECT);
+
+ xml.toEndToken();
+ final XmlCursor grpCur = grp.newCursor();
+ try {
+ grpCur.copyXmlContents(xml);
+ } finally {
+ grpCur.dispose();
+ }
+ } finally {
+ xml.dispose();
+ }
- CTGroup grp = CTGroup.Factory.newInstance();
- CTShapetype shapetype = grp.addNewShapetype();
- _shapeTypeId = COMMENT_SHAPE_TYPE_ID;
- shapetype.setId(_shapeTypeId);
- shapetype.setCoordsize("21600,21600");
- shapetype.setSpt(202);
- shapetype.setPath2("m,l,21600r21600,l21600,xe");
- shapetype.addNewStroke().setJoinstyle(STStrokeJoinStyle.MITER);
- CTPath path = shapetype.addNewPath();
- path.setGradientshapeok(STTrueFalse.T);
- path.setConnecttype(STConnectType.RECT);
-
- xml.toEndToken();
- XmlCursor grpCur = grp.newCursor();
- grpCur.copyXmlContents(xml);
- grpCur.dispose();
}
/**
@@ -269,13 +279,19 @@ public final class XSSFVMLDrawing extend
cldata.addNewColumn().setBigIntegerValue(BigInteger.valueOf(0));
XmlCursor xml = root.getXml().newCursor();
- xml.toEndToken();
- XmlCursor grpCur = grp.newCursor();
- grpCur.copyXmlContents(xml);
- xml.toPrevSibling();
- shape = (CTShape)xml.getObject();
- grpCur.dispose();
- xml.dispose();
+ try {
+ xml.toEndToken();
+ XmlCursor grpCur = grp.newCursor();
+ try {
+ grpCur.copyXmlContents(xml);
+ xml.toPrevSibling();
+ shape = (CTShape)xml.getObject();
+ } finally {
+ grpCur.dispose();
+ }
+ } finally {
+ xml.dispose();
+ }
return shape;
}
@@ -287,11 +303,15 @@ public final class XSSFVMLDrawing extend
*/
public CTShape findCommentShape(int row, int col){
XmlCursor cur = root.getXml().newCursor();
- for (boolean found = cur.toFirstChild(); found; found =
cur.toNextSibling()) {
- XmlObject itm = cur.getObject();
- if (matchCommentShape(itm, row, col)) {
- return (CTShape)itm;
+ try {
+ for (boolean found = cur.toFirstChild(); found; found =
cur.toNextSibling()) {
+ XmlObject itm = cur.getObject();
+ if (matchCommentShape(itm, row, col)) {
+ return (CTShape)itm;
+ }
}
+ } finally {
+ cur.dispose();
}
return null;
}
@@ -318,12 +338,16 @@ public final class XSSFVMLDrawing extend
protected boolean removeCommentShape(int row, int col){
XmlCursor cur = root.getXml().newCursor();
- for (boolean found = cur.toFirstChild(); found; found =
cur.toNextSibling()) {
- XmlObject itm = cur.getObject();
- if (matchCommentShape(itm, row, col)) {
- cur.removeXml();
- return true;
+ try {
+ for (boolean found = cur.toFirstChild(); found; found =
cur.toNextSibling()) {
+ XmlObject itm = cur.getObject();
+ if (matchCommentShape(itm, row, col)) {
+ cur.removeXml();
+ return true;
+ }
}
+ } finally {
+ cur.dispose();
}
return false;
}
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java?rev=1896471&r1=1896470&r2=1896471&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java
Tue Dec 28 10:41:06 2021
@@ -50,41 +50,43 @@ public final class XSSFPasswordHelper {
*/
public static void setPassword(XmlObject xobj, String password,
HashAlgorithm hashAlgo, String prefix) {
XmlCursor cur = xobj.newCursor();
+ try {
+ if (password == null) {
+ cur.removeAttribute(getAttrName(prefix, "password"));
+ cur.removeAttribute(getAttrName(prefix, "algorithmName"));
+ cur.removeAttribute(getAttrName(prefix, "hashValue"));
+ cur.removeAttribute(getAttrName(prefix, "saltValue"));
+ cur.removeAttribute(getAttrName(prefix, "spinCount"));
+ return;
+ }
- if (password == null) {
- cur.removeAttribute(getAttrName(prefix, "password"));
- cur.removeAttribute(getAttrName(prefix, "algorithmName"));
- cur.removeAttribute(getAttrName(prefix, "hashValue"));
- cur.removeAttribute(getAttrName(prefix, "saltValue"));
- cur.removeAttribute(getAttrName(prefix, "spinCount"));
- return;
- }
-
- cur.toFirstContentToken();
- if (hashAlgo == null) {
- int hash = CryptoFunctions.createXorVerifier1(password);
- cur.insertAttributeWithValue(getAttrName(prefix, "password"),
- String.format(Locale.ROOT, "%04X",
hash).toUpperCase(Locale.ROOT));
- } else {
- byte[] salt = RandomSingleton.getInstance().generateSeed(16);
-
- // Iterations specifies the number of times the hashing function
shall be iteratively run (using each
- // iteration's result as the input for the next iteration).
- int spinCount = 100000;
-
- // Implementation Notes List:
- // --> In this third stage, the reversed byte order legacy hash
from the second stage shall
- // be converted to Unicode hex string representation
- byte[] hash = CryptoFunctions.hashPassword(password, hashAlgo,
salt, spinCount, false);
-
- Base64.Encoder enc64 = Base64.getEncoder();
-
- cur.insertAttributeWithValue(getAttrName(prefix, "algorithmName"),
hashAlgo.jceId);
- cur.insertAttributeWithValue(getAttrName(prefix, "hashValue"),
enc64.encodeToString(hash));
- cur.insertAttributeWithValue(getAttrName(prefix, "saltValue"),
enc64.encodeToString(salt));
- cur.insertAttributeWithValue(getAttrName(prefix, "spinCount"),
""+spinCount);
+ cur.toFirstContentToken();
+ if (hashAlgo == null) {
+ int hash = CryptoFunctions.createXorVerifier1(password);
+ cur.insertAttributeWithValue(getAttrName(prefix, "password"),
+ String.format(Locale.ROOT, "%04X",
hash).toUpperCase(Locale.ROOT));
+ } else {
+ byte[] salt = RandomSingleton.getInstance().generateSeed(16);
+
+ // Iterations specifies the number of times the hashing
function shall be iteratively run (using each
+ // iteration's result as the input for the next iteration).
+ int spinCount = 100000;
+
+ // Implementation Notes List:
+ // --> In this third stage, the reversed byte order legacy
hash from the second stage shall
+ // be converted to Unicode hex string representation
+ byte[] hash = CryptoFunctions.hashPassword(password, hashAlgo,
salt, spinCount, false);
+
+ Base64.Encoder enc64 = Base64.getEncoder();
+
+ cur.insertAttributeWithValue(getAttrName(prefix,
"algorithmName"), hashAlgo.jceId);
+ cur.insertAttributeWithValue(getAttrName(prefix, "hashValue"),
enc64.encodeToString(hash));
+ cur.insertAttributeWithValue(getAttrName(prefix, "saltValue"),
enc64.encodeToString(salt));
+ cur.insertAttributeWithValue(getAttrName(prefix, "spinCount"),
""+spinCount);
+ }
+ } finally {
+ cur.dispose();
}
- cur.dispose();
}
/**
@@ -103,30 +105,32 @@ public final class XSSFPasswordHelper {
if (password == null) return false;
XmlCursor cur = xobj.newCursor();
- String xorHashVal = cur.getAttributeText(getAttrName(prefix,
"password"));
- String algoName = cur.getAttributeText(getAttrName(prefix,
"algorithmName"));
- String hashVal = cur.getAttributeText(getAttrName(prefix,
"hashValue"));
- String saltVal = cur.getAttributeText(getAttrName(prefix,
"saltValue"));
- String spinCount = cur.getAttributeText(getAttrName(prefix,
"spinCount"));
- cur.dispose();
-
- if (xorHashVal != null) {
- int hash1 = Integer.parseInt(xorHashVal, 16);
- int hash2 = CryptoFunctions.createXorVerifier1(password);
- return hash1 == hash2;
- } else {
- if (hashVal == null || algoName == null || saltVal == null ||
spinCount == null) {
- return false;
+ try {
+ String xorHashVal = cur.getAttributeText(getAttrName(prefix,
"password"));
+ String algoName = cur.getAttributeText(getAttrName(prefix,
"algorithmName"));
+ String hashVal = cur.getAttributeText(getAttrName(prefix,
"hashValue"));
+ String saltVal = cur.getAttributeText(getAttrName(prefix,
"saltValue"));
+ String spinCount = cur.getAttributeText(getAttrName(prefix,
"spinCount"));
+ if (xorHashVal != null) {
+ int hash1 = Integer.parseInt(xorHashVal, 16);
+ int hash2 = CryptoFunctions.createXorVerifier1(password);
+ return hash1 == hash2;
+ } else {
+ if (hashVal == null || algoName == null || saltVal == null ||
spinCount == null) {
+ return false;
+ }
+
+ Base64.Decoder dec64 = Base64.getDecoder();
+
+ byte[] hash1 = dec64.decode(hashVal);
+ HashAlgorithm hashAlgo = HashAlgorithm.fromString(algoName);
+ byte[] salt = dec64.decode(saltVal);
+ int spinCnt = Integer.parseInt(spinCount);
+ byte[] hash2 = CryptoFunctions.hashPassword(password,
hashAlgo, salt, spinCnt, false);
+ return Arrays.equals(hash1, hash2);
}
-
- Base64.Decoder dec64 = Base64.getDecoder();
-
- byte[] hash1 = dec64.decode(hashVal);
- HashAlgorithm hashAlgo = HashAlgorithm.fromString(algoName);
- byte[] salt = dec64.decode(saltVal);
- int spinCnt = Integer.parseInt(spinCount);
- byte[] hash2 = CryptoFunctions.hashPassword(password, hashAlgo,
salt, spinCnt, false);
- return Arrays.equals(hash1, hash2);
+ } finally {
+ cur.dispose();
}
}
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java?rev=1896471&r1=1896470&r2=1896471&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java
Tue Dec 28 10:41:06 2021
@@ -73,26 +73,29 @@ public abstract class XWPFAbstractFootno
protected void init() {
XmlCursor cursor = ctFtnEdn.newCursor();
- //copied from XWPFDocument...should centralize this code
- //to avoid duplication
- 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 {
+ //copied from XWPFDocument...should centralize this code
+ //to avoid duplication
+ 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);
+ }
+ }
+ } finally {
+ cursor.dispose();
}
- cursor.dispose();
}
/**
@@ -283,10 +286,13 @@ public abstract class XWPFAbstractFootno
*/
private boolean isCursorInFtn(XmlCursor cursor) {
XmlCursor verify = cursor.newCursor();
- verify.toParent();
- boolean result = (verify.getObject() == this.ctFtnEdn);
- verify.dispose();
- return result;
+ try {
+ verify.toParent();
+ return (verify.getObject() == this.ctFtnEdn);
+ } finally {
+ verify.dispose();
+
+ }
}
/**
@@ -331,9 +337,12 @@ public abstract class XWPFAbstractFootno
}
bodyElements.add(i, newT);
XmlCursor c2 = t.newCursor();
- cursor.toCursor(c2);
- cursor.toEndToken();
- c2.dispose();
+ try {
+ cursor.toCursor(c2);
+ cursor.toEndToken();
+ } finally {
+ c2.dispose();
+ }
return newT;
}
return null;
@@ -365,8 +374,11 @@ public abstract class XWPFAbstractFootno
}
int i = 0;
XmlCursor p2 = p.newCursor();
- cursor.toCursor(p2);
- p2.dispose();
+ try {
+ cursor.toCursor(p2);
+ } finally {
+ p2.dispose();
+ }
while (cursor.toPrevSibling()) {
o = cursor.getObject();
if (o instanceof CTP || o instanceof CTTbl)
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java?rev=1896471&r1=1896470&r2=1896471&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java
Tue Dec 28 10:41:06 2021
@@ -48,22 +48,25 @@ public class XWPFFooter extends XWPFHead
public XWPFFooter(XWPFDocument doc, CTHdrFtr hdrFtr) throws IOException {
super(doc, hdrFtr);
XmlCursor cursor = headerFooter.newCursor();
- cursor.selectPath("./*");
- while (cursor.toNextSelection()) {
- XmlObject o = cursor.getObject();
- if (o instanceof CTP) {
- XWPFParagraph p = new XWPFParagraph((CTP) o, this);
- paragraphs.add(p);
- bodyElements.add(p);
- }
- if (o instanceof CTTbl) {
- XWPFTable t = new XWPFTable((CTTbl) o, this);
- tables.add(t);
- bodyElements.add(t);
- }
+ try {
+ cursor.selectPath("./*");
+ while (cursor.toNextSelection()) {
+ XmlObject o = cursor.getObject();
+ if (o instanceof CTP) {
+ XWPFParagraph p = new XWPFParagraph((CTP) o, this);
+ paragraphs.add(p);
+ bodyElements.add(p);
+ }
+ if (o instanceof CTTbl) {
+ XWPFTable t = new XWPFTable((CTTbl) o, this);
+ tables.add(t);
+ bodyElements.add(t);
+ }
+ }
+ } finally {
+ cursor.dispose();
}
- cursor.dispose();
}
/**
@@ -96,25 +99,28 @@ public class XWPFFooter extends XWPFHead
// parse the document with cursor and add
// the XmlObject to its lists
XmlCursor cursor = headerFooter.newCursor();
- cursor.selectPath("./*");
- while (cursor.toNextSelection()) {
- XmlObject o = cursor.getObject();
- if (o instanceof CTP) {
- XWPFParagraph p = new XWPFParagraph((CTP) o, this);
- paragraphs.add(p);
- bodyElements.add(p);
- }
- if (o instanceof CTTbl) {
- XWPFTable t = new XWPFTable((CTTbl) o, this);
- tables.add(t);
- bodyElements.add(t);
- }
- if (o instanceof CTSdtBlock) {
- XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
- bodyElements.add(c);
+ try {
+ cursor.selectPath("./*");
+ while (cursor.toNextSelection()) {
+ XmlObject o = cursor.getObject();
+ if (o instanceof CTP) {
+ XWPFParagraph p = new XWPFParagraph((CTP) o, this);
+ paragraphs.add(p);
+ bodyElements.add(p);
+ }
+ if (o instanceof CTTbl) {
+ XWPFTable t = new XWPFTable((CTTbl) o, this);
+ tables.add(t);
+ bodyElements.add(t);
+ }
+ if (o instanceof CTSdtBlock) {
+ XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
+ bodyElements.add(c);
+ }
}
+ } finally {
+ cursor.dispose();
}
- cursor.dispose();
} catch (Exception e) {
throw new POIXMLException(e);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]