PageRenderTime 56ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/record/LabelRecord.java

http://github.com/openmicroscopy/bioformats
Java | 311 lines | 162 code | 39 blank | 110 comment | 26 complexity | a265baccf3f0d5435d63ee3f5a389b7b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. /*
  38. * LabelRecord.java
  39. *
  40. * Created on November 11, 2001, 12:51 PM
  41. */
  42. package loci.poi.hssf.record;
  43. /**
  44. * Label Record - read only support for strings stored directly in the cell.. Don't
  45. * use this (except to read), use LabelSST instead <P>
  46. * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  47. * @author Andrew C. Oliver (acoliver at apache dot org)
  48. * @author Jason Height (jheight at chariot dot net dot au)
  49. * @version 2.0-pre
  50. * @see loci.poi.hssf.record.LabelSSTRecord
  51. */
  52. public class LabelRecord
  53. extends Record
  54. implements CellValueRecordInterface
  55. {
  56. public final static short sid = 0x204;
  57. //private short field_1_row;
  58. private int field_1_row;
  59. private short field_2_column;
  60. private short field_3_xf_index;
  61. private short field_4_string_len;
  62. private byte field_5_unicode_flag;
  63. private String field_6_value;
  64. /** Creates new LabelRecord */
  65. public LabelRecord()
  66. {
  67. }
  68. /**
  69. * Constructs an Label record and sets its fields appropriately.
  70. *
  71. * @param in the RecordInputstream to read the record from
  72. */
  73. public LabelRecord(RecordInputStream in)
  74. {
  75. super(in);
  76. }
  77. /**
  78. * called by constructor, should throw runtime exception in the event of a
  79. * record passed with a differing ID.
  80. *
  81. * @param id alleged id for this record
  82. */
  83. protected void validateSid(short id)
  84. {
  85. if (id != sid)
  86. {
  87. throw new RecordFormatException("Not a valid LabelRecord");
  88. }
  89. }
  90. /**
  91. * @param in the RecordInputstream to read the record from
  92. */
  93. protected void fillFields(RecordInputStream in)
  94. {
  95. //field_1_row = LittleEndian.getShort(data, 0 + offset);
  96. field_1_row = in.readUShort();
  97. field_2_column = in.readShort();
  98. field_3_xf_index = in.readShort();
  99. field_4_string_len = in.readShort();
  100. field_5_unicode_flag = in.readByte();
  101. if (field_4_string_len > 0) {
  102. if (isUnCompressedUnicode()) {
  103. field_6_value = in.readUnicodeLEString(field_4_string_len);
  104. } else {
  105. field_6_value = in.readCompressedUnicode(field_4_string_len);
  106. }
  107. } else field_6_value = null;
  108. }
  109. /* READ ONLY ACCESS... THIS IS FOR COMPATIBILITY ONLY...USE LABELSST!
  110. public void setRow(short row) {
  111. field_1_row = row;
  112. }
  113. public void setColumn(short col) {
  114. field_2_column = col;
  115. }
  116. public void setXFIndex(short index) {
  117. field_3_xf_index = index;
  118. }
  119. */
  120. //public short getRow()
  121. public int getRow()
  122. {
  123. return field_1_row;
  124. }
  125. public short getColumn()
  126. {
  127. return field_2_column;
  128. }
  129. public short getXFIndex()
  130. {
  131. return field_3_xf_index;
  132. }
  133. /**
  134. * get the number of characters this string contains
  135. * @return number of characters
  136. */
  137. public short getStringLength()
  138. {
  139. return field_4_string_len;
  140. }
  141. /**
  142. * is this uncompressed unicode (16bit)? Or just 8-bit compressed?
  143. * @return isUnicode - True for 16bit- false for 8bit
  144. */
  145. public boolean isUnCompressedUnicode()
  146. {
  147. return (field_5_unicode_flag == 1);
  148. }
  149. /**
  150. * get the value
  151. *
  152. * @return the text string
  153. * @see #getStringLength()
  154. */
  155. public String getValue()
  156. {
  157. return field_6_value;
  158. }
  159. /**
  160. * THROWS A RUNTIME EXCEPTION.. USE LABELSSTRecords. YOU HAVE NO REASON to use LABELRecord!!
  161. */
  162. public int serialize(int offset, byte [] data)
  163. {
  164. throw new RecordFormatException(
  165. "Label Records are supported READ ONLY...convert to LabelSST");
  166. }
  167. public short getSid()
  168. {
  169. return sid;
  170. }
  171. public String toString()
  172. {
  173. StringBuffer buffer = new StringBuffer();
  174. buffer.append("[LABEL]\n");
  175. buffer.append(" .row = ")
  176. .append(Integer.toHexString(getRow())).append("\n");
  177. buffer.append(" .column = ")
  178. .append(Integer.toHexString(getColumn())).append("\n");
  179. buffer.append(" .xfindex = ")
  180. .append(Integer.toHexString(getXFIndex())).append("\n");
  181. buffer.append(" .string_len = ")
  182. .append(Integer.toHexString(field_4_string_len)).append("\n");
  183. buffer.append(" .unicode_flag = ")
  184. .append(Integer.toHexString(field_5_unicode_flag)).append("\n");
  185. buffer.append(" .value = ")
  186. .append(getValue()).append("\n");
  187. buffer.append("[/LABEL]\n");
  188. return buffer.toString();
  189. }
  190. public boolean isBefore(CellValueRecordInterface i)
  191. {
  192. if (this.getRow() > i.getRow())
  193. {
  194. return false;
  195. }
  196. if ((this.getRow() == i.getRow())
  197. && (this.getColumn() > i.getColumn()))
  198. {
  199. return false;
  200. }
  201. if ((this.getRow() == i.getRow())
  202. && (this.getColumn() == i.getColumn()))
  203. {
  204. return false;
  205. }
  206. return true;
  207. }
  208. public boolean isAfter(CellValueRecordInterface i)
  209. {
  210. if (this.getRow() < i.getRow())
  211. {
  212. return false;
  213. }
  214. if ((this.getRow() == i.getRow())
  215. && (this.getColumn() < i.getColumn()))
  216. {
  217. return false;
  218. }
  219. if ((this.getRow() == i.getRow())
  220. && (this.getColumn() == i.getColumn()))
  221. {
  222. return false;
  223. }
  224. return true;
  225. }
  226. public boolean isEqual(CellValueRecordInterface i)
  227. {
  228. return ((this.getRow() == i.getRow())
  229. && (this.getColumn() == i.getColumn()));
  230. }
  231. public boolean isInValueSection()
  232. {
  233. return true;
  234. }
  235. public boolean isValue()
  236. {
  237. return true;
  238. }
  239. /**
  240. * NO-OP!
  241. */
  242. public void setColumn(short col)
  243. {
  244. }
  245. /**
  246. * NO-OP!
  247. */
  248. //public void setRow(short row)
  249. public void setRow(int row)
  250. {
  251. }
  252. /**
  253. * no op!
  254. */
  255. public void setXFIndex(short xf)
  256. {
  257. }
  258. public Object clone() {
  259. LabelRecord rec = new LabelRecord();
  260. rec.field_1_row = field_1_row;
  261. rec.field_2_column = field_2_column;
  262. rec.field_3_xf_index = field_3_xf_index;
  263. rec.field_4_string_len = field_4_string_len;
  264. rec.field_5_unicode_flag = field_5_unicode_flag;
  265. rec.field_6_value = field_6_value;
  266. return rec;
  267. }
  268. }