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 WeblogTrackbackRequest extends WeblogRequest { 36 37 private static Log log = LogFactory.getLog(WeblogTrackbackRequest.class); 38 39 private static final String TRACKBACK_SERVLET = "/roller-ui/rendering/trackback"; 40 41 private String blogName = null; 43 private String url = null; 44 private String excerpt = null; 45 private String title = null; 46 private String weblogAnchor = null; 47 48 private WeblogEntryData weblogEntry = null; 50 51 52 public WeblogTrackbackRequest() {} 53 54 55 public WeblogTrackbackRequest(HttpServletRequest request) 56 throws InvalidRequestException { 57 58 super(request); 61 62 String servlet = request.getServletPath(); 63 64 String pathInfo = this.getPathInfo(); 66 67 if(servlet == null || !TRACKBACK_SERVLET.equals(servlet)) { 69 throw new InvalidRequestException("not a weblog trackback request, "+ 70 request.getRequestURL()); 71 } 72 73 74 79 if(pathInfo != null && pathInfo.trim().length() > 0) { 80 81 String [] pathElements = pathInfo.split("/"); 83 if(pathElements.length == 2) { 84 85 String context = pathElements[0]; 86 if("entry".equals(context)) { 87 try { 88 this.weblogAnchor = 89 URLDecoder.decode(pathElements[1], "UTF-8"); 90 } catch (UnsupportedEncodingException ex) { 91 log.error(ex); 93 } 94 95 } else { 96 throw new InvalidRequestException("bad path info, "+ 97 request.getRequestURL()); 98 } 99 100 } else { 101 throw new InvalidRequestException("bad path info, "+ 102 request.getRequestURL()); 103 } 104 105 } else { 106 throw new InvalidRequestException("bad path info, "+ 108 request.getRequestURL()); 109 } 110 111 112 121 if(request.getParameter("blog_name") != null) { 122 this.blogName = request.getParameter("blog_name"); 123 } 124 125 if(request.getParameter("url") != null) { 126 this.url = request.getParameter("url"); 127 } 128 129 if(request.getParameter("excerpt") != null) { 130 this.excerpt = request.getParameter("excerpt"); 131 } 132 133 if(request.getParameter("title") != null) { 134 this.title = request.getParameter("title"); 135 } 136 137 if(this.blogName == null || this.url == null || 140 this.excerpt == null || this.title == null) { 141 throw new InvalidRequestException("bad request data. did not "+ 142 "receive values for all trackback params (blog_name, url, excerpt, title)"); 143 } 144 145 if(log.isDebugEnabled()) { 146 log.debug("name = "+this.blogName); 147 log.debug("url = "+this.url); 148 log.debug("excerpt = "+this.excerpt); 149 log.debug("title = "+this.title); 150 log.debug("weblogAnchor = "+this.weblogAnchor); 151 } 152 } 153 154 public String getBlogName() { 155 return blogName; 156 } 157 158 public void setBlogName(String blogName) { 159 this.blogName = blogName; 160 } 161 162 public String getUrl() { 163 return url; 164 } 165 166 public void setUrl(String url) { 167 this.url = url; 168 } 169 170 public String getExcerpt() { 171 return excerpt; 172 } 173 174 public void setExcerpt(String excerpt) { 175 this.excerpt = excerpt; 176 } 177 178 public String getTitle() { 179 return title; 180 } 181 182 public void setTitle(String title) { 183 this.title = title; 184 } 185 186 public String getWeblogAnchor() { 187 return weblogAnchor; 188 } 189 190 public void setWeblogAnchor(String weblogAnchor) { 191 this.weblogAnchor = weblogAnchor; 192 } 193 194 public WeblogEntryData getWeblogEntry() { 195 196 if(weblogEntry == null && weblogAnchor != null) { 197 try { 198 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 199 weblogEntry = wmgr.getWeblogEntryByAnchor(getWeblog(), weblogAnchor); 200 } catch (RollerException ex) { 201 log.error("Error getting weblog entry "+weblogAnchor, ex); 202 } 203 } 204 205 return weblogEntry; 206 } 207 208 public void setWeblogEntry(WeblogEntryData weblogEntry) { 209 this.weblogEntry = weblogEntry; 210 } 211 212 } 213 | Popular Tags |