* @see org.archive.wayback.RequestParser#parse(javax.servlet.http.HttpServletRequest, org.archive.wayback.webapp.WaybackContext)
*/
public WaybackRequest parse(HttpServletRequest httpRequest,
AccessPoint wbContext) throws BadQueryException {
WaybackRequest wbRequest = null;
String server = httpRequest.getServerName() +
":" + httpRequest.getServerPort();
if(server.toLowerCase().endsWith(hostPort.toLowerCase())) {
int length = server.length() - hostPort.length();
if(server.length() > hostPort.length()) {
String prefix = server.substring(0,length - 1);
Matcher replayMatcher = REPLAY_REGEX.matcher(prefix);
if (replayMatcher != null && replayMatcher.matches()) {
wbRequest = new WaybackRequest();
String dateStr = replayMatcher.group(1);
String host = replayMatcher.group(2);
String requestUrl = getRequestString(host,httpRequest);
wbRequest.setReplayRequest();
wbRequest.setReplayTimestamp(dateStr);
wbRequest.setRequestUrl(requestUrl);
} else {
Matcher queryMatcher = QUERY_REGEX.matcher(prefix);
if(queryMatcher != null && queryMatcher.matches()) {
wbRequest = new WaybackRequest();
String dateStr = queryMatcher.group(1);
String host = queryMatcher.group(2);
String requestUrl = getRequestString(host,httpRequest);
String startDate;
String endDate;
if(dateStr.length() == 0) {
startDate = getEarliestTimestamp();
endDate = getLatestTimestamp();
} else {
startDate = Timestamp.parseBefore(dateStr).getDateStr();
endDate = Timestamp.parseAfter(dateStr).getDateStr();
}
wbRequest.setCaptureQueryRequest();
wbRequest.setStartTimestamp(startDate);
wbRequest.setEndTimestamp(endDate);
wbRequest.setRequestUrl(requestUrl);
}
// TODO: what if it doesn't match the QUERY_REGEX?
// throw a BadQueryException?
}
}