[Yanel-dev] customizing Yanel serialization formats: XHTML Strict
Transitional, HTML Strict, (X)HTML 5, JSON, ...
Guillaume Déflache
guillaume.deflache at wyona.com
Tue Jun 1 17:53:41 CEST 2010
Hi!
Michi asked me to document the ways to customize serialization
serialization in Yanel, so here it is.
This can be done at two levels:
- in the RC files
- in Java code
First the following formats already exist in Yanel, so no need for
customization to use them: XHTML Strict, HTML Transitional, XML, text.
To implement the following formats the following output properties must
be set:
*HTML Strict*: set serializer key to HTML_TRANSITIONAL to get the base
HTML properties right, then force the public doctype to the standard
HTML Strict value: "-//W3C//DTD HTML 4.01//EN", the system doctype may
be left alone as AFAIK mainstream browsers do not care and anyway Yanel
still has a bug on that, see comment example below)
Example:
---8<---
<?xml version="1.0"?>
<yanel:resource-config xmlns:yanel="http://www.wyona.org/yanel/rti/1.0">
[...]
<yanel:custom-config>
<views xmlns="http://www.wyona.org/yanel/rti/1.0">
<view id="[...]">
[...]
<mime-type>text/html</mime-type>
<serializer key="HTML_TRANSITIONAL">
<!--XXX HACK: forcing the doctype manually since Yanel does not
know about HTML Strict ATM: -->
<doctype-public>-//W3C//DTD HTML 4.01//EN</doctype-public>
<!-- does not seem to work (!?!), the system doctype is stuck
with the 'loose' value: -->
<doctype-system>http://www.w3.org/TR/html4/strict.dtd</doctype-system>
<!--
<indent>no</indent>
-->
</serializer>
</view>
[...]
</views>
</yanel:custom-config>
</yanel:resource-config>
---8<---
*XHTML Transitional*: set serializer key to XHTML_STRICT to get the base
XML properties right, then force the public doctype to the standard
XHTML Transitional value: "-//W3C//DTD XHTML 1.0 Transitional//EN", the
system doctype may remain wrong (same as above).
Sadly this alone does not quite work yet because of one Yanel bug and
one missing workaround, see
http://lists.wyona.org/pipermail/yanel-development/2010-June/004840.html
This can however been done in Java code by overriding
#getViewDescriptor(String viewId) in every resource-type that needs the
right format, using the following helper code example:
---8<---
/**
* Reconfigure the view to use XHTML 1.0 strict.
*/
private static final void
reconfigureViewDescriptor(ConfigurableViewDescriptor cvd) {
cvd.setMimeType("text/html");
cvd.setSerializerKey(SerializerFactory.XHTML_STRICT_KEY);
Properties serializerProperties = new Properties();
serializerProperties.setProperty(OutputKeys.INDENT, "no");
serializerProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
serializerProperties.setProperty(OutputKeys.ENCODING, "UTF-8");
serializerProperties.setProperty(OutputKeys.DOCTYPE_PUBLIC,
"-//W3C//DTD XHTML 1.0 Transitional//EN");
serializerProperties.setProperty(OutputKeys.DOCTYPE_SYSTEM,
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
serializerProperties.setProperty(OutputKeys.METHOD, "html");
//XXX HACK: needed to force root element name in doctype declaration,
see http://lists.wyona.org/pipermail/yanel-development/2010-June/004840.html
cvd.setSerializerProperties(serializerProperties);
}
---8<---
Other interesting format may be: JSON, HTML 5, XHTML 5, etc.
HTH,
Guillaume
More information about the Yanel-development
mailing list