Created
December 15, 2010 12:50
-
-
Save ryanjbaxter/741908 to your computer and use it in GitHub Desktop.
Add some HTML To A Notes Document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lotus.domino.Database; | |
import lotus.domino.Document; | |
import lotus.domino.MIMEEntity; | |
import lotus.domino.NotesException; | |
import lotus.domino.Session; | |
import lotus.domino.Stream; | |
import org.eclipse.core.commands.AbstractHandler; | |
import org.eclipse.core.commands.ExecutionEvent; | |
import org.eclipse.core.commands.ExecutionException; | |
import org.eclipse.core.runtime.IProgressMonitor; | |
import org.eclipse.core.runtime.IStatus; | |
import org.eclipse.core.runtime.Status; | |
import com.ibm.notes.java.api.data.NotesDatabaseData; | |
import com.ibm.notes.java.api.util.NotesSessionJob; | |
import com.ibm.notes.java.ui.NotesUIWorkspace; | |
/** | |
* Our sample handler extends AbstractHandler, an IHandler base class. | |
* @see org.eclipse.core.commands.IHandler | |
* @see org.eclipse.core.commands.AbstractHandler | |
*/ | |
public class SampleHandler extends AbstractHandler { | |
/** | |
* The constructor. | |
*/ | |
public SampleHandler() { | |
} | |
/** | |
* the command has been executed, so extract extract the needed information | |
* from the application context. | |
*/ | |
public Object execute(ExecutionEvent event) throws ExecutionException { | |
NotesSessionJob job = new NotesSessionJob("Create document"){ | |
@Override | |
protected IStatus runInNotesThread(Session session, | |
IProgressMonitor arg1) throws NotesException { | |
NotesUIWorkspace ws = new NotesUIWorkspace(); | |
lotus.domino.DbDirectory directory = session.getDbDirectory(""); | |
Database db = directory.openMailDatabase(); | |
session.setConvertMIME(false); // Do not convert MIME to RT | |
Document doc = ws.getTemporaryDocument(session); | |
doc.replaceItemValue("Form", "Memo"); | |
doc.replaceItemValue("Subject", "test"); | |
//Create the body as a MIME entity | |
MIMEEntity body = doc.createMIMEEntity("Body"); | |
Stream stream = session.createStream(); | |
stream.writeText("<ul><li>hello</li><li>world</li></ul><a href=\"http://www.google.com\">Google</a>"); | |
body.setContentFromText(stream, "text/html;charset=UTF-8", MIMEEntity.ENC_IDENTITY_7BIT); | |
//Save the document | |
doc.save(true, true); | |
//Open the document | |
NotesDatabaseData dataDB = new NotesDatabaseData(db); | |
ws.composeDocument(dataDB,doc); | |
//clean up everything | |
stream.close(); | |
body.recycle(); | |
doc.recycle(); | |
db.recycle(); | |
directory.recycle(); | |
//Restore conversion | |
session.setConvertMime(true); | |
return Status.OK_STATUS; | |
} | |
}; | |
job.schedule(); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment