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