You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tiles.apache.org by Antonio Petrelli <ap...@apache.org> on 2007/04/16 16:04:48 UTC

Loading Tiles configuration files in Tiles extensions

Hi all!
I noticed a problem for Tiles extension developers that I discovered
when converting Dimensions to Tiles 2. I hope to be clear, beucase it
is not easy.
Essentially Dimensions extends UrlDefinitionsFactory. Since a
"DefinitionsFactory" has no knowledge of a TilesApplicationContext, it
cannot load resources.
Now, Dimensions reads a configuration file (specific to Dimensions)
that contains some path references (like "/WEB-INF/tiles-a-defs.xml")
to Tiles definitions files. The configuration file is read inside the
Dimensions DefinitionsFactory, so it cannot load any resources because
it does not know how to resolve them!
(Well, in fact it can, because all implementations of
TilesRequestContext extend an implementation of
TilesApplicationContext, but it seems like a hack).
UrlDefinitionsFactory is able to access different URLs from those
provided by the "addSource" methods, because they are calculating
appending to the main URL one or more suffixes for the current Locale:
the Locale object is provided by the LocaleResolver. But in the case
of Dimensions there is no concept of "base URL"!

So, I think that the best (for me :-) ) solution to this problem is
using an object to manage definitions sources (I'll call it
DefinitionsSourcesManager) whose task is to load (and reload) sources
(usually URLs) and provide simple "Map<String, Definition>" objects.
This object will be created, initialized and invoked by the
DefinitionsFactory. Not in the container because currently its only
task is to transform paths into URLs to pass to the
DefinitionsFactory.
Anyway I know that it is a big change so it can be postponed to Tiles
2.1. Anyway in Tiles 2.0 we can pass a TilesApplicationContext to the
DefinitionsFactory, so it can load new URLs: it's a question of adding
a method, I suppose.

Thoughts?
Antonio