Author: nick Date: Thu May 8 14:49:21 2014 New Revision: 1593298 URL: http://svn.apache.org/r1593298 Log: Implement a few more MAPI property types Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java?rev=1593298&r1=1593297&r2=1593298&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java Thu May 8 14:49:21 2014 @@ -25,8 +25,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.poi.hsmf.datatypes.PropertyValue.BooleanPropertyValue; +import org.apache.poi.hsmf.datatypes.PropertyValue.CurrencyPropertyValue; +import org.apache.poi.hsmf.datatypes.PropertyValue.DoublePropertyValue; +import org.apache.poi.hsmf.datatypes.PropertyValue.FloatPropertyValue; import org.apache.poi.hsmf.datatypes.PropertyValue.LongLongPropertyValue; import org.apache.poi.hsmf.datatypes.PropertyValue.LongPropertyValue; +import org.apache.poi.hsmf.datatypes.PropertyValue.NullPropertyValue; import org.apache.poi.hsmf.datatypes.PropertyValue.ShortPropertyValue; import org.apache.poi.hsmf.datatypes.PropertyValue.TimePropertyValue; import org.apache.poi.hsmf.datatypes.Types.MAPIType; @@ -204,6 +209,12 @@ public abstract class PropertiesChunk ex // We'll match up the chunk later propVal = new ChunkBasedPropertyValue(prop, flags, data); } + else if (type == Types.NULL) { + propVal = new NullPropertyValue(prop, flags, data); + } + else if (type == Types.BOOLEAN) { + propVal = new BooleanPropertyValue(prop, flags, data); + } else if (type == Types.SHORT) { propVal = new ShortPropertyValue(prop, flags, data); } @@ -213,6 +224,15 @@ public abstract class PropertiesChunk ex else if (type == Types.LONG_LONG) { propVal = new LongLongPropertyValue(prop, flags, data); } + else if (type == Types.FLOAT) { + propVal = new FloatPropertyValue(prop, flags, data); + } + else if (type == Types.DOUBLE) { + propVal = new DoublePropertyValue(prop, flags, data); + } + else if (type == Types.CURRENCY) { + propVal = new CurrencyPropertyValue(prop, flags, data); + } else if (type == Types.TIME) { propVal = new TimePropertyValue(prop, flags, data); } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java?rev=1593298&r1=1593297&r2=1593298&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java Thu May 8 14:49:21 2014 @@ -17,6 +17,7 @@ package org.apache.poi.hsmf.datatypes; +import java.math.BigInteger; import java.util.Calendar; import java.util.TimeZone; @@ -72,8 +73,35 @@ public class PropertyValue { } } - // TODO classes for the other important value types + public static class NullPropertyValue extends PropertyValue { + public NullPropertyValue(MAPIProperty property, long flags, byte[] data) { + super(property, flags, data); + } + + public Void getValue() { + return null; + } + } + public static class BooleanPropertyValue extends PropertyValue { + public BooleanPropertyValue(MAPIProperty property, long flags, byte[] data) { + super(property, flags, data); + } + + public Boolean getValue() { + short val = LittleEndian.getShort(data); + return val > 0; + } + public void setValue(boolean value) { + if (data.length != 2) { + data = new byte[2]; + } + if (value) { + LittleEndian.putShort(data, 0, (short)1); + } + } + } + public static class ShortPropertyValue extends PropertyValue { public ShortPropertyValue(MAPIProperty property, long flags, byte[] data) { super(property, flags, data); @@ -88,7 +116,7 @@ public class PropertyValue { } LittleEndian.putShort(data, 0, value); } - } + } public static class LongPropertyValue extends PropertyValue { public LongPropertyValue(MAPIProperty property, long flags, byte[] data) { @@ -122,6 +150,61 @@ public class PropertyValue { } } + public static class FloatPropertyValue extends PropertyValue { + public FloatPropertyValue(MAPIProperty property, long flags, byte[] data) { + super(property, flags, data); + } + + public Float getValue() { + return LittleEndian.getFloat(data); + } + public void setValue(float value) { + if (data.length != 4) { + data = new byte[4]; + } + LittleEndian.putFloat(data, 0, value); + } + } + + public static class DoublePropertyValue extends PropertyValue { + public DoublePropertyValue(MAPIProperty property, long flags, byte[] data) { + super(property, flags, data); + } + + public Double getValue() { + return LittleEndian.getDouble(data); + } + public void setValue(double value) { + if (data.length != 8) { + data = new byte[8]; + } + LittleEndian.putDouble(data, 0, value); + } + } + + /** + * signed 64-bit integer that represents a base ten decimal, + * with four digits to the right of the decimal point + */ + public static class CurrencyPropertyValue extends PropertyValue { + private static final BigInteger SHIFT = BigInteger.valueOf(10000); + public CurrencyPropertyValue(MAPIProperty property, long flags, byte[] data) { + super(property, flags, data); + } + + public BigInteger getValue() { + long unshifted = LittleEndian.getLong(data); + return BigInteger.valueOf(unshifted).divide(SHIFT); + } + public void setValue(BigInteger value) { + if (data.length != 8) { + data = new byte[8]; + } + long shifted = value.multiply(SHIFT).longValue(); + LittleEndian.putLong(data, 0, shifted); + } + } + /** * 64-bit integer specifying the number of 100ns periods since Jan 1, 1601 */ --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org