You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Mick Semb Wever <mc...@apache.org> on 2013/11/03 17:09:22 UTC

Re: Cascading preference when a view name matches several templates

ClamAV 0.96.5

On Tue, 2013-10-29 at 11:45 -0400, Eric B wrote:
> How does tiles know which definition to use?  Is there a precedence
> order?  Is it based on the order in which the tile*.xml files are
> registered/loaded?

Without double-checking the code my memory from experience tells me that
the first definition found (as files are loaded and as found in the
file) is the definition that is used.

~mck

-- 
"Only two things are infinite, the universe and human stupidity, and I'm
not sure about the former." Albert Einstein 

| http://github.com/finn-no | http://tech.finn.no |


Re: Cascading preference when a view name matches several templates

Posted by Mick Semb Wever <mc...@apache.org>.
ClamAV 0.96.5

> >> How does tiles know which definition to use?  Is there a precedence
> >> order?  Is it based on the order in which the tile*.xml files are
> >> registered/loaded?
> >
> > Without double-checking the code my memory from experience tells me that
> > the first definition found (as files are loaded and as found in the
> > file) is the definition that is used.
> 
> [snip], but I would have loved to have a feature that uses "closest
> match" algorithm as opposed to a "first-defn found".


One way to solve this is to have a custom
PrefixedPatternDefinitionResolver overriding
AbstractPatternDefinitionResolver.addDefinitionsAsPatternMatchers(..)

so that the loop over the defsMap happens in the order you want.

And return this custom PrefixedPatternDefinitionResolver from your
TilesContainerFactory.createPatternDefinitionResolver(..)


I guess the closest match strategy could be done using
StringUtils.getLevenshteinDistance(..)


> I'm surprised that no-one has seen the need for something like this
> before.

I guess just adjusting the order of the definitions in the tiles xml has
been good enough for everyone.

But something like described above, a la an
EditDistanceOrderedPrefixedPatternDefinitionResolver, has value and i'd
vote for accepting it into the tiles.

~mck



-- 
Nature does not hurry, yet everything is accomplished. - Lao Tzu 

| http://github.com/finn-no | http://tech.finn.no |


Re: Cascading preference when a view name matches several templates

Posted by Eric B <eb...@hotmail.com>.
On 13-11-03 11:09 AM, Mick Semb Wever wrote:
> ClamAV 0.96.5
>
> On Tue, 2013-10-29 at 11:45 -0400, Eric B wrote:
>> How does tiles know which definition to use?  Is there a precedence
>> order?  Is it based on the order in which the tile*.xml files are
>> registered/loaded?
>
> Without double-checking the code my memory from experience tells me that
> the first definition found (as files are loaded and as found in the
> file) is the definition that is used.

That sounds similar to what I remember reading in the code, and is understandable, but I would have loved to have a feature that uses "closest match" 
algorithm as opposed to a "first-defn found".

For example:
defn= "REGEXP: ^some.+\.jsp"
vs
defn="something.jsp"

I realize that this opens a quagmire of how to determine which is the closest match (ex: is REGEXP: ^some.+\.jsp" a closer match than WILDCARD: 
some*.jsp).  In which case, maybe a weighting or priority option, such that if I have one regex that is more explicit, to use it before using one that 
is less explicit.  If I remember correctly, non-pattern based expressions are checked first, but otherwise, it is somewhat pseudo-random order.

I'm surprised that no-one has seen the need for something like this before.

Thanks,

Eric