Implement a few more MAPI property types

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1593298 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-05-08 14:49:21 +00:00
parent 27e48c3b79
commit 50ad48e746
2 changed files with 105 additions and 2 deletions

View File

@ -25,8 +25,13 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.LongLongPropertyValue;
import org.apache.poi.hsmf.datatypes.PropertyValue.LongPropertyValue; 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.ShortPropertyValue;
import org.apache.poi.hsmf.datatypes.PropertyValue.TimePropertyValue; import org.apache.poi.hsmf.datatypes.PropertyValue.TimePropertyValue;
import org.apache.poi.hsmf.datatypes.Types.MAPIType; 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 // We'll match up the chunk later
propVal = new ChunkBasedPropertyValue(prop, flags, data); 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) { else if (type == Types.SHORT) {
propVal = new ShortPropertyValue(prop, flags, data); propVal = new ShortPropertyValue(prop, flags, data);
} }
@ -213,6 +224,15 @@ public abstract class PropertiesChunk extends Chunk {
else if (type == Types.LONG_LONG) { else if (type == Types.LONG_LONG) {
propVal = new LongLongPropertyValue(prop, flags, data); 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) { else if (type == Types.TIME) {
propVal = new TimePropertyValue(prop, flags, data); propVal = new TimePropertyValue(prop, flags, data);
} }

View File

@ -17,6 +17,7 @@
package org.apache.poi.hsmf.datatypes; package org.apache.poi.hsmf.datatypes;
import java.math.BigInteger;
import java.util.Calendar; import java.util.Calendar;
import java.util.TimeZone; import java.util.TimeZone;
@ -72,7 +73,34 @@ 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 static class ShortPropertyValue extends PropertyValue {
public ShortPropertyValue(MAPIProperty property, long flags, byte[] data) { public ShortPropertyValue(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 * 64-bit integer specifying the number of 100ns periods since Jan 1, 1601
*/ */