|
Dispatching: Configuration of dispatch.xml
Morphis dispatching rules are defined in the dispatch.xml
file. This file provides a mapping of requested URL's to processing rules. These
rules specify:
- From where data will be obtained (Requestor)
- Processing parameters
- Processing filters and their associated parameters
(e.g., stylesheets)
The DispatchContext is created with a copy of these
processing rules for a matched page. The Dispatcher itself is responsible
for creating the context, and inserting the rules. These rules can be
appended to by Requestors, requestor streams, and other filters. For example,
it is possible for the HttpRequestor to obtain an XML document which itself
determines how it is to be processed (one way of doing this is via the
<?xml-stylesheet ...?> processing instruction).
Changes to the dispatch.xml file can be
reloaded automatically by setting the dispatch-refresh-interval property
as illustrated in General Configuration.
dispatch |
The dispatch element is the root element
for all processing. |
Attributes: |
(none) |
|
Sub-Elements: |
context |
The dispatch element may contain
one or more context elements, each describing a different set of processing
rules. |
context |
A context represents a place to obtain
data (the requestor) and a set of processing rules explaining how
the processing will occur. |
Attributes: |
match |
The match attribute identifies
a context. Each Dispatcher uses
the match to determine which context to process. For example, the DispatchServlet
uses the request URI to determine which context to process. |
|
matchtype |
The matchtype determines how the match happens. This attribute
can be:
- exact: the match must happen via an exact, case-sensitive
match
- regexp: the match attribute is a regular expression
- wildcard: the match attribute is a wildcard (an asterisk
"*" represents the wildcard character)
|
|
href |
This attribute tells the requestor which page to retrieve. The
meaning of this attribute is dependent on the requestor, but most
likely points to a file or URL (for proxy requests) from which data
will be sourced.
If regexp is set for the matchtype, the href can include backreferences
by including $1, $2, etc.
|
|
requestor |
The requestor attribute is a classname that references an implementation
extending org.morphis.Requestor. The provided requestor org.morphis.URLRequestor
is able to obtain documents via HTTP, local file system, or any
other document supplied in the form of a URL. See the Requestor
section for more details.
|
Sub-Elements: |
parameters |
A listing of parameters
pertaining to the Requestor, and to the processing in general. Parameters
for a particular Filter should occur as subelements of the filter
element. See Context Parameters for a listing
of valid parameters and their default values. |
|
translator |
The translator performs
the processing that converts a stream of data into another stream
of data. |
parameters |
An element which holds a collection
of param elements. |
Attributes: |
(none) |
|
Sub-Elements: |
param |
One or more param elements
containing the actual name/value pairs. |
param |
Element which holds name/value pairs |
Attributes: |
name |
The parameter name |
|
value |
The parameter value |
Sub-Elements: |
(none) |
|
translator |
A translator performs stream level
translation. |
Attributes: |
class |
The classname for the object
performing the translation. The default value of org.morphis.translator.SAXTranslator
is suitable for processing XML streams. See the section
on translators for more information. |
Sub-Elements: |
filter |
One or more filter elements.
The order the filter elements are lists corresponds to the order they
are processed. |
filter |
An element which describes a particular
processing rule. |
Attributes: |
type |
This attribute defines the filter type. Valid filter types are:
- prechain: A prechain filter has the opportunity to examine
and adjust the context before the requestor obtains its data source.
This provides a hook to set up the context with parameters and
other filters to the beginning of the processing chain.
- postchain: A postchain filter performs the same functionality
as the prechain filter, yet it is executed right before translation
occurs. This allows parameters and filters to be set at the end
of the chain (especially useful for appending filters onto the
processing chain). See the section
on writing custom Pre and Post-Chain Filters.
|
|
class |
This specifies the classname
for the filter. |
Sub-Elements: |
parameters |
Filters may require parameters
in order to operate correctly. To achieve this, you may specify a
parameters element within a filter element. |
The following are predefined
parameters understood by Morphis. You may create your own parameters
that can be understood by custom written requestors and filters.
General Default Processing Parameters
|
Name |
Default Value |
Parameter Value Description |
contenttype |
text/html |
Sets the content-type (also known as mime type, or media type)
of the final output stream. |
requestor-cache-max-age |
-1 |
Sets the time in seconds this page should be cached if no
other heuristics can be used. Defaults to never (-1). Requestors smart enough
to know when their content expires may set this parameter directly. For
instance, the org.morphis.HTTPRequestor looks at the Expires
flag to determine when to expire the cache. If the header does not exists,
the value from parameter requestor-cache-max-age is used instead. |
appname |
morphis |
Sets the application name. This name is used to resolve application
properties, directories, and logging levels. For more detail see the the
section on general configuration properties. |
The following example illustrates a <context>
element that matches URI's that match the regular expression ^/foo/bar .
If this match occurs, then the requestor org.morphis.URLRequestor
will obtain its data from http://foobar.com/foo.xml . Processing
is started with the parameter appname set to myapp. Logging and other
information is determined in the myapp.properties file. The
stream will be processed through one translate filter with the class name
org.morphis.translator.XSLTAdapter . This translator performs
an XSLT translation, using the stylesheet foo.xsl . Since
the content type is not specified, it defaults to text/html .
To be more accurate, the media type will be text/html as long as no other
filters explicity set it. In fact, as you will see in the documentation
of the XSLTAdapter, the stylesheet itself is able to set the content
type using the <xsl:output media-type="..."/>
element.
<dispatch>
<context match="^/foo/bar"
matchtype="regexp"
requestor="org.morphis.URLRequestor"
href="http://foobar.com/foo.xml">
<parameters>
<param name="appname"
value="myapp"/>
</parameters>
<translator class="org.morphis.translator.SAXTranslator">
<filter type="translate"
class="org.morphis.translator.XSLTAdapter
">
<parameters>
<param
name="stylesheet" value="foo.xsl"/>
</parameters>
</filter>
</translator>
</context>
</dispatch>
|
|