*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws ServletException, IOException {
HttpServletRequest httpRequest = (HttpServletRequest)request;
PebbleContext pebbleContext = PebbleContext.getInstance();
AbstractBlog blog;
String url = pebbleContext.getConfiguration().getUrl();
if (pebbleContext != null && (url == null || url.length() == 0)) {
String scheme = httpRequest.getScheme();
url = scheme + "://" + httpRequest.getServerName() + ":" + httpRequest.getServerPort() + httpRequest.getContextPath();
log.info("Setting Pebble URL to " + url);
PebbleContext.getInstance().getConfiguration().setUrl(url);
}
// get URI and strip off the context (e.g. /blog)
String uri = httpRequest.getRequestURI();
uri = uri.substring(httpRequest.getContextPath().length(), uri.length());
// now we're left with a URI
if (BlogManager.getInstance().isMultiBlog()) {
if (uri.length() == 0) {
uri = "/";
}
int index = uri.indexOf("/", 1);
if (index == -1) {
index = uri.length();
}
String blogName = null;
Configuration config = pebbleContext.getConfiguration();
if (config.isVirtualHostingEnabled()) {
String serverName = httpRequest.getServerName();
if (config.isVirtualHostingSubdomain()) {
int index2 = serverName.indexOf(".");
if (index2 < 0) index2 = serverName.length();