]> source.dussan.org Git - poi.git/commitdiff
add ProperyModifier (PRM) field to PieceDescriptor (PD)
authorSergey Vladimirov <sergey@apache.org>
Tue, 12 Jul 2011 00:39:53 +0000 (00:39 +0000)
committerSergey Vladimirov <sergey@apache.org>
Tue, 12 Jul 2011 00:39:53 +0000 (00:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1145409 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/PieceDescriptor.java
src/scratchpad/src/org/apache/poi/hwpf/model/PropertyModifier.java [new file with mode: 0644]

index 5d3c50911b697bf108c00d0d310908f5dadbc92a..c154f1da8d8da4cfd870368de4497639bd962d26 100644 (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() + ")";
     }
 }
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyModifier.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyModifier.java
new file mode 100644 (file)
index 0000000..51da09c
--- /dev/null
@@ -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();
+    }
+}