comparison src/global/UrlMapperImpl.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children 02b2fdfc07e2
comparison
equal deleted inserted replaced
-1:000000000000 0:7ecd1a4ef557
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
39 return null;
40 }
41 }