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.

ListFormatOverrideLevel.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.hwpf.model;
  16. import java.util.Objects;
  17. import org.apache.poi.hwpf.model.types.LFOLVLBaseAbstractType;
  18. import org.apache.poi.util.Internal;
  19. /**
  20. * The LFOLVL structure contains information that is used to override the
  21. * formatting information of a corresponding LVL.
  22. * <p>
  23. * Class and fields descriptions are quoted from Microsoft Office Word 97-2007
  24. * Binary File Format and [MS-DOC] - v20110608 Word (.doc) Binary File Format
  25. */
  26. @Internal
  27. public final class ListFormatOverrideLevel
  28. {
  29. private LFOLVLBase _base;
  30. private ListLevel _lvl;
  31. public ListFormatOverrideLevel( byte[] buf, int offset )
  32. {
  33. _base = new LFOLVLBase( buf, offset );
  34. offset += LFOLVLBaseAbstractType.getSize();
  35. if ( _base.isFFormatting() )
  36. {
  37. _lvl = new ListLevel( buf, offset );
  38. }
  39. }
  40. public boolean equals( Object obj )
  41. {
  42. if (!(obj instanceof ListFormatOverrideLevel)) return false;
  43. ListFormatOverrideLevel lfolvl = (ListFormatOverrideLevel) obj;
  44. boolean lvlEquality = false;
  45. if ( _lvl != null )
  46. {
  47. lvlEquality = _lvl.equals( lfolvl._lvl );
  48. }
  49. else
  50. {
  51. lvlEquality = lfolvl._lvl == null;
  52. }
  53. return lvlEquality && lfolvl._base.equals( _base );
  54. }
  55. public int getIStartAt()
  56. {
  57. return _base.getIStartAt();
  58. }
  59. public ListLevel getLevel()
  60. {
  61. return _lvl;
  62. }
  63. public int getLevelNum()
  64. {
  65. return _base.getILvl();
  66. }
  67. public int getSizeInBytes()
  68. {
  69. return _lvl == null ? LFOLVLBaseAbstractType.getSize() : LFOLVLBaseAbstractType.getSize()
  70. + _lvl.getSizeInBytes();
  71. }
  72. @Override
  73. public int hashCode() {
  74. return Objects.hash(_base,_lvl);
  75. }
  76. public boolean isFormatting()
  77. {
  78. return _base.isFFormatting();
  79. }
  80. public boolean isStartAt()
  81. {
  82. return _base.isFStartAt();
  83. }
  84. public byte[] toByteArray()
  85. {
  86. int offset = 0;
  87. byte[] buf = new byte[getSizeInBytes()];
  88. _base.serialize( buf, offset );
  89. offset += LFOLVLBaseAbstractType.getSize();
  90. if ( _lvl != null )
  91. {
  92. byte[] levelBuf = _lvl.toByteArray();
  93. System.arraycopy( levelBuf, 0, buf, offset, levelBuf.length );
  94. }
  95. return buf;
  96. }
  97. }