add ProperyModifier (PRM) field to PieceDescriptor (PD)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1145409 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-07-12 00:39:53 +00:00
parent 6d3bd4e5b4
commit 5fb7c13c38
2 changed files with 137 additions and 5 deletions

View File

@ -29,7 +29,7 @@ public final class PieceDescriptor
private static BitField fPaphNil = BitFieldFactory.getInstance(0x02);
private static BitField fCopied = BitFieldFactory.getInstance(0x04);
int fc;
short prm;
PropertyModifier prm;
boolean unicode;
@ -39,7 +39,7 @@ public final class PieceDescriptor
offset += LittleEndian.SHORT_SIZE;
fc = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
prm = LittleEndian.getShort(buf, offset);
prm = new PropertyModifier( LittleEndian.getShort(buf, offset));
// see if this piece uses unicode.
if ((fc & 0x40000000) == 0)
@ -70,6 +70,11 @@ public final class PieceDescriptor
return unicode;
}
public PropertyModifier getPrm()
{
return prm;
}
protected byte[] toByteArray()
{
// set up the fc
@ -86,7 +91,7 @@ public final class PieceDescriptor
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putInt(buf, offset, tempFc);
offset += LittleEndian.INT_SIZE;
LittleEndian.putShort(buf, offset, prm);
LittleEndian.putShort(buf, offset, prm.getValue());
return buf;
@ -103,7 +108,7 @@ public final class PieceDescriptor
final int prime = 31;
int result = 1;
result = prime * result + descriptor;
result = prime * result + prm;
result = prime * result + prm.getValue();
result = prime * result + ( unicode ? 1231 : 1237 );
return result;
}
@ -131,6 +136,7 @@ public final class PieceDescriptor
public String toString()
{
return "PieceDescriptor (pos: " + getFilePosition() + "; "
+ ( isUnicode() ? "unicode" : "non-unicode" ) + ")";
+ ( isUnicode() ? "unicode" : "non-unicode" ) + "; prm: "
+ getPrm() + ")";
}
}

View File

@ -0,0 +1,126 @@
package org.apache.poi.hwpf.model;
import org.apache.poi.util.BitField;
public final class PropertyModifier implements Cloneable
{
/**
* <li>"Set to 0 for variant 1" <li>"Set to 1 for variant 2"
*/
private static BitField _fComplex = new BitField( 0x0001 );
/**
* "Index to a grpprl stored in CLX portion of file"
*/
private static BitField _figrpprl = new BitField( 0xfffe );
/**
* "Index to entry into rgsprmPrm"
*/
private static BitField _fisprm = new BitField( 0x00fe );
/**
* "sprm's operand"
*/
private static BitField _fval = new BitField( 0xff00 );
private short value;
public PropertyModifier( short value )
{
this.value = value;
}
@Override
protected PropertyModifier clone() throws CloneNotSupportedException
{
return new PropertyModifier( value );
}
@Override
public boolean equals( Object obj )
{
if ( this == obj )
return true;
if ( obj == null )
return false;
if ( getClass() != obj.getClass() )
return false;
PropertyModifier other = (PropertyModifier) obj;
if ( value != other.value )
return false;
return true;
}
/**
* "Index to a grpprl stored in CLX portion of file"
*/
public short getIgrpprl()
{
if ( !isComplex() )
throw new IllegalStateException( "Not complex" );
return _figrpprl.getShortValue( value );
}
public short getIsprm()
{
if ( isComplex() )
throw new IllegalStateException( "Not simple" );
return _fisprm.getShortValue( value );
}
public short getVal()
{
if ( isComplex() )
throw new IllegalStateException( "Not simple" );
return _fval.getShortValue( value );
}
public short getValue()
{
return value;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + value;
return result;
}
public boolean isComplex()
{
return _fComplex.isSet( value );
}
@Override
public String toString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append( "[PRM] (complex: " );
stringBuilder.append( isComplex() );
stringBuilder.append( "; " );
if ( isComplex() )
{
stringBuilder.append( "igrpprl: " );
stringBuilder.append( getIgrpprl() );
stringBuilder.append( "; " );
}
else
{
stringBuilder.append( "isprm: " );
stringBuilder.append( getIsprm() );
stringBuilder.append( "; " );
stringBuilder.append( "val: " );
stringBuilder.append( getVal() );
stringBuilder.append( "; " );
}
stringBuilder.append( ")" );
return stringBuilder.toString();
}
}