Search in sources :

Example 1 with Type

use of org.openntf.domino.Item.Type in project org.openntf.domino by OpenNTF.

the class Document method toJson.

@Override
public String toJson(final boolean compact) {
    StringWriter sw = new StringWriter();
    JsonWriter jw = new JsonWriter(sw, compact);
    try {
        jw.startObject();
        jw.outStringProperty("@unid", getUniversalID());
        jw.outStringProperty("@noteid", getNoteID());
        jw.outStringProperty("@replicaid", getParentDatabase().getReplicaID());
        jw.outStringProperty("@metaversalid", getMetaversalID());
        try {
            jw.outStringProperty("@created", getCreated().toGMTISO());
            jw.outStringProperty("@lastmodified", getLastModified().toGMTISO());
            jw.outStringProperty("@lastaccessed", getLastAccessed().toGMTISO());
        } catch (Exception e) {
            DominoUtils.handleException(e, "Exception trying to index Dates.");
        }
        Set<String> keys = keySet();
        for (String key : keys) {
            Item currItem = getFirstItem(key);
            // A beer to anyone who can work out how this could happen, except for the person who identified it!
            if (null != currItem) {
                Type itemType = currItem.getTypeEx();
                try {
                    if (itemType == Type.ATTACHMENT) {
                        jw.outProperty(key, "ATTACHMENT");
                    } else if (itemType == Type.AUTHORS || itemType == Type.READERS || itemType == Type.NAMES || itemType == Type.TEXT || itemType == Type.NUMBERS) {
                        Vector<Object> values = currItem.getValues();
                        if (values.size() == 1) {
                            jw.outProperty(key, values.elementAt(0));
                        } else {
                            jw.outProperty(key, values);
                        }
                    } else if (itemType == Type.DATETIMES) {
                        Vector<DateTime> values = currItem.getValueDateTimeArray();
                        if (values.size() == 1) {
                            jw.outProperty(key, values.get(0).toGMTISO());
                        } else {
                            jw.outProperty(key, TypeUtils.toStrings(values));
                        }
                    } else if (itemType == Type.EMBEDDEDOBJECT) {
                        jw.outProperty(key, "EMBEDDED_OBJECT");
                    } else if (itemType == Type.RICHTEXT) {
                        RichTextItem rtItem = (RichTextItem) currItem;
                        jw.outProperty(key, rtItem.getUnformattedText());
                    } else if (itemType == Type.MIME_PART) {
                        MIMEEntity mimeEntity = currItem.getMIMEEntity();
                        if (mimeEntity != null) {
                            jw.outProperty(key, mimeEntity.getContentAsText());
                        } else {
                            jw.outProperty(key, "MIME_PART null");
                        }
                    }
                } catch (Exception e) {
                    DominoUtils.handleException(e, this);
                    // NTF - temporary
                    e.printStackTrace();
                }
            }
            // if (currItem.getMIMEEntity() == null) {
            // jw.outProperty(key, currItem.getText());
            // } else {
            // String abstractedText = currItem.abstractText(0, false, false);
            // if (null == abstractedText) {
            // jw.outProperty(key, "**MIME ITEM, VALUE CANNOT BE DECODED TO JSON**");
            // } else {
            // jw.outProperty(key, abstractedText);
            // }
            // }
            // Now output attachments
            jw.outProperty("@attachments", getAttachmentNames());
        }
        jw.endObject();
        jw.flush();
    } catch (IOException e) {
        DominoUtils.handleException(e, this);
        return null;
    } catch (JsonException e) {
        DominoUtils.handleException(e, this);
        return null;
    }
    return sw.toString();
}
Also used : JsonException(com.ibm.commons.util.io.json.JsonException) IOException(java.io.IOException) JsonWriter(com.ibm.commons.util.io.json.util.JsonWriter) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) JsonException(com.ibm.commons.util.io.json.JsonException) DocumentWriteAccessException(org.openntf.domino.exceptions.DocumentWriteAccessException) DataNotCompatibleException(org.openntf.domino.exceptions.DataNotCompatibleException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) NotesException(lotus.domino.NotesException) DominoNonSummaryLimitException(org.openntf.domino.exceptions.DominoNonSummaryLimitException) IOException(java.io.IOException) ItemNotFoundException(org.openntf.domino.exceptions.ItemNotFoundException) DateTime(org.openntf.domino.DateTime) RichTextItem(org.openntf.domino.RichTextItem) Item(org.openntf.domino.Item) Type(org.openntf.domino.Item.Type) MIMEEntity(org.openntf.domino.MIMEEntity) StringWriter(java.io.StringWriter) RichTextItem(org.openntf.domino.RichTextItem) Vector(java.util.Vector) ItemVector(org.openntf.domino.iterators.ItemVector)

Example 2 with Type

use of org.openntf.domino.Item.Type in project org.openntf.domino by OpenNTF.

the class ItemType method validateItem.

public boolean validateItem(final org.openntf.domino.Item candidate) {
    byte flags = (byte) Item.Flags.getFlags(candidate);
    Item.Type type = candidate.getTypeEx();
    return flags == lotusFlags_ && type == lotusType_;
}
Also used : Item(org.openntf.domino.Item) Type(org.openntf.domino.Item.Type)

Aggregations

Item (org.openntf.domino.Item)2 Type (org.openntf.domino.Item.Type)2 JsonException (com.ibm.commons.util.io.json.JsonException)1 JsonWriter (com.ibm.commons.util.io.json.util.JsonWriter)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Vector (java.util.Vector)1 NotesException (lotus.domino.NotesException)1 DateTime (org.openntf.domino.DateTime)1 MIMEEntity (org.openntf.domino.MIMEEntity)1 RichTextItem (org.openntf.domino.RichTextItem)1 DataNotCompatibleException (org.openntf.domino.exceptions.DataNotCompatibleException)1 DocumentWriteAccessException (org.openntf.domino.exceptions.DocumentWriteAccessException)1 DominoNonSummaryLimitException (org.openntf.domino.exceptions.DominoNonSummaryLimitException)1 ItemNotFoundException (org.openntf.domino.exceptions.ItemNotFoundException)1 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)1 UserAccessException (org.openntf.domino.exceptions.UserAccessException)1 ItemVector (org.openntf.domino.iterators.ItemVector)1