<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="/default.xps" type="application/x-xpathscript"?>
<page>
	<head>
		<title>Some Advanced Topics</title>
	</head>
<body>
<section>
<title>Overriding ConfigReader</title>
<p>
Say you want to emulate Cocoon 2's SITEMAP feature. How can you do this
with AxKit? Actually it's quite possible. If AxKit doesn't find a set of
stylesheets to use in the XML file, it finally turns to the
ConfigReader, and asks for a DefaultStyleMap. This should return a list
in the form:
<pre>
	[
		[ href, type, media ],
		[ href, type, media ],
		...
	]
</pre>
The default built in ConfigReader class looks at the
AxAddDefaultStyleMap options to obtain this list. However in order to
provide a SITEMAP-like feature you're going to have to parse an XML file
(and cache it, should you wish to do that) and do things depending on
matching a URL, and other features such as User-Agent.
</p>
<p>
So how can you do this? Well the implementation of parsing a
Cocoon2-like SITEMAP file is really up to the implementor (although if
anyone wants to volunteer for that project just yell!). Beyond the
internals of implementing the parsing and matching, it's all rather
simple. First you need a class, let's call it My::ConfigReader:
<pre>
package My::ConfigReader;
use strict;
use vars qw/@ISA/;
@ISA = ('Apache::AxKit::ConfigReader');
</pre>
This makes sure we only have to implement the methods we're interested
in. Then we just implement a DefaultStyleMap method:
<pre>
sub DefaultStyleMap {
	my $self = shift;
	my @styles;

	... implementation here ...

	return \@styles;
}
</pre>
The ConfigReader has access to the apache request object, so it can
discover the URL or the filename, or access the Apache configuration
files, should it need to do that.
</p>
<p>
The return value is an array reference containing a list of array refs
that list href, type and media (see above). Both href and media are
optional and can be undef. Returning no href can allow you to use
something that doesn't use a stylesheet file, such as XSP (XML Server
Pages - see <a href="http://xml.apache.org/cocoon">Cocoon</a>). If media
is undef then it is defaulted to "screen".
</p>
<p>
And don't forget to finish your class with a "1;" to return a true
value. The final thing to do is modify your configuration files so that
AxKit picks this module up as the ConfigReader:
<pre>
# Load my module
PerlModule My::ConfigReader

# Use my reader
AxConfigReader My::ConfigReader
</pre>
</p>
</section>
</body>
</page>
