1 18 19 package org.apache.roller.ui.rendering.velocity.deprecated; 20 21 import java.util.Enumeration ; 22 import java.util.HashSet ; 23 import java.util.Locale ; 24 import java.util.Set ; 25 import javax.servlet.http.HttpServletRequest ; 26 import org.apache.commons.lang.StringUtils; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 31 40 public class OldCommentsRequest { 41 42 private static Log log = LogFactory.getLog(OldCommentsRequest.class); 43 44 public static final String MAIN = "main"; 46 public static final String PERMALINK = "permalink"; 47 public static final String ARCHIVE = "archive"; 48 49 private String context = null; 50 private String pageType = null; 51 private String weblogHandle = null; 52 private String weblogAnchor = null; 53 private String weblogPage = null; 54 private String weblogCategory = null; 55 private String weblogDate = null; 56 57 58 61 public OldCommentsRequest(HttpServletRequest request) throws Exception { 62 63 log.debug("parsing url "+request.getRequestURL()); 65 66 String servlet = request.getServletPath(); 67 String pathInfo = request.getPathInfo(); 68 69 if(servlet != null) { 71 servlet = servlet.substring(1); 73 74 if("comments".equals(servlet)) { 75 this.context = "weblog"; 76 } else { 77 throw new Exception ("not a weblog page request, "+request.getRequestURL()); 79 } 80 } else { 81 throw new Exception ("not a weblog page request, "+request.getRequestURL()); 82 } 83 84 85 97 if(pathInfo != null && pathInfo.trim().length() > 1) { 98 pathInfo = pathInfo.substring(1); 100 String [] pathElements = pathInfo.split("/"); 101 102 if ( pathElements.length == 1 ) { 103 104 this.weblogHandle = pathElements[0]; 106 this.weblogPage = "Weblog"; 107 this.pageType = MAIN; 108 109 } else if ( pathElements.length == 2 ) { 110 111 this.weblogHandle = pathElements[0]; 113 this.weblogPage = "Weblog"; 114 115 if(this.isValidDateString(pathElements[1])) { 116 this.weblogDate = pathElements[1]; 117 this.pageType = ARCHIVE; 118 } else { 119 this.weblogPage = pathElements[1]; 120 this.pageType = MAIN; 121 } 122 123 } else if ( pathElements.length == 3 ) { 124 125 this.weblogHandle = pathElements[0]; 127 this.weblogPage = pathElements[1]; 128 129 if(this.isValidDateString(pathElements[2])) { 130 this.weblogDate = pathElements[2]; 131 this.pageType = ARCHIVE; 132 } else { 133 this.weblogAnchor = pathElements[2]; 134 this.pageType = PERMALINK; 135 } 136 137 } else if ( pathElements.length == 4 ) { 138 139 this.weblogHandle = pathElements[0]; 141 this.weblogPage = pathElements[1]; 142 this.weblogDate = pathElements[2]; 143 this.weblogAnchor = pathElements[3]; 144 this.pageType = PERMALINK; 145 } 146 147 } else { 148 throw new Exception ("not a weblog page request, "+request.getRequestURL()); 150 } 151 152 153 161 if(request.getParameter("anchor") != null) { 162 this.weblogAnchor = request.getParameter("anchor"); 163 this.pageType = PERMALINK; 164 } 165 166 if(request.getParameter("entry") != null) { 167 this.weblogAnchor = request.getParameter("entry"); 168 this.pageType = PERMALINK; 169 } 170 171 if(request.getParameter("catname") != null) { 172 String cat = request.getParameter("catname"); 173 174 this.weblogCategory = cat; 175 this.pageType = ARCHIVE; 176 } 177 178 if(this.weblogAnchor == null) { 180 throw new Exception ("invalid comments request, no anchor"); 181 } 182 } 183 184 185 private boolean isValidDateString(String dateString) { 186 return (dateString != null && dateString.length() > 3 && StringUtils.isNumeric(dateString)); 187 } 188 189 public String getContext() { 190 return context; 191 } 192 193 public String getWeblogHandle() { 194 return weblogHandle; 195 } 196 197 public String getWeblogAnchor() { 198 return weblogAnchor; 199 } 200 201 public String getWeblogPage() { 202 return weblogPage; 203 } 204 205 public String getWeblogCategory() { 206 return weblogCategory; 207 } 208 209 public String getWeblogDate() { 210 return weblogDate; 211 } 212 213 public String getPageType() { 214 return pageType; 215 } 216 217 } 218 | Popular Tags |