A target is a destination to which the server can direct output. Targets include physical file locations, either on the local or remote machines, and email addresses.
The targets are defined in the config/ERS2-Config.xml file and users and groups can be granted access to different targets. You can use parameter substitutions, eg. ${dir} in target parameters, so that users can set the values by passing parameters while rendering. This allows the same mail target to be used to send to different recipients, for example.
File Targets are server file system locations where reports will be generated. You can define as many file targets as you need. File targets are defined like this:
<ers:target name="t1"
class="com.elixirtech.ers2.target.FileTarget"
description="">
<ers:property name="dir">${outputdir}/t1</ers:property>
<ers:property name="overwrite">yes</ers:property>
<ers:property name="filename">file2</ers:property>
</ers:target>
A Repository Target writes the report to the server repository. You can identify a target folder in the repository and provided it is writable, files will be written there. This works regardless of whether the target filesystem is of type local, secure or db. You should use Repository Targets when you want to allow users to view the reports through their browser as the repository will automatically update to show the new files. If you use a File Target instead, the repository will need to be manually refreshed. Repository targets are defined like this:
<ers:target name="t1" description=""
class="com.elixirtech.ers2.target.RepositoryTarget" >
<ers:property name="folder">ElixirSamples/Output</ers:property>
<ers:property name="overwrite">yes</ers:property>
</ers:target>
A Mail Target allows the output to be sent with an email.
Before using this, ensure that the appropriate SMTP Server is
configured in ERS2.xml. The default SMTP server elixir.aspirin
is built in to Elixir Repertoire Server, so you only need to change
it if you wish to use an external SMTP Server.
There are a number of parameters to specify, but remember you can use
substitutions to avoid hard-coding those that you decide need
to be flexible. The report will be sent as an attachment to the mail,
so you can choose the render format you prefer.
<ers:target name="mail"
class="com.elixirtech.ers2.target.MailTarget" description="">
<ers:property name="smtp.host">elixir.aspirin</ers:property>
<ers:property name="from">tom@example.com</ers:property>
<ers:property name="to">
jane@example.com, alice@example.com
</ers:property>
<ers:property name="cc">
bob@example.com, susan@example.com
</ers:property>
<ers:property name="subject">
Report from Elixir Server
</ers:property>
<ers:property name="message">Your report is attached.
Elixir Repertoire Server.</ers:property>
<ers:property name="filename">report</ers:property>
</ers:target>
The smtp.host parameter can be either the name of the SMTP Server
mbean (we used ERS2:name=GmailSMTPServer when we
discussed this in the section called “SMTP Server”)
or the matching smtp.host value from that mbean (smtp.gmail.com would be
the corresponding value) - either will work fine.
The Print Target allows you to send a report to a named printer. The only option is the name of the printer. If you have multiple alternate printers, you could use a separate target for each (which means you could control access by different groups) or you could choose a single target with a ${substitution} value for the printer name. Obviously in this case the user could print to any named printer. The configuration looks like this:
<ers:target name="my-printer" description=""
class="com.elixirtech.ers2.target.PrintTarget">
<ers:property name="printer-name">my-hp</ers:property>
</ers:target>
The Split Target specifies how the report will be split based on the Table Of Contents (TOC) generated in the Glint output. Only Glint format supports Split Target.
To enable this function, a Split Target configuration should be added to the config file. (A SplitTarget configuration is already included in the config file by default.)
When the SplitTarget receives the rendered Glint file, it will open it and break it at the TOC position(s). You will notice <ers:property name="split">1</ers:property> indicates to break at the top level. You may choose to break at any tree length.
Next, the SplitTarget will look up the destination by comparing the TOC title in sequence.
The first section, the name of the TOC, "first", will match <ers:when test="first">, so the first part will be sent to the target named "printer". By default, the target named "printer" will be directed at the default printer of the system.
The next section, "second", will match <ers:when test="sec(.*)"> because matching supports
full regular expression syntax. In this case, "sec" followed by any characters. This part will go
to output2, with the file named as ond.glint.
Regular expression substitution is allowed here - ${1} is the content that matches the first (..).
The next two sections, "third" and "fourth" don't match either of the first two targets, so they match
the "catch all" target <ers:when test=".*">. These two sections are therefore sent to
output1 with files named as unhandled-third.glint and
unhandled-fourth.glint. The ${0} is the standard regular expression
substitution for the entire matching string.
JDBC Targets allow reports to be written directly into a database. This is useful if you have some subsequent program to pick them up or otherwise act on them - for example a document management system. Each report is written as a record into a specific table in the database. The report data itself is stored as a BLOB. Before you can use the JDBC target, you need to set up a database with a table that has the correct schema to accept a report file. Here's a sample configuration that will write into a table called JobOutput in the Derby database that is built into the Elixir Repertoire Server:
<ers:target name="db"
class="com.elixirtech.ers2.target.JDBCTarget" description="">
<ers:property name="driver">
org.apache.derby.jdbc.EmbeddedDriver
</ers:property>
<ers:property name="url">
jdbc:derby:${elixir.db}/fs
</ers:property>
<ers:property name="table">JobOutput</ers:property>
<ers:property name="overwrite">yes</ers:property>
<ers:property name="name">${name}</ers:property>
</ers:target>
SFTP Target allows a user to send a report to a location on another machine. The available parameters are
user, password, host, port,
dir and filename. The port is optional and will default to 22,
which is the default SFTP port, if not specified. In order to enable this, SFTP Target must be defined
in the config file like this :
<ers:target name="SFTP" class="com.elixirtech.ers2.target.SFTPTarget" description=""> <ers:property name="user">userA</ers:property> <ers:property name="password">password</ers:property> <ers:property name="host">www.example.com</ers:property> <ers:property name="dir">/home/userA</ers:property> <ers:property name="filename">sample.pdf</ers:property> </ers:target>
Users and groups are defined and maintained using the server's web administration interface. See Chapter 6, Web Interface for more details.
You may want to restrict certain users or groups from using certain targets - for example, you don't want everyone to be able to email confidential reports. You can define in ERS2-Config.xml exactly which users and groups should have access to which targets. The default configuration looks like this:
<ers:roles> <ers:role name="*"> <ers:grant target="*"/> </ers:role> <ers:role name="admin"> <ers:grant target="*"/> </ers:role> </ers:roles>
By default all users and groups (*) can access all targets (*). The second statement (that all admin can access all targets) is redundant, because admin are already allowed by the first clause. Usually, you want admin users to be able to access all targets, so this "catchall" is retained so that you can edit the first clause without restricting your own access.
Let us say we have a group of users in the sales department, who should be allowed to use the email target and the db target, but no others. We can state this as follows:
<ers:roles> <ers:role name="sales"> <ers:grant target="email"/> <ers:grant target="db"/> </ers:role> ... </ers:roles>