| 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 net.sourceforge.pebble.Configuration; |
| 35 |
|
import net.sourceforge.pebble.Constants; |
| 36 |
|
import net.sourceforge.pebble.PebbleContext; |
| 37 |
|
import net.sourceforge.pebble.security.PebbleUserDetails; |
| 38 |
|
import net.sourceforge.pebble.util.HttpsURLRewriter; |
| 39 |
|
import net.sourceforge.pebble.util.SecurityUtils; |
| 40 |
|
import net.sourceforge.pebble.util.CookieUtils; |
| 41 |
|
import net.sourceforge.pebble.util.UrlRewriter; |
| 42 |
|
import net.sourceforge.pebble.util.Utilities; |
| 43 |
|
import net.sourceforge.pebble.api.decorator.ContentDecoratorContext; |
| 44 |
|
import net.sourceforge.pebble.comparator.BlogEntryComparator; |
| 45 |
|
import net.sourceforge.pebble.comparator.BlogByLastModifiedDateComparator; |
| 46 |
|
import net.sourceforge.pebble.decorator.ContentDecoratorChain; |
| 47 |
|
import net.sourceforge.pebble.domain.*; |
| 48 |
|
import org.apache.commons.logging.Log; |
| 49 |
|
import org.apache.commons.logging.LogFactory; |
| 50 |
|
|
| 51 |
|
import javax.servlet.*; |
| 52 |
|
import javax.servlet.http.HttpServletRequest; |
| 53 |
|
import javax.servlet.http.Cookie; |
| 54 |
|
import javax.servlet.http.HttpServletResponse; |
| 55 |
|
import javax.servlet.jsp.jstl.core.Config; |
| 56 |
|
import java.io.IOException; |
| 57 |
|
import java.net.URLDecoder; |
| 58 |
|
import java.util.Collections; |
| 59 |
|
import java.util.List; |
| 60 |
|
import java.util.Locale; |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
@author |
| 66 |
|
|
|
|
|
| 0% |
Uncovered Elements: 65 (65) |
Complexity: 18 |
Complexity Density: 0,39 |
|
| 67 |
|
public class PreProcessingFilter implements Filter { |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
private static Log log = LogFactory.getLog(PreProcessingFilter.class); |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
private FilterConfig filterConfig; |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
@param |
| 79 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 80 |
0
|
public void init(FilterConfig config) {... |
| 81 |
0
|
this.filterConfig = config; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 87 |
0
|
public void destroy() {... |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
|
|
|
| 0% |
Uncovered Elements: 61 (61) |
Complexity: 16 |
Complexity Density: 0,36 |
|
| 93 |
0
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)... |
| 94 |
|
throws ServletException, IOException { |
| 95 |
|
|
| 96 |
0
|
HttpServletRequest httpRequest = (HttpServletRequest)request; |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
0
|
String externalUri = (String)request.getAttribute(Constants.EXTERNAL_URI); |
| 110 |
0
|
if (externalUri.startsWith("/common/") || |
| 111 |
|
externalUri.startsWith("/dwr/") || |
| 112 |
|
externalUri.startsWith("/FCKeditor/") || |
| 113 |
|
externalUri.startsWith("/scripts/") || |
| 114 |
|
externalUri.startsWith("/themes/") || |
| 115 |
|
externalUri.equals("/pebble.css") || |
| 116 |
|
externalUri.equals("/jckconfig_pebble.js") || |
| 117 |
|
externalUri.equals("/favicon.ico") |
| 118 |
|
) { |
| 119 |
|
|
| 120 |
|
} else { |
| 121 |
0
|
AbstractBlog blog = (AbstractBlog)request.getAttribute(Constants.BLOG_KEY); |
| 122 |
0
|
if (blog instanceof Blog) { |
| 123 |
0
|
Blog b = (Blog)blog; |
| 124 |
0
|
ContentDecoratorContext context = new ContentDecoratorContext(); |
| 125 |
0
|
context.setView(ContentDecoratorContext.SUMMARY_VIEW); |
| 126 |
0
|
context.setMedia(ContentDecoratorContext.HTML_PAGE); |
| 127 |
|
|
| 128 |
0
|
List blogEntries = b.getRecentPublishedBlogEntries(); |
| 129 |
0
|
ContentDecoratorChain.decorate(context, blogEntries); |
| 130 |
0
|
Collections.sort(blogEntries, new BlogEntryComparator()); |
| 131 |
0
|
httpRequest.setAttribute(Constants.RECENT_BLOG_ENTRIES, blogEntries); |
| 132 |
|
|
| 133 |
0
|
List<Response> recentApprovedResponses = b.getRecentApprovedResponses(); |
| 134 |
0
|
for (Response r : recentApprovedResponses) { |
| 135 |
0
|
if (r instanceof Comment) { |
| 136 |
0
|
b.getContentDecoratorChain().decorate(context, (Comment)r); |
| 137 |
0
|
} else if (r instanceof TrackBack){ |
| 138 |
0
|
b.getContentDecoratorChain().decorate(context, (TrackBack)r); |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
0
|
httpRequest.setAttribute(Constants.RECENT_RESPONSES, recentApprovedResponses); |
| 142 |
|
|
| 143 |
0
|
httpRequest.setAttribute(Constants.CATEGORIES, b.getCategories()); |
| 144 |
0
|
httpRequest.setAttribute(Constants.TAGS, b.getTags()); |
| 145 |
0
|
httpRequest.setAttribute(Constants.PLUGIN_PROPERTIES, b.getPluginProperties()); |
| 146 |
0
|
httpRequest.setAttribute(Constants.ARCHIVES, b.getArchives()); |
| 147 |
0
|
httpRequest.setAttribute(Constants.BLOG_TYPE, "singleblog"); |
| 148 |
|
} else { |
| 149 |
0
|
httpRequest.setAttribute(Constants.BLOG_TYPE, "multiblog"); |
| 150 |
|
} |
| 151 |
|
|
| 152 |
0
|
if (PebbleContext.getInstance().getConfiguration().isMultiBlog()) { |
| 153 |
0
|
httpRequest.setAttribute(Constants.MULTI_BLOG_KEY, BlogManager.getInstance().getMultiBlog()); |
| 154 |
0
|
httpRequest.setAttribute(Constants.MULTI_BLOG_URL, Utilities.calcBaseUrl(request.getScheme(), BlogManager.getInstance().getMultiBlog().getUrl())); |
| 155 |
|
|
| 156 |
0
|
List blogs = BlogManager.getInstance().getPublicBlogs(); |
| 157 |
0
|
Collections.sort(blogs, new BlogByLastModifiedDateComparator()); |
| 158 |
0
|
httpRequest.setAttribute(Constants.BLOGS, blogs); |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
0
|
if (request.getCharacterEncoding() == null) { |
| 165 |
0
|
request.setCharacterEncoding(blog.getCharacterEncoding()); |
| 166 |
|
} |
| 167 |
|
|
| 168 |
0
|
PebbleUserDetails user = SecurityUtils.getUserDetails(); |
| 169 |
0
|
if (user != null) { |
| 170 |
0
|
httpRequest.setAttribute(Constants.AUTHENTICATED_USER, user); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
0
|
Config.set(request, Config.FMT_LOCALE, blog.getLocale()); |
| 174 |
0
|
Config.set(request, Config.FMT_FALLBACK_LOCALE, Locale.ENGLISH); |
| 175 |
|
} |
| 176 |
|
|
| 177 |
0
|
try { |
| 178 |
0
|
Configuration configuration = PebbleContext.getInstance().getConfiguration(); |
| 179 |
0
|
if(configuration.getSecureUrl().startsWith("https")) { |
| 180 |
0
|
UrlRewriter.useThisRewriter(new HttpsURLRewriter(request.getScheme())); |
| 181 |
|
} |
| 182 |
|
|
| 183 |
0
|
chain.doFilter(request, response); |
| 184 |
|
} finally { |
| 185 |
0
|
UrlRewriter.clear(); |
| 186 |
|
} |
| 187 |
|
} |
| 188 |
|
} |