use of org.openntf.domino.Item in project org.openntf.domino by OpenNTF.
the class Document method copyItem.
/*
* (non-Javadoc)
*
* @see org.openntf.domino.Document#copyItem(lotus.domino.Item, java.lang.String)
*/
@Override
public Item copyItem(final lotus.domino.Item item, final String newName) {
// TODO - NTF markDirty()? Yes. It's necessary.
// TODO RPr: ConvertMime?
checkMimeOpen(newName);
beginEdit();
try {
Item ret = fromLotus(getDelegate().copyItem(toLotus(item), newName), Item.SCHEMA, this);
markDirty(ret.getName(), true);
return ret;
} catch (NotesException e) {
DominoUtils.handleException(e, this);
}
return null;
}
use of org.openntf.domino.Item in project org.openntf.domino by OpenNTF.
the class Document method readBinary.
@Override
public byte[] readBinary(final String name) {
if (isChunked(name)) {
String[] chunkNames = getChunkNames(name);
int chunks = chunkNames.length;
Item startChunk = getFirstItem(name);
if (startChunk != null) {
int chunkSize = startChunk.getValueLength();
int resultMaxSize = chunkSize * chunks;
byte[] accumulated = new byte[resultMaxSize];
int actual = 0;
for (String curChunk : chunkNames) {
// System.out.println("DEBUG: Attempting binary read from " + curChunk);
try {
byte[] cur = getDelegate().getItemValueCustomDataBytes(curChunk, CHUNK_TYPE_NAME);
// System.out.println("Found " + cur.length + " bytes from chunk " + curChunk);
System.arraycopy(cur, 0, accumulated, actual, cur.length);
actual = actual + cur.length;
} catch (Exception e) {
DominoUtils.handleException(e, this);
}
}
byte[] result = new byte[actual];
// System.out.println("DEBUG: resulting read-in array is " + actual + " while we have an actual of " + result.length
// + " for an accumulated " + accumulated.length);
System.arraycopy(accumulated, 0, result, 0, actual);
return result;
} else {
log_.log(Level.WARNING, "No start chunk available for binary read " + name + " on doucment " + noteid_ + " in db " + getAncestorDatabase().getApiPath());
}
} else {
return readBinaryChunk(name, 0);
}
return null;
}
use of org.openntf.domino.Item in project org.openntf.domino by OpenNTF.
the class Document method setUniversalID.
/*
* (non-Javadoc)
*
* @see org.openntf.domino.Document#setUniversalID(java.lang.String)
*/
@Override
public void setUniversalID(final String unid) {
if (getUniversalID().equalsIgnoreCase(unid)) {
// it's already that unid. Don't waste time...
return;
}
checkMimeOpen(unid);
beginEdit();
try {
try {
lotus.domino.Document del = getDelegate().getParentDatabase().getDocumentByUNID(unid);
if (del != null) {
// this is surprising. Why didn't we already get it?
log_.log(Level.WARNING, "Document " + unid + " already existed in the database with noteid " + del.getNoteID() + " and we're trying to set a doc with noteid " + getNoteID() + " to that. The existing document is a " + del.getItemValueString("form") + " and the new document is a " + getItemValueString("form"));
if (isDirty()) {
// we've already made other changes that we should tuck away...
log_.log(Level.WARNING, "Attempting to stash changes to this document to apply to other document of the same UNID. This is pretty dangerous...");
org.openntf.domino.Document stashDoc = copyToDatabase(getParentDatabase());
setDelegate(del, true);
try {
for (Item item : stashDoc.getItems()) {
lotus.domino.Item delItem = del.getFirstItem(item.getName());
if (delItem != null) {
lotus.domino.DateTime delDt = delItem.getLastModified();
java.util.Date delDate = delDt.toJavaDate();
delDt.recycle();
Date modDate = item.getLastModifiedDate();
if (modDate.after(delDate)) {
item.copyItemToDocument(del);
}
} else {
item.copyItemToDocument(del);
}
// TODO NTF properties?
}
} catch (Throwable t) {
DominoUtils.handleException(t);
}
} else {
log_.log(Level.WARNING, "Resetting delegate to existing document for id " + unid);
setDelegate(del, true);
}
} else {
getDelegate().setUniversalID(unid);
}
markDirty();
} catch (NotesException ne) {
// this is what's expected
getDelegate().setUniversalID(unid);
markDirty();
}
} catch (NotesException e) {
DominoUtils.handleException(e, this);
}
unid_ = unid;
}
use of org.openntf.domino.Item 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;
}
use of org.openntf.domino.Item in project org.openntf.domino by OpenNTF.
the class Document method replaceItemValueLotus.
/**
* returns the real LMBCS payload for a Vector of Strings
*
* @param strVect
* The vector of Strings.
* @return LMBCS payload
*/
// private static Charset lLMBCSCharset = null;
//
// private static synchronized CharsetEncoder lGetEncoder() {
// if (lLMBCSCharset == null)
// lLMBCSCharset = new CharsetProviderICU().charsetForName("LMBCS");
// return lLMBCSCharset.newEncoder();
// }
/**
* replaceItemValueLotus writes itemFriendly values or a Collection of itemFriendly values. it throws a Domino32KLimitException if the
* data does not fit into the fied. The caller can decide what to do, if this exception is thrown.
*
* It throws a DataNotCompatibleException, if the data is not domino compatible
*
* @throws DominoNonSummaryLimitException
* if the item does not fit in a field
*/
public Item replaceItemValueLotus(final String itemName, Object value, final Boolean isSummary, final boolean returnItem) throws DominoNonSummaryLimitException {
checkMimeOpen(itemName);
// writing a value of "Null" leads to a remove of the item if configured in SESSION
if (value == null || value instanceof Null) {
if (hasItem(itemName)) {
if (getAncestorSession().isFixEnabled(Fixes.REPLACE_ITEM_NULL)) {
removeItem(itemName);
return null;
} else {
value = "";
}
} else {
return null;
}
}
org.openntf.domino.Item result = TypeUtils.writeToItem(this, itemName, value, isSummary);
if (returnItem) {
return result;
} else {
return null;
}
}
Aggregations