PageRenderTime 31ms CodeModel.GetById 30ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/ingenieux/nullweblog/util/URIUtil.java

https://bitbucket.org/aldrinleal/nullweblog
Java | 28 lines | 20 code | 8 blank | 0 comment | 1 complexity | 72b011ee1d742965df96f9708f3934fc MD5 | raw file
 1package com.ingenieux.nullweblog.util;
 2
 3import java.util.regex.Matcher;
 4import java.util.regex.Pattern;
 5
 6public class URIUtil {
 7	private static final URIUtil INSTANCE = new URIUtil();
 8
 9	public static final URIUtil getInstance() {
10		return INSTANCE;
11	}
12
13	private static final Pattern PATTERN_ROOT = Pattern
14			.compile("^(http://[^/]+).*$");
15
16	public StringBuilder getRequestBase(String requestPath) {
17		Matcher matcher = PATTERN_ROOT.matcher(requestPath);
18
19		if (!matcher.find())
20			return new StringBuilder("");
21
22		return new StringBuilder(matcher.group(1));
23	}
24	
25	public StringBuilder getRequestBase(StringBuffer buffer) {
26		return getRequestBase(buffer.toString());
27	}
28}