Subject: RE: You might not actually want a separate paragraph for each line…
Thanks Andre, I’ll take a look at that if I ever run into limitations with what I’ve come up with. What I was seeing without calling Update before editing the doc was truncation. And then even with Update added, the formatting I was doing went all weird - I was replacing the EOL character with my own (plus stuff), and at about the point where it truncated without using Update, with Update the EOL characters stopped appearing (but the other stuff was still there). Very weird, handling it with an array works nicely though so I don’t want to mess with it. 
So here is the long story of what I have ended up doing. If anyone can think of a better way and doesn’t mind sharing, I’d be interested to hear about it.
What I’m trying to do is get a default value for a rich text field, including formatting and tables and embedded images and whatnot. Without having a source rich text field available to copy from. So:
-
Get the rich text content as DXL.
-
Store it somewhere in the .nsf.
-
…create the new doc with the rich text field(s) on it that need default rich text content:
a. Get the stored DXL into a NotesStream.
b. Extract the DXL for the particular rich tex field that you want.
c. Make a copy of that element and append it to the new doc.
-
Easy Enough.
-
I tried getting the DXL and formatting it as a formula intending to just use it as a default value for an intermediate rich text field, but formulas have a size limit. So I tried formatting it as a LotusScript string intending to store it in code, but strings have a size limit. So I tried formatting it to store each line of DXL as a list value, and that works great. I’m sure I could bump into a limit on script library size if I tried (a bunch of text and tables and a couple medium images gives ~300k in ~900 lines), but hopefully by shrinking images and whatnot I can keep that in the distance. So I use this bit of code to grab the DXL of the selected doc and format it as code to populate a list in LotusScript and pop it up on a temp form:
Dim Session As New NotesSession
Dim SourceDoc As NotesDocument
Dim DestDoc As NotesDocument
Dim Text As NotesRichTextItem
Dim Exporter As NotesDXLExporter
Dim Stream As NotesStream
Dim DXL As String
Dim NewLines As Variant
Dim Counter As Long
Set SourceDoc = Session.CurrentDatabase.UnprocessedDocuments.GetFirstDocument
Set DestDoc = Session.CurrentDatabase.CreateDocument
DestDoc.Form = “SimpleFormWithSingleRichTextField”
Set Text = DestDoc.CreateRichTextItem( “RichTextFieldName” )
Set Stream = Session.CreateStream
Set Exporter = Session.CreateDXLExporter( SourceDoc, Stream )
Call Exporter.Process
Stream.Position = 0
DXL = Stream.ReadText
NewLines = Split( DXL, Chr(10) )
Forall NewLine In NewLines
NewLine = Replace( NewLine, |"|, |""| )
NewLine = | DefaultText( "| & Counter & |" ) = "| & NewLine & |"| & Chr(10)
Call Text.AppendText( NewLine )
Counter = Counter + 1
End Forall
Call Text.Update
Call Workspace.EditDocument( False, DestDoc )
Then I take the results of that code, copy it all and paste it into a new script library. The only other part of that script library is this line in declarations:
Dim DefaultText List As String
Now I have a global variable called DefaultText which is a list of all the lines of DXL needed to recreate that doc.
- By using that script library in any other code, I can read that list back into a NotesStream like this:
Set Stream = Session.CreateStream
Forall NewLine In DefaultText
Call Stream.WriteText( NewLine & Chr(10) )
End Forall
Then it’s relatively trivial to do your regular hook a NotesDOMParser up to the stream, and make copies of the rich text field elements you wan to get the content of (for that I found this very helpful ). Then create another NotesDXLImporter - NotesDOMParser - NOTESDXLImporter chain to stick them into your final destination doc.
So, a new database can be created anywhere based on this design, and with the touch of a button some rich text content can appear (not limited to what you could build by hand with the NotesRichText classes, and much more simply than attempting to roll your own DXL). And if the default rich text content ever needs to be changed, just lay out an example of what you want it to look like, hit a button, and copy the results into the script library and its there ready for the next time. Seems a little odd even to me, but hey it seems to work well 
I hope that helps someone, however unlikely it is that anyone else needs to do anything like this. Like I said if anyone has any advice (like, you don’t need to do any of that madness just do blah, or big deal so-and-so already did that over here) I’d be interested to hear it, even a simple opinion would be appreciated. Thanks again for your help everyone.