Introduction
NetKernel is not limited to just a single transport - any number of transports can be used as the source of
externally initiated processes. In this example we'll show how to use the Intray Transport
to provide
the basis of an XSL-FO to PDF distiller.
Specification
We will configure two directories, one an in-tray, the other an out-tray. XSL-FO files copied into the intray directory
will be processed into PDF and placed in the out-tray directory.
We will create a module xslfo-distiller which will host the Intray transport and the XSL-FO to PDF distiller.
Preparation
-
To create the distiller you must download and install the XSL-FO module. You can do this with the
install wizard
- make sure you select the "view libraries" option.
-
Using the new module wizard
create a new module called xslfo-distiller - choose the default
options for paths etc. Don't import your new module into an existing fulcrum - we will make it the fulcrum for the Intray transport. Also
ensure you include support for DPML as we'll write the distiller process in DPML.
-
You'll find your new module in the [install]/modules directory. Edit it's module.xml definition, follow the
Intray transport instructions
to import the Intray transport and add the transport to your module.
Set up the /etc/TransportIntrayConfig.xml configuration file choosing an in and out directory on
your hosts filesystem with read/write access for NetKernel - make sure that etc/ is mapped in the mapping section or the Intray won't
be able to find it's config.
-
Import the XSL-FO module into the <mapping> section for your module by adding the following - make sure it appears before any
<super> declaration.
<import>
<uri>urn:org:ten60:netkernel:ext:xslfo</uri>
</import>
-
Your distiller module is now configured - all that's left is to test your config and write the distiller process.
Testing
To test your module and Intray transport add a simple DPML idoc in the resources/ directory of your module. Name it 'test.idoc'. Here's one that simply copies the param argument
to the response.
<idoc>
<seq>
<instr>
<type>copy</type>
<operand>this:param</operand>
<target>this:response</target>
</instr>
</seq>
</idoc>
To have the Intray invoke this process for every file that is placed in the "in" directory edit the IntrayConfig and set the process URI
to active:dpml+operand@ffcpl:/resources/test.idoc
. Your Intray transport should now be all set. Do a
cold restart
to pick up the changes you've made to the module.xml.
You should now be able to copy a file to your in directory and see it processed
and placed in the out directory. The Intray transport prepends a "p" to the filename to indicate it is a processed result.
Writing the XSLFO Distiller
The distiller is very simple, it is shown below. Copy it to your resources/ directory as file distiller.idoc. As before edit the etc/TransportIntrayConfig.xml
to active:dpml+operand@ffcpl:/resources/distiller.idoc
and cold restart
to pick up the changes you've made.
<idoc>
<seq>
<instr>
<type>xslfo-fop</type>
<operand>this:param</operand>
<operator>
<xslfo-fop>
<type>pdf</type>
</xslfo-fop>
</operator>
<target>this:response</target>
</instr>
</seq>
</idoc>
Copy an XSL-FO file into the in directory. It will be processed to PDF. Note the Intray transport is very simple and does not yet support renaming
of the processed file. You will have to edit the filename to end in ".pdf".
Conclusion
This pattern shows the use of an alternative transport to initiate requests. It will be obvious to you by now that you could change the process
to anything you like. You might also find it useful to look at the Intray transport's code for ideas as to how to create a custom transport for
NetKernel.