-
Notifications
You must be signed in to change notification settings - Fork 168
Design Doc: Offline Usage
SiteMesh has typically been used to decorate content on the fly in a web-application using a Servlet Filter. However there is also a strong need to be able to apply decorators to static files as an offline batch activity.
The SiteMesh offline generator will keep things simple – it will apply static decorators to static content. If any additional processing needs to be done (e.g. generating a navigation bar), this can be done by other tools (e.g. Texen).
Various options…
Example Java API usage:
Directory sourceDir = new FileSystemDirectory("src/html"); Directory dirDir = new FileSystemDirectory("build/html"); ContentProcessor contentProcessor = // your ContentProcesor DecoratorSelector decoratorSelector = // your DecoratorSelector SiteMeshOfflineGenerator generator = new SiteMeshOfflineGenerator( contentProcessor, decoratorSelector, sourceDir, destinationDir); generator.process("somecontent.html"); generator.process("docs/anotherfile.html");
All the other usages of the generator will simply be layers on top of this.
The standard sitemesh jar will be executable. Options are passed as command line arguments.
java -jar sitemesh.jar --sourcedir=/dir1 --destdir=/dir2 --config=sitemesh.xml /dir1/*.html
The tool must be passed a list of file names that it should process (trailing arguments).
It should also be possible to treat the tool as a pipe filter (i.e. input via stdin, output via stdout). Example:
cat somefile.html | java -jar sitemesh.jar --sourcedir=/dir1 --config=sitemesh.xml > newfile.html
It would also be nice to wrap this up in a script or binary for convenience. This could be a useful tool that would reach beyond Java developers. Example:
# Platform specific installation apt-get install sitemesh # Now use it cat somefile.html | sitemesh --decorator=somedecorator.html > newfile.html
The SiteMesh Ant task will act as an Ant FilterReader that can be embedded in an Ant FilterChain (inside a <copy> task).
The advantage the FilterReader has over a standalone Ant task is that:
- It can be chained with other filters in a single copy operation.
- It inherits all the features of the <copy> task.
Example ant task:
<!-- Define filter --> <typedef type="sitemesh" classname="org.sitemesh.offline.ant.SiteMeshFilter" classpath="path/to/sitemesh.jar"/> <!-- Copy HTML files from srcdir to destdir, applying decorators as it goes. --> <copy todir="destdir"> <fileset dir="srcdir" includes="**/*.html"/> <filterchain> <sitemesh config="sitemesh-config.xml"/> </filterchain> </copy>
Like the other interfaces to the offline generator, it should be possible to configure it by pointing at a sitemesh config file (as in example above) or through inline parameters:
<!-- Alternative, use inline parameters --> <copy file="srcdir" todir="destdir"> <filterchain> <sitemesh> <!-- note Ant style file patterns. --> <decorator path="**/*.html" decorator="/decorators/main.html"/> <decorator path="docs/*.html" decorator="/decorators/docs.html"/> </sitemesh> </filterchain> </copy>
TODO
Any configuration mechanism that is available to the online version of SiteMesh should be applicable offline. In fact, the offline generator and online Servlet should be able share the same config and behave in the same way (assuming the content is static of course).
The configuration options should include:
- Referencing a config file
- Config passed as arguments to tool
- A config object (built programatically, injected through container, etc)
As usual, it should be easy for users to wire up their own config mechanisms.
- The Java API will be accessed through a virtual file system interface. Typically this will be backed by an implementation that reads/writes directly to disk, but it will also make it easy to customize to use different sources/destinations (e.g. database, web sites, in memory).
- Only write if output modified. If SiteMesh is run and the result is no different to the last run, the file should not be modified. This makes it play nice with incremental build tools.
- It should be possible to mix and match offline and online. For example, say a site mostly consists of static page, but a few are generated by Servlets, you should be able to share the same decorators and config, and get optimal runtime performance.
- Offline generation: Java API complete. See org.sitemesh.offline
- Command: line complete. Run java -jar sitemesh.jar for usage.
- Incremental: output complete. Does not overwrite files that have not been modified.
- Ant task: Not yet started