FileDocCategorySizeDatePackage
SprmOperation.javaAPI DocApache Poi 3.0.14333Mon Jan 01 18:55:34 GMT 2007org.apache.poi.hwpf.sprm

SprmOperation

public class SprmOperation extends Object
This class is used to represent a sprm operation from a Word 97/2000/XP document.
author
Ryan Ackley
version
1.0

Fields Summary
private static final BitField
OP_BITFIELD
private static final BitField
SPECIAL_BITFIELD
private static final BitField
TYPE_BITFIELD
private static final BitField
SIZECODE_BITFIELD
private static final short
LONG_SPRM_TABLE
private static final short
LONG_SPRM_PARAGRAPH
public static final int
PAP_TYPE
public static final int
TAP_TYPE
private int
_type
private int
_operation
private int
_gOffset
private byte[]
_grpprl
private int
_sizeCode
private int
_size
Constructors Summary
public SprmOperation(byte[] grpprl, int offset)


      
  
    _grpprl = grpprl;

    short sprmStart = LittleEndian.getShort(grpprl, offset);

    _gOffset = offset + 2;

    _operation = OP_BITFIELD.getValue(sprmStart);
    _type = TYPE_BITFIELD.getValue(sprmStart);
    _sizeCode = SIZECODE_BITFIELD.getValue(sprmStart);
    _size = initSize(sprmStart);
  
Methods Summary
public byte[]getGrpprl()

    return _grpprl;
  
public intgetGrpprlOffset()

    return _gOffset;
  
public intgetOperand()

    switch (_sizeCode)
    {
      case 0:
      case 1:
        return _grpprl[_gOffset];
      case 2:
      case 4:
      case 5:
        return LittleEndian.getShort(_grpprl, _gOffset);
      case 3:
        return LittleEndian.getInt(_grpprl, _gOffset);
      case 6:
        throw new UnsupportedOperationException("This SPRM contains a variable length operand");
      case 7:
        byte threeByteInt[] = new byte[4];
        threeByteInt[0] = _grpprl[_gOffset];
        threeByteInt[1] = _grpprl[_gOffset + 1];
        threeByteInt[2] = _grpprl[_gOffset + 2];
        threeByteInt[3] = (byte)0;
        return LittleEndian.getInt(threeByteInt, 0);
      default:
        throw new IllegalArgumentException("SPRM contains an invalid size code");
    }
  
public intgetOperation()

    return _operation;
  
public static intgetOperationFromOpcode(short opcode)

    return OP_BITFIELD.getValue(opcode);
  
public intgetSizeCode()

    return _sizeCode;
  
public intgetType()

    return _type;
  
public static intgetTypeFromOpcode(short opcode)

    return TYPE_BITFIELD.getValue(opcode);
  
private intinitSize(short sprm)

    switch (_sizeCode)
    {
      case 0:
      case 1:
        return 3;
      case 2:
      case 4:
      case 5:
        return 4;
      case 3:
        return 6;
      case 6:
        if (sprm == LONG_SPRM_TABLE || sprm == LONG_SPRM_PARAGRAPH)
        {
          int retVal = (0x0000ffff & LittleEndian.getShort(_grpprl, _gOffset)) + 3;
          _gOffset += 2;
          return retVal;
        }
        else
        {
          return (0x000000ff & _grpprl[_gOffset++]) + 3;
        }
      case 7:
        return 5;
      default:
        throw new IllegalArgumentException("SPRM contains an invalid size code");
    }
  
public intsize()

    return _size;