From 1dc771394bedaf456b85e9e15d90f7429908919b Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Thu, 2 Apr 2020 23:54:48 +0000 Subject: [PATCH] Sonar Fixes - "static" base class members should not be accessed via derived types git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876067 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hpsf/VariantSupport.java | 20 ++--- .../poi/hssf/usermodel/HSSFPicture.java | 81 ++++++++++++++----- .../apache/poi/poifs/storage/BATBlock.java | 55 ++++++------- .../apache/poi/sl/image/ImageHeaderWMF.java | 35 ++++---- .../poi/ss/format/CellNumberFormatter.java | 3 +- .../apache/poi/ss/formula/ptg/AttrPtg.java | 4 +- .../poi/poifs/crypt/dsig/SignatureConfig.java | 3 +- .../dsig/facets/EnvelopedSignatureFacet.java | 2 +- .../apache/poi/xdgf/geom/SplineRenderer.java | 3 +- .../poi/xssf/binary/XSSFBCellHeader.java | 3 +- .../poi/xssf/binary/XSSFBCellRange.java | 9 ++- .../poi/xssf/binary/XSSFBCommentsTable.java | 3 +- .../poi/xssf/eventusermodel/XSSFBReader.java | 8 +- .../apache/poi/hdgf/chunks/ChunkHeader.java | 12 +-- .../apache/poi/hemf/record/emf/HemfFill.java | 3 +- .../org/apache/poi/hslf/dev/PPTXMLDump.java | 9 ++- .../textproperties/TextPropCollection.java | 11 ++- .../hslf/record/HSLFEscherRecordFactory.java | 3 +- .../poi/hslf/record/TxMasterStyleAtom.java | 9 ++- .../poi/hslf/usermodel/HSLFAutoShape.java | 12 +-- .../poi/hslf/usermodel/HSLFPictureData.java | 19 ++--- .../converter/AbstractExcelConverter.java | 14 ++-- .../hssf/converter/ExcelToFoConverter.java | 22 ++--- .../hssf/converter/ExcelToHtmlConverter.java | 46 +++++------ .../hwpf/converter/AbstractWordConverter.java | 4 +- .../poi/hwpf/converter/AbstractWordUtils.java | 6 +- .../poi/hwpf/converter/FoDocumentFacade.java | 7 +- .../poi/hwpf/model/ComplexFileTable.java | 7 +- .../src/org/apache/poi/hwpf/model/FFData.java | 9 ++- .../poi/hwpf/model/FIBFieldHandler.java | 21 ++--- .../src/org/apache/poi/hwpf/model/Ffn.java | 27 ++++--- .../poi/hwpf/model/FileInformationBlock.java | 45 ++++++----- .../org/apache/poi/hwpf/model/FontTable.java | 11 +-- .../org/apache/poi/hwpf/model/LFOData.java | 5 +- .../org/apache/poi/hwpf/model/ListTables.java | 3 +- .../poi/hwpf/model/NilPICFAndBinData.java | 7 +- .../src/org/apache/poi/hwpf/model/OldFfn.java | 8 +- .../apache/poi/hwpf/model/OldFontTable.java | 3 +- .../poi/hwpf/model/OldSectionTable.java | 3 +- .../poi/hwpf/model/ParagraphHeight.java | 13 +-- .../poi/hwpf/model/PieceDescriptor.java | 9 ++- .../org/apache/poi/hwpf/model/PlexOfCps.java | 9 ++- .../src/org/apache/poi/hwpf/model/PlfLfo.java | 3 +- .../poi/hwpf/model/SectionDescriptor.java | 13 +-- .../apache/poi/hwpf/model/SectionTable.java | 3 +- .../src/org/apache/poi/hwpf/model/Sttb.java | 21 ++--- .../poi/hwpf/model/StyleDescription.java | 13 +-- .../org/apache/poi/hwpf/model/StyleSheet.java | 9 ++- .../src/org/apache/poi/hwpf/model/Xst.java | 11 +-- .../src/org/apache/poi/hwpf/model/Xstz.java | 5 +- .../hwpf/sprm/ParagraphSprmUncompressor.java | 57 +------------ .../poi/hwpf/sprm/SectionSprmCompressor.java | 5 +- .../org/apache/poi/hwpf/sprm/SprmBuffer.java | 21 ++--- .../apache/poi/hwpf/sprm/SprmOperation.java | 5 +- .../org/apache/poi/hwpf/sprm/SprmUtils.java | 7 +- .../poi/hwpf/sprm/TableSprmCompressor.java | 7 +- .../apache/poi/hwpf/usermodel/BorderCode.java | 5 +- .../poi/hwpf/usermodel/DateAndTime.java | 5 +- .../hwpf/usermodel/LineSpacingDescriptor.java | 5 +- .../org/apache/poi/hwpf/usermodel/Range.java | 9 ++- 60 files changed, 406 insertions(+), 384 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java index 0e8dc08c6e..ed57f41967 100644 --- a/src/java/org/apache/poi/hpsf/VariantSupport.java +++ b/src/java/org/apache/poi/hpsf/VariantSupport.java @@ -57,7 +57,7 @@ public class VariantSupport extends Variant { Variant.VT_FILETIME, Variant.VT_LPSTR, Variant.VT_LPWSTR, Variant.VT_CF, Variant.VT_BOOL }; - + private static final POILogger logger = POILogFactory.getLogger(VariantSupport.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000; @@ -69,10 +69,10 @@ public class VariantSupport extends Variant { * been issued for. */ private static List unsupportedMessage; - + private static final byte[] paddingBytes = new byte[3]; - + /** * Specifies whether warnings about unsupported variant types are to be * written to {@code System.err} or not. @@ -166,7 +166,7 @@ public class VariantSupport extends Variant { LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream(src, offset); return read( lei, length, type, codepage ); } - + public static Object read( LittleEndianByteArrayInputStream lei, final int length, final long type, final int codepage ) throws ReadingNotSupportedException, UnsupportedEncodingException { @@ -233,7 +233,7 @@ public class VariantSupport extends Variant { * * August 20, 2009 */ - // l1 = LittleEndian.getInt(src, o1); o1 += LittleEndian.INT_SIZE; + // l1 = LittleEndian.getInt(src, o1); o1 += LittleEndianConts.INT_SIZE; // } // final byte[] v = new byte[l1]; // System.arraycopy(src, o1, v, 0, v.length); @@ -246,7 +246,7 @@ public class VariantSupport extends Variant { case Variant.VT_BOOL: VariantBool bool = (VariantBool) typedPropertyValue.getValue(); return bool.getValue(); - + /* * it is not very good, but what can do without breaking current * API? --sergey @@ -359,7 +359,7 @@ public class VariantSupport extends Variant { if (bi.bitLength() > 64) { throw new WritingNotSupportedException(type, value); } - + byte[] biBytesBE = bi.toByteArray(), biBytesLE = new byte[LittleEndianConsts.LONG_SIZE]; int i=biBytesBE.length; for (byte b : biBytesBE) { @@ -368,7 +368,7 @@ public class VariantSupport extends Variant { } i--; } - + out.write(biBytesLE); length = LittleEndianConsts.LONG_SIZE; } @@ -383,7 +383,7 @@ public class VariantSupport extends Variant { } break; } - + case Variant.VT_R8: if (value instanceof Number) { LittleEndian.putDouble( ((Number)value).doubleValue(), out); @@ -412,7 +412,7 @@ public class VariantSupport extends Variant { throw new WritingNotSupportedException(type, value); } } - + /* pad values to 4-bytes */ int padding = (4-(length & 0x3)) & 0x3; out.write(paddingBytes, 0, padding); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java index 1a877ee3ce..b3a74e69f8 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java @@ -36,24 +36,62 @@ import org.apache.poi.hssf.record.EscherAggregate; import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.Picture; +import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.ImageUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.apache.poi.util.Removal; import org.apache.poi.util.StringUtil; /** * Represents a escher picture. Eg. A GIF, JPEG etc... */ public class HSSFPicture extends HSSFSimpleShape implements Picture { - @SuppressWarnings("unused") - private static POILogger logger = POILogFactory.getLogger(HSSFPicture.class); - - public static final int PICTURE_TYPE_EMF = HSSFWorkbook.PICTURE_TYPE_EMF; // Windows Enhanced Metafile - public static final int PICTURE_TYPE_WMF = HSSFWorkbook.PICTURE_TYPE_WMF; // Windows Metafile - public static final int PICTURE_TYPE_PICT = HSSFWorkbook.PICTURE_TYPE_PICT; // Macintosh PICT - public static final int PICTURE_TYPE_JPEG = HSSFWorkbook.PICTURE_TYPE_JPEG; // JFIF - public static final int PICTURE_TYPE_PNG = HSSFWorkbook.PICTURE_TYPE_PNG; // PNG - public static final int PICTURE_TYPE_DIB = HSSFWorkbook.PICTURE_TYPE_DIB; // Windows DIB + /** + * Windows Enhanced Metafile + * @deprecated use {@link Workbook#PICTURE_TYPE_EMF} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_EMF = Workbook.PICTURE_TYPE_EMF; + + /** + * Windows Metafile + * @deprecated use {@link Workbook#PICTURE_TYPE_WMF} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_WMF = Workbook.PICTURE_TYPE_WMF; + + /** + * Macintosh PICT + * @deprecated use {@link Workbook#PICTURE_TYPE_PICT} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_PICT = Workbook.PICTURE_TYPE_PICT; + + /** + * JFIF / JPEG + * @deprecated use {@link Workbook#PICTURE_TYPE_JPEG} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_JPEG = Workbook.PICTURE_TYPE_JPEG; + + /** + * PNG + * @deprecated use {@link Workbook#PICTURE_TYPE_PNG} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_PNG = Workbook.PICTURE_TYPE_PNG; + + /** + * Windows DIB + * @deprecated use {@link Workbook#PICTURE_TYPE_DIB} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_DIB = Workbook.PICTURE_TYPE_DIB; public HSSFPicture(EscherContainerRecord spContainer, ObjRecord objRecord) { super(spContainer, objRecord); @@ -88,6 +126,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { protected EscherContainerRecord createSpContainer() { EscherContainerRecord spContainer = super.createSpContainer(); EscherOptRecord opt = spContainer.getChildById(EscherOptRecord.RECORD_ID); + assert(opt != null); opt.removeEscherProperty(EscherPropertyTypes.LINESTYLE__LINEDASHING); opt.removeEscherProperty(EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH); spContainer.removeChildRecord(spContainer.getChildById(EscherTextboxRecord.RECORD_ID)); @@ -96,7 +135,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { /** * Reset the image to the dimension of the embedded image - * + * *

* Please note, that this method works correctly only for workbooks * with default font size (Arial 10pt for .xls). @@ -117,7 +156,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { public void resize(double scale) { resize(scale,scale); } - + /** * Resize the image *

@@ -129,7 +168,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { * resize(1.0,1.0) keeps the original size,
* resize(0.5,0.5) resize to 50% of the original,
* resize(2.0,2.0) resizes to 200% of the original.
- * resize({@link Double#MAX_VALUE},{@link Double#MAX_VALUE}) resizes to the dimension of the embedded image. + * resize({@link Double#MAX_VALUE},{@link Double#MAX_VALUE}) resizes to the dimension of the embedded image. *

* * @param scaleX the amount by which the image width is multiplied relative to the original width. @@ -175,7 +214,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { public HSSFClientAnchor getPreferredSize(double scale){ return getPreferredSize(scale, scale); } - + /** * Calculate the preferred size for this picture. * @@ -203,7 +242,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { int type = bse.getBlipTypeWin32(); return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type); } - + /** * Return picture data for this shape * @@ -215,7 +254,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { if (picIdx == -1) { return null; } - + HSSFPatriarch patriarch = getPatriarch(); HSSFShape parent = getParent(); while(patriarch == null && parent != null) { @@ -252,9 +291,9 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { ? "" : StringUtil.getFromUnicodeLE(propFile.getComplexData()).trim(); } - + public void setFileName(String data){ - // TODO: add trailing \u0000? + // TODO: add trailing \u0000? byte[] bytes = StringUtil.getToUnicodeLE(data); EscherComplexProperty prop = new EscherComplexProperty(EscherPropertyTypes.BLIP__BLIPFILENAME, true, bytes.length); prop.setComplexData(bytes); @@ -274,7 +313,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise(); return new HSSFPicture(spContainer, obj); } - + /** * @return the anchor that is used by this picture. */ @@ -284,7 +323,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { return (a instanceof HSSFClientAnchor) ? (HSSFClientAnchor)a : null; } - + /** * @return the sheet which contains the picture shape */ diff --git a/src/java/org/apache/poi/poifs/storage/BATBlock.java b/src/java/org/apache/poi/poifs/storage/BATBlock.java index 4e381f7b6c..4a2f3f3b8f 100644 --- a/src/java/org/apache/poi/poifs/storage/BATBlock.java +++ b/src/java/org/apache/poi/poifs/storage/BATBlock.java @@ -26,6 +26,7 @@ import java.util.List; import org.apache.poi.poifs.common.POIFSBigBlockSize; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * A block of block allocation table entries. BATBlocks are created @@ -39,30 +40,30 @@ public final class BATBlock implements BlockWritable { private POIFSBigBlockSize bigBlockSize; /** - * For a regular fat block, these are 128 / 1024 + * For a regular fat block, these are 128 / 1024 * next sector values. * For a XFat (DIFat) block, these are 127 / 1023 * next sector values, then a chaining value. */ private int[] _values; - + /** * Does this BATBlock have any free sectors in it? */ private boolean _has_free_sectors; - + /** * Where in the file are we? */ private int ourBlockIndex; - + /** * Create a single instance initialized with default values */ private BATBlock(POIFSBigBlockSize bigBlockSize) { this.bigBlockSize = bigBlockSize; - + int _entries_per_block = bigBlockSize.getBATEntriesPerBlock(); _values = new int[_entries_per_block]; _has_free_sectors = true; @@ -89,19 +90,19 @@ public final class BATBlock implements BlockWritable { { // Create an empty block BATBlock block = new BATBlock(bigBlockSize); - + // Fill it - byte[] buffer = new byte[LittleEndian.INT_SIZE]; + byte[] buffer = new byte[LittleEndianConsts.INT_SIZE]; for(int i=0; i bats) { POIFSBigBlockSize bigBlockSize = header.getBigBlockSize(); int entriesPerBlock = bigBlockSize.getBATEntriesPerBlock(); - + int whichBAT = offset / entriesPerBlock; int index = offset % entriesPerBlock; return new BATBlockAndIndex( index, bats.get(whichBAT) ); } - + /** * Returns the BATBlock that handles the specified offset, * and the relative index within it, for the mini stream. * The List of BATBlocks must be in sequential order */ - public static BATBlockAndIndex getSBATBlockAndIndex(final int offset, + public static BATBlockAndIndex getSBATBlockAndIndex(final int offset, final HeaderBlock header, final List sbats) { return getBATBlockAndIndex(offset, header, sbats); } - + /** * Does this BATBlock have any free sectors in it, or * is it full? @@ -190,20 +191,20 @@ public final class BATBlock implements BlockWritable { } return usedSectors; } - + public int getValueAt(int relativeOffset) { if(relativeOffset >= _values.length) { throw new ArrayIndexOutOfBoundsException( - "Unable to fetch offset " + relativeOffset + " as the " + + "Unable to fetch offset " + relativeOffset + " as the " + "BAT only contains " + _values.length + " entries" - ); + ); } return _values[relativeOffset]; } public void setValueAt(int relativeOffset, int value) { int oldValue = _values[relativeOffset]; _values[relativeOffset] = value; - + // Do we need to re-compute the free? if(value == POIFSConstants.UNUSED_BLOCK) { _has_free_sectors = true; @@ -213,7 +214,7 @@ public final class BATBlock implements BlockWritable { recomputeFree(); } } - + /** * Record where in the file we live */ @@ -221,7 +222,7 @@ public final class BATBlock implements BlockWritable { this.ourBlockIndex = index; } /** - * Retrieve where in the file we live + * Retrieve where in the file we live */ public int getOurBlockIndex() { return ourBlockIndex; @@ -246,18 +247,18 @@ public final class BATBlock implements BlockWritable { // Save it out block.put( serialize() ); } - + private byte[] serialize() { // Create the empty array byte[] data = new byte[ bigBlockSize.getBigBlockSize() ]; - + // Fill in the values int offset = 0; for (int _value : _values) { LittleEndian.putInt(data, offset, _value); - offset += LittleEndian.INT_SIZE; + offset += LittleEndianConsts.INT_SIZE; } - + // Done return data; } diff --git a/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java b/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java index c3274d97f6..d210bc5429 100644 --- a/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java +++ b/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java @@ -24,6 +24,7 @@ import java.io.OutputStream; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; @@ -77,7 +78,7 @@ public class ImageHeaderWMF { public ImageHeaderWMF(byte[] data, final int off) { int offset = off; - int key = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; //header key + int key = LittleEndian.getInt(data, offset); offset += LittleEndianConsts.INT_SIZE; //header key if (key != APMHEADER_KEY) { LOG.log(POILogger.WARN, "WMF file doesn't contain a placeable header - ignore parsing"); handle = 0; @@ -90,16 +91,16 @@ public class ImageHeaderWMF { return; } - handle = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; - left = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; - top = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; - right = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; - bottom = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; + handle = LittleEndian.getUShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + left = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + top = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + right = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + bottom = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; - inch = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; - reserved = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; + inch = LittleEndian.getUShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + reserved = LittleEndian.getInt(data, offset); offset += LittleEndianConsts.INT_SIZE; - checksum = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; + checksum = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; if (checksum != getChecksum()){ LOG.log(POILogger.WARN, "WMF checksum does not match the header data"); } @@ -124,14 +125,14 @@ public class ImageHeaderWMF { public void write(OutputStream out) throws IOException { byte[] header = new byte[22]; int pos = 0; - LittleEndian.putInt(header, pos, APMHEADER_KEY); pos += LittleEndian.INT_SIZE; //header key - LittleEndian.putUShort(header, pos, 0); pos += LittleEndian.SHORT_SIZE; //hmf - LittleEndian.putUShort(header, pos, left); pos += LittleEndian.SHORT_SIZE; //left - LittleEndian.putUShort(header, pos, top); pos += LittleEndian.SHORT_SIZE; //top - LittleEndian.putUShort(header, pos, right); pos += LittleEndian.SHORT_SIZE; //right - LittleEndian.putUShort(header, pos, bottom); pos += LittleEndian.SHORT_SIZE; //bottom - LittleEndian.putUShort(header, pos, inch); pos += LittleEndian.SHORT_SIZE; //inch - LittleEndian.putInt(header, pos, 0); pos += LittleEndian.INT_SIZE; //reserved + LittleEndian.putInt(header, pos, APMHEADER_KEY); pos += LittleEndianConsts.INT_SIZE; //header key + LittleEndian.putUShort(header, pos, 0); pos += LittleEndianConsts.SHORT_SIZE; //hmf + LittleEndian.putUShort(header, pos, left); pos += LittleEndianConsts.SHORT_SIZE; //left + LittleEndian.putUShort(header, pos, top); pos += LittleEndianConsts.SHORT_SIZE; //top + LittleEndian.putUShort(header, pos, right); pos += LittleEndianConsts.SHORT_SIZE; //right + LittleEndian.putUShort(header, pos, bottom); pos += LittleEndianConsts.SHORT_SIZE; //bottom + LittleEndian.putUShort(header, pos, inch); pos += LittleEndianConsts.SHORT_SIZE; //inch + LittleEndian.putInt(header, pos, 0); pos += LittleEndianConsts.INT_SIZE; //reserved checksum = getChecksum(); LittleEndian.putUShort(header, pos, checksum); diff --git a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java index 3480343218..901a65c2f9 100644 --- a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java @@ -19,6 +19,7 @@ package org.apache.poi.ss.format; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.FieldPosition; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Formatter; @@ -558,7 +559,7 @@ public class CellNumberFormatter extends CellFormatter { private void writeScientific(double value, StringBuffer output, Set mods) { StringBuffer result = new StringBuffer(); - FieldPosition fractionPos = new FieldPosition(DecimalFormat.FRACTION_FIELD); + FieldPosition fractionPos = new FieldPosition(NumberFormat.FRACTION_FIELD); decimalFmt.format(value, result, fractionPos); writeInteger(result, output, integerSpecials, mods, showGroupingSeparator); writeFractional(result, output); diff --git a/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java b/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java index d046b684b6..a87e11e410 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java @@ -19,7 +19,7 @@ package org.apache.poi.ss.formula.ptg; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; -import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianOutput; @@ -208,7 +208,7 @@ public final class AttrPtg extends ControlPtg { public int getSize() { if (_jumpTable != null) { - return SIZE + (_jumpTable.length + 1) * LittleEndian.SHORT_SIZE; + return SIZE + (_jumpTable.length + 1) * LittleEndianConsts.SHORT_SIZE; } return SIZE; } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureConfig.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureConfig.java index f122b36296..13346dc9e4 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureConfig.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureConfig.java @@ -40,6 +40,7 @@ import java.util.stream.Collectors; import javax.xml.crypto.URIDereferencer; import javax.xml.crypto.dsig.CanonicalizationMethod; import javax.xml.crypto.dsig.DigestMethod; +import javax.xml.crypto.dsig.Transform; import javax.xml.crypto.dsig.XMLSignatureFactory; import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory; @@ -405,9 +406,9 @@ public class SignatureConfig { } switch (canonicalizationMethod) { + case Transform.ENVELOPED: case CanonicalizationMethod.INCLUSIVE: case CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS: - case CanonicalizationMethod.ENVELOPED: case CanonicalizationMethod.EXCLUSIVE: case CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS: return canonicalizationMethod; diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/EnvelopedSignatureFacet.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/EnvelopedSignatureFacet.java index d37cc2ce77..6baebff972 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/EnvelopedSignatureFacet.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/EnvelopedSignatureFacet.java @@ -53,7 +53,7 @@ public class EnvelopedSignatureFacet implements SignatureFacet { , List objects) throws XMLSignatureException { List transforms = new ArrayList<>(); - Transform envelopedTransform = newTransform(signatureInfo, CanonicalizationMethod.ENVELOPED); + Transform envelopedTransform = newTransform(signatureInfo, Transform.ENVELOPED); transforms.add(envelopedTransform); Transform exclusiveTransform = newTransform(signatureInfo, CanonicalizationMethod.EXCLUSIVE); transforms.add(exclusiveTransform); diff --git a/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java b/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java index c16835604c..dd4bfc20ed 100644 --- a/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java +++ b/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java @@ -17,6 +17,7 @@ package org.apache.poi.xdgf.geom; +import com.graphbuilder.curve.BSpline; import com.graphbuilder.curve.ControlPath; import com.graphbuilder.curve.GroupIterator; import com.graphbuilder.curve.NURBSpline; @@ -49,7 +50,7 @@ public class SplineRenderer { NURBSpline spline = new NURBSpline(controlPoints, gi); spline.setDegree(degree); - spline.setKnotVectorType(NURBSpline.NON_UNIFORM); + spline.setKnotVectorType(BSpline.NON_UNIFORM); spline.setKnotVector(knots); if (weights == null) { 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 46d44bdc47..089a605c03 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellHeader.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellHeader.java @@ -19,6 +19,7 @@ package org.apache.poi.xssf.binary; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * This class encapsulates what the spec calls a "Cell" object. @@ -39,7 +40,7 @@ class XSSFBCellHeader { * @param cell cell buffer to update */ public static void parse(byte[] data, int offset, int currentRow, XSSFBCellHeader cell) { - int colNum = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndian.INT_SIZE; + int colNum = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndianConsts.INT_SIZE; int styleIdx = XSSFBUtils.get24BitInt(data, offset); offset += 3; //TODO: range checking boolean showPhonetic = false;//TODO: fill this out diff --git a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellRange.java b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellRange.java index b8d507d275..d090002a28 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellRange.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCellRange.java @@ -20,6 +20,7 @@ package org.apache.poi.xssf.binary; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * @since 3.16-beta3 @@ -28,7 +29,7 @@ import org.apache.poi.util.LittleEndian; class XSSFBCellRange { //TODO: Convert this to generate an AreaReference - public static final int length = 4* LittleEndian.INT_SIZE; + public static final int length = 4* LittleEndianConsts.INT_SIZE; /** * Parses an RfX cell range from the data starting at the offset. * This performs no range checking. @@ -41,9 +42,9 @@ class XSSFBCellRange { if (cellRange == null) { cellRange = new XSSFBCellRange(); } - cellRange.firstRow = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndian.INT_SIZE; - cellRange.lastRow = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndian.INT_SIZE; - cellRange.firstCol = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndian.INT_SIZE; + cellRange.firstRow = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndianConsts.INT_SIZE; + cellRange.lastRow = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndianConsts.INT_SIZE; + cellRange.firstCol = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndianConsts.INT_SIZE; cellRange.lastCol = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); return cellRange; diff --git a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCommentsTable.java b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCommentsTable.java index f84017b764..057f61ee20 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCommentsTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBCommentsTable.java @@ -29,6 +29,7 @@ import java.util.TreeMap; import org.apache.poi.ss.util.CellAddress; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * @since 3.16-beta3 @@ -60,7 +61,7 @@ public class XSSFBCommentsTable extends XSSFBParser { switch (recordType) { case BrtBeginComment: int offset = 0; - authorId = XSSFBUtils.castToInt(LittleEndian.getUInt(data)); offset += LittleEndian.INT_SIZE; + authorId = XSSFBUtils.castToInt(LittleEndian.getUInt(data)); offset += LittleEndianConsts.INT_SIZE; cellRange = XSSFBCellRange.parse(data, offset, cellRange); offset+= XSSFBCellRange.length; //for strict parsing; confirm that firstRow==lastRow and firstCol==colLats (2.4.28) diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java index ac416bb4d6..b1d7700082 100644 --- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java +++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java @@ -36,8 +36,8 @@ import org.apache.poi.openxml4j.opc.PackagePartName; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.apache.poi.openxml4j.opc.PackagingURIHelper; -import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.xssf.binary.XSSFBCommentsTable; @@ -236,9 +236,9 @@ public class XSSFBReader extends XSSFReader { int offset = 0; //this is the sheet state #2.5.142 /*long hsShtat =*/ //noinspection ResultOfMethodCallIgnored - LittleEndian.getUInt(data, offset); offset += LittleEndian.INT_SIZE; + LittleEndian.getUInt(data, offset); offset += LittleEndianConsts.INT_SIZE; - long iTabID = LittleEndian.getUInt(data, offset); offset += LittleEndian.INT_SIZE; + long iTabID = LittleEndian.getUInt(data, offset); offset += LittleEndianConsts.INT_SIZE; //according to #2.4.304 if (iTabID < 1 || iTabID > 0x0000FFFFL) { throw new XSSFBParseException("table id out of range: "+iTabID); @@ -257,7 +257,7 @@ public class XSSFBReader extends XSSFReader { //undocumented what is contained in these 8 bytes. //for the non-beta xlsb files, this would be 4, not 8. int offset = 8; - long iTabID = LittleEndian.getUInt(data, offset); offset += LittleEndian.INT_SIZE; + long iTabID = LittleEndian.getUInt(data, offset); offset += LittleEndianConsts.INT_SIZE; if (iTabID < 1 || iTabID > 0x0000FFFFL) { throw new XSSFBParseException("table id out of range: "+iTabID); } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java index 523aed259f..f5493ac643 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java @@ -17,10 +17,10 @@ package org.apache.poi.hdgf.chunks; -import org.apache.poi.util.LittleEndian; - import java.nio.charset.Charset; +import org.apache.poi.util.LittleEndian; + /** * A chunk header */ @@ -79,13 +79,7 @@ public abstract class ChunkHeader { * @return the header size */ public static int getHeaderSize(int documentVersion) { - if(documentVersion > 6) { - return ChunkHeaderV11.getHeaderSize(); - } else if(documentVersion == 6) { - return ChunkHeaderV6.getHeaderSize(); - } else { - return ChunkHeaderV4V5.getHeaderSize(); - } + return documentVersion >= 6 ? ChunkHeaderV6.getHeaderSize() : ChunkHeaderV4V5.getHeaderSize(); } public abstract int getSizeInBytes(); diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java index 195182a509..187096a8a6 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java +++ b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java @@ -49,7 +49,6 @@ import org.apache.poi.hwmf.record.HwmfTernaryRasterOp; import org.apache.poi.util.GenericRecordJsonWriter; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianInputStream; @@ -875,7 +874,7 @@ public final class HemfFill { xform.setToIdentity(); } - return 6 * LittleEndian.INT_SIZE; + return 6 * LittleEndianConsts.INT_SIZE; } static Shape getRgnShape(List rgnRects) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java b/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java index 11ab16ea54..fc0afe7ece 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java @@ -33,6 +33,7 @@ import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * Utility class which dumps raw contents of a ppt file into XML format @@ -72,7 +73,7 @@ public final class PPTXMLDump { return bos.toByteArray(); } } - + /** * Dump the structure of the supplied PPT file into XML * @param outWriter Writer to write out @@ -118,11 +119,11 @@ public final class PPTXMLDump { //read record header int info = LittleEndian.getUShort(data, pos); - pos += LittleEndian.SHORT_SIZE; + pos += LittleEndianConsts.SHORT_SIZE; int type = LittleEndian.getUShort(data, pos); - pos += LittleEndian.SHORT_SIZE; + pos += LittleEndianConsts.SHORT_SIZE; int size = (int)LittleEndian.getUInt(data, pos); - pos += LittleEndian.INT_SIZE; + pos += LittleEndianConsts.INT_SIZE; //get name of the record by type String recname = RecordTypes.forTypeID(type).name(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java index db041719a8..2e51499c8f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java @@ -32,7 +32,6 @@ import java.util.function.Supplier; import org.apache.poi.common.Duplicatable; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.hslf.exceptions.HSLFException; -import org.apache.poi.hslf.record.StyleTextPropAtom; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.POILogFactory; @@ -292,12 +291,12 @@ public class TextPropCollection implements GenericRecord, Duplicatable { if (!isMasterStyle) { // First goes the number of characters we affect // MasterStyles don't have this field - StyleTextPropAtom.writeLittleEndian(charactersCovered,o); + org.apache.poi.hslf.record.Record.writeLittleEndian(charactersCovered,o); } // Then we have the indentLevel field if it's a paragraph collection if (textPropType == TextPropType.paragraph && indentLevel > -1) { - StyleTextPropAtom.writeLittleEndian(indentLevel, o); + org.apache.poi.hslf.record.Record.writeLittleEndian(indentLevel, o); } // Then the mask field @@ -305,7 +304,7 @@ public class TextPropCollection implements GenericRecord, Duplicatable { for (TextProp textProp : textProps.values()) { mask |= textProp.getWriteMask(); } - StyleTextPropAtom.writeLittleEndian(mask,o); + org.apache.poi.hslf.record.Record.writeLittleEndian(mask,o); // Then the contents of all the properties for (TextProp textProp : getTextPropList()) { @@ -314,9 +313,9 @@ public class TextPropCollection implements GenericRecord, Duplicatable { // don't add empty properties, as they can't be recognized while reading continue; } else if (textProp.getSize() == 2) { - StyleTextPropAtom.writeLittleEndian((short)val,o); + org.apache.poi.hslf.record.Record.writeLittleEndian((short)val,o); } else if (textProp.getSize() == 4) { - StyleTextPropAtom.writeLittleEndian(val,o); + org.apache.poi.hslf.record.Record.writeLittleEndian(val,o); } else if (textProp instanceof HSLFTabStopPropCollection) { ((HSLFTabStopPropCollection)textProp).writeProperty(o); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherRecordFactory.java b/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherRecordFactory.java index 416022e7a9..36ed8229c2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherRecordFactory.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherRecordFactory.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf.record; import java.util.function.Supplier; import org.apache.poi.ddf.DefaultEscherRecordFactory; +import org.apache.poi.ddf.EscherClientDataRecord; import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecordFactory; @@ -40,7 +41,7 @@ public class HSLFEscherRecordFactory extends DefaultEscherRecordFactory { protected Supplier getConstructor(short options, short recordId) { if (recordId == EscherPlaceholder.RECORD_ID) { return EscherPlaceholder::new; - } else if (recordId == HSLFEscherClientDataRecord.RECORD_ID) { + } else if (recordId == EscherClientDataRecord.RECORD_ID) { return HSLFEscherClientDataRecord::new; } return super.getConstructor(options, recordId); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java index 3fd987188b..2597ccbe67 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java @@ -32,6 +32,7 @@ import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianOutputStream; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -148,7 +149,7 @@ public final class TxMasterStyleAtom extends RecordAtom { //number of indentation levels short levels = LittleEndian.getShort(_data, 0); - pos += LittleEndian.SHORT_SIZE; + pos += LittleEndianConsts.SHORT_SIZE; paragraphStyles = new ArrayList<>(levels); charStyles = new ArrayList<>(levels); @@ -159,19 +160,19 @@ public final class TxMasterStyleAtom extends RecordAtom { // Fetch the 2 byte value, that is safe to ignore for some types of text short indentLevel = LittleEndian.getShort(_data, pos); prprops.setIndentLevel(indentLevel); - pos += LittleEndian.SHORT_SIZE; + pos += LittleEndianConsts.SHORT_SIZE; } else { prprops.setIndentLevel((short)-1); } head = LittleEndian.getInt(_data, pos); - pos += LittleEndian.INT_SIZE; + pos += LittleEndianConsts.INT_SIZE; pos += prprops.buildTextPropList( head, _data, pos); paragraphStyles.add(prprops); head = LittleEndian.getInt(_data, pos); - pos += LittleEndian.INT_SIZE; + pos += LittleEndianConsts.INT_SIZE; TextPropCollection chprops = new TextPropCollection(0, TextPropType.character); pos += chprops.buildTextPropList( head, _data, pos); charStyles.add(chprops); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java index 206bb1641b..b10a6a52d5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java @@ -247,7 +247,7 @@ public class HSLFAutoShape extends HSLFTextShape implements AutoShape vertIter) { - HSLFFreeformShape.EscapeInfo ei = getEscapeInfo(segElem); + HSLFAutoShape.EscapeInfo ei = getEscapeInfo(segElem); if (ei == null) { return; } @@ -474,16 +474,16 @@ public class HSLFAutoShape extends HSLFTextShape implements AutoShape{@link #isOutputColumnHeaders()} == true - * + * * @param columnIndex * 0-based column index */ @@ -151,12 +151,12 @@ public abstract class AbstractExcelConverter value = ErrorEval.getText( cell.getErrorCellValue() ); break; default: - value = ExcelToHtmlUtils.EMPTY; + value = AbstractExcelUtils.EMPTY; break; } break; case BLANK: - value = ExcelToHtmlUtils.EMPTY; + value = AbstractExcelUtils.EMPTY; break; case NUMERIC: value = _formatter.formatCellValue( cell ); @@ -171,7 +171,7 @@ public abstract class AbstractExcelConverter return true; } - return ExcelToHtmlUtils.isEmpty( value ); + return AbstractExcelUtils.isEmpty( value ); } public void setFontReplacer( FontReplacer fontReplacer ) diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java index d9c1929e64..1cfb415b66 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java @@ -217,7 +217,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter } else { - value = ExcelToHtmlUtils.EMPTY; + value = AbstractExcelUtils.EMPTY; } break; case NUMERIC: @@ -237,12 +237,12 @@ public class ExcelToFoConverter extends AbstractExcelConverter POILogger.WARN, "Unexpected cell cachedFormulaResultType (" + cell.getCachedFormulaResultType() + ")" ); - value = ExcelToHtmlUtils.EMPTY; + value = AbstractExcelUtils.EMPTY; break; } break; case BLANK: - value = ExcelToHtmlUtils.EMPTY; + value = AbstractExcelUtils.EMPTY; break; case NUMERIC: value = _formatter.formatCellValue( cell ); @@ -259,7 +259,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter return true; } - final boolean noText = ExcelToHtmlUtils.isEmpty( value ); + final boolean noText = AbstractExcelUtils.isEmpty( value ); final boolean wrapInDivs = !noText && !cellStyle.getWrapText(); final boolean emptyStyle = isEmptyStyle( cellStyle ); @@ -318,7 +318,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter block.appendChild( text ); tableCellElement.appendChild( block ); - return ExcelToHtmlUtils.isEmpty( value ) && emptyStyle; + return AbstractExcelUtils.isEmpty( value ) && emptyStyle; } protected void processCellStyle( HSSFWorkbook workbook, @@ -349,7 +349,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter .getFillBackgroundColorColor(); if ( backgroundColor != null ) cellTarget.setAttribute( "background-color", - ExcelToHtmlUtils.getColor( backgroundColor ) ); + AbstractExcelUtils.getColor( backgroundColor ) ); } processCellStyleBorder( workbook, cellTarget, "top", @@ -373,17 +373,17 @@ public class ExcelToFoConverter extends AbstractExcelConverter return; StringBuilder borderStyle = new StringBuilder(); - borderStyle.append( ExcelToHtmlUtils.getBorderWidth( xlsBorder ) ); + borderStyle.append( AbstractExcelUtils.getBorderWidth( xlsBorder ) ); final HSSFColor color = workbook.getCustomPalette().getColor( borderColor ); if ( color != null ) { borderStyle.append( ' ' ); - borderStyle.append( ExcelToHtmlUtils.getColor( color ) ); + borderStyle.append( AbstractExcelUtils.getColor( color ) ); borderStyle.append( ' ' ); - borderStyle.append( ExcelToHtmlUtils.getBorderStyle( xlsBorder ) ); + borderStyle.append( AbstractExcelUtils.getBorderStyle( xlsBorder ) ); } cellTarget.setAttribute( "border-" + type, borderStyle.toString() ); @@ -404,7 +404,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter font.getColor() ); if ( fontColor != null ) blockTarget.setAttribute( "color", - ExcelToHtmlUtils.getColor( fontColor ) ); + AbstractExcelUtils.getColor( fontColor ) ); if ( font.getFontHeightInPoints() != 0 ) blockTarget.setAttribute( "font-size", font.getFontHeightInPoints() @@ -532,7 +532,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter if ( !isOutputHiddenColumns() && sheet.isColumnHidden( colIx ) ) continue; - CellRangeAddress range = ExcelToHtmlUtils.getMergedRange( + CellRangeAddress range = AbstractExcelUtils.getMergedRange( mergedRanges, row.getRowNum(), colIx ); if ( range != null diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java index e3f5e9aaff..1384cc67f0 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java @@ -53,7 +53,7 @@ import org.w3c.dom.Text; /** * Converts xls files (97-2007) to HTML file. - * + * * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com) */ @Beta @@ -63,7 +63,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { /** * Java main() interface to interact with {@link ExcelToHtmlConverter} - * + * *

* Usage: ExcelToHtmlConverter infile outfile *

@@ -92,7 +92,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { /** * Converts Excel file (97-2007) into HTML file. - * + * * @param xlsFile * workbook file to process * @return DOM representation of result HTML @@ -100,14 +100,14 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { * @throws ParserConfigurationException If configuration is incorrect */ public static Document process( File xlsFile ) throws IOException, ParserConfigurationException { - try (HSSFWorkbook workbook = ExcelToHtmlUtils.loadXls(xlsFile)) { + try (HSSFWorkbook workbook = AbstractExcelUtils.loadXls(xlsFile)) { return ExcelToHtmlConverter.process(workbook); } } /** * Converts Excel file (97-2007) into HTML file. - * + * * @param xlsStream workbook stream to process * @return DOM representation of result HTML * @throws IOException If an error occurs reading or writing files @@ -121,7 +121,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { /** * Converts Excel file (97-2007) into HTML file. - * + * * @param workbook workbook instance to process * @return DOM representation of result HTML * @throws IOException If an error occurs reading or writing files @@ -173,13 +173,13 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { case SOLID_FOREGROUND: final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor(); if ( foregroundColor == null ) break; - String fgCol = ExcelToHtmlUtils.getColor( foregroundColor ); + String fgCol = AbstractExcelUtils.getColor( foregroundColor ); style.append("background-color:").append(fgCol).append(";"); break; default: final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor(); if ( backgroundColor == null ) break; - String bgCol = ExcelToHtmlUtils.getColor( backgroundColor ); + String bgCol = AbstractExcelUtils.getColor( backgroundColor ); style.append("background-color:").append(bgCol).append(";"); break; } @@ -206,16 +206,16 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { } StringBuilder borderStyle = new StringBuilder(); - borderStyle.append( ExcelToHtmlUtils.getBorderWidth( xlsBorder ) ); + borderStyle.append( AbstractExcelUtils.getBorderWidth( xlsBorder ) ); borderStyle.append( ' ' ); - borderStyle.append( ExcelToHtmlUtils.getBorderStyle( xlsBorder ) ); + borderStyle.append( AbstractExcelUtils.getBorderStyle( xlsBorder ) ); final HSSFColor color = workbook.getCustomPalette().getColor( borderColor ); if ( color != null ) { borderStyle.append( ' ' ); - borderStyle.append( ExcelToHtmlUtils.getColor( color ) ); + borderStyle.append( AbstractExcelUtils.getColor( color ) ); } style.append("border-").append(type).append(":").append(borderStyle).append(";"); @@ -231,7 +231,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { final HSSFColor fontColor = workbook.getCustomPalette().getColor( font.getColor() ); if ( fontColor != null ) - style.append("color: ").append(ExcelToHtmlUtils.getColor(fontColor)).append("; "); + style.append("color: ").append(AbstractExcelUtils.getColor(fontColor)).append("; "); if ( font.getFontHeightInPoints() != 0 ) style.append("font-size:").append(font.getFontHeightInPoints()).append("pt;"); @@ -307,7 +307,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { } else { - value = ExcelToHtmlUtils.EMPTY; + value = AbstractExcelUtils.EMPTY; } break; case NUMERIC: @@ -327,12 +327,12 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { POILogger.WARN, "Unexpected cell cachedFormulaResultType (" + cell.getCachedFormulaResultType() + ")" ); - value = ExcelToHtmlUtils.EMPTY; + value = AbstractExcelUtils.EMPTY; break; } break; case BLANK: - value = ExcelToHtmlUtils.EMPTY; + value = AbstractExcelUtils.EMPTY; break; case NUMERIC: value = _formatter.formatCellValue( cell ); @@ -349,14 +349,14 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { return true; } - final boolean noText = ExcelToHtmlUtils.isEmpty( value ); + final boolean noText = AbstractExcelUtils.isEmpty( value ); final boolean wrapInDivs = !noText && isUseDivsToSpan() && !cellStyle.getWrapText(); if ( cellStyle.getIndex() != 0 ) { @SuppressWarnings("resource") HSSFWorkbook workbook = cell.getRow().getSheet().getWorkbook(); String mainCssClass = getStyleClassName( workbook, cellStyle ); - + if ( wrapInDivs ) { tableCellElement.setAttribute( "class", mainCssClass + " " + cssClassContainerCell ); @@ -419,7 +419,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { tableCellElement.appendChild( text ); } - return ExcelToHtmlUtils.isEmpty( value ) && (cellStyle.getIndex() == 0); + return AbstractExcelUtils.isEmpty( value ) && (cellStyle.getIndex() == 0); } protected void processColumnHeaders( HSSFSheet sheet, int maxSheetColumns, @@ -472,16 +472,16 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { } protected void processDocumentInformation(SummaryInformation summaryInformation ) { - if ( ExcelToHtmlUtils.isNotEmpty( summaryInformation.getTitle() ) ) + if ( AbstractExcelUtils.isNotEmpty( summaryInformation.getTitle() ) ) htmlDocumentFacade.setTitle( summaryInformation.getTitle() ); - if ( ExcelToHtmlUtils.isNotEmpty( summaryInformation.getAuthor() ) ) + if ( AbstractExcelUtils.isNotEmpty( summaryInformation.getAuthor() ) ) htmlDocumentFacade.addAuthor( summaryInformation.getAuthor() ); - if ( ExcelToHtmlUtils.isNotEmpty( summaryInformation.getKeywords() ) ) + if ( AbstractExcelUtils.isNotEmpty( summaryInformation.getKeywords() ) ) htmlDocumentFacade.addKeywords( summaryInformation.getKeywords() ); - if ( ExcelToHtmlUtils.isNotEmpty( summaryInformation.getComments() ) ) + if ( AbstractExcelUtils.isNotEmpty( summaryInformation.getComments() ) ) htmlDocumentFacade .addDescription( summaryInformation.getComments() ); } @@ -512,7 +512,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { if ( !isOutputHiddenColumns() && sheet.isColumnHidden( colIx ) ) continue; - CellRangeAddress range = ExcelToHtmlUtils.getMergedRange( + CellRangeAddress range = AbstractExcelUtils.getMergedRange( mergedRanges, row.getRowNum(), colIx ); if ( range != null diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java index e59b559f9f..ba759fdff4 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java @@ -923,7 +923,7 @@ public abstract class AbstractWordConverter imageWidth *= aspectRatioX / 1000f; } imageWidth /= AbstractWordUtils.TWIPS_PER_INCH; - + float imageHeight = picture.getDyaGoal(); if (aspectRatioY > 0) { imageHeight *= aspectRatioY / 1000f; @@ -934,7 +934,7 @@ public abstract class AbstractWordConverter picture.suggestPictureType(), picture.suggestFullFileName(), imageWidth, imageHeight ); - if ( WordToFoUtils.isNotEmpty( url ) ) + if ( AbstractWordUtils.isNotEmpty( url ) ) { processImage( currentBlock, inlined, picture, url ); return; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java index b1b227c2d3..90da79a9ee 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java @@ -61,7 +61,7 @@ public class AbstractWordUtils * Creates array of all possible cell edges. In HTML (and FO) cells from * different rows and same column should have same width, otherwise spanning * shall be used. - * + * * @param table * table to build cell edges array from * @return array of cell edges (including leftest one) in twips @@ -137,7 +137,7 @@ public class AbstractWordUtils { Node child1 = childNodes.item( i ); Node child2 = childNodes.item( i + 1 ); - if ( !WordToFoUtils.canBeMerged( child1, child2, childTagName ) ) + if ( !AbstractWordUtils.canBeMerged( child1, child2, childTagName ) ) continue; // merge @@ -266,7 +266,7 @@ public class AbstractWordUtils numberingState.levels.remove( childKey ); } } - + bulletBuffer.append( NumberFormatter.getNumber( num, list.getNumberFormat( level ) ) ); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/FoDocumentFacade.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/FoDocumentFacade.java index 12b15e2dc6..b9c449be63 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/FoDocumentFacade.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/FoDocumentFacade.java @@ -309,9 +309,8 @@ public class FoDocumentFacade if ( child.getNodeType() == Node.ELEMENT_NODE ) { Element childElement = (Element) child; - if ( WordToFoUtils.isNotEmpty( childElement.getNamespaceURI() ) - && WordToFoUtils.isNotEmpty( childElement - .getLocalName() ) + if ( AbstractWordUtils.isNotEmpty( childElement.getNamespaceURI() ) + && AbstractWordUtils.isNotEmpty( childElement.getLocalName() ) && namespace.equals( childElement.getNamespaceURI() ) && name.equals( childElement.getLocalName() ) ) { @@ -321,7 +320,7 @@ public class FoDocumentFacade } } - if ( WordToFoUtils.isNotEmpty( value ) ) + if ( AbstractWordUtils.isNotEmpty( value ) ) { Element property = document.createElementNS( namespace, prefix + ":" + name ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java index adf2c75e5d..9d6b631e4c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java @@ -27,6 +27,7 @@ import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.StringUtil; @Internal @@ -54,7 +55,7 @@ public class ComplexFileTable { while (tableStream[offset] == GRPPRL_TYPE) { offset++; int size = LittleEndian.getShort(tableStream, offset); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; byte[] bs = LittleEndian.getByteArray(tableStream, offset, size, MAX_RECORD_LENGTH); offset += size; @@ -68,7 +69,7 @@ public class ComplexFileTable { " but had " + tableStream[offset]); } int pieceTableSize = LittleEndian.getInt(tableStream, ++offset); - offset += LittleEndian.INT_SIZE; + offset += LittleEndianConsts.INT_SIZE; _tpt = newTextPieceTable(documentStream, tableStream, offset, pieceTableSize, fcMin, charset); } @@ -99,7 +100,7 @@ public class ComplexFileTable { byte[] table = _tpt.writeTo(wordDocumentStream); - byte[] numHolder = new byte[LittleEndian.INT_SIZE]; + byte[] numHolder = new byte[LittleEndianConsts.INT_SIZE]; LittleEndian.putInt(numHolder, 0, table.length); tableStream.write(numHolder); tableStream.write(table); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java index 325fd5b974..81c99985dd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java @@ -18,6 +18,7 @@ package org.apache.poi.hwpf.model; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * The FFData structure specifies form field data for a text box, check box, or @@ -29,7 +30,7 @@ import org.apache.poi.util.LittleEndian; *

* This class is internal. It content or properties may change without notice * due to changes in our knowledge of internal Microsoft Word binary structures. - * + * * @author Sergey Vladimirov; according to [MS-DOC] -- v20121003 Word (.doc) * Binary File Format; Copyright (c) 2012 Microsoft Corporation; * Release: October 8, 2012 @@ -114,7 +115,7 @@ public class FFData { this._wDef = Integer .valueOf( LittleEndian.getUShort( std, offset ) ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; } else { @@ -170,7 +171,7 @@ public class FFData if ( _base.getIType() == FFDataBase.ITYPE_CHCK || _base.getIType() == FFDataBase.ITYPE_DROP ) { - size += LittleEndian.SHORT_SIZE; + size += LittleEndianConsts.SHORT_SIZE; } size += _xstzTextFormat.getSize(); @@ -211,7 +212,7 @@ public class FFData || _base.getIType() == FFDataBase.ITYPE_DROP ) { LittleEndian.putUShort( buffer, offset, _wDef ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; } offset += _xstzTextFormat.serialize( buffer, offset ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java index ab477332cc..3d162f3391 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -146,7 +147,7 @@ public final class FIBFieldHandler private final static POILogger log = POILogFactory.getLogger(FIBFieldHandler.class); - private static final int FIELD_SIZE = LittleEndian.INT_SIZE * 2; + private static final int FIELD_SIZE = LittleEndianConsts.INT_SIZE * 2; private Map _unknownMap = new HashMap<>(); private int[] _fields; @@ -161,7 +162,7 @@ public final class FIBFieldHandler { int fieldOffset = (x * FIELD_SIZE) + offset; int dsOffset = LittleEndian.getInt(mainStream, fieldOffset); - fieldOffset += LittleEndian.INT_SIZE; + fieldOffset += LittleEndianConsts.INT_SIZE; int dsSize = LittleEndian.getInt(mainStream, fieldOffset); if (offsetList.contains(Integer.valueOf(x)) ^ areKnown) @@ -216,13 +217,13 @@ public final class FIBFieldHandler public int sizeInBytes() { - return (_fields.length * LittleEndian.INT_SIZE); + return (_fields.length * LittleEndianConsts.INT_SIZE); } public int getFieldsCount() { return _fields.length / 2; } - + void writeTo(byte[] mainStream, int offset, ByteArrayOutputStream tableStream) throws IOException { @@ -233,21 +234,21 @@ public final class FIBFieldHandler { _fields[x * 2] = tableStream.size(); LittleEndian.putInt(mainStream, offset, tableStream.size()); - offset += LittleEndian.INT_SIZE; + offset += LittleEndianConsts.INT_SIZE; byte[] buf = ds.getBuf(); tableStream.write(buf); _fields[(x * 2) + 1] = buf.length; LittleEndian.putInt(mainStream, offset, buf.length); - offset += LittleEndian.INT_SIZE; + offset += LittleEndianConsts.INT_SIZE; } else { LittleEndian.putInt(mainStream, offset, _fields[x * 2]); - offset += LittleEndian.INT_SIZE; + offset += LittleEndianConsts.INT_SIZE; LittleEndian.putInt(mainStream, offset, _fields[(x * 2) + 1]); - offset += LittleEndian.INT_SIZE; + offset += LittleEndianConsts.INT_SIZE; } } } @@ -283,9 +284,9 @@ public final class FIBFieldHandler { result.append( '\t' ); result.append( leftPad( Integer.toString( x ), 8, ' ' ) ); - result.append( leftPad( Integer.toString( 154 + x * LittleEndian.INT_SIZE * 2 ), 6, ' ' ) ); + result.append( leftPad( Integer.toString( 154 + x * LittleEndianConsts.INT_SIZE * 2 ), 6, ' ' ) ); result.append( " 0x" ); - result.append( leftPad( Integer.toHexString( 154 + x * LittleEndian.INT_SIZE * 2 ), 4, '0' ) ); + result.append( leftPad( Integer.toHexString( 154 + x * LittleEndianConsts.INT_SIZE * 2 ), 4, '0' ) ); result.append( leftPad( Integer.toString( getFieldOffset( x ) ), 8, ' ' ) ); result.append( leftPad( Integer.toString( getFieldSize( x ) ), 8, ' ' ) ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java index 87182333cc..532318d739 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java @@ -24,6 +24,7 @@ import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * FFN - Font Family Name. FFN is a data structure that stores the names of the Main @@ -63,15 +64,15 @@ public final class Ffn int offsetTmp = offset; _cbFfnM1 = LittleEndian.getUByte(buf,offset); - offset += LittleEndian.BYTE_SIZE; + offset += LittleEndianConsts.BYTE_SIZE; _info = buf[offset]; - offset += LittleEndian.BYTE_SIZE; + offset += LittleEndianConsts.BYTE_SIZE; _wWeight = LittleEndian.getShort(buf, offset); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; _chs = buf[offset]; - offset += LittleEndian.BYTE_SIZE; + offset += LittleEndianConsts.BYTE_SIZE; _ixchSzAlt = buf[offset]; - offset += LittleEndian.BYTE_SIZE; + offset += LittleEndianConsts.BYTE_SIZE; // read panose and fs so we can write them back out. System.arraycopy(buf, offset, _panose, 0, _panose.length); @@ -86,7 +87,7 @@ public final class Ffn for(int i = 0; i < _xszFfnLength; i++) { _xszFfn[i] = (char)LittleEndian.getShort(buf, offset); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; } @@ -161,15 +162,15 @@ public final class Ffn byte[] buf = IOUtils.safelyAllocate(this.getSize(), MAX_RECORD_LENGTH); buf[offset] = (byte)_cbFfnM1; - offset += LittleEndian.BYTE_SIZE; + offset += LittleEndianConsts.BYTE_SIZE; buf[offset] = _info; - offset += LittleEndian.BYTE_SIZE; + offset += LittleEndianConsts.BYTE_SIZE; LittleEndian.putShort(buf, offset, _wWeight); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; buf[offset] = _chs; - offset += LittleEndian.BYTE_SIZE; + offset += LittleEndianConsts.BYTE_SIZE; buf[offset] = _ixchSzAlt; - offset += LittleEndian.BYTE_SIZE; + offset += LittleEndianConsts.BYTE_SIZE; System.arraycopy(_panose,0,buf, offset,_panose.length); offset += _panose.length; @@ -179,7 +180,7 @@ public final class Ffn for(int i = 0; i < _xszFfn.length; i++) { LittleEndian.putShort(buf, offset, (short)_xszFfn[i]); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; } return buf; @@ -190,7 +191,7 @@ public final class Ffn public boolean equals(Object other) { if (!(other instanceof Ffn)) return false; Ffn o = (Ffn)other; - + return ( o._cbFfnM1 == this._cbFfnM1 && o._info == this._info diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java index a8503e70ca..d1a9389dcd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java @@ -27,6 +27,7 @@ import java.util.Locale; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -72,7 +73,7 @@ public final class FileInformationBlock assert offset == 32; _csw = LittleEndian.getUShort( mainDocument, offset ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; assert offset == 34; _fibRgW = new FibRgW97( mainDocument, offset ); @@ -80,7 +81,7 @@ public final class FileInformationBlock assert offset == 62; _cslw = LittleEndian.getUShort( mainDocument, offset ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; assert offset == 64; if ( _fibBase.getNFib() < 105 ) @@ -92,10 +93,10 @@ public final class FileInformationBlock _cbRgFcLcb = 74; // skip fibRgFcLcbBlob (read later at fillVariableFields) - offset += _cbRgFcLcb * LittleEndian.INT_SIZE * 2; + offset += _cbRgFcLcb * LittleEndianConsts.INT_SIZE * 2; _cswNew = LittleEndian.getUShort( mainDocument, offset ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; _cswNew = 0; _nFibNew = -1; @@ -109,23 +110,23 @@ public final class FileInformationBlock assert offset == 152; _cbRgFcLcb = LittleEndian.getUShort( mainDocument, offset ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; assert offset == 154; // skip fibRgFcLcbBlob (read later at fillVariableFields) - offset += _cbRgFcLcb * LittleEndian.INT_SIZE * 2; + offset += _cbRgFcLcb * LittleEndianConsts.INT_SIZE * 2; _cswNew = LittleEndian.getUShort( mainDocument, offset ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; if ( _cswNew != 0 ) { _nFibNew = LittleEndian.getUShort( mainDocument, offset ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; // first short is already read as _nFibNew final int fibRgCswNewLength = ( _cswNew - 1 ) - * LittleEndian.SHORT_SIZE; + * LittleEndianConsts.SHORT_SIZE; _fibRgCswNew = IOUtils.safelyAllocate(fibRgCswNewLength, MAX_RECORD_LENGTH); LittleEndian.getByteArray( mainDocument, offset, fibRgCswNewLength, MAX_RECORD_LENGTH ); offset += fibRgCswNewLength; @@ -144,7 +145,7 @@ public final class FileInformationBlock { int nfib = getNFib(); String nfibHex = String.format(Locale.ROOT, "%04X", nfib); - + // Note - CommonCrawl shows there's more variation in these than // the documentation suggests, so accept common clusters around // the "correct" value as well @@ -665,7 +666,7 @@ public final class FileInformationBlock { _fieldHandler.setFieldSize(FIBFieldHandler.STTBFFFN, lcbSttbFffn); } - + public int getFcSttbfRMark() { return _fieldHandler.getFieldOffset(FIBFieldHandler.STTBFRMARK); @@ -675,7 +676,7 @@ public final class FileInformationBlock { return _fieldHandler.getFieldSize(FIBFieldHandler.STTBFRMARK); } - + public void setFcSttbfRMark(int fcSttbfRMark) { _fieldHandler.setFieldOffset(FIBFieldHandler.STTBFRMARK, fcSttbfRMark); @@ -746,7 +747,7 @@ public final class FileInformationBlock { _fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, modifiedHigh); } - + /** * How many bytes of the main stream contain real data. */ @@ -1081,29 +1082,29 @@ public final class FileInformationBlock int offset = FibBase.getSize(); LittleEndian.putUShort( mainStream, offset, _csw ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; _fibRgW.serialize( mainStream, offset ); offset += FibRgW97.getSize(); LittleEndian.putUShort( mainStream, offset, _cslw ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; ( (FibRgLw97) _fibRgLw ).serialize( mainStream, offset ); offset += FibRgLw97.getSize(); LittleEndian.putUShort( mainStream, offset, _cbRgFcLcb ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; _fieldHandler.writeTo( mainStream, offset, tableStream ); - offset += _cbRgFcLcb * LittleEndian.INT_SIZE * 2; + offset += _cbRgFcLcb * LittleEndianConsts.INT_SIZE * 2; LittleEndian.putUShort( mainStream, offset, _cswNew ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; if ( _cswNew != 0 ) { LittleEndian.putUShort( mainStream, offset, _nFibNew ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; System.arraycopy( _fibRgCswNew, 0, mainStream, offset, _fibRgCswNew.length ); @@ -1113,9 +1114,9 @@ public final class FileInformationBlock public int getSize() { - return FibBase.getSize() + LittleEndian.SHORT_SIZE + FibRgW97.getSize() - + LittleEndian.SHORT_SIZE + FibRgLw97.getSize() - + LittleEndian.SHORT_SIZE + _fieldHandler.sizeInBytes(); + return FibBase.getSize() + LittleEndianConsts.SHORT_SIZE + FibRgW97.getSize() + + LittleEndianConsts.SHORT_SIZE + FibRgLw97.getSize() + + LittleEndianConsts.SHORT_SIZE + _fieldHandler.sizeInBytes(); } public FibBase getFibBase() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java index 32105686e9..767520c96b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java @@ -23,6 +23,7 @@ import java.io.IOException; import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -55,9 +56,9 @@ public final class FontTable this.fcSttbfffn = offset; _stringCount = LittleEndian.getShort(buf, offset); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; _extraDataSz = LittleEndian.getShort(buf, offset); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; _fontNames = new Ffn[_stringCount]; //Ffn corresponds to a Pascal style String in STTBF. @@ -124,7 +125,7 @@ public final class FontTable public void writeTo( ByteArrayOutputStream tableStream ) throws IOException { - byte[] buf = new byte[LittleEndian.SHORT_SIZE]; + byte[] buf = new byte[LittleEndianConsts.SHORT_SIZE]; LittleEndian.putShort(buf, 0, _stringCount); tableStream.write(buf); LittleEndian.putShort(buf, 0, _extraDataSz); @@ -146,11 +147,11 @@ public final class FontTable || o._extraDataSz != this._extraDataSz || o._fontNames.length != this._fontNames.length ) return false; - + for (int i=0; i Integer.MAX_VALUE ) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java index b5551d07ba..36832e6c45 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java @@ -20,6 +20,7 @@ package org.apache.poi.hwpf.model; import org.apache.poi.common.Duplicatable; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * Section Descriptor (SED) @@ -64,11 +65,11 @@ public final class SectionDescriptor implements Duplicatable { public SectionDescriptor(byte[] buf, int offset) { fn = LittleEndian.getShort(buf, offset); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; fcSepx = LittleEndian.getInt(buf, offset); - offset += LittleEndian.INT_SIZE; + offset += LittleEndianConsts.INT_SIZE; fnMpr = LittleEndian.getShort(buf, offset); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; fcMpr = LittleEndian.getInt(buf, offset); } @@ -102,11 +103,11 @@ public final class SectionDescriptor implements Duplicatable { byte[] buf = new byte[12]; LittleEndian.putShort(buf, offset, fn); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; LittleEndian.putInt(buf, offset, fcSepx); - offset += LittleEndian.INT_SIZE; + offset += LittleEndianConsts.INT_SIZE; LittleEndian.putShort(buf, offset, fnMpr); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; LittleEndian.putInt(buf, offset, fcMpr); return buf; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java index 23df32a6dc..5e7186b920 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java @@ -26,6 +26,7 @@ import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -81,7 +82,7 @@ public class SectionTable // The first short at the offset is the size of the grpprl. int sepxSize = LittleEndian.getShort(documentStream, fileOffset); byte[] buf = IOUtils.safelyAllocate(sepxSize, MAX_RECORD_LENGTH); - fileOffset += LittleEndian.SHORT_SIZE; + fileOffset += LittleEndianConsts.SHORT_SIZE; System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); _sections.add(new SEPX(sed, startAt, endAt, buf)); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java index f36519c9f3..92378e8fed 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java @@ -19,6 +19,7 @@ package org.apache.poi.hwpf.model; import java.util.Arrays; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; @@ -34,7 +35,7 @@ import org.apache.poi.util.StringUtil; *

* This class is internal. It content or properties may change without notice * due to changes in our knowledge of internal Microsoft Word binary structures. - * + * * @author Sergey Vladimirov; according to [MS-DOC] -- v20121003 Word (.doc) * Binary File Format; Copyright (c) 2012 Microsoft Corporation; * Release: October 8, 2012 @@ -76,7 +77,7 @@ public class Sttb public void fillFields( byte[] buffer, int startOffset ) { short ffff = LittleEndian.getShort( buffer, startOffset ); - int offset = startOffset + LittleEndian.SHORT_SIZE; + int offset = startOffset + LittleEndianConsts.SHORT_SIZE; if ( ffff != (short) 0xffff ) { @@ -137,20 +138,20 @@ public class Sttb public int getSize() { // ffff - int size = LittleEndian.SHORT_SIZE; + int size = LittleEndianConsts.SHORT_SIZE; // cData size += _cDataLength; // cbExtra - size += LittleEndian.SHORT_SIZE; + size += LittleEndianConsts.SHORT_SIZE; if ( this._fExtend ) { for ( String data : _data ) { // cchData - size += LittleEndian.SHORT_SIZE; + size += LittleEndianConsts.SHORT_SIZE; // data size += 2 * data.length(); } @@ -160,9 +161,9 @@ public class Sttb for ( String data : _data ) { // cchData - size += LittleEndian.BYTE_SIZE; + size += LittleEndianConsts.BYTE_SIZE; // data - size += 1 * data.length(); + size += data.length(); } } @@ -200,13 +201,13 @@ public class Sttb { LittleEndian.putInt( buffer, 2, _data.length ); LittleEndian.putUShort( buffer, 6, _cbExtra ); - offset = 2 + LittleEndian.INT_SIZE + LittleEndian.SHORT_SIZE; + offset = 2 + LittleEndianConsts.INT_SIZE + LittleEndianConsts.SHORT_SIZE; } else { LittleEndian.putUShort( buffer, 2, _data.length ); LittleEndian.putUShort( buffer, 4, _cbExtra ); - offset = 2 + LittleEndian.SHORT_SIZE + LittleEndian.SHORT_SIZE; + offset = 2 + LittleEndianConsts.SHORT_SIZE + LittleEndianConsts.SHORT_SIZE; } for ( int i = 0; i < _data.length; i++ ) @@ -224,7 +225,7 @@ public class Sttb if ( _fExtend ) { LittleEndian.putUShort( buffer, offset, entry.length() ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; StringUtil.putUnicodeLE( entry, buffer, offset ); offset += 2 * entry.length(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java index a1f9d9623d..c45a6b1798 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java @@ -24,6 +24,7 @@ import org.apache.poi.hwpf.usermodel.ParagraphProperties; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; @@ -91,7 +92,7 @@ public final class StyleDescription { if (word9) { nameLength = LittleEndian.getShort(std, nameStart); multiplier = 2; - nameStart += LittleEndian.SHORT_SIZE; + nameStart += LittleEndianConsts.SHORT_SIZE; } else { nameLength = std[nameStart]; } @@ -107,7 +108,7 @@ public final class StyleDescription { _upxs = new UPX[countOfUPX]; for (int x = 0; x < countOfUPX; x++) { int upxSize = LittleEndian.getShort(std, varOffset); - varOffset += LittleEndian.SHORT_SIZE; + varOffset += LittleEndianConsts.SHORT_SIZE; byte[] upx = IOUtils.safelyAllocate(upxSize, Short.MAX_VALUE); System.arraycopy(std, varOffset, upx, 0, upxSize); @@ -199,18 +200,18 @@ public final class StyleDescription { char[] letters = _name.toCharArray(); LittleEndian.putShort(buf, _baseLength, (short) letters.length); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; for (int x = 0; x < letters.length; x++) { LittleEndian.putShort(buf, offset, (short) letters[x]); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; } // get past the null delimiter for the name. - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; for (int x = 0; x < _upxs.length; x++) { short upxSize = (short) _upxs[x].size(); LittleEndian.putShort(buf, offset, upxSize); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; System.arraycopy(_upxs[x].getUPX(), 0, buf, offset, upxSize); offset += upxSize + (upxSize % 2); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java index 8811bfb1f0..3a53a8b662 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java @@ -26,6 +26,7 @@ import org.apache.poi.hwpf.usermodel.CharacterProperties; import org.apache.poi.hwpf.usermodel.ParagraphProperties; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * Represents a document's stylesheet. A word documents formatting is stored as @@ -77,11 +78,11 @@ public final class StyleSheet { public StyleSheet(byte[] tableStream, int offset) { int startOffset = offset; _cbStshi = LittleEndian.getShort(tableStream, offset); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; /* * Count of styles in stylesheet - * + * * The number of styles in this style sheet. There will be stshi.cstd * (cbSTD, STD) pairs in the file following the STSHI. Note: styles can * be empty, i.e. cbSTD==0. @@ -92,7 +93,7 @@ public final class StyleSheet { // shall we discard cbLSD and mpstilsd? - offset = startOffset + LittleEndian.SHORT_SIZE + _cbStshi; + offset = startOffset + LittleEndianConsts.SHORT_SIZE + _cbStshi; _styleDescriptions = new StyleDescription[_stshif.getCstd()]; for (int x = 0; x < _stshif.getCstd(); x++) { int stdSize = LittleEndian.getShort(tableStream, offset); @@ -134,7 +135,7 @@ public final class StyleSheet { byte[] buf = new byte[_cbStshi + 2]; LittleEndian.putUShort(buf, offset, (short) _cbStshi); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; _stshif.setCstd(_styleDescriptions.length); _stshif.serialize(buf, offset); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Xst.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Xst.java index 3aef1dd90e..769786afb8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/Xst.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Xst.java @@ -21,6 +21,7 @@ package org.apache.poi.hwpf.model; import java.util.Arrays; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * The Xst structure is a string. The string is prepended by its length and is @@ -56,13 +57,13 @@ public class Xst int offset = startOffset; _cch = LittleEndian.getUShort( data, offset ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; _rgtchar = new char[_cch]; for ( int x = 0; x < _cch; x++ ) { _rgtchar[x] = (char) LittleEndian.getShort( data, offset ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; } } @@ -114,7 +115,7 @@ public class Xst public int getSize() { - return LittleEndian.SHORT_SIZE + _rgtchar.length * 2; + return LittleEndianConsts.SHORT_SIZE + _rgtchar.length * 2; } @Override @@ -127,12 +128,12 @@ public class Xst int offset = startOffset; LittleEndian.putUShort( data, offset, _cch ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; for ( char c : _rgtchar ) { LittleEndian.putShort( data, offset, (short) c ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java index f7aeb10dd1..242fb6755c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java @@ -18,6 +18,7 @@ package org.apache.poi.hwpf.model; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -63,7 +64,7 @@ public class Xstz public int getSize() { - return _xst.getSize() + LittleEndian.SHORT_SIZE; + return _xst.getSize() + LittleEndianConsts.SHORT_SIZE; } public int serialize( byte[] data, int startOffset ) @@ -74,7 +75,7 @@ public class Xstz offset += _xst.getSize(); LittleEndian.putUShort( data, offset, _chTerm ); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; return offset - startOffset; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java index 3fec02b9b5..64b83b7f8f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java @@ -33,6 +33,7 @@ import org.apache.poi.hwpf.usermodel.ShadingDescriptor; import org.apache.poi.hwpf.usermodel.ShadingDescriptor80; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -435,7 +436,7 @@ public final class ParagraphSprmUncompressor for (int x = 0; x < delSize; x++) { tabMap.remove(Integer.valueOf(LittleEndian.getShort(grpprl, offset))); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; } int addSize = grpprl[offset++]; @@ -445,7 +446,7 @@ public final class ParagraphSprmUncompressor Integer key = Integer.valueOf(LittleEndian.getShort(grpprl, offset)); TabDescriptor val = new TabDescriptor( grpprl, start + ((TabDescriptor.getSize() * addSize) + x) ); tabMap.put(key, val); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; } tabPositions = new int[tabMap.size()]; @@ -467,56 +468,4 @@ public final class ParagraphSprmUncompressor pap.setRgdxaTab(tabPositions); pap.setRgtbd(tabDescriptors); } - -// private static void handleTabsAgain(ParagraphProperties pap, SprmOperation sprm) -// { -// byte[] grpprl = sprm.getGrpprl(); -// int offset = sprm.getGrpprlOffset(); -// int delSize = grpprl[offset++]; -// int[] tabPositions = pap.getRgdxaTab(); -// byte[] tabDescriptors = pap.getRgtbd(); -// -// HashMap tabMap = new HashMap(); -// for (int x = 0; x < tabPositions.length; x++) -// { -// tabMap.put(Integer.valueOf(tabPositions[x]), Byte.valueOf(tabDescriptors[x])); -// } -// -// for (int x = 0; x < delSize; x++) -// { -// tabMap.remove(Integer.valueOf(LittleEndian.getInt(grpprl, offset))); -// offset += LittleEndian.INT_SIZE;; -// } -// -// int addSize = grpprl[offset++]; -// for (int x = 0; x < addSize; x++) -// { -// Integer key = Integer.valueOf(LittleEndian.getInt(grpprl, offset)); -// Byte val = Byte.valueOf(grpprl[(LittleEndian.INT_SIZE * (addSize - x)) + x]); -// tabMap.put(key, val); -// offset += LittleEndian.INT_SIZE; -// } -// -// tabPositions = new int[tabMap.size()]; -// tabDescriptors = new byte[tabPositions.length]; -// ArrayList list = new ArrayList(); -// -// Iterator keyIT = tabMap.keySet().iterator(); -// while (keyIT.hasNext()) -// { -// list.add(keyIT.next()); -// } -// Collections.sort(list); -// -// for (int x = 0; x < tabPositions.length; x++) -// { -// Integer key = ((Integer)list.get(x)); -// tabPositions[x] = key.intValue(); -// tabDescriptors[x] = ((Byte)tabMap.get(key)).byteValue(); -// } -// -// pap.setRgdxaTab(tabPositions); -// pap.setRgtbd(tabDescriptors); -// } - } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java index 14798c3590..98c8886f94 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java @@ -24,6 +24,7 @@ import java.util.List; import org.apache.poi.hwpf.usermodel.SectionProperties; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; @Internal public final class SectionSprmCompressor @@ -187,9 +188,9 @@ public final class SectionSprmCompressor { byte[] buf = new byte[7]; buf[0] = (byte)(newSEP.getFPropMark() ? 1 : 0); - int offset = LittleEndian.BYTE_SIZE; + int offset = LittleEndianConsts.BYTE_SIZE; LittleEndian.putShort(buf, 0, (short)newSEP.getIbstPropRMark()); - offset += LittleEndian.SHORT_SIZE; + offset += LittleEndianConsts.SHORT_SIZE; newSEP.getDttmPropRMark().serialize(buf, offset); size += SprmUtils.addSprm((short)0xD227, -1, buf, sprmList); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java index be028da98e..1bcee335e8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java @@ -23,6 +23,7 @@ import org.apache.poi.common.Duplicatable; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.Removal; @Internal @@ -62,38 +63,38 @@ public final class SprmBuffer implements Duplicatable { } public void addSprm(short opcode, byte operand) { - int addition = LittleEndian.SHORT_SIZE + LittleEndian.BYTE_SIZE; + int addition = LittleEndianConsts.SHORT_SIZE + LittleEndianConsts.BYTE_SIZE; ensureCapacity(addition); LittleEndian.putShort(_buf, _offset, opcode); - _offset += LittleEndian.SHORT_SIZE; + _offset += LittleEndianConsts.SHORT_SIZE; _buf[_offset++] = operand; } public void addSprm(short opcode, byte[] operand) { - int addition = LittleEndian.SHORT_SIZE + LittleEndian.BYTE_SIZE + operand.length; + int addition = LittleEndianConsts.SHORT_SIZE + LittleEndianConsts.BYTE_SIZE + operand.length; ensureCapacity(addition); LittleEndian.putShort(_buf, _offset, opcode); - _offset += LittleEndian.SHORT_SIZE; + _offset += LittleEndianConsts.SHORT_SIZE; _buf[_offset++] = (byte) operand.length; System.arraycopy(operand, 0, _buf, _offset, operand.length); } public void addSprm(short opcode, int operand) { - int addition = LittleEndian.SHORT_SIZE + LittleEndian.INT_SIZE; + int addition = LittleEndianConsts.SHORT_SIZE + LittleEndianConsts.INT_SIZE; ensureCapacity(addition); LittleEndian.putShort(_buf, _offset, opcode); - _offset += LittleEndian.SHORT_SIZE; + _offset += LittleEndianConsts.SHORT_SIZE; LittleEndian.putInt(_buf, _offset, operand); - _offset += LittleEndian.INT_SIZE; + _offset += LittleEndianConsts.INT_SIZE; } public void addSprm(short opcode, short operand) { - int addition = LittleEndian.SHORT_SIZE + LittleEndian.SHORT_SIZE; + int addition = LittleEndianConsts.SHORT_SIZE + LittleEndianConsts.SHORT_SIZE; ensureCapacity(addition); LittleEndian.putShort(_buf, _offset, opcode); - _offset += LittleEndian.SHORT_SIZE; + _offset += LittleEndianConsts.SHORT_SIZE; LittleEndian.putShort(_buf, _offset, operand); - _offset += LittleEndian.SHORT_SIZE; + _offset += LittleEndianConsts.SHORT_SIZE; } public void append(byte[] grpprl) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java index 990e1b22b8..287063c22d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java @@ -21,6 +21,7 @@ import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * This class is used to represent a sprm operation from a Word 97/2000/XP @@ -88,7 +89,7 @@ public final class SprmOperation { return _gOffset; } - + public int getOperand() { switch ( getSizeCode() ) @@ -107,7 +108,7 @@ public final class SprmOperation byte operandLength = _grpprl[_gOffset + 1]; // initialized to zeros by JVM - byte[] codeBytes = new byte[LittleEndian.INT_SIZE]; + byte[] codeBytes = new byte[LittleEndianConsts.INT_SIZE]; for ( int i = 0; i < operandLength; i++ ) if ( _gOffset + i < _grpprl.length ) codeBytes[i] = _grpprl[_gOffset + 1 + i]; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java index e47f956512..e6facf2e86 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; @Internal @@ -37,11 +38,11 @@ public final class SprmUtils public static byte[] shortArrayToByteArray(short[] convert) { - byte[] buf = IOUtils.safelyAllocate(convert.length * (long)LittleEndian.SHORT_SIZE, MAX_RECORD_LENGTH); + byte[] buf = IOUtils.safelyAllocate(convert.length * (long)LittleEndianConsts.SHORT_SIZE, MAX_RECORD_LENGTH); for (int x = 0; x < convert.length; x++) { - LittleEndian.putShort(buf, x * LittleEndian.SHORT_SIZE, convert[x]); + LittleEndian.putShort(buf, x * LittleEndianConsts.SHORT_SIZE, convert[x]); } return buf; @@ -130,7 +131,7 @@ public final class SprmUtils { byte[] buf = new byte[4]; LittleEndian.putShort(buf, 0, brc[0]); - LittleEndian.putShort(buf, LittleEndian.SHORT_SIZE, brc[1]); + LittleEndian.putShort(buf, LittleEndianConsts.SHORT_SIZE, brc[1]); return LittleEndian.getInt(buf); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmCompressor.java index cbef3587ce..9c76e2ec13 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmCompressor.java @@ -28,6 +28,7 @@ import org.apache.poi.hwpf.usermodel.TableProperties; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; @Internal public final class TableSprmCompressor @@ -82,7 +83,7 @@ public final class TableSprmCompressor int itcMac = newTAP.getItcMac(); byte[] buf = IOUtils.safelyAllocate( 1 - + (LittleEndian.SHORT_SIZE*((long)itcMac + 1)) + + (LittleEndianConsts.SHORT_SIZE*((long)itcMac + 1)) + (TableCellDescriptor.SIZE*(long)itcMac), MAX_RECORD_LENGTH); buf[0] = (byte)itcMac; @@ -90,7 +91,7 @@ public final class TableSprmCompressor short[] dxaCenters = newTAP.getRgdxaCenter(); for (int x = 0; x < dxaCenters.length; x++) { - LittleEndian.putShort(buf, 1 + (x * LittleEndian.SHORT_SIZE), + LittleEndian.putShort(buf, 1 + (x * LittleEndianConsts.SHORT_SIZE), dxaCenters[x]); } @@ -98,7 +99,7 @@ public final class TableSprmCompressor for (int x = 0; x < cellDescriptors.length; x++) { cellDescriptors[x].serialize(buf, - 1+((itcMac+1)*LittleEndian.SHORT_SIZE)+(x*TableCellDescriptor.SIZE)); + 1+((itcMac+1)* LittleEndianConsts.SHORT_SIZE)+(x*TableCellDescriptor.SIZE)); } size += SprmUtils.addSpecialSprm((short)0xD608, buf, sprmList); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java index 4895196f42..cb7ffc95ac 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java @@ -21,6 +21,7 @@ import org.apache.poi.common.Duplicatable; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.Removal; /** @@ -52,13 +53,13 @@ public final class BorderCode implements Duplicatable { public BorderCode(byte[] buf, int offset) { _info = LittleEndian.getShort(buf, offset); - _info2 = LittleEndian.getShort(buf, offset + LittleEndian.SHORT_SIZE); + _info2 = LittleEndian.getShort(buf, offset + LittleEndianConsts.SHORT_SIZE); } public void serialize(byte[] buf, int offset) { LittleEndian.putShort(buf, offset, _info); - LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _info2); + LittleEndian.putShort(buf, offset + LittleEndianConsts.SHORT_SIZE, _info2); } public int toInt() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java index 871ffa3cd2..be677fba87 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java @@ -23,6 +23,7 @@ import org.apache.poi.common.Duplicatable; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.Removal; @@ -50,7 +51,7 @@ public final class DateAndTime implements Duplicatable { public DateAndTime(byte[] buf, int offset) { _info = LittleEndian.getShort(buf, offset); - _info2 = LittleEndian.getShort(buf, offset + LittleEndian.SHORT_SIZE); + _info2 = LittleEndian.getShort(buf, offset + LittleEndianConsts.SHORT_SIZE); } public Calendar getDate() { @@ -68,7 +69,7 @@ public final class DateAndTime implements Duplicatable { public void serialize(byte[] buf, int offset) { LittleEndian.putShort(buf, offset, _info); - LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _info2); + LittleEndian.putShort(buf, offset + LittleEndianConsts.SHORT_SIZE, _info2); } @Override diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java index 09a8590658..181dc6f75d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java @@ -19,6 +19,7 @@ package org.apache.poi.hwpf.usermodel; import org.apache.poi.common.Duplicatable; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.Removal; /** @@ -41,7 +42,7 @@ public final class LineSpacingDescriptor implements Duplicatable { public LineSpacingDescriptor(byte[] buf, int offset) { _dyaLine = LittleEndian.getShort(buf, offset); - _fMultiLinespace = LittleEndian.getShort(buf, offset + LittleEndian.SHORT_SIZE); + _fMultiLinespace = LittleEndian.getShort(buf, offset + LittleEndianConsts.SHORT_SIZE); } @Override @@ -72,7 +73,7 @@ public final class LineSpacingDescriptor implements Duplicatable { public void serialize(byte[] buf, int offset) { LittleEndian.putShort(buf, offset, _dyaLine); - LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _fMultiLinespace); + LittleEndian.putShort(buf, offset + LittleEndianConsts.SHORT_SIZE, _fMultiLinespace); } public void setDyaLine(short dyaLine) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java index d2e0c2fc7f..8304161c24 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -36,6 +36,7 @@ import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.util.DocumentFormatException; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -471,9 +472,9 @@ public class Range { CharacterProperties baseChp = ss.getCharacterStyle(styleIndex); byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle); - byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE]; + byte[] withIndex = new byte[grpprl.length + LittleEndianConsts.SHORT_SIZE]; LittleEndian.putShort(withIndex, 0, (short) styleIndex); - System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length); + System.arraycopy(grpprl, 0, withIndex, LittleEndianConsts.SHORT_SIZE, grpprl.length); SprmBuffer buf = new SprmBuffer(withIndex, 2); _doc.getParagraphTable().insert(_parStart, _start, buf); @@ -522,9 +523,9 @@ public class Range { CharacterProperties baseChp = ss.getCharacterStyle(styleIndex); byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle); - byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE]; + byte[] withIndex = new byte[grpprl.length + LittleEndianConsts.SHORT_SIZE]; LittleEndian.putShort(withIndex, 0, (short) styleIndex); - System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length); + System.arraycopy(grpprl, 0, withIndex, LittleEndianConsts.SHORT_SIZE, grpprl.length); SprmBuffer buf = new SprmBuffer(withIndex, 2); _doc.getParagraphTable().insert(_parEnd, _end, buf);