public BasicSelector(String... mimeTypesToBuffer) { this(new PathMapper<Boolean>(), false, mimeTypesToBuffer); }
/** Retrieve appropriate pattern by matching patterns with supplied path. */ public String getPatternInUse(String path) { if (path == null) path = "/"; String result = findExactKey(path); if (result == null) result = findComplexKey(path); if (result == null) result = findDefaultKey(); return result; }
private String findComplexKey(String path) { String result = null; for (String key : mappings.keySet()) { if (isComplexKey(key) && match(key, path, false)) { if (result == null || key.length() > result.length()) { // longest key wins result = key; } } } return result; }
/** * Wheter the first pattern is more specific than the second one. * Exact patterns are more specific than complex patterns and * complex patterns are more specific than default patterns. * @param exclusionPattern pattern which must be more or equally specific to return <code>true</code> * @param decoratorPattern pattern which must be less specific to return <code>true</code> * @return <code>true</code> if the first pattern is more specific than the second one */ public static boolean isMoreSpecific(String exclusionPattern, String decoratorPattern) { if(isDefaultKey(decoratorPattern)) { return true; } if(isComplexKey(decoratorPattern)){ if(isComplexKey(exclusionPattern)) { return exclusionPattern.length() >= decoratorPattern.length(); } return !isDefaultKey(decoratorPattern); } return !isComplexKey(exclusionPattern) && !isDefaultKey(exclusionPattern); } }
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String exclusionPattern = getSelector().excludePatternInUse(request); if (exclusionPattern != null) { // Ability to override exclusion by more specific pattern if (decoratorSelector instanceof PathBasedDecoratorSelector) { PathBasedDecoratorSelector<WebAppContext> pbds = (PathBasedDecoratorSelector<WebAppContext>) decoratorSelector; String decoratorPattern = pbds.getPathMapper().getPatternInUse(WebAppContext.getRequestPath(request)); if(decoratorPattern == null) { // there is no decorator rule for this exclusion pattern filterChain.doFilter(request, response); return; } if(PathMapper.isMoreSpecific(exclusionPattern, decoratorPattern)){ // if the exclusion type is more specific filterChain.doFilter(request, response); return; } } } super.doFilter(servletRequest, servletResponse, filterChain); }
public String[] selectDecoratorPaths(Content content, C siteMeshContext) throws IOException { String[] result = pathMapper.get(siteMeshContext.getPath()); return result == null ? EMPTY : result; }
@Override public String excludePatternInUse(HttpServletRequest request) { return excludesMapper.getPatternInUse(WebAppContext.getRequestPath(request)); }
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String exclusionPattern = getSelector().excludePatternInUse(request); if (exclusionPattern != null) { // Ability to override exclusion by more specific pattern if (decoratorSelector instanceof PathBasedDecoratorSelector) { PathBasedDecoratorSelector<WebAppContext> pbds = (PathBasedDecoratorSelector<WebAppContext>) decoratorSelector; String decoratorPattern = pbds.getPathMapper().getPatternInUse(WebAppContext.getRequestPath(request)); if(decoratorPattern == null) { // there is no decorator rule for this exclusion pattern filterChain.doFilter(request, response); return; } if(PathMapper.isMoreSpecific(exclusionPattern, decoratorPattern)){ // if the exclusion type is more specific filterChain.doFilter(request, response); return; } } } super.doFilter(servletRequest, servletResponse, filterChain); }
/** * Wheter the first pattern is more specific than the second one. * Exact patterns are more specific than complex patterns and * complex patterns are more specific than default patterns. * @param exclusionPattern pattern which must be more or equally specific to return <code>true</code> * @param decoratorPattern pattern which must be less specific to return <code>true</code> * @return <code>true</code> if the first pattern is more specific than the second one */ public static boolean isMoreSpecific(String exclusionPattern, String decoratorPattern) { if(isDefaultKey(decoratorPattern)) { return true; } if(isComplexKey(decoratorPattern)){ if(isComplexKey(exclusionPattern)) { return exclusionPattern.length() >= decoratorPattern.length(); } return !isDefaultKey(decoratorPattern); } return !isComplexKey(exclusionPattern) && !isDefaultKey(exclusionPattern); } }
public String[] selectDecoratorPaths(Content content, C siteMeshContext) throws IOException { String[] result = pathMapper.get(siteMeshContext.getPath()); return result == null ? EMPTY : result; }
@Override public String excludePatternInUse(HttpServletRequest request) { return excludesMapper.getPatternInUse(WebAppContext.getRequestPath(request)); }
/** Retrieve appropriate pattern by matching patterns with supplied path. */ public String getPatternInUse(String path) { if (path == null) path = "/"; String result = findExactKey(path); if (result == null) result = findComplexKey(path); if (result == null) result = findDefaultKey(); return result; }
private String findComplexKey(String path) { String result = null; for (String key : mappings.keySet()) { if (isComplexKey(key) && match(key, path, false)) { if (result == null || key.length() > result.length()) { // longest key wins result = key; } } } return result; }
public BasicSelector(boolean includeErrorPages, String... mimeTypesToBuffer) { this(new PathMapper<Boolean>(), includeErrorPages, mimeTypesToBuffer); }
/** Retrieve appropriate key by matching patterns with supplied path. */ public T get(String path) { if (path == null) path = "/"; String result = findExactKey(path); if (result == null) result = findComplexKey(path); if (result == null) result = findDefaultKey(); String mapped = result; if (mapped == null) return null; return mappings.get(mapped); }
public BasicSelector(boolean includeErrorPages, String... mimeTypesToBuffer) { this(new PathMapper<Boolean>(), includeErrorPages, mimeTypesToBuffer); }
/** Retrieve appropriate key by matching patterns with supplied path. */ public T get(String path) { if (path == null) path = "/"; String result = findExactKey(path); if (result == null) result = findComplexKey(path); if (result == null) result = findDefaultKey(); String mapped = result; if (mapped == null) return null; return mappings.get(mapped); }
public BasicSelector(String... mimeTypesToBuffer) { this(new PathMapper<Boolean>(), false, mimeTypesToBuffer); }
private PathMapper<Boolean> excludesMapper = new PathMapper<Boolean>(); private Selector customSelector; private boolean includeErrorPages;
private PathMapper<Boolean> excludesMapper = new PathMapper<Boolean>(); private Selector customSelector; private boolean includeErrorPages;