JMP101: Java for XPages
Development
Paul T. Calhoun, Panagenga

© 2014 IBM Corporation
Your Presenter – This Is Me!
 Paul T. Calhoun
Senior Software Engineer - paul.calhoun@panagenda.com
Owner – NetNotes Solu...
Agenda
 The Java Language Fundamentals
 Domino Designer Settings
 Java Beans and Managed Beans
 Calling Java Code from...
The Java Language Fundamentals

4
How do you eat an Elephant ?
 One Bite at a time !!!
 Learning Java™ is a lot like eating an Elephant !!
– It’s a big jo...
Resources
 Start with J2SE (Java 2 STANDARD Edition)
– This covers core Java functionality
• Syntax
• Data Types
• Constr...
Resources
 Learn XML (not part of Sun Certification)
– XML Syntax
– DTD/XML Schema
– XSL
• XSLT
• XSL:FO
 Finally jump o...
Roadblocks
 Road Blocks on your Journey to Learning Java
– “Linear” thinking instead of thinking in “Objects”
• If you ha...
Very Wise Saying
If the only tool you have is a hammer,
you tend to see every problem as a nail

Abraham Maslow
Your XPages Development Toolbox
CSS

Formula Language

LotusScript

XML
dojo
JavaScript

Java
XSLT

jQuery
Is the Java Language still relevant ?
 The Tiobe index as of December 2013

http://www.tiobe.com/index.php/content/paperi...
Java Version in Notes / Domino
Java Standard Edition (J2SE)
Java 2 Java Development Kit (JDK)

Used in Notes Domino 9.0 an...
Domino Designer Settings

13
Configuring Domino Designer for XPage Development
 There are several things that can be configured that will make your Ja...
Configuring Domino Designer for XPage Development
Configure Memory

 Change your memory allocation
– Edit the jvm.propert...
Configuring Domino Designer for XPage Development
Configure Memory

 Edit with any text editor
– Xmx – Total amount of RA...
Configuring Domino Designer for XPage Development
Show Heap Status

 Monitor Memory Used
 In Designer Preferences
– Sele...
Configuring Domino Designer for XPage Development
Configure XML Editor settings

 Set XML Editor formatting for viewing X...
Configuring Domino Designer for XPage Development
Formatting Differences

 Before and after XPage Source Formatting

19
Configuring Domino Designer for XPage Development
Change Java Editor Margin

 In the Designer Preferences dialog, choose ...
Configuring Domino Designer for XPage Development
Change Java Editor Margin

 Select the “Line Wrapping” tab
– Change the...
Configuring Domino Designer for XPage Development
Change Java Editor Margin

 Ensure your profile is the active profile a...
Code Snippets
 When writing Java code in any Java Editor developers can copy code “snippets” to the
snippet plugin.
 Cho...
Code Snippets
 Type “Snippet” into the search field
 Select “Snippets” and choose OK

24
Code Snippets
 Snippet View is added to Current Perspective

25
Code Snippets
 Highlight code in the editor
 Right click and choose Add to Snippets…
 A prompt to add to an existing ca...
Code Snippets
 Provide a Name for the Snippet that will appear in the snippet view under the category

27
Using Code Snippets
 To use a code snippet
– Place the cursor in the Java editor where the code should be inserted.
– Dou...
Code Snippet Categories can be Imported/Exported to
XML
 Right click the Snippet View and choose “Customize”
 In the edi...
Demo

Java Settings in Domino Designer

30
Java Beans and Managed Beans

31
Java Beans versus Managed Beans
 This is possibly one of the most confusing issues when coding with Java
 Lets start wit...
Java Beans versus Managed Beans
 So what is a Managed Bean?
 It is important to understand that it makes no difference i...
A Java Bean Example
 Lets start with a simple Java Bean Example

34
A Java Bean Example
 Public “getter” and “setters”

35
Calling the Methods from an XPage
 Button Code
– The SSJS Code
– In order to “use” the Java Bean Code it has to be instan...
Demo

A Java Bean

37
Making that same code a “Managed Bean”
 Java code becomes a “Managed Bean” when it is registered with the framework it is...
Faces Confg
 The faces-config.xml file is an xml file where managed beans are defined using the following
syntax
<managed...
Registration components
 The description is just that, a short description of what the bean does
 The name will be the p...
Calling the Methods from an XPage
 Button Code
– The SSJS Code
– In order to “use” the Managed Bean Code simply call the ...
Benefits of Managed Bean
 Managed Beans have scope
 This means
– The setter methods can be executed in one event and
– T...
Demo

Managed Beans

43
Calling Java Code from an XPage

44
Executing Java Code from an XPage
 The only Java code that can be “called” from an XPage is
– Java Code Elements
– Java S...
Executing Java Code from an XPage
Java Code Elements

 Create Java source code that will be compiled into individual clas...
Executing Java Code from an XPage

Java Source Code in a source folders in the Virtual File System (VFS)
 Java Source cod...
Executing Java Code from an XPage
Code in .jar files located in the JARs folder

 Locally developed or third party Java A...
Executing Java Code from an XPage

Compiled .class and .jar files located in the jvm/lib/ext folder in the file system
 ....
Referencing Java Code and Calling Methods from SSJS
 Java code is instantiated and called from an SSJS event
– Import the...
Demo

Calling Java code from SSJS

51
Accessing Domino Objects

52
Session
 The Notes Session object is the top level object in the Domino class hierarchy
 It’s the starting point for cal...
Session
 Pass the global “session” variable in as a parameter
– The SSJS Code
importPackage(com.nnsu.domino);
var jce:Dom...
Session
 Get it from the JSF “context”, the underlying architecture
import javax.faces.context.FacesContext;

import lotu...
Session
 Once there is a “session” object the rest of the Domino class hierarchy can be traversed
 Database
 View
 Vie...
Recycling Domino Objects
 Recycling is something that is unique to working with the Domino Object API
 If done correctly...
Recycling Domino Objects
 In a for or while loop create two objects
 Set the value of the first one
 Process it
 Set t...
Demo

Domino Objects

59
Using Third Party Libraries

60
Development Setup
 There are two choices when configuring an application to use third party Java libraries
– Put all the ...
Put all the JARS in the NSF
 Pros
– Makes the application more portable.
– Can be “deployed” to the test server and produ...
Put the JARS on Host File System
 Pros
– Easier to maintain code/upgrade code for all applications that use it
 Cons
– H...
Development Setup
 I prefer the deploy the JARS to the Host File system
– (Insert self referencing Evil Admin Comment her...
Development Setup
 The JARS can also be added to the NSF container when developing XPages.
– This is the option I’m using...
Development Setup
 In 8.5.3 and below
– In the Application that will contain the XPage Code
• From the XPages perspective...
Development Setup
 In 9.0
– Import the Jars to the new “JAR” design element
– This will automatically add it to the class...
Third Party Libraries
 Third party libraries can come from a variety of sources
– Open Source
– Purchased from vendors
 ...
What is APACHE ?
 The Apache Software Foundation (www.apache.org)
– Is an Open Source (Yes that means FREE) consortium of...
What is APACHE ?
 IBM is a major contributor/supporter
 If you develop using Java code (and you should be) than you owe ...
We will explore the following
 There are too many projects to cover so we will explore three of the most popular and usef...
Apache Commons
 http://commons.apache.org
 Focused on all aspects of reusable Java components
Commons Proper
 Commons Proper
– Goal of creating and maintaining reusable java Components
 Individual downloadable comp...
Commons Proper
 Each of the following components can be downloaded individually
Component
Attributes

Runtime API to meta...
Commons Proper
Component
Discovery

Tools for locating resources by mapping service/reference names to resource names.

EL...
Commons Proper
Component
Launcher

Cross platform Java application launcher.

Logging

Wrapper around a variety of logging...
Commons Lang
 Provides a host of helper utilities for the java.lang API
– String manipulation methods
– Basic numerical m...
Commons Lang - Versions
 Latest Version is 3.3.1
– For Java 1.5 and higher
– For Notes/Domino 8.x and 9.x
 Version 2.6 i...
Commons Lang API
Packages
org.apache.commons.lang3
org.apache.commons.lang3.builder

Provides highly reusable static utili...
org.apache.commons.lang3.StringUtils
 IsEmpty/IsBlank - checks if a String contains text
 Trim/Strip - removes leading a...
org.apache.commons.lang3.StringUtils
 ContainsOnly/ContainsNone/ContainsAny - does String contains only/none/any of these...
org.apache.commons.lang3.StringUtils
 Chomp/Chop - removes the last part of a String
 LeftPad/RightPad/Center/Repeat - p...
org.apache.commons.lang3.StringUtils
 IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String...
Demo

Commons StringUtils

84
Apache POI
 POI is a Java API for Microsoft Documents
– Not just spreadsheets, but what it’s used most often for
– Which ...
Apache POI
 POI can “Read” and “Write” to MS and Open source versions of
– Spreadsheets
– Word Processing documents
– Pre...
Use Cases
 Although POI can be used to create many types of MS Office formats we will concentrate on
spread sheets
 Ther...
Export All Documents From a View
 This is the primary use case
– Create an XPage that displays the View
• This isn’t real...
The Button Code

SSJS code on onClick event of component
//Import the Java code package
importPackage(com.nnsu.util);

//C...
The Java Code
 The Java code has one method “createSpreadSheet” that accepts the parameters from the
SSJS code
package co...
The Java Code
 Use the POI API to create the objects necessary to create a spreadsheet
// Create a new Workbook object fr...
The Java Code
 Process every document in the view and create a “row” in the spreadsheet output
// Get the first document ...
The Java Code
 Set the width of each column to the width of the longest entry in that column
 “Write” the output of the ...
Demo

Export All Documents in a View to a Spreadsheet

94
Exporting Selected Document from a View
 The base code and setup are the same with the following exceptions
– A View cont...
Exporting Selected Document from a View
 The Java code receives the selected documents as an array of string id’s
 In th...
Demo

Export Selected Documents in a View to a Spreadsheet

97
Exporting Query Result Documents
 A Notes Document collection can be returned programmatically
 The query generally incl...
SSJS to Capture the parameters
 The SSJS code captures the parameters from the XPage components
//Import the Java code pa...
SSJS to Capture the parameters
 The parameters are then passed to the java code to be processed
…

//Pass the variables t...
Java code to process the parameters
 The Java code uses the passed in parameters to create a Notes Document Collection fr...
Demo

Export Query Results Documents to a Spreadsheet

102
Bonus Material
 Using APACHE FOP to Create PDF’s

103
So what is FOP?
 FOP is a sub-project of the XML Graphics project at APACHE
 FOP stands for Formatting Objects Processor...
So what is FOP?
 An API that
– Reads an FO Tree
– Renders the resulting pages to a specified output
• PDF (Primary)
• PS
...
Um.. How about that again in English !!
 It’s a java based toolset that lets YOU (the developer) create solutions that al...
The Process
 The great thing about FOP is it is a highly duplicable design pattern

XML Source

XSLT StyleSheet

FO Rende...
The Process
 It all starts with an XML Document (can be from disk or in memory)

XML Source

XSLT StyleSheet

FO Renderin...
The XML
 The XML can be
– A Static Document
– The output from ?ReadViewEntries
• Appended to the end of a Domino View URL...
The XML
 The source of the XML is not as important as the FORMAT and CONSISTANCY of the XML
– The XML must be well formed...
The XML
 Using the ?ReadViewEntries option is HIGHLY duplicable
– Once you have the stylesheet (and I’m providing that to...
The XML
 The other options require an XSLT stylesheet that is specific to transforming the specified
XML to FO XML.
– Thi...
The Stylesheet
 The stylesheet that is used is an XSLT document (written in XML) that uses the FOP tags
from the tag libr...
The XSL FO Stylesheet
 This is by far the most challenging part of this solution
 Stylesheet creators must be able to cr...
Using Eclipse or an XSLT editor is the best choice
 Download the version that has the Web Tools Plugin (WTP)
 I usually ...
The XSLT
 The Stylesheet is made up of a combination of XSLT and XSL:FO tags
Structure of the FO Tags
 The XSL:FO tags are all about the layout of the “printed” page
 XSL:FO tags always start with ...
The Layout and Page Master
 These tags define the output page
– Height
– Width
– Margins
– etc
The Page Sequence tag
 References the page master set tag to get its output constraints
The Page Content
 The Page content is the output using a series of “flows” and “blocks”
 A “flow” contains a series of “...
The Page Content
 Blocks can contain other constraining tags like the “table” tag
Where are the stylesheets Stored
 After the stylesheet is created there are two options
– Save the stylesheet as a design...
Storing Stylesheets in Designer
 The XSLT Sheets can be
stored in DDE in the Style
Sheets folder contained in
the resourc...
Alternately Store in documents
 You can create a
– Form
– View
 to store Notes documents that contain the XSLT styleshee...
The Code
 Now that you have the XML Source and the XSLT stylesheet you are ready to write some
code !!! (Yea !!)

 Can b...
Creating the FO Source
 The code will take the XSLT stylesheet, apply it to the XML source and produce the XSL:FO
that is...
The Code
 The “SSJS” button code that calls the Java Code
The Java Code that creates the PDF
 The Java Code takes the output stream as a parameter, reads the XML and XSLT and uses...
The Complete Process
 That finishes the design pattern

XML Source

XSLT StyleSheet

FO Rendering
FO Source

Engine

Rend...
Demo

Create PDF from Domino Data

130
Resources
 IBM XPages Forum – Moderated by the community
– http://www-10.lotus.com/ldd/xpagesforum.nsf/
 TLCC – Self pac...
 Access Connect Online to complete your session surveys using any:
– Web or mobile browser
– Connect Online kiosk onsite
...
Your Turn !!!
Questions, Questions, Questions !!!!

133
Acknowledgements and Disclaimers
Availability. References in this presentation to IBM products, programs, or services do n...
Upcoming SlideShare
Loading in …5
×

Connect 2014 JMP101: Java for XPages Development

4,612 views

Published on

Paul T. Calhoun, panagenda

IBM Connect 2014, Orlando

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,612
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
100
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Connect 2014 JMP101: Java for XPages Development

  1. 1. JMP101: Java for XPages Development Paul T. Calhoun, Panagenga © 2014 IBM Corporation
  2. 2. Your Presenter – This Is Me!  Paul T. Calhoun Senior Software Engineer - paul.calhoun@panagenda.com Owner – NetNotes Solutions Unlimited, Inc. - pcalhoun@nnsu.com  A highly rated architect, engineer, speaker and presenter who provides customer-focused knowledge transfer and consulting to organizations worldwide.  I have architected Domino, Web, Java, and XML Web Services solutions for his customers using Domino and WebSphere/WebSphere Portal as the primary platforms.  I am the co-author of the IBM Redbook “XML Powered by Domino,” have developed self paced and classroom training for XPages, XML and Web Services as well as Java. I have written dozens of articles for worldwide technical publications.  IBM Champion – 2013 and 2014  Certified – Administrator and Developer  Grandfather of two and ½. – Ask to see my pictures !!!
  3. 3. Agenda  The Java Language Fundamentals  Domino Designer Settings  Java Beans and Managed Beans  Calling Java Code from an XPage  Accessing Domino Objects  Using Third Party Libraries  Wrap Up
  4. 4. The Java Language Fundamentals 4
  5. 5. How do you eat an Elephant ?  One Bite at a time !!!  Learning Java™ is a lot like eating an Elephant !! – It’s a big job !! – And there’s no clear place where to start !!
  6. 6. Resources  Start with J2SE (Java 2 STANDARD Edition) – This covers core Java functionality • Syntax • Data Types • Constructs • Core Classes - java.lang - java.io - java.net - etc. – Allow 3-6 Months http://www.oracle.com/technetwork/java/javase/overview/index.html
  7. 7. Resources  Learn XML (not part of Sun Certification) – XML Syntax – DTD/XML Schema – XSL • XSLT • XSL:FO  Finally jump on the J2E bandwagon (In this order!) – Servlets – JSPs – JSFs – Allow another 3-6 months  Then the rest of the J2E specification – Allow another 3-6 months
  8. 8. Roadblocks  Road Blocks on your Journey to Learning Java – “Linear” thinking instead of thinking in “Objects” • If you have done any LotusScript Class development you are on your way ! – Starting to learn Java with J2E applications (Servlets, JSPs) – Trying to start with the Java Enterprise Technologies – Try to learn Java in conjunction with a HUGE Mission critical project – Not applying what you learn EVERYDAY !! • This is the MOST critical roadblock !!!
  9. 9. Very Wise Saying If the only tool you have is a hammer, you tend to see every problem as a nail Abraham Maslow
  10. 10. Your XPages Development Toolbox CSS Formula Language LotusScript XML dojo JavaScript Java XSLT jQuery
  11. 11. Is the Java Language still relevant ?  The Tiobe index as of December 2013 http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  12. 12. Java Version in Notes / Domino Java Standard Edition (J2SE) Java 2 Java Development Kit (JDK) Used in Notes Domino 9.0 and 8.5 Java 2 Java Development Kit (JDK) Version 1.5.0 Used in Notes Domino 8 Java 2 Software Development Kit (SDK) Version 1.4.2 Used in Notes Domino 7 Java 2 Software Development Kit (SDK) Version 1.4.1 (EOL) Java 2 Software Development Kit (SDK) Version 1.4.0 (EOL) Java 2 Software Development Kit (SDK) Version 1.3.1 Java 2 Software Development Kit (SDK) Version 1.3.0 (EOL) Java 2 Software Development Kit (SDK) Version 1.2.2 Java 1 JDK Development Kit (JDK) 12 Version 6.0 Version 1.1.8 Used in Notes Domino 6 Used in Notes Domino 5
  13. 13. Domino Designer Settings 13
  14. 14. Configuring Domino Designer for XPage Development  There are several things that can be configured that will make your Java in XPages development experience easier  The following are recommendations for setting properties in the Domino Designer BEFORE you start developing 14
  15. 15. Configuring Domino Designer for XPage Development Configure Memory  Change your memory allocation – Edit the jvm.properties file located in the client installation directory under • framework/rcp/deploy
  16. 16. Configuring Domino Designer for XPage Development Configure Memory  Edit with any text editor – Xmx – Total amount of RAM for Designer AND Client • Set to at least 512m • Don’t set equal to the amount of system RAM – Xms – Starting Heap size • Set to at least 128m • Don’t set equal to Xmx value – Xmca – Memory block size • Set to at least 512k • Thanks a “k” NOT A “m”  Always set in multiple of “4”  Will not take effect until client is restarted if it is running when edited
  17. 17. Configuring Domino Designer for XPage Development Show Heap Status  Monitor Memory Used  In Designer Preferences – Select General – Check “Show heap status”  Even though this is a checkbox, it does not “remember” the setting. – It has to be checked each time you start designer.  Heap status is displayed in the lower left hand corner of the designer client. – Monitor the amount of memory being used – Click the trash can icon to trigger garbage collection 17
  18. 18. Configuring Domino Designer for XPage Development Configure XML Editor settings  Set XML Editor formatting for viewing XPage source  In Designer preferences – Select XML | XML Files | Editor – Change Line width – Check “Split multiple attributes each on a new line” – Check “Clear all blank lines”  Any new XPages source will adhere to these settings  Existing XPages can be “reformatted” to adhere to these settings by using the keyboard shortcut – <shift><ctrl><f> 18
  19. 19. Configuring Domino Designer for XPage Development Formatting Differences  Before and after XPage Source Formatting 19
  20. 20. Configuring Domino Designer for XPage Development Change Java Editor Margin  In the Designer Preferences dialog, choose Java | Code Style | Formatter – Click the “New” button – The included profiles can not be edited 20
  21. 21. Configuring Domino Designer for XPage Development Change Java Editor Margin  Select the “Line Wrapping” tab – Change the “Maximum line width:” property to at least 120 21
  22. 22. Configuring Domino Designer for XPage Development Change Java Editor Margin  Ensure your profile is the active profile and save preferences 22
  23. 23. Code Snippets  When writing Java code in any Java Editor developers can copy code “snippets” to the snippet plugin.  Choose Window | Show Eclipse Views | Other… 23
  24. 24. Code Snippets  Type “Snippet” into the search field  Select “Snippets” and choose OK 24
  25. 25. Code Snippets  Snippet View is added to Current Perspective 25
  26. 26. Code Snippets  Highlight code in the editor  Right click and choose Add to Snippets…  A prompt to add to an existing category or create a new one will pop up 26
  27. 27. Code Snippets  Provide a Name for the Snippet that will appear in the snippet view under the category 27
  28. 28. Using Code Snippets  To use a code snippet – Place the cursor in the Java editor where the code should be inserted. – Double click on the Snippet name in the Snippet view to insert it 28
  29. 29. Code Snippet Categories can be Imported/Exported to XML  Right click the Snippet View and choose “Customize”  In the editor select a snippet category and choose “Export”  The exported XML can then be imported by other developers 29
  30. 30. Demo Java Settings in Domino Designer 30
  31. 31. Java Beans and Managed Beans 31
  32. 32. Java Beans versus Managed Beans  This is possibly one of the most confusing issues when coding with Java  Lets start with Java Beans  A Java Bean is a Plain ‘ol Java Object (POJO), or Java class that conforms to a specific programming convention – It must have a public no-argument constructor, otherwise the default no argument constructor is used – The class properties (fields) must be defined as private and accessible using standard public method calls that start with get, set, or is (used for boolean properties instead of get). These are commonly referred to as "getter" and "setter" methods. – The class must implement java.io.Serializable to be technically qualified as a JavaBean. • This is not “necessary” but a best practice  It is up to the developer to follow these conventions when creating a JavaBean. 32
  33. 33. Java Beans versus Managed Beans  So what is a Managed Bean?  It is important to understand that it makes no difference if a bean is going to be just a Java Bean or a Managed Bean, it is coded the exact same way – Nothing in the Java source code defines it as a "Managed Bean” – This is all done in the framework, in our case, XPages  Java Beans are NOT Managed Beans; – But they can be, they just need to be "managed” – A Managed Bean follows all of the same conventions as a regular JavaBean, but is "Managed" by virtue of being registered with the framework it is incorporated in (like the XPages runtime framework) – A Managed Bean has scope in the framework and its methods can be called directly without the need to first instantiate an object variable for the Managed Bean • This is the PRIMARY factor that separates Java Beans from Managed Beans 33
  34. 34. A Java Bean Example  Lets start with a simple Java Bean Example 34
  35. 35. A Java Bean Example  Public “getter” and “setters” 35
  36. 36. Calling the Methods from an XPage  Button Code – The SSJS Code – In order to “use” the Java Bean Code it has to be instantiated (lines 1&2) – The public getter and setter methods have to be called importPackage(com.nnsu.beans); var jce:MyBean = new MyBean(); jce.setFName("Paul"); jce.setLName("Calhoun"); jce.setAge(50); jce.setHobbies(new java.util.ArrayList(java.util.Arrays.asList(["Riding Motorcycles","Playing with Grandkids"]))); var retOutput = jce.getFName()+ " "+ jce.getLName()+"</br>"; 36 retOutput += "He is: " + jce.getAge()+"</br>";
  37. 37. Demo A Java Bean 37
  38. 38. Making that same code a “Managed Bean”  Java code becomes a “Managed Bean” when it is registered with the framework it is running in (In our case XPages)  Managed Beans are “Registered” in the faces-config.xml file in the application they will be used in 38
  39. 39. Faces Confg  The faces-config.xml file is an xml file where managed beans are defined using the following syntax <managed-bean> <description>description</description> <managed-bean-name>beanName</managed-bean-name> <managed-bean-class>beanClass</managed-bean-class> <managed-bean-scope>beanScope</managed-bean-scope>  So to “Register” the previous bean as a “Managed Bean” the sytnax would be </managed-bean> <managed-bean> <description>My Managed Bean</description> <managed-bean-name>myBean</managed-bean-name> <managed-bean-class>com.nnsu.beans.MyBean</managed-bean-class> 39 <managed-bean-scope>session</managed-bean-scope>
  40. 40. Registration components  The description is just that, a short description of what the bean does  The name will be the programmatic name the bean is instantiated with  The class is the full class path to the code in the application  The scope is the “life” of the Managed Bean which can be – application - The bean is available for as long as the application is in memory and is shared among all users of the application. – session - The bean is available for the current user session and is unique for each user. – view - The bean is available for the life of the current "view" or XPage. – request - The bean is available only while the content of the individual XPage is being submitted. – none - The bean is instantiated each time it is referenced. This is helpful if the bean is referenced within another bean. 40
  41. 41. Calling the Methods from an XPage  Button Code – The SSJS Code – In order to “use” the Managed Bean Code simply call the methods using the defined bean name the code was registered with in the faces-config.xml – Notice that the Bean is never instantiated. This is because the framework (XPages) instantiates it when it is called the first time. myBean.setFName("Paul"); myBean.setLName("Calhoun"); myBean.setAge(50); myBean.setHobbies(new java.util.ArrayList(java.util.Arrays.asList(["Riding Motorcycles","Playing with Grandkids"]))); var retOutput = myBean.getFName()+ " "+ myBean.getLName()+"</br>"; retOutput += "He is: " + myBean.getAge()+"</br>"; 41 for (var i=0;i<myBean.getHobbies().size();i++)
  42. 42. Benefits of Managed Bean  Managed Beans have scope  This means – The setter methods can be executed in one event and – The getter methods executed in another event – The methods of the managed bean can be used across multiple pages in the same application  So should Java Beans ALWAYS be Managed Beans?? – As a rule, NO !!! – Only use Managed Beans when you need the values in the bean to “persist” in your application – If persistence is not required then just use POJO’s 42
  43. 43. Demo Managed Beans 43
  44. 44. Calling Java Code from an XPage 44
  45. 45. Executing Java Code from an XPage  The only Java code that can be “called” from an XPage is – Java Code Elements – Java Source Code in a source folders in the Virtual File System (VFS) • Primarily prior to 9.0 – Code in .jar files located in the JARs folder – Code in .jar files located in the WebContent/WEB-INF/lib folder – Compiled .class and .jar files located in the jvm/lib/ext folder in the file system 45
  46. 46. Executing Java Code from an XPage Java Code Elements  Create Java source code that will be compiled into individual class files when the project is built  Java Code elements are automatically added to the classpath 46
  47. 47. Executing Java Code from an XPage Java Source Code in a source folders in the Virtual File System (VFS)  Java Source code located in a Java Source folder in the VFS can be seen in the “Package Explorer” view of the XPages perspective  Java Code in a “source” folder is automatically added to the classpath 47
  48. 48. Executing Java Code from an XPage Code in .jar files located in the JARs folder  Locally developed or third party Java Archive Files (.jar) can be imported into the Jar design element  Classed in JAR elements are automatically added to the classpath 48
  49. 49. Executing Java Code from an XPage Compiled .class and .jar files located in the jvm/lib/ext folder in the file system  .class and .jar files located in this folder are available to all applications running locally and on the server  GOTCHA: Java source files (.java) files in this folder will not compile and execute  Java Code located in this folder is automatically added to the classpath 49
  50. 50. Referencing Java Code and Calling Methods from SSJS  Java code is instantiated and called from an SSJS event – Import the Java package (unless the default package was used)(which is a VERY bad idea) – Instantiate an instance of a class from the imported package – Call a method from the instantiated class – “Do something” with the results or return a status message 50
  51. 51. Demo Calling Java code from SSJS 51
  52. 52. Accessing Domino Objects 52
  53. 53. Session  The Notes Session object is the top level object in the Domino class hierarchy  It’s the starting point for calling all other classes (database, view, etc) in the hierarchy  There are two ways to get the session object in Java code executed from an XPage – Pass it in as a parameter from the SSJS – Get it from the JSF “context”, the underlying architecture 53
  54. 54. Session  Pass the global “session” variable in as a parameter – The SSJS Code importPackage(com.nnsu.domino); var jce:DomSession1 = new DomSession1(); var retOutput = jce.getOutput(session); getComponent("computedField1").setValue(retOutput); – The Java Code import lotus.domino.Session; public class DomSession1 { private StringBuffer output = new StringBuffer(); // global session object passed as parameter in the method call public String getOutput(Session session) { 54 try {
  55. 55. Session  Get it from the JSF “context”, the underlying architecture import javax.faces.context.FacesContext; import lotus.domino.Session; public class DomSession2 { private StringBuffer output = new StringBuffer(); private String nl = "<br />"; // global session object passed as parameter in the method call public String getOutput() { FacesContext context = FacesContext.getCurrentInstance(); Session session = (Session) context.getApplication().getVariableResolver().resolveVariable(context, "session"); 55 …}
  56. 56. Session  Once there is a “session” object the rest of the Domino class hierarchy can be traversed  Database  View  ViewNavigator  Document  Item  DocumentCollection  Etc… 56
  57. 57. Recycling Domino Objects  Recycling is something that is unique to working with the Domino Object API  If done correctly then it’s not ever a concern  If NOT done, then the appearance of memory leaks can become an issue  Rule: – If ANY Domino object is iterated over (for or while loops) • Item, Document, ViewEntry, Database, etc. – Then those items should be recycled as soon as the operation is complete 57
  58. 58. Recycling Domino Objects  In a for or while loop create two objects  Set the value of the first one  Process it  Set the value of the “next” to the second object name  Recycle first object  Set First object equal to the second object  Second Object no longer has any memory reference 58
  59. 59. Demo Domino Objects 59
  60. 60. Using Third Party Libraries 60
  61. 61. Development Setup  There are two choices when configuring an application to use third party Java libraries – Put all the JARS in the NSF – Put the JARS on the Host File System
  62. 62. Put all the JARS in the NSF  Pros – Makes the application more portable. – Can be “deployed” to the test server and production by replication  Cons – JARS are only accessible by code in the containing NSF – If many NSF’s use this solution then maintenance can become difficult • Going from version “x” to version “y” has to be done in every application
  63. 63. Put the JARS on Host File System  Pros – Easier to maintain code/upgrade code for all applications that use it  Cons – Harder to deploy (insert snarky Evil Admin comment here)
  64. 64. Development Setup  I prefer the deploy the JARS to the Host File system – (Insert self referencing Evil Admin Comment here) – If the code that CALLS the classes from the JARS is • A Java Agent, Servlet, Java Class or Java Code Element (available in 8.5.3 and above) - Deploy the JARS to the <installDir>/jvm/lib/ext folder • SSJS Code from an XPage - Deploy the JARS to the <installDir>/xsp folder – The JARS will have to be deployed to the Notes Designer Client AND the development/production servers !! – If the Client or Server is running then they will have to be restarted in order for your code to recognize that they are there • This is the step you will forget. Just say’in
  65. 65. Development Setup  The JARS can also be added to the NSF container when developing XPages. – This is the option I’m using so you have a self contained demonstration/example system you can play with locally or on a TEST Server.
  66. 66. Development Setup  In 8.5.3 and below – In the Application that will contain the XPage Code • From the XPages perspective switch to the Package Explorer View • Expand the WebContent/WEB-INF folder - Create a folder named “lib” • Import (you can also drag and drop) the JARS to the lib folder
  67. 67. Development Setup  In 9.0 – Import the Jars to the new “JAR” design element – This will automatically add it to the class/build path • No other configuration is required
  68. 68. Third Party Libraries  Third party libraries can come from a variety of sources – Open Source – Purchased from vendors  Typically provide a “solution” to a particular coding problem not available in the host system API – “I need to parse a String object at every capitalized letter” – “I need to export all my data to a spreadsheet” – “I need to create a PDF from this data”  One of the “Go To” solutions for tested, reliable Java Libraries is the Apache Software Foundation 68
  69. 69. What is APACHE ?  The Apache Software Foundation (www.apache.org) – Is an Open Source (Yes that means FREE) consortium of companies and developers – Donates time and resources to developing tools (primarily Java based) that simplify many tasks that developers are faced with everyday – It’s a lot like OpenNTF, but for Java developers
  70. 70. What is APACHE ?  IBM is a major contributor/supporter  If you develop using Java code (and you should be) than you owe it to yourself to spend some time reviewing the projects on this site  Some I use all the time – Xerces – Xalan – XML Graphics (FOP) – POI – Commons
  71. 71. We will explore the following  There are too many projects to cover so we will explore three of the most popular and useful to Domino Developers – Commons – POI 71
  72. 72. Apache Commons  http://commons.apache.org  Focused on all aspects of reusable Java components
  73. 73. Commons Proper  Commons Proper – Goal of creating and maintaining reusable java Components  Individual downloadable components – Not one GIANT utility library – Just get what you need
  74. 74. Commons Proper  Each of the following components can be downloaded individually Component Attributes Runtime API to metadata attributes such as doclet tags. BCEL Byte Code Engineering Library - analyze, create, and manipulate Java class files BeanUtils Easy-to-use wrappers around the Java reflection and introspection APIs. Betwixt Services for mapping JavaBeans to XML documents, and vice versa. BSF Bean Scripting Framework - interface to scripting languages, including JSR-223 Chain Chain of Responsibility pattern implemention. CLI Command Line arguments parser. Codec General encoding/decoding algorithms (for example phonetic, base64, URL). Collections Extends or augments the Java Collections Framework. Compress Defines an API for working with tar, zip and bzip2 files. Configuration Reading of configuration/preferences files in various formats. CSV Component for reading and writing comma separated value files. Daemon Alternative invocation mechanism for unix-daemon-like java code. DBCP Database connection pooling services. DbUtils JDBC helper library. Digester XML-to-Java-object mapping utility.
  75. 75. Commons Proper Component Discovery Tools for locating resources by mapping service/reference names to resource names. EL Interpreter for the Expression Language defined by the JSP 2.0 specification. Email Library for sending e-mail from Java. Exec API for dealing with external process execution and environment management in Java. FileUpload File upload capability for your servlets and web applications. Functor A functor is a function that can be manipulated as an object, or an object representing a single, generic function. A pure-Java image library. Imaging (previously called Sanselan) IO Collection of I/O utilities. JCI Java Compiler Interface JCS Java Caching System Jelly XML based scripting and processing engine. Jexl Expression language which extends the Expression Language of the JSTL. JXPath Utilities for manipulating Java Beans using the XPath syntax. Lang Provides extra functionality for classes in java.lang.
  76. 76. Commons Proper Component Launcher Cross platform Java application launcher. Logging Wrapper around a variety of logging API implementations. Math Lightweight, self-contained mathematics and statistics components. Modeler Mechanisms to create Model MBeans compatible with JMX specification. Net Collection of network utilities and protocol implementations. OGNL An Object-Graph Navigation Language Pool Generic object pooling component. Primitives Smaller, faster and easier to work with types supporting Java primitive types. Proxy Library for creating dynamic proxies. SCXML Transaction An implementation of the State Chart XML specification aimed at creating and maintaining a Java SCXML engine. It is capable of executing a state machine defined using a SCXML document, and abstracts out the environment interfaces. Implementations for multi level locks, transactional collections and transactional file access. Validator Framework to define validators and validation rules in an xml file. VFS Virtual File System component for treating files, FTP, SMB, ZIP and such like as a single logical file system.
  77. 77. Commons Lang  Provides a host of helper utilities for the java.lang API – String manipulation methods – Basic numerical methods – Object reflection – Additionally it contains basic enhancements to java.util.Date
  78. 78. Commons Lang - Versions  Latest Version is 3.3.1 – For Java 1.5 and higher – For Notes/Domino 8.x and 9.x  Version 2.6 is still available – For Java 1.2 and higher – For Notes Domino 7.x and below http://commons.apache.org/proper/commons-lang/download_lang.cgi
  79. 79. Commons Lang API Packages org.apache.commons.lang3 org.apache.commons.lang3.builder Provides highly reusable static utility methods, chiefly concerned with adding value to the java.lang classes. Assists in creating consistent equals(Object), toString(), hashCode(), and compareTo(Object) methods. org.apache.commons.lang3.concurrent Provides support classes for multi-threaded programming. org.apache.commons.lang3.event Provides some useful event-based utilities. org.apache.commons.lang3.exception Provides functionality for Exceptions. org.apache.commons.lang3.math Extends java.math for business mathematical classes. org.apache.commons.lang3.mutable Provides typed mutable wrappers to primitive values and Object. org.apache.commons.lang3.reflect Accumulates common high-level uses of the java.lang.reflect APIs. org.apache.commons.lang3.text Provides classes for handling and manipulating text, partly as an extension to java.text. org.apache.commons.lang3.text.translate An API for creating text translation routines from a set of smaller building blocks. org.apache.commons.lang3.time Provides classes and methods to work with dates and durations. org.apache.commons.lang3.tuple Tuple classes, starting with a Pair class in version 3.0.
  80. 80. org.apache.commons.lang3.StringUtils  IsEmpty/IsBlank - checks if a String contains text  Trim/Strip - removes leading and trailing whitespace  Equals - compares two strings null-safe  startsWith - check if a String starts with a prefix null-safe  endsWith - check if a String ends with a suffix null-safe  IndexOf/LastIndexOf/Contains - null-safe index-of checks  IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
  81. 81. org.apache.commons.lang3.StringUtils  ContainsOnly/ContainsNone/ContainsAny - does String contains only/none/any of these characters  Substring/Left/Right/Mid - null-safe substring extractions  SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings  Split/Join - splits a String into an array of substrings and vice versa  Remove/Delete - removes part of a String  Replace/Overlay - Searches a String and replaces one String with another
  82. 82. org.apache.commons.lang3.StringUtils  Chomp/Chop - removes the last part of a String  LeftPad/RightPad/Center/Repeat - pads a String  UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize - changes the case of a String  CountMatches - counts the number of occurrences of one String in another
  83. 83. org.apache.commons.lang3.StringUtils  IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String  DefaultString - protects against a null input String  Reverse/ReverseDelimited - reverses a String  Abbreviate - abbreviates a string using ellipsis  Difference - compares Strings and reports on their differences  LevenshteinDistance - the number of changes needed to change one String into another
  84. 84. Demo Commons StringUtils 84
  85. 85. Apache POI  POI is a Java API for Microsoft Documents – Not just spreadsheets, but what it’s used most often for – Which is misleading because it contains libraries that specifically allow API access to file formats based upon • OOXML – Open Office XML Standards • OLE2 – Microsoft’s Compound Document Format – You do NOT have to have MS Office installed in order to use POI !! • This is a major benefit / enhancement to COM options that require MS Office to be installed on Domino Servers
  86. 86. Apache POI  POI can “Read” and “Write” to MS and Open source versions of – Spreadsheets – Word Processing documents – Presentation (Powerpoint) – MS Publisher  Useless Trivia – POI is an acronym for “Poor Obfuscation Implementation” in reference to reverse engineering the original MS Office document formats
  87. 87. Use Cases  Although POI can be used to create many types of MS Office formats we will concentrate on spread sheets  There are three primary use cases for creating spreadsheets from Domino Data – Export all the documents in a view – Export selected documents from a view – Export documents that match a query (Ad Hoc Reporting)
  88. 88. Export All Documents From a View  This is the primary use case – Create an XPage that displays the View • This isn’t really required, but is nice for context purposes  Create a clickable component that will instantiate the Java code and pass parameters too it
  89. 89. The Button Code SSJS code on onClick event of component //Import the Java code package importPackage(com.nnsu.util); //Create an Instance of the Java Class var jcode:POIAllDocs = new POIAllDocs(); //Set the varibles for passing to the Java Class method var vName = "Main"; var fieldList = ["Company","FirstName","LastName","EmailAddress"]; // The Faces Context global object provides access to the servlet environment via the external content var extCont = facesContext.getExternalContext(); // The servlet's response object provides control to the response object var pageResponse = extCont.getResponse(); //Get the output stream to stream binary data var pageOutput = pageResponse.getOutputStream(); //Set the file name to pass to the response header var fileName = "CustomerView.xls"; // Set the content type and headers
  90. 90. The Java Code  The Java code has one method “createSpreadSheet” that accepts the parameters from the SSJS code package com.nnsu.util; public class POIAllDocs { public static void createSpreadSheet( String viewName, String[] fieldList, OutputStream fileout) { try { // Get Database and View to be processed FacesContext context = FacesContext.getCurrentInstance(); Session s = (Session) context.getApplication().getVariableResolver().resolveVariable(context, "session"); Database db = s.getCurrentDatabase(); View nc = db.getView(viewName); //Variables to create the workbook and sheet String sheetName = "Customer View Data";
  91. 91. The Java Code  Use the POI API to create the objects necessary to create a spreadsheet // Create a new Workbook object from the POI library HSSFWorkbook wb = new HSSFWorkbook(); // Create a sheet in the workbook HSSFSheet sheet1 = wb.createSheet(sheetName); // Create styles for dates and header columns HSSFCellStyle dateStyle = wb.createCellStyle(); dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); HSSFCellStyle headerStyle = wb.createCellStyle(); HSSFFont headerFont = wb.createFont(); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerStyle.setFont(headerFont); // Create the Column Header Rows from the Field array passed into the class HSSFRow row = sheet1.createRow(0); for (int i = 0; i <= fieldList.length - 1; i++) { HSSFCell hCell = row.createCell(i);
  92. 92. The Java Code  Process every document in the view and create a “row” in the spreadsheet output // Get the first document in the view and process each document in the view doc = nc.getFirstDocument(); for (int d = 1; d <= nc.getEntryCount(); d++) { row = sheet1.createRow(d); for (int f = 0; f <= fieldList.length - 1; f++) { Item itemval = doc.getFirstItem(fieldList[f]); if (itemval.getType() == 768) { row.createCell((Integer) (f)).setCellValue( itemval.getValueDouble()); } else if (itemval.getType() == 1024) { Date jdate = itemval.getDateTimeValue().toJavaDate(); HSSFCell dcell = row.createCell(f); dcell.setCellValue(jdate); dcell.setCellStyle(dateStyle); } else { row.createCell((java.lang.Integer) (f)).setCellValue( itemval.getText());
  93. 93. The Java Code  Set the width of each column to the width of the longest entry in that column  “Write” the output of the spreadsheet to the output stream passed in as a parameter // Autoset the width of the spreadsheet columns based upon the values for (int c = 0; c <= fieldList.length - 1; c++) { sheet1.autoSizeColumn(c); } //Write the contents of the spreadsheet to the output stream wb.write(fileout); } catch (EvaluationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NotesException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) {
  94. 94. Demo Export All Documents in a View to a Spreadsheet 94
  95. 95. Exporting Selected Document from a View  The base code and setup are the same with the following exceptions – A View container must be included with the first column set to “select” the documents – The SSJS code must be edited to get the list of selected documents from the View and pass them to the processing Java Code //Get the list of selected documents to pass to the java code. var viewPanel1:com.ibm.xsp.component.xp.XspViewPanel = getComponent("viewPanel1"); var docIds = viewPanel1.getSelectedIds(); … //Pass the variables to the Java Method to create the spreadsheet jcode.createSpreadSheet(vName,fieldList,pageOutput,docIds); 95
  96. 96. Exporting Selected Document from a View  The Java code receives the selected documents as an array of string id’s  In the code that creates the spread sheet rows each document id retrieved by it’s id from the array to be processed public static void createSpreadSheet(String viewName, String[] fieldList, OutputStream fileout,String[] nc) { try { … // Get the first document in the id array and process each document in the array for (int d = 1; d <= nc.length ; d++) { doc = db.getDocumentByID(nc[d-1]); … 96
  97. 97. Demo Export Selected Documents in a View to a Spreadsheet 97
  98. 98. Exporting Query Result Documents  A Notes Document collection can be returned programmatically  The query generally includes the name of the form the document was created with and then the value from one of the fields  The same base code is used with fields added to capture the additional information needed to create the spreadsheet 98
  99. 99. SSJS to Capture the parameters  The SSJS code captures the parameters from the XPage components //Import the Java code package importPackage(com.nnsu.util); //Create an Instance of the Java Class var jcode:POIQueryDocs = new POIQueryDocs(); //Set the variables from the XPage input var formName = getComponent("comboBox1").getValue(); var selFields = getComponent("inputText1").getValue(); var selLabels = getComponent("inputText2").getValue(); var fieldList = selFields.split(","); var colLabels = selLabels.split(","); var fileName = getComponent("wbName").getValue(); var sheetName = getComponent("sheetName").getValue(); var qString = getComponent("queryString").getValue(); 99
  100. 100. SSJS to Capture the parameters  The parameters are then passed to the java code to be processed … //Pass the variables to the Java Method to create the spreadsheet jcode.createSpreadSheet(fieldList,colLabels,pageOutput,formName,sheetName,qString); //Flush the buffer and close the stream pageOutput.flush(); pageOutput.close(); // Terminate the request processing lifecycle. facesContext.responseComplete(); 100
  101. 101. Java code to process the parameters  The Java code uses the passed in parameters to create a Notes Document Collection from a full text query – This works even if the application is not full text indexed, it’s just not as efficient – GOTCHA: The administrator can set a switch on the application to NOT ALLOW full text queries if the application is not full text indexed public class POIQueryDocs { public static void createSpreadSheet(String[] fieldList,String[] colList, OutputStream fileout,String formName, String sheetName,String qString) { try { // Get Database and View to be processed FacesContext context = FacesContext.getCurrentInstance(); Session s = (Session) context.getApplication().getVariableResolver().resolveVariable(context, "session"); Database db = s.getCurrentDatabase(); 101
  102. 102. Demo Export Query Results Documents to a Spreadsheet 102
  103. 103. Bonus Material  Using APACHE FOP to Create PDF’s 103
  104. 104. So what is FOP?  FOP is a sub-project of the XML Graphics project at APACHE  FOP stands for Formatting Objects Processor – This is a print formatter driven by XSL FO (Formatted Objects)
  105. 105. So what is FOP?  An API that – Reads an FO Tree – Renders the resulting pages to a specified output • PDF (Primary) • PS • PCL • AFP • XML • Print • AWT • PNG
  106. 106. Um.. How about that again in English !!  It’s a java based toolset that lets YOU (the developer) create solutions that allow your End Users (the Bain of all existence) to create PDF documents from Notes content for FREE !!!  Yes FREE!!! – Ok, Free is relative. – You are going to have to invest some time, but I’m going to give you a working framework that you can implement out of the box. – For Free!!!
  107. 107. The Process  The great thing about FOP is it is a highly duplicable design pattern XML Source XSLT StyleSheet FO Rendering FO Source Engine Rendered Output
  108. 108. The Process  It all starts with an XML Document (can be from disk or in memory) XML Source XSLT StyleSheet FO Rendering FO Source Rendered Engine Output
  109. 109. The XML  The XML can be – A Static Document – The output from ?ReadViewEntries • Appended to the end of a Domino View URL – The output from generateXML • Method of the Notes Document class – The results of running an XAgent – The results of running an Agent – The results of running a Web Service
  110. 110. The XML  The source of the XML is not as important as the FORMAT and CONSISTANCY of the XML – The XML must be well formed and optionally valid – Make sure that if you do not control the source that you have an SLA with the source provider that includes them providing the XML Schema AND changes to the XML Schema in enough advance that you have time to test it.
  111. 111. The XML  Using the ?ReadViewEntries option is HIGHLY duplicable – Once you have the stylesheet (and I’m providing that to you) that transforms the source XML to the FO XML then ANY view source can be passed to the code to produce a PDF of the view
  112. 112. The XML  The other options require an XSLT stylesheet that is specific to transforming the specified XML to FO XML. – This is not as flexible, but once the base stylesheet is created it can be stored in a notes document that is editable by a non-developer • This option allows changes to colors, fonts etc without developer intervention and re-compiling/re-deploying the code
  113. 113. The Stylesheet  The stylesheet that is used is an XSLT document (written in XML) that uses the FOP tags from the tag library XML Source XSLT StyleSheet FO FO Source Rendered Rendering Engine Output
  114. 114. The XSL FO Stylesheet  This is by far the most challenging part of this solution  Stylesheet creators must be able to create and edit XSLT stylesheets (Doh!)  The Tags used in the style sheet are not documented at the FOP site – The good news is they ARE documented at the w3 schools site • http://www.w3schools.com/xslfo/default.asp – The other good news is they are documented in the form of a tutorial !! – You can follow the tutorial to examine how to create a base XSL FO style sheet • You can also copy/paste this example code directly to your XSL FO style sheet to get started !!
  115. 115. Using Eclipse or an XSLT editor is the best choice  Download the version that has the Web Tools Plugin (WTP)  I usually download the one that supports J2EE development  The benefit of this option is there is an XSLT editor included not just an XML editor  Also you can train “power-users” to use eclipse to build, edit, maintain XSLT stylesheets for the purpose of maintaining their own output without the need for them to have designer – This might sound difficult, but it is significantly easier to train both developers and power users on XSLT than it is Java !!
  116. 116. The XSLT  The Stylesheet is made up of a combination of XSLT and XSL:FO tags
  117. 117. Structure of the FO Tags  The XSL:FO tags are all about the layout of the “printed” page  XSL:FO tags always start with “root” – Followed by a “layout master” • Followed by a “page master” • The a series of page sequences that contain - Flows - Blocks
  118. 118. The Layout and Page Master  These tags define the output page – Height – Width – Margins – etc
  119. 119. The Page Sequence tag  References the page master set tag to get its output constraints
  120. 120. The Page Content  The Page content is the output using a series of “flows” and “blocks”  A “flow” contains a series of “blocks”  A “block” is roughly equivalent to a paragraph on the page
  121. 121. The Page Content  Blocks can contain other constraining tags like the “table” tag
  122. 122. Where are the stylesheets Stored  After the stylesheet is created there are two options – Save the stylesheet as a design resource (A stylesheet) – Save the stylesheet in a document that is accessible from the notes client • This allows editing/maintainence of the stylesheets without the need of a designer client  The option you choose will depend upon level of expertise of the folks you have back at your house
  123. 123. Storing Stylesheets in Designer  The XSLT Sheets can be stored in DDE in the Style Sheets folder contained in the resources folder
  124. 124. Alternately Store in documents  You can create a – Form – View  to store Notes documents that contain the XSLT stylesheets  Your code will “lookup” the stylesheet when applying it to the XML source
  125. 125. The Code  Now that you have the XML Source and the XSLT stylesheet you are ready to write some code !!! (Yea !!)  Can be coded as – Java Agents – Java Code elements – Coded in SSJS (like an XAgent)
  126. 126. Creating the FO Source  The code will take the XSLT stylesheet, apply it to the XML source and produce the XSL:FO that is used by the rendering engine to produce the PDF XML Source XSLT StyleSheet FO Rendering FO Source Engine Rendered Output
  127. 127. The Code  The “SSJS” button code that calls the Java Code
  128. 128. The Java Code that creates the PDF  The Java Code takes the output stream as a parameter, reads the XML and XSLT and uses APACHE FOP to generate the PDF
  129. 129. The Complete Process  That finishes the design pattern XML Source XSLT StyleSheet FO Rendering FO Source Engine Rendered Output
  130. 130. Demo Create PDF from Domino Data 130
  131. 131. Resources  IBM XPages Forum – Moderated by the community – http://www-10.lotus.com/ldd/xpagesforum.nsf/  TLCC – Self paced Courses on XPages and Java – http://www.tlcc.com  NetNotes Solutions Unlimited - My Web Site  http://www.nnsu.com (Sample code available here)  Apache Software Foundation – http://www.apache.org  OpenNTF – http://www.openntf.org  XPages Tips – http://xpagetips.blogspot.com 131
  132. 132.  Access Connect Online to complete your session surveys using any: – Web or mobile browser – Connect Online kiosk onsite 132
  133. 133. Your Turn !!! Questions, Questions, Questions !!!! 133
  134. 134. Acknowledgements and Disclaimers Availability. References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. The workshops, sessions and materials have been prepared by IBM or the session speakers and reflect their own views. They are provided for informational purposes only, and are neither intended to, nor shall have the effect of being, legal or other guidance or advice to any participant. While efforts were made to verify the completeness and accuracy of the information contained in this presentation, it is provided AS-IS without warranty of any kind, express or implied. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this presentation or any other materials. Nothing contained in this presentation is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software. All customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual environmental costs and performance characteristics may vary by customer. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results. © Copyright IBM Corporation 2014. All rights reserved.  U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.  Please update paragraph below for the particular product or family brand trademarks you mention such as WebSphere, DB2, Maximo, Clearcase, Lotus, etc.  IBM, the IBM logo, ibm.com, [IBM Brand, if trademarked], and [IBM Product, if trademarked] are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both. If these and other IBM trademarked terms are marked on their first occurrence in this information with a trademark symbol (® or ™), these symbols indicate U.S. registered or common law trademarks owned by IBM at the time this information was published. Such trademarks may also be registered or common law trademarks in other countries. A current list of IBM trademarks is available on the Web at “Copyright and trademark information” at www.ibm.com/legal/copytrade.shtml If you have mentioned trademarks that are not from IBM, please update and add the following lines: Java Other company, product, or service names may be trademarks or service marks of others. 134

×