use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class Database method getDocumentWithKey.
@Override
public Document getDocumentWithKey(final Serializable key, final boolean createOnFail) {
try {
if (key != null) {
if (key instanceof String && ((String) key).length() == 32) {
if ("000000000000000000000000000000000000".equals(key)) {
// $NON-NLS-1$
Document result = getIconNote();
if (result == null) {
result = getACLNote();
}
return result;
}
}
String checksum = DominoUtils.toUnid(key);
Document doc = this.getDocumentByUNID(checksum);
if (doc == null && createOnFail) {
doc = this.createDocument();
if (checksum != null) {
doc.setUniversalID(checksum, true);
}
// $NON-NLS-1$
doc.replaceItemValue("$$Key", key);
// $NON-NLS-1$
doc.replaceItemValue("$Created", new Date());
}
return doc;
} else if (createOnFail) {
// log_.log(java.util.logging.Level.FINE,
// "Document by key requested with null key. This is probably not what you meant to do...");
// NTF No, its exactly what we meant to do in the case of graph elements
Document doc = this.createDocument();
// $NON-NLS-1$
doc.replaceItemValue("$Created", new Date());
// doc.replaceItemValue("$$Key", "");
return doc;
}
} catch (UserAccessException uae) {
throw uae;
} catch (Exception e) {
DominoUtils.handleException(e, this);
}
return null;
}
use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class Database method createDocument.
/*
* (non-Javadoc)
*
* @see org.openntf.domino.Database#createDocument()
*/
@Override
public Document createDocument() {
// System.out.println("Generating a new document in " + this.getFilePath());
// try {
// Thread.sleep(100);
// } catch (InterruptedException e1) {
// DominoUtils.handleException(e1);
// return null;
// }
Document result = null;
boolean go;
go = !hasListeners() ? true : fireListener(generateEvent(Events.BEFORE_CREATE_DOCUMENT, this, null));
if (go) {
try {
open();
result = fromLotus(getDelegate().createDocument(), Document.SCHEMA, this);
((org.openntf.domino.impl.Document) result).isNew_ = true;
} catch (NotesException e) {
DominoUtils.handleException(e, this);
}
if (hasListeners()) {
fireListener(generateEvent(Events.AFTER_CREATE_DOCUMENT, this, null));
}
}
// }
return result;
}
use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class DocumentSorter method _normalize.
protected void _normalize() {
if (dataset_ == null) {
List<String> criteria = getCriteria();
if (criteria.isEmpty()) {
// $NON-NLS-1$
addCriteria("@created");
}
if (sourceColl_ == null) {
throw new IllegalStateException("Cannot sort from a null DocumentCollection. Please add a DocumentCollection that you want to sort...");
}
// System.out.println("Normalizing collection of " + sourceColl_.getCount() + " docs");
long startTime = System.nanoTime();
int docCount = 0;
dataset_ = new DocumentData[sourceColl_.getCount()];
for (Document doc : sourceColl_) {
dataset_[docCount++] = new DocumentData(doc, criteria);
// System.out.println("Processed " + ++docCount + " documents");
if (debug) {
if (docCount % 50000 == 0) {
System.out.println("Added " + docCount + " documents to set for sorting...");
}
}
}
long endTime = System.nanoTime();
if (debug) {
System.out.println("Normalized dataset of " + docCount + " in " + (endTime - startTime) / 1000000 + "ms");
}
}
}
use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class DocumentSyncHelper method process.
/**
* Process a specific DocumentCollection.
*
* WARNING: Does not currently check that all properties of the SyncHelper have been set up
*
* @param coll
* DocumentCollection of source documents
* @since org.openntf.domino 1.0.0
*/
public void process(final DocumentCollection coll) {
// TODO Check to make sure properties are all set up before running
Session session = coll.getAncestorSession();
Database targetDb = session.getDatabase(getTargetServer(), getTargetFilepath());
View targetView = targetDb.getView(getTargetLookupView());
Strategy strategy = getStrategy();
DatabaseTransaction txn = null;
if (getTransactionRule() == TransactionRule.COMMIT_AT_END) {
txn = targetDb.startTransaction();
}
for (Document source : coll) {
txn = processDocument(targetDb, targetView, strategy, txn, source);
}
if (getTransactionRule() == TransactionRule.COMMIT_AT_END && txn != null) {
txn.commit();
txn = null;
}
}
use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class DominoEmail method send.
/* (non-Javadoc)
* @see org.openntf.domino.email.IEmail#send()
*/
@Override
public Document send() {
try {
Stream stream;
MIMEEntity mimeEntity;
MIMEHeader mimeHeader;
Database currDb;
Session currSess = getSession();
// in case Khan is still in suspended animation!
currSess.setConvertMime(false);
// Create memo doc
try {
currDb = currSess.getCurrentDatabase();
if (null == currDb) {
// Will this work if we're running from DOTS or OSGi plugin??
// $NON-NLS-1$
currDb = currSess.getDatabase(currSess.getServerName(), "mail.box");
}
} catch (Throwable t) {
// $NON-NLS-1$
currDb = currSess.getDatabase(currSess.getServerName(), "mail.box");
}
Document memo = currDb.createDocument();
// no replies from out of office agents //$NON-NLS-1$ //$NON-NLS-2$
memo.put("RecNoOutOfOffice", "1");
String mimeBoundary = memo.getUniversalID().toLowerCase();
// $NON-NLS-1$
MIMEEntity mimeRoot = memo.createMIMEEntity("Body");
// $NON-NLS-1$
mimeHeader = mimeRoot.createHeader("To");
// $NON-NLS-1$
mimeHeader.setHeaderVal(join(getTo(), ""));
if (cc_.size() > 0) {
// $NON-NLS-1$
mimeHeader = mimeRoot.createHeader("CC");
// $NON-NLS-1$
mimeHeader.setHeaderVal(join(getCC(), ""));
// memo.replaceItemValue("cc", getCC());
}
if (bcc_.size() > 0) {
// $NON-NLS-1$
mimeHeader = mimeRoot.createHeader("BCC");
// $NON-NLS-1$
mimeHeader.setHeaderVal(join(getBCC(), ""));
// memo.replaceItemValue("bcc", getBCC());
}
// set subject
// $NON-NLS-1$
mimeHeader = mimeRoot.createHeader("Subject");
// $NON-NLS-1$
mimeHeader.addValText(getSubject(), "UTF-8");
// create text/alternative directive: text/plain and text/html part will be childs of this entity
MIMEEntity mimeRootChild = mimeRoot.createChildEntity();
// $NON-NLS-1$
mimeHeader = mimeRootChild.createHeader("Content-Type");
// $NON-NLS-1$ //$NON-NLS-2$
mimeHeader.setHeaderVal("multipart/alternative; boundary=\"" + mimeBoundary + "\"");
// create plain text part
if (getText().size() > 0) {
mimeEntity = mimeRootChild.createChildEntity();
stream = currSess.createStream();
// $NON-NLS-1$
stream.writeText(join(getText(), System.getProperty("line.separator")));
// $NON-NLS-1$
mimeEntity.setContentFromText(stream, "text/plain; charset=\"UTF-8\"", MIMEEntity.ENC_NONE);
stream.close();
}
// create HTML part
if (contentsHTML_.size() > 0) {
mimeEntity = mimeRootChild.createChildEntity();
stream = currSess.createStream();
// $NON-NLS-1$
stream.writeText(join(contentsHTML_, System.getProperty("line.separator")));
// $NON-NLS-1$
mimeEntity.setContentFromText(stream, "text/html; charset=\"UTF-8\"", MIMEEntity.ENC_NONE);
stream.close();
}
// create embedded JSON part
if (!StringUtil.isEmpty(getJSON())) {
mimeEntity = mimeRootChild.createChildEntity();
stream = currSess.createStream();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String json = "{\"url\" : \"" + getJSON() + "\"}" + System.getProperty("line.separator");
stream.writeText(json);
// $NON-NLS-1$
mimeEntity.setContentFromText(stream, "application/embed+json; charset=\"UTF-8\"", MIMEEntity.ENC_NONE);
stream.close();
}
// Add any attachments
addAttachments(mimeRoot);
// set the sender
setSender(mimeRoot);
// mime processing done.
memo.closeMIMEEntities(true);
// send the e-mail
memo.send();
return memo;
} catch (Throwable t) {
DominoUtils.handleException(t);
return null;
}
}
Aggregations