Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DBCellRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DBCellRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DBCellRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DBCellRecord.java Sun Apr 12 22:03:52 2020 @@ -17,7 +17,10 @@ package org.apache.poi.hssf.record; -import org.apache.poi.util.HexDump; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -50,19 +53,6 @@ public final class DBCellRecord extends } } - public String toString() { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[DBCELL]\n"); - buffer.append(" .rowoffset = ").append(HexDump.intToHex(field_1_row_offset)).append("\n"); - for (int k = 0; k < field_2_cell_offsets.length; k++) { - buffer.append(" .cell_").append(k).append(" = ") - .append(HexDump.shortToHex(field_2_cell_offsets[ k ])).append("\n"); - } - buffer.append("[/DBCELL]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeInt(field_1_row_offset); for (short field_2_cell_offset : field_2_cell_offsets) { @@ -78,7 +68,7 @@ public final class DBCellRecord extends } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public DBCellRecord clone() { @@ -90,4 +80,17 @@ public final class DBCellRecord extends // safe because immutable return this; } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DB_CELL; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "rowOffset", () -> field_1_row_offset, + "cellOffsets", () -> field_2_cell_offsets + ); + } }
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DConRefRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DConRefRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DConRefRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DConRefRecord.java Sun Apr 12 22:03:52 2020 @@ -20,7 +20,10 @@ package org.apache.poi.hssf.record; import java.io.ByteArrayInputStream; import java.util.Arrays; +import java.util.Map; +import java.util.function.Supplier; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.RecordFormatException; @@ -228,25 +231,6 @@ public class DConRefRecord extends Stand return lastRow; } - @Override - public String toString() - { - StringBuilder b = new StringBuilder(); - b.append("[DCONREF]\n"); - b.append(" .ref\n"); - b.append(" .firstrow = ").append(firstRow).append("\n"); - b.append(" .lastrow = ").append(lastRow).append("\n"); - b.append(" .firstcol = ").append(firstCol).append("\n"); - b.append(" .lastcol = ").append(lastCol).append("\n"); - b.append(" .cch = ").append(charCount).append("\n"); - b.append(" .stFile\n"); - b.append(" .h = ").append(charType).append("\n"); - b.append(" .rgb = ").append(getReadablePath()).append("\n"); - b.append("[/DCONREF]\n"); - - return b.toString(); - } - /** * * @return raw path byte array. @@ -298,4 +282,22 @@ public class DConRefRecord extends Stand ric.nextRecord(); return ric; } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DCON_REF; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "firstRow", this::getFirstRow, + "lastRow", this::getLastRow, + "firstColumn", this::getFirstColumn, + "lastColumn", this::getLastColumn, + "charCount", () -> charCount, + "charType", () -> charType, + "path", this::getReadablePath + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DSFRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DSFRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DSFRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DSFRecord.java Sun Apr 12 22:03:52 2020 @@ -17,9 +17,12 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; -import org.apache.poi.util.HexDump; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; /** @@ -56,15 +59,6 @@ public final class DSFRecord extends Sta return biff5BookStreamFlag.isSet(_options); } - public String toString() { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[DSF]\n"); - buffer.append(" .options = ").append(HexDump.shortToHex(_options)).append("\n"); - buffer.append("[/DSF]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeShort(_options); } @@ -81,4 +75,17 @@ public final class DSFRecord extends Sta public DSFRecord copy() { return new DSFRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DSF; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "options", () -> _options, + "biff5BookStreamPresent", this::isBiff5BookStreamPresent + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DVALRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DVALRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DVALRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DVALRecord.java Sun Apr 12 22:03:52 2020 @@ -17,6 +17,10 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -135,20 +139,6 @@ public final class DVALRecord extends St return field_5_dv_no; } - - public String toString() { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[DVAL]\n"); - buffer.append(" .options = ").append(getOptions()).append('\n'); - buffer.append(" .horizPos = ").append(getHorizontalPos()).append('\n'); - buffer.append(" .vertPos = ").append(getVerticalPos()).append('\n'); - buffer.append(" .comboObjectID = ").append(Integer.toHexString(getObjectID())).append("\n"); - buffer.append(" .DVRecordsNumber = ").append(Integer.toHexString(getDVRecNo())).append("\n"); - buffer.append("[/DVAL]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeShort(getOptions()); out.writeInt(getHorizontalPos()); @@ -166,7 +156,7 @@ public final class DVALRecord extends St } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public DVALRecord clone() { @@ -177,4 +167,20 @@ public final class DVALRecord extends St public DVALRecord copy() { return new DVALRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DVAL; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "options", this::getOptions, + "horizPos", this::getHorizontalPos, + "vertPos", this::getVerticalPos, + "comboObjectID", this::getObjectID, + "dvRecordsNumber", this::getDVRecNo + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DVRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DVRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DVRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DVRecord.java Sun Apr 12 22:03:52 2020 @@ -17,13 +17,18 @@ package org.apache.poi.hssf.record; +import static org.apache.poi.util.GenericRecordUtil.getBitsAsString; + +import java.util.Map; +import java.util.function.Supplier; + import org.apache.poi.hssf.record.common.UnicodeString; import org.apache.poi.hssf.usermodel.HSSFDataValidation; import org.apache.poi.ss.formula.Formula; import org.apache.poi.ss.formula.ptg.Ptg; -import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.util.BitField; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; import org.apache.poi.util.StringUtil; @@ -53,6 +58,15 @@ public final class DVRecord extends Stan private static final BitField opt_show_error_on_invalid_value = new BitField(0x00080000); private static final BitField opt_condition_operator = new BitField(0x00700000); + private static final int[] FLAG_MASKS = { 0x0000000F,0x00000070,0x00000080,0x00000100, + 0x00000200,0x00040000,0x00080000,0x00700000 }; + + private static final String[] FLAG_NAMES = { "DATA_TYPE", "ERROR_STYLE", "STRING_LIST_FORMULA", + "EMPTY_CELL_ALLOWED", "SUPPRESS_DROPDOWN_ARROW", "SHOW_PROMPT_ON_CELL_SELECTED", + "SHOW_ERROR_ON_INVALID_VALUE", "CONDITION_OPERATOR" }; + + + /** Option flags */ private int _option_flags; /** Title of the prompt box, cannot be longer than 32 chars */ @@ -250,55 +264,6 @@ public final class DVRecord extends Stan } - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("[DV]\n"); - sb.append(" options=").append(Integer.toHexString(_option_flags)); - sb.append(" title-prompt=").append(formatTextTitle(_promptTitle)); - sb.append(" title-error=").append(formatTextTitle(_errorTitle)); - sb.append(" text-prompt=").append(formatTextTitle(_promptText)); - sb.append(" text-error=").append(formatTextTitle(_errorText)); - sb.append("\n"); - appendFormula(sb, "Formula 1:", _formula1); - appendFormula(sb, "Formula 2:", _formula2); - sb.append("Regions: "); - int nRegions = _regions.countRanges(); - for(int i=0; i<nRegions; i++) { - if (i>0) { - sb.append(", "); - } - CellRangeAddress addr = _regions.getCellRangeAddress(i); - sb.append('(').append(addr.getFirstRow()).append(',').append(addr.getLastRow()); - sb.append(',').append(addr.getFirstColumn()).append(',').append(addr.getLastColumn()).append(')'); - } - sb.append("\n"); - sb.append("[/DV]"); - - return sb.toString(); - } - - private static String formatTextTitle(UnicodeString us) { - String str = us.getString(); - if (str.length() == 1 && str.charAt(0) == '\0') { - return "'\\0'"; - } - return str; - } - - private static void appendFormula(StringBuilder sb, String label, Formula f) { - sb.append(label); - - if (f == null) { - sb.append("<empty>\n"); - return; - } - Ptg[] ptgs = f.getTokens(); - sb.append('\n'); - for (Ptg ptg : ptgs) { - sb.append('\t').append(ptg).append('\n'); - } - } - public void serialize(LittleEndianOutput out) { out.writeInt(_option_flags); @@ -367,7 +332,7 @@ public final class DVRecord extends Stan } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public DVRecord clone() { @@ -379,4 +344,23 @@ public final class DVRecord extends Stan public DVRecord copy() { return new DVRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DV; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "optionFlags", getBitsAsString(() -> _option_flags, FLAG_MASKS, FLAG_NAMES), + "promptTitle", this::getPromptTitle, + "errorTitle", this::getErrorTitle, + "promptText", this::getPromptText, + "errorText", this::getErrorText, + "formula1", this::getFormula1, + "formula2", this::getFormula2, + "regions", () -> _regions + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DateWindow1904Record.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DateWindow1904Record.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DateWindow1904Record.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DateWindow1904Record.java Sun Apr 12 22:03:52 2020 @@ -19,6 +19,10 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; /** @@ -63,17 +67,6 @@ public final class DateWindow1904Record return field_1_window; } - public String toString() - { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[1904]\n"); - buffer.append(" .is1904 = ") - .append(Integer.toHexString(getWindowing())).append("\n"); - buffer.append("[/1904]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeShort(getWindowing()); } @@ -91,4 +84,14 @@ public final class DateWindow1904Record public DateWindow1904Record copy() { return new DateWindow1904Record(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DATE_WINDOW_1904; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties("is1904", this::getWindowing); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DefaultColWidthRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DefaultColWidthRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DefaultColWidthRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DefaultColWidthRecord.java Sun Apr 12 22:03:52 2020 @@ -17,6 +17,10 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -69,17 +73,6 @@ public final class DefaultColWidthRecord return field_1_col_width; } - public String toString() - { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[DEFAULTCOLWIDTH]\n"); - buffer.append(" .colwidth = ") - .append(Integer.toHexString(getColWidth())).append("\n"); - buffer.append("[/DEFAULTCOLWIDTH]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeShort(getColWidth()); } @@ -94,7 +87,7 @@ public final class DefaultColWidthRecord } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public DefaultColWidthRecord clone() { @@ -105,4 +98,16 @@ public final class DefaultColWidthRecord public DefaultColWidthRecord copy() { return new DefaultColWidthRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DEFAULT_COL_WIDTH; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "colWidth", this::getColWidth + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DefaultRowHeightRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DefaultRowHeightRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DefaultRowHeightRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DefaultRowHeightRecord.java Sun Apr 12 22:03:52 2020 @@ -18,6 +18,10 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -92,19 +96,6 @@ public final class DefaultRowHeightRecor return field_2_row_height; } - public String toString() - { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[DEFAULTROWHEIGHT]\n"); - buffer.append(" .optionflags = ") - .append(Integer.toHexString(getOptionFlags())).append("\n"); - buffer.append(" .rowheight = ") - .append(Integer.toHexString(getRowHeight())).append("\n"); - buffer.append("[/DEFAULTROWHEIGHT]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeShort(getOptionFlags()); out.writeShort(getRowHeight()); @@ -120,7 +111,7 @@ public final class DefaultRowHeightRecor } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public DefaultRowHeightRecord clone() { @@ -129,6 +120,19 @@ public final class DefaultRowHeightRecor @Override public DefaultRowHeightRecord copy() { - return new DefaultRowHeightRecord(this); + return new DefaultRowHeightRecord(this); + } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DEFAULT_ROW_HEIGHT; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "optionFlags", this::getOptionFlags, + "rowHeight", this::getRowHeight + ); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DeltaRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DeltaRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DeltaRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DeltaRecord.java Sun Apr 12 22:03:52 2020 @@ -17,6 +17,10 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -50,15 +54,6 @@ public final class DeltaRecord extends S return field_1_max_change; } - public String toString() { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[DELTA]\n"); - buffer.append(" .maxchange = ").append(getMaxChange()).append("\n"); - buffer.append("[/DELTA]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeDouble(getMaxChange()); } @@ -72,7 +67,7 @@ public final class DeltaRecord extends S } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public DeltaRecord clone() { @@ -84,4 +79,14 @@ public final class DeltaRecord extends S // immutable return this; } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DELTA; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties("maxChange", this::getMaxChange); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DimensionsRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DimensionsRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DimensionsRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DimensionsRecord.java Sun Apr 12 22:03:52 2020 @@ -19,6 +19,10 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -145,25 +149,6 @@ public final class DimensionsRecord exte return field_4_last_col; } - public String toString() - { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[DIMENSIONS]\n"); - buffer.append(" .firstrow = ") - .append(Integer.toHexString(getFirstRow())).append("\n"); - buffer.append(" .lastrow = ") - .append(Integer.toHexString(getLastRow())).append("\n"); - buffer.append(" .firstcol = ") - .append(Integer.toHexString(getFirstCol())).append("\n"); - buffer.append(" .lastcol = ") - .append(Integer.toHexString(getLastCol())).append("\n"); - buffer.append(" .zero = ") - .append(Integer.toHexString(field_5_zero)).append("\n"); - buffer.append("[/DIMENSIONS]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeInt(getFirstRow()); out.writeInt(getLastRow()); @@ -182,7 +167,7 @@ public final class DimensionsRecord exte } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public DimensionsRecord clone() { @@ -193,4 +178,20 @@ public final class DimensionsRecord exte public DimensionsRecord copy() { return new DimensionsRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DIMENSIONS; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "firstRow", this::getFirstRow, + "lastRow", this::getLastRow, + "firstColumn", this::getFirstCol, + "lastColumn", this::getLastCol, + "zero", () -> field_5_zero + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DrawingGroupRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DrawingGroupRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DrawingGroupRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DrawingGroupRecord.java Sun Apr 12 22:03:52 2020 @@ -17,8 +17,9 @@ package org.apache.poi.hssf.record; -import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.function.Supplier; import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.NullEscherSerializationListener; @@ -60,10 +61,8 @@ public final class DrawingGroupRecord ex } byte[] buffer = new byte[getRawDataSize()]; int pos = 0; - for ( Iterator<EscherRecord> iterator = getEscherRecords().iterator(); iterator.hasNext(); ) - { - EscherRecord r = iterator.next(); - pos += r.serialize(pos, buffer, new NullEscherSerializationListener() ); + for (EscherRecord r : getEscherRecords()) { + pos += r.serialize(pos, buffer, new NullEscherSerializationListener()); } return writeData( offset, data, buffer ); @@ -92,9 +91,7 @@ public final class DrawingGroupRecord ex return rawData.length; } int size = 0; - for ( Iterator<EscherRecord> iterator = escherRecords.iterator(); iterator.hasNext(); ) - { - EscherRecord r = iterator.next(); + for (EscherRecord r : escherRecords) { size += r.getRecordSize(); } return size; @@ -128,18 +125,28 @@ public final class DrawingGroupRecord ex private void writeHeader( byte[] data, int offset, int sizeExcludingHeader ) { - LittleEndian.putShort(data, 0 + offset, getSid()); - LittleEndian.putShort(data, 2 + offset, (short) sizeExcludingHeader); + LittleEndian.putShort(data, offset, getSid()); + LittleEndian.putShort(data, offset + 2, (short) sizeExcludingHeader); } private void writeContinueHeader( byte[] data, int offset, int sizeExcludingHeader ) { - LittleEndian.putShort(data, 0 + offset, ContinueRecord.sid); - LittleEndian.putShort(data, 2 + offset, (short) sizeExcludingHeader); + LittleEndian.putShort(data, offset, ContinueRecord.sid); + LittleEndian.putShort(data, offset + 2, (short) sizeExcludingHeader); } @Override public DrawingGroupRecord copy() { return new DrawingGroupRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DRAWING_GROUP; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return null; + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DrawingRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DrawingRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DrawingRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DrawingRecord.java Sun Apr 12 22:03:52 2020 @@ -17,6 +17,10 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -80,7 +84,7 @@ public final class DrawingRecord extends } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public DrawingRecord clone() { @@ -97,7 +101,15 @@ public final class DrawingRecord extends } @Override - public String toString() { - return "DrawingRecord["+recordData.length+"]"; + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DRAWING; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "recordData", this::getRecordData, + "contd", () -> contd + ); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java Sun Apr 12 22:03:52 2020 @@ -18,6 +18,8 @@ package org.apache.poi.hssf.record; import java.io.ByteArrayInputStream; +import java.util.Map; +import java.util.function.Supplier; /** * This is purely for the biff viewer. During normal operations we don't want @@ -66,4 +68,14 @@ public final class DrawingRecordForBiffV public DrawingRecordForBiffViewer copy() { return new DrawingRecordForBiffViewer(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DRAWING; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return null; + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java Sun Apr 12 22:03:52 2020 @@ -17,7 +17,11 @@ package org.apache.poi.hssf.record; -import org.apache.poi.util.HexDump; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.common.usermodel.GenericRecord; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -34,7 +38,7 @@ public final class DrawingSelectionRecor * From [MS-ODRAW].pdf sec 2.2.1<p> * TODO - make EscherRecordHeader {@link LittleEndianInput} aware and refactor with this */ - private static final class OfficeArtRecordHeader { + private static final class OfficeArtRecordHeader implements GenericRecord { public static final int ENCODED_SIZE = 8; /** * lower 4 bits is 'version' usually 0x01 or 0x0F (for containers) @@ -45,12 +49,6 @@ public final class DrawingSelectionRecor private final int _type; private final int _length; - public OfficeArtRecordHeader(OfficeArtRecordHeader other) { - _verAndInstance = other._verAndInstance; - _type = other._type; - _length = other._length; - } - public OfficeArtRecordHeader(LittleEndianInput in) { _verAndInstance = in.readUShort(); _type = in.readUShort(); @@ -63,11 +61,13 @@ public final class DrawingSelectionRecor out.writeInt(_length); } - public String debugFormatAsString() { - return - "ver+inst=" + HexDump.shortToHex(_verAndInstance) + - " type=" + HexDump.shortToHex(_type) + - " len=" + HexDump.intToHex(_length); + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "verAndInstance", () -> _verAndInstance, + "type", () -> _type, + "length", () -> _length + ); } } @@ -109,13 +109,13 @@ public final class DrawingSelectionRecor out.writeInt(_cpsp); out.writeInt(_dgslk); out.writeInt(_spidFocus); - for (int i = 0; i < _shapeIds.length; i++) { - out.writeInt(_shapeIds[i]); + for (int shapeId : _shapeIds) { + out.writeInt(shapeId); } } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public DrawingSelectionRecord clone() { @@ -128,24 +128,19 @@ public final class DrawingSelectionRecor return this; } - public String toString() { - StringBuilder sb = new StringBuilder(); - - sb.append("[MSODRAWINGSELECTION]\n"); - sb.append(" .rh =(").append(_header.debugFormatAsString()).append(")\n"); - sb.append(" .cpsp =").append(HexDump.intToHex(_cpsp)).append('\n'); - sb.append(" .dgslk =").append(HexDump.intToHex(_dgslk)).append('\n'); - sb.append(" .spidFocus=").append(HexDump.intToHex(_spidFocus)).append('\n'); - sb.append(" .shapeIds =("); - for (int i = 0; i < _shapeIds.length; i++) { - if (i > 0) { - sb.append(", "); - } - sb.append(HexDump.intToHex(_shapeIds[i])); - } - sb.append(")\n"); + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.DRAWING_SELECTION; + } - sb.append("[/MSODRAWINGSELECTION]\n"); - return sb.toString(); + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "rh", () -> _header, + "cpsp", () -> _cpsp, + "dgslk", () -> _dgslk, + "spidFocus", () -> _spidFocus, + "shapeIds", () -> _shapeIds + ); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/EOFRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/EOFRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/EOFRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/EOFRecord.java Sun Apr 12 22:03:52 2020 @@ -17,6 +17,9 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -38,15 +41,6 @@ public final class EOFRecord extends Sta */ public EOFRecord(RecordInputStream in) {} - public String toString() - { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[EOF]\n"); - buffer.append("[/EOF]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { } @@ -60,7 +54,7 @@ public final class EOFRecord extends Sta } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public EOFRecord clone() { @@ -71,4 +65,14 @@ public final class EOFRecord extends Sta public EOFRecord copy() { return instance; } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.EOF; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return null; + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java Sun Apr 12 22:03:52 2020 @@ -18,13 +18,15 @@ package org.apache.poi.hssf.record; import java.io.ByteArrayInputStream; +import java.util.Map; +import java.util.function.Supplier; import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.formula.ptg.AreaPtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.Ref3DPtg; import org.apache.poi.ss.formula.ptg.RefPtg; -import org.apache.poi.util.HexDump; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianInput; @@ -87,6 +89,10 @@ public final class EmbeddedObjectRefSubR } public EmbeddedObjectRefSubRecord(LittleEndianInput in, int size) { + this(in,size,-1); + } + + EmbeddedObjectRefSubRecord(LittleEndianInput in, int size, int cmoOt) { // Much guess-work going on here due to lack of any documentation. // See similar source code in OOO: @@ -327,32 +333,6 @@ public final class EmbeddedObjectRefSubR return new EmbeddedObjectRefSubRecord(this); } - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("[ftPictFmla]\n"); - sb.append(" .f2unknown = ").append(HexDump.intToHex(field_1_unknown_int)).append("\n"); - if (field_2_refPtg == null) { - sb.append(" .f3unknown = ").append(HexDump.toHex(field_2_unknownFormulaData)).append("\n"); - } else { - sb.append(" .formula = ").append(field_2_refPtg).append("\n"); - } - if (field_4_ole_classname != null) { - sb.append(" .unicodeFlag = ").append(field_3_unicode_flag).append("\n"); - sb.append(" .oleClassname = ").append(field_4_ole_classname).append("\n"); - } - if (field_4_unknownByte != null) { - sb.append(" .f4unknown = ").append(HexDump.byteToHex(field_4_unknownByte)).append("\n"); - } - if (field_5_stream_id != null) { - sb.append(" .streamId = ").append(HexDump.intToHex(field_5_stream_id)).append("\n"); - } - if (field_6_unknown.length > 0) { - sb.append(" .f7unknown = ").append(HexDump.toHex(field_6_unknown)).append("\n"); - } - sb.append("[/ftPictFmla]"); - return sb.toString(); - } - public void setUnknownFormulaData(byte[] formularData) { field_2_unknownFormulaData = formularData; } @@ -364,4 +344,23 @@ public final class EmbeddedObjectRefSubR public void setStorageId(int storageId) { field_5_stream_id = storageId; } + + @Override + public SubRecordTypes getGenericRecordType() { + return SubRecordTypes.EMBEDDED_OBJECT_REF; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "f2unknown", () -> field_1_unknown_int, + "f3unknown", () -> field_2_unknownFormulaData, + "formula", () -> field_2_refPtg, + "unicodeFlag", () -> field_3_unicode_flag, + "oleClassname", () -> field_4_ole_classname, + "f4unknown", () -> field_4_unknownByte, + "streamId", () -> field_5_stream_id, + "f7unknown", () -> field_6_unknown + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/EndSubRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/EndSubRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/EndSubRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/EndSubRecord.java Sun Apr 12 22:03:52 2020 @@ -17,6 +17,9 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.RecordFormatException; @@ -39,6 +42,10 @@ public final class EndSubRecord extends * @param size must be 0 */ public EndSubRecord(LittleEndianInput in, int size) { + this(in, size, -1); + } + + EndSubRecord(LittleEndianInput in, int size, int cmoOt) { if ((size & 0xFF) != ENCODED_SIZE) { // mask out random crap in upper byte throw new RecordFormatException("Unexpected size (" + size + ")"); } @@ -49,16 +56,6 @@ public final class EndSubRecord extends return true; } - public String toString() - { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[ftEnd]\n"); - - buffer.append("[/ftEnd]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeShort(sid); out.writeShort(ENCODED_SIZE); @@ -85,4 +82,14 @@ public final class EndSubRecord extends public EndSubRecord copy() { return new EndSubRecord(); } + + @Override + public SubRecordTypes getGenericRecordType() { + return SubRecordTypes.END; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return null; + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/EscherAggregate.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/EscherAggregate.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/EscherAggregate.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/EscherAggregate.java Sun Apr 12 22:03:52 2020 @@ -29,6 +29,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.function.Supplier; import org.apache.poi.ddf.DefaultEscherRecordFactory; import org.apache.poi.ddf.EscherClientDataRecord; @@ -39,6 +40,7 @@ import org.apache.poi.ddf.EscherSerializ import org.apache.poi.ddf.EscherSpRecord; import org.apache.poi.ddf.EscherSpgrRecord; import org.apache.poi.ddf.EscherTextboxRecord; +import org.apache.poi.util.GenericRecordXmlWriter; import org.apache.poi.util.IOUtils; import org.apache.poi.util.RecordFormatException; @@ -333,36 +335,13 @@ public final class EscherAggregate exten } /** - * Calculates the string representation of this record. This is - * simply a dump of all the records. - */ - public String toString() { - String nl = System.getProperty("line.separtor"); - - StringBuilder result = new StringBuilder(); - result.append('[').append(getRecordName()).append(']').append(nl); - for (EscherRecord escherRecord : getEscherRecords()) { - result.append(escherRecord); - } - result.append("[/").append(getRecordName()).append(']').append(nl); - - return result.toString(); - } - - /** * Calculates the xml representation of this record. This is * simply a dump of all the records. * @param tab - string which must be added before each line (used by default '\t') * @return xml representation of the all aggregated records */ public String toXml(String tab) { - StringBuilder builder = new StringBuilder(); - builder.append(tab).append("<").append(getRecordName()).append(">\n"); - for (EscherRecord escherRecord : getEscherRecords()) { - builder.append(escherRecord.toXml(tab + "\t")); - } - builder.append(tab).append("</").append(getRecordName()).append(">\n"); - return builder.toString(); + return GenericRecordXmlWriter.marshal(this); } /** @@ -789,4 +768,14 @@ public final class EscherAggregate exten public EscherAggregate copy() { return new EscherAggregate(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.ESCHER_AGGREGATE; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return null; + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java Sun Apr 12 22:03:52 2020 @@ -18,10 +18,14 @@ package org.apache.poi.hssf.record; import java.util.ArrayList; +import java.util.Map; +import java.util.function.Supplier; import java.util.stream.Stream; +import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.hssf.record.cont.ContinuableRecord; import org.apache.poi.hssf.record.cont.ContinuableRecordOutput; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; /** @@ -38,7 +42,7 @@ public final class ExtSSTRecord extends public static final int MAX_BUCKETS = 128; - public static final class InfoSubRecord { + public static final class InfoSubRecord implements GenericRecord { public static final int ENCODED_SIZE = 8; private int field_1_stream_pos; // stream pointer to the SST record private int field_2_bucket_sst_offset; // don't really understand this yet. @@ -62,8 +66,7 @@ public final class ExtSSTRecord extends field_3_zero = other.field_3_zero; } - public InfoSubRecord(RecordInputStream in) - { + public InfoSubRecord(RecordInputStream in) { field_1_stream_pos = in.readInt(); field_2_bucket_sst_offset = in.readShort(); field_3_zero = in.readShort(); @@ -82,6 +85,14 @@ public final class ExtSSTRecord extends out.writeShort(field_2_bucket_sst_offset); out.writeShort(field_3_zero); } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "streamPos", this::getStreamPos, + "bucketSSTOffset", this::getBucketSSTOffset + ); + } } @@ -121,41 +132,18 @@ public final class ExtSSTRecord extends _stringsPerBucket = numStrings; } - public String toString() { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[EXTSST]\n"); - buffer.append(" .dsst = ") - .append(Integer.toHexString(_stringsPerBucket)) - .append("\n"); - buffer.append(" .numInfoRecords = ").append(_sstInfos.length) - .append("\n"); - for (int k = 0; k < _sstInfos.length; k++) - { - buffer.append(" .inforecord = ").append(k).append("\n"); - buffer.append(" .streampos = ") - .append(Integer - .toHexString(_sstInfos[k].getStreamPos())).append("\n"); - buffer.append(" .sstoffset = ") - .append(Integer - .toHexString(_sstInfos[k].getBucketSSTOffset())) - .append("\n"); - } - buffer.append("[/EXTSST]\n"); - return buffer.toString(); - } - public void serialize(ContinuableRecordOutput out) { out.writeShort(_stringsPerBucket); - for (int k = 0; k < _sstInfos.length; k++) { - _sstInfos[k].serialize(out); + for (InfoSubRecord sstInfo : _sstInfos) { + sstInfo.serialize(out); } } - protected int getDataSize() { + + int getDataSize() { return 2 + InfoSubRecord.ENCODED_SIZE*_sstInfos.length; } - protected InfoSubRecord[] getInfoSubRecords() { + InfoSubRecord[] getInfoSubRecords() { return _sstInfos; } @@ -197,4 +185,17 @@ public final class ExtSSTRecord extends public ExtSSTRecord copy() { return new ExtSSTRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.EXT_SST; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "dataSize", this::getDataSize, + "infoSubRecords", this::getInfoSubRecords + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java Sun Apr 12 22:03:52 2020 @@ -18,7 +18,15 @@ package org.apache.poi.hssf.record; +import static org.apache.poi.util.GenericRecordUtil.getBitsAsString; +import static org.apache.poi.util.GenericRecordUtil.getEnumBitsAsString; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Objects; +import java.util.function.Supplier; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; @@ -1645,114 +1653,6 @@ public final class ExtendedFormatRecord } @Override - public String toString() - { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[EXTENDEDFORMAT]\n"); - if (getXFType() == XF_STYLE) - { - buffer.append(" STYLE_RECORD_TYPE\n"); - } - else if (getXFType() == XF_CELL) - { - buffer.append(" CELL_RECORD_TYPE\n"); - } - buffer.append(" .fontindex = ") - .append(Integer.toHexString(getFontIndex())).append("\n"); - buffer.append(" .formatindex = ") - .append(Integer.toHexString(getFormatIndex())).append("\n"); - buffer.append(" .celloptions = ") - .append(Integer.toHexString(getCellOptions())).append("\n"); - buffer.append(" .islocked = ").append(isLocked()) - .append("\n"); - buffer.append(" .ishidden = ").append(isHidden()) - .append("\n"); - buffer.append(" .recordtype= ") - .append(Integer.toHexString(getXFType())).append("\n"); - buffer.append(" .parentidx = ") - .append(Integer.toHexString(getParentIndex())).append("\n"); - buffer.append(" .alignmentoptions= ") - .append(Integer.toHexString(getAlignmentOptions())).append("\n"); - buffer.append(" .alignment = ").append(getAlignment()) - .append("\n"); - buffer.append(" .wraptext = ").append(getWrapText()) - .append("\n"); - buffer.append(" .valignment= ") - .append(Integer.toHexString(getVerticalAlignment())).append("\n"); - buffer.append(" .justlast = ") - .append(Integer.toHexString(getJustifyLast())).append("\n"); - buffer.append(" .rotation = ") - .append(Integer.toHexString(getRotation())).append("\n"); - buffer.append(" .indentionoptions= ") - .append(Integer.toHexString(getIndentionOptions())).append("\n"); - buffer.append(" .indent = ") - .append(Integer.toHexString(getIndent())).append("\n"); - buffer.append(" .shrinktoft= ").append(getShrinkToFit()) - .append("\n"); - buffer.append(" .mergecells= ").append(getMergeCells()) - .append("\n"); - buffer.append(" .readngordr= ") - .append(Integer.toHexString(getReadingOrder())).append("\n"); - buffer.append(" .formatflag= ") - .append(isIndentNotParentFormat()).append("\n"); - buffer.append(" .fontflag = ") - .append(isIndentNotParentFont()).append("\n"); - buffer.append(" .prntalgnmt= ") - .append(isIndentNotParentAlignment()).append("\n"); - buffer.append(" .borderflag= ") - .append(isIndentNotParentBorder()).append("\n"); - buffer.append(" .paternflag= ") - .append(isIndentNotParentPattern()).append("\n"); - buffer.append(" .celloption= ") - .append(isIndentNotParentCellOptions()).append("\n"); - buffer.append(" .borderoptns = ") - .append(Integer.toHexString(getBorderOptions())).append("\n"); - buffer.append(" .lftln = ") - .append(Integer.toHexString(getBorderLeft())).append("\n"); - buffer.append(" .rgtln = ") - .append(Integer.toHexString(getBorderRight())).append("\n"); - buffer.append(" .topln = ") - .append(Integer.toHexString(getBorderTop())).append("\n"); - buffer.append(" .btmln = ") - .append(Integer.toHexString(getBorderBottom())).append("\n"); - buffer.append(" .paleteoptns = ") - .append(Integer.toHexString(getPaletteOptions())).append("\n"); - buffer.append(" .leftborder= ") - .append(Integer.toHexString(getLeftBorderPaletteIdx())) - .append("\n"); - buffer.append(" .rghtborder= ") - .append(Integer.toHexString(getRightBorderPaletteIdx())) - .append("\n"); - buffer.append(" .diag = ") - .append(Integer.toHexString(getDiag())).append("\n"); - buffer.append(" .paleteoptn2 = ") - .append(Integer.toHexString(getAdtlPaletteOptions())) - .append("\n"); - buffer.append(" .topborder = ") - .append(Integer.toHexString(getTopBorderPaletteIdx())) - .append("\n"); - buffer.append(" .botmborder= ") - .append(Integer.toHexString(getBottomBorderPaletteIdx())) - .append("\n"); - buffer.append(" .adtldiag = ") - .append(Integer.toHexString(getAdtlDiag())).append("\n"); - buffer.append(" .diaglnstyl= ") - .append(Integer.toHexString(getAdtlDiagLineStyle())).append("\n"); - buffer.append(" .fillpattrn= ") - .append(Integer.toHexString(getAdtlFillPattern())).append("\n"); - buffer.append(" .fillpaloptn = ") - .append(Integer.toHexString(getFillPaletteOptions())) - .append("\n"); - buffer.append(" .foreground= ") - .append(Integer.toHexString(getFillForeground())).append("\n"); - buffer.append(" .background= ") - .append(Integer.toHexString(getFillBackground())).append("\n"); - buffer.append("[/EXTENDEDFORMAT]\n"); - return buffer.toString(); - } - - @Override public void serialize(LittleEndianOutput out) { out.writeShort(getFontIndex()); out.writeShort(getFormatIndex()); @@ -1827,25 +1727,7 @@ public final class ExtendedFormatRecord return false; if (obj instanceof ExtendedFormatRecord) { final ExtendedFormatRecord other = (ExtendedFormatRecord) obj; - if (field_1_font_index != other.field_1_font_index) - return false; - if (field_2_format_index != other.field_2_format_index) - return false; - if (field_3_cell_options != other.field_3_cell_options) - return false; - if (field_4_alignment_options != other.field_4_alignment_options) - return false; - if (field_5_indention_options != other.field_5_indention_options) - return false; - if (field_6_border_options != other.field_6_border_options) - return false; - if (field_7_palette_options != other.field_7_palette_options) - return false; - if (field_8_adtl_palette_options != other.field_8_adtl_palette_options) - return false; - if (field_9_fill_palette_options != other.field_9_fill_palette_options) - return false; - return true; + return Arrays.equals(stateSummary(), other.stateSummary()); } return false; } @@ -1860,4 +1742,54 @@ public final class ExtendedFormatRecord public ExtendedFormatRecord copy() { return new ExtendedFormatRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.EXTENDED_FORMAT; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + final Map<String,Supplier<?>> m = new LinkedHashMap<>(); + m.put("xfType", getEnumBitsAsString(this::getXFType, new int[]{0,1}, new String[]{"CELL", "STYLE"})); + m.put("fontIndex", this::getFontIndex); + m.put("formatIndex", this::getFormatIndex); + m.put("cellOptions", getBitsAsString(this::getCellOptions, + new BitField[]{_locked,_hidden,_123_prefix}, + new String[]{"LOCKED","HIDDEN","LOTUS_123_PREFIX"})); + m.put("parentIndex", this::getParentIndex); + m.put("alignmentOptions", getBitsAsString(this::getAlignmentOptions, + new BitField[]{_wrap_text, _justify_last}, + new String[]{"WRAP_TEXT", "JUSTIFY_LAST"})); + m.put("alignment", this::getAlignment); + m.put("verticalAlignment", this::getVerticalAlignment); + m.put("rotation", this::getRotation); + m.put("indentionOptions", getBitsAsString(this::getIndentionOptions, + new BitField[]{_shrink_to_fit,_merge_cells,_indent_not_parent_format,_indent_not_parent_font, + _indent_not_parent_alignment,_indent_not_parent_border,_indent_not_parent_pattern,_indent_not_parent_cell_options}, + new String[]{"SHRINK_TO_FIT","MERGE_CELLS","NOT_PARENT_FORMAT","NOT_PARENT_FONT", + "NOT_PARENT_ALIGNMENT","NOT_PARENT_BORDER","NOT_PARENT_PATTERN","NOT_PARENT_CELL_OPTIONS"})); + m.put("indent", this::getIndent); + m.put("readingOrder", this::getReadingOrder); + m.put("borderOptions", this::getBorderOptions); + m.put("borderLeft", this::getBorderLeft); + m.put("borderRight", this::getBorderRight); + m.put("borderTop", this::getBorderTop); + m.put("borderBottom", this::getBorderBottom); + m.put("paletteOptions", this::getPaletteOptions); + m.put("leftBorderPaletteIdx", this::getLeftBorderPaletteIdx); + m.put("rightBorderPaletteIdx", this::getRightBorderPaletteIdx); + m.put("diag", this::getDiag); + m.put("adtlPaletteOptions", this::getAdtlPaletteOptions); + m.put("topBorderPaletteIdx", this::getTopBorderPaletteIdx); + m.put("bottomBorderPaletteIdx", this::getBottomBorderPaletteIdx); + m.put("adtlDiag", this::getAdtlDiag); + m.put("adtlDiagLineStyle", this::getAdtlDiagLineStyle); + m.put("adtlFillPattern", this::getAdtlFillPattern); + m.put("fillPaletteOptions", this::getFillPaletteOptions); + m.put("fillForeground", this::getFillForeground); + m.put("fillBackground", this::getFillBackground); + + return Collections.unmodifiableMap(m); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java Sun Apr 12 22:03:52 2020 @@ -19,7 +19,12 @@ package org.apache.poi.hssf.record; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.function.Supplier; +import org.apache.poi.common.usermodel.GenericRecord; +import org.apache.poi.util.GenericRecordJsonWriter; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; /** @@ -31,7 +36,7 @@ public class ExternSheetRecord extends S public static final short sid = 0x0017; private final List<RefSubRecord> _list = new ArrayList<>(); - private static final class RefSubRecord { + private static final class RefSubRecord implements GenericRecord { public static final int ENCODED_SIZE = 6; /** index to External Book Block (which starts with a EXTERNALBOOK record) */ @@ -58,11 +63,6 @@ public class ExternSheetRecord extends S this(in.readShort(), in.readShort(), in.readShort()); } - public void adjustIndex(int offset) { - _firstSheetIndex += offset; - _lastSheetIndex += offset; - } - public int getExtBookIndex(){ return _extBookIndex; } @@ -75,11 +75,7 @@ public class ExternSheetRecord extends S @Override public String toString() { - StringBuilder buffer = new StringBuilder(); - buffer.append("extBook=").append(_extBookIndex); - buffer.append(" firstSheet=").append(_firstSheetIndex); - buffer.append(" lastSheet=").append(_lastSheetIndex); - return buffer.toString(); + return GenericRecordJsonWriter.marshal(this); } public void serialize(LittleEndianOutput out) { @@ -87,6 +83,15 @@ public class ExternSheetRecord extends S out.writeShort(_firstSheetIndex); out.writeShort(_lastSheetIndex); } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "extBookIndex", this::getExtBookIndex, + "firstSheetIndex", this::getFirstSheetIndex, + "lastSheetIndex", this::getLastSheetIndex + ); + } } public ExternSheetRecord() {} @@ -127,24 +132,6 @@ public class ExternSheetRecord extends S return _list.size(); } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - int nItems = _list.size(); - sb.append("[EXTERNSHEET]\n"); - sb.append(" numOfRefs = ").append(nItems).append("\n"); - for (int i=0; i < nItems; i++) { - sb.append("refrec #").append(i).append(": "); - sb.append(getRef(i)); - sb.append('\n'); - } - sb.append("[/EXTERNSHEET]\n"); - - - return sb.toString(); - } - @Override protected int getDataSize() { return 2 + _list.size() * RefSubRecord.ENCODED_SIZE; @@ -309,4 +296,14 @@ public class ExternSheetRecord extends S public ExternSheetRecord copy() { return new ExternSheetRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.EXTERN_SHEET; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties("refrec", () -> _list); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java Sun Apr 12 22:03:52 2020 @@ -17,9 +17,13 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + import org.apache.poi.ss.formula.Formula; import org.apache.poi.ss.formula.constant.ConstantValueParser; import org.apache.poi.ss.formula.ptg.Ptg; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.StringUtil; @@ -38,6 +42,12 @@ public final class ExternalNameRecord ex // private static final int OPT_CLIP_FORMAT_MASK = 0x7FE0; private static final int OPT_ICONIFIED_PICTURE_LINK= 0x8000; + private static final int[] OPTION_FLAGS = { + OPT_BUILTIN_NAME,OPT_AUTOMATIC_LINK,OPT_PICTURE_LINK,OPT_STD_DOCUMENT_NAME,OPT_OLE_LINK,OPT_ICONIFIED_PICTURE_LINK}; + private static final String[] OPTION_NAMES = { + "BUILTIN_NAME","AUTOMATIC_LINK","PICTURE_LINK","STD_DOCUMENT_NAME","OLE_LINK","ICONIFIED_PICTURE_LINK"}; + + private short field_1_option_flag; private short field_2_ixals; @@ -225,24 +235,23 @@ public final class ExternalNameRecord ex } @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("[EXTERNALNAME]\n"); - sb.append(" .options = ").append(field_1_option_flag).append("\n"); - sb.append(" .ix = ").append(field_2_ixals).append("\n"); - sb.append(" .name = ").append(field_4_name).append("\n"); - if(field_5_name_definition != null) { - Ptg[] ptgs = field_5_name_definition.getTokens(); - for (Ptg ptg : ptgs) { - sb.append(" .namedef = ").append(ptg).append(ptg.getRVAType()).append("\n"); - } - } - sb.append("[/EXTERNALNAME]\n"); - return sb.toString(); + public ExternalNameRecord copy() { + return new ExternalNameRecord(this); } @Override - public ExternalNameRecord copy() { - return new ExternalNameRecord(this); + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.EXTERNAL_NAME; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "options", GenericRecordUtil.getBitsAsString(() -> field_1_option_flag, OPTION_FLAGS, OPTION_NAMES), + "ix", this::getIx, + "name", this::getText, + "nameDefinition", (field_5_name_definition == null ? () -> null : field_5_name_definition::getTokens) + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FeatHdrRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FeatHdrRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/FeatHdrRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/FeatHdrRecord.java Sun Apr 12 22:03:52 2020 @@ -17,7 +17,11 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + import org.apache.poi.hssf.record.common.FtrHeader; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -55,8 +59,10 @@ public final class FeatHdrRecord extends public static final short sid = 0x0867; private final FtrHeader futureHeader; - private int isf_sharedFeatureType; // See SHAREDFEATURES_ - private byte reserved; // Should always be one + // See SHAREDFEATURES + private int isf_sharedFeatureType; + // Should always be one + private byte reserved; /** * 0x00000000 = rgbHdrData not present * 0xffffffff = rgbHdrData present @@ -93,16 +99,6 @@ public final class FeatHdrRecord extends return sid; } - public String toString() { - StringBuilder buffer = new StringBuilder(); - buffer.append("[FEATURE HEADER]\n"); - - // TODO ... - - buffer.append("[/FEATURE HEADER]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { futureHeader.serialize(out); @@ -117,7 +113,7 @@ public final class FeatHdrRecord extends } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public FeatHdrRecord clone() { @@ -130,5 +126,19 @@ public final class FeatHdrRecord extends return new FeatHdrRecord(this); } + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.FEAT_HDR; + } + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "futureHeader", () -> futureHeader, + "isf_sharedFeatureType", () -> isf_sharedFeatureType, + "reserved", () -> reserved, + "cbHdrData", () -> cbHdrData, + "rgbHdrData", () -> rgbHdrData + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FeatRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FeatRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/FeatRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/FeatRecord.java Sun Apr 12 22:03:52 2020 @@ -17,6 +17,8 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; import java.util.stream.Stream; import org.apache.poi.hssf.record.common.FeatFormulaErr2; @@ -25,6 +27,7 @@ import org.apache.poi.hssf.record.common import org.apache.poi.hssf.record.common.FtrHeader; import org.apache.poi.hssf.record.common.SharedFeature; import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -114,16 +117,6 @@ public final class FeatRecord extends St return sid; } - public String toString() { - StringBuilder buffer = new StringBuilder(); - buffer.append("[SHARED FEATURE]\n"); - - // TODO ... - - buffer.append("[/SHARED FEATURE]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { futureHeader.serialize(out); @@ -134,8 +127,8 @@ public final class FeatRecord extends St out.writeInt((int)cbFeatData); out.writeShort(reserved3); - for(int i=0; i<cellRefs.length; i++) { - cellRefs[i].serialize(out); + for (CellRangeAddress cellRef : cellRefs) { + cellRef.serialize(out); } sharedFeature.serialize(out); @@ -189,7 +182,7 @@ public final class FeatRecord extends St } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public FeatRecord clone() { @@ -200,4 +193,23 @@ public final class FeatRecord extends St public FeatRecord copy() { return new FeatRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.FEAT; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "futureHeader", () -> futureHeader, + "isf_sharedFeatureType", this::getIsf_sharedFeatureType, + "reserved1", () -> reserved1, + "reserved2", () -> reserved2, + "cbFeatData", this::getCbFeatData, + "reserved3", () -> reserved3, + "cellRefs", this::getCellRefs, + "sharedFeature", this::getSharedFeature + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FilePassRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FilePassRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/FilePassRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/FilePassRecord.java Sun Apr 12 22:03:52 2020 @@ -19,6 +19,8 @@ package org.apache.poi.hssf.record; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.Map; +import java.util.function.Supplier; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.poifs.crypt.EncryptionInfo; @@ -29,7 +31,7 @@ import org.apache.poi.poifs.crypt.crypto import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionVerifier; import org.apache.poi.poifs.crypt.xor.XOREncryptionHeader; import org.apache.poi.poifs.crypt.xor.XOREncryptionVerifier; -import org.apache.poi.util.HexDump; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianByteArrayOutputStream; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutputStream; @@ -86,7 +88,7 @@ public final class FilePassRecord extend public void serialize(LittleEndianOutput out) { out.writeShort(encryptionType); - byte data[] = new byte[1024]; + byte[] data = new byte[1024]; try (LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(data, 0)) { // NOSONAR @@ -137,7 +139,7 @@ public final class FilePassRecord extend } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public FilePassRecord clone() { @@ -149,19 +151,16 @@ public final class FilePassRecord extend return new FilePassRecord(this); } - @Override - public String toString() { - StringBuilder buffer = new StringBuilder(); + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.FILE_PASS; + } - buffer.append("[FILEPASS]\n"); - buffer.append(" .type = ").append(HexDump.shortToHex(encryptionType)).append('\n'); - String prefix = " ."+encryptionInfo.getEncryptionMode(); - buffer.append(prefix+".info = ").append(HexDump.shortToHex(encryptionInfo.getVersionMajor())).append('\n'); - buffer.append(prefix+".ver = ").append(HexDump.shortToHex(encryptionInfo.getVersionMinor())).append('\n'); - buffer.append(prefix+".salt = ").append(HexDump.toHex(encryptionInfo.getVerifier().getSalt())).append('\n'); - buffer.append(prefix+".verifier = ").append(HexDump.toHex(encryptionInfo.getVerifier().getEncryptedVerifier())).append('\n'); - buffer.append(prefix+".verifierHash = ").append(HexDump.toHex(encryptionInfo.getVerifier().getEncryptedVerifierHash())).append('\n'); - buffer.append("[/FILEPASS]\n"); - return buffer.toString(); - } + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "type", () -> encryptionType, + "encryptionInfo", this::getEncryptionInfo + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FileSharingRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FileSharingRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/FileSharingRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/FileSharingRecord.java Sun Apr 12 22:03:52 2020 @@ -17,6 +17,10 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; import org.apache.poi.util.StringUtil; @@ -106,20 +110,6 @@ public final class FileSharingRecord ext } - public String toString() { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[FILESHARING]\n"); - buffer.append(" .readonly = ") - .append(getReadOnly() == 1 ? "true" : "false").append("\n"); - buffer.append(" .password = ") - .append(Integer.toHexString(getPassword())).append("\n"); - buffer.append(" .username = ") - .append(getUsername()).append("\n"); - buffer.append("[/FILESHARING]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { // TODO - junit out.writeShort(getReadOnly()); @@ -144,7 +134,7 @@ public final class FileSharingRecord ext } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public FileSharingRecord clone() { @@ -153,6 +143,20 @@ public final class FileSharingRecord ext @Override public FileSharingRecord copy() { - return new FileSharingRecord(this); + return new FileSharingRecord(this); + } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.FILE_SHARING; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "readOnly", this::getReadOnly, + "password", this::getPassword, + "username", this::getUsername + ); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FnGroupCountRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FnGroupCountRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/FnGroupCountRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/FnGroupCountRecord.java Sun Apr 12 22:03:52 2020 @@ -19,6 +19,10 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; /** @@ -70,17 +74,6 @@ public final class FnGroupCountRecord ex return field_1_count; } - public String toString() - { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[FNGROUPCOUNT]\n"); - buffer.append(" .count = ").append(getCount()) - .append("\n"); - buffer.append("[/FNGROUPCOUNT]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { out.writeShort(getCount()); } @@ -98,4 +91,14 @@ public final class FnGroupCountRecord ex public FnGroupCountRecord copy() { return new FnGroupCountRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.FN_GROUP_COUNT; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties("count", this::getCount); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java Sun Apr 12 22:03:52 2020 @@ -17,11 +17,13 @@ package org.apache.poi.hssf.record; +import java.util.Map; import java.util.Objects; +import java.util.function.Supplier; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; -import org.apache.poi.util.HexDump; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.StringUtil; @@ -380,25 +382,6 @@ public final class FontRecord extends St return field_11_font_name; } - public String toString() { - return - "[FONT]\n" + - " .fontheight = " + HexDump.shortToHex(getFontHeight()) + "\n" + - " .attributes = " + HexDump.shortToHex(getAttributes()) + "\n" + - " .italic = " + isItalic() + "\n" + - " .strikout = " + isStruckout() + "\n" + - " .macoutlined= " + isMacoutlined() + "\n" + - " .macshadowed= " + isMacshadowed() + "\n" + - " .colorpalette = " + HexDump.shortToHex(getColorPaletteIndex()) + "\n" + - " .boldweight = " + HexDump.shortToHex(getBoldWeight()) + "\n" + - " .supersubscript= " + HexDump.shortToHex(getSuperSubScript()) + "\n" + - " .underline = " + HexDump.byteToHex(getUnderline()) + "\n" + - " .family = " + HexDump.byteToHex(getFamily()) + "\n" + - " .charset = " + HexDump.byteToHex(getCharset()) + "\n" + - " .fontname = " + getFontName() + "\n" + - "[/FONT]\n"; - } - public void serialize(LittleEndianOutput out) { out.writeShort(getFontHeight()); @@ -509,4 +492,26 @@ public final class FontRecord extends St public FontRecord copy() { return new FontRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.FONT; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "fontHeight", this::getFontHeight, + "attributes", GenericRecordUtil.getBitsAsString(this::getAttributes, + new BitField[]{italic,strikeout,macoutline,macshadow}, + new String[]{"ITALIC","STRIKEOUT","MACOUTLINE","MACSHADOW"}), + "colorPalette", this::getColorPaletteIndex, + "boldWeight", this::getBoldWeight, + "superSubScript", this::getSuperSubScript, + "underline", this::getUnderline, + "family", this::getFamily, + "charset", this::getCharset, + "fontName", this::getFontName + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FooterRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FooterRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/FooterRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/FooterRecord.java Sun Apr 12 22:03:52 2020 @@ -37,21 +37,12 @@ public final class FooterRecord extends super(in); } - public String toString() { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[FOOTER]\n"); - buffer.append(" .footer = ").append(getText()).append("\n"); - buffer.append("[/FOOTER]\n"); - return buffer.toString(); - } - public short getSid() { return sid; } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public FooterRecord clone() { @@ -62,4 +53,9 @@ public final class FooterRecord extends public FooterRecord copy() { return new FooterRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.FOOTER; + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FormatRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FormatRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/FormatRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/FormatRecord.java Sun Apr 12 22:03:52 2020 @@ -17,7 +17,10 @@ package org.apache.poi.hssf.record; -import org.apache.poi.util.HexDump; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.POILogFactory; @@ -82,17 +85,6 @@ public final class FormatRecord extends return field_4_formatstring; } - public String toString() { - StringBuilder buffer = new StringBuilder(); - - buffer.append("[FORMAT]\n"); - buffer.append(" .indexcode = ").append(HexDump.shortToHex(getIndexCode())).append("\n"); - buffer.append(" .isUnicode = ").append(field_3_hasMultibyte ).append("\n"); - buffer.append(" .formatstring = ").append(getFormatString()).append("\n"); - buffer.append("[/FORMAT]\n"); - return buffer.toString(); - } - public void serialize(LittleEndianOutput out) { String formatString = getFormatString(); out.writeShort(getIndexCode()); @@ -115,7 +107,7 @@ public final class FormatRecord extends } @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public FormatRecord clone() { @@ -134,10 +126,9 @@ public final class FormatRecord extends if (requestedLength < 0 || requestedLength > 0x100000) { // 16 million chars? throw new IllegalArgumentException("Bad requested string length (" + requestedLength + ")"); } - char[] buf = null; + char[] buf; int availableChars = pIsCompressedEncoding ? ris.remaining() : ris.remaining() / LittleEndianConsts.SHORT_SIZE; //everything worked out. Great! - int remaining = ris.remaining(); if (requestedLength == availableChars) { buf = new char[requestedLength]; } else { @@ -176,4 +167,17 @@ public final class FormatRecord extends return new String(buf); } + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.FORMAT; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "indexCode", this::getIndexCode, + "unicode", () -> field_3_hasMultibyte, + "formatString", this::getFormatString + ); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java?rev=1876433&r1=1876432&r2=1876433&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java Sun Apr 12 22:03:52 2020 @@ -17,12 +17,15 @@ package org.apache.poi.hssf.record; +import java.util.Map; +import java.util.function.Supplier; + import org.apache.poi.ss.formula.Formula; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; -import org.apache.poi.util.HexDump; +import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.Removal; @@ -228,32 +231,7 @@ public final class FormulaRecord extends } @Override - protected void appendValueText(StringBuilder sb) { - sb.append(" .value = "); - if (specialCachedValue == null) { - sb.append(field_4_value).append("\n"); - } else { - sb.append(specialCachedValue.formatDebugString()).append("\n"); - } - sb.append(" .options = ").append(HexDump.shortToHex(getOptions())).append("\n"); - sb.append(" .alwaysCalc= ").append(isAlwaysCalc()).append("\n"); - sb.append(" .calcOnLoad= ").append(isCalcOnLoad()).append("\n"); - sb.append(" .shared = ").append(isSharedFormula()).append("\n"); - sb.append(" .zero = ").append(HexDump.intToHex(field_6_zero)).append("\n"); - - Ptg[] ptgs = field_8_parsed_expr.getTokens(); - for (int k = 0; k < ptgs.length; k++ ) { - if (k>0) { - sb.append("\n"); - } - sb.append(" Ptg[").append(k).append("]="); - Ptg ptg = ptgs[k]; - sb.append(ptg).append(ptg.getRVAType()); - } - } - - @Override - @SuppressWarnings("squid:S2975") + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) @Deprecated @Removal(version = "5.0.0") public FormulaRecord clone() { @@ -264,5 +242,24 @@ public final class FormulaRecord extends public FormulaRecord copy() { return new FormulaRecord(this); } + + @Override + public HSSFRecordTypes getGenericRecordType() { + return HSSFRecordTypes.FORMULA; + } + + @Override + public Map<String, Supplier<?>> getGenericProperties() { + return GenericRecordUtil.getGenericProperties( + "base", super::getGenericProperties, + "options", this::getOptions, + "alwaysCalc", this::isAlwaysCalc, + "calcOnLoad", this::isCalcOnLoad, + "shared", this::isSharedFormula, + "zero", () -> field_6_zero, + "value", () -> specialCachedValue == null ? field_4_value : specialCachedValue, + "formula", this::getFormula + ); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org