From 369681f7f9c08124b7af2d75cf531aa08646bc05 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Wed, 20 Jul 2022 10:56:16 +0000 Subject: [PATCH] use try-with-resources git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902873 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/examples/xslf/AddVideoToPptx.java.txt | 6 ++---- .../java/org/apache/poi/examples/xslf/LinkVideoToPptx.java | 5 +---- .../org/apache/poi/xslf/usermodel/TestXSLFExamples.java | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xslf/AddVideoToPptx.java.txt b/poi-examples/src/main/java/org/apache/poi/examples/xslf/AddVideoToPptx.java.txt index 835fe63d6d..910d264236 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/xslf/AddVideoToPptx.java.txt +++ b/poi-examples/src/main/java/org/apache/poi/examples/xslf/AddVideoToPptx.java.txt @@ -165,16 +165,14 @@ public class AddVideoToPptx { // see http://msdn.microsoft.com/en-us/library/dd950140(v=office.12).aspx ext.setUri("{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}"); String p14Ns = "http://schemas.microsoft.com/office/powerpoint/2010/main"; - XmlCursor cur = ext.newCursor(); - try { + + try (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)); - } finally { - cur.dispose(); } } diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xslf/LinkVideoToPptx.java b/poi-examples/src/main/java/org/apache/poi/examples/xslf/LinkVideoToPptx.java index 265fa730d4..e86cd791e5 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/xslf/LinkVideoToPptx.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/xslf/LinkVideoToPptx.java @@ -84,14 +84,11 @@ public final class LinkVideoToPptx { ext.setUri("{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}"); String p14Ns = "http://schemas.microsoft.com/office/powerpoint/2010/main"; - XmlCursor cur = ext.newCursor(); - try { + 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()); - } finally { - cur.dispose(); } CTSlide xslide = slide1.getXmlObject(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFExamples.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFExamples.java index 3e82f28f0e..71a49d6e0f 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFExamples.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFExamples.java @@ -55,7 +55,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STTLTimeNodeType; */ class TestXSLFExamples { @Test - void LinkVideoToPptx() throws IOException, URISyntaxException { + void linkVideoToPptx() throws IOException, URISyntaxException { String videoFileName = "file_example_MP4_640_3MG.mp4"; File previewJpg = POIDataSamples.getDocumentInstance().getFile("abstract1.jpg"); -- 2.39.5