From: <bra...@us...> - 2007-07-16 23:39:54
|
Revision: 1797 http://archive-access.svn.sourceforge.net/archive-access/?rev=1797&view=rev Author: bradtofel Date: 2007-07-16 16:39:55 -0700 (Mon, 16 Jul 2007) Log Message: ----------- TWEAK: now aware of CaptureSearchResults + URLSearchResults TWEAK: type-safety FEATURE: added a couple jsp-friendly methods for converting data types, and constructing various types of query and replay URLs. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIQueryResults.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIQueryResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIQueryResults.java 2007-07-16 23:35:59 UTC (rev 1796) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIQueryResults.java 2007-07-16 23:39:55 UTC (rev 1797) @@ -30,12 +30,15 @@ import javax.servlet.http.HttpServletRequest; +import org.apache.commons.httpclient.URIException; import org.archive.wayback.WaybackConstants; import org.archive.wayback.ResultURIConverter; +import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.SearchResult; import org.archive.wayback.core.SearchResults; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.UIResults; +import org.archive.wayback.core.UrlSearchResults; import org.archive.wayback.core.WaybackRequest; /** @@ -72,7 +75,6 @@ private int curPage; private SearchResults results; - private HttpServletRequest httpRequest; private ResultURIConverter uriConverter; /** @@ -116,10 +118,25 @@ this.results = results; this.uriConverter = uriConverter; - this.httpRequest = httpRequest; } /** + * @return true if the underlying SearchResult objects contain Capture level + * data + */ + public boolean isCaptureResults() { + return (results instanceof CaptureSearchResults); + } + + /** + * @return true if the underlying SearchResult objects contain Url level + * data + */ + public boolean isUrlResults() { + return (results instanceof UrlSearchResults); + } + + /** * @return Timestamp end cutoff requested by user */ public Timestamp getEndTimestamp() { @@ -157,7 +174,7 @@ /** * @return Iterator of ResourceResults */ - public Iterator resultsIterator() { + public Iterator<SearchResult> resultsIterator() { return results.iterator(); } @@ -166,7 +183,9 @@ * @return URL string that will replay the specified Resource Result. */ public String resultToReplayUrl(SearchResult result) { - return uriConverter.makeReplayURI(result); + String url = result.getAbsoluteUrl(); + String captureDate = result.getCaptureDate(); + return uriConverter.makeReplayURI(captureDate,url); } /** @@ -177,6 +196,42 @@ } /** + * @param url + * @param timestamp + * @return String url that will replay the url at timestamp + */ + public String makeReplayUrl(String url, String timestamp) { + return uriConverter.makeReplayURI(timestamp, url); + } + + /** + * @param url + * @return String url that will make a query for all captures of an URL. + */ + public String makeCaptureQueryUrl(String url) { + WaybackRequest newWBR = wbRequest.clone(); + + newWBR.put(WaybackConstants.REQUEST_TYPE, + WaybackConstants.REQUEST_URL_QUERY); + try { + newWBR.setRequestUrl(url); + } catch (URIException e) { + // should not happen... + e.printStackTrace(); + } + return newWBR.getContextPrefix() + "query?" + + newWBR.getQueryArguments(1); + } + + /** + * @param timestamp + * @return Date for the timestamp string + */ + public Date timestampToDate(String timestamp) { + return new Timestamp(timestamp).getDate(); + } + + /** * @param result * @return Date representing captureDate of SearchResult result */ @@ -234,8 +289,7 @@ * different page of results for the same query */ public String urlForPage(int pageNum) { - //http://localhost:8080/wayback/query?q=url:peagreenboat.com%20type:urlprefixquery&count=20&start_page=4 - return httpRequest.getContextPath() + "/query?" + + return wbRequest.getContextPrefix() + "query?" + wbRequest.getQueryArguments(pageNum); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |