1 18 19 package org.apache.roller.ui.rendering.util; 20 21 import java.io.UnsupportedEncodingException ; 22 import java.net.URLDecoder ; 23 import javax.servlet.http.HttpServletRequest ; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.roller.RollerException; 27 import org.apache.roller.model.RollerFactory; 28 import org.apache.roller.model.WeblogManager; 29 import org.apache.roller.pojos.WeblogEntryData; 30 31 32 35 public class WeblogCommentRequest extends WeblogRequest { 36 37 private static Log log = LogFactory.getLog(WeblogCommentRequest.class); 38 39 private static final String COMMENT_SERVLET = "/roller-ui/rendering/comment"; 40 41 private String name = null; 43 private String email = null; 44 private String url = null; 45 private String content = null; 46 private boolean notify = false; 47 private String weblogAnchor = null; 48 49 private WeblogEntryData weblogEntry = null; 51 52 53 public WeblogCommentRequest() {} 54 55 56 public WeblogCommentRequest(HttpServletRequest request) 57 throws InvalidRequestException { 58 59 super(request); 62 63 String servlet = request.getServletPath(); 64 65 String pathInfo = this.getPathInfo(); 67 68 if(servlet == null || !COMMENT_SERVLET.equals(servlet)) { 70 throw new InvalidRequestException("not a weblog comment request, "+ 71 request.getRequestURL()); 72 } 73 74 75 80 if(pathInfo != null && pathInfo.trim().length() > 0) { 81 82 String [] pathElements = pathInfo.split("/"); 84 if(pathElements.length == 2) { 85 86 String context = pathElements[0]; 87 if("entry".equals(context)) { 88 try { 89 this.weblogAnchor = 90 URLDecoder.decode(pathElements[1], "UTF-8"); 91 } catch (UnsupportedEncodingException ex) { 92 log.error(ex); 94 } 95 96 } else { 97 throw new InvalidRequestException("bad path info, "+ 98 request.getRequestURL()); 99 } 100 101 } else { 102 throw new InvalidRequestException("bad path info, "+ 103 request.getRequestURL()); 104 } 105 106 } else { 107 throw new InvalidRequestException("bad path info, "+ 109 request.getRequestURL()); 110 } 111 112 113 123 if(request.getParameter("name") != null) { 124 this.name = request.getParameter("name"); 125 } 126 127 if(request.getParameter("email") != null) { 128 this.email = request.getParameter("email"); 129 } 130 131 if(request.getParameter("url") != null) { 132 this.url = request.getParameter("url"); 133 } 134 135 if(request.getParameter("content") != null) { 136 this.content = request.getParameter("content"); 137 } 138 139 if(request.getParameter("notify") != null) { 140 this.notify = Boolean.valueOf(request.getParameter("notify")).booleanValue(); 141 } 142 143 if(log.isDebugEnabled()) { 144 log.debug("name = "+this.name); 145 log.debug("email = "+this.email); 146 log.debug("url = "+this.url); 147 log.debug("content = "+this.content); 148 log.debug("notify = "+this.notify); 149 log.debug("weblogAnchor = "+this.weblogAnchor); 150 } 151 } 152 153 public String getName() { 154 return name; 155 } 156 157 public void setName(String name) { 158 this.name = name; 159 } 160 161 public String getEmail() { 162 return email; 163 } 164 165 public void setEmail(String email) { 166 this.email = email; 167 } 168 169 public String getUrl() { 170 return url; 171 } 172 173 public void setUrl(String url) { 174 this.url = url; 175 } 176 177 public String getContent() { 178 return content; 179 } 180 181 public void setContent(String content) { 182 this.content = content; 183 } 184 185 public boolean isNotify() { 186 return notify; 187 } 188 189 public void setNotify(boolean notify) { 190 this.notify = notify; 191 } 192 193 public String getWeblogAnchor() { 194 return weblogAnchor; 195 } 196 197 public void setWeblogAnchor(String weblogAnchor) { 198 this.weblogAnchor = weblogAnchor; 199 } 200 201 public WeblogEntryData getWeblogEntry() { 202 203 if(weblogEntry == null && weblogAnchor != null) { 204 try { 205 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 206 weblogEntry = wmgr.getWeblogEntryByAnchor(getWeblog(), weblogAnchor); 207 } catch (RollerException ex) { 208 log.error("Error getting weblog entry "+weblogAnchor, ex); 209 } 210 } 211 212 return weblogEntry; 213 } 214 215 public void setWeblogEntry(WeblogEntryData weblogEntry) { 216 this.weblogEntry = weblogEntry; 217 } 218 219 } 220 | Popular Tags |