]> source.dussan.org Git - poi.git/commitdiff
SonarQube fixes
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 8 Jan 2017 00:38:41 +0000 (00:38 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 8 Jan 2017 00:38:41 +0000 (00:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1777855 13f79535-47bb-0310-9956-ffa450edef68

30 files changed:
src/examples/src/org/apache/poi/xssf/streaming/examples/SavePasswordProtectedXlsx.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/FitSheetToOnePage.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/HeadersAndFooters.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/IterateCells.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/LineChart.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/NewLinesInCells.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/Outlining.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/ShiftRows.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/SplitAndFreezePanes.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkbookProperties.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
src/examples/src/org/apache/poi/xwpf/usermodel/examples/BetterHeaderFooterExample.java
src/examples/src/org/apache/poi/xwpf/usermodel/examples/UpdateEmbeddedDoc.java
src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/java/org/apache/poi/xssf/util/NumericRanges.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java

index 9aaa8bf276297c6f649f901f847534e344f457fd..79b3293a6f081ffcd862c76dc1c29718f90d976b 100644 (file)
@@ -84,24 +84,22 @@ public class SavePasswordProtectedXlsx {
     
     public static void save(final InputStream inputStream, final String filename, final String pwd)
             throws InvalidFormatException, IOException, GeneralSecurityException {
+        POIFSFileSystem fs = null;
+        FileOutputStream fos = null;
+        OPCPackage opc = null;
         try {
-            POIFSFileSystem fs = new POIFSFileSystem();
+            fs = new POIFSFileSystem();
             EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
             Encryptor enc = Encryptor.getInstance(info);
             enc.confirmPassword(pwd);
-            OPCPackage opc = OPCPackage.open(inputStream);
-            try {
-                FileOutputStream fos = new FileOutputStream(filename);
-                try {
-                    opc.save(enc.getDataStream(fs));
-                    fs.writeFilesystem(fos);
-                } finally {
-                    IOUtils.closeQuietly(fos);
-                }
-            } finally {
-                IOUtils.closeQuietly(opc);
-            }
+            opc = OPCPackage.open(inputStream);
+            fos = new FileOutputStream(filename);
+            opc.save(enc.getDataStream(fs));
+            fs.writeFilesystem(fos);
         } finally {
+            IOUtils.closeQuietly(fos);
+            IOUtils.closeQuietly(opc);
+            IOUtils.closeQuietly(fs);
             IOUtils.closeQuietly(inputStream);
         }
     }
index 3e6736014cccbcd955666bf5af47df2b536cf471..b84814f1be7a9a872397dc3e130fce64b8fbe2ec 100644 (file)
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.Date;
 
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
@@ -29,7 +37,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 public class CreateCell {
 
 
-       public static void main(String[]args) throws Exception {
+       public static void main(String[]args) throws IOException {
         Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
         CreationHelper creationHelper = wb.getCreationHelper();
         Sheet sheet = wb.createSheet("new sheet");
@@ -76,5 +84,6 @@ public class CreateCell {
         FileOutputStream fileOut = new FileOutputStream("ooxml-cell.xlsx");
         wb.write(fileOut);
         fileOut.close();
+        wb.close();
        }
 }
index c26ff067c5958ea077d6f4aff244d8258e44d917..056c67fc3fa22f16211fa0a6057af10b02f66b06 100644 (file)
@@ -16,9 +16,9 @@
 ==================================================================== */
 package org.apache.poi.xssf.usermodel.examples;
 
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.AreaReference;
 import org.apache.poi.ss.util.CellReference;
@@ -37,8 +37,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo;
  */
 public class CreateTable {
         
-    public static void main(String[] args) throws FileNotFoundException, 
-            IOException {
+    public static void main(String[] args) throws IOException {
         
         Workbook wb = new XSSFWorkbook();
         XSSFSheet sheet = (XSSFSheet) wb.createSheet();
@@ -88,5 +87,6 @@ public class CreateTable {
         FileOutputStream fileOut = new FileOutputStream("ooxml-table.xlsx");
         wb.write(fileOut);
         fileOut.close();
+        wb.close();
     }
 }
index f5edd4a8eab10e8e6e2324048754422d564abd0b..e93d997eda8077a4452784cc52427767f9c31c9a 100644 (file)
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
+import java.io.IOException;
 
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
 import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFRichTextString;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
@@ -27,7 +33,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  * Fills and Colors
  */
 public class FillsAndColors {
-    public static void main(String[] args) throws Exception {
+    public static void main(String[] args) throws IOException {
         Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("new sheet");
 
@@ -37,7 +43,7 @@ public class FillsAndColors {
         // Aqua background
         CellStyle style = wb.createCellStyle();
         style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
-        style.setFillPattern(CellStyle.BIG_SPOTS);
+        style.setFillPattern(FillPatternType.BIG_SPOTS);
         Cell cell = row.createCell(1);
         cell.setCellValue(new XSSFRichTextString("X"));
         cell.setCellStyle(style);
@@ -45,7 +51,7 @@ public class FillsAndColors {
         // Orange "foreground", foreground being the fill foreground not the font color.
         style = wb.createCellStyle();
         style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
-        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
+        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
         cell = row.createCell(2);
         cell.setCellValue(new XSSFRichTextString("X"));
         cell.setCellStyle(style);
@@ -54,6 +60,6 @@ public class FillsAndColors {
         FileOutputStream fileOut = new FileOutputStream("fill_colors.xlsx");
         wb.write(fileOut);
         fileOut.close();
-
+        wb.close();
     }
 }
index a781688c3969c0ed61f3cccf7cac002c34d460cd..a27ebb8633fd82d7ab0f68f11e0386514a98c751 100644 (file)
@@ -17,6 +17,7 @@
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
+import java.io.IOException;
 
 import org.apache.poi.ss.usermodel.PrintSetup;
 import org.apache.poi.ss.usermodel.Sheet;
@@ -25,8 +26,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 public class FitSheetToOnePage {
 
-
-    public static void main(String[]args) throws Exception {
+    public static void main(String[]args) throws IOException {
         Workbook wb = new XSSFWorkbook();  //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("format sheet");
         PrintSetup ps = sheet.getPrintSetup();
@@ -41,6 +41,6 @@ public class FitSheetToOnePage {
         FileOutputStream fileOut = new FileOutputStream("fitSheetToOnePage.xlsx");
         wb.write(fileOut);
         fileOut.close();
-
+        wb.close();
     }
 }
index 8b95fe63c28c88ac7044a7b7085bd38e035604e0..057a87a771591891c7226eb78dcee21a50026b3b 100644 (file)
@@ -17,6 +17,7 @@
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
+import java.io.IOException;
 
 import org.apache.poi.ss.usermodel.Footer;
 import org.apache.poi.ss.usermodel.Header;
@@ -28,7 +29,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 public class HeadersAndFooters {
 
 
-    public static void main(String[]args) throws Exception {
+    public static void main(String[]args) throws IOException {
         Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("first-header - format sheet");
         sheet.createRow(0).createCell(0).setCellValue(123);
@@ -79,6 +80,6 @@ public class HeadersAndFooters {
         FileOutputStream fileOut = new FileOutputStream("headerFooter.xlsx");
         wb.write(fileOut);
         fileOut.close();
-
+        wb.close();
     }
 }
index 99d1cacf614b0918aee25ee683ba710ba28f7688..2ac609a8aaf233c12d02360abe3f51fc90a04ac2 100644 (file)
 
 package org.apache.poi.xssf.usermodel.examples;
 
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.Sheet;
+import java.io.FileInputStream;
+import java.io.IOException;
+
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
-
-import java.io.FileInputStream;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
  *  Iterate over rows and cells
  */
 public class IterateCells {
 
-    public static void main(String[] args) throws Exception {
+    public static void main(String[] args) throws IOException {
         Workbook wb = new XSSFWorkbook(new FileInputStream(args[0]));
         for (int i = 0; i < wb.getNumberOfSheets(); i++) {
             Sheet sheet = wb.getSheetAt(i);
@@ -42,5 +43,6 @@ public class IterateCells {
                 }
             }
         }
+        wb.close();
     }
 }
index d8564c52312b73639a781600696f81cc7705e921..d6d5e8ed0846fef272a4828533ae7c6e76051e9c 100644 (file)
@@ -17,6 +17,7 @@
 package org.apache.poi.xssf.usermodel.examples;\r
 \r
 import java.io.FileOutputStream;\r
+import java.io.IOException;\r
 \r
 import org.apache.poi.ss.usermodel.Cell;\r
 import org.apache.poi.ss.usermodel.Chart;\r
@@ -42,7 +43,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  */\r
 public class LineChart {\r
 \r
-    public static void main(String[] args) throws Exception {\r
+    public static void main(String[] args) throws IOException {\r
         Workbook wb = new XSSFWorkbook();\r
         Sheet sheet = wb.createSheet("linechart");\r
         final int NUM_OF_ROWS = 3;\r
@@ -59,7 +60,7 @@ public class LineChart {
             }\r
         }\r
 \r
-        Drawing drawing = sheet.createDrawingPatriarch();\r
+        Drawing<?> drawing = sheet.createDrawingPatriarch();\r
         ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);\r
 \r
         Chart chart = drawing.createChart(anchor);\r
@@ -87,5 +88,6 @@ public class LineChart {
         FileOutputStream fileOut = new FileOutputStream("ooxml-line-chart.xlsx");\r
         wb.write(fileOut);\r
         fileOut.close();\r
+        wb.close();\r
     }\r
 }\r
index 9d63268fc3da43195aed581b4b63274db2e50640..b6bca2e8d70311a7c2fbe0eb65a4d03bda5db1c2 100644 (file)
 
 package org.apache.poi.xssf.usermodel.examples;
 
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Row;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFRichTextString;
-
-import java.io.FileOutputStream;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
  * An example of how to merge regions of cells.
  */
 public class MergingCells {
-    public static void main(String[] args) throws Exception {
+    public static void main(String[] args) throws IOException {
         Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("new sheet");
 
@@ -45,5 +46,6 @@ public class MergingCells {
         FileOutputStream fileOut = new FileOutputStream("merging_cells.xlsx");
         wb.write(fileOut);
         fileOut.close();
+        wb.close();
     }
 }
index eb179357d5834262decf06568303aa394e718b4f..35d26918c71c2b54b71d887927b86ee43c686734 100644 (file)
@@ -17,6 +17,7 @@
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
+import java.io.IOException;
 
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
@@ -30,7 +31,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  */
 public class NewLinesInCells {
 
-    public static void main(String[]args) throws Exception {
+    public static void main(String[]args) throws IOException {
         Workbook wb = new XSSFWorkbook();   //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet();
 
@@ -52,6 +53,7 @@ public class NewLinesInCells {
         FileOutputStream fileOut = new FileOutputStream("ooxml-newlines.xlsx");
         wb.write(fileOut);
         fileOut.close();
+        wb.close();
     }
 
 }
index 869316f087a4a585ba0aad823e2e000e547edf1a..f859c9eb5131425602aa6bd3eb698a688fbaa42c 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.OutputStream;
 
 import org.apache.poi.ss.usermodel.Sheet;
@@ -26,14 +27,14 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 public class Outlining {
 
-    public static void main(String[] args) throws Exception {
+    public static void main(String[] args) throws IOException {
         Outlining o=new Outlining();
         o.groupRowColumn();
         o.collapseExpandRowColumn();
     }
 
 
-    private void groupRowColumn() throws Exception {
+    private void groupRowColumn() throws IOException {
         Workbook wb = new XSSFWorkbook();
         Sheet sheet1 = wb.createSheet("new sheet");
 
@@ -50,10 +51,11 @@ public class Outlining {
             wb.write(fileOut);
         } finally {
             fileOut.close();
+            wb.close();
         }
     }
 
-    private void collapseExpandRowColumn() throws Exception {
+    private void collapseExpandRowColumn() throws IOException {
         Workbook wb2 = new XSSFWorkbook();
         Sheet sheet2 = wb2.createSheet("new sheet");
         sheet2.groupRow( 5, 14 );
@@ -76,6 +78,7 @@ public class Outlining {
             wb2.write(fileOut);
         } finally {
             fileOut.close();
+            wb2.close();
         }
     }
 }
index f0a94777f00aeb95751219c6d4319d073aeb63ce..8b02eba307b06f2f005a6323f0b448c5a23a2572 100644 (file)
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.ss.util.*;
-import org.apache.poi.ss.usermodel.charts.*;
+import java.io.IOException;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Chart;
+import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.Drawing;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.charts.AxisCrosses;
+import org.apache.poi.ss.usermodel.charts.AxisPosition;
+import org.apache.poi.ss.usermodel.charts.ChartDataSource;
+import org.apache.poi.ss.usermodel.charts.ChartLegend;
+import org.apache.poi.ss.usermodel.charts.DataSources;
+import org.apache.poi.ss.usermodel.charts.LegendPosition;
+import org.apache.poi.ss.usermodel.charts.ScatterChartData;
+import org.apache.poi.ss.usermodel.charts.ValueAxis;
+import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
  * Illustrates how to create a simple scatter chart.
- *
- * @author Roman Kashitsyn
  */
 public class ScatterChart {
 
-    public static void main(String[] args) throws Exception {
+    public static void main(String[] args) throws IOException {
         Workbook wb = new XSSFWorkbook();
         Sheet sheet = wb.createSheet("Sheet 1");
         final int NUM_OF_ROWS = 3;
@@ -49,7 +62,7 @@ public class ScatterChart {
             }
         }
 
-        Drawing drawing = sheet.createDrawingPatriarch();
+        Drawing<?> drawing = sheet.createDrawingPatriarch();
         ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
 
         Chart chart = drawing.createChart(anchor);
@@ -76,5 +89,6 @@ public class ScatterChart {
         FileOutputStream fileOut = new FileOutputStream("ooxml-scatter-chart.xlsx");
         wb.write(fileOut);
         fileOut.close();
+        wb.close();
     }
 }
index ec4bb21398728f7541f6625d799dc3c22a3313d2..5f70b6ab9468472d313e30cbb696660881ac5037 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
+import java.io.IOException;
 
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
@@ -29,7 +30,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  */
 public class ShiftRows {
 
-    public static void main(String[]args) throws Exception {
+    public static void main(String[]args) throws IOException {
         Workbook wb = new XSSFWorkbook();   //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("Sheet1");
 
@@ -54,7 +55,7 @@ public class ShiftRows {
         FileOutputStream fileOut = new FileOutputStream("shiftRows.xlsx");
         wb.write(fileOut);
         fileOut.close();
-
+        wb.close();
     }
 
 
index 937086b85d6c5cbf5e6a4bcbaddc372b1ab7ded0..4ea6ea37002a936a304eaabdb742b8f95727146a 100644 (file)
 
 package org.apache.poi.xssf.usermodel.examples;
 
-import org.apache.poi.ss.usermodel.Workbook;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
 import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
-import java.io.FileOutputStream;
-
 /**
- * How to set spklit and freeze panes
+ * How to set split and freeze panes
  */
 public class SplitAndFreezePanes {
-    public static void main(String[]args) throws Exception {
+    public static void main(String[]args) throws IOException {
         Workbook wb = new XSSFWorkbook();
         Sheet sheet1 = wb.createSheet("new sheet");
         Sheet sheet2 = wb.createSheet("second sheet");
@@ -46,5 +47,6 @@ public class SplitAndFreezePanes {
         FileOutputStream fileOut = new FileOutputStream("splitFreezePane.xlsx");
         wb.write(fileOut);
         fileOut.close();
+        wb.close();
     }
 }
index 3a8fd56d00a3b6720fccbc5d2c447aa07b37cf89..5911caa6cab7952624f55aff4f5ce5f4a674e309 100644 (file)
 package org.apache.poi.xssf.usermodel.examples;
 
 import java.io.FileOutputStream;
+import java.io.IOException;
 
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.POIXMLProperties;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
- *  How to set extended and custom properties
- *
- * @author Yegor Kozlov
+ * How to set extended and custom properties
  */
 public class WorkbookProperties {
 
-    public static void main(String[]args) throws Exception {
+    public static void main(String[]args) throws IOException {
 
         XSSFWorkbook workbook = new XSSFWorkbook();
         workbook.createSheet("Workbook Properties");
@@ -59,7 +58,7 @@ public class WorkbookProperties {
         FileOutputStream out = new FileOutputStream("workbook.xlsx");
         workbook.write(out);
         out.close();
-
+        workbook.close();
     }
 
 
index 6e12fffe74484b40d4f779298a4fd2c401696634..32b233ce7fe25421ae68c43a3d55dd0427f33ece 100644 (file)
 
 package org.apache.poi.xssf.usermodel.examples;
 
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.usermodel.*;
-
 import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
  * Working with borders
  */
 public class WorkingWithBorders {
-    public static void main(String[] args) throws Exception {
+    public static void main(String[] args) throws IOException {
         Workbook wb = new XSSFWorkbook();  //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("borders");
 
@@ -40,13 +46,13 @@ public class WorkingWithBorders {
 
         // Style the cell with borders all around.
         CellStyle style = wb.createCellStyle();
-        style.setBorderBottom(CellStyle.BORDER_THIN);
+        style.setBorderBottom(BorderStyle.THIN);
         style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
-        style.setBorderLeft(CellStyle.BORDER_THIN);
+        style.setBorderLeft(BorderStyle.THIN);
         style.setLeftBorderColor(IndexedColors.GREEN.getIndex());
-        style.setBorderRight(CellStyle.BORDER_THIN);
+        style.setBorderRight(BorderStyle.THIN);
         style.setRightBorderColor(IndexedColors.BLUE.getIndex());
-        style.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED);
+        style.setBorderTop(BorderStyle.MEDIUM_DASHED);
         style.setTopBorderColor(IndexedColors.BLACK.getIndex());
         cell.setCellStyle(style);
 
@@ -54,5 +60,6 @@ public class WorkingWithBorders {
         FileOutputStream fileOut = new FileOutputStream("xssf-borders.xlsx");
         wb.write(fileOut);
         fileOut.close();
+        wb.close();
     }
 }
index 3d4393ba1f82734f5d1645e812d423238fdcc6ad..9930674845584b5a05f0bd30cda12a0adc93d73e 100644 (file)
 
 package org.apache.poi.xssf.usermodel.examples;
 
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.ss.usermodel.IndexedColors;
-
 import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
  * Working with Fonts
  */
 public class WorkingWithFonts {
-    public static void main(String[] args) throws Exception {
+    public static void main(String[] args) throws IOException {
         Workbook wb = new XSSFWorkbook();  //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("Fonts");
 
@@ -97,5 +102,6 @@ public class WorkingWithFonts {
         FileOutputStream fileOut = new FileOutputStream("xssf-fonts.xlsx");
         wb.write(fileOut);
         fileOut.close();
+        wb.close();
     }
 }
index fe5f5ad44a8999efe5567a54a6eb304234971943..d40c4ed0cb11b8b116fec210fcea68ea36cc0563 100644 (file)
@@ -30,7 +30,7 @@ import org.apache.poi.xwpf.usermodel.XWPFRun;
 
 public class BetterHeaderFooterExample {
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException {
         XWPFDocument doc = new XWPFDocument();
 
         XWPFParagraph p = doc.createParagraph();
@@ -48,13 +48,9 @@ public class BetterHeaderFooterExample {
         XWPFFooter foot = doc.createFooter(HeaderFooterType.DEFAULT);
         foot.createParagraph().createRun().setText("footer");
         
-        try {
-            OutputStream os = new FileOutputStream(new File("header2.docx"));
-            doc.write(os);
-            doc.close();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
+        OutputStream os = new FileOutputStream(new File("header2.docx"));
+        doc.write(os);
+        os.close();
+        doc.close();
     }
 }
index 410f3c62f70fa024a25355ef9b8b986dfbfbf81a..166f39cdab908f8b738012d92ca7b2b9ac819e89 100644 (file)
@@ -23,33 +23,31 @@ import static org.junit.Assert.assertEquals;
 \r
 import java.io.File;\r
 import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
 import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
 import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
 import java.util.List;\r
-import java.util.Iterator;\r
 \r
-import org.apache.poi.openxml4j.opc.PackagePart;\r
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;\r
+import org.apache.poi.openxml4j.opc.PackagePart;\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+import org.apache.poi.ss.usermodel.Workbook;\r
 import org.apache.poi.ss.usermodel.WorkbookFactory;\r
+import org.apache.poi.util.IOUtils;\r
 import org.apache.poi.xwpf.usermodel.XWPFDocument;\r
-import org.apache.poi.ss.usermodel.Workbook;\r
-import org.apache.poi.ss.usermodel.Sheet;\r
-import org.apache.poi.ss.usermodel.Row;\r
-import org.apache.poi.ss.usermodel.Cell;\r
 \r
 /**\r
  * Tests whether it is possible to successfully update an Excel workbook that is\r
  * embedded into a WordprocessingML document. Note that the test has currently\r
  * only been conducted with a binary Excel workbook and NOT yet with a\r
- * SpreadsheetML workbook embedded into the document.\r
- *\r
- * <p>\r
- *     This code was successfully tested with the following file from the POI test collection:\r
- *     http://svn.apache.org/repos/asf/poi/trunk/test-data/document/EmbeddedDocument.docx\r
- * </p>\r
- *\r
- * @author Mark B\r
+ * SpreadsheetML workbook embedded into the document.<p>\r
+ * \r
+ * This code was successfully tested with the following file from the POI test collection:\r
+ * http://svn.apache.org/repos/asf/poi/trunk/test-data/document/EmbeddedDocument.docx\r
  */\r
 public class UpdateEmbeddedDoc {\r
 \r
@@ -79,27 +77,15 @@ public class UpdateEmbeddedDoc {
         this.docFile = new File(filename);\r
         FileInputStream fis = null;\r
         if (!this.docFile.exists()) {\r
-            throw new FileNotFoundException("The Word dcoument " +\r
-                    filename +\r
-                    " does not exist.");\r
+            throw new FileNotFoundException("The Word dcoument " + filename + " does not exist.");\r
         }\r
         try {\r
-\r
             // Open the Word document file and instantiate the XWPFDocument\r
             // class.\r
             fis = new FileInputStream(this.docFile);\r
             this.doc = new XWPFDocument(fis);\r
         } finally {\r
-            if (fis != null) {\r
-                try {\r
-                    fis.close();\r
-                    fis = null;\r
-                } catch (IOException ioEx) {\r
-                    System.out.println("IOException caught trying to close " +\r
-                            "FileInputStream in the constructor of " +\r
-                            "UpdateEmbeddedDoc.");\r
-                }\r
-            }\r
+            IOUtils.closeQuietly(fis);\r
         }\r
     }\r
 \r
@@ -121,35 +107,38 @@ public class UpdateEmbeddedDoc {
      *                             file system.\r
      */\r
     public void updateEmbeddedDoc() throws OpenXML4JException, IOException {\r
-        Workbook workbook = null;\r
-        Sheet sheet = null;\r
-        Row row = null;\r
-        Cell cell = null;\r
-        PackagePart pPart = null;\r
-        Iterator<PackagePart> pIter = null;\r
         List<PackagePart> embeddedDocs = this.doc.getAllEmbedds();\r
-        if (embeddedDocs != null && !embeddedDocs.isEmpty()) {\r
-            pIter = embeddedDocs.iterator();\r
-            while (pIter.hasNext()) {\r
-                pPart = pIter.next();\r
-                if (pPart.getPartName().getExtension().equals(BINARY_EXTENSION) ||\r
-                        pPart.getPartName().getExtension().equals(OPENXML_EXTENSION)) {\r
-\r
-                    // Get an InputStream from the pacage part and pass that\r
-                    // to the create method of the WorkbookFactory class. Update\r
-                    // the resulting Workbook and then stream that out again\r
-                    // using an OutputStream obtained from the same PackagePart.\r
-                    workbook = WorkbookFactory.create(pPart.getInputStream());\r
-                    sheet = workbook.getSheetAt(SHEET_NUM);\r
-                    row = sheet.getRow(ROW_NUM);\r
-                    cell = row.getCell(CELL_NUM);\r
+        for (PackagePart pPart : embeddedDocs) {\r
+            String ext = pPart.getPartName().getExtension();\r
+            if (BINARY_EXTENSION.equals(ext) || OPENXML_EXTENSION.equals(ext)) {\r
+                // Get an InputStream from the package part and pass that\r
+                // to the create method of the WorkbookFactory class. Update\r
+                // the resulting Workbook and then stream that out again\r
+                // using an OutputStream obtained from the same PackagePart.\r
+                InputStream is = pPart.getInputStream();\r
+                Workbook workbook = null;\r
+                OutputStream os = null;\r
+                try {\r
+                    workbook = WorkbookFactory.create(is);\r
+                    Sheet sheet = workbook.getSheetAt(SHEET_NUM);\r
+                    Row row = sheet.getRow(ROW_NUM);\r
+                    Cell cell = row.getCell(CELL_NUM);\r
                     cell.setCellValue(NEW_VALUE);\r
-                    workbook.write(pPart.getOutputStream());\r
+                    os = pPart.getOutputStream();\r
+                    workbook.write(os);\r
+                } finally {\r
+                    IOUtils.closeQuietly(os);\r
+                    IOUtils.closeQuietly(workbook);\r
+                    IOUtils.closeQuietly(is);\r
                 }\r
             }\r
+        }\r
 \r
+        if (!embeddedDocs.isEmpty()) {\r
             // Finally, write the newly modified Word document out to file.\r
-            this.doc.write(new FileOutputStream(this.docFile));\r
+            FileOutputStream fos = new FileOutputStream(this.docFile);\r
+            this.doc.write(fos);\r
+            fos.close();\r
         }\r
     }\r
 \r
@@ -179,24 +168,20 @@ public class UpdateEmbeddedDoc {
      *                             file system.\r
      */\r
     public void checkUpdatedDoc() throws OpenXML4JException, IOException {\r
-        Workbook workbook = null;\r
-        Sheet sheet = null;\r
-        Row row = null;\r
-        Cell cell = null;\r
-        PackagePart pPart = null;\r
-        Iterator<PackagePart> pIter = null;\r
-        List<PackagePart> embeddedDocs = this.doc.getAllEmbedds();\r
-        if (embeddedDocs != null && !embeddedDocs.isEmpty()) {\r
-            pIter = embeddedDocs.iterator();\r
-            while (pIter.hasNext()) {\r
-                pPart = pIter.next();\r
-                if (pPart.getPartName().getExtension().equals(BINARY_EXTENSION) ||\r
-                        pPart.getPartName().getExtension().equals(OPENXML_EXTENSION)) {\r
-                    workbook = WorkbookFactory.create(pPart.getInputStream());\r
-                    sheet = workbook.getSheetAt(SHEET_NUM);\r
-                    row = sheet.getRow(ROW_NUM);\r
-                    cell = row.getCell(CELL_NUM);\r
+        for (PackagePart pPart : this.doc.getAllEmbedds()) {\r
+            String ext = pPart.getPartName().getExtension();\r
+            if (BINARY_EXTENSION.equals(ext) || OPENXML_EXTENSION.equals(ext)) {\r
+                InputStream is = pPart.getInputStream();\r
+                Workbook workbook = null;\r
+                try {\r
+                    workbook = WorkbookFactory.create(is);\r
+                    Sheet sheet = workbook.getSheetAt(SHEET_NUM);\r
+                    Row row = sheet.getRow(ROW_NUM);\r
+                    Cell cell = row.getCell(CELL_NUM);\r
                     assertEquals(cell.getNumericCellValue(), NEW_VALUE, 0.0001);\r
+                } finally {\r
+                    IOUtils.closeQuietly(workbook);\r
+                    IOUtils.closeQuietly(is);\r
                 }\r
             }\r
         }\r
@@ -206,16 +191,11 @@ public class UpdateEmbeddedDoc {
      * Code to test updating of the embedded Excel workbook.\r
      *\r
      * @param args\r
+     * @throws OpenXML4JException \r
      */\r
-    public static void main(String[] args) {\r
-        try {\r
-            UpdateEmbeddedDoc ued = new UpdateEmbeddedDoc(args[0]);\r
-            ued.updateEmbeddedDoc();\r
-            ued.checkUpdatedDoc();\r
-        } catch (Exception ex) {\r
-            System.out.println(ex.getClass().getName());\r
-            System.out.println(ex.getMessage());\r
-            ex.printStackTrace(System.out);\r
-        }\r
+    public static void main(String[] args) throws IOException, OpenXML4JException {\r
+        UpdateEmbeddedDoc ued = new UpdateEmbeddedDoc(args[0]);\r
+        ued.updateEmbeddedDoc();\r
+        ued.checkUpdatedDoc();\r
     }\r
 }\r
index 48ee58e829e246b90125f44632d1a46fbc9ff484..09e02c4e07d8e85d2ae9ffdc09156a9790b9b082 100644 (file)
@@ -56,9 +56,8 @@ public final class LittleEndianByteArrayInputStream extends ByteArrayInputStream
            final int size = LittleEndianConsts.INT_SIZE;
                checkPosition(size);
                int le = LittleEndian.getInt(buf, pos);
-        if (super.skip(size) < size) {
-            throw new RuntimeException("Buffer overrun");
-        }
+        long skipped = super.skip(size);
+        assert skipped == size : "Buffer overrun";
                return le;
        }
 
@@ -67,9 +66,8 @@ public final class LittleEndianByteArrayInputStream extends ByteArrayInputStream
            final int size = LittleEndianConsts.LONG_SIZE;
                checkPosition(size);
                long le = LittleEndian.getLong(buf, pos);
-               if (super.skip(size) < size) {
-                   throw new RuntimeException("Buffer overrun");
-               }
+        long skipped = super.skip(size);
+        assert skipped == size : "Buffer overrun";
                return le;
        }
 
@@ -88,9 +86,8 @@ public final class LittleEndianByteArrayInputStream extends ByteArrayInputStream
         final int size = LittleEndianConsts.SHORT_SIZE;
         checkPosition(size);
         int le = LittleEndian.getUShort(buf, pos);
-        if (super.skip(size) < size) {
-            throw new RuntimeException("Buffer overrun");
-        }
+        long skipped = super.skip(size);
+        assert skipped == size : "Buffer overrun";
         return le;
        }
 
index 83b1e8609bd6128cf18286a48e5ac1ee3287e6f0..312642ffe22d6af599545194afa3c3e697a1248a 100644 (file)
@@ -261,7 +261,7 @@ public class WorkbookFactory {
             }
         } catch(OfficeXmlFileException e) {
             // opening as .xls failed => try opening as .xlsx
-            OPCPackage pkg = OPCPackage.open(file, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE);
+            OPCPackage pkg = OPCPackage.open(file, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE); // NOSONAR
             try {
                 return new XSSFWorkbook(pkg);
             } catch (Exception ioe) {
index 18a77bf569e835a4205f5a0554cdd53b15d6e9d4..a11bef310094f8350650ce59d85553f9aeb6017c 100644 (file)
@@ -48,10 +48,12 @@ import org.apache.poi.ss.usermodel.PictureData;
 import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.NotImplemented;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
 import org.apache.poi.util.TempFile;
 import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -233,20 +235,14 @@ public class SXSSFWorkbook implements Workbook {
     public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize, boolean compressTmpFiles, boolean useSharedStringsTable){
         setRandomAccessWindowSize(rowAccessWindowSize);
         setCompressTempFiles(compressTmpFiles);
-        if (workbook == null)
-        {
+        if (workbook == null) {
             _wb=new XSSFWorkbook();
             _sharedStringSource = useSharedStringsTable ? _wb.getSharedStringSource() : null;
-        }
-        else
-        {
+        } else {
             _wb=workbook;
             _sharedStringSource = useSharedStringsTable ? _wb.getSharedStringSource() : null;
-            final int numberOfSheets = _wb.getNumberOfSheets();
-            for ( int i = 0; i < numberOfSheets; i++ )
-            {
-                XSSFSheet sheet = _wb.getSheetAt( i );
-                createAndRegisterSXSSFSheet( sheet );
+            for ( Sheet sheet : _wb ) {
+                createAndRegisterSXSSFSheet( (XSSFSheet)sheet );
             }
         }
     }
@@ -364,62 +360,44 @@ public class SXSSFWorkbook implements Workbook {
     {
         for(XSSFSheet sheet : _sxFromXHash.values())
         {
-            if(sheetRef.equals(sheet.getPackagePart().getPartName().getName().substring(1))) return sheet;
+            if(sheetRef.equals(sheet.getPackagePart().getPartName().getName().substring(1))) {
+                return sheet;
+            }
         }
         return null;
     }
 
-    protected void injectData(ZipEntrySource zipEntrySource, OutputStream out) throws IOException 
-    {
-        try
-        {
+    protected void injectData(ZipEntrySource zipEntrySource, OutputStream out) throws IOException {
+        try {
             ZipOutputStream zos = new ZipOutputStream(out);
-            try
-            {
+            try {
                 Enumeration<? extends ZipEntry> en = zipEntrySource.getEntries();
-                while (en.hasMoreElements()) 
-                {
+                while (en.hasMoreElements()) {
                     ZipEntry ze = en.nextElement();
                     zos.putNextEntry(new ZipEntry(ze.getName()));
                     InputStream is = zipEntrySource.getInputStream(ze);
                     XSSFSheet xSheet=getSheetFromZipEntryName(ze.getName());
-                    if(xSheet!=null)
-                    {
+                    if(xSheet!=null) {
                         SXSSFSheet sxSheet=getSXSSFSheet(xSheet);
                         InputStream xis = sxSheet.getWorksheetXMLInputStream();
-                        try
-                        {
+                        try {
                             copyStreamAndInjectWorksheet(is,zos,xis);
-                        }
-                        finally
-                        {
+                        } finally {
                             xis.close();
                         }
-                    }
-                    else
-                    {
-                        copyStream(is, zos);
+                    } else {
+                        IOUtils.copy(is, zos);
                     }
                     is.close();
                 }
-            }
-            finally
-            {
+            } finally {
                 zos.close();
             }
-        }
-        finally
-        {
+        } finally {
             zipEntrySource.close();
         }
     }
-    private static void copyStream(InputStream in, OutputStream out) throws IOException {
-        byte[] chunk = new byte[1024];
-        int count;
-        while ((count = in.read(chunk)) >=0 ) {
-          out.write(chunk,0,count);
-        }
-    }
+
     private static void copyStreamAndInjectWorksheet(InputStream in, OutputStream out, InputStream worksheetData) throws IOException {
         InputStreamReader inReader=new InputStreamReader(in,"UTF-8"); //TODO: Is it always UTF-8 or do we need to read the xml encoding declaration in the file? If not, we should perhaps use a SAX reader instead.
         OutputStreamWriter outWriter=new OutputStreamWriter(out,"UTF-8");
@@ -428,7 +406,7 @@ public class SXSSFWorkbook implements Workbook {
         int pos=0;
         String s="<sheetData";
         int n=s.length();
-//Copy from "in" to "out" up to the string "<sheetData/>" or "</sheetData>" (excluding).
+        //Copy from "in" to "out" up to the string "<sheetData/>" or "</sheetData>" (excluding).
         while(((c=inReader.read())!=-1))
         {
             if(c==s.charAt(pos))
@@ -492,7 +470,9 @@ public class SXSSFWorkbook implements Workbook {
             }
             else
             {
-                if(pos>0) outWriter.write(s,0,pos);
+                if(pos>0) {
+                    outWriter.write(s,0,pos);
+                }
                 if(c==s.charAt(0))
                 {
                     pos=1;
@@ -510,13 +490,14 @@ public class SXSSFWorkbook implements Workbook {
                outWriter.write("<sheetData>\n");
                outWriter.flush();
         }
-//Copy the worksheet data to "out".
-        copyStream(worksheetData,out);
+        //Copy the worksheet data to "out".
+        IOUtils.copy(worksheetData,out);
         outWriter.write("</sheetData>");
         outWriter.flush();
-//Copy the rest of "in" to "out".
-        while(((c=inReader.read())!=-1))
+        //Copy the rest of "in" to "out".
+        while(((c=inReader.read())!=-1)) {
             outWriter.write(c);
+        }
         outWriter.flush();
     }
 
@@ -830,7 +811,9 @@ public class SXSSFWorkbook implements Workbook {
      * @return the font with the matched attributes or <code>null</code>
      * @deprecated POI 3.15 beta 2. Use {@link #findFont(boolean, short, short, String, boolean, boolean, short, byte)} instead.
      */
+    @Deprecated
     @Override
+    @Removal(version="3.17")
     public Font findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
     {
         return _wb.findFont(boldWeight, color, fontHeight, name, italic, strikeout, typeOffset, underline);
@@ -934,7 +917,7 @@ public class SXSSFWorkbook implements Workbook {
     }
     
     /**
-     * Write out this workbook to an Outputstream.
+     * Write out this workbook to an OutputStream.
      *
      * @param stream - the java OutputStream you wish to write to
      * @exception IOException if anything can't be written.
@@ -946,27 +929,23 @@ public class SXSSFWorkbook implements Workbook {
 
         //Save the template
         File tmplFile = TempFile.createTempFile("poi-sxssf-template", ".xlsx");
-        try
-        {
+        boolean deleted;
+        try {
             FileOutputStream os = new FileOutputStream(tmplFile);
-            try
-            {
+            try {
                 _wb.write(os);
-            }
-            finally
-            {
+            } finally {
                 os.close();
             }
 
             //Substitute the template entries with the generated sheet data files
             final ZipEntrySource source = new ZipFileZipEntrySource(new ZipFile(tmplFile));
             injectData(source, stream);
+        } finally {
+            deleted = tmplFile.delete();
         }
-        finally
-        {
-            if(!tmplFile.delete()) {
-                throw new IOException("Could not delete temporary file after processing: " + tmplFile);
-            }
+        if(!deleted) {
+            throw new IOException("Could not delete temporary file after processing: " + tmplFile);
         }
     }
     
@@ -1046,6 +1025,7 @@ public class SXSSFWorkbook implements Workbook {
      */
     @Override
     @Deprecated
+    @Removal(version="3.18")
     public Name getNameAt(int nameIndex)
     {
         return _wb.getNameAt(nameIndex);
@@ -1076,6 +1056,7 @@ public class SXSSFWorkbook implements Workbook {
      */
     @Override
     @Deprecated
+    @Removal(version="3.18")
     public int getNameIndex(String name)
     {
         return _wb.getNameIndex(name);
@@ -1090,6 +1071,7 @@ public class SXSSFWorkbook implements Workbook {
      */
     @Override
     @Deprecated
+    @Removal(version="3.18")
     public void removeName(int index)
     {
         _wb.removeName(index);
@@ -1104,6 +1086,7 @@ public class SXSSFWorkbook implements Workbook {
      */
     @Override
     @Deprecated
+    @Removal(version="3.18")
     public void removeName(String name)
     {
         _wb.removeName(name);
index f1f1ca381b58beb8254e33312ef1d89cc9bf0bb6..a39fd47bf322161f8419317672a8e74e48232ac7 100644 (file)
@@ -46,6 +46,7 @@ import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.Beta;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.util.Removal;
 import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.model.StylesTable;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
@@ -180,32 +181,20 @@ public final class XSSFCell implements Cell {
         
         // Copy CellStyle
         if (policy.isCopyCellStyle()) {
-            if (srcCell != null) {
-                setCellStyle(srcCell.getCellStyle());
-            }
-            else {
-                // clear cell style
-                setCellStyle(null);
-            }
+            setCellStyle(srcCell == null ? null : srcCell.getCellStyle());
         }
         
+        final Hyperlink srcHyperlink = (srcCell == null) ? null : srcCell.getHyperlink();
+
         if (policy.isMergeHyperlink()) {
             // if srcCell doesn't have a hyperlink and destCell has a hyperlink, don't clear destCell's hyperlink
-            final Hyperlink srcHyperlink = srcCell.getHyperlink();
             if (srcHyperlink != null) {
                 setHyperlink(new XSSFHyperlink(srcHyperlink));
             }
-        }
-        else if (policy.isCopyHyperlink()) {
+        } else if (policy.isCopyHyperlink()) {
             // overwrite the hyperlink at dest cell with srcCell's hyperlink
             // if srcCell doesn't have a hyperlink, clear the hyperlink (if one exists) at destCell
-            final Hyperlink srcHyperlink = srcCell.getHyperlink();
-            if (srcHyperlink == null) {
-                setHyperlink(null);
-            }
-            else {
-                setHyperlink(new XSSFHyperlink(srcHyperlink));
-            }
+            setHyperlink(srcHyperlink == null ? null : new XSSFHyperlink(srcHyperlink));
         }
     }
 
@@ -303,7 +292,9 @@ public final class XSSFCell implements Cell {
             case NUMERIC:
                 if(_cell.isSetV()) {
                    String v = _cell.getV();
-                   if (v.isEmpty()) return 0.0;
+                   if (v.isEmpty()) {
+                       return 0.0;
+                   }
                    try {
                       return Double.parseDouble(v);
                    } catch(NumberFormatException e) {
@@ -487,7 +478,9 @@ public final class XSSFCell implements Cell {
      */
     protected String getCellFormula(XSSFEvaluationWorkbook fpb) {
         CellType cellType = getCellTypeEnum();
-        if(cellType != CellType.FORMULA) throw typeMismatch(CellType.FORMULA, cellType, false);
+        if(cellType != CellType.FORMULA) {
+            throw typeMismatch(CellType.FORMULA, cellType, false);
+        }
 
         CTCellFormula f = _cell.getF();
         if (isPartOfArrayFormulaGroup() && f == null) {
@@ -510,8 +503,10 @@ public final class XSSFCell implements Cell {
         XSSFSheet sheet = getSheet();
 
         CTCellFormula f = sheet.getSharedFormula(si);
-        if(f == null) throw new IllegalStateException(
-                "Master cell of a shared formula with sid="+si+" was not found");
+        if(f == null) {
+            throw new IllegalStateException(
+                    "Master cell of a shared formula with sid="+si+" was not found");
+        }
 
         String sharedFormula = f.getStringValue();
         //Range of cells which the shared formula applies to
@@ -560,7 +555,9 @@ public final class XSSFCell implements Cell {
         XSSFWorkbook wb = _row.getSheet().getWorkbook();
         if (formula == null) {
             wb.onDeleteFormula(this);
-            if(_cell.isSetF()) _cell.unsetF();
+            if(_cell.isSetF()) {
+                _cell.unsetF();
+            }
             return;
         }
 
@@ -571,7 +568,9 @@ public final class XSSFCell implements Cell {
         CTCellFormula f = CTCellFormula.Factory.newInstance();
         f.setStringValue(formula);
         _cell.setF(f);
-        if(_cell.isSetV()) _cell.unsetV();
+        if(_cell.isSetV()) {
+            _cell.unsetV();
+        }
     }
 
     /**
@@ -644,7 +643,9 @@ public final class XSSFCell implements Cell {
     @Override
     public void setCellStyle(CellStyle style) {
         if(style == null) {
-            if(_cell.isSetS()) _cell.unsetS();
+            if(_cell.isSetS()) {
+                _cell.unsetS();
+            }
         } else {
             XSSFCellStyle xStyle = (XSSFCellStyle)style;
             xStyle.verifyBelongsToStylesSource(_stylesSource);
@@ -670,7 +671,9 @@ public final class XSSFCell implements Cell {
      * @return the cell type
      * @deprecated 3.15. Will return a {@link CellType} enum in the future.
      */
+    @Deprecated
     @Override
+    @Removal(version="3.17")
     public int getCellType() {
         return getCellTypeEnum().getCode();
     }
@@ -684,7 +687,9 @@ public final class XSSFCell implements Cell {
      */
     @Override
     public CellType getCellTypeEnum() {
-        if (isFormulaCell()) return CellType.FORMULA;
+        if (isFormulaCell()) {
+            return CellType.FORMULA;
+        }
 
         return getBaseCellType(true);
     }
@@ -700,7 +705,9 @@ public final class XSSFCell implements Cell {
      * on the cached value of the formula
      * @deprecated 3.15. Will return a {@link CellType} enum in the future.
      */
+    @Deprecated
     @Override
+    @Removal(version="3.17")
     public int getCachedFormulaResultType() {
         return getCachedFormulaResultTypeEnum().getCode();
     }
@@ -826,7 +833,9 @@ public final class XSSFCell implements Cell {
      */
     public String getErrorCellString() throws IllegalStateException {
         CellType cellType = getBaseCellType(true);
-        if(cellType != CellType.ERROR) throw typeMismatch(CellType.ERROR, cellType, false);
+        if(cellType != CellType.ERROR) {
+            throw typeMismatch(CellType.ERROR, cellType, false);
+        }
 
         return _cell.getV();
     }
@@ -897,7 +906,9 @@ public final class XSSFCell implements Cell {
     private void setBlank(){
         CTCell blank = CTCell.Factory.newInstance();
         blank.setR(_cell.getR());
-        if(_cell.isSetS()) blank.setS(_cell.getS());
+        if(_cell.isSetS()) {
+            blank.setS(_cell.getS());
+        }
         _cell.set(blank);
     }
 
@@ -925,7 +936,9 @@ public final class XSSFCell implements Cell {
      * @see CellType#ERROR
      * @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead.
      */
+    @Deprecated
     @Override
+    @Removal(version="3.17")
     public void setCellType(int cellType) {
         setCellType(CellType.forInt(cellType));
     }
@@ -964,7 +977,9 @@ public final class XSSFCell implements Cell {
                     CTCellFormula f =  CTCellFormula.Factory.newInstance();
                     f.setStringValue("0");
                     _cell.setF(f);
-                    if(_cell.isSetT()) _cell.unsetT();
+                    if(_cell.isSetT()) {
+                        _cell.unsetT();
+                    }
                 }
                 break;
             case BLANK:
index d93b8ed5bcf145f154adcc2e644f4ad9ec06d62a..5066ff7d01dff8c2ac8375507d3f82a39e38b089 100644 (file)
@@ -78,7 +78,7 @@ public class XSSFPivotCacheDefinition extends POIXMLDocumentPart{
             options.setLoadReplaceDocumentElement(null);
             ctPivotCacheDefinition = CTPivotCacheDefinition.Factory.parse(is, options);
         } catch (XmlException e) {
-            throw new IOException(e.getLocalizedMessage());
+            throw new IOException(e.getLocalizedMessage(), e);
         }
     }
 
@@ -123,22 +123,30 @@ public class XSSFPivotCacheDefinition extends POIXMLDocumentPart{
         final String ref = wsSource.getRef();
         final String name = wsSource.getName();
         
-        if (ref == null && name == null) throw new IllegalArgumentException("Pivot cache must reference an area, named range, or table.");
+        if (ref == null && name == null) {
+            throw new IllegalArgumentException("Pivot cache must reference an area, named range, or table.");
+        }
         
         // this is the XML format, so tell the reference that.
-        if (ref != null) return new AreaReference(ref, SpreadsheetVersion.EXCEL2007);
+        if (ref != null) {
+            return new AreaReference(ref, SpreadsheetVersion.EXCEL2007);
+        }
+        
+        assert (name != null);
+        
+        // named range or table?
+        final Name range = wb.getName(name);
+        if (range != null) {
+            return new AreaReference(range.getRefersToFormula(), SpreadsheetVersion.EXCEL2007);
+        }
         
-        if (name != null) {
-            // named range or table?
-            final Name range = wb.getName(name);
-            if (range != null) return new AreaReference(range.getRefersToFormula(), SpreadsheetVersion.EXCEL2007);
-            // not a named range, check for a table.
-            // do this second, as tables are sheet-specific, but named ranges are not, and may not have a sheet name given.
-            final XSSFSheet sheet = (XSSFSheet) wb.getSheet(wsSource.getSheet());
-            for (XSSFTable table : sheet.getTables()) {
-                if (table.getName().equals(name)) { //case-sensitive?
-                    return new AreaReference(table.getStartCellReference(), table.getEndCellReference());
-                }
+        // not a named range, check for a table.
+        // do this second, as tables are sheet-specific, but named ranges are not, and may not have a sheet name given.
+        final XSSFSheet sheet = (XSSFSheet) wb.getSheet(wsSource.getSheet());
+        for (XSSFTable table : sheet.getTables()) {
+            // TODO: case-sensitive?
+            if (name.equals(table.getName())) {
+                return new AreaReference(table.getStartCellReference(), table.getEndCellReference());
             }
         }
         
index 20432104962bf309b78c39c5f9b140eec33cb65d..bde93d663caec5062d3b8f5d1baad0a466d5c1af 100644 (file)
@@ -236,7 +236,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
     private void initHyperlinks() {
         hyperlinks = new ArrayList<XSSFHyperlink>();
 
-        if(!worksheet.isSetHyperlinks()) return;
+        if(!worksheet.isSetHyperlinks()) {
+            return;
+        }
 
         try {
             PackageRelationshipCollection hyperRels =
@@ -390,11 +392,15 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
         // for each cell in sheet, if cell belongs to an array formula, check if merged region intersects array formula cells
         for (int rowIn = firstRow; rowIn <= lastRow; rowIn++) {
             XSSFRow row = getRow(rowIn);
-            if (row == null) continue;
+            if (row == null) {
+                continue;
+            }
             
             for (int colIn = firstColumn; colIn <= lastColumn; colIn++) {
                 XSSFCell cell = row.getCell(colIn);
-                if (cell == null) continue;
+                if (cell == null) {
+                    continue;
+                }
 
                 if (cell.isPartOfArrayFormulaGroup()) {
                     CellRangeAddress arrayRange = cell.getArrayFormulaRange();
@@ -646,7 +652,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
 
         // If both colSplit and rowSplit are zero then the existing freeze pane is removed
         if(colSplit == 0 && rowSplit == 0){
-            if(ctView.isSetPane()) ctView.unsetPane();
+            if(ctView.isSetPane()) {
+                ctView.unsetPane();
+            }
             ctView.setSelectionArray(null);
             return;
         }
@@ -659,12 +667,16 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
         if (colSplit > 0) {
            pane.setXSplit(colSplit);
         } else {
-           if(pane.isSetXSplit()) pane.unsetXSplit();
+           if(pane.isSetXSplit()) {
+               pane.unsetXSplit();
+           }
         }
         if (rowSplit > 0) {
            pane.setYSplit(rowSplit);
         } else {
-           if(pane.isSetYSplit()) pane.unsetYSplit();
+           if(pane.isSetYSplit()) {
+               pane.unsetYSplit();
+           }
         }
 
         pane.setState(STPaneState.FROZEN);
@@ -756,7 +768,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      * @return the cell comment, if one exists. Otherwise return null.
      * @deprecated as of 2015-11-23 (circa POI 3.14beta1). Use {@link #getCellComment(CellAddress)} instead.
      */
+    @Deprecated
     @Override
+    @Removal(version="3.16")
     public XSSFComment getCellComment(int row, int column) {
         return getCellComment(new CellAddress(row, column));
     }
@@ -778,7 +792,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
 
         CellAddress ref = new CellAddress(row, column);
         CTComment ctComment = sheetComments.getCTComment(ref);
-        if(ctComment == null) return null;
+        if(ctComment == null) {
+            return null;
+        }
 
         XSSFVMLDrawing vml = getVMLDrawing(false);
         return new XSSFComment(sheetComments, ctComment,
@@ -1181,7 +1197,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      */
     @Override
     public double getMargin(short margin) {
-        if (!worksheet.isSetPageMargins()) return 0;
+        if (!worksheet.isSetPageMargins()) {
+            return 0;
+        }
 
         CTPageMargins pageMargins = worksheet.getPageMargins();
         switch (margin) {
@@ -1252,7 +1270,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
     @Override
     public CellRangeAddress getMergedRegion(int index) {
         CTMergeCells ctMergeCells = worksheet.getMergeCells();
-        if(ctMergeCells == null) throw new IllegalStateException("This worksheet does not contain merged regions");
+        if(ctMergeCells == null) {
+            throw new IllegalStateException("This worksheet does not contain merged regions");
+        }
 
         CTMergeCell ctMergeCell = ctMergeCells.getMergeCellArray(index);
         String ref = ctMergeCell.getRef();
@@ -1269,7 +1289,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
     public List<CellRangeAddress> getMergedRegions() {
         List<CellRangeAddress> addresses = new ArrayList<CellRangeAddress>();
         CTMergeCells ctMergeCells = worksheet.getMergeCells();
-        if(ctMergeCells == null) return addresses;
+        if(ctMergeCells == null) {
+            return addresses;
+        }
 
         for(CTMergeCell ctMergeCell : ctMergeCells.getMergeCellArray()) {
             String ref = ctMergeCell.getRef();
@@ -1302,7 +1324,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
     public PaneInformation getPaneInformation() {
         CTPane pane = getDefaultSheetView().getPane();
         // no pane configured
-        if(pane == null)  return null;
+        if(pane == null) {
+            return null;
+        }
 
         CellReference cellRef = pane.isSetTopLeftCell() ? new CellReference(pane.getTopLeftCell()) : null;
         return new PaneInformation((short)pane.getXSplit(), (short)pane.getYSplit(),
@@ -1861,7 +1885,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      */
     @Override
     public void removeMergedRegion(int index) {
-        if (!worksheet.isSetMergeCells()) return;
+        if (!worksheet.isSetMergeCells()) {
+            return;
+        }
         
         CTMergeCells ctMergeCells = worksheet.getMergeCells();
         int size = ctMergeCells.sizeOfMergeCellArray();
@@ -1884,7 +1910,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      */
     @Override
     public void removeMergedRegions(Collection<Integer> indices) {
-        if (!worksheet.isSetMergeCells()) return;
+        if (!worksheet.isSetMergeCells()) {
+            return;
+        }
         
         CTMergeCells ctMergeCells = worksheet.getMergeCells();
         List<CTMergeCell> newMergeCells = new ArrayList<CTMergeCell>(ctMergeCells.sizeOfMergeCellArray());
@@ -2466,7 +2494,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      */
     @Override
     public void setColumnWidth(int columnIndex, int width) {
-        if(width > 255*256) throw new IllegalArgumentException("The maximum column width for an individual cell is 255 characters.");
+        if(width > 255*256) {
+            throw new IllegalArgumentException("The maximum column width for an individual cell is 255 characters.");
+        }
 
         columnHelper.setColWidth(columnIndex, (double)width/256);
         columnHelper.setCustomWidth(columnIndex, true);
@@ -2611,8 +2641,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
         short level = getRow(rowIndex).getCTRow().getOutlineLevel();
         int currentRow = rowIndex;
         while (getRow(currentRow) != null) {
-            if (getRow(currentRow).getCTRow().getOutlineLevel() < level)
+            if (getRow(currentRow).getCTRow().getOutlineLevel() < level) {
                 return currentRow + 1;
+            }
             currentRow--;
         }
         return currentRow;
@@ -2641,8 +2672,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      * @param rowNumber the zero based row index to expand
      */
     private void expandRow(int rowNumber) {
-        if (rowNumber == -1)
+        if (rowNumber == -1) {
             return;
+        }
         XSSFRow row = getRow(rowNumber);
         // If it is already expanded do nothing.
         if (!row.getCTRow().isSetHidden()) {
@@ -2756,6 +2788,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      * @param denominator   The denominator for the zoom magnification.
      * @deprecated 2015-11-23 (circa POI 3.14beta1). Use {@link #setZoom(int)} instead.
      */
+    @Deprecated
     @Removal(version="3.16")
     @Override
     public void setZoom(int numerator, int denominator) {
@@ -2989,6 +3022,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
         // we need to sort it in a way so the shifting does not mess up the structures, 
         // i.e. when shifting down, start from down and go up, when shifting up, vice-versa
         SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<XSSFComment, Integer>(new Comparator<XSSFComment>() {
+            @Override
             public int compare(XSSFComment o1, XSSFComment o2) {
                 int row1 = o1.getRow();
                 int row2 = o2.getRow();
@@ -3038,7 +3072,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
                 }
             }
 
-            if(rownum < startRow || rownum > endRow) continue;
+            if(rownum < startRow || rownum > endRow) {
+                continue;
+            }
 
             if (!copyRowHeight) {
                 row.setHeight((short)-1);
@@ -3266,6 +3302,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      * @param cellRef the location of the active cell, e.g. <code>A1</code>..
      * @deprecated 3.14beta2 (circa 2015-12-05). Use {@link #setActiveCell(CellAddress)} instead.
      */
+    @Deprecated
+    @Removal(version="3.16")
     public void setActiveCell(String cellRef) {
         CTSelection ctsel = getSheetTypeSelection();
         ctsel.setActiveCell(cellRef);
@@ -3313,11 +3351,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      */
     private CTSheetView getDefaultSheetView() {
         CTSheetViews views = getSheetTypeSheetViews();
-        int sz = views == null ? 0 : views.sizeOfSheetViewArray();
-        if (sz  == 0) {
+        if (views == null) {
             return null;
         }
-        return views.getSheetViewArray(sz - 1);
+        int sz = views.sizeOfSheetViewArray();
+        return (sz == 0) ? null : views.getSheetViewArray(sz - 1);
     }
 
     /**
@@ -3835,6 +3873,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
         return dataValidationHelper;
     }
 
+    @Override
     public List<XSSFDataValidation> getDataValidations() {
         List<XSSFDataValidation> xssfValidations = new ArrayList<XSSFDataValidation>();
         CTDataValidations dataValidations = this.worksheet.getDataValidations();
@@ -3879,7 +3918,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
     @Override
     public XSSFAutoFilter setAutoFilter(CellRangeAddress range) {
         CTAutoFilter af = worksheet.getAutoFilter();
-        if(af == null) af = worksheet.addNewAutoFilter();
+        if(af == null) {
+            af = worksheet.addNewAutoFilter();
+        }
 
         CellRangeAddress norm = new CellRangeAddress(range.getFirstRow(), range.getLastRow(),
                 range.getFirstColumn(), range.getLastColumn());
@@ -3945,7 +3986,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      */
     public XSSFColor getTabColor() {
         CTSheetPr pr = worksheet.getSheetPr();
-        if(pr == null) pr = worksheet.addNewSheetPr();
+        if(pr == null) {
+            pr = worksheet.addNewSheetPr();
+        }
         if (!pr.isSetTabColor()) {
             return null;
         }
@@ -3958,6 +4001,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      * @param colorIndex  the indexed color to set, must be a constant from {@link org.apache.poi.ss.usermodel.IndexedColors}
      * @deprecated 3.15-beta2. Removed in 3.17. Use {@link #setTabColor(XSSFColor)}.
      */
+    @Deprecated
+    @Removal(version="3.17")
     public void setTabColor(int colorIndex) {
         IndexedColors indexedColor = IndexedColors.fromInt(colorIndex);
         XSSFColor color = new XSSFColor(indexedColor);
@@ -3971,7 +4016,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
      */
     public void setTabColor(XSSFColor color) {
         CTSheetPr pr = worksheet.getSheetPr();
-        if(pr == null) pr = worksheet.addNewSheetPr();
+        if(pr == null) {
+            pr = worksheet.addNewSheetPr();
+        }
         pr.setTabColor(color.getCTColor());
     }
 
@@ -4197,6 +4244,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
         }
 
         return createPivotTable(position, sourceSheet, new PivotTableReferenceConfigurator() {
+                @Override
                 public void configureReference(CTWorksheetSource wsSource) {
                     final String[] firstCell = source.getFirstCell().getCellRefParts();
                     final String firstRow = firstCell[1];
@@ -4269,6 +4317,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
         }
         
         return createPivotTable(position, sourceSheet, new PivotTableReferenceConfigurator() {
+                @Override
                 public void configureReference(CTWorksheetSource wsSource) {
                     wsSource.setName(source.getNameName());
                 }
@@ -4297,7 +4346,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
     @Beta
     public XSSFPivotTable createPivotTable(final Table source, CellReference position) {
        return createPivotTable(position, getWorkbook().getSheet(source.getSheetName()), new PivotTableReferenceConfigurator() {
-           public void configureReference(CTWorksheetSource wsSource) {
+           @Override
+        public void configureReference(CTWorksheetSource wsSource) {
                wsSource.setName(source.getName());
            }
        });
@@ -4317,6 +4367,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
         return tables;
     }
     
+    @Override
     public int getColumnOutlineLevel(int columnIndex) {
         CTCol col = columnHelper.getColumn(columnIndex, false);
         if (col == null) {
index eafe8789fbb57835169952bad7f55a6fd05ddba5..c6df00599d64e8b3b3faebcf73b0345a2302f540 100644 (file)
@@ -352,15 +352,19 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
             Map<String, ExternalLinksTable> elIdMap = new HashMap<String, ExternalLinksTable>();
             for(RelationPart rp : getRelationParts()){
                 POIXMLDocumentPart p = rp.getDocumentPart();
-                if(p instanceof SharedStringsTable) sharedStringSource = (SharedStringsTable)p;
-                else if(p instanceof StylesTable) stylesSource = (StylesTable)p;
-                else if(p instanceof ThemesTable) theme = (ThemesTable)p;
-                else if(p instanceof CalculationChain) calcChain = (CalculationChain)p;
-                else if(p instanceof MapInfo) mapInfo = (MapInfo)p;
-                else if (p instanceof XSSFSheet) {
+                if(p instanceof SharedStringsTable) {
+                    sharedStringSource = (SharedStringsTable)p;
+                } else if(p instanceof StylesTable) {
+                    stylesSource = (StylesTable)p;
+                } else if(p instanceof ThemesTable) {
+                    theme = (ThemesTable)p;
+                } else if(p instanceof CalculationChain) {
+                    calcChain = (CalculationChain)p;
+                } else if(p instanceof MapInfo) {
+                    mapInfo = (MapInfo)p;
+                } else if (p instanceof XSSFSheet) {
                     shIdMap.put(rp.getRelationship().getId(), (XSSFSheet)p);
-                }
-                else if (p instanceof ExternalLinksTable) {
+                } else if (p instanceof ExternalLinksTable) {
                     elIdMap.put(rp.getRelationship().getId(), (ExternalLinksTable)p);
                 }
             }
@@ -723,8 +727,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
      */
     @Override
     public XSSFDataFormat createDataFormat() {
-        if (formatter == null)
+        if (formatter == null) {
             formatter = new XSSFDataFormat(stylesSource);
+        }
         return formatter;
     }
 
@@ -827,7 +832,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
         validateSheetName(sheetname);
 
         // YK: Mimic Excel and silently truncate sheet names longer than 31 characters
-        if(sheetname.length() > 31) sheetname = sheetname.substring(0, 31);
+        if(sheetname.length() > 31) {
+            sheetname = sheetname.substring(0, 31);
+        }
         WorkbookUtil.validateSheetName(sheetname);
 
         CTSheet sheet = addSheet(sheetname);
@@ -860,7 +867,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
         wrapper.sheet = sheet;
         sheet.setId(rp.getRelationship().getId());
         sheet.setSheetId(sheetNumber);
-        if (sheets.isEmpty()) wrapper.setSelected(true);
+        if (sheets.isEmpty()) {
+            wrapper.setSelected(true);
+        }
         sheets.add(wrapper);
         return wrapper;
     }
@@ -1082,7 +1091,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
     @Override
     public String getPrintArea(int sheetIndex) {
         XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex);
-        if (name == null) return null;
+        if (name == null) {
+            return null;
+        }
         //adding one here because 0 indicates a global named region; doesnt make sense for print areas
         return name.getRefersToFormula();
 
@@ -1146,7 +1157,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
     public int getSheetIndex(Sheet sheet) {
         int idx = 0;
         for(XSSFSheet sh : sheets){
-            if(sh == sheet) return idx;
+            if(sh == sheet) {
+                return idx;
+            }
             idx++;
         }
         return -1;
@@ -1439,7 +1452,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
         List<XSSFName> toRemove = new ArrayList<XSSFName>();
         for (XSSFName nm : namedRanges) {
             CTDefinedName ct = nm.getCTName();
-            if(!ct.isSetLocalSheetId()) continue;
+            if(!ct.isSetLocalSheetId()) {
+                continue;
+            }
             if (ct.getLocalSheetId() == index) {
                 toRemove.add(nm);
             } else if (ct.getLocalSheetId() > index){
@@ -1639,21 +1654,28 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
      */
     @Override
     public void setSheetName(int sheetIndex, String sheetname) {
+        if (sheetname == null) {
+            throw new IllegalArgumentException( "sheetName must not be null" );
+        }
+        
         validateSheetIndex(sheetIndex);
         String oldSheetName = getSheetName(sheetIndex);
 
         // YK: Mimic Excel and silently truncate sheet names longer than 31 characters
-        if(sheetname != null && sheetname.length() > 31) sheetname = sheetname.substring(0, 31);
+        if(sheetname.length() > 31) {
+            sheetname = sheetname.substring(0, 31);
+        }
         WorkbookUtil.validateSheetName(sheetname);
-        // findbugs fix - validateSheetName has already checked for null value
-        assert(sheetname != null); 
 
         // Do nothing if no change
-        if (sheetname.equals(oldSheetName)) return;
+        if (sheetname.equals(oldSheetName)) {
+            return;
+        }
         
         // Check it isn't already taken
-        if (containsSheet(sheetname, sheetIndex ))
+        if (containsSheet(sheetname, sheetIndex )) {
             throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
+        }
 
         // Update references to the name
         XSSFFormulaUtils utils = new XSSFFormulaUtils(this);
@@ -1822,7 +1844,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
      * Returns the Theme of current workbook.
      */
     public ThemesTable getTheme() {
-        if (stylesSource == null) return null;
+        if (stylesSource == null) {
+            return null;
+        }
         return stylesSource.getTheme();
     }
 
@@ -1832,7 +1856,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
      */
     @Override
     public XSSFCreationHelper getCreationHelper() {
-        if(_creationHelper == null) _creationHelper = new XSSFCreationHelper(this);
+        if(_creationHelper == null) {
+            _creationHelper = new XSSFCreationHelper(this);
+        }
         return _creationHelper;
     }
 
@@ -1857,8 +1883,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
                 ctName = ctName.substring(0, MAX_SENSITIVE_SHEET_NAME_LEN);
             }
 
-            if (excludeSheetIdx != i && name.equalsIgnoreCase(ctName))
+            if (excludeSheetIdx != i && name.equalsIgnoreCase(ctName)) {
                 return true;
+            }
         }
         return false;
     }
@@ -2149,7 +2176,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
      *  otherwise the given algorithm is used for calculating the hash password (Excel 2013)
      */
     public void setWorkbookPassword(String password, HashAlgorithm hashAlgo) {
-        if (password == null && !workbookProtectionPresent()) return;
+        if (password == null && !workbookProtectionPresent()) {
+            return;
+        }
         setPassword(safeGetWorkbookProtection(), password, hashAlgo, "workbook");
     }
 
@@ -2159,7 +2188,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
      * @return true, if the hashes match (... though original password may differ ...)
      */
     public boolean validateWorkbookPassword(String password) {
-        if (!workbookProtectionPresent()) return (password == null);
+        if (!workbookProtectionPresent()) {
+            return (password == null);
+        }
         return validatePassword(safeGetWorkbookProtection(), password, "workbook");
     }
 
@@ -2171,7 +2202,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
      *  otherwise the given algorithm is used for calculating the hash password (Excel 2013)
      */
     public void setRevisionsPassword(String password, HashAlgorithm hashAlgo) {
-        if (password == null && !workbookProtectionPresent()) return;
+        if (password == null && !workbookProtectionPresent()) {
+            return;
+        }
         setPassword(safeGetWorkbookProtection(), password, hashAlgo, "revisions");
     }
 
@@ -2181,7 +2214,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
      * @return true if the hashes match (... though original password may differ ...)
      */
     public boolean validateRevisionsPassword(String password) {
-        if (!workbookProtectionPresent()) return (password == null);
+        if (!workbookProtectionPresent()) {
+            return (password == null);
+        }
         return validatePassword(safeGetWorkbookProtection(), password, "revisions");
     }
     
index 442e24a48a79e941a66f1428a79b9627621a4ad7..0a853cc7c81f42746852ab8acf0963f6a4dccf9e 100644 (file)
@@ -26,20 +26,19 @@ public class NumericRanges {
     public static final int OVERLAPS_2_WRAPS = 3;
     
     public static long[] getOverlappingRange(long[] range1, long[] range2) {
-        int overlappingType = getOverlappingType(range1, range2);
-        if (overlappingType == OVERLAPS_1_MINOR) {
-            return new long[]{range2[0], range1[1]};
+        switch(getOverlappingType(range1, range2)) {
+            case OVERLAPS_1_MINOR:
+                return new long[]{range2[0], range1[1]};
+            case OVERLAPS_2_MINOR:
+                return new long[]{range1[0], range2[1]};
+            case OVERLAPS_2_WRAPS:
+                return range1;
+            case OVERLAPS_1_WRAPS:
+                return range2;
+            default:
+            case NO_OVERLAPS:
+                return new long[]{-1, -1};
         }
-        else if (overlappingType == OVERLAPS_2_MINOR) {
-            return new long[]{range1[0], range2[1]};
-        }
-        else if (overlappingType == OVERLAPS_2_WRAPS) {
-            return range1;
-        }
-        else if (overlappingType == OVERLAPS_1_WRAPS) {
-            return range2;
-        }
-        return new long[]{-1, -1};
     }
     
     public static int getOverlappingType(long[] range1, long[] range2) {
@@ -47,17 +46,18 @@ public class NumericRanges {
         long max1 = range1[1];
         long min2 = range2[0];
         long max2 = range2[1];
-        if (min1 >= min2 && max1 <= max2) {
-            return OVERLAPS_2_WRAPS;
-        }
-        else if (min2 >= min1 && max2 <= max1) {
-            return OVERLAPS_1_WRAPS;
-        }
-        else if ((min2 >= min1 && min2 <= max1) && max2 >= max1) {
-            return OVERLAPS_1_MINOR;
-        }
-        else if ((min1 >= min2 && min1 <= max2)  && max1 >= max2) {
-            return OVERLAPS_2_MINOR;
+        if (min1 >= min2) {
+            if (max1 <= max2) {
+                return OVERLAPS_2_WRAPS;
+            } else if (min1 <= max2) {
+                return OVERLAPS_2_MINOR;
+            }
+        } else {
+            if (max1 >= max2) {
+                return OVERLAPS_1_WRAPS;
+            } else if (max1 >= min2) {
+                return OVERLAPS_1_MINOR;
+            }
         }
         return NO_OVERLAPS;
         
index 55a7f9a0d1eacde2b9a5c6a0452d89369c6f4e8e..0fbc65ec00c151ac168f9e02d70172bd81f4ea8d 100644 (file)
@@ -26,37 +26,7 @@ import org.apache.poi.util.Internal;
 import org.apache.poi.wp.usermodel.Paragraph;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTProofErr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRunTrackChange;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtRun;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSimpleField;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSmartTagRun;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
 
 /**
  * <p>A Paragraph within a Document, Table, Header etc.</p>
@@ -114,8 +84,8 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
                     for (XWPFParagraph p : footnote.getParagraphs()) {
                         if (!first) {
                             footnoteText.append("\n");
-                            first = false;
                         }
+                        first = false;
                         footnoteText.append(p.getText());
                     }
 
@@ -204,6 +174,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
         return !paragraph.getDomNode().hasChildNodes();
     }
 
+    @Override
     public XWPFDocument getDocument() {
         return document;
     }
@@ -240,8 +211,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     public String getStyleID() {
         if (paragraph.getPPr() != null) {
             if (paragraph.getPPr().getPStyle() != null) {
-                if (paragraph.getPPr().getPStyle().getVal() != null)
+                if (paragraph.getPPr().getPStyle().getVal() != null) {
                     return paragraph.getPPr().getPStyle().getVal();
+                }
             }
         }
         return null;
@@ -257,8 +229,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     public BigInteger getNumID() {
         if (paragraph.getPPr() != null) {
             if (paragraph.getPPr().getNumPr() != null) {
-                if (paragraph.getPPr().getNumPr().getNumId() != null)
+                if (paragraph.getPPr().getNumPr().getNumId() != null) {
                     return paragraph.getPPr().getNumPr().getNumId().getVal();
+                }
             }
         }
         return null;
@@ -270,10 +243,12 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
      * @param numPos
      */
     public void setNumID(BigInteger numPos) {
-        if (paragraph.getPPr() == null)
+        if (paragraph.getPPr() == null) {
             paragraph.addNewPPr();
-        if (paragraph.getPPr().getNumPr() == null)
+        }
+        if (paragraph.getPPr().getNumPr() == null) {
             paragraph.getPPr().addNewNumPr();
+        }
         if (paragraph.getPPr().getNumPr().getNumId() == null) {
             paragraph.getPPr().getNumPr().addNewNumId();
         }
@@ -289,8 +264,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     public BigInteger getNumIlvl() {
         if (paragraph.getPPr() != null) {
             if (paragraph.getPPr().getNumPr() != null) {
-                if (paragraph.getPPr().getNumPr().getIlvl() != null)
+                if (paragraph.getPPr().getNumPr().getIlvl() != null) {
                     return paragraph.getPPr().getNumPr().getIlvl().getVal();
+                }
             }
         }
         return null;
@@ -319,8 +295,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
                     }
                 }
                 if (level != null && level.getNumFmt() != null
-                        && level.getNumFmt().getVal() != null)
+                        && level.getNumFmt().getVal() != null) {
                     return level.getNumFmt().getVal().toString();
+                }
             }
         }
         return null;
@@ -339,26 +316,31 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
             if (num != null) {
                 BigInteger ilvl = getNumIlvl();
                 CTNum ctNum = num.getCTNum();
-                if (ctNum == null)
+                if (ctNum == null) {
                     return null;
+                }
 
                 CTDecimalNumber ctDecimalNumber = ctNum.getAbstractNumId();
-                if (ctDecimalNumber == null)
+                if (ctDecimalNumber == null) {
                     return null;
+                }
 
                 BigInteger abstractNumId = ctDecimalNumber.getVal();
-                if (abstractNumId == null)
+                if (abstractNumId == null) {
                     return null;
+                }
 
                 XWPFAbstractNum xwpfAbstractNum = numbering.getAbstractNum(abstractNumId);
 
-                if (xwpfAbstractNum == null)
+                if (xwpfAbstractNum == null) {
                     return null;
+                }
 
                 CTAbstractNum anum = xwpfAbstractNum.getCTAbstractNum();
 
-                if (anum == null)
+                if (anum == null) {
                     return null;
+                }
 
                 CTLvl level = null;
                 for (int i = 0; i < anum.sizeOfLvlArray(); i++) {
@@ -369,8 +351,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
                     }
                 }
                 if (level != null && level.getLvlText() != null
-                        && level.getLvlText().getVal() != null)
+                        && level.getLvlText().getVal() != null) {
                     return level.getLvlText().getVal().toString();
+                }
             }
         }
         return null;
@@ -486,10 +469,12 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     /**
      * @return The raw alignment value, {@link #getAlignment()} is suggested
      */
+    @Override
     public int getFontAlignment() {
         return getAlignment().getValue();
     }
 
+    @Override
     public void setFontAlignment(int align) {
         ParagraphAlignment pAlign = ParagraphAlignment.valueOf(align);
         setAlignment(pAlign);
@@ -600,10 +585,11 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
         }
 
         CTBorder pr = (ct.isSetTop()) ? ct.getTop() : ct.addNewTop();
-        if (border.getValue() == Borders.NONE.getValue())
+        if (border.getValue() == Borders.NONE.getValue()) {
             ct.unsetTop();
-        else
+        } else {
             pr.setVal(STBorder.Enum.forInt(border.getValue()));
+        }
     }
 
     /**
@@ -654,10 +640,11 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     public void setBorderBottom(Borders border) {
         CTPBdr ct = getCTPBrd(true);
         CTBorder pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom();
-        if (border.getValue() == Borders.NONE.getValue())
+        if (border.getValue() == Borders.NONE.getValue()) {
             ct.unsetBottom();
-        else
+        } else {
             pr.setVal(STBorder.Enum.forInt(border.getValue()));
+        }
     }
 
     /**
@@ -703,10 +690,11 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     public void setBorderLeft(Borders border) {
         CTPBdr ct = getCTPBrd(true);
         CTBorder pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft();
-        if (border.getValue() == Borders.NONE.getValue())
+        if (border.getValue() == Borders.NONE.getValue()) {
             ct.unsetLeft();
-        else
+        } else {
             pr.setVal(STBorder.Enum.forInt(border.getValue()));
+        }
     }
 
     /**
@@ -752,10 +740,11 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     public void setBorderRight(Borders border) {
         CTPBdr ct = getCTPBrd(true);
         CTBorder pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
-        if (border.getValue() == Borders.NONE.getValue())
+        if (border.getValue() == Borders.NONE.getValue()) {
             ct.unsetRight();
-        else
+        } else {
             pr.setVal(STBorder.Enum.forInt(border.getValue()));
+        }
     }
 
     /**
@@ -805,10 +794,11 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     public void setBorderBetween(Borders border) {
         CTPBdr ct = getCTPBrd(true);
         CTBorder pr = ct.isSetBetween() ? ct.getBetween() : ct.addNewBetween();
-        if (border.getValue() == Borders.NONE.getValue())
+        if (border.getValue() == Borders.NONE.getValue()) {
             ct.unsetBetween();
-        else
+        } else {
             pr.setVal(STBorder.Enum.forInt(border.getValue()));
+        }
     }
 
     /**
@@ -857,10 +847,11 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
         CTPPr ppr = getCTPPr();
         CTOnOff ctPageBreak = ppr.isSetPageBreakBefore() ? ppr
                 .getPageBreakBefore() : ppr.addNewPageBreakBefore();
-        if (pageBreak)
+        if (pageBreak) {
             ctPageBreak.setVal(STOnOff.TRUE);
-        else
+        } else {
             ctPageBreak.setVal(STOnOff.FALSE);
+        }
     }
 
     /**
@@ -1228,26 +1219,32 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
         indent.setFirstLine(bi);
     }
 
+    @Override
     public int getIndentFromLeft() {
         return getIndentationLeft();
     }
 
+    @Override
     public void setIndentFromLeft(int dxaLeft) {
         setIndentationLeft(dxaLeft);
     }
 
+    @Override
     public int getIndentFromRight() {
         return getIndentationRight();
     }
 
+    @Override
     public void setIndentFromRight(int dxaRight) {
         setIndentationRight(dxaRight);
     }
 
+    @Override
     public int getFirstLineIndent() {
         return getIndentationFirstLine();
     }
 
+    @Override
     public void setFirstLineIndent(int first) {
         setIndentationFirstLine(first);
     }
@@ -1260,6 +1257,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
      *
      * @return boolean
      */
+    @Override
     public boolean isWordWrapped() {
         CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
                 .getWordWrap() : null;
@@ -1279,13 +1277,15 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
      *
      * @param wrap - boolean
      */
+    @Override
     public void setWordWrapped(boolean wrap) {
         CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
                 .getWordWrap() : getCTPPr().addNewWordWrap();
-        if (wrap)
+        if (wrap) {
             wordWrap.setVal(STOnOff.TRUE);
-        else
+        } else {
             wordWrap.unsetVal();
+        }
     }
 
     public boolean isWordWrap() {
@@ -1325,8 +1325,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     private CTPBdr getCTPBrd(boolean create) {
         CTPPr pr = getCTPPr();
         CTPBdr ct = pr.isSetPBdr() ? pr.getPBdr() : null;
-        if (create && ct == null)
+        if (create && ct == null) {
             ct = pr.addNewPBdr();
+        }
         return ct;
     }
 
@@ -1337,8 +1338,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     private CTSpacing getCTSpacing(boolean create) {
         CTPPr pr = getCTPPr();
         CTSpacing ct = pr.getSpacing() == null ? null : pr.getSpacing();
-        if (create && ct == null)
+        if (create && ct == null) {
             ct = pr.addNewSpacing();
+        }
         return ct;
     }
 
@@ -1349,8 +1351,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     private CTInd getCTInd(boolean create) {
         CTPPr pr = getCTPPr();
         CTInd ct = pr.getInd() == null ? null : pr.getInd();
-        if (create && ct == null)
+        if (create && ct == null) {
             ct = pr.addNewInd();
+        }
         return ct;
     }
 
@@ -1536,8 +1539,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
             for (int j = startText; j <= endText; j++) {
                 String tmpText = tArray[j].getStringValue();
                 int startChar = 0, endChar = tmpText.length() - 1;
-                if ((j == textBegin) && (i == runBegin))
+                if ((j == textBegin) && (i == runBegin)) {
                     startChar = charBegin;
+                }
                 if ((j == textEnd) && (i == runEnd)) {
                     endChar = charEnd;
                 }
@@ -1585,10 +1589,12 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
      *
      * @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
      */
+    @Override
     public BodyElementType getElementType() {
         return BodyElementType.PARAGRAPH;
     }
 
+    @Override
     public IBody getBody() {
         return part;
     }
@@ -1598,6 +1604,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
      *
      * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
      */
+    @Override
     public POIXMLDocumentPart getPart() {
         if (part != null) {
             return part.getPart();
@@ -1610,6 +1617,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
      *
      * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
      */
+    @Override
     public BodyType getPartType() {
         return part.getPartType();
     }
index e3f51e774d4475afe8ce47f11feb51659fc8f49f..d0dc8152c88605ee8ec27c78fccc790061647d88 100644 (file)
@@ -156,11 +156,7 @@ public class XWPFPictureData extends POIXMLDocumentPart {
             } catch (IOException e) {
                 throw new POIXMLException(e);
             } finally {
-                try {
-                    if (is != null) is.close();
-                } catch (IOException e) {
-                    throw new POIXMLException(e);
-                }
+                IOUtils.closeQuietly(is);
             }
             this.checksum = IOUtils.calculateChecksum(data);
         }
index 202b9e18e95b5f6747742b78bc046b8ac4359cd3..bd13e13c03479f460a2ed41d3271042d752d5b82 100644 (file)
@@ -36,7 +36,11 @@ import java.io.FileOutputStream;
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.io.OutputStream;\r
-import java.net.*;\r
+import java.net.ConnectException;\r
+import java.net.HttpURLConnection;\r
+import java.net.MalformedURLException;\r
+import java.net.SocketTimeoutException;\r
+import java.net.URL;\r
 import java.security.Key;\r
 import java.security.KeyPair;\r
 import java.security.KeyStore;\r
@@ -389,17 +393,16 @@ public class TestSignatureInfo {
                 throw e;\r
             }\r
             if((e.getCause() instanceof ConnectException) || (e.getCause() instanceof SocketTimeoutException)) {\r
-                Assume.assumeTrue("Only allowing ConnectException with 'timed out' as message here, but had: " + e,\r
+                Assume.assumeFalse("Only allowing ConnectException with 'timed out' as message here, but had: " + e,\r
                         e.getCause().getMessage().contains("timed out"));\r
             } else if (e.getCause() instanceof IOException) {\r
-                Assume.assumeTrue("Only allowing IOException with 'Error contacting TSP server' as message here, but had: " + e,\r
+                Assume.assumeFalse("Only allowing IOException with 'Error contacting TSP server' as message here, but had: " + e,\r
                         e.getCause().getMessage().contains("Error contacting TSP server"));\r
             } else if (e.getCause() instanceof RuntimeException) {\r
-                Assume.assumeTrue("Only allowing RuntimeException with 'This site is cur' as message here, but had: " + e,\r
+                Assume.assumeFalse("Only allowing RuntimeException with 'This site is cur' as message here, but had: " + e,\r
                         e.getCause().getMessage().contains("This site is cur"));\r
-            } else {\r
-                throw e;\r
             }\r
+            throw e;\r
         }\r
         \r
         // verify\r
@@ -557,7 +560,9 @@ public class TestSignatureInfo {
                 boolean b = si.verifySignature();\r
                 assertTrue("Signature not correctly calculated for " + ha, b);\r
             } finally {\r
-                if (pkg != null) pkg.close();\r
+                if (pkg != null) {\r
+                    pkg.close();\r
+                }\r
             }\r
         }\r
     }\r