| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
package net.sourceforge.pebble.web.filter; |
| 33 |
|
|
| 34 |
|
import org.apache.commons.logging.Log; |
| 35 |
|
import org.apache.commons.logging.LogFactory; |
| 36 |
|
|
| 37 |
|
import javax.servlet.*; |
| 38 |
|
import javax.servlet.jsp.jstl.core.Config; |
| 39 |
|
import javax.servlet.http.HttpServletRequest; |
| 40 |
|
import java.io.IOException; |
| 41 |
|
import java.net.URLDecoder; |
| 42 |
|
import java.util.List; |
| 43 |
|
import java.util.Collections; |
| 44 |
|
import java.util.Locale; |
| 45 |
|
|
| 46 |
|
import net.sourceforge.pebble.PebbleContext; |
| 47 |
|
import net.sourceforge.pebble.Constants; |
| 48 |
|
import net.sourceforge.pebble.comparator.BlogEntryComparator; |
| 49 |
|
import net.sourceforge.pebble.decorator.ContentDecoratorChain; |
| 50 |
|
import net.sourceforge.pebble.api.decorator.ContentDecoratorContext; |
| 51 |
|
import net.sourceforge.pebble.domain.*; |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
@author |
| 57 |
|
|
|
|
|
| 84,9% |
Uncovered Elements: 8 (53) |
Complexity: 12 |
Complexity Density: 0,33 |
|
| 58 |
|
public class BlogLookupFilter implements Filter { |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
private static Log log = LogFactory.getLog(BlogLookupFilter.class); |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
private FilterConfig filterConfig; |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
@param |
| 70 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 71 |
4
|
public void init(FilterConfig config) {... |
| 72 |
4
|
this.filterConfig = config; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 78 |
4
|
public void destroy() {... |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
|
|
|
| 83,7% |
Uncovered Elements: 8 (49) |
Complexity: 10 |
Complexity Density: 0,29 |
|
| 84 |
14
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)... |
| 85 |
|
throws ServletException, IOException { |
| 86 |
|
|
| 87 |
14
|
HttpServletRequest httpRequest = (HttpServletRequest)request; |
| 88 |
14
|
PebbleContext pebbleContext = PebbleContext.getInstance(); |
| 89 |
14
|
AbstractBlog blog; |
| 90 |
|
|
| 91 |
14
|
String url = pebbleContext.getConfiguration().getUrl(); |
| 92 |
14
|
if (pebbleContext != null && (url == null || url.length() == 0)) { |
| 93 |
0
|
String scheme = httpRequest.getScheme(); |
| 94 |
0
|
url = scheme + "://" + httpRequest.getServerName() + ":" + httpRequest.getServerPort() + httpRequest.getContextPath(); |
| 95 |
0
|
log.info("Setting Pebble URL to " + url); |
| 96 |
0
|
PebbleContext.getInstance().getConfiguration().setUrl(url); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
14
|
String uri = httpRequest.getRequestURI(); |
| 101 |
14
|
uri = uri.substring(httpRequest.getContextPath().length(), uri.length()); |
| 102 |
|
|
| 103 |
|
|
| 104 |
14
|
if (BlogManager.getInstance().isMultiBlog()) { |
| 105 |
8
|
if (uri.length() == 0) { |
| 106 |
2
|
uri = "/"; |
| 107 |
|
} |
| 108 |
8
|
int index = uri.indexOf("/", 1); |
| 109 |
8
|
if (index == -1) { |
| 110 |
6
|
index = uri.length(); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
8
|
String blogName = null; |
| 114 |
8
|
if (pebbleContext.getConfiguration().isVirtualHostingEnabled()) { |
| 115 |
0
|
String serverName = httpRequest.getServerName(); |
| 116 |
0
|
blogName = serverName.substring(0, serverName.indexOf(".")); |
| 117 |
|
} else { |
| 118 |
8
|
blogName = uri.substring(1, index); |
| 119 |
|
} |
| 120 |
|
|
| 121 |
8
|
blogName = URLDecoder.decode(blogName, "UTF-8"); |
| 122 |
8
|
if (BlogManager.getInstance().hasBlog(blogName)) { |
| 123 |
4
|
blog = BlogManager.getInstance().getBlog(blogName); |
| 124 |
4
|
uri = uri.substring(index, uri.length()); |
| 125 |
|
} else { |
| 126 |
4
|
blog = BlogManager.getInstance().getMultiBlog(); |
| 127 |
|
} |
| 128 |
|
} else { |
| 129 |
6
|
blog = BlogManager.getInstance().getBlog(); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
14
|
httpRequest.setAttribute(Constants.BLOG_KEY, blog); |
| 133 |
14
|
httpRequest.setAttribute(Constants.BLOG_MANAGER, BlogManager.getInstance()); |
| 134 |
14
|
httpRequest.setAttribute(Constants.PEBBLE_CONTEXT, pebbleContext); |
| 135 |
|
|
| 136 |
14
|
if (blog instanceof Blog) { |
| 137 |
10
|
httpRequest.setAttribute(Constants.BLOG_TYPE, "singleblog"); |
| 138 |
|
} else { |
| 139 |
4
|
httpRequest.setAttribute(Constants.BLOG_TYPE, "multiblog"); |
| 140 |
|
} |
| 141 |
|
|
| 142 |
14
|
chain.doFilter(request, response); |
| 143 |
|
} |
| 144 |
|
} |