From 4c0697dea54ea9fd02a246292fae240bc09740d8 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 8 May 2014 14:49:21 +0000 Subject: [PATCH] Implement a few more MAPI property types git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1593298 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hsmf/datatypes/PropertiesChunk.java | 20 +++++ .../poi/hsmf/datatypes/PropertyValue.java | 87 ++++++++++++++++++- 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java index 8972220d92..c48b757dc9 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java @@ -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 extends Chunk { // 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 extends Chunk { 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); } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java index b76b2de295..e1f9ba3fc0 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java @@ -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 */ -- 2.39.5