From: <bra...@us...> - 2008-07-01 23:54:05
|
Revision: 2379 http://archive-access.svn.sourceforge.net/archive-access/?rev=2379&view=rev Author: bradtofel Date: 2008-07-01 16:54:14 -0700 (Tue, 01 Jul 2008) Log Message: ----------- INTERMEDIATE REFACTOR: split this class out into more classes, but hopefully this will soon be followed by a removal of most of this code, as the underlying *SearchResult*, WaybackRequest and Resource objects get better accessors. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java 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/replay/UIReplayResult.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UICaptureQueryResults.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIUrlQueryResults.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java 2008-07-01 23:51:43 UTC (rev 2378) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java 2008-07-01 23:54:14 UTC (rev 2379) @@ -28,6 +28,9 @@ import javax.servlet.http.HttpServletRequest; +import org.apache.commons.httpclient.URIException; +import org.archive.wayback.ResultURIConverter; +import org.archive.wayback.WaybackConstants; import org.archive.wayback.util.StringFormatter; import org.archive.wayback.webapp.AccessPoint; @@ -39,7 +42,8 @@ */ public class UIResults { private final static String FERRET_NAME = "ui-results"; - protected WaybackRequest wbRequest; + private WaybackRequest wbRequest; + private ResultURIConverter uriConverter; private String contentJsp = null; private String originalRequestURL = null; @@ -47,9 +51,10 @@ /** * @param wbRequest Wayback Request argument */ - public UIResults(WaybackRequest wbRequest) { + public UIResults(WaybackRequest wbRequest,ResultURIConverter uriConverter) { super(); this.wbRequest = wbRequest; + this.uriConverter = uriConverter; } /** * @return Returns the wbRequest. @@ -60,6 +65,25 @@ } return wbRequest; } + + /** + * @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); + } /** * @return StringFormatter localized to user request @@ -100,7 +124,7 @@ public static UIResults getGeneric(HttpServletRequest httpRequest) { WaybackRequest wbRequest = new WaybackRequest(); wbRequest.fixup(httpRequest); - return new UIResults(wbRequest); + return new UIResults(wbRequest, null); } private static void replaceAll(StringBuffer s, final String o, final String n) { @@ -203,5 +227,35 @@ public String getOriginalRequestURL() { return originalRequestURL; } + /** + * @param result + * @return URL string that will replay the specified Resource Result. + */ + public String resultToReplayUrl(CaptureSearchResult result) { + if(uriConverter == null) { + return null; + } + String url = result.getOriginalUrl(); + String captureDate = result.getCaptureTimestamp(); + return uriConverter.makeReplayURI(captureDate,url); + } + + /** + * @return the ResultURIConverter + */ + public ResultURIConverter getURIConverter() { + return uriConverter; + } + /** + * @param url + * @param timestamp + * @return String url that will replay the url at timestamp + */ + public String makeReplayUrl(String url, String timestamp) { + if(uriConverter == null) { + return null; + } + return uriConverter.makeReplayURI(timestamp, url); + } } Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UICaptureQueryResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UICaptureQueryResults.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UICaptureQueryResults.java 2008-07-01 23:54:14 UTC (rev 2379) @@ -0,0 +1,99 @@ +/* UICaptureQueryResults + * + * $Id$ + * + * Created on 6:14:06 PM Jun 27, 2008. + * + * Copyright (C) 2008 Internet Archive. + * + * This file is part of wayback. + * + * wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.query; + +import java.util.Iterator; + +import javax.servlet.http.HttpServletRequest; + +import org.archive.wayback.ResultURIConverter; +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.CaptureSearchResults; +import org.archive.wayback.core.Timestamp; +import org.archive.wayback.core.WaybackRequest; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class UICaptureQueryResults extends UIQueryResults { + + private CaptureSearchResults results; + private Timestamp firstResultTimestamp; + + private Timestamp lastResultTimestamp; + + /** + * Constructor -- chew search result summaries into format easier for JSPs + * to digest. + * + * @param httpRequest + * @param wbRequest + * @param results + * @param uriConverter + */ + public UICaptureQueryResults(HttpServletRequest httpRequest, + WaybackRequest wbRequest, CaptureSearchResults results, + ResultURIConverter uriConverter) { + super(httpRequest, wbRequest, results, uriConverter); + + this.firstResultTimestamp = Timestamp.parseBefore(results + .getFirstResultTimestamp()); + this.lastResultTimestamp = Timestamp.parseBefore(results + .getLastResultTimestamp()); + + this.results = results; + } + + /** + * @return first Timestamp in returned ResourceResults + */ + public Timestamp getFirstResultTimestamp() { + return firstResultTimestamp; + } + + /** + * @return last Timestamp in returned ResourceResults + */ + public Timestamp getLastResultTimestamp() { + return lastResultTimestamp; + } + + /** + * @return Iterator of CaptureSearchResult + */ + public Iterator<CaptureSearchResult> resultsIterator() { + return results.iterator(); + } + + /** + * @return Returns the results. + */ + public CaptureSearchResults getResults() { + return results; + } +} 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 2008-07-01 23:51:43 UTC (rev 2378) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIQueryResults.java 2008-07-01 23:54:14 UTC (rev 2379) @@ -25,19 +25,15 @@ package org.archive.wayback.query; import java.util.Date; -import java.util.Iterator; 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.CaptureSearchResult; 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; /** @@ -58,24 +54,18 @@ private Timestamp endTimestamp; - private Timestamp firstResultTimestamp; - - private Timestamp lastResultTimestamp; - private Timestamp exactRequestedTimestamp; - private int resultsReturned; - private int resultsMatching; - private int resultsPerPage; - private int firstResult; - private int lastResult; + private long resultsReturned; + private long resultsMatching; + private long resultsPerPage; + private long firstResult; + private long lastResult; private int numPages; private int curPage; - private SearchResults results; - private SearchResult result; - private ResultURIConverter uriConverter; + private CaptureSearchResult result; /** * Constructor -- chew search result summaries into format easier for JSPs @@ -89,26 +79,17 @@ public UIQueryResults(HttpServletRequest httpRequest, WaybackRequest wbRequest, SearchResults results, ResultURIConverter uriConverter) { - super(wbRequest); - this.searchUrl = wbRequest.get(WaybackConstants.RESULT_URL); + super(wbRequest,uriConverter); + this.searchUrl = wbRequest.get(WaybackConstants.REQUEST_URL); this.startTimestamp = Timestamp.parseBefore(results. getFilter(WaybackConstants.REQUEST_START_DATE)); this.endTimestamp = Timestamp.parseAfter(results.getFilter( WaybackConstants.REQUEST_END_DATE)); - this.firstResultTimestamp = Timestamp.parseBefore(results - .getFirstResultDate()); - this.lastResultTimestamp = Timestamp.parseBefore(results - .getLastResultDate()); - - this.resultsReturned = Integer.parseInt(results.getFilter( - WaybackConstants.RESULTS_NUM_RETURNED)); - this.resultsMatching = Integer.parseInt(results.getFilter( - WaybackConstants.RESULTS_NUM_RESULTS)); - this.resultsPerPage = Integer.parseInt(results.getFilter( - WaybackConstants.RESULTS_REQUESTED)); - this.firstResult = Integer.parseInt(results.getFilter( - WaybackConstants.RESULTS_FIRST_RETURNED)) + 1; + this.resultsReturned = results.getReturnedCount(); + this.resultsMatching = results.getMatchingCount(); + this.resultsPerPage = results.getNumRequested(); + this.firstResult = results.getFirstReturned() + 1; this.lastResult = ((firstResult - 1) + resultsReturned); this.exactRequestedTimestamp = Timestamp.parseAfter( wbRequest.get(WaybackConstants.REQUEST_EXACT_DATE)); @@ -116,27 +97,9 @@ numPages = (int) Math.ceil((double)resultsMatching/(double)resultsPerPage); curPage = (int) Math.floor(((double)(firstResult-1))/(double)resultsPerPage) + 1; - this.results = results; - this.uriConverter = uriConverter; } /** - * @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() { @@ -144,20 +107,6 @@ } /** - * @return first Timestamp in returned ResourceResults - */ - public Timestamp getFirstResultTimestamp() { - return firstResultTimestamp; - } - - /** - * @return last Timestamp in returned ResourceResults - */ - public Timestamp getLastResultTimestamp() { - return lastResultTimestamp; - } - - /** * @return URL or URL prefix requested by user */ public String getSearchUrl() { @@ -172,59 +121,7 @@ } /** - * @return Iterator of ResourceResults - */ - public Iterator<SearchResult> resultsIterator() { - return results.iterator(); - } - - /** - * @param result - * @return URL string that will replay the specified Resource Result. - */ - public String resultToReplayUrl(SearchResult result) { - String url = result.getAbsoluteUrl(); - String captureDate = result.getCaptureDate(); - return uriConverter.makeReplayURI(captureDate,url); - } - - /** - * @return the ResultURIConverter - */ - public ResultURIConverter getURIConverter() { - return uriConverter; - } - - /** - * @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) { @@ -235,37 +132,35 @@ * @param result * @return Date representing captureDate of SearchResult result */ - public Date resultToDate(SearchResult result) { - Timestamp t = new Timestamp(result.get( - WaybackConstants.RESULT_CAPTURE_DATE)); - return t.getDate(); + public Date resultToDate(CaptureSearchResult result) { + return result.getCaptureDate(); } /** * @return Returns the firstResult. */ - public int getFirstResult() { + public long getFirstResult() { return firstResult; } /** * @return Returns the resultsMatching. */ - public int getResultsMatching() { + public long getResultsMatching() { return resultsMatching; } /** * @return Returns the resultsPerPage. */ - public int getResultsPerPage() { + public long getResultsPerPage() { return resultsPerPage; } /** * @return Returns the resultsReturned. */ - public int getResultsReturned() { + public long getResultsReturned() { return resultsReturned; } @@ -289,6 +184,7 @@ * different page of results for the same query */ public String urlForPage(int pageNum) { + WaybackRequest wbRequest = getWbRequest(); return wbRequest.getContextPrefix() + "query?" + wbRequest.getQueryArguments(pageNum); } @@ -296,16 +192,9 @@ /** * @return Returns the lastResult. */ - public int getLastResult() { + public long getLastResult() { return lastResult; } - - /** - * @return Returns the results. - */ - public SearchResults getResults() { - return results; - } /** * @return Returns the exactRequestedTimestamp. @@ -314,11 +203,11 @@ return exactRequestedTimestamp; } - public SearchResult getResult() { + public CaptureSearchResult getResult() { return result; } - public void setResult(SearchResult result) { + public void setResult(CaptureSearchResult result) { this.result = result; } } Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIUrlQueryResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIUrlQueryResults.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIUrlQueryResults.java 2008-07-01 23:54:14 UTC (rev 2379) @@ -0,0 +1,76 @@ +/* UIUrlQueryResults + * + * $Id$ + * + * Created on 6:01:39 PM Jun 27, 2008. + * + * Copyright (C) 2008 Internet Archive. + * + * This file is part of wayback. + * + * wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.query; + +import java.util.Iterator; + +import javax.servlet.http.HttpServletRequest; + +import org.archive.wayback.ResultURIConverter; +import org.archive.wayback.core.UrlSearchResult; +import org.archive.wayback.core.UrlSearchResults; +import org.archive.wayback.core.WaybackRequest; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class UIUrlQueryResults extends UIQueryResults { + + private UrlSearchResults results; + + /** + * Constructor -- chew search result summaries into format easier for JSPs + * to digest. + * + * @param httpRequest + * @param wbRequest + * @param results + * @param uriConverter + */ + public UIUrlQueryResults(HttpServletRequest httpRequest, + WaybackRequest wbRequest, UrlSearchResults results, + ResultURIConverter uriConverter) { + super(httpRequest, wbRequest, results, uriConverter); + + this.results = results; + } + + /** + * @return Iterator of ResourceResults + */ + public Iterator<UrlSearchResult> resultsIterator() { + return results.iterator(); + } + + /** + * @return Returns the results. + */ + public UrlSearchResults getResults() { + return results; + } +} Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/UIReplayResult.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/UIReplayResult.java 2008-07-01 23:51:43 UTC (rev 2378) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/UIReplayResult.java 2008-07-01 23:54:14 UTC (rev 2379) @@ -30,8 +30,8 @@ import javax.servlet.http.HttpServletRequest; import org.archive.wayback.ResultURIConverter; -import org.archive.wayback.WaybackConstants; -import org.archive.wayback.core.SearchResult; +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.Resource; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.UIResults; @@ -45,10 +45,11 @@ */ public class UIReplayResult extends UIResults { - private HttpServletRequest httpRequest; - private SearchResult result; + private HttpServletRequest httpRequest; + private CaptureSearchResult result; + private CaptureSearchResults results; private Resource resource; - private ResultURIConverter uriConverter; + /** * Constructor -- chew search result summaries into format easier for JSPs @@ -57,20 +58,22 @@ * @param httpRequest * @param wbRequest * @param result + * @param results * @param resource * @param uriConverter * @throws IOException */ public UIReplayResult(HttpServletRequest httpRequest, - WaybackRequest wbRequest, SearchResult result, - Resource resource, ResultURIConverter uriConverter) + WaybackRequest wbRequest, CaptureSearchResult result, + CaptureSearchResults results, Resource resource, + ResultURIConverter uriConverter) throws IOException { - super(wbRequest); + super(wbRequest,uriConverter); this.httpRequest = httpRequest; this.result = result; + this.results = results; this.resource = resource; - this.uriConverter = uriConverter; } /** @@ -90,68 +93,62 @@ /** * @return Returns the result. */ - public SearchResult getResult() { + public CaptureSearchResult getResult() { return result; } /** - * @return Returns the uriConverter. - */ - public ResultURIConverter getUriConverter() { - return uriConverter; - } - - /** - * @return Returns the wbRequest. - */ - public WaybackRequest getWbRequest() { - return wbRequest; - } - - /** * @return the original URL, or at least as close as can be rebuilt from * the index info */ public String getOriginalUrl() { - return result.get(WaybackConstants.RESULT_URL); + return result.getOriginalUrl(); } /** * @return the MimeURL key from the index of the result */ public String getUrlKey() { - return result.get(WaybackConstants.RESULT_URL_KEY); + return result.getUrlKey(); } /** * @return a string offset+arc file name combo, which should uniquely * identify this document */ public String getArchiveID() { - return result.get(WaybackConstants.RESULT_OFFSET) + "/" + - result.get(WaybackConstants.RESULT_ARC_FILE); + return result.getOffset() + "/" + result.getFile(); } /** * @return the CaptureDate Timestamp of the result */ public Timestamp getCaptureTimestamp() { - return Timestamp.parseBefore( - result.get(WaybackConstants.RESULT_CAPTURE_DATE)); + return Timestamp.parseBefore(result.getCaptureTimestamp()); } /** * @return the MimeType String of the result */ public String getMimeType() { - return result.get(WaybackConstants.RESULT_MIME_TYPE); + return result.getMimeType(); } + /** * @return the Digest string of the result */ public String getDigest() { - return result.get(WaybackConstants.RESULT_MD5_DIGEST); + return result.getDigest(); } + /** * @return the HTTP Headers as Properties */ public Map<String,String> getHttpHeaders() { return resource.getHttpHeaders(); } + + public CaptureSearchResults getResults() { + return results; + } + + public void setResults(CaptureSearchResults results) { + this.results = results; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |