This document discusses options for converting LotusScript and @Formula code to SSJS. It begins by introducing the presenter and the topic. It then covers various conversion options like using NotesAgent.run(), search and replace, and dedicated tools. It provides tips for preparing code for conversion through search and replace by refactoring code. It also introduces regular expressions as useful tools. The document then provides examples of converting code elements like Dim statements, If statements, and field handling. It discusses issues like converting data types and user interaction. Finally, it discusses resources for further information.
1. 1
The Road to Damascas –
A Conversion Experience:
LS and @Formula to SSJS
2014/03/17– Matthew Fyleman
2. 2
Matthew Fyleman
21 YearsasaNotes/Domino Developer
MostlyWorking on:
Xpagesconversions
Product development
Who AmI?
3. 3
Based on MyExperiences
Converting LotusScript and @Formula to
SSJS
Toolsthat can help – particularly regular
expressions
What isthisTalk About?
4. 4
When should you convert existing
code?
Conversion Options
NotesAgent.run() with parameter doc
Search and Replace
Dedicated Tools
Search and Replace
Preparation
Introduction to Regular Expressions
Examplesand Demonstration
Tipsand Traps
Dedicated Tools
Questions
What amI talking about?
6. 6
What isthe problem?
It isalwaysgoing to beslow
GIGO
You will introducenew bugs
Re-developing will bequicker, cheaper and
you will end up with abetter result
But if you really must ...
When should you convert existing code?
7. 7
What are your options?
NotesAgent.run()
Quick and Dirty
Agent must run independently
Only usewhen agentsareavailableand timeiscritical
Search and Replace
LotusScript -> JavaScript (and Java)
Lessuseful for @Formula
Dedicated Tools
@Formula
Conversion Options
8. 8
Search and Replaceismost useful for LSconversion
Syntacticallysimilar
Easiest if you do alittlerefactoring first
Option Declare
doc.field(0) -> doc.getItemValue(“ Field“ )(0)
Camel CaseNotesObjects
MakeSureMethod callsareconsistentlynamed
Best to Avoid All-In-One-Go
Function or Sub at aTime
Variablewith onepurposein onelocation mayhaveadifferent useelsewhere
Converting LotusScript to SSJS- Preparation
9. 9
Regular Expressionsareyour new BFF
Sophisticated Pattern Matching
Elementsfromsearch can becarried through to
replace
TheSearch and Replacebuilt in to DDEcan use
Regular Expressions
Useful outsideLSconversion (e.g. Validation)
SeePlanet Lotus- http://planetlotus.org/profiles/ross-swick_97733
Regular Expressions
10. 10
Tidyup first – Option Declare, removeclustering e.g.:
Dimx asInteger,y asInteger,zasInteger
Wewant to match any variablenamein thepattern:
Dim<var name> As<Anyvalid type>
Fairly simple:
Dim[ ]+[A-Za-z0-9_]+[ ]+As[ ]+(Integer|String|Boolean|Double|Variant)
But how do wereplace?
Modifythesearch:
Dim[ ]+([w]*)[ ]+As[ ]+String
Usethisfor replace
var 1 = “ ” ;
Starting Simple– DimStatements
11. 11
For NotesObjects, Thingsaresimpler
Dim<var name> AsNotes<rest of object name>
- Ignore... AsNew NotesSession for now
Also, initialising in SSJS, = null isok:
var <var name>:Notes<rest of object name> = null;
So our termsare:
Search:
Dim[ ]+([w]*)[ ]+As[ ]+(Notes[w]*)
Replace:
var 1:2 = null;
Starting Simple– DimStatements(2)
12. 12
For themost part, simpleS& R(but order isimportant):
End If to }
[ ]*Then to ) {
Else[ ]+If[ ]* to } elseif (
If[ ]* to if (
But what about:
If (x = 10) Then
UseSearch: If[ ]+([w()[].<>" ]*)=([w()[].<> "]*)[ ]+Then
UseReplace: if (1==2) {
NB: Worksbut not optimal!
Other comparison operatorsnot aproblem
A bit morecomplex – If Statements
13. 13
Theproblem:
Session object isglobal in ssjs: ‘session’
In LSit iscreated:
DimsessAsNew NotesSession
Need to find all LSsession objects, and replacewith session
How do you get alist of session object names?
! – session objects
You need a coffee!
14. 14
JavaString Object hasregex search and replace
String source = “Dim x As String”;
String result = source.replaceAll(“Dim[ ]+([w]*)[ ]+As[ ]+String”, “var $1 = “”;”);
Pattern and Matcher objectsmakethiseven morepowerful
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(this.source);
int startPos = 0;
while (m.find(startPos)) {
if (!itemList.contains(m.group(1))) {
itemList.add(m.group(1));
}
startPos = m.end() + 1;
}
Adding Java
15. 15
Similar Issueto Session
Need to find all document object names, and replacefield handling
methods
Will probablyneed to handledot notation
Arrgghh!
How do you search for dot notation?
<doc name>.([^GetItemValue])([0-9]+)
Still hard work!
Field Handling
16. 16
Thereareother typesthan string!
Alwaysreview and test converted codethoroughly
Datehandling isapain
Script librariescan help here– Java?
Watch out for User interaction and particularly dialogues
Work out your strategiesin advance!
Search and Replace– Tipsand Traps
17. 17
In somerespects@Formula -> SSJSiseasier than LS-> SSJS
@Formula JavaScript Wrappershelp alot
Mostly just ‘;’ to ‘,’, and converting liststo arrays
Someconstructionsareobvious:
@SetField(“ Field” , Value);
Goesto:
doc.replaceItemValue(“ Field” , Value);
Or
S: @SetField([ ]*([w” ]*)[ ]*,[ ]*([w” ]*)[ ]*);
R: doc.replaceItemValue(1, 2);
But therearesomeissues...
Converting Formula
@
18. 18
No direct equivalent in SSJSfor *+, *= *>= etc.
when applied to Lists
Need to plan for this
JavaClass/Library to providedirect substitute
Unfortunately, Javadoesnot permit operator
overloading, so hasto beaset of methods
Converting Formula – List Processing
@!
19. 19
@If(@Contains(_WFData_neu;_Key);"";
@Do(
@Set("_Sachgebiet_Zuordnung";@DbLookup("NOTES":"NOCACHE";"":_ADM$StructureDB;"Workflows";"WFArbeitsanweisung";"Sachgebietzuordn
ung"));
@If(_Sachgebiet_Zuordnung= "" | !@Contains(_Sachgebiet_Zuordnung;_Key2);@Do(
@Prompt([Ok];"Hinweis";"Inder SystemStruktur VBM wurdefür dasaktuelleSachgebiet kein Workflow definiert. DasDokument wird zumehemaligen
Kompetenzträger zurückgegeben, damit dieser ein neuesSachgebiet auswählenkann.");
@Set("_Kompetenzträger";Bearbeiter1);
@Set("_tmpintern";5)
);
@Do(
@Prompt([Ok];"Hinweis";"Inder SystemStruktur VBM wurdefür dasaktuelleSachgebiet ein neuesSachgebiet konfiguriert. DasDokument wird zum
Kompetenzträger zurückgegeben, damit dieser dasneueSachgebiet auswählenkann.");
@Set("_neues_Sachgebiet";@Left(@Right(_Sachgebiet_Zuordnung;_key2);"||"));
@Set("_Elements";@Elements(@Explode(@Left(@Left(@Right(_WFData_neu;"||Sachgebiet#");"||"); _neues_Sachgebiet)+ _neues_Sachgebiet; "$"
)));
@Set("_KompetenzträgerData";@Explode(@Left(@Right(_WFData_neu;"||Kompetenzträger#");"||"); "$"));
@Set("_Kompetenzträger";@Subset(@Subset(_KompetenzträgerData;_Elements);-1));
@Set("_tmpintern";6)
)
)
)
);
Converting Formula - @If, @Do and @While
@!!!
20. 20
Search and Replacecan beused for @Formula ->
SSJS...
... but it can only takeyou so far
Adedicated parser can go further
Onlyreal alternativeto manual translation for complex
statements
Timeconsuming to create
Still not asilver bullet
Parsers
21. 21
Espresso - http://www.ultrapico.com/Expresso.htm
Good for learning regex, and seriousregex dev
Free!
PowerGREP
Sophisticated regex filesearch
Whereregex started (UNIXgrep)!
Expensive
Dedicated Tools
22. 22
We4IT– www.we4it.com
OpenNTF– www.openntf.org
Regex Quick Reference
http://www.night-ray.com/regex.pdf
Loadsof websitesfor all aspectsof regex development
Mastering Regular Expressions– JeffreyE.F. Friedl –
O’ReillyPublishing
Resourcesand Information