SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
1
The Road to Damascas –
A Conversion Experience:
LS and @Formula to SSJS
2014/03/17– Matthew Fyleman
2
 Matthew Fyleman
 21 YearsasaNotes/Domino Developer
 MostlyWorking on:
 Xpagesconversions
 Product development
Who AmI?
3
 Based on MyExperiences
 Converting LotusScript and @Formula to
SSJS
 Toolsthat can help – particularly regular
expressions
What isthisTalk About?
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?
5
Never!
When should you convert existing code?
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
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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
@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
 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
 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
 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
23
Questions?
24
matthew.fyleman@we4it.com

Mais conteúdo relacionado

Destaque

Destaque (14)

bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014
 
bccon-2014 dev04 domino_apps_reaching_up&out
bccon-2014 dev04 domino_apps_reaching_up&outbccon-2014 dev04 domino_apps_reaching_up&out
bccon-2014 dev04 domino_apps_reaching_up&out
 
bccon-2014 adm04 ibm-domino-64bit-all-you-need-to-know
bccon-2014 adm04 ibm-domino-64bit-all-you-need-to-knowbccon-2014 adm04 ibm-domino-64bit-all-you-need-to-know
bccon-2014 adm04 ibm-domino-64bit-all-you-need-to-know
 
bccon-2014-welcome
bccon-2014-welcomebccon-2014-welcome
bccon-2014-welcome
 
Slide Show
Slide ShowSlide Show
Slide Show
 
bccon-2014 adm05 ibm traveler-2013-and-beyond
bccon-2014 adm05 ibm traveler-2013-and-beyondbccon-2014 adm05 ibm traveler-2013-and-beyond
bccon-2014 adm05 ibm traveler-2013-and-beyond
 
bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries
bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-librariesbccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries
bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries
 
bccon-2014 com02 level-up_building_next_generation_business_applications
bccon-2014 com02 level-up_building_next_generation_business_applicationsbccon-2014 com02 level-up_building_next_generation_business_applications
bccon-2014 com02 level-up_building_next_generation_business_applications
 
bccon-2014 adm06 hony,_i_shrunk_the_data
bccon-2014 adm06 hony,_i_shrunk_the_databccon-2014 adm06 hony,_i_shrunk_the_data
bccon-2014 adm06 hony,_i_shrunk_the_data
 
Lotus iNotes をカスタマイズしてみよう
Lotus iNotes をカスタマイズしてみようLotus iNotes をカスタマイズしてみよう
Lotus iNotes をカスタマイズしてみよう
 
презентация Dancers 2.0
презентация Dancers 2.0презентация Dancers 2.0
презентация Dancers 2.0
 
bccon-2014 str06 ibm-notes-browser-plug-in_9.0.1
bccon-2014 str06 ibm-notes-browser-plug-in_9.0.1bccon-2014 str06 ibm-notes-browser-plug-in_9.0.1
bccon-2014 str06 ibm-notes-browser-plug-in_9.0.1
 
bccon-2014 str05 ibm-smart_cloud-for-social-business
bccon-2014 str05 ibm-smart_cloud-for-social-businessbccon-2014 str05 ibm-smart_cloud-for-social-business
bccon-2014 str05 ibm-smart_cloud-for-social-business
 
IBM iNotes 9.0 Social Edition のご紹介
IBM iNotes 9.0 Social Edition のご紹介IBM iNotes 9.0 Social Edition のご紹介
IBM iNotes 9.0 Social Edition のご紹介
 

Semelhante a bccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjs

SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
Sergey Karpushin
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love Game
Antony Stubbs
 

Semelhante a bccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjs (20)

Icsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjs
Icsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjsIcsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjs
Icsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjs
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love Game
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
mod_rewrite
mod_rewritemod_rewrite
mod_rewrite
 
The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala Makeover
 
Ruby
RubyRuby
Ruby
 
Unit 3-Javascript.pptx
Unit 3-Javascript.pptxUnit 3-Javascript.pptx
Unit 3-Javascript.pptx
 
mod_rewrite
mod_rewritemod_rewrite
mod_rewrite
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
 
Fancy talk
Fancy talkFancy talk
Fancy talk
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

bccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjs

  • 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?
  • 5. 5 Never! When should you convert existing code?
  • 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