Hi Conal,
On 10-10-20 06:46 PM, Conal Tuohy wrote:
> On 21/10/10 03:37, Martin Holmes wrote:
>> Congratulations on progress with the mime type. I've just started
>> experimenting again with this, to see what the effect would be on my
>> Cocoon sites, and the results at the moment are not ideal.
> Thanks Martin!
>
> Based onyour experience I had this idea: serve the TEI content-type if
> the browser requests it, otherwise serve plain XML.
This is great -- thanks for all the detail. I'll set this up on all my
Cocoon sites, and see how easy it is to configure various browsers to
use it. I think this would make a good wiki page.
Cheers,
Martin
> In Cocoon, as I'm sure you know, you can do this by declaring two
> instances of the XML serializer, with the two content types "text/xml"
> and "application/tei+xml", and in your pipelines selecting the
> appropriate one based on the user agent's Accept header, as described here:
> http://cocoon.apache.org/2.1/userdocs/regular-expression-header-selector.html
>
> <select type="accept-content-type">
> <when test="application/tei+xml">
> <serialize type="tei"/>
> </when>
> <otherwise>
> <serialize type="xml"/>
> </otherwise>
> </select>
>
> This way if you wish to launch your favourite XML editor to display TEI
> then you can do so by configuring your browser to send the appropriate
> Accept header and to associate the content-type with your XML editor
> application.
>
> I've tested this out and you can see an example here:
> http://tei.versi.edu.au/bates/transcript/2d9.xml
>
> My browser is now configured to send "application/tei+xml" in the Accept
> header, and to launch jEdit to display TEI content. Other "text/xml"
> content still displays in Firefox. This is actually really handy and I
> wish I'd thought of it earlier.
>
> BTW, I'm not sure if there's a really convenient way to change the
> Accept header in Firefox: what I did was enter "about:config" into the
> address bar, find the key called "network.http.accept.default" and
> change it to this:
>
> "text/html;q=0.7,application/xhtml+xml;q=0.8,application/tei+xml;q=0.7,application/xml;q=0.6,*/*;q=0.4,application/json;q=0.5"
>
> (inserting "application/tei+xml" in with a higher priority than
> "application/xml")
>
> The Cocoon sitemap looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <sitemap xmlns="http://apache.org/cocoon/sitemap/1.0">
> <components>
> <serializers>
> <serializer mime-type="application/xml" name="xml"
> src="org.apache.cocoon.serialization.XMLSerializer"/>
> <serializer mime-type="application/tei+xml" name="tei"
> src="org.apache.cocoon.serialization.XMLSerializer"/>
> </serializers>
> <selectors>
> <selector name="accept-content-type"
> src="org.apache.cocoon.selection.RegexpHeaderSelector">
> <pattern xmlns="" name="tei">application/tei\+xml</pattern>
> <header-name xmlns="">accept</header-name>
> </selector>
> </selectors>
> </components>
>
> <resources>
> <resource name="serialize-tei">
> <select type="accept-content-type">
> <when test="tei">
> <serialize type="tei"/>
> </when>
> <otherwise>
> <serialize type="xml"/>
> </otherwise>
> </select>
> </resource>
> </resources>
>
> <pipelines>
> <pipeline>
>
> <match pattern="transcript/*.xml">
> <generate src="tei/{1}.xml"/>
> <call resource="serialize-tei"/>
> </match>
>
> <match pattern="lexicon/*.xml">
> <generate src="cocoon:/transcript/{1}.xml"/>
> <transform src="xslt/tei-add-term-gloss-markup.xsl"/>
> <call resource="serialize-tei"/>
> </match>
>
> <match pattern="search/*.xml">
> <generate src="cocoon:/lexicon/{1}.xml"/>
> <transform src="xslt/translate.xsl">
> <parameter name="use-request-parameters" value="true"/>
> </transform>
> <serialize type="html"/>
> </match>
> </pipeline>
> </pipelines>
>
> </sitemap>
>
> NB that's a sub-sitemap which inherits some default generators etc. I
> factored out the content-type negotiation into a Cocoon resource called
> "serialize-tei" because I needed it twice. Strictly speaking it's a bit
> broken since it doesn't respect the "q" parameter in the Accept header
> (i.e. you get application/tei+xml even if you configure your browser to
> say you prefer application/xml but are prepared to accept
> application/tei+xml with a lower priority - though why you'd do that I
> can't imagine).
>
|