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.

CountryRecord.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.GenericRecordUtil;
  19. import org.apache.poi.util.LittleEndianOutput;
  20. /**
  21. * Country Record (aka WIN.INI country) - used for localization<p>
  22. *
  23. * Currently HSSF always sets this to 1 and it seems to work fine even in Germany.
  24. *
  25. * @version 2.0-pre
  26. */
  27. public final class CountryRecord extends StandardRecord {
  28. public static final short sid = 0x8c;
  29. // 1 for US
  30. private short field_1_default_country;
  31. private short field_2_current_country;
  32. public CountryRecord() {}
  33. public CountryRecord(CountryRecord other) {
  34. super(other);
  35. field_1_default_country = other.field_1_default_country;
  36. field_2_current_country = other.field_2_current_country;
  37. }
  38. public CountryRecord(RecordInputStream in) {
  39. field_1_default_country = in.readShort();
  40. field_2_current_country = in.readShort();
  41. }
  42. /**
  43. * sets the default country
  44. *
  45. * @param country ID to set (1 = US)
  46. */
  47. public void setDefaultCountry(short country)
  48. {
  49. field_1_default_country = country;
  50. }
  51. /**
  52. * sets the current country
  53. *
  54. * @param country ID to set (1 = US)
  55. */
  56. public void setCurrentCountry(short country)
  57. {
  58. field_2_current_country = country;
  59. }
  60. /**
  61. * gets the default country
  62. *
  63. * @return country ID (1 = US)
  64. */
  65. public short getDefaultCountry()
  66. {
  67. return field_1_default_country;
  68. }
  69. /**
  70. * gets the current country
  71. *
  72. * @return country ID (1 = US)
  73. */
  74. public short getCurrentCountry()
  75. {
  76. return field_2_current_country;
  77. }
  78. public void serialize(LittleEndianOutput out) {
  79. out.writeShort(getDefaultCountry());
  80. out.writeShort(getCurrentCountry());
  81. }
  82. protected int getDataSize() {
  83. return 4;
  84. }
  85. public short getSid()
  86. {
  87. return sid;
  88. }
  89. @Override
  90. public CountryRecord copy() {
  91. return new CountryRecord(this);
  92. }
  93. @Override
  94. public HSSFRecordTypes getGenericRecordType() {
  95. return HSSFRecordTypes.COUNTRY;
  96. }
  97. @Override
  98. public Map<String, Supplier<?>> getGenericProperties() {
  99. return GenericRecordUtil.getGenericProperties(
  100. "defaultCountry", this::getDefaultCountry,
  101. "currentCountry", this::getCurrentCountry
  102. );
  103. }
  104. }