0
|
1 package global;
|
|
2
|
|
3 import java.util.Collections;
|
|
4 import java.util.Map;
|
|
5 import java.util.HashMap;
|
|
6 import java.util.regex.Matcher;
|
|
7 import java.util.regex.Pattern;
|
|
8 import javax.servlet.http.HttpServletRequest;
|
|
9 import fschmidt.util.servlet.UrlMapper;
|
|
10 import fschmidt.util.servlet.UrlMapping;
|
|
11
|
|
12
|
|
13 enum UrlMapperImpl implements UrlMapper {
|
|
14 INSTANCE;
|
|
15
|
|
16 private static final Pattern ROOT_FORUMS_PATTERN = Pattern.compile("/free-apps/page(\\d+)\\.html$");
|
|
17
|
|
18 public UrlMapping getUrlMapping(HttpServletRequest request) {
|
|
19 String path = request.getServletPath();
|
|
20
|
|
21 if( path.equals("/") )
|
|
22 return new UrlMapping( global.web.Index.class, Collections.<String,String[]>emptyMap() );
|
|
23
|
|
24 if( path.equals("/tools/") )
|
|
25 return new UrlMapping( global.web.tools.Index.class, Collections.<String,String[]>emptyMap() );
|
|
26
|
|
27 Matcher m = ROOT_FORUMS_PATTERN.matcher(path);
|
|
28 if( m.find() ) {
|
|
29 Map<String,String[]> params = new HashMap<String,String[]>();
|
|
30 String s = m.group(1);
|
|
31 if( s != null )
|
|
32 params.put( "page", new String[]{s} );
|
|
33 return new UrlMapping( global.web.RootForums.class, params );
|
|
34 }
|
|
35
|
|
36 if( path.equals("/sitemap.txt") )
|
|
37 return new UrlMapping( global.web.Sitemap.class, Collections.<String,String[]>emptyMap() );
|
|
38
|
10
|
39 if( path.equals("/ads.txt") )
|
|
40 return new UrlMapping( global.web.Ads.class, Collections.<String,String[]>emptyMap() );
|
|
41
|
0
|
42 return null;
|
|
43 }
|
|
44 }
|