001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hwpf.model;
019:
020: import org.apache.poi.util.LittleEndian;
021: import org.apache.poi.util.BitField;
022: import org.apache.poi.util.BitFieldFactory;
023:
024: import java.util.Arrays;
025:
026: public class ListFormatOverrideLevel {
027: private static final int BASE_SIZE = 8;
028:
029: int _iStartAt;
030: byte _info;
031: private static BitField _ilvl = BitFieldFactory.getInstance(0xf);
032: private static BitField _fStartAt = BitFieldFactory
033: .getInstance(0x10);
034: private static BitField _fFormatting = BitFieldFactory
035: .getInstance(0x20);
036: byte[] _reserved = new byte[3];
037: ListLevel _lvl;
038:
039: public ListFormatOverrideLevel(byte[] buf, int offset) {
040: _iStartAt = LittleEndian.getInt(buf, offset);
041: offset += LittleEndian.INT_SIZE;
042: _info = buf[offset++];
043: System.arraycopy(buf, offset, _reserved, 0, _reserved.length);
044: offset += _reserved.length;
045:
046: if (_fFormatting.getValue(_info) > 0) {
047: _lvl = new ListLevel(buf, offset);
048: }
049: }
050:
051: public ListLevel getLevel() {
052: return _lvl;
053: }
054:
055: public int getLevelNum() {
056: return _ilvl.getValue(_info);
057: }
058:
059: public boolean isFormatting() {
060: return _fFormatting.getValue(_info) != 0;
061: }
062:
063: public boolean isStartAt() {
064: return _fStartAt.getValue(_info) != 0;
065: }
066:
067: public int getSizeInBytes() {
068: return (_lvl == null ? BASE_SIZE : BASE_SIZE
069: + _lvl.getSizeInBytes());
070: }
071:
072: public boolean equals(Object obj) {
073: if (obj == null) {
074: return false;
075: }
076: ListFormatOverrideLevel lfolvl = (ListFormatOverrideLevel) obj;
077: boolean lvlEquality = false;
078: if (_lvl != null) {
079: lvlEquality = _lvl.equals(lfolvl._lvl);
080: } else {
081: lvlEquality = lfolvl._lvl == null;
082: }
083:
084: return lvlEquality && lfolvl._iStartAt == _iStartAt
085: && lfolvl._info == _info
086: && Arrays.equals(lfolvl._reserved, _reserved);
087: }
088:
089: public byte[] toByteArray() {
090: byte[] buf = new byte[getSizeInBytes()];
091:
092: int offset = 0;
093: LittleEndian.putInt(buf, _iStartAt);
094: offset += LittleEndian.INT_SIZE;
095: buf[offset++] = _info;
096: System.arraycopy(_reserved, 0, buf, offset, 3);
097: offset += 3;
098:
099: if (_lvl != null) {
100: byte[] levelBuf = _lvl.toByteArray();
101: System.arraycopy(levelBuf, 0, buf, offset, levelBuf.length);
102: }
103:
104: return buf;
105: }
106: }
|