From: Andreas Beeker Date: Sat, 26 Dec 2020 00:08:19 +0000 (+0000) Subject: Sonar fixes X-Git-Tag: REL_5_0_0~76 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d121353f612c6efbcf156e166158f1d403e8697e;p=poi.git Sonar fixes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884807 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/examples/src/org/apache/poi/examples/xslf/LinkVideoToPptx.java b/src/examples/src/org/apache/poi/examples/xslf/LinkVideoToPptx.java index d2988478d2..9fcf312011 100644 --- a/src/examples/src/org/apache/poi/examples/xslf/LinkVideoToPptx.java +++ b/src/examples/src/org/apache/poi/examples/xslf/LinkVideoToPptx.java @@ -52,66 +52,69 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STTLTimeNodeFillType import org.openxmlformats.schemas.presentationml.x2006.main.STTLTimeNodeRestartType; import org.openxmlformats.schemas.presentationml.x2006.main.STTLTimeNodeType; -public class LinkVideoToPptx { - public static void main(String[] args) throws IOException, URISyntaxException { - XMLSlideShow pptx = new XMLSlideShow(); - - String videoFileName = "file_example_MP4_640_3MG.mp4"; - XSLFSlide slide1 = pptx.createSlide(); - - PackagePart pp = slide1.getPackagePart(); - URI mp4uri = new URI("./"+videoFileName); - PackageRelationship prsEmbed1 = pp.addRelationship(mp4uri, TargetMode.EXTERNAL, "http://schemas.microsoft.com/office/2007/relationships/media"); - PackageRelationship prsExec1 = pp.addRelationship(mp4uri, TargetMode.EXTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/video"); - - - File previewJpg = new File("preview.jpg"); - XSLFPictureData snap = pptx.addPicture(previewJpg, PictureData.PictureType.JPEG); - XSLFPictureShape pic1 = slide1.createPicture(snap); - pic1.setAnchor(new Rectangle(100, 100, 500, 400)); - - CTPicture xpic1 = (CTPicture)pic1.getXmlObject(); - CTHyperlink link1 = xpic1.getNvPicPr().getCNvPr().addNewHlinkClick(); - link1.setId(""); - link1.setAction("ppaction://media"); - - - CTApplicationNonVisualDrawingProps nvPr = xpic1.getNvPicPr().getNvPr(); - nvPr.addNewVideoFile().setLink(prsExec1.getId()); - CTExtension ext = nvPr.addNewExtLst().addNewExt(); - ext.setUri("{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}"); - - String p14Ns = "http://schemas.microsoft.com/office/powerpoint/2010/main"; - XmlCursor cur = ext.newCursor(); - cur.toEndToken(); - cur.beginElement(new QName(p14Ns, "media", "p14")); - cur.insertNamespace("p14", p14Ns); - cur.insertAttributeWithValue(new QName(CORE_PROPERTIES_ECMA376_NS, "link"), prsEmbed1.getId()); - cur.dispose(); - - - CTSlide xslide = slide1.getXmlObject(); - CTTimeNodeList ctnl; - if (!xslide.isSetTiming()) { - CTTLCommonTimeNodeData ctn = xslide.addNewTiming().addNewTnLst().addNewPar().addNewCTn(); - ctn.setDur(STTLTimeIndefinite.INDEFINITE); - ctn.setRestart(STTLTimeNodeRestartType.NEVER); - ctn.setNodeType(STTLTimeNodeType.TM_ROOT); - ctnl = ctn.addNewChildTnLst(); - } else { - ctnl = xslide.getTiming().getTnLst().getParArray(0).getCTn().getChildTnLst(); - } - CTTLCommonMediaNodeData cmedia = ctnl.addNewVideo().addNewCMediaNode(); - cmedia.setVol(80000); - CTTLCommonTimeNodeData ctn = cmedia.addNewCTn(); - ctn.setFill(STTLTimeNodeFillType.HOLD); - ctn.setDisplay(false); - ctn.addNewStCondLst().addNewCond().setDelay(STTLTimeIndefinite.INDEFINITE); - cmedia.addNewTgtEl().addNewSpTgt().setSpid(pic1.getShapeId()); +public final class LinkVideoToPptx { + private LinkVideoToPptx() {} - - try (FileOutputStream fos = new FileOutputStream("mp4test/mp4test-poi.pptx")) { - pptx.write(fos); + public static void main(String[] args) throws IOException, URISyntaxException { + try (XMLSlideShow pptx = new XMLSlideShow()) { + + String videoFileName = "file_example_MP4_640_3MG.mp4"; + XSLFSlide slide1 = pptx.createSlide(); + + PackagePart pp = slide1.getPackagePart(); + URI mp4uri = new URI("./" + videoFileName); + PackageRelationship prsEmbed1 = pp.addRelationship(mp4uri, TargetMode.EXTERNAL, "http://schemas.microsoft.com/office/2007/relationships/media"); + PackageRelationship prsExec1 = pp.addRelationship(mp4uri, TargetMode.EXTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/video"); + + + File previewJpg = new File("preview.jpg"); + XSLFPictureData snap = pptx.addPicture(previewJpg, PictureData.PictureType.JPEG); + XSLFPictureShape pic1 = slide1.createPicture(snap); + pic1.setAnchor(new Rectangle(100, 100, 500, 400)); + + CTPicture xpic1 = (CTPicture) pic1.getXmlObject(); + CTHyperlink link1 = xpic1.getNvPicPr().getCNvPr().addNewHlinkClick(); + link1.setId(""); + link1.setAction("ppaction://media"); + + + CTApplicationNonVisualDrawingProps nvPr = xpic1.getNvPicPr().getNvPr(); + nvPr.addNewVideoFile().setLink(prsExec1.getId()); + CTExtension ext = nvPr.addNewExtLst().addNewExt(); + ext.setUri("{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}"); + + String p14Ns = "http://schemas.microsoft.com/office/powerpoint/2010/main"; + XmlCursor cur = ext.newCursor(); + cur.toEndToken(); + cur.beginElement(new QName(p14Ns, "media", "p14")); + cur.insertNamespace("p14", p14Ns); + cur.insertAttributeWithValue(new QName(CORE_PROPERTIES_ECMA376_NS, "link"), prsEmbed1.getId()); + cur.dispose(); + + + CTSlide xslide = slide1.getXmlObject(); + CTTimeNodeList ctnl; + if (!xslide.isSetTiming()) { + CTTLCommonTimeNodeData ctn = xslide.addNewTiming().addNewTnLst().addNewPar().addNewCTn(); + ctn.setDur(STTLTimeIndefinite.INDEFINITE); + ctn.setRestart(STTLTimeNodeRestartType.NEVER); + ctn.setNodeType(STTLTimeNodeType.TM_ROOT); + ctnl = ctn.addNewChildTnLst(); + } else { + ctnl = xslide.getTiming().getTnLst().getParArray(0).getCTn().getChildTnLst(); + } + CTTLCommonMediaNodeData cmedia = ctnl.addNewVideo().addNewCMediaNode(); + cmedia.setVol(80000); + CTTLCommonTimeNodeData ctn = cmedia.addNewCTn(); + ctn.setFill(STTLTimeNodeFillType.HOLD); + ctn.setDisplay(false); + ctn.addNewStCondLst().addNewCond().setDelay(STTLTimeIndefinite.INDEFINITE); + cmedia.addNewTgtEl().addNewSpTgt().setSpid(pic1.getShapeId()); + + + try (FileOutputStream fos = new FileOutputStream("mp4test/mp4test-poi.pptx")) { + pptx.write(fos); + } } } } diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntUserDefinedFunction.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntUserDefinedFunction.java index 5c19912b35..f96a01f996 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntUserDefinedFunction.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntUserDefinedFunction.java @@ -22,19 +22,19 @@ import org.apache.tools.ant.taskdefs.Typedef; /** * This class encapsulates the Strings necessary to create the User Defined * Function instances that will be passed to POI's Evaluator instance. - * + * * @author Jon Svede ( jon [at] loquatic [dot] com ) * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) * */ public class ExcelAntUserDefinedFunction extends Typedef { - - public String functionAlias ; - - public String className ; - + private String functionAlias ; + + private String className ; + + public ExcelAntUserDefinedFunction() {} protected String getFunctionAlias() { diff --git a/src/java/org/apache/poi/extractor/ExtractorFactory.java b/src/java/org/apache/poi/extractor/ExtractorFactory.java index 0833535189..b45b5e29e2 100644 --- a/src/java/org/apache/poi/extractor/ExtractorFactory.java +++ b/src/java/org/apache/poi/extractor/ExtractorFactory.java @@ -178,6 +178,7 @@ public final class ExtractorFactory { return createExtractor(file, getCurrentUserPassword()); } + @SuppressWarnings({"java:S2095"}) public static POITextExtractor createExtractor(File file, String password) throws IOException { if (file.length() == 0) { throw new EmptyFileException(); @@ -318,6 +319,6 @@ public final class ExtractorFactory { } public static void removeProvider(Class provider){ - Singleton.INSTANCE.provider.removeIf(p -> p.getClass().getName().equals(provider.getName())); + Singleton.INSTANCE.provider.removeIf(p -> p.getClass().isAssignableFrom(provider)); } } diff --git a/src/java/org/apache/poi/extractor/MainExtractorFactory.java b/src/java/org/apache/poi/extractor/MainExtractorFactory.java index 7f8733eecf..d485f864ff 100644 --- a/src/java/org/apache/poi/extractor/MainExtractorFactory.java +++ b/src/java/org/apache/poi/extractor/MainExtractorFactory.java @@ -41,6 +41,7 @@ public class MainExtractorFactory implements ExtractorProvider { return FileMagic.OLE2 == fm; } + @SuppressWarnings({"java:S2095"}) @Override public POITextExtractor create(File file, String password) throws IOException { return create(new POIFSFileSystem(file, true).getRoot(), password); diff --git a/src/java/org/apache/poi/hssf/dev/ReSave.java b/src/java/org/apache/poi/hssf/dev/ReSave.java index 7f19888973..2f31eb48d8 100644 --- a/src/java/org/apache/poi/hssf/dev/ReSave.java +++ b/src/java/org/apache/poi/hssf/dev/ReSave.java @@ -37,7 +37,6 @@ public class ReSave { public static void main(String[] args) throws Exception { boolean initDrawing = false; boolean saveToMemory = false; - ByteArrayOutputStream bos = new ByteArrayOutputStream(); for(String filename : args) { if(filename.equals("-dg")) { initDrawing = true; @@ -45,11 +44,10 @@ public class ReSave { saveToMemory = true; } else { System.out.print("reading " + filename + "..."); - FileInputStream is = new FileInputStream(filename); - HSSFWorkbook wb = new HSSFWorkbook(is); - try { + try (FileInputStream is = new FileInputStream(filename); + HSSFWorkbook wb = new HSSFWorkbook(is)) { System.out.println("done"); - + for(int i = 0; i < wb.getNumberOfSheets(); i++){ HSSFSheet sheet = wb.getSheetAt(i); if(initDrawing) { @@ -57,25 +55,15 @@ public class ReSave { } } - OutputStream os; - if (saveToMemory) { - bos.reset(); - os = bos; - } else { - String outputFile = filename.replace(".xls", "-saved.xls"); + String outputFile = filename.replace(".xls", "-saved.xls"); + if (!saveToMemory) { System.out.print("saving to " + outputFile + "..."); - os = new FileOutputStream(outputFile); } - - try { + + try (OutputStream os = saveToMemory ? new ByteArrayOutputStream() : new FileOutputStream(outputFile)) { wb.write(os); - } finally { - os.close(); } System.out.println("done"); - } finally { - wb.close(); - is.close(); } } } diff --git a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java index 8ddb368e0a..e1d4f85718 100644 --- a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java +++ b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java @@ -1052,7 +1052,7 @@ public final class InternalWorkbook { // Can be a few short if new sheets were added if(records.getTabpos() > 0) { TabIdRecord tir = ( TabIdRecord ) records.get(records.getTabpos()); - if(tir._tabids.length < boundsheets.size()) { + if(tir.getTabIdSize() < boundsheets.size()) { fixTabIdRecord(); } } diff --git a/src/java/org/apache/poi/hssf/record/GridsetRecord.java b/src/java/org/apache/poi/hssf/record/GridsetRecord.java index d5f705071f..b5cfd92055 100644 --- a/src/java/org/apache/poi/hssf/record/GridsetRecord.java +++ b/src/java/org/apache/poi/hssf/record/GridsetRecord.java @@ -30,7 +30,7 @@ import org.apache.poi.util.LittleEndianOutput; */ public final class GridsetRecord extends StandardRecord { public static final short sid = 0x82; - public short field_1_gridset_flag; + private short field_1_gridset_flag; public GridsetRecord() {} diff --git a/src/java/org/apache/poi/hssf/record/PageBreakRecord.java b/src/java/org/apache/poi/hssf/record/PageBreakRecord.java index 99369d9ae3..402c04d02c 100644 --- a/src/java/org/apache/poi/hssf/record/PageBreakRecord.java +++ b/src/java/org/apache/poi/hssf/record/PageBreakRecord.java @@ -53,9 +53,9 @@ public abstract class PageBreakRecord extends StandardRecord { public static final class Break implements GenericRecord { public static final int ENCODED_SIZE = 6; - public int main; - public int subFrom; - public int subTo; + private int main; + private int subFrom; + private int subTo; public Break(Break other) { main = other.main; @@ -75,6 +75,18 @@ public abstract class PageBreakRecord extends StandardRecord { subTo = in.readUShort(); } + public int getMain() { + return main; + } + + public int getSubFrom() { + return subFrom; + } + + public int getSubTo() { + return subTo; + } + public void serialize(LittleEndianOutput out) { out.writeShort(main + 1); out.writeShort(subFrom); diff --git a/src/java/org/apache/poi/hssf/record/PrecisionRecord.java b/src/java/org/apache/poi/hssf/record/PrecisionRecord.java index 49cbf31de5..27471b935f 100644 --- a/src/java/org/apache/poi/hssf/record/PrecisionRecord.java +++ b/src/java/org/apache/poi/hssf/record/PrecisionRecord.java @@ -32,7 +32,7 @@ import org.apache.poi.util.LittleEndianOutput; public final class PrecisionRecord extends StandardRecord { public static final short sid = 0xE; - public short field_1_precision; + private short field_1_precision; public PrecisionRecord() {} diff --git a/src/java/org/apache/poi/hssf/record/TabIdRecord.java b/src/java/org/apache/poi/hssf/record/TabIdRecord.java index 2fc905bb9e..c76a396bd7 100644 --- a/src/java/org/apache/poi/hssf/record/TabIdRecord.java +++ b/src/java/org/apache/poi/hssf/record/TabIdRecord.java @@ -30,7 +30,7 @@ public final class TabIdRecord extends StandardRecord { public static final short sid = 0x013D; private static final short[] EMPTY_SHORT_ARRAY = { }; - public short[] _tabids; + private short[] _tabids; public TabIdRecord() { _tabids = EMPTY_SHORT_ARRAY; @@ -63,6 +63,14 @@ public final class TabIdRecord extends StandardRecord { } } + public int getTabIdSize() { + return _tabids.length; + } + + public short getTabIdAt(int index) { + return _tabids[index]; + } + protected int getDataSize() { return _tabids.length * 2; } diff --git a/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java b/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java index 78b93a0e41..c8d931f349 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java @@ -121,7 +121,7 @@ public final class PageSettingsBlock extends RecordAggregate { /** * @param sid the record sid - * + * * @return true if the specified Record sid is one belonging to the * 'Page Settings Block'. */ @@ -486,7 +486,7 @@ public final class PageSettingsBlock extends RecordAggregate { while(iterator.hasNext()) { PageBreakRecord.Break breakItem = iterator.next(); - int breakLocation = breakItem.main; + int breakLocation = breakItem.getMain(); boolean inStart = (breakLocation >= start); boolean inEnd = (breakLocation <= stop); if(inStart && inEnd) { @@ -497,8 +497,8 @@ public final class PageSettingsBlock extends RecordAggregate { iterator = shiftedBreak.iterator(); while (iterator.hasNext()) { PageBreakRecord.Break breakItem = iterator.next(); - breaks.removeBreak(breakItem.main); - breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo); + breaks.removeBreak(breakItem.getMain()); + breaks.addBreak((short)(breakItem.getMain()+count), breakItem.getSubFrom(), breakItem.getSubTo()); } } @@ -526,9 +526,9 @@ public final class PageSettingsBlock extends RecordAggregate { /** * Queries if the specified row has a page break - * + * * @param row the row to check for - * + * * @return true if the specified row has a page break */ public boolean isRowBroken(int row) { @@ -538,7 +538,7 @@ public final class PageSettingsBlock extends RecordAggregate { /** * Queries if the specified column has a page break - * + * * @param column the column to check for * * @return true if the specified column has a page break @@ -606,7 +606,7 @@ public final class PageSettingsBlock extends RecordAggregate { /** * HEADERFOOTER is new in 2007. Some apps seem to have scattered this record long after * the {@link PageSettingsBlock} where it belongs. - * + * * @param rec the HeaderFooterRecord to set */ public void addLateHeaderFooter(HeaderFooterRecord rec) { @@ -623,10 +623,10 @@ public final class PageSettingsBlock extends RecordAggregate { * This method reads PageSettingsBlock records from the supplied RecordStream until the first * non-PageSettingsBlock record is encountered. As each record is read, it is incorporated * into this PageSettingsBlock.

- * + * * The latest Excel version seems to write the PageSettingsBlock uninterrupted. However there * are several examples (that Excel reads OK) where these records are not written together: - * + * *

- * + * * These were probably written by other applications (or earlier versions of Excel). It was * decided to not write specific code for detecting each of these cases. POI now tolerates * PageSettingsBlock records scattered all over the sheet record stream, and in any order, but @@ -646,7 +646,7 @@ public final class PageSettingsBlock extends RecordAggregate { * were when they were originally read. * * @param rs the RecordStream to read from - * + * * @throws org.apache.poi.util.RecordFormatException if any PSB record encountered has the same type (sid) as * a record that is already part of this PageSettingsBlock */ diff --git a/src/java/org/apache/poi/hssf/record/common/PhRun.java b/src/java/org/apache/poi/hssf/record/common/PhRun.java index 2f5a9229da..404efb0bd0 100644 --- a/src/java/org/apache/poi/hssf/record/common/PhRun.java +++ b/src/java/org/apache/poi/hssf/record/common/PhRun.java @@ -59,4 +59,14 @@ public class PhRun { public int hashCode() { return Objects.hash(phoneticTextFirstCharacterOffset, realTextFirstCharacterOffset, realTextLength); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PhRun phRun = (PhRun) o; + return phoneticTextFirstCharacterOffset == phRun.phoneticTextFirstCharacterOffset + && realTextFirstCharacterOffset == phRun.realTextFirstCharacterOffset + && realTextLength == phRun.realTextLength; + } } diff --git a/src/java/org/apache/poi/poifs/common/POIFSConstants.java b/src/java/org/apache/poi/poifs/common/POIFSConstants.java index 7cacb68fe8..f3804a90be 100644 --- a/src/java/org/apache/poi/poifs/common/POIFSConstants.java +++ b/src/java/org/apache/poi/poifs/common/POIFSConstants.java @@ -57,11 +57,4 @@ public interface POIFSConstants int END_OF_CHAIN = -2; /** Indicates the sector is not used (0xFFFFFFFF) */ int UNUSED_BLOCK = -1; - - /** The first 4 bytes of an OOXML file, used in detection */ - byte[] OOXML_FILE_HEADER = - new byte[] { 0x50, 0x4b, 0x03, 0x04 }; - /** The first 5 bytes of a raw XML file, used in detection */ - byte[] RAW_XML_FILE_HEADER = - new byte[] { 0x3c, 0x3f, 0x78, 0x6d, 0x6c }; -} // end public interface POIFSConstants; +} diff --git a/src/java/org/apache/poi/poifs/crypt/agile/AgileDecryptor.java b/src/java/org/apache/poi/poifs/crypt/agile/AgileDecryptor.java index f8efe0d201..898670eaba 100644 --- a/src/java/org/apache/poi/poifs/crypt/agile/AgileDecryptor.java +++ b/src/java/org/apache/poi/poifs/crypt/agile/AgileDecryptor.java @@ -205,6 +205,7 @@ public class AgileDecryptor extends Decryptor { } } + @SuppressWarnings({"java:S2095"}) @Override public InputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException { DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY); diff --git a/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java b/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java index 3aec22e55f..ff14f19ab3 100644 --- a/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java +++ b/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java @@ -140,7 +140,7 @@ public class BinaryRC4Decryptor extends Decryptor { } @Override - @SuppressWarnings("resource") + @SuppressWarnings({"java:S2095","resource"}) public ChunkedCipherInputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException { DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY); diff --git a/src/java/org/apache/poi/poifs/filesystem/FileMagic.java b/src/java/org/apache/poi/poifs/filesystem/FileMagic.java index 501db481a6..60667f88a5 100644 --- a/src/java/org/apache/poi/poifs/filesystem/FileMagic.java +++ b/src/java/org/apache/poi/poifs/filesystem/FileMagic.java @@ -17,9 +17,6 @@ package org.apache.poi.poifs.filesystem; -import static org.apache.poi.poifs.common.POIFSConstants.OOXML_FILE_HEADER; -import static org.apache.poi.poifs.common.POIFSConstants.RAW_XML_FILE_HEADER; - import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -39,24 +36,24 @@ import org.apache.poi.util.LocaleUtil; public enum FileMagic { /** OLE2 / BIFF8+ stream used for Office 97 and higher documents */ OLE2(HeaderBlockConstants._signature), - /** OOXML / ZIP stream */ - OOXML(OOXML_FILE_HEADER), - /** XML file */ - XML(RAW_XML_FILE_HEADER), + /** OOXML / ZIP stream - The first 4 bytes of an OOXML file, used in detection */ + OOXML(0x50, 0x4b, 0x03, 0x04), + /** XML file - The first 5 bytes of a raw XML file, used in detection */ + XML(0x3c, 0x3f, 0x78, 0x6d, 0x6c), /** BIFF2 raw stream - for Excel 2 */ - BIFF2(new byte[]{ + BIFF2( 0x09, 0x00, // sid=0x0009 0x04, 0x00, // size=0x0004 0x00, 0x00, // unused '?', 0x00 // '?' = multiple values - }), + ), /** BIFF3 raw stream - for Excel 3 */ - BIFF3(new byte[]{ + BIFF3( 0x09, 0x02, // sid=0x0209 0x06, 0x00, // size=0x0006 0x00, 0x00, // unused '?', 0x00 // '?' = multiple values - }), + ), /** BIFF4 raw stream - for Excel 4 */ BIFF4(new byte[]{ 0x09, 0x04, // sid=0x0409 @@ -81,7 +78,7 @@ public enum FileMagic { HTML(" provider){ - Singleton.INSTANCE.provider.removeIf(p -> p.getClass().getName().equals(provider.getName())); + public static void removeProvider(Class> provider){ + Singleton.INSTANCE.provider.removeIf(p -> p.getClass().isAssignableFrom(provider)); } } diff --git a/src/java/org/apache/poi/ss/formula/SheetIdentifier.java b/src/java/org/apache/poi/ss/formula/SheetIdentifier.java index 51c0852b30..69f6f99501 100644 --- a/src/java/org/apache/poi/ss/formula/SheetIdentifier.java +++ b/src/java/org/apache/poi/ss/formula/SheetIdentifier.java @@ -18,8 +18,8 @@ package org.apache.poi.ss.formula; public class SheetIdentifier { - public String _bookName; - public NameIdentifier _sheetIdentifier; + private final String _bookName; + private final NameIdentifier _sheetIdentifier; public SheetIdentifier(String bookName, NameIdentifier sheetIdentifier) { _bookName = bookName; diff --git a/src/java/org/apache/poi/ss/formula/SheetRangeIdentifier.java b/src/java/org/apache/poi/ss/formula/SheetRangeIdentifier.java index 8cb5b3201a..88c91991b9 100644 --- a/src/java/org/apache/poi/ss/formula/SheetRangeIdentifier.java +++ b/src/java/org/apache/poi/ss/formula/SheetRangeIdentifier.java @@ -18,7 +18,7 @@ package org.apache.poi.ss.formula; public class SheetRangeIdentifier extends SheetIdentifier { - public NameIdentifier _lastSheetIdentifier; + private final NameIdentifier _lastSheetIdentifier; public SheetRangeIdentifier(String bookName, NameIdentifier firstSheetIdentifier, NameIdentifier lastSheetIdentifier) { super(bookName, firstSheetIdentifier); diff --git a/src/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java b/src/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java index 77ed481481..aba00e7f6b 100644 --- a/src/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java +++ b/src/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java @@ -324,7 +324,7 @@ final class YearFracCalculator { /** day of month */ public final int day; /** milliseconds since 1970 */ - public long tsMilliseconds; + public final long tsMilliseconds; public SimpleDate(Calendar cal) { year = cal.get(Calendar.YEAR); diff --git a/src/java/org/apache/poi/ss/formula/functions/LinearRegressionFunction.java b/src/java/org/apache/poi/ss/formula/functions/LinearRegressionFunction.java index aee79ab274..513daa3a1b 100644 --- a/src/java/org/apache/poi/ss/formula/functions/LinearRegressionFunction.java +++ b/src/java/org/apache/poi/ss/formula/functions/LinearRegressionFunction.java @@ -107,7 +107,7 @@ public final class LinearRegressionFunction extends Fixed2ArgFunction { } public enum FUNCTION {INTERCEPT, SLOPE} - public FUNCTION function; + private final FUNCTION function; public LinearRegressionFunction(FUNCTION function) { this.function = function; diff --git a/src/java/org/apache/poi/ss/formula/functions/Trend.java b/src/java/org/apache/poi/ss/formula/functions/Trend.java index 2a1227e2db..62eb545670 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Trend.java +++ b/src/java/org/apache/poi/ss/formula/functions/Trend.java @@ -60,11 +60,10 @@ import org.apache.poi.ss.formula.eval.ValueEval; */ public final class Trend implements Function { - MatrixFunction.MutableValueCollector collector = new MatrixFunction.MutableValueCollector(false, false); private static final class TrendResults { - public double[] vals; - public int resultWidth; - public int resultHeight; + private final double[] vals; + private final int resultWidth; + private final int resultHeight; public TrendResults(double[] vals, int resultWidth, int resultHeight) { this.vals = vals; @@ -149,7 +148,7 @@ public final class Trend implements Function { } double[] oneD = new double[twoD.length * twoD[0].length]; for (int i = 0; i < twoD.length; i++) { - System.arraycopy(twoD[i], 0, oneD, i * twoD[0].length + 0, twoD[0].length); + System.arraycopy(twoD[i], 0, oneD, i * twoD[0].length, twoD[0].length); } return oneD; } @@ -335,7 +334,7 @@ public final class Trend implements Function { if(isAllColumnsSame(x)){ double[] result = new double[newX.length]; double avg = Arrays.stream(y).average().orElse(0); - for(int i = 0; i < result.length; i++) result[i] = avg; + Arrays.fill(result, avg); return new TrendResults(result, resultWidth, resultHeight); } diff --git a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java index b730731f7c..c2b6e6936f 100644 --- a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java +++ b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java @@ -305,6 +305,6 @@ public final class WorkbookFactory { } public static void removeProvider(Class provider){ - Singleton.INSTANCE.provider.removeIf(p -> p.getClass().getName().equals(provider.getName())); + Singleton.INSTANCE.provider.removeIf(p -> p.getClass().isAssignableFrom(provider)); } } diff --git a/src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java b/src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java index 2826cc3323..d26d7a9864 100644 --- a/src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java +++ b/src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java @@ -17,6 +17,10 @@ package org.apache.poi.ss.util.cellwalk; +import static org.apache.commons.math3.util.ArithmeticUtils.addAndCheck; +import static org.apache.commons.math3.util.ArithmeticUtils.mulAndCheck; +import static org.apache.commons.math3.util.ArithmeticUtils.subAndCheck; + import org.apache.commons.math3.util.ArithmeticUtils; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; @@ -26,13 +30,11 @@ import org.apache.poi.ss.util.CellRangeAddress; /** * Traverse cell range. - * - * @author Roman Kashitsyn */ public class CellWalk { - private Sheet sheet; - private CellRangeAddress range; + private final Sheet sheet; + private final CellRangeAddress range; private boolean traverseEmptyCells; @@ -74,8 +76,8 @@ public class CellWalk { int lastColumn = range.getLastColumn(); final int width = lastColumn - firstColumn + 1; SimpleCellWalkContext ctx = new SimpleCellWalkContext(); - Row currentRow = null; - Cell currentCell = null; + Row currentRow; + Cell currentCell; for (ctx.rowNumber = firstRow; ctx.rowNumber <= lastRow; ++ctx.rowNumber) { currentRow = sheet.getRow(ctx.rowNumber); @@ -92,10 +94,9 @@ public class CellWalk { continue; } - long rowSize = ArithmeticUtils.mulAndCheck( - (long)ArithmeticUtils.subAndCheck(ctx.rowNumber, firstRow), (long)width); + long rowSize = mulAndCheck(subAndCheck(ctx.rowNumber, firstRow), (long)width); - ctx.ordinalNumber = ArithmeticUtils.addAndCheck(rowSize, (ctx.colNumber - firstColumn + 1)); + ctx.ordinalNumber = addAndCheck(rowSize, (ctx.colNumber - firstColumn + 1)); handler.onCell(currentCell, ctx); } @@ -108,13 +109,11 @@ public class CellWalk { /** * Inner class to hold walk context. - * - * @author Roman Kashitsyn */ private static class SimpleCellWalkContext implements CellWalkContext { - public long ordinalNumber; - public int rowNumber; - public int colNumber; + private long ordinalNumber; + private int rowNumber; + private int colNumber; @Override public long getOrdinalNumber() { diff --git a/src/java/org/apache/poi/util/DrawingDump.java b/src/java/org/apache/poi/util/DrawingDump.java index ef7b2d29ac..72d9580b65 100644 --- a/src/java/org/apache/poi/util/DrawingDump.java +++ b/src/java/org/apache/poi/util/DrawingDump.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.util; import java.io.File; @@ -37,23 +37,20 @@ public final class DrawingDump { } public static void main( String[] args ) throws IOException { - OutputStreamWriter osw = new OutputStreamWriter(System.out, Charset.defaultCharset()); - PrintWriter pw = new PrintWriter(osw); - POIFSFileSystem fs = new POIFSFileSystem(new File(args[0])); - HSSFWorkbook wb = new HSSFWorkbook(fs); - try { + try (OutputStreamWriter osw = new OutputStreamWriter(System.out, Charset.defaultCharset()); + PrintWriter pw = new PrintWriter(osw); + POIFSFileSystem fs = new POIFSFileSystem(new File(args[0])); + HSSFWorkbook wb = new HSSFWorkbook(fs)) { + pw.println( "Drawing group:" ); wb.dumpDrawingGroupRecords(true); - + int i = 1; for (Sheet sheet : wb) { pw.println( "Sheet " + i + "(" + sheet.getSheetName() + "):" ); ((HSSFSheet) sheet).dumpDrawingRecords(true, pw); } - } finally { - wb.close(); - fs.close(); } } } diff --git a/src/java/org/apache/poi/util/IOUtils.java b/src/java/org/apache/poi/util/IOUtils.java index 1a53cdd0b0..f1532b75e2 100644 --- a/src/java/org/apache/poi/util/IOUtils.java +++ b/src/java/org/apache/poi/util/IOUtils.java @@ -162,13 +162,13 @@ public final class IOUtils { * @return A byte array with the read bytes. * @throws IOException If reading data fails or EOF is encountered too early for the given length. */ - public static byte[] toByteArray(InputStream stream, final long length, final int maxLength) throws IOException { + public static byte[] toByteArray(InputStream stream, final int length, final int maxLength) throws IOException { if (length < 0L || maxLength < 0L) { throw new RecordFormatException("Can't allocate an array of length < 0"); } - if (length > (long)Integer.MAX_VALUE) { - throw new RecordFormatException("Can't allocate an array > "+Integer.MAX_VALUE); - } + // if (length > (long)Integer.MAX_VALUE) { + // throw new RecordFormatException("Can't allocate an array > "+Integer.MAX_VALUE); + // } if ((length != Integer.MAX_VALUE) || (maxLength != Integer.MAX_VALUE)) { checkLength(length, maxLength); } diff --git a/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java b/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java index 2a5a9d86f7..2d90b46f20 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java +++ b/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java @@ -124,7 +124,6 @@ public final class POIXMLExtractorFactory implements ExtractorProvider { return ExtractorFactory.createExtractor(f, password); } - OPCPackage pkg = null; try { pkg = OPCPackage.open(f.toString(), PackageAccess.READ); @@ -136,7 +135,9 @@ public final class POIXMLExtractorFactory implements ExtractorProvider { } catch (InvalidFormatException ife) { throw new IOException(ife); } catch (IOException e) { - pkg.revert(); + if (pkg != null) { + pkg.revert(); + } throw e; } } diff --git a/src/ooxml/java/org/apache/poi/ooxml/util/IdentifierManager.java b/src/ooxml/java/org/apache/poi/ooxml/util/IdentifierManager.java index f367473cc3..8634862bb7 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/util/IdentifierManager.java +++ b/src/ooxml/java/org/apache/poi/ooxml/util/IdentifierManager.java @@ -19,28 +19,12 @@ package org.apache.poi.ooxml.util; import java.util.LinkedList; import java.util.ListIterator; -/** - *

- * 24.08.2009
- *

- * - * @author Stefan Stern
- */ - public class IdentifierManager { public static final long MAX_ID = Long.MAX_VALUE - 1; - public static final long MIN_ID = 0L; - /** - * - */ private final long upperbound; - - /** - * - */ private final long lowerbound; /** @@ -56,7 +40,7 @@ public class IdentifierManager { if (lowerbound > upperbound) { throw new IllegalArgumentException("lowerbound must not be greater than upperbound, had " + lowerbound + " and " + upperbound); } - else if (lowerbound < MIN_ID) { + else if (lowerbound < MIN_ID) { String message = "lowerbound must be greater than or equal to " + Long.toString(MIN_ID); throw new IllegalArgumentException(message); } @@ -78,7 +62,7 @@ public class IdentifierManager { throw new IllegalArgumentException("Value for parameter 'id' was out of bounds, had " + id + ", but should be within [" + lowerbound + ":" + upperbound + "]"); } verifyIdentifiersLeft(); - + if (id == upperbound) { Segment lastSegment = segments.getLast(); if (lastSegment.end == upperbound) { @@ -136,7 +120,7 @@ public class IdentifierManager { } /** - * @return a new identifier. + * @return a new identifier. * @throws IllegalStateException if no more identifiers are available, then an Exception is raised. */ public long reserveNew() { @@ -236,7 +220,7 @@ public class IdentifierManager { } /** - * + * */ private void verifyIdentifiersLeft() { if (segments.isEmpty()) { @@ -245,20 +229,14 @@ public class IdentifierManager { } private static class Segment { + private long start; + private long end; public Segment(long start, long end) { this.start = start; this.end = end; } - public long start; - public long end; - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ public String toString() { return "[" + start + "; " + end + "]"; } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java index c6dcde6d74..06067ea531 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java @@ -386,7 +386,7 @@ public abstract class SignatureLine { int mpos = measurer.getPosition(); int limit = text.indexOf('\n', mpos); limit = (limit == -1) ? text.length() : limit+1; - TextLayout textLayout = measurer.nextLayout(bi.getWidth()-10, limit, false); + TextLayout textLayout = measurer.nextLayout(bi.getWidth()-10f, limit, false); if (lineNr != 1) { y += textLayout.getAscent(); } diff --git a/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GeometryRowTypes.java b/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GeometryRowTypes.java index b841da4ada..7dd4641107 100644 --- a/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GeometryRowTypes.java +++ b/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GeometryRowTypes.java @@ -62,8 +62,8 @@ enum GeometryRowTypes { SPLINE_START("SplineStart", SplineStart::new) ; - public String rowType; - public Function constructor; + private final String rowType; + private final Function constructor; GeometryRowTypes(String rowType, Function constructor) { this.rowType = rowType; diff --git a/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/XDGFSectionTypes.java b/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/XDGFSectionTypes.java index 8aa0bdca4d..35af8d52be 100644 --- a/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/XDGFSectionTypes.java +++ b/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/XDGFSectionTypes.java @@ -50,8 +50,8 @@ enum XDGFSectionTypes { ANNOTATION("Annotation", GenericSection::new), ACTION_TAG("ActionTag", GenericSection::new); - public String sectionType; - public BiFunction constructor; + private final String sectionType; + private final BiFunction constructor; XDGFSectionTypes(String sectionType, BiFunction constructor) { this.sectionType = sectionType; diff --git a/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/EllipticalArcTo.java b/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/EllipticalArcTo.java index d29392d6a1..2ec09f6b6b 100644 --- a/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/EllipticalArcTo.java +++ b/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/EllipticalArcTo.java @@ -126,8 +126,6 @@ public class EllipticalArcTo implements GeometryRow { _master = (EllipticalArcTo) row; } - public static int draw; - @Override public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) { diff --git a/src/ooxml/java/org/apache/poi/xslf/util/DummyGraphics2d.java b/src/ooxml/java/org/apache/poi/xslf/util/DummyGraphics2d.java index 281f4129d5..b3f158a334 100644 --- a/src/ooxml/java/org/apache/poi/xslf/util/DummyGraphics2d.java +++ b/src/ooxml/java/org/apache/poi/xslf/util/DummyGraphics2d.java @@ -809,6 +809,7 @@ public class DummyGraphics2d extends Graphics2D { log.println( "finalize():" ); g2D.dispose(); dispose(); + super.finalize(); } public Shape getClip() { diff --git a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellHeader.java b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellHeader.java index 089a605c03..6e3d0c0c9f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellHeader.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellHeader.java @@ -30,7 +30,7 @@ import org.apache.poi.util.LittleEndianConsts; */ @Internal class XSSFBCellHeader { - public static int length = 8; + public static final int length = 8; /** * diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java index 64ead9f4b5..79f003eb9c 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java @@ -70,7 +70,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork public void clearAllCachedResultValues() { _tableCache = null; } - + private int convertFromExternalSheetIndex(int externSheetIndex) { return externSheetIndex; } @@ -113,16 +113,16 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork List tables = _uBook.getExternalLinksTable(); int index = findExternalLinkIndex(bookName, tables); if (index != -1) return index; - + // Is it an absolute file reference? if (bookName.startsWith("'file:///") && bookName.endsWith("'")) { String relBookName = bookName.substring(bookName.lastIndexOf('/')+1); relBookName = relBookName.substring(0, relBookName.length()-1); // Trailing ' - + // Try with this name index = findExternalLinkIndex(relBookName, tables); if (index != -1) return index; - + // If we get here, it's got no associated proper links yet // So, add the missing reference and return // Note - this is really rather nasty... @@ -130,7 +130,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork tables.add(fakeLinkTable); return tables.size(); // 1 based results, 0 = current workbook } - + // Not properly referenced throw new RuntimeException("Book not linked for filename " + bookName); } @@ -162,7 +162,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork * @param sheetIndex index of sheet if named range scope is limited to one sheet * if named range scope is global to the workbook, sheetIndex is -1. * @return If name is a named range in the workbook, returns - * EvaluationName corresponding to that named range + * EvaluationName corresponding to that named range * Returns null if there is no named range with the same name and scope in the workbook */ @Override @@ -171,7 +171,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork XSSFName nm = _uBook.getNameAt(i); String nameText = nm.getNameName(); int nameSheetindex = nm.getSheetIndex(); - if (name.equalsIgnoreCase(nameText) && + if (name.equalsIgnoreCase(nameText) && (nameSheetindex == -1 || nameSheetindex == sheetIndex)) { return new Name(nm, i, this); } @@ -183,7 +183,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork public String getSheetName(int sheetIndex) { return _uBook.getSheetName(sheetIndex); } - + @Override public ExternalName getExternalName(int externSheetIndex, int externNameIndex) { throw new IllegalStateException("HSSF-style external references are not supported for XSSF"); @@ -195,13 +195,13 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork // External reference - reference is 1 based, link table is 0 based int linkNumber = externalWorkbookNumber - 1; ExternalLinksTable linkTable = _uBook.getExternalLinksTable().get(linkNumber); - + for (org.apache.poi.ss.usermodel.Name name : linkTable.getDefinedNames()) { if (name.getNameName().equals(nameName)) { // HSSF returns one sheet higher than normal, and various bits // of the code assume that. So, make us match that behaviour! int nameSheetIndex = name.getSheetIndex() + 1; - + // TODO Return a more specialised form of this, see bug #56752 // Should include the cached values, for in case that book isn't available // Should support XSSF stuff lookups @@ -215,7 +215,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork int nameIdx = _uBook.getNameIndex(nameName); return new ExternalName(nameName, nameIdx, 0); // TODO Is this right? } - + } /** @@ -229,7 +229,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork if (func != null) { return new NameXPxg(null, name); } - + // Otherwise, try it as a named range if (sheet == null) { if (!_uBook.getNames(name).isEmpty()) { @@ -237,17 +237,17 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork } return null; } - if (sheet._sheetIdentifier == null) { + if (sheet.getSheetIdentifier() == null) { // Workbook + Named Range only - int bookIndex = resolveBookIndex(sheet._bookName); + int bookIndex = resolveBookIndex(sheet.getBookName()); return new NameXPxg(bookIndex, null, name); } // Use the sheetname and process - String sheetName = sheet._sheetIdentifier.getName(); - - if (sheet._bookName != null) { - int bookIndex = resolveBookIndex(sheet._bookName); + String sheetName = sheet.getSheetIdentifier().getName(); + + if (sheet.getBookName() != null) { + int bookIndex = resolveBookIndex(sheet.getBookName()); return new NameXPxg(bookIndex, sheetName, name); } else { return new NameXPxg(sheetName, name); @@ -255,8 +255,8 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork } @Override public Ptg get3DReferencePtg(CellReference cell, SheetIdentifier sheet) { - if (sheet._bookName != null) { - int bookIndex = resolveBookIndex(sheet._bookName); + if (sheet.getBookName() != null) { + int bookIndex = resolveBookIndex(sheet.getBookName()); return new Ref3DPxg(bookIndex, sheet, cell); } else { return new Ref3DPxg(sheet, cell); @@ -264,8 +264,8 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork } @Override public Ptg get3DReferencePtg(AreaReference area, SheetIdentifier sheet) { - if (sheet._bookName != null) { - int bookIndex = resolveBookIndex(sheet._bookName); + if (sheet.getBookName() != null) { + int bookIndex = resolveBookIndex(sheet.getBookName()); return new Area3DPxg(bookIndex, sheet, area); } else { return new Area3DPxg(sheet, area); @@ -276,18 +276,18 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork public String resolveNameXText(NameXPtg n) { int idx = n.getNameIndex(); String name = null; - + // First, try to find it as a User Defined Function IndexedUDFFinder udfFinder = (IndexedUDFFinder)getUDFFinder(); name = udfFinder.getFunctionName(idx); if (name != null) return name; - + // Otherwise, try it as a named range XSSFName xname = _uBook.getNameAt(idx); if (xname != null) { name = xname.getNameName(); } - + return name; } @@ -307,7 +307,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork // Internal reference workbookName = null; } - + if (lastSheetName == null || firstSheetName.equals(lastSheetName)) { return new ExternalSheet(workbookName, firstSheetName); } else { @@ -385,7 +385,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork * Tables are cached for performance (formula evaluation looks them up by name repeatedly). * After the first table lookup, adding or removing a table from the document structure will cause trouble. * This is meant to be used on documents whose structure is essentially static at the point formulas are evaluated. - * + * * @param name the data table name (case-insensitive) * @return The Data table in the workbook named name, or null if no table is named name. * @since 3.15 beta 2 @@ -396,7 +396,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork String lname = caseInsensitive(name); return getTableCache().get(lname); } - + @Override public UDFFinder getUDFFinder(){ return _uBook.getUDFFinder(); diff --git a/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java index 1ef26afca2..3f827c3797 100644 --- a/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java +++ b/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java @@ -165,10 +165,8 @@ public class TestExtractorFactory { @Test public void testPOIFSInvalid() { - IOException ex = assertThrows( - IOException.class, - () -> ExtractorFactory.createExtractor(new POIFSFileSystem(txt)) - ); + // Not really an Extractor test, but we'll leave it to test POIFS reaction anyway ... + IOException ex = assertThrows(IOException.class, () -> new POIFSFileSystem(txt)); assertTrue(ex.getMessage().contains("Invalid header signature; read 0x3D20726F68747541, expected 0xE11AB1A1E011CFD0")); } diff --git a/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java b/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java index d0e0f88e81..dfc09b2f7e 100644 --- a/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java +++ b/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java @@ -65,6 +65,7 @@ public class OLE2ScratchpadExtractorFactory implements ExtractorProvider { return FileMagic.OLE2 == fm; } + @SuppressWarnings("java:S2095") @Override public POITextExtractor create(File file, String password) throws IOException { return create(new POIFSFileSystem(file, true).getRoot(), password); diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java index 91f8d31c95..71ade3fdb3 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java +++ b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java @@ -355,7 +355,7 @@ public class HemfPlusBrush { size += LittleEndianConsts.INT_SIZE; } - brushBytes = IOUtils.toByteArray(leis, dataSize-size, MAX_OBJECT_SIZE); + brushBytes = IOUtils.toByteArray(leis, (int)(dataSize-size), MAX_OBJECT_SIZE); return dataSize; } diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java index b52053bec4..b52e44b833 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java +++ b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java @@ -708,7 +708,7 @@ public final class HemfPlusDraw { // If the CMAP_LOOKUP flag in the optionsFlags field is set, each value in this array specifies a // Unicode character. Otherwise, each value specifies an index to a character glyph in the EmfPlusFont // object specified by the ObjectId value in Flags field. - byte[] glyphBuf = IOUtils.toByteArray(leis, glyphCount*2L, MAX_OBJECT_SIZE); + byte[] glyphBuf = IOUtils.toByteArray(leis, glyphCount*2, MAX_OBJECT_SIZE); glyphs = StringUtil.getFromUnicodeLE(glyphBuf); size += glyphBuf.length; diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java index 908a1d1151..1e04c5524e 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java +++ b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java @@ -265,7 +265,7 @@ public class HemfPlusObject { long size = graphicsVersion.init(leis); - objectDataBytes = IOUtils.toByteArray(leis, dataSize - size, MAX_OBJECT_SIZE); + objectDataBytes = IOUtils.toByteArray(leis, (int)(dataSize - size), MAX_OBJECT_SIZE); return dataSize; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java index 9d1f9a7078..bc0de3d22f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java @@ -35,7 +35,7 @@ public class ExEmbed extends RecordContainer { private final byte[] _header; // Links to our more interesting children - public org.apache.poi.hslf.record.RecordAtom embedAtom; + private org.apache.poi.hslf.record.RecordAtom embedAtom; private ExOleObjAtom oleObjAtom; private CString menuName; private CString progId; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java index 99ac049994..187e2f4bce 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java @@ -37,7 +37,7 @@ import org.apache.poi.util.LittleEndian; public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecord { public static final long _type = RecordTypes.TextHeaderAtom.typeID; private byte[] _header; - public org.apache.poi.hslf.record.RecordContainer parentRecord; + private org.apache.poi.hslf.record.RecordContainer parentRecord; /** The kind of text it is */ private int textType; diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java index c119b70222..d683ba8567 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java @@ -54,15 +54,15 @@ public class AttachmentChunks implements ChunkGroup { * This is in WMF Format. You'll probably want to pass it to Apache Batik to * turn it into a SVG that you can then display. */ - public ByteChunk attachRenderingWMF; + private ByteChunk attachRenderingWMF; /** * What the POIFS name of this attachment is. */ - private String poifsName; + private final String poifsName; /** Holds all the chunks that were found. */ - private List allChunks = new ArrayList<>(); + private final List allChunks = new ArrayList<>(); public AttachmentChunks(String poifsName) { this.poifsName = poifsName; diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/NameIdChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/NameIdChunks.java index a80d26fd48..6af621e26f 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/NameIdChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/NameIdChunks.java @@ -39,10 +39,14 @@ public final class NameIdChunks implements ChunkGroup { PS_PUBLIC_STRINGS("00020329-0000-0000-C000-000000000046"), PS_INTERNET_HEADERS("00020386-0000-0000-C000-000000000046"); - public ClassID classID; + private final ClassID classID; PropertySetType(String uuid) { classID = new ClassID(uuid); } + + public ClassID getClassID() { + return classID; + } } public enum PredefinedPropertySet { @@ -61,10 +65,14 @@ public final class NameIdChunks implements ChunkGroup { PSETID_XML_EXTRACTED_ENTITIES("23239608-685D-4732-9C55-4C95CB4E8E33"), PSETID_ATTACHMENT("96357F7F-59E1-47D0-99A7-46515C183B54"); - public ClassID classID; + private final ClassID classID; PredefinedPropertySet(String uuid) { classID = new ClassID(uuid); } + + public ClassID getClassID() { + return classID; + } } private ByteChunk guidStream; diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java index 4e142c6cff..efcd051eb9 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java @@ -29,7 +29,7 @@ import org.apache.poi.util.POILogger; /** * Collection of convenience chunks for the Recip(ient) part of an outlook file. - * + * * If a message has multiple recipients, there will be several of these. */ public final class RecipientChunks implements ChunkGroupWithProperties { @@ -45,35 +45,35 @@ public final class RecipientChunks implements ChunkGroupWithProperties { public static final MAPIProperty RECIPIENT_DISPLAY_NAME = MAPIProperty.RECIPIENT_DISPLAY_NAME; /** Our 0 based position in the list of recipients */ - public int recipientNumber; + private int recipientNumber; /** TODO */ - public ByteChunk recipientSearchChunk; + private ByteChunk recipientSearchChunk; /** * The "name", which could be their name if an internal person, or their * email address if an external person */ - public StringChunk recipientNameChunk; + private StringChunk recipientNameChunk; /** * The email address of the recipient, which could be in SMTP or SEARCH * format, but isn't always present... */ - public StringChunk recipientEmailChunk; + private StringChunk recipientEmailChunk; /** * The smtp destination email address of the recipient, but isn't always * present... */ - public StringChunk recipientSMTPChunk; + private StringChunk recipientSMTPChunk; /** * Normally EX or SMTP. Will generally affect where the email address ends * up. */ - public StringChunk deliveryTypeChunk; + private StringChunk deliveryTypeChunk; /** * The display name of the recipient. Normally seems to hold the same value * as in recipientNameChunk */ - public StringChunk recipientDisplayNameChunk; + private StringChunk recipientDisplayNameChunk; /** * Holds the fixed sized properties, and the pointers to the data of * variable sized ones @@ -93,6 +93,34 @@ public final class RecipientChunks implements ChunkGroupWithProperties { } } + public int getRecipientNumber() { + return recipientNumber; + } + + public ByteChunk getRecipientSearchChunk() { + return recipientSearchChunk; + } + + public StringChunk getRecipientNameChunk() { + return recipientNameChunk; + } + + public StringChunk getRecipientEmailChunk() { + return recipientEmailChunk; + } + + public StringChunk getRecipientSMTPChunk() { + return recipientSMTPChunk; + } + + public StringChunk getDeliveryTypeChunk() { + return deliveryTypeChunk; + } + + public StringChunk getRecipientDisplayNameChunk() { + return recipientDisplayNameChunk; + } + /** * Tries to find their name, in whichever chunk holds it. */ diff --git a/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfGraphics.java b/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfGraphics.java index 75fbe4dc25..701ab2d54e 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfGraphics.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfGraphics.java @@ -256,7 +256,7 @@ public class HwmfGraphics implements HwmfCharsetAware { protected Paint getHatchedFill() { HwmfDrawProperties prop = getProperties(); BufferedImage pattern = getPatternFromLong( - prop.getBrushHatch().pattern, + prop.getBrushHatch().getPattern(), prop.getBackgroundColor().getColor(), prop.getBrushColor().getColor(), prop.getBkMode() == HwmfBkMode.TRANSPARENT diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBinaryRasterOp.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBinaryRasterOp.java index 4bb03ef391..5325931dbe 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBinaryRasterOp.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBinaryRasterOp.java @@ -97,14 +97,18 @@ public enum HwmfBinaryRasterOp { /** 1, Pixel is always 1 */ R2_WHITE(0x0010, HwmfBinaryRasterOp::R2_WHITE); - public int opIndex; - private BiConsumer op; + private final int opIndex; + private final BiConsumer op; HwmfBinaryRasterOp(int opIndex, BiConsumer op) { this.opIndex = opIndex; this.op = op; } + public int getOpIndex() { + return opIndex; + } + public static HwmfBinaryRasterOp valueOf(int opIndex) { for (HwmfBinaryRasterOp bb : HwmfBinaryRasterOp.values()) { if (bb.opIndex == opIndex) { diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java index ee5912773f..82baf52036 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java @@ -163,9 +163,9 @@ public class HwmfEscape implements HwmfRecord { MXDC_ESCAPE(0x101A, WmfEscapeUnknownData::new), /** Enables applications to include private procedures and other arbitrary data in documents. */ SPCLPASSTHROUGH2(0x11D8, WmfEscapeUnknownData::new); - - public int flag; - public final Supplier constructor; + + private final int flag; + private final Supplier constructor; EscapeFunction(int flag, Supplier constructor) { @@ -173,6 +173,14 @@ public class HwmfEscape implements HwmfRecord { this.constructor = constructor; } + public int getFlag() { + return flag; + } + + public Supplier getConstructor() { + return constructor; + } + static EscapeFunction valueOf(int flag) { for (EscapeFunction hs : values()) { if (hs.flag == flag) return hs; @@ -180,14 +188,14 @@ public class HwmfEscape implements HwmfRecord { return null; } } - + public interface HwmfEscapeData { public int init(LittleEndianInputStream leis, long recordSize, EscapeFunction escapeFunction) throws IOException; } /** - * A 16-bit unsigned integer that defines the escape function. The + * A 16-bit unsigned integer that defines the escape function. The * value MUST be from the MetafileEscapes enumeration. */ private EscapeFunction escapeFunction; @@ -197,7 +205,7 @@ public class HwmfEscape implements HwmfRecord { public HwmfRecordType getWmfRecordType() { return HwmfRecordType.escape; } - + @Override public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException { escapeFunction = EscapeFunction.valueOf(leis.readUShort()); @@ -221,9 +229,9 @@ public class HwmfEscape implements HwmfRecord { @Override public void draw(HwmfGraphics ctx) { - + } - + public String toString() { return GenericRecordJsonWriter.marshal(this); } @@ -247,7 +255,7 @@ public class HwmfEscape implements HwmfRecord { @Override public int init(LittleEndianInputStream leis, long recordSize, EscapeFunction escapeFunction) throws IOException { this.escapeFunction = escapeFunction; - escapeDataBytes = IOUtils.toByteArray(leis,recordSize,MAX_OBJECT_SIZE); + escapeDataBytes = IOUtils.toByteArray(leis,(int)recordSize,MAX_OBJECT_SIZE); return (int)recordSize; } @@ -290,7 +298,7 @@ public class HwmfEscape implements HwmfRecord { if (commentIdentifier != EMF_COMMENT_IDENTIFIER) { // there are some WMF implementation using this record as a MFCOMMENT or similar // if the commentIdentifier doesn't match, then return immediately - emfData = IOUtils.toByteArray(leis, recordSize-LittleEndianConsts.INT_SIZE, MAX_OBJECT_SIZE); + emfData = IOUtils.toByteArray(leis, (int)(recordSize-LittleEndianConsts.INT_SIZE), MAX_OBJECT_SIZE); remainingBytes = emfData.length; return (int)recordSize; } diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHatchStyle.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHatchStyle.java index 2d1a065670..addf32d652 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHatchStyle.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfHatchStyle.java @@ -47,14 +47,22 @@ public enum HwmfHatchStyle { HS_DITHEREDBKCLR(0x000B, 0xAA55AA55AA55AA55L) ; - int flag; - public long pattern; + private final int flag; + private final long pattern; HwmfHatchStyle(int flag, long pattern) { this.flag = flag; this.pattern = pattern; } + public int getFlag() { + return flag; + } + + public long getPattern() { + return pattern; + } + public static HwmfHatchStyle valueOf(int flag) { for (HwmfHatchStyle hs : values()) { if (hs.flag == flag) return hs; diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPenStyle.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPenStyle.java index 5976322e90..fced0a24a5 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPenStyle.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPenStyle.java @@ -129,6 +129,7 @@ public class HwmfPenStyle implements Duplicatable, GenericRecord { public final int wmfFlag; public final float[] dashes; + HwmfLineDash(int wmfFlag, float... dashes) { this.wmfFlag = wmfFlag; this.dashes = dashes; diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfTernaryRasterOp.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfTernaryRasterOp.java index b4c0b6ce42..2f79af4087 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfTernaryRasterOp.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfTernaryRasterOp.java @@ -370,7 +370,7 @@ public enum HwmfTernaryRasterOp { private static final String OPS = "nxoa"; - public int opValue; + private final int opValue; HwmfTernaryRasterOp(int opValue) { this.opValue=opValue; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/FontReplacer.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/FontReplacer.java index 24bb97f2e9..a8b07c085a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/FontReplacer.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/FontReplacer.java @@ -19,14 +19,12 @@ package org.apache.poi.hwpf.converter; import org.apache.poi.util.Beta; @Beta -public interface FontReplacer -{ - public class Triplet - { +public interface FontReplacer { + class Triplet { public String fontName; public boolean bold; public boolean italic; } - public Triplet update( Triplet original ); + Triplet update(Triplet original); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java index d38e883aaf..c91a38f341 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java @@ -46,11 +46,11 @@ public final class Picture { private static final POILogger log = POILogFactory .getLogger( Picture.class ); - public static final byte[] COMPRESSED1 = { (byte) 0xFE, 0x78, (byte) 0xDA }; + private static final byte[] COMPRESSED1 = { (byte) 0xFE, 0x78, (byte) 0xDA }; - public static final byte[] COMPRESSED2 = { (byte) 0xFE, 0x78, (byte) 0x9C }; + private static final byte[] COMPRESSED2 = { (byte) 0xFE, 0x78, (byte) 0x9C }; - public static final byte[] IHDR = new byte[] { 'I', 'H', 'D', 'R' }; + private static final byte[] IHDR = new byte[] { 'I', 'H', 'D', 'R' }; @Deprecated private static final byte[] PNG = new byte[] { (byte) 0x89, 0x50, 0x4E, @@ -119,7 +119,7 @@ public final class Picture { } else { _blipRecords = Collections.emptyList(); } - + if ( fillBytes ) { fillImageContent(); } @@ -177,16 +177,16 @@ public final class Picture { { /* * http://www.codecomments.com/archive281-2004-3-158083.html - * + * * Algorithm proposed by Patrick TJ McPhee: - * + * * read 2 bytes make sure they are 'ffd8'x repeatedly: read 2 bytes make * sure the first one is 'ff'x if the second one is 'd9'x stop else if * the second one is c0 or c2 (or possibly other values ...) skip 2 * bytes read one byte into depth read two bytes into height read two * bytes into width else read two bytes into length skip forward * length-2 bytes - * + * * Also used Ruby code snippet from: * http://www.bigbold.com/snippets/posts/show/805 for reference */ @@ -321,7 +321,7 @@ public final class Picture { /** * Gets the initial width of the picture, in twips, prior to cropping or * scaling. - * + * * @return the initial width of the picture in twips */ public int getDxaGoal() @@ -352,7 +352,7 @@ public final class Picture { /** * Gets the initial height of the picture, in twips, prior to cropping or * scaling. - * + * * @return the initial width of the picture in twips */ public int getDyaGoal() @@ -384,7 +384,7 @@ public final class Picture { /** * Returns the MIME type for the image - * + * * @return MIME-type for known types of image or "image/unknown" if unknown */ public String getMimeType() @@ -395,7 +395,7 @@ public final class Picture { /** * Returns picture's content as stored in the Word file, i.e. possibly in * compressed form. - * + * * @return picture's content as it stored in Word file or an empty byte array * if it cannot be read. */ @@ -416,14 +416,14 @@ public final class Picture { EscherBlipRecord blip = ( (EscherBSERecord) escherRecord ).getBlipRecord(); if (blip != null) { return blip.getPicturedata(); - + } } return new byte[0]; } /** - * + * * @return size in bytes of the picture */ public int getSize() @@ -460,10 +460,10 @@ public final class Picture { } return width; } - + /** * returns the description stored in the alternative text - * + * * @return pictue description */ public String getDescription() @@ -486,7 +486,7 @@ public final class Picture { /** * tries to suggest extension for picture's file by matching signatures of * popular image formats to first bytes of picture's contents - * + * * @return suggested file extension */ public String suggestFileExtension() @@ -498,7 +498,7 @@ public final class Picture { * Tries to suggest a filename: hex representation of picture structure * offset in "Data" stream plus extension that is tried to determine from * first byte of picture's content. - * + * * @return suggested file name */ public String suggestFullFileName() @@ -571,7 +571,7 @@ public final class Picture { * Writes Picture's content bytes to specified OutputStream. Is useful when * there is need to write picture bytes directly to stream, omitting its * representation in memory as distinct byte array. - * + * * @param out * a stream to write to * @throws IOException diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java index 077c290849..5ab8857233 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java @@ -214,18 +214,18 @@ public final class TestBasics { @Test public void testEncoding() throws Exception { assertEquals(2, cyrillic.getRecipientDetailsChunks().length); - assertEquals("CP1252", cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); - assertEquals("CP1252", cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding()); + assertEquals("CP1252", cyrillic.getRecipientDetailsChunks()[0].getRecipientDisplayNameChunk().get7BitEncoding()); + assertEquals("CP1252", cyrillic.getRecipientDetailsChunks()[1].getRecipientDisplayNameChunk().get7BitEncoding()); cyrillic.guess7BitEncoding(); - assertEquals("Cp1251", cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); - assertEquals("Cp1251", cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding()); + assertEquals("Cp1251", cyrillic.getRecipientDetailsChunks()[0].getRecipientDisplayNameChunk().get7BitEncoding()); + assertEquals("Cp1251", cyrillic.getRecipientDetailsChunks()[1].getRecipientDisplayNameChunk().get7BitEncoding()); // Override it, check it's taken cyrillic.set7BitEncoding("UTF-8"); - assertEquals("UTF-8", cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); - assertEquals("UTF-8", cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding()); + assertEquals("UTF-8", cyrillic.getRecipientDetailsChunks()[0].getRecipientDisplayNameChunk().get7BitEncoding()); + assertEquals("UTF-8", cyrillic.getRecipientDetailsChunks()[1].getRecipientDisplayNameChunk().get7BitEncoding()); // Check with a file that has no headers @@ -235,10 +235,10 @@ public final class TestBasics { assertTrue(html.contains("text/html; charset=big5"), "Charset not found:\n" + html); // Defaults to CP1251 - assertEquals("CP1252", chinese.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); + assertEquals("CP1252", chinese.getRecipientDetailsChunks()[0].getRecipientDisplayNameChunk().get7BitEncoding()); // But after guessing goes to the correct one, cp950 (Windows Traditional Chinese) chinese.guess7BitEncoding(); - assertEquals("cp950", chinese.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); + assertEquals("cp950", chinese.getRecipientDetailsChunks()[0].getRecipientDisplayNameChunk().get7BitEncoding()); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestNameIdChunks.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestNameIdChunks.java index c3ddf2b7fc..2d7cc1355d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestNameIdChunks.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestNameIdChunks.java @@ -59,7 +59,7 @@ public class TestNameIdChunks { */ @Test public void testReadKeywords() { - long keywordsPropTag = keywordsMsg.getNameIdChunks().getPropertyTag(PS_PUBLIC_STRINGS.classID, "Keywords", 0); + long keywordsPropTag = keywordsMsg.getNameIdChunks().getPropertyTag(PS_PUBLIC_STRINGS.getClassID(), "Keywords", 0); assertEquals(0x8003, keywordsPropTag); String[] exp = { "TODO", "Currently Important", "Currently To Do", "Test" }; String[] act = getValues(keywordsPropTag); @@ -72,7 +72,7 @@ public class TestNameIdChunks { */ @Test public void testCurrentVersionName() { - long testPropTag = keywordsMsg.getNameIdChunks().getPropertyTag(PSETID_COMMON.classID, null, 0x8554); + long testPropTag = keywordsMsg.getNameIdChunks().getPropertyTag(PSETID_COMMON.getClassID(), null, 0x8554); assertEquals(0x8006, testPropTag); String[] exp = { "16.0" }; String[] act = getValues(testPropTag); diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java index 8b134f76b2..9f68c44b03 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java @@ -72,8 +72,8 @@ public final class TestSorters { new RecipientChunks("__recip_version1.0_#00000000"), }; Arrays.sort(chunks, new RecipientChunksSorter()); - assertEquals(0, chunks[0].recipientNumber); - assertEquals(1, chunks[1].recipientNumber); + assertEquals(0, chunks[0].getRecipientNumber()); + assertEquals(1, chunks[1].getRecipientNumber()); // Lots, with gaps chunks = new RecipientChunks[] { @@ -87,13 +87,13 @@ public final class TestSorters { new RecipientChunks("__recip_version1.0_#00000000"), }; Arrays.sort(chunks, new RecipientChunksSorter()); - assertEquals(0, chunks[0].recipientNumber); - assertEquals(1, chunks[1].recipientNumber); - assertEquals(5, chunks[2].recipientNumber); - assertEquals(9, chunks[3].recipientNumber); - assertEquals(0xFF, chunks[4].recipientNumber); - assertEquals(0x205, chunks[5].recipientNumber); - assertEquals(0x404, chunks[6].recipientNumber); - assertEquals(0x20001, chunks[7].recipientNumber); + assertEquals(0, chunks[0].getRecipientNumber()); + assertEquals(1, chunks[1].getRecipientNumber()); + assertEquals(5, chunks[2].getRecipientNumber()); + assertEquals(9, chunks[3].getRecipientNumber()); + assertEquals(0xFF, chunks[4].getRecipientNumber()); + assertEquals(0x205, chunks[5].getRecipientNumber()); + assertEquals(0x404, chunks[6].getRecipientNumber()); + assertEquals(0x20001, chunks[7].getRecipientNumber()); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java b/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java index c68326dee0..e8f175266a 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java @@ -90,11 +90,11 @@ public final class TestPOIFSChunkParser { assertTrue(groups[2] instanceof NameIdChunks); RecipientChunks recips = (RecipientChunks)groups[1]; - assertEquals("kevin.roast@alfresco.org", recips.recipientSMTPChunk.getValue()); + assertEquals("kevin.roast@alfresco.org", recips.getRecipientSMTPChunk().getValue()); assertEquals("/O=HOSTEDSERVICE2/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=Kevin.roast@ben", - recips.recipientEmailChunk.getValue()); + recips.getRecipientEmailChunk().getValue()); - String search = new String(recips.recipientSearchChunk.getValue(), StandardCharsets.US_ASCII); + String search = new String(recips.getRecipientSearchChunk().getValue(), StandardCharsets.US_ASCII); assertEquals("CN=KEVIN.ROAST@BEN\0", search.substring(search.length()-19)); // Now via MAPIMessage @@ -102,17 +102,17 @@ public final class TestPOIFSChunkParser { assertNotNull(msg.getRecipientDetailsChunks()); assertEquals(1, msg.getRecipientDetailsChunks().length); - assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].recipientSMTPChunk.getValue()); + assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].getRecipientSMTPChunk().getValue()); assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].getRecipientEmailAddress()); assertEquals("Kevin Roast", msg.getRecipientDetailsChunks()[0].getRecipientName()); assertEquals("kevin.roast@alfresco.org", msg.getRecipientEmailAddress()); // Try both SMTP and EX files for recipient - assertEquals("EX", msg.getRecipientDetailsChunks()[0].deliveryTypeChunk.getValue()); - assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].recipientSMTPChunk.getValue()); + assertEquals("EX", msg.getRecipientDetailsChunks()[0].getDeliveryTypeChunk().getValue()); + assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].getRecipientSMTPChunk().getValue()); assertEquals("/O=HOSTEDSERVICE2/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=Kevin.roast@ben", - msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue()); + msg.getRecipientDetailsChunks()[0].getRecipientEmailChunk().getValue()); msg.close(); simple.close(); @@ -123,10 +123,10 @@ public final class TestPOIFSChunkParser { assertNotNull(msg.getRecipientDetailsChunks()); assertEquals(1, msg.getRecipientDetailsChunks().length); - assertEquals("SMTP", msg.getRecipientDetailsChunks()[0].deliveryTypeChunk.getValue()); - assertNull(msg.getRecipientDetailsChunks()[0].recipientSMTPChunk); - assertNull(msg.getRecipientDetailsChunks()[0].recipientNameChunk); - assertEquals("travis@overwrittenstack.com", msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue()); + assertEquals("SMTP", msg.getRecipientDetailsChunks()[0].getDeliveryTypeChunk().getValue()); + assertNull(msg.getRecipientDetailsChunks()[0].getRecipientSMTPChunk()); + assertNull(msg.getRecipientDetailsChunks()[0].getRecipientNameChunk()); + assertEquals("travis@overwrittenstack.com", msg.getRecipientDetailsChunks()[0].getRecipientEmailChunk().getValue()); assertEquals("travis@overwrittenstack.com", msg.getRecipientEmailAddress()); msg.close(); @@ -166,12 +166,12 @@ public final class TestPOIFSChunkParser { (RecipientChunks)groups[7], }; assertEquals(6, chunks.length); - assertEquals(0, chunks[0].recipientNumber); - assertEquals(2, chunks[1].recipientNumber); - assertEquals(4, chunks[2].recipientNumber); - assertEquals(5, chunks[3].recipientNumber); - assertEquals(3, chunks[4].recipientNumber); - assertEquals(1, chunks[5].recipientNumber); + assertEquals(0, chunks[0].getRecipientNumber()); + assertEquals(2, chunks[1].getRecipientNumber()); + assertEquals(4, chunks[2].getRecipientNumber()); + assertEquals(5, chunks[3].getRecipientNumber()); + assertEquals(3, chunks[4].getRecipientNumber()); + assertEquals(1, chunks[5].getRecipientNumber()); // Check assertEquals("'Ashutosh Dandavate'", chunks[0].getRecipientName()); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 342335e267..ff955df1e3 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1640,8 +1640,8 @@ public final class TestBugs extends BaseTestBugzillaIssues { } } assertNotNull(tr); - assertEquals(1, tr._tabids.length); - assertEquals(0, tr._tabids[0]); + assertEquals(1, tr.getTabIdSize()); + assertEquals(0, tr.getTabIdAt(0)); // Ensure the print setup assertEquals("new_sheet!$A$1:$C$1", wb2.getPrintArea(0)); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java b/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java index 135cd1f1a6..667c58f0d6 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java @@ -263,7 +263,7 @@ public final class TestSumifs { HSSFSheet example3 = wb.getSheet("Example 3"); HSSFCell ex3cell = example3.getRow(5).getCell(2); fe.evaluate(ex3cell); - assertEquals(8,8, ex3cell.getNumericCellValue()); + assertEquals(8.8, ex3cell.getNumericCellValue(), 0); HSSFSheet example4 = wb.getSheet("Example 4"); HSSFCell ex4cell = example4.getRow(8).getCell(2);