wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

By Date: March 2008

Domino Design Code Injection - Part 2


In Part 1 I introduced the approach to code injection and some sample LotusScript Code to pull a design element, transform it and push it back. Missing there was the function that actually implemented that method. I'm using a Java class to do that, which I wrap into LS2J. The LotusScript function looks like this:
 
Option Public Option Declare Uselsx "*javacon" Use "CodeInjector" Function injectCode (rawDXL As String , xPath As String , codeSnippet As String ) As String 'Dummy doesn't do anything Dim jSession As JAVASESSION Dim injectorClass As JAVACLASS Dim injector As JavaObject Set jSession = New JAVASESSION injectCode = rawDXL Set injectorClass = jSession .GetClass ( "DominoXPathInjector" ) Set injector = injectorClass . CreateObject 'Now set the document Call injector .setDocument (rawDXL ) 'and execute the function injectCode = injector .injectCode (codeSnippet , xPath , 4 ) End Function
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
Now let us have a quick look at the Java class.

Read more

Posted by on 21 March 2008 | Comments (0) | categories: Show-N-Tell Thursday

Domino Design Code Injection


In an earlier entry I discussed how to maintain custom system databases. It works well when you add design elements or change them wholesale. However it doesn't work very well when you tweak design elements. Something like: adding one action in a form or using a different subform for a specific task. Once an updated system template is available, you have to go back and recreate all your changes in your template.
This entry discusses how to automate these little fixes. There are a number of moving parts involved:
  1. Export the design element using DXL. (You might need to set NotesDXLExporter.RichTextOption = RICHTEXTOPTION_RAW to make sure the fidelity of forms is maintained)
  2. Locate the entry/replace point. The best mechanism for that is XPath
  3. Locate the new code. This could be as easy as provide a string with the XML Snippet to pointing to an existing design element elsewhere. (We would use XPath again)
  4. Perform the insertion/replacement. We will have the option: before/after/replace
  5. Write back your changes and test it
What type of code injections come to my mind:
  • Add an action to a form/view
  • Add a subform to a form
  • Replace a validation formula in a field
  • Insert a script library and a custom class into a form
  • Add a field at the top or bottom of a form (our favorite hidden fields $$Return anyone
Understanding DXL and XPath is key to make this work. As a Domino developer (and you are one? Otherwise all this might sound Greek and Latin to you) you have seen DXL and its description in the help file. XPath might be less familiar. In a nutshell: XPath is to XML what SQL is to relational data. When you develop XML Stylesheets (a.k.a. XSLT) you use XPath selectors to define your template matches. XPath is a set language, so you better remember your kindergarden days (give me all shapes that are blue, triangle and big). It is easy to get an overview and to get started and can get as complex as you can take it. One little caveat (you see Latin is creeping it): XPath is case sensitive
Some simple examples:
  • * selects ANY element.
  • / selects the root element, basically before any tags in the XML
  • /database/form/actionbar selects the actionbar elements in all forms in our XML
  • /database/form[1]/actionbar selects the actionbar element in the first form in our XML
  • /database/form[@name='Message']/actionbar selects the actionbar element in the form Message in our XML
  • /database/form[@name='Message'] //field[@name='Subject'] /code[@event='defaultvalue'] /formula Select the default value formula for the field "Subject". Please note the double slashes in front of the field. They are intentional. One slash says: a child, two slashes says any decendant down the document. Also: no spaces before/after the slashes. They are here for readablitity only.
  • //field[code/@event='inputvalidation'] Any field that has an input validation formula
You get the idea. You want to have a good XML editor.

Read more

Posted by on 21 March 2008 | Comments (2) | categories: Show-N-Tell Thursday