Search in sources :

Example 11 with NotesException

use of lotus.domino.NotesException in project org.openntf.domino by OpenNTF.

the class Document method appendItemValue.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Document#appendItemValue(java.lang.String, java.lang.Object)
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Item appendItemValue(final String name, final Object value, final boolean unique) {
    checkMimeOpen(name);
    Item result = null;
    if (unique && hasItem(name)) {
        // TODO RPr This function is not yet 100% mime compatible
        // Once mime compatible, remove the reference in org.openntf.domino.ext.Document Javadoc
        result = getFirstItem(name);
        if (result.containsValue(value)) {
            // this does not work when it is not dominoFriendly
            return result;
        }
    }
    try {
        if (!hasItem(name)) {
            result = replaceItemValue(name, value);
        } else if (value != null) {
            List recycleThis = new ArrayList();
            try {
                Object domNode = toDominoFriendly(value, getAncestorSession(), recycleThis);
                if (getAncestorSession().isFixEnabled(Fixes.APPEND_ITEM_VALUE)) {
                    Vector current = getItemValue(name);
                    if (current == null) {
                        result = replaceItemValue(name, value);
                    } else if (domNode instanceof Collection) {
                        current.addAll((Collection) domNode);
                        result = replaceItemValue(name, current);
                    } else {
                        current.add(domNode);
                        result = replaceItemValue(name, current);
                    }
                } else {
                    beginEdit();
                    result = fromLotus(getDelegate().appendItemValue(name, domNode), Item.SCHEMA, this);
                    markDirty(name, true);
                }
            } finally {
                s_recycle(recycleThis);
            }
        } else {
            result = appendItemValue(name);
        }
    } catch (NotesException e) {
        DominoUtils.handleException(e, this, "Item=" + name);
    }
    return result;
}
Also used : RichTextItem(org.openntf.domino.RichTextItem) Item(org.openntf.domino.Item) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) NoteCollection(org.openntf.domino.NoteCollection) DocumentCollection(org.openntf.domino.DocumentCollection) List(java.util.List) ArrayList(java.util.ArrayList) EmbeddedObject(org.openntf.domino.EmbeddedObject) Vector(java.util.Vector) ItemVector(org.openntf.domino.iterators.ItemVector)

Example 12 with NotesException

use of lotus.domino.NotesException in project org.openntf.domino by OpenNTF.

the class Document method get.

/**
 * Gets a value depending on the parameter 'key'. Key can either be a @Formula, a special value or an item name.
 * <p>
 * Possible values for the 'key' parameter:
 * <dl>
 * <dt>parentdocument</dt>
 * <dd>Returns the parent document if this document is a response</dd>
 * <dt>@accesseddate</dt>
 * <dd>Indicates the time and date when the document was last accessed by a Notes client, whether for reading or editing as a
 * java.util.Date.</dd>
 * <dt>@modifieddate</dt>
 * <dd>Returns a time-date value indicating when the document was modified initially as a java.util.Date</dd>
 * <dt>@createddate</dt>
 * <dd>Returns the time-date when the document was created as a java.util.Date</dd>
 * </dl>
 * </p>
 *
 * @param key
 *            &#64;formula, item name or a special value from a list above
 * @return value corresponding to the given 'key'
 */
@Override
public Object get(final Object key) {
    // TODO NTF: Implement a read-only mode for Documents so we know in advance that our cache is valid
    if (key == null) {
        return null;
    }
    if (key instanceof CharSequence) {
        String skey = key.toString().toLowerCase();
        if ("parentdocument".equalsIgnoreCase(skey)) {
            return this.getParentDocument();
        }
        if ("form".equalsIgnoreCase(skey)) {
            return this.getFormName();
        }
        if (skey.indexOf("@") != -1) {
            // TODO RPr: Should we REALLY detect all formulas, like "3+5" or "field[2]" ?
            // TODO NTF: If so, we should change to looking for valid item names first, then trying to treat as formula
            int pos = skey.indexOf('(');
            if (pos != -1) {
                skey = skey.substring(0, pos);
            }
            if ("@accessed".equals(skey)) {
                return this.getLastAccessed();
            }
            if ("@modified".equals(skey)) {
                return this.getLastModified();
            }
            if ("@created".equals(skey)) {
                return this.getCreated();
            }
            if ("@accesseddate".equals(skey)) {
                return this.getLastAccessedDate();
            }
            if ("@modifieddate".equals(skey)) {
                return this.getLastModifiedDate();
            }
            if ("@createddate".equals(skey)) {
                return this.getCreatedDate();
            }
            if ("@documentuniqueid".equals(skey)) {
                return this.getUniversalID();
            }
            if ("@noteid".equals(skey)) {
                return this.getNoteID();
            }
            if ("@doclength".equals(skey)) {
                return this.getSize();
            }
            if ("@isresponsedoc".equals(skey)) {
                return this.isResponse();
            }
            if ("@replicaid".equals(skey)) {
                return this.getAncestorDatabase().getReplicaID();
            }
            if ("@responses".equals(skey)) {
                DocumentCollection resp = this.getResponses();
                if (resp == null) {
                    return 0;
                }
                return resp.getCount();
            }
            if ("@isnewdoc".equals(skey)) {
                return this.isNewNote();
            }
            if ("@inheriteddocumentuniqueid".equals(skey)) {
                org.openntf.domino.Document parent = this.getParentDocument();
                if (parent == null) {
                    return "";
                }
                return parent.getUniversalID();
            }
            // TODO RPr: This should be replaced
            // TODO NTF: Agreed when we can have an extensible switch for which formula engine to use
            Formula formula = new Formula();
            formula.setExpression(key.toString());
            List<?> value = formula.getValue(this);
            if (value.size() == 1) {
                return value.get(0);
            }
            return value;
        }
    }
    // TODO: What is the best way to use here without breaking everything?
    // Object value = this.getItemValue(key.toString(), Object.class);
    // Object value = this.getItemValue(key.toString(), Object[].class);
    Object value = null;
    String keyS = key.toString();
    try {
        value = this.getItemValue(keyS, Object.class);
    } catch (OpenNTFNotesException e) {
        if (e.getCause() instanceof NotesException || (e.getCause() != null && e.getCause().getCause() instanceof NotesException)) {
            value = getFirstItem(keyS, true);
        }
        if (value == null) {
            throw e;
        }
    }
    if (value instanceof Vector) {
        Vector<?> v = (Vector<?>) value;
        if (v.size() == 1) {
            return v.get(0);
        }
    }
    return value;
// if (this.containsKey(key)) {
// Vector<Object> value = this.getItemValue(key.toString());
// if (value == null) {
// //TODO Throw an exception if the item data can't be read? Null implies the key doesn't exist
// return null;
// } else if (value.size() == 1) {
// return value.get(0);
// }
// return value;
// }
// return null;
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) DocumentCollection(org.openntf.domino.DocumentCollection) Formula(org.openntf.domino.helpers.Formula) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) EmbeddedObject(org.openntf.domino.EmbeddedObject) Vector(java.util.Vector) ItemVector(org.openntf.domino.iterators.ItemVector)

Example 13 with NotesException

use of lotus.domino.NotesException in project org.openntf.domino by OpenNTF.

the class Database method resurrect.

@Override
public void resurrect() {
    // should only happen if the delegate has been destroyed somehow.
    // clear metaData
    shadowedMetaData_ = null;
    lotus.domino.Session rawSession = toLotus(parent);
    try {
        lotus.domino.Database d = rawSession.getDatabase(server_, path_);
        setDelegate(d, true);
    /* No special logging, since by now Database is a BaseThreadSafe */
    } catch (NotesException e) {
        if (e.id == NotesError.NOTES_ERR_DBNOACCESS) {
            throw new UserAccessException("User " + parent.getEffectiveUserName() + " cannot open database " + path_ + " on server " + server_, e);
        } else {
            DominoUtils.handleException(e, this);
        }
    }
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) UserAccessException(org.openntf.domino.exceptions.UserAccessException)

Example 14 with NotesException

use of lotus.domino.NotesException in project org.openntf.domino by OpenNTF.

the class Database method getLastFTIndexedDate.

@Override
public Date getLastFTIndexedDate() {
    try {
        lotus.domino.DateTime dt = getDelegate().getLastFTIndexed();
        // recycles the javaDate!
        Date ret = DominoUtils.toJavaDateSafe(dt);
        s_recycle(dt);
        return ret;
    } catch (NotesException e) {
        DominoUtils.handleException(e, this);
        return null;
    }
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) Date(java.util.Date)

Example 15 with NotesException

use of lotus.domino.NotesException in project org.openntf.domino by OpenNTF.

the class Database method getDocumentByURL.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Database#getDocumentByURL(java.lang.String, boolean, boolean, boolean, java.lang.String, java.lang.String,
	 * java.lang.String, java.lang.String, java.lang.String, boolean)
	 */
@Override
@SuppressWarnings("unused")
public Document getDocumentByURL(final String url, final boolean reload, final boolean reloadIfModified, final boolean urlList, final String charSet, final String webUser, final String webPassword, final String proxyUser, final String proxyPassword, final boolean returnImmediately) {
    try {
        // Let's have some fun with this
        try {
            URL urlObj = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
            conn.connect();
            conn.disconnect();
        } catch (MalformedURLException e) {
            DominoUtils.handleException(e, this);
        } catch (IOException e) {
            DominoUtils.handleException(e, this);
        }
        if (true) {
            return null;
        }
        return fromLotus(getDelegate().getDocumentByURL(url, reload, reloadIfModified, urlList, charSet, webUser, webPassword, proxyUser, proxyPassword, returnImmediately), Document.SCHEMA, this);
    } catch (NotesException e) {
        DominoUtils.handleException(e, this);
        return null;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) HttpURLConnection(java.net.HttpURLConnection) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

NotesException (lotus.domino.NotesException)105 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)29 ArrayList (java.util.ArrayList)28 List (java.util.List)19 ViewNavigator (org.openntf.domino.ViewNavigator)13 Vector (java.util.Vector)11 Database (lotus.domino.Database)11 Database (org.openntf.domino.Database)10 IOException (java.io.IOException)8 ViewColumn (org.openntf.domino.ViewColumn)8 DocumentCollection (org.openntf.domino.DocumentCollection)7 EmbeddedObject (org.openntf.domino.EmbeddedObject)7 RichTextItem (org.openntf.domino.RichTextItem)7 Session (lotus.domino.Session)6 MIMEEntity (org.openntf.domino.MIMEEntity)5 Date (java.util.Date)4 Document (org.openntf.domino.Document)4 DocumentCollection (lotus.domino.DocumentCollection)3 DominoQuery (lotus.domino.DominoQuery)3 Item (org.openntf.domino.Item)3