Email:   
Home
In This Issue
EasyPrint
Click here for the RSS feed's XML code. This is not a browser URL.
Getting inside the code of the automated signature generator (continued)

You can see how the @commands edit the text and insert the placeholder as bold, red text with the bounding characters.

When the template is processed as part of making the signature, the Render HTML and Format the Text clicks use LotusScript to do the replacement. The key lines of code are below. I've removed a few case entries to simplify and numbered them to call them out.

01 i = Instr(text,"#%")
02 Do While i > 0
03 j = Instr(text,"%#")
04 If j < i Then
05 Msgbox "Template is not properly formatted; terminating field replacement"
06 Exit Do
07 Else
08 fieldname = Mid(text,i+2,j-(i+2))
09 Select Case Ucase(fieldname)
10 Case "HTTP": text = Mid(text,1,i-1) & doc.http(0) & Mid(text,j+2)
11 Case "HTTP_1": text = Mid(text,1,i-1) & doc.http_1(0) & Mid(text,j+2)
12 Case "USERNAME": text = Mid(text,1,i-1) & doc.username(0) & Mid(text,j+2)
13 Case "EMAIL": text = Mid(text,1,i-1) & doc.email(0) & Mid(text,j+2)
14 << several Case statements removed here >>
15 Case "STRAPLINE": text = Mid(text,1,i-1) & doc.Strapline(0) & Mid(text,j+2)
16 End Select
17 End If
18 i = Instr(text,"#%")
19 Loop:

At line 01, we find the beginning of the next placeholder in the template text. If there are none, i will be 0 and the loop at 2 never starts. We'll assume there is at least one placeholder.

At line 03, we find the next end placeholder, which is fair to assume matches the start. Identifiers i and j now point to the start and end placeholders. Note that there is a check that j is greater than i at line 04 and we blow out if not, because the data is bad.

Line 08 then pulls out the placeholder name, and then the case statement between lines 09 and 16 examines that name and replaces the placeholder and the placeholder characters #%..%# with the actual value to be used. We then find a new value for i from the next placeholder, and go round again.

Getting the application to render HTML directly on to the screen in Notes 6 and above is easy. If you look at the HTML template, you can see just how easy it is, as shown in Figure A.

FIGURE A

Getting HTML to render is easy. Click picture for a larger image.

The HTML template is copied to the Computed Text, which is marked as Passthru HTML. When the Render HTML button is clicked it merely closes and reopens the UIDoc. That causes the Notes client to render the HTML. The main Signature Block create form does something very similar when you hit the Render HTML button, again, assuming you use a Notes 6 or above client.

For R5, life was a bit harder. Here's the code fragment that actually does it, taken from the Render HTML button in the HTML template:

01 If sess.notesbuildversion <= "166" Then 'R5 - we have to launch a browser
02 Print "Launching your browser to display the HTML.... please wait"
03 'write the HTML as a file in the Notes data directory
04 Set uidoc = wk.CurrentDocument
05 Dim fileNum As Integer
06 fileNum% = Freefile()
07 NotesDataDir = sess.getenvironmentstring("Directory", True)
08 HTMLFile = NotesDataDir & "\MailSigTemplateHTML.htm"
09 Open HTMLFile For Output As fileNum%
10 Print #fileNum%, Uidoc.fieldgettext("HTMLTemplate")
11 Close #filenum
12 Dim db As NotesDatabase
13 Set db = sess.currentdatabase
14 Dim newdoc As New Notesdocument(db)
15 Call newdoc.ReplaceItemValue("$publicaccess","1")
16 Dim rt As New notesrichtextitem(newdoc, "RT")
17 Dim eo As notesembeddedobject
18 Set eo = rt.EmbedObject(EMBED_OBJECTLINK,"",htmlfile)
19 Call eo.activate(True) 'should fire up the browser.
20 'We dont save the document we just created.
21 Print ""
22 Else 'Notes 6 can render the HTML directly,
23 'close and reopen the form to get the RT reloaded and the passthru HTML rendered
24 Call uidoc.Save
25 Call uidoc.close
26 Call wk.editdocument(True, doc)
27 End If




[ Prev | Next ]

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
-- Advertisement --

Learn Notes and Domino 8 at your place and pace!
Learn Notes and Domino in your office and/or home! TLCC's highly acclaimed distance learning courses for users, developers, and admins will enhance your career and your resume.

The many included activities and demos will make you a pro! Expert instructor help is a click away.

Click here to try a FREE demo course!!

-- Advertisement --

The Ultimate Notes Domino Training Experience - Amsterdam, 11-13 November
Get in-depth technical training that you can put to use on the job right away at THE VIEW's Admin2008 and Lotus Developer2008 Europe! One registration gets you into your choice of over 70 new and updated expert know-how sessions, one-on-one consultations, hands-on labs, and more.

See complete agendas and register by 10 October to save 495 euros!
Copyright © 1998-2008, ZATZ Publishing. All rights reserved worldwide.
Editor's Login