Difference between revisions of "Serving "application/tei+xml" from Cocoon"
(New page: = How to serve TEI XML from Cocoon with the content-type "application/tei+xml" = Most websites which publish TEI XML documents describe them with the content type "application/xml" or "te...) |
|||
Line 17: | Line 17: | ||
<pre><nowiki> | <pre><nowiki> | ||
<serialize type="tei"/> | <serialize type="tei"/> | ||
− | </ | + | </nowiki></pre> |
= Preferred configuration = | = Preferred configuration = | ||
Line 68: | Line 68: | ||
</sitemap> | </sitemap> | ||
− | </ | + | </nowiki></pre> |
Revision as of 06:36, 22 October 2010
How to serve TEI XML from Cocoon with the content-type "application/tei+xml"
Most websites which publish TEI XML documents describe them with the content type "application/xml" or "text/xml". These are two labels for XML files in general, and don't identify the files as specifically TEI XML. By using the content type "application/tei+xml", a webserver can make the specific claim that the XML file is TEI rather than any other kind of XML. This has the advantage that browsers can be configured to handle TEI files distinctly from the way they handle other XML files (for instance, by opening them in an XML editor).
Simple configuration
To specify the content type, simply configure a serializer in your sitemap.xmap file, and then invoke the serializer in your TEI pipeline.
To declare the serializer:
<serializer mime-type="application/tei+xml" name="tei" src="org.apache.cocoon.serialization.XMLSerializer"/>
Invoking the serializer:
<serialize type="tei"/>
Preferred configuration
Most browsers will adequately display generic XML but will not be configured to handle the specific content type "application/tei+xml". For this reason, it's usually better to serve the TEI as "application/tei+xml" only if the browser specifically asks for it, and otherwise to serve it as the generic "application/xml".
In Cocoon, you can use a RegexpHeaderSelector to determine if a browser is prepared to handle the specific content type. The following Cocoon sitemap shows a Reg
<?xml version="1.0" encoding="UTF-8"?> <sitemap xmlns="http://apache.org/cocoon/sitemap/1.0"> <components> <!-- declare two serializers: one for tei-xml, and one for generic xml --> <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> <!-- declare a selector for determining if a browser will accept tei-xml --> <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> <!-- declare a pipeline fragment for serializing TEI with the most appropriate content type; --> <!-- tei-xml if the browser will accept it, or plain generic xml otherwise --> <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> </pipeline> </pipelines> </sitemap>