6. Loading processor results

The <value> tag can not only be used to read from a store, but can also be used to invoke a process implicitly and retrieve a result entry of the called processor. The following example shows us how to achieve this:

...

<step id="compose" processor="hello">
   <load parameter="username">
      <value processor=”system” result=”currentDate”/>
   </load>
   <load parameter="style">
      <string>color:red;font:italic;</string>
   </load>
</step>

...

When the parameter username gets loaded, the processor registered by the URL system is called and the result with the key currentDate is bound to the parameter. The system processor can be used to access some information related to the system environment comparable to the java.lang.System class that you might know. The system processor doesn’t require any input and can because of that be invoked this way.

If you want to test this example please remove the content type restriction from the template that we use as we have learned before that a date value is not accepted if the content type is restricted. If you’ve changed the template and have uploaded the latest changes our page should display the current date.

It is also possible to call a processor that required a single parameter as input. To show this by example we now introduce the DateFormatter processor. This processor can be used to format a date to the locale specific representation.

Example 7.1. Portrait of the DateFormatter

DescriptionThis processor can be used to format a date to the locale specific representation
URLdateFormatter
Classorg.apache.projector.processor.text.DateFormatter

Table 7.3. Parameters

NameDescriptionAllowed ValuesRequiredDefault Value
DateThe date to formatAny values of type dateValueYes 
dateFormatSpecifies the date related representation of the formatted result.One of the following stringValue values: none, short, medium, long, fullNoshort
timeFormatSpecifies the time related representation of the formatted result.One of the following stringValue values: none, short, medium, long, fullNoshort
localeSpecifies the locale Any values of type localeNodefault locale

Table 7.4. Results

StateNameDescriptionContent-TypePresentable
OKOutputThe string representation of the formatted datetext/plaintrue

The table above shows us exactly what parameters this processor accepts and what results we can expect. We can see that exactly one parameter is required, the other parameters are optional. So this processor is suited for calling it via the <value> element as you can call processors that require just one or zero parameters.

Change the process definition that it uses the date formatter instead of the current date delivered by the system processor:

<step id="compose" processor="hello">
   <load parameter="username">
      <value processor=”dateFormatter” result=”output”>
         <date>1104354657683</date>
      </value>
   </load>
   <load parameter="style">
      <string>color:red;font:italic;</string>	
   </load>

...

As you can see in this example the child element inside the <value> element contains the value the will be passed to the processor as input parameter. We pass the fixed date value that we already know from our previous examples. If we now take a look at the rendered page we can see that the date is formatted in the way that we could have expected: The time and date part of the format are in short form as these are the default values of the optional parameters and the date is formatted in the appropriate way for the systems default locale:

As the output of the date formatter is of content type plain/text we now can restrict the content type for our variable in our template again.