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.

TextProp.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.hslf.model.textproperties;
  16. /**
  17. * Definition of a property of some text, or its paragraph. Defines
  18. * how to find out if it's present (via the mask on the paragraph or
  19. * character "contains" header field), how long the value of it is,
  20. * and how to get and set the value.
  21. *
  22. * As the exact form of these (such as mask value, size of data
  23. * block etc) is different for StyleTextProps and
  24. * TxMasterTextProps, the definitions of the standard
  25. * TextProps is stored in the different record classes
  26. */
  27. public class TextProp implements Cloneable {
  28. protected int sizeOfDataBlock; // Number of bytes the data part uses
  29. protected String propName;
  30. protected int dataValue;
  31. protected int maskInHeader;
  32. /**
  33. * Generate the definition of a given type of text property.
  34. */
  35. public TextProp(int sizeOfDataBlock, int maskInHeader, String propName) {
  36. this.sizeOfDataBlock = sizeOfDataBlock;
  37. this.maskInHeader = maskInHeader;
  38. this.propName = propName;
  39. this.dataValue = 0;
  40. }
  41. /**
  42. * Clones the property
  43. */
  44. public TextProp(TextProp other) {
  45. this.sizeOfDataBlock = other.sizeOfDataBlock;
  46. this.maskInHeader = other.maskInHeader;
  47. this.propName = other.propName;
  48. this.dataValue = other.dataValue;
  49. }
  50. /**
  51. * Name of the text property
  52. */
  53. public String getName() { return propName; }
  54. /**
  55. * Size of the data section of the text property (2 or 4 bytes)
  56. */
  57. public int getSize() { return sizeOfDataBlock; }
  58. /**
  59. * Mask in the paragraph or character "contains" header field
  60. * that indicates that this text property is present.
  61. */
  62. public int getMask() { return maskInHeader; }
  63. /**
  64. * Get the mask that's used at write time. Only differs from
  65. * the result of getMask() for the mask based properties
  66. */
  67. public int getWriteMask() { return getMask(); }
  68. /**
  69. * Fetch the value of the text property (meaning is specific to
  70. * each different kind of text property)
  71. */
  72. public int getValue() { return dataValue; }
  73. /**
  74. * Set the value of the text property.
  75. */
  76. public void setValue(int val) { dataValue = val; }
  77. /**
  78. * Clone, eg when you want to actually make use of one of these.
  79. */
  80. @Override
  81. public TextProp clone(){
  82. try {
  83. return (TextProp)super.clone();
  84. } catch(CloneNotSupportedException e) {
  85. throw new InternalError(e.getMessage());
  86. }
  87. }
  88. @Override
  89. public int hashCode() {
  90. final int prime = 31;
  91. int result = 1;
  92. result = prime * result + dataValue;
  93. result = prime * result + maskInHeader;
  94. result = prime * result + ((propName == null) ? 0 : propName.hashCode());
  95. result = prime * result + sizeOfDataBlock;
  96. return result;
  97. }
  98. @Override
  99. public boolean equals(Object obj) {
  100. if (this == obj) return true;
  101. if (obj == null) return false;
  102. if (getClass() != obj.getClass()) return false;
  103. TextProp other = (TextProp) obj;
  104. if (dataValue != other.dataValue) return false;
  105. if (maskInHeader != other.maskInHeader) return false;
  106. if (propName == null) {
  107. if (other.propName != null) return false;
  108. } else if (!propName.equals(other.propName)) return false;
  109. if (sizeOfDataBlock != other.sizeOfDataBlock) return false;
  110. return true;
  111. }
  112. @Override
  113. public String toString() {
  114. int len;
  115. switch (sizeOfDataBlock) {
  116. case 1: len = 4; break;
  117. case 2: len = 6; break;
  118. default: len = 10; break;
  119. }
  120. return String.format("%s = %d (%0#"+len+"X mask / %d bytes)", propName, dataValue, maskInHeader, sizeOfDataBlock);
  121. }
  122. }