Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CAA119976 for ; Wed, 21 Sep 2011 10:01:08 +0000 (UTC) Received: (qmail 1244 invoked by uid 500); 21 Sep 2011 10:01:08 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 1210 invoked by uid 500); 21 Sep 2011 10:01:08 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 1203 invoked by uid 99); 21 Sep 2011 10:01:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Sep 2011 10:01:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Sep 2011 10:01:05 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DDA942388AF0 for ; Wed, 21 Sep 2011 10:00:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1173550 - in /poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model: StdfBase.java StyleDescription.java Date: Wed, 21 Sep 2011 10:00:43 -0000 To: commits@poi.apache.org From: sergey@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20110921100043.DDA942388AF0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergey Date: Wed Sep 21 10:00:43 2011 New Revision: 1173550 URL: http://svn.apache.org/viewvc?rev=1173550&view=rev Log: use StdfBase structure in StyleDescription Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StdfBase.java Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StdfBase.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StdfBase.java?rev=1173550&view=auto ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StdfBase.java (added) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StdfBase.java Wed Sep 21 10:00:43 2011 @@ -0,0 +1,78 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.hwpf.model; + +import org.apache.poi.hwpf.model.types.StdfBaseAbstractType; + +/** + * The StdfBase structure specifies general information about a style. + */ +public class StdfBase extends StdfBaseAbstractType +{ + + public StdfBase() + { + } + + public StdfBase( byte[] std, int offset ) + { + fillFields( std, offset ); + } + + @Override + public boolean equals( Object obj ) + { + if ( this == obj ) + return true; + if ( obj == null ) + return false; + if ( getClass() != obj.getClass() ) + return false; + StdfBase other = (StdfBase) obj; + if ( field_1_info1 != other.field_1_info1 ) + return false; + if ( field_2_info2 != other.field_2_info2 ) + return false; + if ( field_3_info3 != other.field_3_info3 ) + return false; + if ( field_4_bchUpe != other.field_4_bchUpe ) + return false; + if ( field_5_grfstd != other.field_5_grfstd ) + return false; + return true; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + field_1_info1; + result = prime * result + field_2_info2; + result = prime * result + field_3_info3; + result = prime * result + field_4_bchUpe; + result = prime * result + field_5_grfstd; + return result; + } + + public byte[] serialize() + { + byte[] result = new byte[getSize()]; + serialize( result, 0 ); + return result; + } +} Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java?rev=1173550&r1=1173549&r2=1173550&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java Wed Sep 21 10:00:43 2011 @@ -22,10 +22,9 @@ import java.util.Arrays; import org.apache.poi.hwpf.usermodel.CharacterProperties; import org.apache.poi.hwpf.usermodel.ParagraphProperties; -import org.apache.poi.util.BitField; -import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; + /** * Comment me * @@ -37,25 +36,11 @@ public final class StyleDescription impl private final static int PARAGRAPH_STYLE = 1; private final static int CHARACTER_STYLE = 2; + private final static int TABLE_STYLE = 3; + private final static int NUMBERING_STYLE = 4; - private int _istd; private int _baseLength; - private short _infoShort; - private static BitField _sti = BitFieldFactory.getInstance(0xfff); - private static BitField _fScratch = BitFieldFactory.getInstance(0x1000); - private static BitField _fInvalHeight = BitFieldFactory.getInstance(0x2000); - private static BitField _fHasUpe = BitFieldFactory.getInstance(0x4000); - private static BitField _fMassCopy = BitFieldFactory.getInstance(0x8000); - private short _infoShort2; - private static BitField _styleTypeCode = BitFieldFactory.getInstance(0xf); - private static BitField _baseStyle = BitFieldFactory.getInstance(0xfff0); - private short _infoShort3; - private static BitField _numUPX = BitFieldFactory.getInstance(0xf); - private static BitField _nextStyle = BitFieldFactory.getInstance(0xfff0); - private short _bchUpe; - private short _infoShort4; - private static BitField _fAutoRedef = BitFieldFactory.getInstance(0x1); - private static BitField _fHidden = BitFieldFactory.getInstance(0x2); + private StdfBase _stdfBase; UPX[] _upxs; String _name; @@ -71,16 +56,9 @@ public final class StyleDescription impl { _baseLength = baseLength; int nameStart = offset + baseLength; - _infoShort = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; - _infoShort2 = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; - _infoShort3 = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; - _bchUpe = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; - _infoShort4 = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; + + _stdfBase = new StdfBase(std, offset); + offset += StdfBase.getSize(); //first byte(s) of variable length section of std is the length of the //style name and aliases string @@ -112,9 +90,9 @@ public final class StyleDescription impl // the spec only refers to two possible upxs but it mentions // that more may be added in the future int varOffset = grupxStart; - int numUPX = _numUPX.getValue(_infoShort3); - _upxs = new UPX[numUPX]; - for(int x = 0; x < numUPX; x++) + int countOfUPX = _stdfBase.getCupx(); + _upxs = new UPX[countOfUPX]; + for(int x = 0; x < countOfUPX; x++) { int upxSize = LittleEndian.getShort(std, varOffset); varOffset += LittleEndian.SHORT_SIZE; @@ -137,11 +115,11 @@ public final class StyleDescription impl } public int getBaseStyle() { - return _baseStyle.getValue(_infoShort2); + return _stdfBase.getIstdBase(); } public byte[] getCHPX() { - switch (_styleTypeCode.getValue(_infoShort2)) + switch (_stdfBase.getStk()) { case PARAGRAPH_STYLE: if (_upxs.length > 1) @@ -158,7 +136,7 @@ public final class StyleDescription impl } public byte[] getPAPX() { - switch (_styleTypeCode.getValue(_infoShort2)) + switch (_stdfBase.getStk()) { case PARAGRAPH_STYLE: return _upxs[0].getUPX(); @@ -206,18 +184,9 @@ public final class StyleDescription impl byte[] buf = new byte[size]; + _stdfBase.serialize( buf, 0 ); - int offset = 0; - LittleEndian.putShort(buf, offset, _infoShort); - offset += LittleEndian.SHORT_SIZE; - LittleEndian.putShort(buf, offset, _infoShort2); - offset += LittleEndian.SHORT_SIZE; - LittleEndian.putShort(buf, offset, _infoShort3); - offset += LittleEndian.SHORT_SIZE; - LittleEndian.putShort(buf, offset, _bchUpe); - offset += LittleEndian.SHORT_SIZE; - LittleEndian.putShort(buf, offset, _infoShort4); - offset = _baseLength; + int offset = _baseLength; char[] letters = _name.toCharArray(); LittleEndian.putShort(buf, _baseLength, (short)letters.length); @@ -242,21 +211,44 @@ public final class StyleDescription impl return buf; } - public boolean equals(Object o) - { - StyleDescription sd = (StyleDescription)o; - if (sd._infoShort == _infoShort && sd._infoShort2 == _infoShort2 && - sd._infoShort3 == _infoShort3 && sd._bchUpe == _bchUpe && - sd._infoShort4 == _infoShort4 && - _name.equals(sd._name)) + @Override + public int hashCode() { - - if (!Arrays.equals(_upxs, sd._upxs)) - { - return false; - } - return true; + final int prime = 31; + int result = 1; + result = prime * result + ( ( _name == null ) ? 0 : _name.hashCode() ); + result = prime * result + + ( ( _stdfBase == null ) ? 0 : _stdfBase.hashCode() ); + result = prime * result + Arrays.hashCode( _upxs ); + return result; + } + + @Override + public boolean equals( Object obj ) + { + if ( this == obj ) + return true; + if ( obj == null ) + return false; + if ( getClass() != obj.getClass() ) + return false; + StyleDescription other = (StyleDescription) obj; + if ( _name == null ) + { + if ( other._name != null ) + return false; + } + else if ( !_name.equals( other._name ) ) + return false; + if ( _stdfBase == null ) + { + if ( other._stdfBase != null ) + return false; + } + else if ( !_stdfBase.equals( other._stdfBase ) ) + return false; + if ( !Arrays.equals( _upxs, other._upxs ) ) + return false; + return true; } - return false; - } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org