You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OldLabelRecord.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.record;
  16. import org.apache.poi.util.HexDump;
  17. import org.apache.poi.util.POILogFactory;
  18. import org.apache.poi.util.POILogger;
  19. /**
  20. * Biff2 - Biff 4 Label Record (0x0004 / 0x0204) - read only support for
  21. * strings stored directly in the cell, from the older file formats that
  22. * didn't use {@link LabelSSTRecord}
  23. */
  24. public final class OldLabelRecord extends Record implements CellValueRecordInterface {
  25. private final static POILogger logger = POILogFactory.getLogger(OldLabelRecord.class);
  26. public final static short biff2_sid = 0x0004;
  27. public final static short biff345_sid = 0x0204;
  28. private short sid;
  29. private int field_1_row;
  30. private short field_2_column;
  31. private int field_3_cell_attrs; // Biff 2
  32. private short field_3_xf_index; // Biff 3+
  33. private short field_4_string_len;
  34. private byte[] field_5_bytes;
  35. //private XXXXX codepage; // TODO
  36. /**
  37. * @param in the RecordInputstream to read the record from
  38. */
  39. public OldLabelRecord(RecordInputStream in)
  40. {
  41. sid = in.getSid();
  42. field_1_row = in.readUShort();
  43. field_2_column = in.readShort();
  44. if (in.getSid() == biff2_sid) {
  45. field_3_cell_attrs = in.readUShort() << 8;
  46. field_3_cell_attrs += in.readUByte();
  47. field_4_string_len = (short)in.readUByte();
  48. } else {
  49. field_3_xf_index = in.readShort();
  50. field_4_string_len = in.readShort();
  51. }
  52. // Can only decode properly later when you know the codepage
  53. field_5_bytes = new byte[field_4_string_len];
  54. in.read(field_5_bytes, 0, field_4_string_len);
  55. if (in.remaining() > 0) {
  56. logger.log(POILogger.INFO,
  57. "LabelRecord data remains: " + in.remaining() +
  58. " : " + HexDump.toHex(in.readRemainder())
  59. );
  60. }
  61. }
  62. public boolean isBiff2() {
  63. return sid == biff2_sid;
  64. }
  65. public int getRow()
  66. {
  67. return field_1_row;
  68. }
  69. public short getColumn()
  70. {
  71. return field_2_column;
  72. }
  73. public short getXFIndex()
  74. {
  75. return field_3_xf_index;
  76. }
  77. public int getCellAttrs()
  78. {
  79. return field_3_cell_attrs;
  80. }
  81. /**
  82. * get the number of characters this string contains
  83. * @return number of characters
  84. */
  85. public short getStringLength()
  86. {
  87. return field_4_string_len;
  88. }
  89. /**
  90. * Get the String of the cell
  91. */
  92. public String getValue()
  93. {
  94. // We really need the codepage here to do this right...
  95. return new String(field_5_bytes);
  96. }
  97. /**
  98. * Not supported
  99. */
  100. public int serialize(int offset, byte [] data) {
  101. throw new RecordFormatException("Old Label Records are supported READ ONLY");
  102. }
  103. public int getRecordSize() {
  104. throw new RecordFormatException("Old Label Records are supported READ ONLY");
  105. }
  106. public short getSid()
  107. {
  108. return sid;
  109. }
  110. public String toString()
  111. {
  112. StringBuffer sb = new StringBuffer();
  113. sb.append("[OLD LABEL]\n");
  114. sb.append(" .row = ").append(HexDump.shortToHex(getRow())).append("\n");
  115. sb.append(" .column = ").append(HexDump.shortToHex(getColumn())).append("\n");
  116. if (isBiff2()) {
  117. sb.append(" .cellattrs = ").append(HexDump.shortToHex(getCellAttrs())).append("\n");
  118. } else {
  119. sb.append(" .xfindex = ").append(HexDump.shortToHex(getXFIndex())).append("\n");
  120. }
  121. sb.append(" .string_len= ").append(HexDump.shortToHex(field_4_string_len)).append("\n");
  122. sb.append(" .value = ").append(getValue()).append("\n");
  123. sb.append("[/OLD LABEL]\n");
  124. return sb.toString();
  125. }
  126. /**
  127. * NO-OP!
  128. */
  129. public void setColumn(short col)
  130. {
  131. }
  132. /**
  133. * NO-OP!
  134. */
  135. public void setRow(int row)
  136. {
  137. }
  138. /**
  139. * no op!
  140. */
  141. public void setXFIndex(short xf)
  142. {
  143. }
  144. }