T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2...

31
1 Coffee from a Friend: Using Third Party Java Libraries 2014/03/18 – Matthew Fyleman

Transcript of T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2...

Page 1: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

1

Coffee from a Friend:

Using Third Party Java Libraries2014/03/18 – Matthew Fyleman

Page 2: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

2

� Matthew Fyleman

� 21 Years as a Notes/Domino

Developer

� Mostly Working on:

� Xpages conversions

� Product development

Who Am I?

Page 3: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

6

<<Demonstration>>

Why Java? – 2. Its Faster than SSJS

But not as much as you might think!

Page 7: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

7

See also Stephan Wissel‘s blog post:

http://www.wissel.net/blog/d6plinks/SHWL-8SLCVR

Why Java? – 3. Its Easier to Debug

Page 8: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

11

� Easy to create

� In the code section under Java

� Create new java class

Java Options – Class Files

Page 12: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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 Laustens page ‘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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

15

� Demonstration

Pre-Packaged Options

Page 16: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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 Libs within my Application

� No Deployment to the Server (technically speaking!)

� Simple

� Still had access to the Functionality

Use the Library ‘RAW‘

Page 18: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

22

� Demonstration

Deployment

Page 23: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

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: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

29

�We4IT – www.we4it.com

�OpenNTF – www.openntf.org

�Ulrich Krause – www.eknori.de

�Wissel.net – Stephan Wissel‘s blog

�Xpages Portable Command Guide –

Martin Donnelly et. al., IBM Press

Resources and Information

Page 30: T4S5-Xpages-coffe from a friend - AdminCamp · 2016. 7. 9. · 2014/03/18 – Matthew Fyleman. 2 Matthew Fyleman 21 Years as a Notes/Domino Developer Mostly Working on: Xpages conversions

30

Questions?