com.mindoo.domino.jna.internal.CollationDecoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of domino-jna Show documentation
Show all versions of domino-jna Show documentation
Java project to access the HCL Domino C API using Java Native Access (JNA)
package com.mindoo.domino.jna.internal;
import java.util.ArrayList;
import java.util.List;
import com.mindoo.domino.jna.NotesCollateDescriptor;
import com.mindoo.domino.jna.NotesCollationInfo;
import com.mindoo.domino.jna.constants.CollateType;
import com.mindoo.domino.jna.internal.structs.collation.NotesCollateDescriptorStruct;
import com.mindoo.domino.jna.internal.structs.collation.NotesCollationStruct;
import com.mindoo.domino.jna.utils.DumpUtil;
import com.mindoo.domino.jna.utils.NotesStringUtils;
import com.sun.jna.Pointer;
/**
* Utility class to decode the COLLATION and COLLATE_DESCRIPTOR data structures from
* view note items of type TYPE_COLLATION (e.g. $Collation, $Collation1, $Collation2 etc.).
*
* @author Karsten Lehmann
*/
public class CollationDecoder {
/**
* Decodes the item value. Extracted data is returned as {@link NotesCollationInfo} object
*
* @param dataPtr item value pointer
* @return collation info
*/
public static NotesCollationInfo decodeCollation(Pointer dataPtr) {
NotesCollationStruct collationStruct = NotesCollationStruct.newInstance(dataPtr);
collationStruct.read();
//sanity check that the signature byte is at the right position
if (NotesConstants.COLLATION_SIGNATURE != collationStruct.signature)
throw new AssertionError("Collation signature byte is not correct.\nMem dump:\n"+DumpUtil.dumpAsAscii(dataPtr, NotesConstants.notesCollationSize));
List collateDescriptors = new ArrayList();
int items = (int) (collationStruct.Items & 0xffff);
long baseOffsetDescriptors = NotesConstants.notesCollationSize;
long baseOffsetTextBuffer = baseOffsetDescriptors + (items * NotesConstants.notesCollateDescriptorSize);
NotesCollationInfo collationInfo = new NotesCollationInfo(collationStruct.Flags, collateDescriptors);
for (int i=0; i