CCM NG: ShortcutsFilter now works
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4169 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
9b181dc6ab
commit
784722ddd0
|
|
@ -31,6 +31,7 @@ import javax.servlet.FilterConfig;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.annotation.WebFilter;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
|
@ -38,10 +39,11 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class ShortcutFilter implements Filter {
|
@WebFilter(urlPatterns = {"/*"})
|
||||||
|
public class ShortcutsFilter implements Filter {
|
||||||
|
|
||||||
private final static Logger LOGGER = LogManager.getLogger(
|
private final static Logger LOGGER = LogManager.getLogger(
|
||||||
ShortcutFilter.class);
|
ShortcutsFilter.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ShortcutRepository shortcutRepository;
|
private ShortcutRepository shortcutRepository;
|
||||||
|
|
@ -77,15 +79,14 @@ public class ShortcutFilter implements Filter {
|
||||||
}
|
}
|
||||||
|
|
||||||
final Optional<Shortcut> shortcut = shortcutRepository.findByUrlKey(
|
final Optional<Shortcut> shortcut = shortcutRepository.findByUrlKey(
|
||||||
path);
|
cleanUrlKey(httpRequest, path));
|
||||||
|
|
||||||
if (shortcut.isPresent()) {
|
if (shortcut.isPresent()) {
|
||||||
LOGGER.debug("Found Shortcut for path {}: {}",
|
LOGGER.debug("Found Shortcut for path {}: {}",
|
||||||
path,
|
path,
|
||||||
shortcut.toString());
|
shortcut.toString());
|
||||||
final StringBuffer targetBuffer = new StringBuffer(shortcut
|
final StringBuffer targetBuffer = new StringBuffer(shortcut
|
||||||
.get()
|
.get().getRedirect());
|
||||||
.getRedirect());
|
|
||||||
|
|
||||||
final String queryString = httpRequest.getQueryString();
|
final String queryString = httpRequest.getQueryString();
|
||||||
if (queryString != null && !queryString.isEmpty()) {
|
if (queryString != null && !queryString.isEmpty()) {
|
||||||
|
|
@ -114,6 +115,29 @@ public class ShortcutFilter implements Filter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String cleanUrlKey(final HttpServletRequest request,
|
||||||
|
final String requestUri) {
|
||||||
|
String urlKey;
|
||||||
|
if (request.getContextPath() == null
|
||||||
|
|| request.getContextPath().isEmpty()) {
|
||||||
|
urlKey = requestUri;
|
||||||
|
} else if (requestUri.startsWith(request.getContextPath())) {
|
||||||
|
urlKey = requestUri.substring(request.getContextPath().length());
|
||||||
|
} else {
|
||||||
|
urlKey = requestUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!urlKey.startsWith("/")) {
|
||||||
|
urlKey = String.join("", "/", urlKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!urlKey.endsWith("/")) {
|
||||||
|
urlKey = String.join("", urlKey, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
return urlKey;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
//Nothing
|
//Nothing
|
||||||
Loading…
Reference in New Issue