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.

UnknownRecord.java 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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.hssf.record.aggregates.PageSettingsBlock;
  17. import org.apache.poi.util.HexDump;
  18. import org.apache.poi.util.LittleEndianOutput;
  19. /**
  20. * Title: Unknown Record (for debugging)<p/>
  21. * Description: Unknown record just tells you the sid so you can figure out
  22. * what records you are missing. Also helps us read/modify sheets we
  23. * don't know all the records to. (HSSF leaves these alone!) <p/>
  24. * Company: SuperLink Software, Inc.<P>
  25. * @author Andrew C. Oliver (acoliver at apache dot org)
  26. * @author Jason Height (jheight at chariot dot net dot au)
  27. * @author Glen Stampoultzis (glens at apache.org)
  28. */
  29. public final class UnknownRecord extends StandardRecord {
  30. /*
  31. * Some Record IDs used by POI as 'milestones' in the record stream
  32. */
  33. /**
  34. * seems to be part of the {@link PageSettingsBlock}. Not interpreted by POI.
  35. * The name 'PRINTSIZE' was taken from OOO source.<br/>
  36. * The few POI test samples with this record have data { 0x03, 0x00 }.
  37. */
  38. public static final int PRINTSIZE_0033 = 0x0033;
  39. /**
  40. * Environment-Specific Print Record
  41. */
  42. public static final int PLS_004D = 0x004D;
  43. public static final int SHEETPR_0081 = 0x0081;
  44. public static final int SORT_0090 = 0x0090;
  45. public static final int STANDARDWIDTH_0099 = 0x0099;
  46. public static final int SCL_00A0 = 0x00A0;
  47. public static final int BITMAP_00E9 = 0x00E9;
  48. public static final int PHONETICPR_00EF = 0x00EF;
  49. public static final int LABELRANGES_015F = 0x015F;
  50. public static final int QUICKTIP_0800 = 0x0800;
  51. public static final int SHEETEXT_0862 = 0x0862; // OOO calls this SHEETLAYOUT
  52. public static final int SHEETPROTECTION_0867 = 0x0867;
  53. public static final int HEADER_FOOTER_089C = 0x089C;
  54. public static final int CODENAME_1BA = 0x01BA;
  55. private int _sid;
  56. private byte[] _rawData;
  57. /**
  58. * @param id id of the record -not validated, just stored for serialization
  59. * @param data the data
  60. */
  61. public UnknownRecord(int id, byte[] data) {
  62. _sid = id & 0xFFFF;
  63. _rawData = data;
  64. }
  65. /**
  66. * construct an unknown record. No fields are interpreted and the record will
  67. * be serialized in its original form more or less
  68. * @param in the RecordInputstream to read the record from
  69. */
  70. public UnknownRecord(RecordInputStream in) {
  71. _sid = in.getSid();
  72. _rawData = in.readRemainder();
  73. if (false && getBiffName(_sid) == null) {
  74. // unknown sids in the range 0x0004-0x0013 are probably 'sub-records' of ObjectRecord
  75. // those sids are in a different number space.
  76. // TODO - put unknown OBJ sub-records in a different class
  77. System.out.println("Unknown record 0x" + Integer.toHexString(_sid).toUpperCase());
  78. }
  79. }
  80. /**
  81. * spit the record out AS IS. no interpretation or identification
  82. */
  83. public void serialize(LittleEndianOutput out) {
  84. out.write(_rawData);
  85. }
  86. protected int getDataSize() {
  87. return _rawData.length;
  88. }
  89. /**
  90. * print a sort of string representation ([UNKNOWN RECORD] id = x [/UNKNOWN RECORD])
  91. */
  92. public String toString() {
  93. String biffName = getBiffName(_sid);
  94. if (biffName == null) {
  95. biffName = "UNKNOWNRECORD";
  96. }
  97. StringBuffer sb = new StringBuffer();
  98. sb.append("[").append(biffName).append("] (0x");
  99. sb.append(Integer.toHexString(_sid).toUpperCase() + ")\n");
  100. if (_rawData.length > 0) {
  101. sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
  102. }
  103. sb.append("[/").append(biffName).append("]\n");
  104. return sb.toString();
  105. }
  106. public short getSid() {
  107. return (short) _sid;
  108. }
  109. /**
  110. * These BIFF record types are known but still uninterpreted by POI
  111. *
  112. * @return the documented name of this BIFF record type, <code>null</code> if unknown to POI
  113. */
  114. public static String getBiffName(int sid) {
  115. // Note to POI developers:
  116. // Make sure you delete the corresponding entry from
  117. // this method any time a new Record subclass is created.
  118. switch (sid) {
  119. case PRINTSIZE_0033: return "PRINTSIZE";
  120. case PLS_004D: return "PLS";
  121. case 0x0050: return "DCON"; // Data Consolidation Information
  122. case 0x007F: return "IMDATA";
  123. case SHEETPR_0081: return "SHEETPR";
  124. case SORT_0090: return "SORT"; // Sorting Options
  125. case 0x0094: return "LHRECORD"; // .WK? File Conversion Information
  126. case STANDARDWIDTH_0099: return "STANDARDWIDTH"; //Standard Column Width
  127. case SCL_00A0: return "SCL"; // Window Zoom Magnification
  128. case 0x00AE: return "SCENMAN"; // Scenario Output Data
  129. case 0x00B2: return "SXVI"; // (pivot table) View Item
  130. case 0x00B4: return "SXIVD"; // (pivot table) Row/Column Field IDs
  131. case 0x00B5: return "SXLI"; // (pivot table) Line Item Array
  132. case 0x00D3: return "OBPROJ";
  133. case 0x00DC: return "PARAMQRY";
  134. case 0x00DE: return "OLESIZE";
  135. case BITMAP_00E9: return "BITMAP";
  136. case PHONETICPR_00EF: return "PHONETICPR";
  137. case 0x00F1: return "SXEX"; // PivotTable View Extended Information
  138. case LABELRANGES_015F: return "LABELRANGES";
  139. case 0x01BA: return "CODENAME";
  140. case 0x01A9: return "USERBVIEW";
  141. case 0x01AD: return "QSI";
  142. case 0x01C0: return "EXCEL9FILE";
  143. case 0x0802: return "QSISXTAG"; // Pivot Table and Query Table Extensions
  144. case 0x0803: return "DBQUERYEXT";
  145. case 0x0805: return "TXTQUERY";
  146. case 0x0810: return "SXVIEWEX9"; // Pivot Table Extensions
  147. case 0x0812: return "CONTINUEFRT";
  148. case QUICKTIP_0800: return "QUICKTIP";
  149. case SHEETEXT_0862: return "SHEETEXT";
  150. case 0x0863: return "BOOKEXT";
  151. case 0x0864: return "SXADDL"; // Pivot Table Additional Info
  152. case SHEETPROTECTION_0867: return "SHEETPROTECTION";
  153. case 0x086B: return "DATALABEXTCONTENTS";
  154. case 0x086C: return "CELLWATCH";
  155. case 0x0874: return "DROPDOWNOBJIDS";
  156. case 0x0876: return "DCONN";
  157. case 0x087B: return "CFEX";
  158. case 0x087C: return "XFCRC";
  159. case 0x087D: return "XFEXT";
  160. case 0x087F: return "CONTINUEFRT12";
  161. case 0x088B: return "PLV";
  162. case 0x088C: return "COMPAT12";
  163. case 0x088D: return "DXF";
  164. case 0x0892: return "STYLEEXT";
  165. case 0x0896: return "THEME";
  166. case 0x0897: return "GUIDTYPELIB";
  167. case 0x089A: return "MTRSETTINGS";
  168. case 0x089B: return "COMPRESSPICTURES";
  169. case HEADER_FOOTER_089C: return "HEADERFOOTER";
  170. case 0x08A1: return "SHAPEPROPSSTREAM";
  171. case 0x08A3: return "FORCEFULLCALCULATION";
  172. case 0x08A4: return "SHAPEPROPSSTREAM";
  173. case 0x08A5: return "TEXTPROPSSTREAM";
  174. case 0x08A6: return "RICHTEXTSTREAM";
  175. case 0x08C8: return "PLV{Mac Excel}";
  176. }
  177. if (isObservedButUnknown(sid)) {
  178. return "UNKNOWN-" + Integer.toHexString(sid).toUpperCase();
  179. }
  180. return null;
  181. }
  182. /**
  183. * @return <code>true</code> if the unknown record id has been observed in POI unit tests
  184. */
  185. private static boolean isObservedButUnknown(int sid) {
  186. switch (sid) {
  187. case 0x0033:
  188. // contains 2 bytes of data: 0x0001 or 0x0003
  189. case 0x0034:
  190. // Seems to be written by MSAccess
  191. // contains text "[Microsoft JET Created Table]0021010"
  192. // appears after last cell value record and before WINDOW2
  193. case 0x01BD:
  194. case 0x01C2:
  195. // Written by Excel 2007
  196. // rawData is multiple of 12 bytes long
  197. // appears after last cell value record and before WINDOW2 or drawing records
  198. case 0x089D:
  199. case 0x089E:
  200. case 0x08A7:
  201. case 0x1001:
  202. case 0x1006:
  203. case 0x1007:
  204. case 0x1009:
  205. case 0x100A:
  206. case 0x100B:
  207. case 0x100C:
  208. case 0x1014:
  209. case 0x1017:
  210. case 0x1018:
  211. case 0x1019:
  212. case 0x101A:
  213. case 0x101B:
  214. case 0x101D:
  215. case 0x101E:
  216. case 0x101F:
  217. case 0x1020:
  218. case 0x1021:
  219. case 0x1022:
  220. case 0x1024:
  221. case 0x1025:
  222. case 0x1026:
  223. case 0x1027:
  224. case 0x1032:
  225. case 0x1033:
  226. case 0x1034:
  227. case 0x1035:
  228. case 0x103A:
  229. case 0x1041:
  230. case 0x1043:
  231. case 0x1044:
  232. case 0x1045:
  233. case 0x1046:
  234. case 0x104A:
  235. case 0x104B:
  236. case 0x104E:
  237. case 0x104F:
  238. case 0x1051:
  239. case 0x105C:
  240. case 0x105D:
  241. case 0x105F:
  242. case 0x1060:
  243. case 0x1062:
  244. case 0x1063:
  245. case 0x1064:
  246. case 0x1065:
  247. case 0x1066:
  248. return true;
  249. }
  250. return false;
  251. }
  252. public Object clone() {
  253. // immutable - OK to return this
  254. return this;
  255. }
  256. }