private String process(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { if ((url == null) || (rule.getMatch().length() == 0) || (rule.getSubstitute().length() == 0)) { return url; } Matcher m = rule.getPattern().matcher(url); StringBuffer result = new StringBuffer(); while (m.find()) { m.appendReplacement(result, rule.getSubstitute()); } m.appendTail(result); return result.toString(); }
private String process(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; switch (rule.getToCase()) { case LOWERCASE: result = result.toLowerCase(); break; case UPPERCASE: result = result.toUpperCase(); break; default: break; } return result; }
private String process(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { if ((url == null) || (rule.getUrl().length() == 0)) { return url; } String result = url; if (rule.getMatch().length() > 0) { result = url.replaceAll(rule.getMatch(), rule.getUrl()); } else { result = rule.getUrl(); } return result; }
/** * Rewrite the given URL using the provided {@link RewriteRule} object as a set of rules. * * @return The rewritten URL, or the unchanged URL if no action was taken. */ public String processInbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; if ((rule != null) && rule.isInbound() && rule.matches(url)) { for (Processor p : processors) { result = p.processInbound(request, response, rule, result); } } return result; }
for (RewriteRule rule : getConfig().getGlobalRewriteRules()) if (rule.matches(newUrl)) if (!Redirect.CHAIN.equals(rule.getRedirect())) if (StringUtils.isBlank(rule.getUrl()) && !originalUrl.equals(newUrl)) else if (StringUtils.isNotBlank(rule.getUrl())) resp.setStatus(rule.getRedirect().getStatus()); resp.flushBuffer(); break;
/** * Rewrite the given URL using the provided {@link RewriteRule} object. Process the URL only if the rule is set to * outbound="true" * * @return The rewritten URL, or the unchanged URL if no action was taken. */ public String processOutbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; if ((rule != null) && rule.isOutbound() && rule.matches(url)) { for (Processor p : processors) { result = p.processOutbound(request, response, rule, result); } } return result; }
public String processInbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; if (rule.getProcessor().length() > 0) { try { Class<?> processorClass = Class.forName(rule.getProcessor()); Processor processor = (Processor) processorClass.newInstance(); result = processor.processInbound(request, response, rule, url); } catch (Exception e) { throw new PrettyException("Error occurred exececuting processor of type: " + rule.getProcessor() + ", for input URL <[" + url + "]>", e); } } return result; }
((HttpServletRewrite) event).getResponse(), rule, originalUrl); if (!Redirect.CHAIN.equals(rule.getRedirect())) if (StringUtils.isBlank(rule.getUrl()) && !originalUrl.equals(newUrl)) else if (StringUtils.isNotBlank(rule.getUrl())) if (Redirect.PERMANENT.equals(rule.getRedirect())) ((HttpInboundServletRewrite) event).redirectPermanent(redirectURL); if (Redirect.TEMPORARY.equals(rule.getRedirect())) ((HttpInboundServletRewrite) event).redirectTemporary(redirectURL);
/** * Return true if the <b>match</b> field contains a regex that matches some * or all of the given URL, false if no match is found. */ public boolean matches(final String url) { if (url != null) { if (getMatch().length() == 0) { return true; } else { Matcher m = pattern.matcher(url).useAnchoringBounds(outbound); while (m.find()) { return true; } } } return false; }
private String process(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; switch (rule.getTrailingSlash()) { case APPEND: if (!result.endsWith("/")) { result = result + "/"; } break; case REMOVE: if (result.endsWith("/") && !"/".equals(result)) { result = result.substring(0, result.length() - 1); } break; default: break; } return result; }
for (RewriteRule rule : getConfig().getGlobalRewriteRules()) if (rule.matches(newUrl)) if (!Redirect.CHAIN.equals(rule.getRedirect())) if (StringUtils.isBlank(rule.getUrl()) && !originalUrl.equals(newUrl)) else if (StringUtils.isNotBlank(rule.getUrl())) resp.setStatus(rule.getRedirect().getStatus()); resp.flushBuffer(); break;
/** * Rewrite the given URL using the provided {@link RewriteRule} object. Process the URL only if the rule is set to * outbound="true" * * @return The rewritten URL, or the unchanged URL if no action was taken. */ public String processOutbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; if ((rule != null) && rule.isOutbound() && rule.matches(url)) { for (Processor p : processors) { result = p.processOutbound(request, response, rule, result); } } return result; }
/** * Rewrite the given URL using the provided {@link RewriteRule} object as a set of rules. * * @return The rewritten URL, or the unchanged URL if no action was taken. */ public String processInbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; if ((rule != null) && rule.isInbound() && rule.matches(url)) { for (Processor p : processors) { result = p.processInbound(request, response, rule, result); } } return result; }
public String processOutbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; if (rule.getProcessor().length() > 0) { try { Class<?> processorClass = Class.forName(rule.getProcessor()); Processor processor = (Processor) processorClass.newInstance(); result = processor.processOutbound(request, response, rule, url); } catch (Exception e) { throw new PrettyException("Error occurred exececuting processor of type: " + rule.getProcessor() + ", for input URL <[" + url + "]>", e); } } return result; }
/** * Return true if the <b>match</b> field contains a regex that matches some * or all of the given URL, false if no match is found. */ public boolean matches(final String url) { if (url != null) { if (getMatch().length() == 0) { return true; } else { Matcher m = pattern.matcher(url).useAnchoringBounds(outbound); while (m.find()) { return true; } } } return false; }
private String process(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; switch (rule.getTrailingSlash()) { case APPEND: if (!result.endsWith("/")) { result = result + "/"; } break; case REMOVE: if (result.endsWith("/") && !"/".equals(result)) { result = result.substring(0, result.length() - 1); } break; default: break; } return result; }
private String process(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { if ((url == null) || (rule.getMatch().length() == 0) || (rule.getSubstitute().length() == 0)) { return url; } Matcher m = rule.getPattern().matcher(url); StringBuffer result = new StringBuffer(); while (m.find()) { m.appendReplacement(result, rule.getSubstitute()); } m.appendTail(result); return result.toString(); }
for (RewriteRule rule : getConfig().getGlobalRewriteRules()) if (rule.matches(newUrl)) if (!Redirect.CHAIN.equals(rule.getRedirect())) if (StringUtils.isBlank(rule.getUrl()) && !originalUrl.equals(newUrl)) else if (StringUtils.isNotBlank(rule.getUrl())) resp.setStatus(rule.getRedirect().getStatus()); resp.flushBuffer(); break;
/** * Rewrite the given URL using the provided {@link RewriteRule} object. Process the URL only if the rule is set to * outbound="true" * * @return The rewritten URL, or the unchanged URL if no action was taken. */ public String processOutbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; if ((rule != null) && rule.isOutbound() && rule.matches(url)) { for (Processor p : processors) { result = p.processOutbound(request, response, rule, result); } } return result; }
/** * Rewrite the given URL using the provided {@link RewriteRule} object as a set of rules. * * @return The rewritten URL, or the unchanged URL if no action was taken. */ public String processInbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rule, final String url) { String result = url; if ((rule != null) && rule.isInbound() && rule.matches(url)) { for (Processor p : processors) { result = p.processInbound(request, response, rule, result); } } return result; }