Eclipse warnings, close resources in CommandLineTextExtractor, add try/finally, formatting, ...
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1701139 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
de46578051
commit
b2bd6a0a4c
@ -27,11 +27,9 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.zip.ZipException;
|
|
||||||
|
|
||||||
import org.apache.poi.POIOLE2TextExtractor;
|
import org.apache.poi.POIOLE2TextExtractor;
|
||||||
import org.apache.poi.POITextExtractor;
|
import org.apache.poi.POITextExtractor;
|
||||||
import org.apache.poi.dev.OOXMLPrettyPrint;
|
|
||||||
import org.apache.poi.extractor.ExtractorFactory;
|
import org.apache.poi.extractor.ExtractorFactory;
|
||||||
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
|
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
|
@ -42,14 +42,18 @@ public class CommandLineTextExtractor {
|
|||||||
|
|
||||||
POITextExtractor extractor =
|
POITextExtractor extractor =
|
||||||
ExtractorFactory.createExtractor(f);
|
ExtractorFactory.createExtractor(f);
|
||||||
POITextExtractor metadataExtractor =
|
try {
|
||||||
extractor.getMetadataTextExtractor();
|
POITextExtractor metadataExtractor =
|
||||||
|
extractor.getMetadataTextExtractor();
|
||||||
|
|
||||||
System.out.println(" " + DIVIDER);
|
System.out.println(" " + DIVIDER);
|
||||||
System.out.println(metadataExtractor.getText());
|
System.out.println(metadataExtractor.getText());
|
||||||
System.out.println(" " + DIVIDER);
|
System.out.println(" " + DIVIDER);
|
||||||
System.out.println(extractor.getText());
|
System.out.println(extractor.getText());
|
||||||
System.out.println(DIVIDER);
|
System.out.println(DIVIDER);
|
||||||
|
} finally {
|
||||||
|
extractor.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ import org.apache.poi.util.TempFile;
|
|||||||
/**
|
/**
|
||||||
* Physical zip package.
|
* Physical zip package.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public final class ZipPackage extends Package {
|
public final class ZipPackage extends Package {
|
||||||
private static POILogger logger = POILogFactory.getLogger(ZipPackage.class);
|
private static POILogger logger = POILogFactory.getLogger(ZipPackage.class);
|
||||||
|
|
||||||
@ -62,7 +63,6 @@ public final class ZipPackage extends Package {
|
|||||||
/**
|
/**
|
||||||
* Constructor. Creates a new, empty ZipPackage.
|
* Constructor. Creates a new, empty ZipPackage.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public ZipPackage() {
|
public ZipPackage() {
|
||||||
super(defaultPackageAccess);
|
super(defaultPackageAccess);
|
||||||
this.zipArchive = null;
|
this.zipArchive = null;
|
||||||
@ -84,7 +84,6 @@ public final class ZipPackage extends Package {
|
|||||||
* If the specified input stream not an instance of
|
* If the specified input stream not an instance of
|
||||||
* ZipInputStream.
|
* ZipInputStream.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
ZipPackage(InputStream in, PackageAccess access) throws IOException {
|
ZipPackage(InputStream in, PackageAccess access) throws IOException {
|
||||||
super(access);
|
super(access);
|
||||||
InputStream zis = new ZipInputStream(in);
|
InputStream zis = new ZipInputStream(in);
|
||||||
@ -102,7 +101,6 @@ public final class ZipPackage extends Package {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If the content type part parsing encounters an error.
|
* If the content type part parsing encounters an error.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
ZipPackage(String path, PackageAccess access) {
|
ZipPackage(String path, PackageAccess access) {
|
||||||
super(access);
|
super(access);
|
||||||
|
|
||||||
@ -128,7 +126,6 @@ public final class ZipPackage extends Package {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If the content type part parsing encounters an error.
|
* If the content type part parsing encounters an error.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
ZipPackage(File file, PackageAccess access) {
|
ZipPackage(File file, PackageAccess access) {
|
||||||
super(access);
|
super(access);
|
||||||
|
|
||||||
@ -156,7 +153,6 @@ public final class ZipPackage extends Package {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If the content type part parsing encounters an error.
|
* If the content type part parsing encounters an error.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
ZipPackage(ZipEntrySource zipEntry, PackageAccess access) {
|
ZipPackage(ZipEntrySource zipEntry, PackageAccess access) {
|
||||||
super(access);
|
super(access);
|
||||||
this.zipArchive = zipEntry;
|
this.zipArchive = zipEntry;
|
||||||
|
@ -917,8 +917,8 @@ public class XSSFCellStyle implements CellStyle {
|
|||||||
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
|
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
|
||||||
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
|
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setBorderRight(short border) {
|
public void setBorderRight(short border) {
|
||||||
CTBorder ct = getCTBorder();
|
CTBorder ct = getCTBorder();
|
||||||
CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
|
CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
|
||||||
if(border == BORDER_NONE) ct.unsetRight();
|
if(border == BORDER_NONE) ct.unsetRight();
|
||||||
|
@ -18,6 +18,8 @@ package org.apache.poi.xslf.usermodel;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.sl.usermodel.*;
|
import org.apache.poi.sl.usermodel.*;
|
||||||
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
|
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
|
||||||
import org.apache.poi.sl.usermodel.TextShape.TextAutofit;
|
import org.apache.poi.sl.usermodel.TextShape.TextAutofit;
|
||||||
@ -32,7 +34,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
|
|||||||
*/
|
*/
|
||||||
public class TestXSLFAutoShape {
|
public class TestXSLFAutoShape {
|
||||||
@Test
|
@Test
|
||||||
public void testTextBodyProperies() {
|
public void testTextBodyProperies() throws IOException {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
@ -102,10 +104,12 @@ public class TestXSLFAutoShape {
|
|||||||
assertEquals(TextDirection.VERTICAL, shape.getTextDirection());
|
assertEquals(TextDirection.VERTICAL, shape.getTextDirection());
|
||||||
shape.setTextDirection(null);
|
shape.setTextDirection(null);
|
||||||
assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
|
assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTextParagraph() {
|
public void testTextParagraph() throws IOException {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
assertTrue(slide.getShapes().isEmpty());
|
assertTrue(slide.getShapes().isEmpty());
|
||||||
@ -202,10 +206,12 @@ public class TestXSLFAutoShape {
|
|||||||
p.setTextAlign(null);
|
p.setTextAlign(null);
|
||||||
assertEquals(TextAlign.LEFT, p.getTextAlign());
|
assertEquals(TextAlign.LEFT, p.getTextAlign());
|
||||||
assertFalse(p.getXmlObject().getPPr().isSetAlgn());
|
assertFalse(p.getXmlObject().getPPr().isSetAlgn());
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTextRun() {
|
public void testTextRun() throws IOException {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
@ -272,10 +278,12 @@ public class TestXSLFAutoShape {
|
|||||||
assertEquals("POI", r.getRawText());
|
assertEquals("POI", r.getRawText());
|
||||||
r.setText(null);
|
r.setText(null);
|
||||||
assertNull(r.getRawText());
|
assertNull(r.getRawText());
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testShapeType() {
|
public void testShapeType() throws IOException {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
@ -290,5 +298,7 @@ public class TestXSLFAutoShape {
|
|||||||
shape.setShapeType(tp);
|
shape.setShapeType(tp);
|
||||||
assertEquals(tp, shape.getShapeType());
|
assertEquals(tp, shape.getShapeType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2381,9 +2381,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
// using temp file instead of ByteArrayOutputStream because of OOM in gump run
|
// using temp file instead of ByteArrayOutputStream because of OOM in gump run
|
||||||
File tmp = TempFile.createTempFile("poi-test", ".bug57880");
|
File tmp = TempFile.createTempFile("poi-test", ".bug57880");
|
||||||
FileOutputStream fos = new FileOutputStream(tmp);
|
OutputStream fos = new FileOutputStream(tmp);
|
||||||
wb.write(fos);
|
try {
|
||||||
fos.close();
|
wb.write(fos);
|
||||||
|
} finally {
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
|
||||||
wb.close();
|
wb.close();
|
||||||
fmt = null; /*s = null;*/ wb = null;
|
fmt = null; /*s = null;*/ wb = null;
|
||||||
|
@ -139,5 +139,7 @@ public final class VisioTextExtractor extends POIOLE2TextExtractor {
|
|||||||
|
|
||||||
// Print not PrintLn as already has \n added to it
|
// Print not PrintLn as already has \n added to it
|
||||||
System.out.print(extractor.getText());
|
System.out.print(extractor.getText());
|
||||||
|
|
||||||
|
extractor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,6 +228,7 @@ public final class TestHSSFDataFormatter extends TestCase {
|
|||||||
row = wb.getSheetAt(0).getRow(1);
|
row = wb.getSheetAt(0).getRow(1);
|
||||||
it = row.cellIterator();
|
it = row.cellIterator();
|
||||||
log("==== VALID TIME FORMATS ====");
|
log("==== VALID TIME FORMATS ====");
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Cell cell = it.next();
|
Cell cell = it.next();
|
||||||
String fmt = cell.getCellStyle().getDataFormatString();
|
String fmt = cell.getCellStyle().getDataFormatString();
|
||||||
@ -239,7 +240,8 @@ public final class TestHSSFDataFormatter extends TestCase {
|
|||||||
assertTrue( ! "555.47431".equals(fmtval));
|
assertTrue( ! "555.47431".equals(fmtval));
|
||||||
|
|
||||||
// check we found the time properly
|
// check we found the time properly
|
||||||
assertTrue("Format came out incorrect - " + fmt, fmtval.indexOf("11:23") > -1);
|
assertTrue("Format came out incorrect - " + fmt + ": " + fmtval + ", but expected to find '11:23'",
|
||||||
|
fmtval.indexOf("11:23") > -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test number formats
|
// test number formats
|
||||||
@ -409,8 +411,8 @@ public final class TestHSSFDataFormatter extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void log(String msg) {
|
private static void log(String msg) {
|
||||||
if (false) { // successful tests should be silent
|
// if (false) { // successful tests should be silent
|
||||||
System.out.println(msg);
|
// System.out.println(msg);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user