1 7 package com.inversoft.verge.mvc; 8 9 10 import javax.servlet.http.HttpServletRequest ; 11 12 import com.inversoft.util.StringTools; 13 import com.inversoft.verge.mvc.controller.ControllerMVCInfo; 14 15 16 35 public class MVCURLTools { 36 37 private static volatile String urlBeginning = "/mvc"; 38 39 40 45 public static String getURLBeginning() { 46 return urlBeginning; 47 } 48 49 56 public static void setURLEnding(String urlBeginning) { 57 if (StringTools.isTrimmedEmpty(urlBeginning)) { 58 throw new NullPointerException ("[MVCURLTools] URL beginnings can not be" + 59 " empty or null"); 60 } 61 MVCURLTools.urlBeginning = urlBeginning; 62 } 63 64 70 public static ControllerMVCInfo decodeURL(HttpServletRequest request) 71 throws MVCException { 72 String path = request.getPathInfo(); 74 String begin = MVCURLTools.getURLBeginning(); 75 if (path != null && path.startsWith(begin)) { 76 path = path.substring(begin.length()); 77 } else if (path == null) { 78 throw new MVCException("[MVCURLTools] Encountered an invalid " + 79 "MVC URL [" + request.getRequestURI() + "]."); 80 } 81 82 return new ControllerMVCInfo(path); 84 } 85 } | Popular Tags |