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.

LabelRecord.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. * Label Record (0x0204) - read only support for strings stored directly in the cell.. Don't
  21. * use this (except to read), use LabelSST instead <P>
  22. * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  23. * @author Andrew C. Oliver (acoliver at apache dot org)
  24. * @author Jason Height (jheight at chariot dot net dot au)
  25. * @version 2.0-pre
  26. * @see org.apache.poi.hssf.record.LabelSSTRecord
  27. */
  28. public final class LabelRecord extends Record implements CellValueRecordInterface {
  29. private final static POILogger logger = POILogFactory.getLogger(LabelRecord.class);
  30. public final static short sid = 0x0204;
  31. private int field_1_row;
  32. private short field_2_column;
  33. private short field_3_xf_index;
  34. private short field_4_string_len;
  35. private byte field_5_unicode_flag;
  36. private String field_6_value;
  37. /** Creates new LabelRecord */
  38. public LabelRecord()
  39. {
  40. }
  41. /**
  42. * @param in the RecordInputstream to read the record from
  43. */
  44. public LabelRecord(RecordInputStream in)
  45. {
  46. field_1_row = in.readUShort();
  47. field_2_column = in.readShort();
  48. field_3_xf_index = in.readShort();
  49. field_4_string_len = in.readShort();
  50. field_5_unicode_flag = in.readByte();
  51. if (field_4_string_len > 0) {
  52. if (isUnCompressedUnicode()) {
  53. field_6_value = in.readUnicodeLEString(field_4_string_len);
  54. } else {
  55. field_6_value = in.readCompressedUnicode(field_4_string_len);
  56. }
  57. } else {
  58. field_6_value = "";
  59. }
  60. if (in.remaining() > 0) {
  61. logger.log(POILogger.INFO,
  62. "LabelRecord data remains: " + in.remaining() +
  63. " : " + HexDump.toHex(in.readRemainder())
  64. );
  65. }
  66. }
  67. /*
  68. * READ ONLY ACCESS... THIS IS FOR COMPATIBILITY ONLY...USE LABELSST! public
  69. */
  70. public int getRow()
  71. {
  72. return field_1_row;
  73. }
  74. public short getColumn()
  75. {
  76. return field_2_column;
  77. }
  78. public short getXFIndex()
  79. {
  80. return field_3_xf_index;
  81. }
  82. /**
  83. * get the number of characters this string contains
  84. * @return number of characters
  85. */
  86. public short getStringLength()
  87. {
  88. return field_4_string_len;
  89. }
  90. /**
  91. * is this uncompressed unicode (16bit)? Or just 8-bit compressed?
  92. * @return isUnicode - True for 16bit- false for 8bit
  93. */
  94. public boolean isUnCompressedUnicode()
  95. {
  96. return (field_5_unicode_flag & 0x01) != 0;
  97. }
  98. /**
  99. * get the value
  100. *
  101. * @return the text string
  102. * @see #getStringLength()
  103. */
  104. public String getValue()
  105. {
  106. return field_6_value;
  107. }
  108. /**
  109. * THROWS A RUNTIME EXCEPTION.. USE LABELSSTRecords. YOU HAVE NO REASON to use LABELRecord!!
  110. */
  111. public int serialize(int offset, byte [] data) {
  112. throw new RecordFormatException("Label Records are supported READ ONLY...convert to LabelSST");
  113. }
  114. public int getRecordSize() {
  115. throw new RecordFormatException("Label Records are supported READ ONLY...convert to LabelSST");
  116. }
  117. public short getSid()
  118. {
  119. return sid;
  120. }
  121. public String toString()
  122. {
  123. StringBuffer sb = new StringBuffer();
  124. sb.append("[LABEL]\n");
  125. sb.append(" .row = ").append(HexDump.shortToHex(getRow())).append("\n");
  126. sb.append(" .column = ").append(HexDump.shortToHex(getColumn())).append("\n");
  127. sb.append(" .xfindex = ").append(HexDump.shortToHex(getXFIndex())).append("\n");
  128. sb.append(" .string_len= ").append(HexDump.shortToHex(field_4_string_len)).append("\n");
  129. sb.append(" .unicode_flag= ").append(HexDump.byteToHex(field_5_unicode_flag)).append("\n");
  130. sb.append(" .value = ").append(getValue()).append("\n");
  131. sb.append("[/LABEL]\n");
  132. return sb.toString();
  133. }
  134. /**
  135. * NO-OP!
  136. */
  137. public void setColumn(short col)
  138. {
  139. }
  140. /**
  141. * NO-OP!
  142. */
  143. public void setRow(int row)
  144. {
  145. }
  146. /**
  147. * no op!
  148. */
  149. public void setXFIndex(short xf)
  150. {
  151. }
  152. public Object clone() {
  153. LabelRecord rec = new LabelRecord();
  154. rec.field_1_row = field_1_row;
  155. rec.field_2_column = field_2_column;
  156. rec.field_3_xf_index = field_3_xf_index;
  157. rec.field_4_string_len = field_4_string_len;
  158. rec.field_5_unicode_flag = field_5_unicode_flag;
  159. rec.field_6_value = field_6_value;
  160. return rec;
  161. }
  162. }