1. 1
Coffee from a Friend:
Using Third Party Java Libraries
2014/03/18 –Matthew Fyleman
2. 2
Matthew Fyleman
21 Years as a Notes/Domino Developer
Mostly Working on:
Xpages conversions
Product development
Who Am I?
3. 3
Based on My Experiences
Beginner Level!
Using Java Generally in XPages
Will focus on .jar files, but will look at other ways of incorporating Java
What to use when
What is this Talk About?
4. 4
Why Java?
Advantages over SSJS
Java Options
Prepackaged Options
.jars packaged into Extension Libraries
OpenNTF.org
Apache POI Example
Raw Libraries
Deploying
Incorporation
Security
Creating .jars
Questions
What am I talking about?
5. 5
It has a better structure than ssjs
Strongly typed
Object Oriented from the ground up
It‘s a very useful skill
Widely used outside Notes/Domino
Encourages better programming practise
Why Java? – 1. The basics
7. 7
See also Stephan Wissel‘sblog post:
http://www.wissel.net/blog/d6plinks/SHWL-8SLCVR
Why Java? –3. Its Easier to Debug
8. 8
Why Java? –4. There are Lots of 3rd Party Libraries
Adobe Acrobat (PDF) Manipulation
Word and Excel Creation and Modification
XML parsing
... Many more
If you need it, there is probably a Java library out there
Tested and stable (relatively!)
9. 9
Raw Java
You’re already doing this!
Java Class Files
Better for development
.jars provide obfuscation
.jars are easily portable –write once use anywhere
Managed Beans
Much easier to create than you might think
Automatically work within a scope
.jar Files
Java Options
10. 10
Almost certainly done this already:
varvecThis= new java.util.Vector();
Can Import Packages
importPackage(java.util);
varvecThis= new Vector();
Can be a disadvantage, particularly for beginners!
Java Options –Raw Java
11. 11
Easy to create
In the code section under Java
Create new java class
Java Options –Class Files
12. 12
Need to generate constructor?
Under the source menu
Generate Constructor using ...
Getters and Setters?
Same menu
Correct indentation?
Same menu
Java Options –Getting Help From Eclipse
13. 13
Rules for Managed Beans
If you have a constructor, it must be parameterless
Fields in your class are only publically accessible through getters and setters
To support persistence it should implement the Serializableinterface
It needs an entry in the faces-config.xml file
See Per Laustenspage ‘Creating Your First managed bean for Xpages’
http://per.lausten.dk/blog/2012/02/creating-your-first- managed-bean-for-xpages.html
Java Options –Managed Beans
14. 14
You are probably not the first!
Check OpenNTF.org
Pre-Packaged into an Extension Library
Easy to Use
Documentation (?)
Once ext lib installed, no security settings to think about
Pre-Packaged Options
16. 16
Not Always Available
Extension Libraries need to be deployed to the server!
What can you do if this is not an option?
Pre-Packaged Options -Issues
17. 17
This was the situation I found myself in on a recent project
Customer needed .docxfile manipulation
Customer would not permit third party deployment to the server
Deployed the POI Libswithin my Application
No Deployment to the Server (technically speaking!)
Simple
Still had access to the Functionality
Use the Library ‘RAW‘
18. 18
Three Options:
1.Deploy to the server file system
Non-starter
2.Deploy under WEB-INF
Better but only use if you are 8.5.2 or lower
3.Deploy to jar area under ‘code‘
Best option
Deployment Options
19. 19
Java Libraries for manipulating Microsoft Word and Excel files
Open Source
Main library is poi-3.9-20121203.jar
But you will need others particularly if you wish to work on docxand xlsx
dom4j-1.6.1.jar
stax-api-1.0.1.jar
xmlbeans-2.3.0.jar
Apache POI Project
20. 20
To create an Excel spreadsheet using POI, have your code perform the following steps:
Create a workbook object:
varxl=new org.apache.poi.hssf.usermodel.HSSFWorkbook();
Add a sheet to the workbook:
varsheet = xl.createSheet("Sheet 1");
Apache POI Creating a Spreadsheet
21. 21
Add a row to the sheet
They start at 0
row = sheet.createRow(rowCount++);
Write data into cells into each row
cell = row.createCell((java.lang.Integer)(cellCount++));
cell.setCellValue(document.getItemValueString(“AField”));
Watch out!
Apache POI Creating a Spreadsheet
23. 23
Sooner or later you will hit this
Need to edit the ‘java.policy’ file
Proper way is to database specific entry
For Production Systems
Doesn’t work on Domino 9 ?
For Dev Environments You Can Cheat!
grant { permission java.security.AllPermission; };
See blog post ‘Java Security in Xpages’from Stephan Wissel:
http://www.wissel.net/blog/d6plinks/SHWL-8JYAT5
don‘t miss Nathan Freeman‘s comment!
Deployment -Security Issues
24. 24
Similar to working with Excel:
Get the document
Get document’s paragraphs
Get the text runs in the paragraphs
Search and replace in text runs
Get the tables
Iterate through the rows
Iterate through the cells
Do paragraph search and replace in each cell
Apache POI Search and Replace in Word
25. 25
Java Libraries for manipulating Adobe Acrobat (pdf) documents
Open Source –but Apache License!
Main library is itextpdf-5.5.0.jar
Unlike POI, this is all you need for basic PDFs
iTextPdf
26. 26
Its open source so its free, right?
Maybe, but check the license
E.g. Apache License
Free to use if your software is also distributed under an Apache License
Otherwise there may be a fee for commercial use
iText–OEM license, 125 desktops, approx. $3,000
Deployment -License Issues
27. 27
Doing a lot of @Formula conversion to SSJS
Encountering a lot of List Ops
SSJS has no built in permutation operations
Wanted a library of List Op utilities
What About My Own .jars
28. 28
In Domino:
Create the class files
Test and debug
Go to package explorer view
File export
Create the .jar
Deploy into your database
-Simple!
My Own jar
29. 29
We4IT –www.we4it.com
OpenNTF–www.openntf.org
Ulrich Krause –www.eknori.de
Wissel.net –Stephan Wissel‘sblog
XpagesPortable Command Guide –
Martin Donnelly et. al., IBM Press
Resources and Information