Browse Source

close cursors in finally blocks

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896472 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_0
PJ Fanning 2 years ago
parent
commit
70dc07dd3b

+ 27
- 14
poi-examples/src/main/java/org/apache/poi/examples/ss/LoadEmbedded.java View File

@@ -101,33 +101,46 @@ public final class LoadEmbedded {
String contentType = pPart.getContentType();
if (contentType.equals("application/vnd.ms-excel")) {
// Excel Workbook - either binary or OpenXML
HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(pPart.getInputStream());
embeddedWorkbook.close();
try (InputStream stream = pPart.getInputStream()) {
HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(stream);
embeddedWorkbook.close();
}
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
// Excel Workbook - OpenXML file format
XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(pPart.getInputStream());
embeddedWorkbook.close();
try (InputStream stream = pPart.getInputStream()) {
XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(stream);
embeddedWorkbook.close();
}
} else if (contentType.equals("application/msword")) {
// Word Document - binary (OLE2CDF) file format
HWPFDocument document = new HWPFDocument(pPart.getInputStream());
document.close();
try (InputStream stream = pPart.getInputStream()) {
HWPFDocument document = new HWPFDocument(stream);
document.close();
}
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
// Word Document - OpenXML file format
XWPFDocument document = new XWPFDocument(pPart.getInputStream());
document.close();
try (InputStream stream = pPart.getInputStream()) {
XWPFDocument document = new XWPFDocument(stream);
document.close();
}
} else if (contentType.equals("application/vnd.ms-powerpoint")) {
// PowerPoint Document - binary file format
HSLFSlideShow slideShow = new HSLFSlideShow(pPart.getInputStream());
slideShow.close();
try (InputStream stream = pPart.getInputStream()) {
HSLFSlideShow slideShow = new HSLFSlideShow(stream);
slideShow.close();
}
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
// PowerPoint Document - OpenXML file format
XMLSlideShow slideShow = new XMLSlideShow(pPart.getInputStream());
slideShow.close();
try (InputStream stream = pPart.getInputStream()) {
XMLSlideShow slideShow = new XMLSlideShow(stream);
slideShow.close();
}
} else {
// Any other type of embedded object.
System.out.println("Unknown Embedded Document: " + contentType);
InputStream inputStream = pPart.getInputStream();
inputStream.close();
try (InputStream inputStream = pPart.getInputStream()) {

}
}
}
}

+ 10
- 8
poi-examples/src/main/java/org/apache/poi/examples/xslf/AddVideoToPptx.java.txt View File

@@ -166,14 +166,16 @@ public class AddVideoToPptx {
ext.setUri("{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}");
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(STRelationshipId.type.getName().getNamespaceURI(), "embed"), prsEmbed1.getId());
cur.beginElement(new QName(p14Ns, "trim", "p14"));
cur.insertAttributeWithValue("st", df_time.format(seconds*1000.0));
cur.dispose();
try {
cur.toEndToken();
cur.beginElement(new QName(p14Ns, "media", "p14"));
cur.insertNamespace("p14", p14Ns);
cur.insertAttributeWithValue(new QName(STRelationshipId.type.getName().getNamespaceURI(), "embed"), prsEmbed1.getId());
cur.beginElement(new QName(p14Ns, "trim", "p14"));
cur.insertAttributeWithValue("st", df_time.format(seconds*1000.0));
} finally {
cur.dispose();
}
}
static void addTimingInfo(XSLFSlide slide1, XSLFPictureShape pic1) {

+ 8
- 6
poi-examples/src/main/java/org/apache/poi/examples/xslf/LinkVideoToPptx.java View File

@@ -85,12 +85,14 @@ public final class LinkVideoToPptx {

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 {
cur.toEndToken();
cur.beginElement(new QName(p14Ns, "media", "p14"));
cur.insertNamespace("p14", p14Ns);
cur.insertAttributeWithValue(new QName(CORE_PROPERTIES_ECMA376_NS, "link"), prsEmbed1.getId());
} finally {
cur.dispose();
}

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

Loading…
Cancel
Save