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.

CodepageRecord.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 java.util.Map;
  17. import java.util.function.Supplier;
  18. import org.apache.poi.util.CodePageUtil;
  19. import org.apache.poi.util.GenericRecordUtil;
  20. import org.apache.poi.util.LittleEndianOutput;
  21. /**
  22. * The default characterset. for the workbook<p>
  23. *
  24. * Use {@link CodePageUtil} to turn these values into Java code pages to encode/decode strings.
  25. *
  26. * @version 2.0-pre
  27. */
  28. public final class CodepageRecord extends StandardRecord {
  29. public static final short sid = 0x42;
  30. /**
  31. * Excel 97+ (Biff 8) should always store strings as UTF-16LE or
  32. * compressed versions of that. As such, this should always be
  33. * 0x4b0 = UTF_16, except for files coming from older versions.
  34. */
  35. public static final short CODEPAGE = ( short ) 0x4b0;
  36. private short field_1_codepage;
  37. public CodepageRecord() {}
  38. public CodepageRecord(CodepageRecord other) {
  39. super(other);
  40. field_1_codepage = other.field_1_codepage;
  41. }
  42. public CodepageRecord(RecordInputStream in) {
  43. field_1_codepage = in.readShort();
  44. }
  45. /**
  46. * set the codepage for this workbook
  47. *
  48. * @see #CODEPAGE
  49. * @param cp the codepage to set
  50. */
  51. public void setCodepage(short cp)
  52. {
  53. field_1_codepage = cp;
  54. }
  55. /**
  56. * get the codepage for this workbook
  57. *
  58. * @see #CODEPAGE
  59. * @return codepage - the codepage to set
  60. */
  61. public short getCodepage()
  62. {
  63. return field_1_codepage;
  64. }
  65. public void serialize(LittleEndianOutput out) {
  66. out.writeShort(getCodepage());
  67. }
  68. protected int getDataSize() {
  69. return 2;
  70. }
  71. public short getSid()
  72. {
  73. return sid;
  74. }
  75. @Override
  76. public CodepageRecord copy() {
  77. return new CodepageRecord(this);
  78. }
  79. @Override
  80. public HSSFRecordTypes getGenericRecordType() {
  81. return HSSFRecordTypes.CODEPAGE;
  82. }
  83. @Override
  84. public Map<String, Supplier<?>> getGenericProperties() {
  85. return GenericRecordUtil.getGenericProperties(
  86. "codepage", this::getCodepage
  87. );
  88. }
  89. }