diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/global/UrlMapperImpl.java	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,41 @@
+package global;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.servlet.http.HttpServletRequest;
+import fschmidt.util.servlet.UrlMapper;
+import fschmidt.util.servlet.UrlMapping;
+
+
+enum UrlMapperImpl implements UrlMapper {
+	INSTANCE;
+
+	private static final Pattern ROOT_FORUMS_PATTERN = Pattern.compile("/free-apps/page(\\d+)\\.html$");
+
+	public UrlMapping getUrlMapping(HttpServletRequest request) {
+		String path = request.getServletPath();
+
+		if( path.equals("/") )
+			return new UrlMapping( global.web.Index.class, Collections.<String,String[]>emptyMap() );
+
+		if( path.equals("/tools/") )
+			return new UrlMapping( global.web.tools.Index.class, Collections.<String,String[]>emptyMap() );
+
+		Matcher m = ROOT_FORUMS_PATTERN.matcher(path);
+		if( m.find() ) {
+			Map<String,String[]> params = new HashMap<String,String[]>();
+			String s = m.group(1);
+			if( s != null )
+				params.put( "page", new String[]{s} );
+			return new UrlMapping( global.web.RootForums.class, params );
+		}
+
+		if( path.equals("/sitemap.txt") )
+			return new UrlMapping( global.web.Sitemap.class, Collections.<String,String[]>emptyMap() );
+
+		return null;
+	}
+}