1 18 19 package org.apache.roller.ui.rendering.util; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.roller.RollerException; 25 import org.apache.roller.model.RollerFactory; 26 import org.apache.roller.model.WeblogManager; 27 import org.apache.roller.pojos.WeblogCategoryData; 28 import org.apache.roller.util.URLUtilities; 29 30 31 39 public class WeblogFeedRequest extends WeblogRequest { 40 41 private static Log log = LogFactory.getLog(WeblogFeedRequest.class); 42 43 private static final String FEED_SERVLET = "/roller-ui/rendering/feed"; 44 45 private String type = null; 47 private String format = null; 48 private String weblogCategoryName = null; 49 private boolean excerpts = false; 50 51 private WeblogCategoryData weblogCategory = null; 53 54 55 public WeblogFeedRequest() {} 56 57 58 61 public WeblogFeedRequest(HttpServletRequest request) 62 throws InvalidRequestException { 63 64 super(request); 67 68 String servlet = request.getServletPath(); 69 70 String pathInfo = this.getPathInfo(); 72 73 log.debug("parsing path "+pathInfo); 75 76 if(servlet == null || !FEED_SERVLET.equals(servlet)) { 78 throw new InvalidRequestException("not a weblog feed request, "+ 79 request.getRequestURL()); 80 } 81 82 83 90 if(pathInfo != null && pathInfo.trim().length() > 1) { 91 92 String [] pathElements = pathInfo.split("/"); 93 if(pathElements.length == 2) { 94 this.type = pathElements[0]; 95 this.format = pathElements[1]; 96 } else { 97 throw new InvalidRequestException("invalid feed path info, "+ 98 request.getRequestURL()); 99 } 100 101 } else { 102 throw new InvalidRequestException("invalid feed path info, "+ 103 request.getRequestURL()); 104 } 105 106 107 115 if(request.getParameter("cat") != null) { 116 this.weblogCategoryName = 117 URLUtilities.decode(request.getParameter("cat")); 118 119 if(!this.weblogCategoryName.startsWith("/")) { 121 this.weblogCategoryName = "/"+this.weblogCategoryName; 122 } 123 } 124 125 if(request.getParameter("excerpts") != null) { 126 this.excerpts = Boolean.valueOf(request.getParameter("excerpts")).booleanValue(); 127 } 128 129 if(log.isDebugEnabled()) { 130 log.debug("type = "+this.type); 131 log.debug("format = "+this.format); 132 log.debug("weblogCategory = "+this.weblogCategoryName); 133 log.debug("excerpts = "+this.excerpts); 134 } 135 } 136 137 public String getType() { 138 return type; 139 } 140 141 public void setType(String type) { 142 this.type = type; 143 } 144 145 public String getFormat() { 146 return format; 147 } 148 149 public void setFormat(String format) { 150 this.format = format; 151 } 152 153 public String getWeblogCategoryName() { 154 return weblogCategoryName; 155 } 156 157 public void setWeblogCategoryName(String weblogCategory) { 158 this.weblogCategoryName = weblogCategory; 159 } 160 161 public boolean isExcerpts() { 162 return excerpts; 163 } 164 165 public void setExcerpts(boolean excerpts) { 166 this.excerpts = excerpts; 167 } 168 169 public WeblogCategoryData getWeblogCategory() { 170 171 if(weblogCategory == null && weblogCategoryName != null) { 172 try { 173 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 174 weblogCategory = wmgr.getWeblogCategoryByPath(getWeblog(), weblogCategoryName); 175 } catch (RollerException ex) { 176 log.error("Error getting weblog category "+weblogCategoryName, ex); 177 } 178 } 179 180 return weblogCategory; 181 } 182 183 public void setWeblogCategory(WeblogCategoryData weblogCategory) { 184 this.weblogCategory = weblogCategory; 185 } 186 187 } 188 | Popular Tags |