For those interested I just did a test in my local workspace whether
this is feasible and it turns out to be quite easy.
Added a MappingService with the method:
public void addPagePath(List fileList, String resource);
By default it checks if the resource ends with ".jsp" or ".htm" and
adds it to the fileList.
The following XmlConfigService methods needed changing in order to
invoke the MappingService#addPagePath(fileList, resource) method:
private List getTemplateFiles()
private List processDirectory(String dirPath, List fileList)
A change was also needed for the XmlConfigService#isJspPage check.
With this in place I mapped ".xml" extension (together with ".htm") to
ClickServlet in web.xml and overrode the method addPagePath to also
add all ".xml" resources to the fileList. And voila Click rendered xml
templates :)
regards
bob
Bob Schellink wrote:
Hi Jozsef,
Perhaps we can introduce a service which encapsulates the URL mapping
into a Service. A default implementation can handle .htm and .jsp but
users can extend it for other purposes as well.
How would the web.xml mapping look like for ClickServlet though? Say one
wants to serve a *.css template backed by a Click Page how will it be
mapped in web.xml? If one maps it as '*.css', then all css files,
regardless if they have a backing Page, will be served by ClickServlet
and it will need to handle that.
kind regards
bob
[email protected] wrote:
May I defend my points?
CSS templating:
It think dynamically generated CSS files are acceptable and they work
wonderfully.
They allow to change border colors background colors, background
images on the fly.
Example:
input {
border-color: $objectStyle.borderColor;
border-width: 1px;
border-style: solid;
}
body{
background-image: url($context/content?id=1&file=101&cat=0);
background-repeat: repeat;
}
XML files and RSS files:
RSS and list like XML files can be generated with templating too.
Very complex XML files require a library.
Sitemap Index and Sitemap files are same as XML
Example sitemap template:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
#foreach ($pData in $pageData)
<sitemap>
<loc>$pData.location</loc>
<lastmod>$pData.lastModified</lastmod>
</sitemap>
#end
</sitemapindex>
Here are the living sitemap examples. (The sitemap xml is requested as
html so the browser will display it as html.
Please open the source in the browser to be able to see the xml.)
http://217.114.115.252/sitemap.htm?cat=346
http://217.114.115.252/sitemap.htm?cat=883
http://217.114.115.252/sitemap-index.htm
Json data file can be generated with the xstream library.
If the Json data set is not huge the entire content can be collected
into a single string.
Javascript templating.
Sometimes javascript components need several configuration parameters.
These configuration parameters could be supplied by objects placed in
the context.
For example a flash object can be implemented as a custom control.
Instances of this the flash controls can be placed in the middle of
pages for example.
It is also possible to create a flash-panel that use html template.
Instances of the panel can be added to a page.
Both solution would work. Selection is the question of preference. (I
prefer custom control for flash.)
In general any kind of textual content (except json) can be served by
templating mechanism.
It may not be efficient to create custom control for everything.
Kind Regards.
Jozsef Gabor