From: <bra...@us...> - 2010-10-01 16:20:42
|
Revision: 3265 http://archive-access.svn.sourceforge.net/archive-access/?rev=3265&view=rev Author: bradtofel Date: 2010-10-01 16:20:35 +0000 (Fri, 01 Oct 2010) Log Message: ----------- BUGFIX (unreported): previously Archival URL and Domain Prefix replay modes were actually pulling the resource from underlying storage before redirecting users to a more specific date, an incredibly wasteful operation, as the resource had to be pulled out a second time, after the redirect. Now the redirect is done before pulling the resource out... INTERFACE:Added new ReplayDispatcher component to allow specific instances to decide if users should be redirected to a more specific URL indicating the exact date. REFACTOR: Moved all closest date calculation out of CaptureSearchResults, so it is tracked as results are pulled from the ResourceIndex, rather than requiring an additional scan after all results are extracted. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ReplayDispatcher.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/SelectorReplayDispatcher.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filterfactory/QueryCaptureFilterGroup.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlReplay.xml trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/DomainPrefixReplay.xml trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/MementoReplay.xml trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ProxyReplay.xml trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/query/Memento.jsp trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/query/ORE.jsp trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/MementoValidity.jsp Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ClosestResultSelector.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DateRedirectingClosestResultSelector.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DefaultClosestResultSelector.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/ClosestResultTrackingFilter.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ReplayDispatcher.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ReplayDispatcher.java 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ReplayDispatcher.java 2010-10-01 16:20:35 UTC (rev 3265) @@ -19,9 +19,11 @@ */ package org.archive.wayback; +import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.Resource; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BetterRequestException; /** * Locate and return a ReplayRenderer appropriate for the users request @@ -45,4 +47,14 @@ */ public ReplayRenderer getRenderer(WaybackRequest wbRequest, CaptureSearchResult result, Resource resource); + + /** + * @param wbRequest the Request being handled + * @param results the CaptureSearchResults from the ResourceIndex + * @return the CaptureSearchResult to be rendered (best for the wbRequest) + * @throws BetterRequestException if the user should be directed to a + * different URL, with the exact timestamp, for example. + */ + public CaptureSearchResult getClosest(WaybackRequest wbRequest, + CaptureSearchResults results) throws BetterRequestException; } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java 2010-10-01 16:20:35 UTC (rev 3265) @@ -24,7 +24,6 @@ import java.util.Iterator; import java.util.List; -import org.archive.wayback.exception.AnchorWindowTooSmallException; import org.archive.wayback.util.Timestamp; /** @@ -39,6 +38,9 @@ */ private ArrayList<CaptureSearchResult> results = new ArrayList<CaptureSearchResult>(); + + private CaptureSearchResult closest = null; + /** * 14-digit timestamp of first capture date contained in the SearchResults */ @@ -75,71 +77,7 @@ return new Timestamp(lastResultTimestamp).getDate(); } - public void markClosest(WaybackRequest wbRequest) { - CaptureSearchResult closest = getClosest(wbRequest); - if(closest != null) { - closest.setClosest(true); - } - } /** - * @param wbRequest - * @return The closest CaptureSearchResult to the request. - */ - public CaptureSearchResult getClosest(WaybackRequest wbRequest) { - try { - return getClosest(wbRequest,false); - } catch (AnchorWindowTooSmallException e) { - // cannot happen with 2nd arg false... - e.printStackTrace(); - } - return null; - } - /** - * @param wbRequest - * @param useAnchor if true, then check Request Anchor Window and Date, - * throwing exception if no Result is within the Window. - * @return The closest CaptureSearchResult to the request. - */ - public CaptureSearchResult getClosest(WaybackRequest wbRequest, - boolean useAnchor) - throws AnchorWindowTooSmallException { - - CaptureSearchResult closest = null; - long closestDistance = 0; - CaptureSearchResult cur = null; - String anchorDate = null; - // TODO: check if HTTP request referrer is set before using? - if(useAnchor) { - anchorDate = wbRequest.getAnchorTimestamp(); - } - long maxWindow = -1; - long wantTime = wbRequest.getReplayDate().getTime(); - if(anchorDate != null) { - wantTime = Timestamp.parseBefore(anchorDate).getDate().getTime(); - maxWindow = wbRequest.getAnchorWindow() * 1000; - } - - Iterator<CaptureSearchResult> itr = results.iterator(); - while (itr.hasNext()) { - cur = itr.next(); - long curDistance = Math.abs(wantTime - - cur.getCaptureDate().getTime()); - - if ((closest == null) || (curDistance < closestDistance)) { - closest = cur; - closestDistance = curDistance; - } - } - if(useAnchor && (maxWindow > 0)) { - if(closestDistance > maxWindow) { - throw new AnchorWindowTooSmallException("Closest is " + - closestDistance + " seconds away, Window is " + - maxWindow); - } - } - return closest; - } - /** * append a result * @param result */ @@ -186,4 +124,16 @@ public int size() { return results.size(); } + /** + * @param closest the closest to set + */ + public void setClosest(CaptureSearchResult closest) { + this.closest = closest; + } + /** + * @return the closest + */ + public CaptureSearchResult getClosest() { + return closest; + } } Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ClosestResultSelector.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ClosestResultSelector.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ClosestResultSelector.java 2010-10-01 16:20:35 UTC (rev 3265) @@ -0,0 +1,49 @@ +/* + * This file is part of the Wayback archival access software + * (http://archive-access.sourceforge.net/projects/wayback/). + * + * Licensed to the Internet Archive (IA) by one or more individual + * contributors. + * + * The IA licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.archive.wayback.replay; + +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.CaptureSearchResults; +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BetterRequestException; + +/** + * New interface component on Replay to allow customized selection of the + * "best" particular search result from a set to return for a particular + * request. Also allows specific Replay instances to optionally bounce the user + * to a better URL, via a BetterRequestException. + * + * @author brad + * + */ +public interface ClosestResultSelector { + /** + * Locate and return the best matching search result from a set for a given + * request. + * @param wbRequest The WaybackRequest being handled + * @param results the CaptureSeachResults found matching the request + * @return the best CaptureSearchResult, which should be replayed to the + * user. + * @throws BetterRequestException if the user should be redirected to a + * different, better URL to make this request. + */ + public CaptureSearchResult getClosest(WaybackRequest wbRequest, + CaptureSearchResults results) throws BetterRequestException; +} Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ClosestResultSelector.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Id Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DateRedirectingClosestResultSelector.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DateRedirectingClosestResultSelector.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DateRedirectingClosestResultSelector.java 2010-10-01 16:20:35 UTC (rev 3265) @@ -0,0 +1,67 @@ +/* + * This file is part of the Wayback archival access software + * (http://archive-access.sourceforge.net/projects/wayback/). + * + * Licensed to the Internet Archive (IA) by one or more individual + * contributors. + * + * The IA licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.archive.wayback.replay; + +import org.archive.wayback.ResultURIConverter; +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.CaptureSearchResults; +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BetterRequestException; + +/** + * @author brad + * + */ +public class DateRedirectingClosestResultSelector +implements ClosestResultSelector { + + public CaptureSearchResult getClosest(WaybackRequest wbRequest, + CaptureSearchResults results) throws BetterRequestException { + + CaptureSearchResult closest = results.getClosest(); + String reqDateStr = wbRequest.getReplayTimestamp(); + String resDateStr = closest.getCaptureTimestamp(); + + boolean doRedirect = false; + + // if the request date is shorter than the result date, always redirect: + if(reqDateStr.length() < resDateStr.length()) { + doRedirect = true; + } else { + // if the result is not for the exact date requested, redirect to the + // exact date. some capture dates are not 14 digits, only compare as + // many digits as are in the result date: + if(!resDateStr.equals(reqDateStr.substring(0,resDateStr.length()))) { + doRedirect = true; + } + } + if(doRedirect) { + // redirect to the better version: + String url = closest.getOriginalUrl(); + String captureDate = closest.getCaptureTimestamp(); + ResultURIConverter uriConverter = + wbRequest.getAccessPoint().getUriConverter(); + String betterURI = uriConverter.makeReplayURI(captureDate,url); + throw new BetterRequestException(betterURI); + } + return closest; + } + +} Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DateRedirectingClosestResultSelector.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Id Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DefaultClosestResultSelector.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DefaultClosestResultSelector.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DefaultClosestResultSelector.java 2010-10-01 16:20:35 UTC (rev 3265) @@ -0,0 +1,38 @@ +/* + * This file is part of the Wayback archival access software + * (http://archive-access.sourceforge.net/projects/wayback/). + * + * Licensed to the Internet Archive (IA) by one or more individual + * contributors. + * + * The IA licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.archive.wayback.replay; + +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.CaptureSearchResults; +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BetterRequestException; + +/** + * @author brad + * + */ +public class DefaultClosestResultSelector implements ClosestResultSelector { + + public CaptureSearchResult getClosest(WaybackRequest wbRequest, + CaptureSearchResults results) throws BetterRequestException { + return results.getClosest(); + } + +} Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/DefaultClosestResultSelector.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Id Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/SelectorReplayDispatcher.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/SelectorReplayDispatcher.java 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/SelectorReplayDispatcher.java 2010-10-01 16:20:35 UTC (rev 3265) @@ -24,17 +24,22 @@ import org.archive.wayback.ReplayDispatcher; import org.archive.wayback.ReplayRenderer; import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.Resource; import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BetterRequestException; /** + * ReplayDispatcher instance which uses a configurable ClosestResultSelector + * to find the best result to show from a given set, and a list of + * ReplayRendererSelector to determine how best to replay that result to a user. * - * * @author brad * @version $Date$, $Revision$ */ public class SelectorReplayDispatcher implements ReplayDispatcher { private List<ReplayRendererSelector> selectors = null; + private ClosestResultSelector closestSelector = null; /* (non-Javadoc) * @see org.archive.wayback.ReplayDispatcher#getRenderer(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.CaptureSearchResult, org.archive.wayback.core.Resource) */ @@ -49,11 +54,34 @@ } return null; } + + public CaptureSearchResult getClosest(WaybackRequest wbRequest, + CaptureSearchResults results) throws BetterRequestException { + return closestSelector.getClosest(wbRequest, results); + } + + /** + * @return the List of ReplayRendererSelector objects configured + */ public List<ReplayRendererSelector> getSelectors() { return selectors; } + /** + * @param selectors the List of ReplayRendererSelector to use + */ public void setSelectors(List<ReplayRendererSelector> selectors) { this.selectors = selectors; } - + /** + * @param closestSelector the closestSelector to set + */ + public void setClosestSelector(ClosestResultSelector closestSelector) { + this.closestSelector = closestSelector; + } + /** + * @return the closestSelector + */ + public ClosestResultSelector getClosestSelector() { + return closestSelector; + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filterfactory/QueryCaptureFilterGroup.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filterfactory/QueryCaptureFilterGroup.java 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filterfactory/QueryCaptureFilterGroup.java 2010-10-01 16:20:35 UTC (rev 3265) @@ -27,9 +27,11 @@ import org.apache.commons.httpclient.URIException; import org.archive.wayback.UrlCanonicalizer; import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.SearchResults; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; +import org.archive.wayback.resourceindex.filters.ClosestResultTrackingFilter; import org.archive.wayback.resourceindex.filters.DateRangeFilter; import org.archive.wayback.resourceindex.filters.HostMatchFilter; import org.archive.wayback.resourceindex.filters.SchemeMatchFilter; @@ -47,6 +49,7 @@ // private ObjectFilter<CaptureSearchResult> selfRedirectFilter = null; // private ObjectFilter<CaptureSearchResult> exactHost = null; // private ObjectFilter<CaptureSearchResult> exactScheme = null; + private ClosestResultTrackingFilter closestTracker = null; private ObjectFilterChain<CaptureSearchResult> chain = null; private String requestType = null; private String keyUrl = null; @@ -81,9 +84,24 @@ } chain.addFilter(new UrlMatchFilter(keyUrl)); chain.addFilter(new SelfRedirectFilter(canonicalizer)); + + long wantMS = request.getReplayDate().getTime(); + if(request.getAccessPoint().isUseAnchorWindow()) { + // use AnchorTimestamp, if specified: + String anchorTS = request.getAnchorTimestamp(); + if(anchorTS != null) { + wantMS = + Timestamp.parseBefore(anchorTS).getDate().getTime(); + } + } + + closestTracker = new ClosestResultTrackingFilter( + request.getReplayDate().getTime()); } else if(request.isCaptureQueryRequest()) { chain.addFilter(new UrlMatchFilter(keyUrl)); + closestTracker = new ClosestResultTrackingFilter( + request.getReplayDate().getTime()); } else if(request.isUrlQueryRequest()) { chain.addFilter(new UrlPrefixMatchFilter(keyUrl)); } @@ -112,6 +130,9 @@ chain.addFilter(new SchemeMatchFilter( UrlOperations.urlToScheme(request.getRequestUrl()),this)); } + if(closestTracker != null) { + chain.addFilter(closestTracker); + } } public List<ObjectFilter<CaptureSearchResult>> getFilters() { @@ -131,6 +152,12 @@ if(!closeMatches.isEmpty()) { results.setCloseMatches(new ArrayList<String>(closeMatches.values())); } + if(closestTracker != null) { + if(results instanceof CaptureSearchResults) { + CaptureSearchResults cResults = (CaptureSearchResults) results; + cResults.setClosest(closestTracker.getClosest()); + } + } } public void addCloseMatch(String host, String closeMatch) { Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/ClosestResultTrackingFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/ClosestResultTrackingFilter.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/ClosestResultTrackingFilter.java 2010-10-01 16:20:35 UTC (rev 3265) @@ -0,0 +1,83 @@ +/* + * This file is part of the Wayback archival access software + * (http://archive-access.sourceforge.net/projects/wayback/). + * + * Licensed to the Internet Archive (IA) by one or more individual + * contributors. + * + * The IA licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.archive.wayback.resourceindex.filters; + +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.util.ObjectFilter; + +/** + * Class which observes CaptureSearchResults, keeping track of the closest + * result found to a given date. This class has an optimization which ASSUMES + * results will be seen in increasing date order, so computation can be skipped + * as soon as dates stop getting closer to the desired date. + * + * @author brad + * + */ +public class ClosestResultTrackingFilter implements ObjectFilter<CaptureSearchResult> { + + private boolean found = false; + private long wantMS = 0; + private long closestDiffMS = 0; + private CaptureSearchResult closest = null; + + /** + * @return the closest + */ + public CaptureSearchResult getClosest() { + return closest; + } + + /** + * @param wantMS the number of MS since the epoch of the desired date. + */ + public ClosestResultTrackingFilter(long wantMS) { + this.wantMS = wantMS; + } + + public int filterObject(CaptureSearchResult o) { + + if(found) { + // dates are now getting further from desired dates, as an + // optimization, skip the math: + return FILTER_INCLUDE; + } + long captureMS = o.getCaptureDate().getTime(); + long diffMS = Math.abs(captureMS - wantMS); + + if(closest == null) { + // first result to pass, by definition, for now it's the closest: + closest = o; + closestDiffMS = diffMS; + + } else { + + if(closestDiffMS < diffMS) { + // dates now increasing, start short-circuiting the rest + found = true; + } else { + // this is closer than anything we've seen: + closest = o; + closestDiffMS = diffMS; + } + } + return FILTER_INCLUDE; + } +} Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/ClosestResultTrackingFilter.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Id Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java 2010-10-01 16:20:35 UTC (rev 3265) @@ -47,6 +47,7 @@ import org.archive.wayback.core.UrlSearchResults; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.AdministrativeAccessControlException; +import org.archive.wayback.exception.AnchorWindowTooSmallException; import org.archive.wayback.exception.AuthenticationControlException; import org.archive.wayback.exception.BaseExceptionRenderer; import org.archive.wayback.exception.BetterRequestException; @@ -315,9 +316,12 @@ (CaptureSearchResults) results; // TODO: check which versions are actually accessible right now? - CaptureSearchResult closest = captureResults.getClosest(wbRequest, - isUseAnchorWindow()); + CaptureSearchResult closest = + getReplay().getClosest(wbRequest, captureResults); + closest.setClosest(true); + checkAnchorWindow(wbRequest,closest); + try { resource = getCollection().getResourceStore().retrieveResource(closest); @@ -342,6 +346,28 @@ } } + private void checkAnchorWindow(WaybackRequest wbRequest, + CaptureSearchResult result) throws AnchorWindowTooSmallException { + if(isUseAnchorWindow()) { + String anchorDate = wbRequest.getAnchorTimestamp(); + if(anchorDate != null) { + long wantTime = wbRequest.getReplayDate().getTime(); + long maxWindow = wbRequest.getAnchorWindow() * 1000; + if(maxWindow > 0) { + long closestDistance = Math.abs(wantTime - + result.getCaptureDate().getTime()); + + if(closestDistance > maxWindow) { + throw new AnchorWindowTooSmallException("Closest is " + + closestDistance + " seconds away, Window is " + + maxWindow); + } + } + } + + } + } + private void handleQuery(WaybackRequest wbRequest, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException, IOException, WaybackException { @@ -352,7 +378,15 @@ p.queried(); if(results instanceof CaptureSearchResults) { CaptureSearchResults cResults = (CaptureSearchResults) results; - cResults.markClosest(wbRequest); + + // The Firefox proxy plugin maks an XML request to populate the + // list of available captures, and needs the closest result to + // the one being replayed to be flagged as such: + CaptureSearchResult closest = cResults.getClosest(); + if(closest != null) { + closest.setClosest(true); + } + getQuery().renderCaptureResults(httpRequest,httpResponse,wbRequest, cResults,getUriConverter()); Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlReplay.xml =================================================================== --- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlReplay.xml 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlReplay.xml 2010-10-01 16:20:35 UTC (rev 3265) @@ -105,6 +105,9 @@ return the document to the user. --> <bean id="archivalurlreplay" class="org.archive.wayback.replay.SelectorReplayDispatcher"> + <property name="closestSelector"> + <bean class="org.archive.wayback.replay.DateRedirectingClosestResultSelector" /> + </property> <property name="selectors"> <list> Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/DomainPrefixReplay.xml =================================================================== --- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/DomainPrefixReplay.xml 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/DomainPrefixReplay.xml 2010-10-01 16:20:35 UTC (rev 3265) @@ -26,6 +26,9 @@ </bean> <bean id="domainprefixreplay" class="org.archive.wayback.replay.SelectorReplayDispatcher"> + <property name="closestSelector"> + <bean class="org.archive.wayback.replay.DateRedirectingClosestResultSelector" /> + </property> <property name="selectors"> <list> Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/MementoReplay.xml =================================================================== --- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/MementoReplay.xml 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/MementoReplay.xml 2010-10-01 16:20:35 UTC (rev 3265) @@ -23,6 +23,9 @@ </bean> <bean id="mementoreplay" class="org.archive.wayback.replay.SelectorReplayDispatcher"> + <property name="closestSelector"> + <bean class="org.archive.wayback.replay.DateRedirectingClosestResultSelector" /> + </property> <property name="selectors"> <list> Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ProxyReplay.xml =================================================================== --- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ProxyReplay.xml 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ProxyReplay.xml 2010-10-01 16:20:35 UTC (rev 3265) @@ -23,6 +23,9 @@ </bean> <bean id="proxyreplay" class="org.archive.wayback.replay.SelectorReplayDispatcher"> + <property name="closestSelector"> + <bean class="org.archive.wayback.replay.DefaultClosestResultSelector" /> + </property> <property name="selectors"> <list> Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/query/Memento.jsp =================================================================== --- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/query/Memento.jsp 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/query/Memento.jsp 2010-10-01 16:20:35 UTC (rev 3265) @@ -41,7 +41,7 @@ String dtdate = wbRequest.get("dtconneg"); CaptureSearchResults cResults = results.getCaptureResults(); - CaptureSearchResult res = cResults.getClosest(wbRequest, true); + CaptureSearchResult res = cResults.getClosest(); Date closestDate = res.getCaptureDate(); Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/query/ORE.jsp =================================================================== --- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/query/ORE.jsp 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/query/ORE.jsp 2010-10-01 16:20:35 UTC (rev 3265) @@ -36,7 +36,7 @@ WaybackRequest wbRequest = results.getWbRequest(); CaptureSearchResults cResults = results.getCaptureResults(); - CaptureSearchResult res = cResults.getClosest(wbRequest, true); + CaptureSearchResult res = cResults.getClosest(); ArchivalUrlResultURIConverter uriconverter = (ArchivalUrlResultURIConverter) results .getURIConverter(); Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/MementoValidity.jsp =================================================================== --- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/MementoValidity.jsp 2010-10-01 15:43:09 UTC (rev 3264) +++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/MementoValidity.jsp 2010-10-01 16:20:35 UTC (rev 3265) @@ -11,7 +11,7 @@ UIResults results = UIResults.extractCaptureQuery(request); WaybackRequest wbRequest = results.getWbRequest(); CaptureSearchResults cResults = results.getCaptureResults(); - CaptureSearchResult res = cResults.getClosest(wbRequest, true); + CaptureSearchResult res = cResults.getClosest(); String u = wbRequest.getRequestUrl(); SimpleDateFormat httpformatterl = new SimpleDateFormat( "E, dd MMM yyyy HH:mm:ss z"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |