Wednesday, January 25, 2012

Page Header & Page Footer

A new feature will be included in NextReports 5.1 release: Page Header & Page Footer.

For document file exports like PDF and RTF, NextReports created page number in page header and current date in page footer. There was no way to define your header and footer data.

In 5.1 release, user will be able to define page header and page footer. Two new bands will be added to layout and they can contain any number of rows.

A new type of variable for page number can be inserted $V{PAGE_NO}. There is also the possibility to format page number as roman value:

Page number variable can also be inserted inside expressions like:

resulting in the following output:

Tuesday, January 17, 2012

Keep Settings inside Storage

Every application needs configuration. If configuration must be accessible by users of the application, then you have to persist all your properties.

NextReports Server kept its properties inside a property file. Some problems with a file approach are:
  • you must know where the file is located
  • after any modification it may be needed to restart the application
  • after any new version installation you need to copy your old property file

Starting with 5.0 version, server has a new Settings section visible by administrators. All settings are now kept inside JCR storage and the problems with the file approach were removed:
  • we know where the place to modify application settings is
  • after properties modification there is no need to restart the server (except for some that must be defined also in your web server configuration)
  • when a new installation (update) is done, by specifying the old storage path, you have by default all your previously settings

Settings are arranged by categories : general, thread pool, application look, jasper, synchronizer. Information or attention about properties are offered through tool-tips.  Only three properties require a restart of the server because you also have to modify something in your web server configuration files. These are:
  • Base Url: if you change this you maybe have to talk to your network administrator
  • Reports Home: “reports” folder must be in web server class path. For default Jetty server used, inside the installation folder you can find a start-nextserver.vmoptions file. In this file, the jetty class path is specified like this:         
  • Reports Url: “reports” folder must be mapped to a web context. This is needed because all generated reports have to be accessed through http URL links that look like the following:         
           For Jetty server used by default, there is a contexts folder where you installed the server.
           Inside reports.xml file found here, there are two properties:
           which tell us that reports found at “resourceBase” on the hard disk can be served by the web server’s “contextPath”.

Monday, January 09, 2012

Know your date format

When it comes to date formatting, java makes use of SimpleDateFormat class:

"Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') to avoid interpretation. "''" represents a single quote. All other characters are not interpreted; they're simply copied into the output string during formatting or matched against the input string during parsing."

When it comes to Jackrabbit internal, dates as saved to a specific format like the following string:
Taking forward to create the pattern for such a String results in:
Note that we need T not to be a pattern letter, so we unquoted it. We may think everything it's ok. If we need just to show a nice formatted date, we may not even see the difference. But if we want to use date formatted strings for some business, for example to do a Jackrabbit search of entities between two dates, we will found out (not easily) that the pattern is wrong.

Jackrabbit has a xs:dateTime function which has a formatted date as parameter. Obviously this date must have the same format used to store dates in Jackrabbit.

The problem with previously date format is the time zone, because there is no delimiter between the hours and the minutes, so the resulting string with SimpleDateFormat will be :
Because we cannot use a SimpleDateFormat string, we must use Jackrabbit api to format dates:
Calendar cal = Calendar.getInstance();
String formattedDate = ValueFactoryImpl.getInstance().createValue(cal).getString();