Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CustomProperty.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.hpsf;
  16. /**
  17. * <p>This class represents custom properties in the document summary
  18. * information stream. The difference to normal properties is that custom
  19. * properties have an optional name. If the name is not <code>null</code> it
  20. * will be maintained in the section's dictionary.</p>
  21. *
  22. * @author Rainer Klute <a
  23. * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
  24. */
  25. public class CustomProperty extends MutableProperty
  26. {
  27. private String name;
  28. /**
  29. * <p>Creates an empty {@link CustomProperty}. The set methods must be
  30. * called to make it usable.</p>
  31. */
  32. public CustomProperty()
  33. {
  34. this.name = null;
  35. }
  36. /**
  37. * <p>Creates a {@link CustomProperty} without a name by copying the
  38. * underlying {@link Property}' attributes.</p>
  39. *
  40. * @param property the property to copy
  41. */
  42. public CustomProperty(final Property property)
  43. {
  44. this(property, null);
  45. }
  46. /**
  47. * <p>Creates a {@link CustomProperty} with a name.</p>
  48. *
  49. * @param property This property's attributes are copied to the new custom
  50. * property.
  51. * @param name The new custom property's name.
  52. */
  53. public CustomProperty(final Property property, final String name)
  54. {
  55. super(property);
  56. this.name = name;
  57. }
  58. /**
  59. * <p>Gets the property's name.</p>
  60. *
  61. * @return the property's name.
  62. */
  63. public String getName()
  64. {
  65. return name;
  66. }
  67. /**
  68. * <p>Sets the property's name.</p>
  69. *
  70. * @param name The name to set.
  71. */
  72. public void setName(final String name)
  73. {
  74. this.name = name;
  75. }
  76. /**
  77. * <p>Compares two custom properties for equality. The method returns
  78. * <code>true</code> if all attributes of the two custom properties are
  79. * equal.</p>
  80. *
  81. * @param o The custom property to compare with.
  82. * @return <code>true</code> if both custom properties are equal, else
  83. * <code>false</code>.
  84. *
  85. * @see java.util.AbstractSet#equals(java.lang.Object)
  86. */
  87. public boolean equalsContents(final Object o)
  88. {
  89. final CustomProperty c = (CustomProperty) o;
  90. final String name1 = c.getName();
  91. final String name2 = this.getName();
  92. boolean equalNames = true;
  93. if (name1 == null)
  94. equalNames = name2 == null;
  95. else
  96. equalNames = name1.equals(name2);
  97. return equalNames && c.getID() == this.getID()
  98. && c.getType() == this.getType()
  99. && c.getValue().equals(this.getValue());
  100. }
  101. /**
  102. * @see java.util.AbstractSet#hashCode()
  103. */
  104. public int hashCode()
  105. {
  106. return (int) this.getID();
  107. }
  108. }