All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mindoo.domino.jna.internal.ItemDecoder Maven / Gradle / Ivy

There is a newer version: 0.9.53
Show newest version
package com.mindoo.domino.jna.internal;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;

import com.mindoo.domino.jna.NotesDateRange;
import com.mindoo.domino.jna.NotesTimeDate;
import com.mindoo.domino.jna.errors.NotesErrorUtils;
import com.mindoo.domino.jna.internal.structs.NotesNumberPairStruct;
import com.mindoo.domino.jna.internal.structs.NotesRangeStruct;
import com.mindoo.domino.jna.internal.structs.NotesTimeDatePairStruct;
import com.mindoo.domino.jna.internal.structs.NotesTimeDateStruct;
import com.mindoo.domino.jna.utils.LMBCSString;
import com.mindoo.domino.jna.utils.NotesDateTimeUtils;
import com.mindoo.domino.jna.utils.NotesStringUtils;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.ShortByReference;

public class ItemDecoder {

	public static double decodeNumber(Pointer ptr, int valueLength) {
		double numVal = ptr.getDouble(0);
		return numVal;
	}
	
	public static Object decodeTextValue(Pointer ptr, int valueLength, boolean convertStringsLazily) {
		if (valueLength<=0) {
			return "";
		}
		
		if (convertStringsLazily) {
			byte[] stringDataArr = new byte[valueLength];
			ptr.read(0, stringDataArr, 0, valueLength);

			LMBCSString lmbcsString = new LMBCSString(stringDataArr);
			return lmbcsString;
		}
		else {
			String txtVal = NotesStringUtils.fromLMBCS(ptr, valueLength);
			return txtVal;
		}
	}
	
	public static List decodeTextListValue(Pointer ptr, boolean convertStringsLazily) {
		//read a text list item value
		int listCountAsInt = ptr.getShort(0) & 0xffff;
		
		List listValues = new ArrayList(listCountAsInt);
		
		Memory retTextPointer = new Memory(Native.POINTER_SIZE);
		ShortByReference retTextLength = new ShortByReference();
		
		for (short l=0; l decodeNumberList(Pointer ptr, int valueLength) {
		NotesRangeStruct range = NotesRangeStruct.newInstance(ptr);
		range.read();
		
		//read number of list and range entries in range
		int listEntriesAsInt = range.ListEntries & 0xffff;
		int rangeEntriesAsInt = range.RangeEntries & 0xffff;
		
		//skip range header
		Pointer ptrAfterRange = ptr.share(NotesConstants.rangeSize);
		
		//we create an object list, because number ranges contain double[] array
		//(not sure whether number ranges exist in real life)
		List numberValues = new ArrayList(listEntriesAsInt + rangeEntriesAsInt);
		for (int t=0; t decodeTimeDateListAsNotesTimeDate(Pointer ptr) {
		NotesRangeStruct range = NotesRangeStruct.newInstance(ptr);
		range.read();
		
		//read number of list and range entries in range
		int listEntriesAsInt = range.ListEntries & 0xffff;
		int rangeEntriesAsInt = range.RangeEntries & 0xffff;
		
		//skip range header
		Pointer ptrAfterRange = ptr.share(NotesConstants.rangeSize);
		
		List calendarValues = new ArrayList(listEntriesAsInt + rangeEntriesAsInt);
		
		for (int t=0; t decodeTimeDateList(Pointer ptr) {
		NotesRangeStruct range = NotesRangeStruct.newInstance(ptr);
		range.read();
		
		//read number of list and range entries in range
		int listEntriesAsInt = range.ListEntries & 0xffff;
		int rangeEntriesAsInt = range.RangeEntries & 0xffff;
		
		//skip range header
		Pointer ptrAfterRange = ptr.share(NotesConstants.rangeSize);
		
		List calendarValues = new ArrayList(listEntriesAsInt + rangeEntriesAsInt);
		
		for (int t=0; t