tags:

views:

22

answers:

2

I would like a library that works just like servlet mappings without the servlet container. It should support concepts such as

/*        maps the default value
/exact    maps exact path maps
/prefix   maps any path that begins with "/prefix"
*.suffix  maps any paths that end with "suffix".

Imagine something like a Map that accepts string paths to fetch values. The library should also support some concept of priority so if i add an exact path before a prefix, the test is against the exact before checking the prefix paths. Naturaly i could write my own up but a boring linear search seems a bit dumb especially as most paths will be exact patterns.

Does anyone know of a library that does something like this ???

A: 

Spring MVC supports Ant-style globs in request path mappings. In your controller class (annotated with @Controller), you can specify your path pattern in the RequestMapping annotation on your handler method like this:

@Controller
public class HelloWorldController {

    @RequestMapping("/myPath/*.do")
    public ModelAndView helloWorld() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("helloWorld");
        mav.addObject("message", "Hello World!");
        return mav;
    }
}
oksayt
Oops, I think I misread the question.. You want to use path lookup functionality similar to this outside of a servlet container.
oksayt
A: 

I ended up righting my own little package that uses the chain of responsbility pattern. It groups exact matches that were added consecutively into a single link(not sure what eacch element in a cor is called) in the chain. All other types of mapping are single "links". The search invokes the chain until a value is returned ignoring the remainder of the chain.

mP