Sonar fix - Suppress "Make sure that command line arguments are used safely here." for examples

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876766 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2020-04-20 20:57:37 +00:00
parent 30280a9e5a
commit 65c8c6cd11
35 changed files with 130 additions and 65 deletions

View File

@ -30,7 +30,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/** /**
* Demonstrates how you can extract embedded data from a .xls file * Demonstrates how you can extract embedded data from a .xls file
*/ */
@SuppressWarnings({"java:S106","java:S4823"}) @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class EmbeddedObjects { public final class EmbeddedObjects {
private EmbeddedObjects() {} private EmbeddedObjects() {}

View File

@ -32,6 +32,7 @@ import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph; import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.hwpf.usermodel.Range;
@SuppressWarnings({"java:S106","java:S4823"})
public final class Word2Forrest public final class Word2Forrest
{ {
Writer _out; Writer _out;

View File

@ -199,6 +199,7 @@ import org.apache.poi.util.IOUtils;
* 2mm have been noted in testing. Further investigation will * 2mm have been noted in testing. Further investigation will
* continue to rectify this issue. * continue to rectify this issue.
*/ */
@SuppressWarnings({"java:S106","java:S4823"})
public class AddDimensionedImage { public class AddDimensionedImage {
// Four constants that determine how - and indeed whether - the rows // Four constants that determine how - and indeed whether - the rows

View File

@ -45,8 +45,8 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@SuppressWarnings("java:S1192") @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class BusinessPlan { public final class BusinessPlan {
private static final String[] titles = { private static final String[] titles = {
"ID", "Project Name", "Owner", "Days", "Start", "End"}; "ID", "Project Name", "Owner", "Days", "Start", "End"};
@ -88,6 +88,8 @@ public class BusinessPlan {
null, null, null, null, null, "x", null, null, null, null, null}, null, null, null, null, null, "x", null, null, null, null, null},
}; };
private BusinessPlan() {}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Workbook wb; Workbook wb;

View File

@ -17,16 +17,26 @@
package org.apache.poi.ss.examples; package org.apache.poi.ss.examples;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.Calendar; import java.util.Calendar;
import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/** /**
* A monthly calendar created using Apache POI. Each month is on a separate sheet. * A monthly calendar created using Apache POI. Each month is on a separate sheet.
@ -37,7 +47,8 @@ import java.util.HashMap;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class CalendarDemo { @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class CalendarDemo {
private static final String[] days = { private static final String[] days = {
"Sunday", "Monday", "Tuesday", "Sunday", "Monday", "Tuesday",
@ -47,6 +58,8 @@ public class CalendarDemo {
"January", "February", "March","April", "May", "June","July", "August", "January", "February", "March","April", "May", "June","July", "August",
"September","October", "November", "December"}; "September","October", "November", "December"};
private CalendarDemo() {}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();

View File

@ -37,12 +37,15 @@ import org.apache.poi.xssf.usermodel.XSSFFont;
/** /**
* Demonstrates how to read excel styles for cells * Demonstrates how to read excel styles for cells
*/ */
public class CellStyleDetails { @SuppressWarnings({"java:S106","java:S4823"})
public final class CellStyleDetails {
private CellStyleDetails() {}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
if(args.length == 0) { if(args.length == 0) {
throw new IllegalArgumentException("Filename must be given"); throw new IllegalArgumentException("Filename must be given");
} }
try (Workbook wb = WorkbookFactory.create(new File(args[0]))) { try (Workbook wb = WorkbookFactory.create(new File(args[0]))) {
DataFormatter formatter = new DataFormatter(); DataFormatter formatter = new DataFormatter();
@ -82,7 +85,7 @@ public class CellStyleDetails {
} }
} }
} }
private static String renderColor(Color color) { private static String renderColor(Color color) {
if(color instanceof HSSFColor) { if(color instanceof HSSFColor) {
return ((HSSFColor)color).getHexString(); return ((HSSFColor)color).getHexString();

View File

@ -57,8 +57,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* http://www.contextures.com/xlcondformat03.html * http://www.contextures.com/xlcondformat03.html
* </p> * </p>
*/ */
@SuppressWarnings("java:S1192") @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class ConditionalFormats { public final class ConditionalFormats {
private ConditionalFormats() {}
/** /**
* generates a sample workbook with conditional formatting, * generates a sample workbook with conditional formatting,

View File

@ -36,13 +36,16 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/** /**
* Excel Border Drawing - examples * Excel Border Drawing - examples
* *
* <p> * <p>
* Partly based on the code snippets from * Partly based on the code snippets from
* org.apache.poi.ss.examples.ConditionalFormats * org.apache.poi.ss.examples.ConditionalFormats
* </p> * </p>
*/ */
public class DrawingBorders { @SuppressWarnings({"java:S106","java:S4823"})
public final class DrawingBorders {
private DrawingBorders() {}
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
try (Workbook wb = (args.length > 0 && args[0].equals("-xls")) try (Workbook wb = (args.length > 0 && args[0].equals("-xls"))

View File

@ -80,7 +80,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* } * }
* </pre> * </pre>
*/ */
@SuppressWarnings("java:S1192") @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class ExcelComparator { public class ExcelComparator {
private static final String CELL_DATA_DOES_NOT_MATCH = "Cell Data does not Match ::"; private static final String CELL_DATA_DOES_NOT_MATCH = "Cell Data does not Match ::";

View File

@ -43,12 +43,15 @@ import org.apache.xmlbeans.XmlException;
* Loads embedded resources from Workbooks. Code taken from the website: * Loads embedded resources from Workbooks. Code taken from the website:
* https://poi.apache.org/spreadsheet/quick-guide.html#Embedded * https://poi.apache.org/spreadsheet/quick-guide.html#Embedded
*/ */
public class LoadEmbedded { @SuppressWarnings({"java:S106","java:S4823"})
public static void main(String[] args) throws IOException, EncryptedDocumentException, OpenXML4JException, XmlException { public final class LoadEmbedded {
private LoadEmbedded() {}
public static void main(String[] args) throws IOException, EncryptedDocumentException, OpenXML4JException, XmlException {
Workbook wb = WorkbookFactory.create(new File(args[0])); Workbook wb = WorkbookFactory.create(new File(args[0]));
loadEmbedded(wb); loadEmbedded(wb);
} }
public static void loadEmbedded(Workbook wb) throws IOException, InvalidFormatException, OpenXML4JException, XmlException { public static void loadEmbedded(Workbook wb) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
if (wb instanceof HSSFWorkbook) { if (wb instanceof HSSFWorkbook) {
loadEmbedded((HSSFWorkbook)wb); loadEmbedded((HSSFWorkbook)wb);
@ -60,7 +63,7 @@ public class LoadEmbedded {
throw new IllegalArgumentException(wb.getClass().getName()); throw new IllegalArgumentException(wb.getClass().getName());
} }
} }
public static void loadEmbedded(HSSFWorkbook workbook) throws IOException { public static void loadEmbedded(HSSFWorkbook workbook) throws IOException {
for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) { for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
//the OLE2 Class Name of the object //the OLE2 Class Name of the object
@ -92,7 +95,7 @@ public class LoadEmbedded {
} }
} }
} }
public static void loadEmbedded(XSSFWorkbook workbook) throws IOException, InvalidFormatException, OpenXML4JException, XmlException { public static void loadEmbedded(XSSFWorkbook workbook) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
for (PackagePart pPart : workbook.getAllEmbeddedParts()) { for (PackagePart pPart : workbook.getAllEmbeddedParts()) {
String contentType = pPart.getContentType(); String contentType = pPart.getContentType();

View File

@ -45,8 +45,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@SuppressWarnings("java:S1192") @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class LoanCalculator { public final class LoanCalculator {
private LoanCalculator() {}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Workbook wb; Workbook wb;

View File

@ -42,8 +42,10 @@ import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@SuppressWarnings("java:S1192") @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class SSPerformanceTest { public final class SSPerformanceTest {
private SSPerformanceTest() {}
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
if (args.length < 4) { if (args.length < 4) {
usage("need at least four command arguments"); usage("need at least four command arguments");

View File

@ -44,18 +44,20 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@SuppressWarnings("java:S1192") @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class TimesheetDemo { public final class TimesheetDemo {
private static final String[] titles = { private static final String[] titles = {
"Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
"Total\nHrs", "Overtime\nHrs", "Regular\nHrs" "Total\nHrs", "Overtime\nHrs", "Regular\nHrs"
}; };
private static Object[][] sample_data = { private static final Object[][] sample_data = {
{"Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0}, {"Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},
{"Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0}, {"Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0},
}; };
private TimesheetDemo() {}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Workbook wb; Workbook wb;

View File

@ -129,6 +129,7 @@ import org.apache.poi.ss.usermodel.WorkbookFactory;
* either obeying Excel's or UNIX formatting * either obeying Excel's or UNIX formatting
* conventions. * conventions.
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class ToCSV { public class ToCSV {
private Workbook workbook; private Workbook workbook;

View File

@ -45,6 +45,7 @@ import org.apache.poi.ss.util.CellReference;
* files using Apache POI, along with how to handle errors whilst * files using Apache POI, along with how to handle errors whilst
* doing so. * doing so.
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class CheckFunctionsSupported { public class CheckFunctionsSupported {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
if (args.length < 1) { if (args.length < 1) {
@ -96,8 +97,8 @@ public class CheckFunctionsSupported {
} }
} }
private Workbook workbook; private final Workbook workbook;
private FormulaEvaluator evaluator; private final FormulaEvaluator evaluator;
public CheckFunctionsSupported(Workbook workbook) { public CheckFunctionsSupported(Workbook workbook) {
this.workbook = workbook; this.workbook = workbook;
this.evaluator = workbook.getCreationHelper().createFormulaEvaluator(); this.evaluator = workbook.getCreationHelper().createFormulaEvaluator();

View File

@ -16,11 +16,11 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.ss.examples.formula; package org.apache.poi.ss.examples.formula;
import java.io.File ; import java.io.File;
import org.apache.poi.ss.formula.functions.FreeRefFunction ; import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.apache.poi.ss.formula.udf.DefaultUDFFinder ; import org.apache.poi.ss.formula.udf.DefaultUDFFinder;
import org.apache.poi.ss.formula.udf.UDFFinder ; import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.FormulaEvaluator;
@ -28,26 +28,29 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellReference ; import org.apache.poi.ss.util.CellReference;
/** /**
* An example class of how to invoke a User Defined Function for a given * An example class of how to invoke a User Defined Function for a given
* XLS instance using POI's UDFFinder implementation. * XLS instance using POI's UDFFinder implementation.
*/ */
public class UserDefinedFunctionExample { @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class UserDefinedFunctionExample {
private UserDefinedFunctionExample() {}
public static void main(String[] args ) throws Exception {
public static void main( String[] args ) throws Exception {
if( args.length != 2 ) { if( args.length != 2 ) {
// e.g. src/examples/src/org/apache/poi/ss/examples/formula/mortgage-calculation.xls Sheet1!B4 // e.g. src/examples/src/org/apache/poi/ss/examples/formula/mortgage-calculation.xls Sheet1!B4
System.out.println( "usage: UserDefinedFunctionExample fileName cellId" ) ; System.out.println( "usage: UserDefinedFunctionExample fileName cellId" ) ;
return; return;
} }
System.out.println( "fileName: " + args[0] ) ; System.out.println( "fileName: " + args[0] ) ;
System.out.println( "cell: " + args[1] ) ; System.out.println( "cell: " + args[1] ) ;
File workbookFile = new File( args[0] ) ; File workbookFile = new File( args[0] ) ;
try (Workbook workbook = WorkbookFactory.create(workbookFile, null, true)) { try (Workbook workbook = WorkbookFactory.create(workbookFile, null, true)) {

View File

@ -53,8 +53,8 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* This example shows how to display a spreadsheet in HTML using the classes for * This example shows how to display a spreadsheet in HTML using the classes for
* spreadsheet display. * spreadsheet display.
*/ */
@SuppressWarnings("java:S1192") @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class ToHtml { public final class ToHtml {
private final Workbook wb; private final Workbook wb;
private final Appendable output; private final Appendable output;
private boolean completeHTML; private boolean completeHTML;

View File

@ -41,6 +41,7 @@ import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
/** /**
* Build a bar chart from a template pptx * Build a bar chart from a template pptx
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class BarChartDemo { public final class BarChartDemo {
private BarChartDemo() {} private BarChartDemo() {}

View File

@ -49,6 +49,7 @@ import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
/** /**
* Build a chart without reading template file * Build a chart without reading template file
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class ChartFromScratch { public final class ChartFromScratch {
private ChartFromScratch() {} private ChartFromScratch() {}

View File

@ -14,7 +14,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.apache.poi.xslf.usermodel; package org.apache.poi.xslf.usermodel;
@ -25,16 +25,16 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
/** /**
* Demonstrates how you can extract data from a .pptx file * Demonstrates how you can extract data from a .pptx file
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class DataExtraction { public final class DataExtraction {
private DataExtraction() {} private DataExtraction() {}
public static void main(String[] args) throws IOException, OpenXML4JException { public static void main(String[] args) throws IOException {
PrintStream out = System.out; PrintStream out = System.out;
@ -42,7 +42,7 @@ public final class DataExtraction {
out.println("Input file is required"); out.println("Input file is required");
return; return;
} }
FileInputStream is = new FileInputStream(args[0]); FileInputStream is = new FileInputStream(args[0]);
try (XMLSlideShow ppt = new XMLSlideShow(is)) { try (XMLSlideShow ppt = new XMLSlideShow(is)) {
is.close(); is.close();

View File

@ -14,7 +14,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.apache.poi.xslf.usermodel; package org.apache.poi.xslf.usermodel;
@ -25,6 +25,7 @@ import java.io.FileOutputStream;
/** /**
* Merge multiple pptx presentations together * Merge multiple pptx presentations together
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class MergePresentations { public final class MergePresentations {
private MergePresentations() {} private MergePresentations() {}

View File

@ -38,6 +38,7 @@ import org.apache.poi.xddf.usermodel.chart.XDDFPieChartData;
/** /**
* Build a pie chart from a template pptx * Build a pie chart from a template pptx
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class PieChartDemo { public final class PieChartDemo {
private PieChartDemo() {} private PieChartDemo() {}

View File

@ -31,6 +31,7 @@ import org.apache.poi.xslf.usermodel.XSLFTextShape;
/** /**
* Reading a .pptx presentation and printing basic shape properties * Reading a .pptx presentation and printing basic shape properties
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class Step1 { public final class Step1 {
private Step1() {} private Step1() {}

View File

@ -61,10 +61,11 @@ import org.xml.sax.XMLReader;
* For a more advanced implementation of SAX event parsing * For a more advanced implementation of SAX event parsing
* of XLSX files, see {@link XSSFEventBasedExcelExtractor} * of XLSX files, see {@link XSSFEventBasedExcelExtractor}
* and {@link XSSFSheetXMLHandler}. Note that for many cases, * and {@link XSSFSheetXMLHandler}. Note that for many cases,
* it may be possible to simply use those with a custom * it may be possible to simply use those with a custom
* {@link SheetContentsHandler} and no SAX code needed of * {@link SheetContentsHandler} and no SAX code needed of
* your own! * your own!
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class XLSX2CSV { public class XLSX2CSV {
/** /**
* Uses the XSSF Event SAX helpers to do most of the work * Uses the XSSF Event SAX helpers to do most of the work
@ -75,7 +76,7 @@ public class XLSX2CSV {
private boolean firstCellOfRow; private boolean firstCellOfRow;
private int currentRow = -1; private int currentRow = -1;
private int currentCol = -1; private int currentCol = -1;
private void outputMissingRows(int number) { private void outputMissingRows(int number) {
for (int i=0; i<number; i++) { for (int i=0; i<number; i++) {
for (int j=0; j<minColumns; j++) { for (int j=0; j<minColumns; j++) {
@ -125,7 +126,7 @@ public class XLSX2CSV {
output.append(','); output.append(',');
} }
currentCol = thisCol; currentCol = thisCol;
// Number or string? // Number or string?
try { try {
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
@ -183,7 +184,7 @@ public class XLSX2CSV {
public void processSheet( public void processSheet(
Styles styles, Styles styles,
SharedStrings strings, SharedStrings strings,
SheetContentsHandler sheetHandler, SheetContentsHandler sheetHandler,
InputStream sheetInputStream) throws IOException, SAXException { InputStream sheetInputStream) throws IOException, SAXException {
DataFormatter formatter = new DataFormatter(); DataFormatter formatter = new DataFormatter();
InputSource sheetSource = new InputSource(sheetInputStream); InputSource sheetSource = new InputSource(sheetInputStream);

View File

@ -42,6 +42,7 @@ import org.xml.sax.helpers.DefaultHandler;
* See {@link XLSX2CSV} for a fuller example of doing * See {@link XLSX2CSV} for a fuller example of doing
* XSLX processing with the XSSF Event code. * XSLX processing with the XSSF Event code.
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class FromHowTo { public class FromHowTo {
public void processFirstSheet(String filename) throws Exception { public void processFirstSheet(String filename) throws Exception {
try (OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ)) { try (OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ)) {

View File

@ -35,10 +35,10 @@ import org.apache.poi.xssf.usermodel.examples.LoadPasswordProtectedXlsx;
* <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted. * <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted.
* </ul><p> * </ul><p>
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class LoadPasswordProtectedXlsxStreaming { public final class LoadPasswordProtectedXlsxStreaming {
private LoadPasswordProtectedXlsxStreaming() { private LoadPasswordProtectedXlsxStreaming() {}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
LoadPasswordProtectedXlsx.execute(args, LoadPasswordProtectedXlsxStreaming::printSheetCount); LoadPasswordProtectedXlsx.execute(args, LoadPasswordProtectedXlsxStreaming::printSheetCount);

View File

@ -46,7 +46,10 @@ import org.apache.poi.xssf.streaming.SXSSFSheet;
* <li><code>SXSSFWorkbookWithCustomZipEntrySource</code> extends SXSSFWorkbook to ensure temp files are encrypted. * <li><code>SXSSFWorkbookWithCustomZipEntrySource</code> extends SXSSFWorkbook to ensure temp files are encrypted.
* </ul><p> * </ul><p>
*/ */
public class SavePasswordProtectedXlsx { @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class SavePasswordProtectedXlsx {
private SavePasswordProtectedXlsx() {}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
if(args.length != 2) { if(args.length != 2) {
@ -81,7 +84,7 @@ public class SavePasswordProtectedXlsx {
} }
TempFileUtils.checkTempFiles(); TempFileUtils.checkTempFiles();
} }
public static void save(final InputStream inputStream, final String filename, final String pwd) public static void save(final InputStream inputStream, final String filename, final String pwd)
throws InvalidFormatException, IOException, GeneralSecurityException { throws InvalidFormatException, IOException, GeneralSecurityException {

View File

@ -16,17 +16,20 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.usermodel.examples; package org.apache.poi.xssf.usermodel.examples;
import java.io.ByteArrayOutputStream;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.extractor.XSSFExportToXml; import org.apache.poi.xssf.extractor.XSSFExportToXml;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFMap; import org.apache.poi.xssf.usermodel.XSSFMap;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.ByteArrayOutputStream;
/** /**
* Print all custom XML mappings registered in the given workbook * Print all custom XML mappings registered in the given workbook
*/ */
public class CustomXMLMapping { @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class CustomXMLMapping {
private CustomXMLMapping() {}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
try (OPCPackage pkg = OPCPackage.open(args[0]); try (OPCPackage pkg = OPCPackage.open(args[0]);

View File

@ -29,7 +29,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/** /**
* Iterate over rows and cells * Iterate over rows and cells
*/ */
public class IterateCells { @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class IterateCells {
private IterateCells() {}
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
try ( try (

View File

@ -37,8 +37,11 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted. * <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted.
* </ul><p> * </ul><p>
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class LoadPasswordProtectedXlsx { public final class LoadPasswordProtectedXlsx {
private LoadPasswordProtectedXlsx() {}
public interface EncryptionHandler { public interface EncryptionHandler {
void handle(final InputStream inputStream) throws Exception; void handle(final InputStream inputStream) throws Exception;
} }

View File

@ -35,7 +35,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/** /**
* Demonstrates how to insert pictures in a SpreadsheetML document * Demonstrates how to insert pictures in a SpreadsheetML document
*/ */
public class WorkingWithPictures { @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class WorkingWithPictures {
private WorkingWithPictures() {}
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
//create a new workbook //create a new workbook

View File

@ -43,6 +43,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
/** /**
* Build a bar chart from a template docx * Build a bar chart from a template docx
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class BarChartExample { public final class BarChartExample {
private BarChartExample() {} private BarChartExample() {}

View File

@ -49,6 +49,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
/** /**
* Build a chart without reading template file * Build a chart without reading template file
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class ChartFromScratch { public final class ChartFromScratch {
private ChartFromScratch() {} private ChartFromScratch() {}

View File

@ -33,6 +33,7 @@ import org.apache.poi.xwpf.usermodel.XWPFRun;
/** /**
* Demonstrates how to add pictures in a .docx document * Demonstrates how to add pictures in a .docx document
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class SimpleImages { public final class SimpleImages {
private SimpleImages() {} private SimpleImages() {}

View File

@ -42,10 +42,11 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
* embedded into a WordprocessingML document. Note that the test has currently * embedded into a WordprocessingML document. Note that the test has currently
* only been conducted with a binary Excel workbook and NOT yet with a * only been conducted with a binary Excel workbook and NOT yet with a
* SpreadsheetML workbook embedded into the document.<p> * SpreadsheetML workbook embedded into the document.<p>
* *
* This code was successfully tested with the following file from the POI test collection: * This code was successfully tested with the following file from the POI test collection:
* http://svn.apache.org/repos/asf/poi/trunk/test-data/document/EmbeddedDocument.docx * http://svn.apache.org/repos/asf/poi/trunk/test-data/document/EmbeddedDocument.docx
*/ */
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class UpdateEmbeddedDoc { public class UpdateEmbeddedDoc {
private XWPFDocument doc; private XWPFDocument doc;