It's very common for the pathinfo of an URL to provide structured data to the element that handles the request. You can now easily setup rules that let RIFE do all the parsing of received pathinfos and construction of created pathinfos. This allows you to continue to work with regular exits and inputs, and automatically have usable and RESTful URLs with pathinfos created for you.
introducing pathinfo mappings
To make this possible, you have to use the <pathinfo> tag, for example:
<element id="MyElement" url="myurl/*" implementation="com.pakkage.MyImplementation">
<pathinfo mapping="$year/$month/$day"/>
<pathinfo mapping="$year/$month"/>
<input name="year"/>
<input name="month"/>
<input name="day"/>
</element>
RIFE will now detect when an URL like this is called:
The pathinfo ('/2005/11/25' here) will be matched against the mappings that have been setup in the element declaration. This causes the year, month and day variables to be extracted. Their values will simply be provided as inputs to your elements.
You can declare as many mappings as you want and RIFE will process them sequentially according to their order of declaration. This means that the following URL will also be supported and only the year and month inputs will be populated.
regular expressions
By default, RIFE matches the following regular expression as values for pathinfo mapping variables:
It is possible to declare your own regular expression for each variable, like this for example:
<element id="MyElement" url="myurl/*" implementation="com.pakkage.MyImplementation">
<pathinfo mapping="$year(\d{4})/$month(\d{2})/$day(\d{2})"/>
<pathinfo mapping="$year(\d{4})/$month(\d{2})"/>
</element>
This will ensure that your pathinfo will only be mapped to the inputs when the variable actually correspond to the regular expressions that you declared (in this case they are enforced to be numbers and their length has been fixed).
optional input declarations
You also see in the previous example that haven't declared the inputs anymore. RIFE supports this since it will automatically add inputs for all the variables that you declared in the pathinfo mappings.
alternative variable syntax
For complex pathinfo situations, we support an alternative syntax that uses a curly brace syntax, for instance:
<pathinfo mapping="y${year}m${month}(\d+)d${day}"/>
This will map URLs like this:
URL generation
RIFE will also automatically detect when you have a flowlink and datalinks that point towards an element that accepts pathinfo mappings. Any output values that are provided to inputs, will be matched to the supported regular expressions. The first pathinfo mapping for which all the input values are valid, will be used to generate an URL that contains the input values in the pathinfo. This provides you with a single point of declaration that automatically, consistently and easily handles the mapping of pathinfo in bidirectional manner.