| 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.view; |
| 33 |
|
|
| 34 |
|
import java.io.File; |
| 35 |
|
import java.io.IOException; |
| 36 |
|
|
| 37 |
|
import javax.servlet.RequestDispatcher; |
| 38 |
|
import javax.servlet.ServletContext; |
| 39 |
|
import javax.servlet.ServletException; |
| 40 |
|
import javax.servlet.http.HttpServletRequest; |
| 41 |
|
import javax.servlet.http.HttpServletResponse; |
| 42 |
|
|
| 43 |
|
import net.sourceforge.pebble.Constants; |
| 44 |
|
import net.sourceforge.pebble.PebbleContext; |
| 45 |
|
import net.sourceforge.pebble.domain.AbstractBlog; |
| 46 |
|
import net.sourceforge.pebble.domain.Blog; |
| 47 |
|
import net.sourceforge.pebble.domain.StaticPage; |
| 48 |
|
import net.sourceforge.pebble.util.I18n; |
| 49 |
|
|
| 50 |
|
import org.apache.commons.logging.Log; |
| 51 |
|
import org.apache.commons.logging.LogFactory; |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
@author |
| 58 |
|
|
|
|
|
| 0% |
Uncovered Elements: 53 (53) |
Complexity: 14 |
Complexity Density: 0,38 |
|
| 59 |
|
public abstract class HtmlView extends JspView { |
| 60 |
|
|
| 61 |
|
public static final String SYSTEM_THEME = "_pebble"; |
| 62 |
|
public static final String DEFAULT_THEME = "default"; |
| 63 |
|
|
| 64 |
|
private static Log log = LogFactory.getLog(HtmlView.class); |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
@return |
| 70 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 71 |
0
|
public String getContentType() {... |
| 72 |
0
|
AbstractBlog blog = (AbstractBlog)getModel().get(Constants.BLOG_KEY); |
| 73 |
0
|
return "text/html; charset=" + blog.getCharacterEncoding(); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
@return |
| 80 |
|
|
| 81 |
|
public abstract String getTitle(); |
| 82 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 83 |
0
|
public String getLocalizedString(String key) {... |
| 84 |
0
|
return I18n.getMessage(((AbstractBlog)getModel().get(Constants.BLOG_KEY)).getLocale(), key); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
@return |
| 92 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 5 |
Complexity Density: 0,83 |
|
| 93 |
0
|
protected String getTheme() {... |
| 94 |
0
|
AbstractBlog blog = (AbstractBlog)getModel().get(Constants.BLOG_KEY); |
| 95 |
0
|
String theme = blog.getTheme(); |
| 96 |
|
|
| 97 |
0
|
if (!PebbleContext.getInstance().getConfiguration().isUserThemesEnabled()) { |
| 98 |
0
|
if (theme != null && !theme.equals(DEFAULT_THEME) && !theme.equals(SYSTEM_THEME)) { |
| 99 |
0
|
return DEFAULT_THEME; |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
|
| 103 |
0
|
return theme; |
| 104 |
|
} |
| 105 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 106 |
0
|
protected int getStatus() {... |
| 107 |
0
|
return HttpServletResponse.SC_OK; |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
@param |
| 114 |
|
@param |
| 115 |
|
@param |
| 116 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 2 |
Complexity Density: 0,12 |
|
| 117 |
0
|
public void dispatch(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException {... |
| 118 |
0
|
String theme = getTheme(); |
| 119 |
0
|
request.setAttribute(Constants.THEME, theme); |
| 120 |
0
|
request.setAttribute(Constants.TITLE_KEY, getTitle()); |
| 121 |
0
|
log.debug("Content is " + getUri()); |
| 122 |
0
|
request.setAttribute("content", getUri()); |
| 123 |
0
|
String uri = "/themes/" + theme + "/" + getTemplate() + ".jsp"; |
| 124 |
0
|
log.debug("Dispatching to " + uri); |
| 125 |
|
|
| 126 |
0
|
response.setHeader("Cache-Control","no-cache, no-store"); |
| 127 |
0
|
response.setDateHeader("Expires", 0); |
| 128 |
0
|
response.setHeader("Pragma","no-cache"); |
| 129 |
|
|
| 130 |
0
|
try { |
| 131 |
0
|
RequestDispatcher dispatcher = context.getRequestDispatcher(uri); |
| 132 |
0
|
dispatcher.forward(request, response); |
| 133 |
|
} catch (IOException ioe) { |
| 134 |
0
|
ioe.printStackTrace(); |
| 135 |
0
|
throw new ServletException(ioe); |
| 136 |
|
} finally { |
| 137 |
0
|
AbstractBlog blog = (AbstractBlog)getModel().get(Constants.BLOG_KEY); |
| 138 |
0
|
blog.log(request, getStatus()); |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0,4 |
|
| 142 |
0
|
private String getTemplate() {... |
| 143 |
0
|
if (!(getModel().get(Constants.BLOG_KEY) instanceof Blog)) { |
| 144 |
0
|
return "template"; |
| 145 |
|
} |
| 146 |
0
|
if (!getModel().contains(Constants.STATIC_PAGE_KEY)) { |
| 147 |
0
|
return "template"; |
| 148 |
|
} |
| 149 |
0
|
StaticPage staticPage = (StaticPage) getModel().get(Constants.STATIC_PAGE_KEY); |
| 150 |
0
|
Blog blog = (Blog) getModel().get(Constants.BLOG_KEY); |
| 151 |
0
|
String templateFile = blog.getThemeDirectory() + "/" + staticPage.getTemplate() + ".jsp"; |
| 152 |
0
|
if (new File(templateFile).canRead()) { |
| 153 |
0
|
return staticPage.getTemplate(); |
| 154 |
|
} |
| 155 |
0
|
return "template"; |
| 156 |
|
} |
| 157 |
|
} |