]> source.dussan.org Git - poi.git/commitdiff
Fix some Eclipse warnings
authorDominik Stadler <centic@apache.org>
Fri, 2 Jan 2015 21:06:51 +0000 (21:06 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 2 Jan 2015 21:06:51 +0000 (21:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1649123 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java
src/examples/src/org/apache/poi/xslf/usermodel/Tutorial1.java
src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java
src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithPictures.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithRichText.java
src/examples/src/org/apache/poi/xwpf/usermodel/UpdateEmbeddedDoc.java
src/excelant/java/org/apache/poi/ss/excelant/ExcelAntHandlerTask.java
src/java/org/apache/poi/hssf/model/InternalSheet.java
src/java/org/apache/poi/hssf/util/HSSFColor.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java

index f6e6a847d61a9e3d3e8384e05319a98a6ed1d143..de90c52d20716241ee0ee4cb23236fdb2485e893 100644 (file)
@@ -63,90 +63,101 @@ public class PieChartDemo {
         }\r
 \r
         BufferedReader modelReader = new BufferedReader(new FileReader(args[1]));\r
-\r
-        String chartTitle = modelReader.readLine();  // first line is chart title\r
-\r
-        XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(args[0]));\r
-        XSLFSlide slide = pptx.getSlides()[0];\r
-\r
-        // find chart in the slide\r
-        XSLFChart chart = null;\r
-        for(POIXMLDocumentPart part : slide.getRelations()){\r
-            if(part instanceof XSLFChart){\r
-                chart = (XSLFChart) part;\r
-                break;\r
+        try {\r
+            String chartTitle = modelReader.readLine();  // first line is chart title\r
+    \r
+            XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(args[0]));\r
+            XSLFSlide slide = pptx.getSlides()[0];\r
+    \r
+            // find chart in the slide\r
+            XSLFChart chart = null;\r
+            for(POIXMLDocumentPart part : slide.getRelations()){\r
+                if(part instanceof XSLFChart){\r
+                    chart = (XSLFChart) part;\r
+                    break;\r
+                }\r
             }\r
+    \r
+            if(chart == null) throw new IllegalStateException("chart not found in the template");\r
+    \r
+            // embedded Excel workbook that holds the chart data\r
+            POIXMLDocumentPart xlsPart = chart.getRelations().get(0);\r
+            XSSFWorkbook wb = new XSSFWorkbook();\r
+            try {\r
+                XSSFSheet sheet = wb.createSheet();\r
+        \r
+                CTChart ctChart = chart.getCTChart();\r
+                CTPlotArea plotArea = ctChart.getPlotArea();\r
+        \r
+                CTPieChart pieChart = plotArea.getPieChartArray(0);\r
+                //Pie Chart Series\r
+                CTPieSer ser = pieChart.getSerArray(0);\r
+        \r
+                // Series Text\r
+                CTSerTx tx = ser.getTx();\r
+                tx.getStrRef().getStrCache().getPtArray(0).setV(chartTitle);\r
+                sheet.createRow(0).createCell(1).setCellValue(chartTitle);\r
+                String titleRef = new CellReference(sheet.getSheetName(), 0, 1, true, true).formatAsString();\r
+                tx.getStrRef().setF(titleRef);\r
+        \r
+                // Category Axis Data\r
+                CTAxDataSource cat = ser.getCat();\r
+                CTStrData strData = cat.getStrRef().getStrCache();\r
+        \r
+                // Values\r
+                CTNumDataSource val = ser.getVal();\r
+                CTNumData numData = val.getNumRef().getNumCache();\r
+        \r
+                strData.setPtArray(null);  // unset old axis text\r
+                numData.setPtArray(null);  // unset old values\r
+        \r
+                // set model\r
+                int idx = 0;\r
+                int rownum = 1;\r
+                String ln;\r
+                while((ln = modelReader.readLine()) != null){\r
+                    String[] vals = ln.split("\\s+");\r
+                    CTNumVal numVal = numData.addNewPt();\r
+                    numVal.setIdx(idx);\r
+                    numVal.setV(vals[1]);\r
+        \r
+                    CTStrVal sVal = strData.addNewPt();\r
+                    sVal.setIdx(idx);\r
+                    sVal.setV(vals[0]);\r
+        \r
+                    idx++;\r
+                    XSSFRow row = sheet.createRow(rownum++);\r
+                    row.createCell(0).setCellValue(vals[0]);\r
+                    row.createCell(1).setCellValue(Double.valueOf(vals[1]));\r
+                }\r
+                numData.getPtCount().setVal(idx);\r
+                strData.getPtCount().setVal(idx);\r
+        \r
+                String numDataRange = new CellRangeAddress(1, rownum-1, 1, 1).formatAsString(sheet.getSheetName(), true);\r
+                val.getNumRef().setF(numDataRange);\r
+                String axisDataRange = new CellRangeAddress(1, rownum-1, 0, 0).formatAsString(sheet.getSheetName(), true);\r
+                cat.getStrRef().setF(axisDataRange);\r
+        \r
+                // updated the embedded workbook with the data\r
+                OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream();\r
+                try {\r
+                    wb.write(xlsOut);\r
+                } finally {\r
+                    xlsOut.close();\r
+                }\r
+        \r
+                // save the result\r
+                OutputStream out = new FileOutputStream("pie-chart-demo-output.pptx");\r
+                try {\r
+                    pptx.write(out);\r
+                } finally {\r
+                    out.close();\r
+                }\r
+            } finally {\r
+                wb.close();\r
+            }\r
+        } finally {\r
+            modelReader.close();\r
         }\r
-\r
-        if(chart == null) throw new IllegalStateException("chart not found in the template");\r
-\r
-        // embedded Excel workbook that holds the chart data\r
-        POIXMLDocumentPart xlsPart = chart.getRelations().get(0);\r
-        XSSFWorkbook wb = new XSSFWorkbook();\r
-        XSSFSheet sheet = wb.createSheet();\r
-\r
-        CTChart ctChart = chart.getCTChart();\r
-        CTPlotArea plotArea = ctChart.getPlotArea();\r
-\r
-        CTPieChart pieChart = plotArea.getPieChartArray(0);\r
-        //Pie Chart Series\r
-        CTPieSer ser = pieChart.getSerArray(0);\r
-\r
-        // Series Text\r
-        CTSerTx tx = ser.getTx();\r
-        tx.getStrRef().getStrCache().getPtArray(0).setV(chartTitle);\r
-        sheet.createRow(0).createCell(1).setCellValue(chartTitle);\r
-        String titleRef = new CellReference(sheet.getSheetName(), 0, 1, true, true).formatAsString();\r
-        tx.getStrRef().setF(titleRef);\r
-\r
-\r
-        // Category Axis Data\r
-        CTAxDataSource cat = ser.getCat();\r
-        CTStrData strData = cat.getStrRef().getStrCache();\r
-\r
-        // Values\r
-        CTNumDataSource val = ser.getVal();\r
-        CTNumData numData = val.getNumRef().getNumCache();\r
-\r
-        strData.setPtArray(null);  // unset old axis text\r
-        numData.setPtArray(null);  // unset old values\r
-\r
-\r
-        // set model\r
-        int idx = 0;\r
-        int rownum = 1;\r
-        String ln;\r
-        while((ln = modelReader.readLine()) != null){\r
-            String[] vals = ln.split("\\s+");\r
-            CTNumVal numVal = numData.addNewPt();\r
-            numVal.setIdx(idx);\r
-            numVal.setV(vals[1]);\r
-\r
-            CTStrVal sVal = strData.addNewPt();\r
-            sVal.setIdx(idx);\r
-            sVal.setV(vals[0]);\r
-\r
-            idx++;\r
-            XSSFRow row = sheet.createRow(rownum++);\r
-            row.createCell(0).setCellValue(vals[0]);\r
-            row.createCell(1).setCellValue(Double.valueOf(vals[1]));\r
-        }\r
-        numData.getPtCount().setVal(idx);\r
-        strData.getPtCount().setVal(idx);\r
-\r
-        String numDataRange = new CellRangeAddress(1, rownum-1, 1, 1).formatAsString(sheet.getSheetName(), true);\r
-        val.getNumRef().setF(numDataRange);\r
-        String axisDataRange = new CellRangeAddress(1, rownum-1, 0, 0).formatAsString(sheet.getSheetName(), true);\r
-        cat.getStrRef().setF(axisDataRange);\r
-\r
-        // updated the embedded workbook with the data\r
-        OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream();\r
-        wb.write(xlsOut);\r
-        xlsOut.close();\r
-\r
-        // save the result\r
-        FileOutputStream out = new FileOutputStream("pie-chart-demo-output.pptx");\r
-        pptx.write(out);\r
-        out.close();\r
     }\r
 }\r
index 726013d82c1757b4e39cf9ca4cf179a74a3d05ac..93d437b913513d5f12b1cc7081e25340d7bccd2b 100644 (file)
@@ -34,7 +34,7 @@ public class Tutorial1 {
         XMLSlideShow ppt = new XMLSlideShow();\r
 \r
         // XSLFSlide#createSlide() with no arguments creates a blank slide\r
-        XSLFSlide blankSlide = ppt.createSlide();\r
+        /*XSLFSlide blankSlide =*/ ppt.createSlide();\r
 \r
         \r
         XSLFSlideMaster master = ppt.getSlideMasters()[0];\r
index 607248a7533c333e6b839ddc43e3f320f5a28b22..a64e25ad722bfb3f0b850e9902efc7b559dc4c38 100644 (file)
@@ -41,7 +41,7 @@ public class Tutorial5 {
         byte[] data = IOUtils.toByteArray(new FileInputStream(img));\r
         int pictureIndex = ppt.addPicture(data, XSLFPictureData.PICTURE_TYPE_PNG);\r
 \r
-        XSLFPictureShape shape = slide.createPicture(pictureIndex);\r
+        /*XSLFPictureShape shape =*/ slide.createPicture(pictureIndex);\r
 \r
         FileOutputStream out = new FileOutputStream("images.pptx");\r
         ppt.write(out);\r
index 16b155d3f2938960d0a660ac875c5411222361ad..b006eb86a121df8e839d469a4f82796cb211fac1 100644 (file)
@@ -47,7 +47,7 @@ public class Step2 {
         }
 
         // blank slide
-        XSLFSlide blankSlide = ppt.createSlide();
+        /*XSLFSlide blankSlide =*/ ppt.createSlide();
 
         XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0];
 
index a2a914335e1df92b2501250e45484eceb20536bf..6607beb3fce95c7c6c848d7cc96de6708d046ae4 100644 (file)
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.OutputStream;
 
 /**
  * Demonstrates how to insert pictures in a SpreadsheetML document
@@ -36,34 +37,41 @@ public class WorkingWithPictures {
 
         //create a new workbook
         Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
-        CreationHelper helper = wb.getCreationHelper();
-
-        //add a picture in this workbook.
-        InputStream is = new FileInputStream(args[0]);
-        byte[] bytes = IOUtils.toByteArray(is);
-        is.close();
-        int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
-
-        //create sheet
-        Sheet sheet = wb.createSheet();
-
-        //create drawing
-        Drawing drawing = sheet.createDrawingPatriarch();
-
-        //add a picture shape
-        ClientAnchor anchor = helper.createClientAnchor();
-        anchor.setCol1(1);
-        anchor.setRow1(1);
-        Picture pict = drawing.createPicture(anchor, pictureIdx);
-
-        //auto-size picture
-        pict.resize(2);
-
-        //save workbook
-        String file = "picture.xls";
-        if(wb instanceof XSSFWorkbook) file += "x";
-        FileOutputStream fileOut = new FileOutputStream(file);
-        wb.write(fileOut);
-        fileOut.close();
+        try {
+            CreationHelper helper = wb.getCreationHelper();
+    
+            //add a picture in this workbook.
+            InputStream is = new FileInputStream(args[0]);
+            byte[] bytes = IOUtils.toByteArray(is);
+            is.close();
+            int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
+    
+            //create sheet
+            Sheet sheet = wb.createSheet();
+    
+            //create drawing
+            Drawing drawing = sheet.createDrawingPatriarch();
+    
+            //add a picture shape
+            ClientAnchor anchor = helper.createClientAnchor();
+            anchor.setCol1(1);
+            anchor.setRow1(1);
+            Picture pict = drawing.createPicture(anchor, pictureIdx);
+    
+            //auto-size picture
+            pict.resize(2);
+    
+            //save workbook
+            String file = "picture.xls";
+            if(wb instanceof XSSFWorkbook) file += "x";
+            OutputStream fileOut = new FileOutputStream(file);
+            try {
+                wb.write(fileOut);
+            } finally {
+                fileOut.close();
+            }
+        } finally {
+            wb.close();
+        }
     }
 }
index d019ab8d8b6f3d039fc32bb63c06875de6f7fea7..09def94461678a998c5e376977000a12af9855d6 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.xssf.usermodel.examples;
 import org.apache.poi.xssf.usermodel.*;
 
 import java.io.FileOutputStream;
+import java.io.OutputStream;
 
 /**
  * Demonstrates how to work with rich text
@@ -29,33 +30,39 @@ public class WorkingWithRichText {
     public static void main(String[] args) throws Exception {
 
         XSSFWorkbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
-
-        XSSFSheet sheet = wb.createSheet();
-        XSSFRow row = sheet.createRow((short) 2);
-
-        XSSFCell cell = row.createCell(1);
-        XSSFRichTextString rt = new XSSFRichTextString("The quick brown fox");
-
-        XSSFFont font1 = wb.createFont();
-        font1.setBold(true);
-        font1.setColor(new XSSFColor(new java.awt.Color(255, 0, 0)));
-        rt.applyFont(0, 10, font1);
-
-        XSSFFont font2 = wb.createFont();
-        font2.setItalic(true);
-        font2.setUnderline(XSSFFont.U_DOUBLE);
-        font2.setColor(new XSSFColor(new java.awt.Color(0, 255, 0)));
-        rt.applyFont(10, 19, font2);
-
-        XSSFFont font3 = wb.createFont();
-        font3.setColor(new XSSFColor(new java.awt.Color(0, 0, 255)));
-        rt.append(" Jumped over the lazy dog", font3);
-
-        cell.setCellValue(rt);
-
-        // Write the output to a file
-        FileOutputStream fileOut = new FileOutputStream("xssf-richtext.xlsx");
-        wb.write(fileOut);
-        fileOut.close();
+        try {
+            XSSFSheet sheet = wb.createSheet();
+            XSSFRow row = sheet.createRow((short) 2);
+    
+            XSSFCell cell = row.createCell(1);
+            XSSFRichTextString rt = new XSSFRichTextString("The quick brown fox");
+    
+            XSSFFont font1 = wb.createFont();
+            font1.setBold(true);
+            font1.setColor(new XSSFColor(new java.awt.Color(255, 0, 0)));
+            rt.applyFont(0, 10, font1);
+    
+            XSSFFont font2 = wb.createFont();
+            font2.setItalic(true);
+            font2.setUnderline(XSSFFont.U_DOUBLE);
+            font2.setColor(new XSSFColor(new java.awt.Color(0, 255, 0)));
+            rt.applyFont(10, 19, font2);
+    
+            XSSFFont font3 = wb.createFont();
+            font3.setColor(new XSSFColor(new java.awt.Color(0, 0, 255)));
+            rt.append(" Jumped over the lazy dog", font3);
+    
+            cell.setCellValue(rt);
+    
+            // Write the output to a file
+            OutputStream fileOut = new FileOutputStream("xssf-richtext.xlsx");
+            try {
+                wb.write(fileOut);
+            } finally {
+                fileOut.close();
+            }
+        } finally {
+            wb.close();
+        }
     }
 }
index ffdb7e2049e7fc59b2dc8ffa8a1847e8d4860c31..06493ce3561d302992016616adaa25913031ad42 100644 (file)
@@ -19,6 +19,8 @@
 \r
 package org.apache.poi.xwpf.usermodel;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+\r
 import java.io.File;\r
 import java.io.FileInputStream;\r
 import java.io.FileOutputStream;\r
@@ -27,7 +29,6 @@ import java.io.IOException;
 import java.util.List;\r
 import java.util.Iterator;\r
 \r
-import junit.framework.Assert;\r
 import org.apache.poi.openxml4j.opc.PackagePart;\r
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;\r
 import org.apache.poi.ss.usermodel.WorkbookFactory;\r
@@ -194,7 +195,7 @@ public class UpdateEmbeddedDoc {
                     sheet = workbook.getSheetAt(SHEET_NUM);\r
                     row = sheet.getRow(ROW_NUM);\r
                     cell = row.getCell(CELL_NUM);\r
-                    Assert.assertEquals(cell.getNumericCellValue(), NEW_VALUE);\r
+                    assertEquals(cell.getNumericCellValue(), NEW_VALUE, 0.0001);\r
                 }\r
             }\r
         }\r
index eef50c7a925ec9d575788471b1db31cea53af0e8..eaf04007ce4ad0de40b57370b3481286ee131f7f 100644 (file)
@@ -61,7 +61,7 @@ public class ExcelAntHandlerTask extends Task {
     public void execute() throws BuildException {\r
         log( "handling the workbook with class " + className, Project.MSG_INFO ) ;\r
         try {\r
-            Class clazz = Class.forName( className ) ;\r
+            Class<?> clazz = Class.forName( className ) ;\r
             Object handlerObj = clazz.newInstance() ;\r
             if( handlerObj instanceof IExcelAntWorkbookHandler ) {\r
                 IExcelAntWorkbookHandler iHandler = (IExcelAntWorkbookHandler)handlerObj ;\r
index 9f0701e1602378d96aa596738c73ebc62ec75f78..078cfaa3dfc33ce66571128ef95c47df11130d9a 100644 (file)
@@ -1627,9 +1627,9 @@ public final class InternalSheet {
 
     private void recalcRowGutter() {
         int maxLevel = 0;
-        Iterator iterator = _rowsAggregate.getIterator();
+        Iterator<RowRecord> iterator = _rowsAggregate.getIterator();
         while (iterator.hasNext()) {
-            RowRecord rowRecord = (RowRecord) iterator.next();
+            RowRecord rowRecord = iterator.next();
             maxLevel = Math.max(rowRecord.getOutlineLevel(), maxLevel);
         }
 
index c449b656aeac6f205a59b32f2d5a51f17390ba79..493db7f38f7073685130f85e8cce821f55588f17 100644 (file)
@@ -164,7 +164,7 @@ public class HSSFColor implements Color {
 
             String hexString = color.getHexString();
             if (result.containsKey(hexString)) {
-               HSSFColor other = (HSSFColor)result.get(hexString);
+               HSSFColor other = result.get(hexString);
                 throw new RuntimeException(
                                "Dup color hexString (" + hexString
                         + ") for color (" + color.getClass().getName() + ") - "
index d7f4af1e86569e5186d1517da97b18cc719c546c..0eb6e4788397195ed462929553444d065cc8e799 100644 (file)
 package org.apache.poi.xssf.usermodel;
 
 import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -52,29 +46,11 @@ import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.NumberEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.formula.functions.Function;
-import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.CellValue;
-import org.apache.poi.ss.usermodel.ClientAnchor;
-import org.apache.poi.ss.usermodel.Comment;
-import org.apache.poi.ss.usermodel.CreationHelper;
-import org.apache.poi.ss.usermodel.DataFormatter;
-import org.apache.poi.ss.usermodel.DateUtil;
-import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.FormulaError;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.Hyperlink;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.usermodel.Name;
-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.WorkbookFactory;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.AreaReference;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.ss.util.RegionUtil;
 import org.apache.poi.util.TempFile;
 import org.apache.poi.xssf.XLSBUnsupportedException;
 import org.apache.poi.xssf.XSSFITestDataProvider;
@@ -1800,9 +1776,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
     /**
      * New hyperlink with no initial cell reference, still need
      *  to be able to change it
+     * @throws IOException 
      */
     @Test
-    public void testBug56527() {
+    public void testBug56527() throws IOException {
         XSSFWorkbook wb = new XSSFWorkbook();
         XSSFSheet sheet = wb.createSheet();
         XSSFCreationHelper creationHelper = wb.getCreationHelper();
@@ -1829,6 +1806,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         assertEquals(3, hyperlink.getFirstColumn());
         assertEquals(5, hyperlink.getLastRow());
         assertEquals(3, hyperlink.getLastColumn());
+        wb.close();
     }
     
     /**
index b36da1aadfec04a439d45fce389b0a318fd3cf86..a203ae4c2b04259dd423e4da4e056a8b545d62c9 100644 (file)
@@ -64,7 +64,7 @@ public final class TestMergeCellsRecord extends TestCase {
        };
        public void testMCTable_bug46009() {
                MergedCellsTable mct = new MergedCellsTable();
-               List recList = new ArrayList();
+               List<Record> recList = new ArrayList<Record>();
                CellRangeAddress[] cras = new CellRangeAddress[] {
                                new CellRangeAddress(0, 0, 0, 3), 
                };