icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries
DESCRIPTION
ICS User Group Conference 2014 - XPages using third party java librariesTRANSCRIPT
![Page 1: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/1.jpg)
1
Coffee from a Friend:
Using Third Party Java Libraries2014/03/18 – Matthew Fyleman
![Page 2: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/2.jpg)
2
Matthew Fyleman
21 Years as a Notes/Domino Developer
Mostly Working on:
Xpages conversions
Product development
Who Am I?
![Page 3: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/3.jpg)
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?
![Page 4: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/4.jpg)
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?
![Page 5: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/5.jpg)
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
![Page 6: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/6.jpg)
6
<<Demonstration>>
Why Java? – 2. Its Faster than SSJS
But not as much as you might think!
![Page 7: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/7.jpg)
7
See also Stephan Wissel‘sblog post:
http://www.wissel.net/blog/d6plinks/SHWL-8SLCVR
Why Java? – 3. Its Easier to Debug
![Page 8: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/8.jpg)
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!)
![Page 9: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/9.jpg)
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
![Page 10: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/10.jpg)
10
Almost certainly done this already:
var vecThis= new java.util.Vector();
Can Import Packages
importPackage(java.util);
var vecThis= new Vector();
Can be a disadvantage, particularly for beginners!
Java Options – Raw Java
![Page 11: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/11.jpg)
11
Easy to create
In the code section under Java
Create new java class
Java Options – Class Files
![Page 12: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/12.jpg)
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
![Page 13: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/13.jpg)
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 Serializable interface
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
![Page 14: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/14.jpg)
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
![Page 15: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/15.jpg)
15
Demonstration
Pre-Packaged Options
![Page 16: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/16.jpg)
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
![Page 17: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/17.jpg)
17
This was the situation I found myself in on a recent project
Customer needed .docx file 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‘
![Page 18: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/18.jpg)
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
![Page 19: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/19.jpg)
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 docx and xlsx
dom4j-1.6.1.jar
stax-api-1.0.1.jar
xmlbeans-2.3.0.jar
Apache POI Project
![Page 20: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/20.jpg)
20
To create an Excel spreadsheet using POI, have your
code perform the following steps:
Create a workbook object:
var xl=new org.apache.poi.hssf.usermodel.HSSFWorkbook();
Add a sheet to the workbook:
var sheet = xl.createSheet("Sheet 1");
Apache POI Creating a Spreadsheet
![Page 21: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/21.jpg)
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
![Page 22: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/22.jpg)
22
Demonstration
Deployment
![Page 23: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/23.jpg)
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
![Page 24: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/24.jpg)
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
![Page 25: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/25.jpg)
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
![Page 26: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/26.jpg)
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
![Page 27: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/27.jpg)
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
![Page 28: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/28.jpg)
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
![Page 29: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/29.jpg)
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
![Page 30: Icsug conf 14_dev02_xpages-coffe-from-a-friend-using-third-party-java-libraries](https://reader034.vdocuments.site/reader034/viewer/2022052622/558e66fd1a28ab92218b46d1/html5/thumbnails/30.jpg)
30
Questions?