Going Beyond Layout Richard V. Jackson Huntington Library, Art Collections, and Botanical Gardens...

Post on 22-Dec-2015

220 views 0 download

Transcript of Going Beyond Layout Richard V. Jackson Huntington Library, Art Collections, and Botanical Gardens...

Going Beyond Layout

Richard V. JacksonHuntington Library, Art Collections, and Botanical GardensSan Marino, California

Print Templates

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 2

Print templates can be a real pain …

Steep learning curve

iReport can be difficult

Many ways things can go wrong — can be hard to troubleshoot problems

Information is scattered among several sources (Sierra documentation, CSDirect wiki, IUG List, etc.)

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 3

… but there are advantages

More control (page size, font, color, layout)

More fields available

Images and graphical elements

Scannable barcodes

Hyperlinks (in email notices)

Save output to a PDF file

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 4

Yet another advantage

Data manipulation and conditional

printing

Using Java string methods, you can:– Print “Call of the wild” as “CALL OF THE

WILD”

– Print the last 4 digits of a barcode

– Automate call number pre-stamps

– Print “Jackson, Richard” as “Richard Jackson”

– Print “Jackson, Richard” as “JACK/R”

– Convert fixed-length codes to corresponding text

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 5

Purpose of this presentation

Detailed explanation of the use of Java string methods in Text Fields, including:– Conditional printing

– Data manipulation

– Many practical examples

A method for reformatting Due Dates in notices

Changing text formattingEverything applies to both Millennium and

Sierra

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 6

Handout

Supplementary handout onJava string methods available

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 7

Print templates overview

For help getting started:

“Print Templates 101 & 102,” a LibGuide created by Shad Harder and Carla Myers http://libguides.uccs.edu/PrintTemplates101 http://libguides.uccs.edu/PrintTemplates102

Print templates on CSDirect (login required)

http://csdirect.iii.com/documentation/print_templates.php

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 8

Print templates overview

iReport 4.0.2 used to create/edit templates

Download from CSDirect: http://csdirect.iii.com/downloads/ireport.shtml

iReport requires a Java Runtime Environment. Unfortunately, the current version of Java for Windows (version 8) is incompatible with iReport 4.0.2. Detailed instructions for downloading and installing version 7 are in the “Print Templates 101” LibGuide at:http://libguides.uccs.edu/ld.php?content_id=9608837

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 9

Print templates overview

Print template = a .jrxml file– Edit using iReport– Start with default

template Define page and

margins Define bands Add report elements

– Static text– Text fields– Images– Lines, boxes, etc.

Title

Page Header

Detail

Page Footer

Title: $F{Item_Title}

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 10

The palette in iReport

Click and drag report elements from the palette to the document

If the palette isn’t visible, click Window > Palette (or type Ctrl+Shift+8)

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 11

Static Text vs. Text Fields

Static Text (or label)– Text doesn’t change– No double-quotes needed

Text Field– Is dynamic– Contains a single Java expression that

results in a string value

Title:

$F{Item_Title}

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 12

Editing the Text Field expression

Expression editor window

Available fields String methods

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 13

Terminology clarification: “Fields”

“Fields” in Millennium/Sierra– Fixed-length fields e.g.: COPY#, LOCATION

– Variable-length fields e.g.: CALL NO.

Print template “fields” (“data elements”)$F{itemFix58} $F{callAlphaStart}$F{itemFix58c} $F{callNumericStart}$F{itemFix79} $F{callNumericAfterDec}$F{Item_Location} [etc.]

“Text field”– Report element occupying space on the

layout and containing a Java expression

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 14

Text Fields

Simple text field

Concatenation of multiple text elements

– Use “+” to join elements

– Literal text in quotes– "\n" means carriage return

$F{callEntire}

$F{callEntire}$F{itemv}

$F{callEntire} + "\n" +$F{itemv}

- OR -

+ " " +

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 15

A complex text field expression

Don’t do this — it works, but is difficult to decipher and maintain

($F{itemFix79}.equals("gcrf ")?"REF"+"\n":$F{itemFix79}.equals("gcrff")?"REF"+"\n"+"folio"+"\n":$F{itemFix79}.equals("bot ")?"BOT"+"\n"+"LIBRARY"+"\n":$F{itemFix79}.substring(4).equals("f")?"folio"+"\n":"")+$F{callAlphaStart}+($F{callAlphaStart}.equals("")?"":"\n")+$F{callNumericStart}+$F{callNumericAfterDec}+"\n"+$F{callEndCR}+($F{callEndCR}.equals("")?"":"\n")+$F{callSubbCR}+($F{itemv}.trim().isEmpty()?"":"\n"+$F{itemv}.trim().replace(" ","\n"))+($F{itemFix58c}.equals("c.1")?"" : "\n"+$F{itemFix58c})

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 16

A more readable complex expression// Print pre-stamps for select locations:($F{itemFix79}.equals( "gcrf " ) ? "REF" + "\n" :$F{itemFix79}.equals( "gcrff" ) ? "REF" + "\n" + "folio" + "\n" :$F{itemFix79}.equals( "bot " ) ? "BOT" + "\n" + "LIBRARY" + "\n" :$F{itemFix79}.substring(4).equals( "f" ) ? "folio" + "\n" // Print ‘folio’ if Loc ends in 'f' : "")// Print LC call number:+ $F{callAlphaStart}+ ($F{callAlphaStart}.equals( "" ) ? "" : "\n")+ $F{callNumericStart} + $F{callNumericAfterDec} + "\n"+ $F{callEndCR}+ ($F{callEndCR}.equals( "" ) ? "" : "\n")+ $F{callSubbCR}// Print Volume if present. Convert 2 spaces to Carriage Return:+ ( $F{itemv}.trim( ).isEmpty( ) ? "" : "\n" + $F{itemv}.trim( ).replace( " " , "\n" ) )// Print copy number except for "c.1":+ ( $F{itemFix58c}.equals( "c.1" ) ? "" : "\n" + $F{itemFix58c} )

Use spaces and line breaks to make the expression more readable

Comments can also be added

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 17

Comments in text field expressions

Use “// …”or “/* … */”to enter comments anywhere in the text field expression

/*Comment block*/

Expression

// Comment

Expression Expression // CommentExpression

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 18

Conditional printing

Conditional statements use a trinary operator:

( [If] ? [Then] : [Else] )

( ? : )

Boolean expression

Expression to execute

if true

Expression to execute

if false

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 19

Conditional printing

If the Item Volume field is empty, print nothing, otherwise, print the Item Volume + <CR>

This avoids a blank line when there is no Volume.

$F{itemv}.equals("")

Boolean expressi

on

Expression to execute

if true

Expression to execute

if false

? "" : "\n" + $F{itemv}

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 20

Conditional printing: another example

Print the copy number (on a spine label) unless the copy number is “1”

(

$F{itemFix58}.equals("1")

? ""

: "copy " + $F{itemFix58}

)

IfThen

Else

Alternatively, you can use the field “$F{itemFix58c}”, which automatically puts “c.” in front of the copy no.

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 21

Automating call number pre-stamps

Certain special locations require a location “stamp” above the call number

These had been generated using a locally-defined “LABEL LOC” field in the Item record

Problem: The location code and LABEL LOC are logically dependent but functionally independent — errors and inconsistencies can easily occur

MSS REFCD1879.5C64 G37

folioTR647W395 2010c.2

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 22

Automating call number pre-stamps

Mismatch: Is the book in the Gen. Coll. East Basement or the Manuscript Reference Reading Room?

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 23

Automating call number pre-stamps

Checking for a single case:

Parentheses around the conditional expression are crucial. Otherwise, the call number itself would only print under the “else” condition

Note that the location code is padded out to 5 characters with trailing spaces ("hmrf ")

( $F{itemFix79}.equals("hmrf ")

? "MSS REF" + "\n"

: "" )

+ [rest of the call number]

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 24

Automating call number pre-stamps

To cover multiple pre-stamps, use nested conditional statements:

(

If Location="gcrf ", print "REF"

Else if Location="hmrf ", print "MSS REF"

Else if Location="hcons", print "CONSERV."

Else if Location="botr ", print "BOT RARE"

Else if Location="href ", print "INVALID!“

Else print ""

)

+ [rest of the call number]

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 25

Nested conditional statements

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 26

A closer look at Java string methods

This string method returns a Boolean value (true or false)

Used in the first part of conditional statements

$F{itemFix79}.equals("hmrf ")

Field name (or other string expression)

Method name Argument(s)

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 27

Examples of Java string methods

These string methods return Boolean values:

Returns true if Item barcode starts with “2123”

Returns true for locations “gccbf”, “gcn3f”, “hconf”, etc. (but false for “hmrf ”)

Returns true if the Patron name contains “, ” (comma followed by space)

$F{Item_Barcode}.startsWith("2123")

$F{itemFix79}.endsWith("f")

$F{Patron_Name}.contains(", ")

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 28

Examples of Java string methods

These string methods return Boolean values:

Returns true if the call number starts with H, J, or K(The argument is a regular expression)

Returns true if there is no a-tagged field (author) in the bib record. Same as .equals("").Avoid using the .isEmpty method with fields that draw data from the fixed-length fields

$F{callAlphaStart}.matches("^[HJK]")

$F{biba}.isEmpty( )

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 29

Examples of Java string methods

These string methods return string values:

Converts lower case letters to upper case(“Call of the wild” would become “CALL OF THE WILD”)

Removes leading and trailing spaces(“ Jackson, R. V. ” would become “Jackson, R. V.”)

$F{bib245}.toUpperCase( )

$F{Patron_Name}.trim( )

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 30

Examples of Java string methods

These string methods return string values:

Replaces all occurrences of the space character with carriage returns

The .replaceAll method allows you to use a regular expression in the first argumentIn this example, leading zeroes are removed(“002” would become “2”; “010” would become “10”)

$F{callEntire}.replace( " " , "\n" )

$F{itemFix58}.replaceAll( "^0*" , "" )

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 31

Examples of Java string methods

These string methods return string values:

Returns a substring of the patron’s barcode, from character position 10 to the end (e.g., last 4 digits of a 14-digit barcode)

Returns the first 4 characters of the patron’s name

More details given in the examples to come

$F{Patron_Name_C}.substring( 0 , 4 )

$F{Patron_Barcode}.substring( 10 )

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 32

Examples of Java string methods

These string methods return integer values:

Returns the length of the string

Returns the character position of the first occurrence of the specified character or string (counting starts at 0)

In this example, the method would return 5

$F{Item_Barcode}.length( )

$F{Patron_Name}.indexOf(",")

Smith, J.0 1 2 3 4 5 6 7 8

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 33

Examples of Java string methods

Arithmetic and comparison operations can be done on integer string methods:

Returns the character position 2 characters after the first comma (7 in this example)

Returns a Boolean true if the barcode is shorter than 14 characters

$F{Item_Barcode}.trim( ).length( ) < 14

$F{Patron_Name}.indexOf(",") + 2

Smith, J.0 1 2 3 4 5 6 7 8

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 34

Examples of Java string methods

Boolean expressions can be joined with Boolean operators:

&& (and) || (or) ! (not)

Returns true if both the Item Location = “main” AND the call number subfield f = “Large print”

$F{itemFix79}.equals("main ")

&& $F{callSubf}.equals("Large print") ? … : …

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 35

Examples of Java string methods

Returns true if either the Patron Type = “Staff” OR the Patron Type = “Intern”

Returns true if patron address line 3 does NOT contain “91108”. You can also do this:

$F{Patron_Type}.equals("Staff")

|| $F{Patron_Type}.equals("Intern") ? … : …

$F{Patron_Address_Line3}.contains("91108") !( )

($F{Patron_Address_Line2} + " " +

$F{Patron_Address_Line3}) .contains("91108")

!(

)

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 36

Example: Using the .replace method

Volume: ser.3 v.29-30

Volume: n.s. v.11-12

Problem: The print template wraps a long field as far to the right as possible

Solution: Make it possible to manually set line breaks in a long Volume field

VM1S32 n.s. v.11-12

VM1S32 ser.3 v.29-30

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 37

Example: Using the .replace method

Solution: Add a string method that convert 2 spaces in a Volume field to a carriage return

Volume:

n.s.^^v.11-12

VM1S32 n.s. v.11-12

Volume:

ser.3^^v.29-30

VM1S32 ser.3 v.29-30

$F{itemv}.replace( " " , "\n" )

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 38

Example: Using the .substring method Print only the last 6 digits of a 14-digit

barcode

3 0 0 0 6 2 0 0 5 0 1 6 3 40 1 2 3 4 5 6 7 8 9 10 11 12 13

$F{Item_Barcode}.substring( 8 )

.substring methodA single argument specifies

the starting character position, returning a substring from that character to the end of the field

“501634”

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 39

$F{Item_Barcode}.substring(

)

Example: Using the .substring method Print the last 4 digits of variable-length

barcodes

3 1 2 3 4 5 6 7 8 90 1 2 3 4 5 6 7 8 9

$F{Item_Barcode}.length( ) - 4

Subtracting 4 from the length of the field gives the correct starting character positionIn this example: 10 – 4 = 6

“6789”

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 40

A more complex example

Create an abbreviation form of the patron name for printing on Hold Slips

Jackson, Richard V. JAC/R

$F{v_p_name}

.substring(0,3)

+ "/"

+ $F{v_p_name}.substring(

)

$F{v_p_name}.indexOf(",") + 2,

$F{v_p_name}.indexOf(",") + 3

(

).toUpperCase( )

Result: Jackson, Richard V.JacJac/Jac/RJAC/R

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 41

A more complex example This does not account for last names

shorter than 3 characters, or names that lack a comma or vary in the number of spaces following the comma

See the handout (p. 2) for a more complex expression that deals with all these situations

( $F{v_p_name}.substring(0,3)

+ "/"

+ $F{v_p_name}.substring(

$F{v_p_name}.indexOf(",") + 2,

$F{v_p_name}.indexOf(",") + 3 )

).toUpperCase( )

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 42

Formatting dates

To add today’s date to a notice:

04/30/2014

To format the date:– Right-click the field– Select “Field pattern”– Select a format

new java.util.Date( )

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 43

Formatting dates

Dates from records such as Item Due Date are string fields and cannot be formatted this way

07–09–14

A more complex expression is needed to format such dates

July 9, 2014

$F{Item_Due_Date}

new SimpleDateFormat("MMMM d, yyyy").format(new SimpleDateFormat("MM-dd-yy").parse($F{Item_Due_Date}))

See the Handout p. 6 for more information

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 44

Changing text styles within a report element Text properties (font

name, size, bold, italic, etc.) normally apply to the entire Report element

With the Markup property, markup tags can be added to change text styles for a portion of the text

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 45

Changing text styles within a report element For simple changes (e.g., boldfacing

some text), using html tags– Set the Markup property to “html”

– Tags are still text and must be in quotes

"You currently have "

+ $F{Patron_Checked_Out_Number}

+ " items checked out."

+ "<b>" + "</b>"

Note: With HTML markup, "\n" doesn’t work; use "<p>" instead

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 46

Changing text styles within a report element You can also set Markup to “styled” and

use the <style> tag with various attributes

Problem: The pre-stamp

AHMANSON READING RM.

wouldn’t fit on the spine label

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 47

Changing text styles within a report element

– Since the <style> tag must be in double quotes, use single quotes around attribute values

"<style fontName='Arial Narrow' size='10'>"

+ "AHMANSON" + "\n" + "Reading Rm."

+ "</style>" + "\n"

Double quotes around the <style> tag

Single quotes around attri-bute values

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 48

Changing text styles within a report element Some attributes used with the <style>

tag(examples)

– fontName fontName='Verdana'– size size='10.5'– isBold isBold='true'– isItalic isItalic='false'– isUnderline isUnderline='true'– forecolor forecolor='#DDDDDD'– backcolor backcolor='#3E75AD'

For more information, see The JasperReports Ultimate Guide, 3rd ed. (p. 122+, especially p. 134-35) (http://jasperreports.sourceforge.net/JasperReports-Ultimate-Guide-3.pdf)

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 49

More information Reference page on Java string methods

(http://docs.oracle.com/javase/6/docs/api/java/lang/String.html)

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 50

More information

Jasper Reports Ultimate Guide (PDF, 333 p.) (http://jasperreports.sourceforge.net/JasperReports-Ultimate-Guide-3.pdf)

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee 51

Questions?

Richard V. JacksonSupervising Librarian / System Coordinator

Huntington Library, Art Collections, and Botanical Gardens

San Marino, Californiarjackson@huntington.org

http://www.huntington.org/

Thank you!