+ All Categories
Home > Technology > 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-libraries

Date post: 18-Nov-2014
Category:
Upload: ics-user-group
View: 476 times
Download: 2 times
Share this document with a friend
Description:
One of the great advantages of XPages is the ability to extend its functionality by adding your own Java libraries or third-party offerings. In fact, the functionality you want is often available in a readily consumable form on OpenNTF. But what do you do when it isn't? This session is about how to use third party Java libraries in your Xpages applications - installing them, interfacing with existing code, configuring security and optimisation. Join me, and take your application's functionality to new heights.
31
1 Coffee from a Friend: Using Third Party Java Libraries 2014/03/18 Matthew Fyleman
Transcript
Page 1: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

1

Coffee from a Friend:

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

Page 2: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

2

Matthew Fyleman

21 Years as a Notes/Domino Developer

Mostly Working on:

Xpages conversions

Product development

Who Am I?

Page 3: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

6

<<Demonstration>>

Why Java? – 2. Its Faster than SSJS

But not as much as you might think!

Page 7: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

7

See also Stephan Wissel‘sblog post:

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

Why Java? – 3. Its Easier to Debug

Page 8: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

11

Easy to create

In the code section under Java

Create new java class

Java Options – Class Files

Page 12: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

15

Demonstration

Pre-Packaged Options

Page 16: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

22

Demonstration

Deployment

Page 23: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

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: bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries

30

Questions?


Recommended