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 import org.apache.roller.RollerException; 30 import org.apache.roller.pojos.WeblogTemplate; 31 import org.apache.roller.util.Utilities; 32 33 34 43 public class OldPageRequest { 44 45 private static Log mLogger = LogFactory.getLog(OldPageRequest.class); 46 47 public static final String MAIN = "main"; 49 public static final String PERMALINK = "permalink"; 50 public static final String ARCHIVE = "archive"; 51 52 private String context = null; 53 private String pageType = null; 54 private String weblogHandle = null; 55 private String weblogAnchor = null; 56 private String weblogPage = null; 57 private String weblogCategory = null; 58 private String weblogDate = null; 59 60 61 64 public OldPageRequest(HttpServletRequest request) throws Exception { 65 66 mLogger.debug("parsing url "+request.getRequestURL()); 68 69 String servlet = request.getServletPath(); 70 String pathInfo = request.getPathInfo(); 71 72 if(servlet != null) { 74 servlet = servlet.substring(1); 76 77 if("page".equals(servlet)) { 78 this.context = "weblog"; 79 } else { 80 throw new Exception ("not a weblog page request, "+request.getRequestURL()); 82 } 83 } else { 84 throw new Exception ("not a weblog page request, "+request.getRequestURL()); 85 } 86 87 88 100 if(pathInfo != null && pathInfo.trim().length() > 1) { 101 pathInfo = pathInfo.substring(1); 103 String [] pathElements = pathInfo.split("/"); 104 105 if ( pathElements.length == 1 ) { 106 107 this.weblogHandle = pathElements[0]; 109 this.weblogPage = WeblogTemplate.DEFAULT_PAGE; 110 this.pageType = MAIN; 111 112 } else if ( pathElements.length == 2 ) { 113 114 this.weblogHandle = pathElements[0]; 116 this.weblogPage = WeblogTemplate.DEFAULT_PAGE; 117 118 if(this.isValidDateString(pathElements[1])) { 119 this.weblogDate = pathElements[1]; 120 this.pageType = ARCHIVE; 121 } else { 122 this.weblogPage = pathElements[1]; 123 this.pageType = MAIN; 124 } 125 126 } else if ( pathElements.length == 3 ) { 127 128 this.weblogHandle = pathElements[0]; 130 this.weblogPage = pathElements[1]; 131 132 if(this.isValidDateString(pathElements[2])) { 133 this.weblogDate = pathElements[2]; 134 this.pageType = ARCHIVE; 135 } else { 136 this.weblogAnchor = pathElements[2]; 137 this.pageType = PERMALINK; 138 } 139 140 } else if ( pathElements.length == 4 ) { 141 142 this.weblogHandle = pathElements[0]; 144 this.weblogPage = pathElements[1]; 145 this.weblogDate = pathElements[2]; 146 this.weblogAnchor = pathElements[3]; 147 this.pageType = PERMALINK; 148 } 149 150 } else { 151 throw new Exception ("not a weblog page request, "+request.getRequestURL()); 153 } 154 155 156 164 if(request.getParameter("anchor") != null) { 165 this.weblogAnchor = request.getParameter("anchor"); 166 this.pageType = PERMALINK; 167 } 168 169 if(request.getParameter("entry") != null) { 170 this.weblogAnchor = request.getParameter("entry"); 171 this.pageType = PERMALINK; 172 } 173 174 if(request.getParameter("catname") != null) { 175 String cat = request.getParameter("catname"); 176 177 this.weblogCategory = cat; 178 this.pageType = ARCHIVE; 179 } 180 181 } 182 183 184 private boolean isValidDateString(String dateString) { 185 return (dateString != null && dateString.length() > 3 && StringUtils.isNumeric(dateString)); 186 } 187 188 public String getContext() { 189 return context; 190 } 191 192 public String getWeblogHandle() { 193 return weblogHandle; 194 } 195 196 public String getWeblogAnchor() { 197 return weblogAnchor; 198 } 199 200 public String getWeblogPage() { 201 return weblogPage; 202 } 203 204 public String getWeblogCategory() { 205 return weblogCategory; 206 } 207 208 public String getWeblogDate() { 209 return weblogDate; 210 } 211 212 public String getPageType() { 213 return pageType; 214 } 215 216 } 217 | Popular Tags |