From: <bra...@us...> - 2008-04-11 04:05:09
|
Revision: 2230 http://archive-access.svn.sourceforge.net/archive-access/?rev=2230&view=rev Author: bradtofel Date: 2008-04-10 21:05:05 -0700 (Thu, 10 Apr 2008) Log Message: ----------- INTERFACE: added shutdown() to ResourceStore, currently no-op on all implementations Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceStore.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/Http11ResourceStore.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/LocalARCResourceStore.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceStore.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceStore.java 2008-04-11 03:58:09 UTC (rev 2229) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceStore.java 2008-04-11 04:05:05 UTC (rev 2230) @@ -46,4 +46,6 @@ */ public Resource retrieveResource(SearchResult result) throws IOException, ResourceNotAvailableException; + + public void shutdown() throws IOException; } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/Http11ResourceStore.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/Http11ResourceStore.java 2008-04-11 03:58:09 UTC (rev 2229) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/Http11ResourceStore.java 2008-04-11 04:05:05 UTC (rev 2230) @@ -98,4 +98,8 @@ public void setUrlPrefix(String urlPrefix) { this.urlPrefix = urlPrefix; } + + public void shutdown() throws IOException { + // no-op + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/LocalARCResourceStore.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/LocalARCResourceStore.java 2008-04-11 03:58:09 UTC (rev 2229) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/LocalARCResourceStore.java 2008-04-11 04:05:05 UTC (rev 2230) @@ -363,4 +363,8 @@ public void setIndexClient(IndexClient indexClient) { this.indexClient = indexClient; } + + public void shutdown() throws IOException { + // no-op... could shutdown threads... + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-04-11 04:07:13
|
Revision: 2232 http://archive-access.svn.sourceforge.net/archive-access/?rev=2232&view=rev Author: bradtofel Date: 2008-04-10 21:07:18 -0700 (Thu, 10 Apr 2008) Log Message: ----------- INTERFACE: added shutdown() to ResourceIndex interface, LocalResourceIndex is the only implementation that uses this at present, shutting down it's SearchResultSource Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/LocalResourceIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/RemoteResourceIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/AlphaPartitionedIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/RangeGroup.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/RangeMember.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceIndex.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceIndex.java 2008-04-11 04:06:12 UTC (rev 2231) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceIndex.java 2008-04-11 04:07:18 UTC (rev 2232) @@ -23,6 +23,8 @@ package org.archive.wayback; +import java.io.IOException; + import org.archive.wayback.core.SearchResults; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.AccessControlException; @@ -53,4 +55,6 @@ throws ResourceIndexNotAvailableException, ResourceNotInArchiveException, BadQueryException, AccessControlException; + + public void shutdown() throws IOException; } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/LocalResourceIndex.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/LocalResourceIndex.java 2008-04-11 04:06:12 UTC (rev 2231) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/LocalResourceIndex.java 2008-04-11 04:07:18 UTC (rev 2232) @@ -464,4 +464,8 @@ public void setCanonicalizer(UrlCanonicalizer canonicalizer) { this.canonicalizer = canonicalizer; } + + public void shutdown() throws IOException { + source.shutdown(); + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/RemoteResourceIndex.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/RemoteResourceIndex.java 2008-04-11 04:06:12 UTC (rev 2231) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/RemoteResourceIndex.java 2008-04-11 04:07:18 UTC (rev 2232) @@ -287,4 +287,8 @@ public void setSearchUrlBase(String searchUrlBase) { this.searchUrlBase = searchUrlBase; } + + public void shutdown() throws IOException { + // No-op + } } \ No newline at end of file Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/AlphaPartitionedIndex.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/AlphaPartitionedIndex.java 2008-04-11 04:06:12 UTC (rev 2231) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/AlphaPartitionedIndex.java 2008-04-11 04:07:18 UTC (rev 2232) @@ -248,4 +248,10 @@ public void setCanonicalizer(UrlCanonicalizer canonicalizer) { this.canonicalizer = canonicalizer; } + + public void shutdown() throws IOException { + for(RangeGroup group : groups) { + group.shutdown(); + } + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/RangeGroup.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/RangeGroup.java 2008-04-11 04:06:12 UTC (rev 2231) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/RangeGroup.java 2008-04-11 04:07:18 UTC (rev 2232) @@ -24,6 +24,7 @@ */ package org.archive.wayback.resourceindex.distributed; +import java.io.IOException; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -169,4 +170,10 @@ } }; } + + public void shutdown() throws IOException { + for(RangeMember member : members.values()) { + member.shutdown(); + } + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/RangeMember.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/RangeMember.java 2008-04-11 04:06:12 UTC (rev 2231) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/RangeMember.java 2008-04-11 04:07:18 UTC (rev 2232) @@ -24,6 +24,8 @@ */ package org.archive.wayback.resourceindex.distributed; +import java.io.IOException; + import org.archive.wayback.ResourceIndex; import org.archive.wayback.core.SearchResults; import org.archive.wayback.core.WaybackRequest; @@ -89,4 +91,7 @@ public void setUrlBase(String urlBase) { index.setSearchUrlBase(urlBase); } + public void shutdown() throws IOException { + index.shutdown(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-06-24 22:52:30
|
Revision: 2304 http://archive-access.svn.sourceforge.net/archive-access/?rev=2304&view=rev Author: bradtofel Date: 2008-06-24 15:52:35 -0700 (Tue, 24 Jun 2008) Log Message: ----------- REFACTOR: moved renderException from QueryRenderer and ReplayDispatcher to ExceptionRenderer. REFACTOR: changed interface of ReplayDispatcher to return a ReplayRenderer. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/QueryRenderer.java 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/archivalurl/ArchivalUrlReplayDispatcher.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayDispatcher.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayDispatcher.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/QueryRenderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/QueryRenderer.java 2008-06-24 22:50:52 UTC (rev 2303) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/QueryRenderer.java 2008-06-24 22:52:35 UTC (rev 2304) @@ -32,7 +32,6 @@ import org.archive.wayback.core.SearchResults; import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.exception.WaybackException; /** * @@ -42,20 +41,6 @@ */ public interface QueryRenderer { - /** - * Render the contents of a WaybackException in either xml or html format. - * - * @param httpRequest - * @param httpResponse - * @param wbRequest - * @param exception - * @throws ServletException - * @throws IOException - */ - public void renderException(HttpServletRequest httpRequest, - HttpServletResponse httpResponse, WaybackRequest wbRequest, - WaybackException exception) throws ServletException, IOException; - /** Show the SearchResults of the request for this particular URL * * @param httpRequest the HttpServletRequest 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 2008-06-24 22:50:52 UTC (rev 2303) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ReplayDispatcher.java 2008-06-24 22:52:35 UTC (rev 2304) @@ -24,14 +24,9 @@ */ package org.archive.wayback; -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import org.archive.wayback.core.Resource; +import org.archive.wayback.core.SearchResult; import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.exception.WaybackException; /** * @@ -39,21 +34,16 @@ * @author brad * @version $Date$, $Revision$ */ -public interface ReplayDispatcher extends ReplayRenderer { +public interface ReplayDispatcher { /** - * Render the contents of a WaybackException in either html, javascript, or - * css format, depending on the guessed context, so errors in embedded - * documents do not cause unneeded errors in the embedding document. * - * @param httpRequest - * @param httpResponse + * Return a ReplayRenderer appropriate for the Resource. + * * @param wbRequest - * @param exception - * @throws ServletException - * @throws IOException + * @param result + * @param resource + * @return the correct ReplayRenderer for the Resource */ - public void renderException(HttpServletRequest httpRequest, - HttpServletResponse httpResponse, WaybackRequest wbRequest, - WaybackException exception) throws ServletException, IOException; - + public ReplayRenderer getRenderer(WaybackRequest wbRequest, + SearchResult result, Resource resource); } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlReplayDispatcher.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlReplayDispatcher.java 2008-06-24 22:50:52 UTC (rev 2303) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlReplayDispatcher.java 2008-06-24 22:52:35 UTC (rev 2304) @@ -26,12 +26,12 @@ import java.util.List; +import org.archive.wayback.ReplayDispatcher; import org.archive.wayback.ReplayRenderer; import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Resource; import org.archive.wayback.core.SearchResult; import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.replay.BaseReplayDispatcher; import org.archive.wayback.replay.DateRedirectReplayRenderer; /** @@ -40,8 +40,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class ArchivalUrlReplayDispatcher - extends BaseReplayDispatcher { +public class ArchivalUrlReplayDispatcher implements ReplayDispatcher { /** * MIME type of documents which should be marked up with javascript to @@ -69,9 +68,8 @@ new ArchivalUrlASXReplayRenderer(); /* (non-Javadoc) - * @see org.archive.wayback.replay.ReplayRendererDispatcher#getRenderer(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.SearchResult, org.archive.wayback.core.Resource) + * @see org.archive.wayback.ReplayDispatcher#getRenderer(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.SearchResult, org.archive.wayback.core.Resource) */ - @Override public ReplayRenderer getRenderer(WaybackRequest wbRequest, SearchResult result, Resource resource) { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayDispatcher.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayDispatcher.java 2008-06-24 22:50:52 UTC (rev 2303) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayDispatcher.java 2008-06-24 22:52:35 UTC (rev 2304) @@ -24,12 +24,12 @@ */ package org.archive.wayback.domainprefix; +import org.archive.wayback.ReplayDispatcher; import org.archive.wayback.ReplayRenderer; import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Resource; import org.archive.wayback.core.SearchResult; import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.replay.BaseReplayDispatcher; import org.archive.wayback.replay.DateRedirectReplayRenderer; import org.archive.wayback.replay.TransparentReplayRenderer; @@ -39,7 +39,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class DomainPrefixReplayDispatcher extends BaseReplayDispatcher { +public class DomainPrefixReplayDispatcher implements ReplayDispatcher { private final static String TEXT_HTML_MIME = "text/html"; private final static String TEXT_XHTML_MIME = "application/xhtml"; @@ -53,9 +53,8 @@ private DomainPrefixReplayRenderer html = new DomainPrefixReplayRenderer(); /* (non-Javadoc) - * @see org.archive.wayback.replay.BaseReplayDispatcher#getRenderer(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.SearchResult, org.archive.wayback.core.Resource) + * @see org.archive.wayback.ReplayDispatcher#getRenderer(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.SearchResult, org.archive.wayback.core.Resource) */ - @Override public ReplayRenderer getRenderer(WaybackRequest wbRequest, SearchResult result, Resource resource) { // if the result is not for the exact date requested, redirect to the Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayDispatcher.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayDispatcher.java 2008-06-24 22:50:52 UTC (rev 2303) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayDispatcher.java 2008-06-24 22:52:35 UTC (rev 2304) @@ -24,27 +24,27 @@ */ package org.archive.wayback.proxy; +import org.archive.wayback.ReplayDispatcher; import org.archive.wayback.ReplayRenderer; import org.archive.wayback.core.Resource; import org.archive.wayback.core.SearchResult; import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.replay.BaseReplayDispatcher; import org.archive.wayback.replay.TransparentReplayRenderer; /** + * Trivial Replay dispatcher implementation, generally used in Proxy mode, that + * sends all documents back as-is. * - * * @author brad * @version $Date$, $Revision$ */ -public class ProxyReplayDispatcher extends BaseReplayDispatcher { +public class ProxyReplayDispatcher implements ReplayDispatcher { private ReplayRenderer renderer = new TransparentReplayRenderer(); - + /* (non-Javadoc) - * @see org.archive.wayback.replay.ReplayRendererDispatcher#getRenderer(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.SearchResult, org.archive.wayback.core.Resource) + * @see org.archive.wayback.ReplayDispatcher#getRenderer(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.SearchResult, org.archive.wayback.core.Resource) */ - @Override public ReplayRenderer getRenderer(WaybackRequest wbRequest, SearchResult result, Resource resource) { // always use the transparent: Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java 2008-06-24 22:50:52 UTC (rev 2303) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java 2008-06-24 22:52:35 UTC (rev 2304) @@ -35,20 +35,18 @@ import org.archive.wayback.ResultURIConverter; import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.SearchResults; -import org.archive.wayback.core.UIResults; import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.exception.WaybackException; /** + * Brain-dead simple QueryRenderer implementation, which shunts all the work off + * to a .jsp file as defined by administrators. Also has basic logic to switch + * to a different .jsp to format request asking for XML data. * - * * @author brad * @version $Date$, $Revision$ */ public class Renderer implements QueryRenderer { - private String errorJsp = "/jsp/HTMLError.jsp"; - private String xmlErrorJsp = "/jsp/XMLError.jsp"; private String captureJsp = "/jsp/HTMLResults.jsp"; private String urlJsp = "/jsp/HTMLResults.jsp"; private String xmlJsp = "/jsp/XMLResults.jsp"; @@ -68,21 +66,6 @@ dispatcher.forward(request, response); } - public void renderException(HttpServletRequest httpRequest, - HttpServletResponse httpResponse, WaybackRequest wbRequest, - WaybackException exception) throws ServletException, IOException { - - httpRequest.setAttribute("exception", exception); - UIResults uiResults = new UIResults(wbRequest); - String jsp = errorJsp; - if(wbRequest.containsKey(WaybackConstants.REQUEST_XML_DATA)) { - jsp = xmlErrorJsp; - } - uiResults.storeInRequest(httpRequest,jsp); - - proxyRequest(httpRequest,httpResponse,jsp); - } - public void renderUrlResults(HttpServletRequest httpRequest, HttpServletResponse httpResponse, WaybackRequest wbRequest, SearchResults results, ResultURIConverter uriConverter) @@ -121,20 +104,6 @@ } /** - * @return the errorJsp - */ - public String getErrorJsp() { - return errorJsp; - } - - /** - * @param errorJsp the errorJsp to set - */ - public void setErrorJsp(String errorJsp) { - this.errorJsp = errorJsp; - } - - /** * @return the captureJsp */ public String getCaptureJsp() { @@ -161,4 +130,18 @@ public void setUrlJsp(String urlJsp) { this.urlJsp = urlJsp; } + + /** + * @return the xmlJsp + */ + public String getXmlJsp() { + return xmlJsp; + } + + /** + * @param xmlJsp the xmlJsp to set + */ + public void setXmlJsp(String xmlJsp) { + this.xmlJsp = xmlJsp; + } } 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 2008-06-24 22:50:52 UTC (rev 2303) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java 2008-06-24 22:52:35 UTC (rev 2304) @@ -33,8 +33,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.archive.wayback.ExceptionRenderer; import org.archive.wayback.QueryRenderer; import org.archive.wayback.ReplayDispatcher; +import org.archive.wayback.ReplayRenderer; import org.archive.wayback.RequestParser; import org.archive.wayback.ResultURIConverter; import org.archive.wayback.WaybackConstants; @@ -46,7 +48,7 @@ import org.archive.wayback.core.UIResults; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.AuthenticationControlException; -import org.archive.wayback.exception.BadQueryException; +import org.archive.wayback.exception.BaseExceptionRenderer; import org.archive.wayback.exception.ResourceNotAvailableException; import org.archive.wayback.exception.ResourceNotInArchiveException; import org.archive.wayback.exception.WaybackException; @@ -76,6 +78,7 @@ private String contextName = null; private WaybackCollection collection = null; private ReplayDispatcher replay = null; + private ExceptionRenderer exception = new BaseExceptionRenderer(); private QueryRenderer query = null; private RequestParser parser = null; private ResultURIConverter uriConverter = null; @@ -287,10 +290,9 @@ handled = dispatchLocal(httpRequest,httpResponse); } - } catch (BadQueryException e) { - query.renderException(httpRequest, httpResponse, wbRequest, e); - } catch (AuthenticationControlException e) { - query.renderException(httpRequest, httpResponse, wbRequest, e); + } catch(WaybackException e) { + logNotInArchive(e,wbRequest); + exception.renderException(httpRequest, httpResponse, wbRequest, e); } return handled; @@ -298,7 +300,7 @@ private void handleReplay(WaybackRequest wbRequest, HttpServletRequest httpRequest, HttpServletResponse httpResponse) - throws IOException, ServletException { + throws IOException, ServletException, WaybackException { Resource resource = null; try { SearchResults results = collection.getResourceIndex().query(wbRequest); @@ -310,12 +312,9 @@ // TODO: check which versions are actually accessible right now? SearchResult closest = captureResults.getClosest(wbRequest); resource = collection.getResourceStore().retrieveResource(closest); - - replay.renderResource(httpRequest, httpResponse, wbRequest, + ReplayRenderer renderer = replay.getRenderer(wbRequest, closest, resource); + renderer.renderResource(httpRequest, httpResponse, wbRequest, closest, resource, uriConverter, captureResults); - } catch(WaybackException e) { - logNotInArchive(e,wbRequest); - replay.renderException(httpRequest, httpResponse, wbRequest, e); } finally { if(resource != null) { resource.close(); @@ -325,26 +324,21 @@ private void handleQuery(WaybackRequest wbRequest, HttpServletRequest httpRequest, HttpServletResponse httpResponse) - throws ServletException, IOException { + throws ServletException, IOException, WaybackException { - try { - SearchResults results = collection.getResourceIndex().query(wbRequest); - if(results.getResultsType().equals( - WaybackConstants.RESULTS_TYPE_CAPTURE)) { - CaptureSearchResults cResults = (CaptureSearchResults) results; - SearchResult closest = cResults.getClosest(wbRequest); - closest.put(WaybackConstants.RESULT_CLOSEST_INDICATOR, - WaybackConstants.RESULT_CLOSEST_VALUE); - query.renderUrlResults(httpRequest,httpResponse,wbRequest, - results,uriConverter); + SearchResults results = collection.getResourceIndex().query(wbRequest); + if(results.getResultsType().equals( + WaybackConstants.RESULTS_TYPE_CAPTURE)) { + CaptureSearchResults cResults = (CaptureSearchResults) results; + SearchResult closest = cResults.getClosest(wbRequest); + closest.put(WaybackConstants.RESULT_CLOSEST_INDICATOR, + WaybackConstants.RESULT_CLOSEST_VALUE); + query.renderUrlResults(httpRequest,httpResponse,wbRequest, + results,uriConverter); - } else { - query.renderUrlPrefixResults(httpRequest,httpResponse,wbRequest, - results,uriConverter); - } - } catch(WaybackException e) { - logNotInArchive(e,wbRequest); - query.renderException(httpRequest, httpResponse, wbRequest, e); + } else { + query.renderUrlPrefixResults(httpRequest,httpResponse,wbRequest, + results,uriConverter); } } @@ -355,6 +349,7 @@ } private void logNotInArchive(WaybackException e, WaybackRequest r) { + // TODO: move this into ResourceNotInArchiveException constructor if(e instanceof ResourceNotInArchiveException) { String url = r.get(WaybackConstants.REQUEST_URL); StringBuilder sb = new StringBuilder(100); @@ -468,4 +463,12 @@ public void setCollection(WaybackCollection collection) { this.collection = collection; } + + public ExceptionRenderer getException() { + return exception; + } + + public void setException(ExceptionRenderer exception) { + this.exception = exception; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-07-01 23:38:11
|
Revision: 2367 http://archive-access.svn.sourceforge.net/archive-access/?rev=2367&view=rev Author: bradtofel Date: 2008-07-01 16:38:20 -0700 (Tue, 01 Jul 2008) Log Message: ----------- REFACTOR: SearchResult => (Url|Capture)SearchResult Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/QueryRenderer.java 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/ReplayRenderer.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceStore.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/QueryRenderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/QueryRenderer.java 2008-07-01 23:36:18 UTC (rev 2366) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/QueryRenderer.java 2008-07-01 23:38:20 UTC (rev 2367) @@ -30,7 +30,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.archive.wayback.core.SearchResults; +import org.archive.wayback.core.CaptureSearchResults; +import org.archive.wayback.core.UrlSearchResults; import org.archive.wayback.core.WaybackRequest; /** @@ -52,9 +53,9 @@ * @throws ServletException * @throws IOException */ - public void renderUrlResults(HttpServletRequest httpRequest, + public void renderCaptureResults(HttpServletRequest httpRequest, HttpServletResponse httpResponse, WaybackRequest wbRequest, - SearchResults results, ResultURIConverter uriConverter) + CaptureSearchResults results, ResultURIConverter uriConverter) throws ServletException, IOException; /** Show the SearchResults of the request which may have resulted in @@ -69,9 +70,9 @@ * @throws ServletException * @throws IOException */ - public void renderUrlPrefixResults(HttpServletRequest httpRequest, + public void renderUrlResults(HttpServletRequest httpRequest, HttpServletResponse response, WaybackRequest wbRequest, - SearchResults results, ResultURIConverter uriConverter) + UrlSearchResults results, ResultURIConverter uriConverter) throws ServletException, IOException; } 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 2008-07-01 23:36:18 UTC (rev 2366) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ReplayDispatcher.java 2008-07-01 23:38:20 UTC (rev 2367) @@ -25,7 +25,7 @@ package org.archive.wayback; import org.archive.wayback.core.Resource; -import org.archive.wayback.core.SearchResult; +import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.WaybackRequest; /** @@ -45,5 +45,5 @@ * @return the correct ReplayRenderer for the Resource */ public ReplayRenderer getRenderer(WaybackRequest wbRequest, - SearchResult result, Resource resource); + CaptureSearchResult result, Resource resource); } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ReplayRenderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ReplayRenderer.java 2008-07-01 23:36:18 UTC (rev 2366) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ReplayRenderer.java 2008-07-01 23:38:20 UTC (rev 2367) @@ -31,8 +31,8 @@ import javax.servlet.http.HttpServletResponse; import org.archive.wayback.core.Resource; -import org.archive.wayback.core.SearchResult; -import org.archive.wayback.core.SearchResults; +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.WaybackException; @@ -50,11 +50,11 @@ * @param httpRequest the HttpServletRequest * @param httpResponse the HttpServletResponse * @param wbRequest the WaybackRequest that returned the results - * @param result actual SearchResult that maps to resource to replay + * @param result actual CaptureSearchResult that maps to resource to replay * @param resource resource to replay * @param uriConverter the URI converter to use to translate matching * results into replayable URLs - * @param results all SearchResults that were returned from the + * @param results all CaptureSearchResults that were returned from the * ResourceIndex, probably including other capture * dates of the same URL. * @throws ServletException @@ -63,7 +63,7 @@ */ public void renderResource(HttpServletRequest httpRequest, HttpServletResponse httpResponse, WaybackRequest wbRequest, - SearchResult result, Resource resource, - ResultURIConverter uriConverter, SearchResults results) + CaptureSearchResult result, Resource resource, + ResultURIConverter uriConverter, CaptureSearchResults results) throws ServletException, IOException, WaybackException; } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceStore.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceStore.java 2008-07-01 23:36:18 UTC (rev 2366) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/ResourceStore.java 2008-07-01 23:38:20 UTC (rev 2367) @@ -26,7 +26,7 @@ import java.io.IOException; import org.archive.wayback.core.Resource; -import org.archive.wayback.core.SearchResult; +import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.exception.ResourceNotAvailableException; /** @@ -44,7 +44,7 @@ * @throws IOException * @throws ResourceNotAvailableException */ - public Resource retrieveResource(SearchResult result) throws IOException, + public Resource retrieveResource(CaptureSearchResult result) throws IOException, ResourceNotAvailableException; public void shutdown() throws IOException; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <bra...@us...> - 2008-07-07 21:31:40
|
Revision: 2412 http://archive-access.svn.sourceforge.net/archive-access/?rev=2412&view=rev Author: bradtofel Date: 2008-07-07 14:31:49 -0700 (Mon, 07 Jul 2008) Log Message: ----------- TWEAK: return from all InterruptedExceptions. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/cdx/dynamic/DynamicCDXIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/LocalResourceIndexUpdater.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/AutoIndexThread.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexQueueUpdater.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/ResourceFileLocationDBUpdater.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/resourcefile/ResourceFileSourceUpdater.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/cdx/dynamic/DynamicCDXIndex.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/cdx/dynamic/DynamicCDXIndex.java 2008-07-07 21:30:27 UTC (rev 2411) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/cdx/dynamic/DynamicCDXIndex.java 2008-07-07 21:31:49 UTC (rev 2412) @@ -335,6 +335,7 @@ sleep(sleepInterval); } catch (InterruptedException e) { e.printStackTrace(); + return; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/LocalResourceIndexUpdater.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/LocalResourceIndexUpdater.java 2008-07-07 21:30:27 UTC (rev 2411) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/LocalResourceIndexUpdater.java 2008-07-07 21:31:49 UTC (rev 2412) @@ -293,6 +293,7 @@ } } catch (InterruptedException e) { e.printStackTrace(); + return; } } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/AutoIndexThread.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/AutoIndexThread.java 2008-07-07 21:30:27 UTC (rev 2411) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/AutoIndexThread.java 2008-07-07 21:31:49 UTC (rev 2412) @@ -56,6 +56,7 @@ } } catch (InterruptedException e) { e.printStackTrace(); + return; } } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexQueueUpdater.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexQueueUpdater.java 2008-07-07 21:30:27 UTC (rev 2411) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexQueueUpdater.java 2008-07-07 21:31:49 UTC (rev 2412) @@ -151,6 +151,7 @@ sleep(sleepInterval); } catch (InterruptedException e) { e.printStackTrace(); + return; } catch (IOException e) { e.printStackTrace(); } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/ResourceFileLocationDBUpdater.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/ResourceFileLocationDBUpdater.java 2008-07-07 21:30:27 UTC (rev 2411) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/ResourceFileLocationDBUpdater.java 2008-07-07 21:31:49 UTC (rev 2412) @@ -168,6 +168,7 @@ sleep(sleepInterval); } catch (InterruptedException e) { e.printStackTrace(); + return; } catch (IOException e) { e.printStackTrace(); } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/resourcefile/ResourceFileSourceUpdater.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/resourcefile/ResourceFileSourceUpdater.java 2008-07-07 21:30:27 UTC (rev 2411) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/resourcefile/ResourceFileSourceUpdater.java 2008-07-07 21:31:49 UTC (rev 2412) @@ -125,6 +125,7 @@ } } catch (InterruptedException e) { e.printStackTrace(); + return; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-07-07 21:57:22
|
Revision: 2417 http://archive-access.svn.sourceforge.net/archive-access/?rev=2417&view=rev Author: bradtofel Date: 2008-07-07 14:57:30 -0700 (Mon, 07 Jul 2008) Log Message: ----------- REFACTOR: moved WaybackConstants.REQUEST* to WaybackRequest class. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/WaybackConstants.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlReplayDispatcher.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDateRangeQueryRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDatePrefixQueryRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDateRangeQueryRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ReplayRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/authenticationcontrol/HTTPAuthBooleanOperator.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/authenticationcontrol/IPMatchesBooleanOperator.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/core/SearchResults.java 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/WaybackRequest.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayDispatcher.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/BaseExceptionRenderer.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/LiveWebCache.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.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/query/resultspartitioner/ResultsPartitionsFactory.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsTimelinePartitionsFactory.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/LocalResourceIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/NutchResourceIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/RemoteResourceIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/distributed/AlphaPartitionedIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/WaybackConstants.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/WaybackConstants.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/WaybackConstants.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -24,6 +24,7 @@ */ package org.archive.wayback; + /** * * @@ -48,319 +49,6 @@ public static final String DNS_URL_PREFIX = "dns:"; /** - * Request: (query) filter results to those prefixed with this (possibly - * partial) 14-digit timestamp - */ - public static final String REQUEST_DATE = "date"; - - /** - * Request: filter results before this 14-digit timestamp - */ - public static final String REQUEST_START_DATE = "startdate"; - - /** - * Request: filter results after this 14-digit timestamp - */ - public static final String REQUEST_END_DATE = "enddate"; - - /** - * Request: (replay) find closest result to this 14-digit timestamp - */ - public static final String REQUEST_EXACT_DATE = "exactdate"; - - /** - * Request: URL or URL prefix requested - */ - public static final String REQUEST_URL = "url"; - - /** - * Request: Original URL or URL prefix requested. - * This version differs from @{link {@link #REQUEST_URL} in that its - * the URL before it was passed via the UURIFactory cleanup. - */ - public static final String REQUEST_URL_CLEANED = "cleanedurl"; - - /** - * Request: URL of referrer, if supplied, or "" if not - */ - public static final String REQUEST_REFERER_URL = "refererurl"; - - /** - * Request: defines type - urlquery, urlprefixquery, or replay - */ - public static final String REQUEST_TYPE = "type"; - - /** - * Request: xml data requested - */ - public static final String REQUEST_XML_DATA = "xmldata"; - - /** - * Request: urlquery type request - */ - public static final String REQUEST_URL_QUERY = "urlquery"; - - /** - * Request: urlprefixquery type request - */ - public static final String REQUEST_URL_PREFIX_QUERY = "urlprefixquery"; - - /** - * Request: replay type request - */ - public static final String REQUEST_REPLAY_QUERY = "replay"; - - /** - * Request: closest type request - */ - public static final String REQUEST_CLOSEST_QUERY = "urlclosestquery"; - - /** - * Request: resolution of results to be displayed: (TimeLine mode) - */ - public static final String REQUEST_RESOLUTION = "resolution"; - - /** - * Request: replay actual document or metadata for document: "yes" means - * replay metadata only, not the actual document: (TimeLine mode) - */ - public static final String REQUEST_META_MODE = "metamode"; - - /** - * Request: hour resolution (TimeLine mode) - */ - public static final String REQUEST_RESOLUTION_HOURS = "hours"; - - /** - * Request: day resolution (TimeLine mode) - */ - public static final String REQUEST_RESOLUTION_DAYS = "days"; - - /** - * Request: month resolution (TimeLine mode) - */ - public static final String REQUEST_RESOLUTION_MONTHS = "months"; - - /** - * Request: two-month resolution (TimeLine mode) - */ - public static final String REQUEST_RESOLUTION_TWO_MONTHS = "twomonths"; - - /** - * Request: year resolution (TimeLine mode) - */ - public static final String REQUEST_RESOLUTION_YEARS = "years"; - - /** - * Request: auto resolution (TimeLine mode) - */ - public static final String REQUEST_RESOLUTION_AUTO = "auto"; - - /** - * Request: Remote Address, string IP address: "127.0.0.1" - */ - public static final String REQUEST_REMOTE_ADDRESS = "remoteaddress"; - - /** - * Request: Wayback Hostname: the string "Host:" HTTP header - */ - public static final String REQUEST_WAYBACK_HOSTNAME = "waybackhostname"; - - /** - * Request: Wayback Port: the port the remote user connected to for this - * request. - */ - public static final String REQUEST_WAYBACK_PORT = "waybackport"; - - /** - * Request: Wayback Context: the string context used in the request, - * if applicable. - */ - public static final String REQUEST_WAYBACK_CONTEXT = "waybackcontext"; - - /** - * Request: Authorization Type: "BASIC", "SSL", or "" if none. - */ - public static final String REQUEST_AUTH_TYPE = "requestauthtype"; - - /** - * Request: Remote User or "" if the request did not contain auth info. - */ - public static final String REQUEST_REMOTE_USER = "requestremoteuser"; - - /** - * Request: Best Guess at users requested locale. - */ - public static final String REQUEST_LOCALE_LANG = "requestlocalelang"; - - /** - * Request: Indicates user only wants results that exactly match the - * requested hostname -- no canonicalization. - */ - public static final String REQUEST_EXACT_HOST_ONLY = "requestexacthost"; - /** - * Request: indicates positive value for any request boolean flag. - */ - public static final String REQUEST_YES = "yes"; - - /** - * Results: type of results: "Capture" or "Url" - */ - public static final String RESULTS_TYPE = "resultstype"; - - /** - * Results: indicates SearchResult objects within the SearchResults are of - * type UrlSearchResults. - */ - public static final String RESULTS_TYPE_URL = "resultstypeurl"; - - /** - * Results: indicates SearchResult objects within the SearchResults are of - * type CaptureSearchResults. - */ - public static final String RESULTS_TYPE_CAPTURE = "resultstypecapture"; - - /** - * Results: int total number of records matching, not all necc. returned. - */ - public static final String RESULTS_NUM_RESULTS = "numresults"; - - /** - * Results: int first record of all matching returned, 1-based - */ - public static final String RESULTS_FIRST_RETURNED = "firstreturned"; - - /** - * Results: int total number of records *returned* in results - */ - public static final String RESULTS_NUM_RETURNED = "numreturned"; - - /** - * Results: int number of results requested - */ - public static final String RESULTS_REQUESTED = "resultsrequested"; - - - /** - * Result: as close as possible to original URL of captured document given - * informatio accessible only within the index. - * - * This may not always yield the exact URL requested: some canonicalization - * operations are irreversible. - * Example: lowercasing of GET URI encoded arguments - * http://foo.com/q?a=%3F => foo.com/q?a=%3f - * Example: rearrangement of GET URI encoded arguments - * http://foo.com/q?b=1&a=1 => foo.com/q?a=1&b=1 - * Example: removal of sessionID information from request path - * http://foo.com/SESSION_A2KSM2/i.htm => foo.com/i.htm - * - */ - public static final String RESULT_URL = "url"; - - /** - * Result: canonicalized(lookup key) form of URL of captured document - */ - public static final String RESULT_URL_KEY = "urlkey"; - - /** - * Result: 14-digit timestamp when document was captured - */ - public static final String RESULT_CAPTURE_DATE = "capturedate"; - - /** - * Result: basename of ARC file containing this document. - */ - public static final String RESULT_ARC_FILE = "arcfile"; - - /** - * Result: compressed byte offset within ARC file where this document's - * gzip envelope begins. - */ - public static final String RESULT_OFFSET = "compressedoffset"; - - /** - * Result: compressed byte offset within ARC file where this document's - * gzip envelope Ends. - */ - public static final String RESULT_END_OFFSET = "compressedendoffset"; - - /** - * Result: original exact host from which this document was captured. - */ - public static final String RESULT_ORIG_HOST = "originalhost"; - - /** - * Result: best-guess at mime-type of this document. - */ - public static final String RESULT_MIME_TYPE = "mimetype"; - - /** - * Result: 3-digit integer HTTP response code. may be '0' in some - * fringe conditions, old ARCs, bug in crawler, etc. - */ - public static final String RESULT_HTTP_CODE = "httpresponsecode"; - - /** - * Result: all or part of the 32-digit hexadecimal MD5 digest of this - * document - */ - public static final String RESULT_MD5_DIGEST= "md5digest"; - - /** - * Result: URL that this document redirected to, or '-' if it does - * not redirect - */ - public static final String RESULT_REDIRECT_URL = "redirecturl"; - - /** - * Result: flag within a SearchResult that indicates this is the closest to - * a particular requested date. - */ - public static final String RESULT_CLOSEST_INDICATOR = "closest"; - public static final String RESULT_CLOSEST_VALUE = "true"; - - /** - * Result: this key being present indicates that this particular capture - * was not actually stored, and that other values within this SearchResult - * are actually values from a different record which *should* be identical - * to this capture, had it been stored. - */ - public static final String RESULT_DUPLICATE_ANNOTATION = "duplicate"; - - /** - * Result: this key is present when the RESULT_DUPLICATE_ANNOTATION is also - * present, with the value indicating the last date that was actually - * stored for this duplicate. - */ - public static final String RESULT_DUPLICATE_STORED_DATE = "duplicate-date"; - - /** - * flag indicates that this document was downloaded and verified as - * identical to a previous capture by digest. - */ - public static final String RESULT_DUPLICATE_DIGEST = "digest"; - - /** - * flag indicates that this document was NOT downloaded, but that the - * origin server indicated that the document had not changed, based on - * If-Modified HTTP request headers. - */ - public static final String RESULT_DUPLICATE_HTTP = "http"; - - - /** - * Name of configuration in web.xml for maximum number of results to return - * in index searches. - */ - public static final String MAX_RESULTS_CONFIG_NAME = "maxresults"; - - /** - * Name of configuration in web.xml for default number of results to show - * on each page - */ - public static final String RESULTS_PER_PAGE_CONFIG_NAME = "resultsperpage"; - - /** * HTTP Header for redirection URL */ public final static String LOCATION_HTTP_HEADER = "Location"; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlReplayDispatcher.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlReplayDispatcher.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlReplayDispatcher.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -28,7 +28,6 @@ import org.archive.wayback.ReplayDispatcher; import org.archive.wayback.ReplayRenderer; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Resource; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.WaybackRequest; @@ -76,7 +75,7 @@ // 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: - String reqDateStr = wbRequest.get(WaybackConstants.REQUEST_DATE); + String reqDateStr = wbRequest.get(WaybackRequest.REQUEST_DATE); String resDateStr = result.getCaptureTimestamp(); if(!resDateStr.equals(reqDateStr.substring(0, resDateStr.length()))) { return redirect; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -28,7 +28,6 @@ import java.util.regex.Pattern; import org.apache.commons.httpclient.URIException; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; @@ -67,10 +66,10 @@ startDate = Timestamp.parseBefore(dateStr).getDateStr(); endDate = Timestamp.parseAfter(dateStr).getDateStr(); } - wbRequest.put(WaybackConstants.REQUEST_START_DATE,startDate); - wbRequest.put(WaybackConstants.REQUEST_END_DATE,endDate); - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_URL_QUERY); + wbRequest.put(WaybackRequest.REQUEST_START_DATE,startDate); + wbRequest.put(WaybackRequest.REQUEST_END_DATE,endDate); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_URL_QUERY); try { wbRequest.setRequestUrl(urlStr); } catch (URIException e) { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDateRangeQueryRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDateRangeQueryRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDateRangeQueryRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -28,7 +28,6 @@ import java.util.regex.Pattern; import org.apache.commons.httpclient.URIException; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; @@ -62,10 +61,10 @@ String startDate = Timestamp.parseBefore(startDateStr).getDateStr(); String endDate = Timestamp.parseAfter(endDateStr).getDateStr(); - wbRequest.put(WaybackConstants.REQUEST_START_DATE,startDate); - wbRequest.put(WaybackConstants.REQUEST_END_DATE,endDate); - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_URL_QUERY); + wbRequest.put(WaybackRequest.REQUEST_START_DATE,startDate); + wbRequest.put(WaybackRequest.REQUEST_END_DATE,endDate); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_URL_QUERY); try { wbRequest.setRequestUrl(urlStr); } catch (URIException e) { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDatePrefixQueryRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDatePrefixQueryRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDatePrefixQueryRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -28,7 +28,6 @@ import java.util.regex.Pattern; import org.apache.commons.httpclient.URIException; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; @@ -67,12 +66,12 @@ endDate = Timestamp.parseAfter(dateStr).getDateStr(); } - wbRequest.put(WaybackConstants.REQUEST_START_DATE, + wbRequest.put(WaybackRequest.REQUEST_START_DATE, startDate); - wbRequest.put(WaybackConstants.REQUEST_END_DATE,endDate); + wbRequest.put(WaybackRequest.REQUEST_END_DATE,endDate); - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_URL_PREFIX_QUERY); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_URL_PREFIX_QUERY); try { wbRequest.setRequestUrl(urlStr); } catch (URIException e) { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDateRangeQueryRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDateRangeQueryRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDateRangeQueryRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -28,7 +28,6 @@ import java.util.regex.Pattern; import org.apache.commons.httpclient.URIException; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; @@ -59,12 +58,12 @@ String urlStr = matcher.group(3); String startDate = Timestamp.parseBefore(startDateStr).getDateStr(); String endDate = Timestamp.parseAfter(endDateStr).getDateStr(); - wbRequest.put(WaybackConstants.REQUEST_START_DATE, + wbRequest.put(WaybackRequest.REQUEST_START_DATE, startDate); - wbRequest.put(WaybackConstants.REQUEST_END_DATE,endDate); + wbRequest.put(WaybackRequest.REQUEST_END_DATE,endDate); - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_URL_PREFIX_QUERY); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_URL_PREFIX_QUERY); try { wbRequest.setRequestUrl(urlStr); } catch (URIException e) { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ReplayRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ReplayRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ReplayRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -30,7 +30,6 @@ import org.apache.commons.httpclient.URIException; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; @@ -87,12 +86,12 @@ dateStr = Timestamp.parseAfter(dateStr).getDateStr(); } - wbRequest.put(WaybackConstants.REQUEST_EXACT_DATE, dateStr); - wbRequest.put(WaybackConstants.REQUEST_START_DATE, startDate); - wbRequest.put(WaybackConstants.REQUEST_END_DATE, endDate); + wbRequest.put(WaybackRequest.REQUEST_EXACT_DATE, dateStr); + wbRequest.put(WaybackRequest.REQUEST_START_DATE, startDate); + wbRequest.put(WaybackRequest.REQUEST_END_DATE, endDate); - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_REPLAY_QUERY); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_REPLAY_QUERY); try { // String wbPrefix = wbRequest.getDefaultWaybackPrefix(); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/authenticationcontrol/HTTPAuthBooleanOperator.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/authenticationcontrol/HTTPAuthBooleanOperator.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/authenticationcontrol/HTTPAuthBooleanOperator.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -2,7 +2,6 @@ import java.util.List; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.util.operator.BooleanOperator; @@ -12,7 +11,7 @@ if(allowedUsers == null) { return false; } - String currentUser = value.get(WaybackConstants.REQUEST_REMOTE_USER); + String currentUser = value.get(WaybackRequest.REQUEST_REMOTE_USER); if(currentUser == null) { return false; } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/authenticationcontrol/IPMatchesBooleanOperator.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/authenticationcontrol/IPMatchesBooleanOperator.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/authenticationcontrol/IPMatchesBooleanOperator.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -4,7 +4,6 @@ import java.util.List; import java.util.logging.Logger; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.util.IPRange; import org.archive.wayback.util.operator.BooleanOperator; @@ -34,7 +33,7 @@ if(allowedRanges == null) { return false; } - String ipString = value.get(WaybackConstants.REQUEST_REMOTE_ADDRESS); + String ipString = value.get(WaybackRequest.REQUEST_REMOTE_ADDRESS); if(ipString == null) { return false; } 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 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -28,7 +28,6 @@ import java.util.Date; import java.util.Iterator; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.exception.AnchorWindowTooSmallException; /** @@ -113,7 +112,7 @@ String anchorDate = wbRequest.get(WaybackRequest.REQUEST_ANCHOR_DATE); long maxWindow = -1; long wantTime = Timestamp.parseBefore(wbRequest - .get(WaybackConstants.REQUEST_EXACT_DATE)).getDate().getTime(); + .get(WaybackRequest.REQUEST_EXACT_DATE)).getDate().getTime(); if(anchorDate != null) { wantTime = Timestamp.parseBefore(anchorDate).getDate().getTime(); String anchorWindow = wbRequest.get(WaybackRequest.REQUEST_ANCHOR_WINDOW); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -69,6 +69,23 @@ private long firstReturned = -1; private long matchingCount = -1; private long numRequested = -1; + + /** + * Results: indicates SearchResult objects within the SearchResults are of + * type UrlSearchResults. + */ + public static final String RESULTS_TYPE_URL = "resultstypeurl"; + + /** + * Results: indicates SearchResult objects within the SearchResults are of + * type CaptureSearchResults. + */ + public static final String RESULTS_TYPE_CAPTURE = "resultstypecapture"; + + /** + * Results: type of results: "Capture" or "Url" + */ + public static final String RESULTS_TYPE = "resultstype"; /** * @param key 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-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -30,7 +30,6 @@ 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; @@ -73,8 +72,8 @@ public String makeCaptureQueryUrl(String url) { WaybackRequest newWBR = wbRequest.clone(); - newWBR.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_URL_QUERY); + newWBR.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_URL_QUERY); try { newWBR.setRequestUrl(url); } catch (URIException e) { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -37,7 +37,6 @@ import org.apache.commons.httpclient.URIException; import org.archive.net.UURI; import org.archive.net.UURIFactory; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.requestparser.OpenSearchRequestParser; import org.archive.wayback.util.ObjectFilter; import org.archive.wayback.util.StringFormatter; @@ -67,17 +66,144 @@ private HashMap<String,String> filters = new HashMap<String,String>(); private StringFormatter formatter = null; + /** + * Request: Authorization Type: "BASIC", "SSL", or "" if none. + */ + public static final String REQUEST_AUTH_TYPE = "requestauthtype"; + /** + * Request: Wayback Context: the string context used in the request, + * if applicable. + */ + public static final String REQUEST_WAYBACK_CONTEXT = "waybackcontext"; + /** + * Request: Wayback Port: the port the remote user connected to for this + * request. + */ + public static final String REQUEST_WAYBACK_PORT = "waybackport"; + /** + * Request: Wayback Hostname: the string "Host:" HTTP header + */ + public static final String REQUEST_WAYBACK_HOSTNAME = "waybackhostname"; + /** + * Request: Remote Address, string IP address: "127.0.0.1" + */ + public static final String REQUEST_REMOTE_ADDRESS = "remoteaddress"; + /** + * Request: auto resolution (TimeLine mode) + */ + public static final String REQUEST_RESOLUTION_AUTO = "auto"; + /** + * Request: year resolution (TimeLine mode) + */ + public static final String REQUEST_RESOLUTION_YEARS = "years"; + /** + * Request: two-month resolution (TimeLine mode) + */ + public static final String REQUEST_RESOLUTION_TWO_MONTHS = "twomonths"; + /** + * Request: month resolution (TimeLine mode) + */ + public static final String REQUEST_RESOLUTION_MONTHS = "months"; + /** + * Request: day resolution (TimeLine mode) + */ + public static final String REQUEST_RESOLUTION_DAYS = "days"; + /** + * Request: hour resolution (TimeLine mode) + */ + public static final String REQUEST_RESOLUTION_HOURS = "hours"; + /** + * Request: replay actual document or metadata for document: "yes" means + * replay metadata only, not the actual document: (TimeLine mode) + */ + public static final String REQUEST_META_MODE = "metamode"; + /** + * Request: resolution of results to be displayed: (TimeLine mode) + */ + public static final String REQUEST_RESOLUTION = "resolution"; + /** + * Request: closest type request + */ + public static final String REQUEST_CLOSEST_QUERY = "urlclosestquery"; + /** + * Request: replay type request + */ + public static final String REQUEST_REPLAY_QUERY = "replay"; + /** + * Request: urlprefixquery type request + */ + public static final String REQUEST_URL_PREFIX_QUERY = "urlprefixquery"; + /** + * Request: urlquery type request + */ + public static final String REQUEST_URL_QUERY = "urlquery"; + /** + * Request: xml data requested + */ + public static final String REQUEST_XML_DATA = "xmldata"; + /** + * Request: defines type - urlquery, urlprefixquery, or replay + */ + public static final String REQUEST_TYPE = "type"; + /** + * Request: URL of referrer, if supplied, or "" if not + */ + public static final String REQUEST_REFERER_URL = "refererurl"; + /** + * Request: Original URL or URL prefix requested. + * This version differs from @{link {@link REQUEST_URL} in that its + * the URL before it was passed via the UURIFactory cleanup. + */ + public static final String REQUEST_URL_CLEANED = "cleanedurl"; + /** + * Request: URL or URL prefix requested + */ + public static final String REQUEST_URL = "url"; + /** + * Request: (replay) find closest result to this 14-digit timestamp + */ + public static final String REQUEST_EXACT_DATE = "exactdate"; + /** + * Request: filter results after this 14-digit timestamp + */ + public static final String REQUEST_END_DATE = "enddate"; + /** + * Request: filter results before this 14-digit timestamp + */ + public static final String REQUEST_START_DATE = "startdate"; + /** + * Request: (query) filter results to those prefixed with this (possibly + * partial) 14-digit timestamp + */ + public static final String REQUEST_DATE = "date"; + /** + * Request: Remote User or "" if the request did not contain auth info. + */ + public static final String REQUEST_REMOTE_USER = "requestremoteuser"; + /** + * Request: Best Guess at users requested locale. + */ + public static final String REQUEST_LOCALE_LANG = "requestlocalelang"; + /** + * Request: Indicates user only wants results that exactly match the + * requested hostname -- no canonicalization. + */ + public static final String REQUEST_EXACT_HOST_ONLY = "requestexacthost"; + /** + * Request: indicates positive value for any request boolean flag. + */ + public static final String REQUEST_YES = "yes"; private static String UI_RESOURCE_BUNDLE_NAME = "WaybackUI"; private final static String standardHeaders[] = { - WaybackConstants.REQUEST_REFERER_URL, - WaybackConstants.REQUEST_REMOTE_ADDRESS, - WaybackConstants.REQUEST_WAYBACK_HOSTNAME, - WaybackConstants.REQUEST_WAYBACK_PORT, - WaybackConstants.REQUEST_WAYBACK_CONTEXT, - WaybackConstants.REQUEST_AUTH_TYPE, - WaybackConstants.REQUEST_REMOTE_USER, - WaybackConstants.REQUEST_LOCALE_LANG }; + WaybackRequest.REQUEST_REFERER_URL, + WaybackRequest.REQUEST_REMOTE_ADDRESS, + WaybackRequest.REQUEST_WAYBACK_HOSTNAME, + WaybackRequest.REQUEST_WAYBACK_PORT, + WaybackRequest.REQUEST_WAYBACK_CONTEXT, + WaybackRequest.REQUEST_AUTH_TYPE, + WaybackRequest.REQUEST_REMOTE_USER, + WaybackRequest.REQUEST_LOCALE_LANG }; /** * Constructor, possibly/probably this should BE a Properties, instead of @@ -91,8 +217,8 @@ * @return true if REQUEST_TYPE is set, and is set to REQUEST_REPLAY_QUERY */ public boolean isReplayRequest() { - String type = get(WaybackConstants.REQUEST_TYPE); - if(type != null && type.equals(WaybackConstants.REQUEST_REPLAY_QUERY)) { + String type = get(WaybackRequest.REQUEST_TYPE); + if(type != null && type.equals(WaybackRequest.REQUEST_REPLAY_QUERY)) { return true; } return false; @@ -191,21 +317,21 @@ */ private void extractHttpRequestInfo(HttpServletRequest httpRequest) { // attempt to get the HTTP referer if present.. - put(WaybackConstants.REQUEST_REFERER_URL, emptyIfNull(httpRequest + put(WaybackRequest.REQUEST_REFERER_URL, emptyIfNull(httpRequest .getHeader("REFERER"))); - put(WaybackConstants.REQUEST_REMOTE_ADDRESS, emptyIfNull(httpRequest + put(WaybackRequest.REQUEST_REMOTE_ADDRESS, emptyIfNull(httpRequest .getRemoteAddr())); - put(WaybackConstants.REQUEST_WAYBACK_HOSTNAME, emptyIfNull(httpRequest + put(WaybackRequest.REQUEST_WAYBACK_HOSTNAME, emptyIfNull(httpRequest .getLocalName())); - put(WaybackConstants.REQUEST_WAYBACK_PORT, String.valueOf(httpRequest + put(WaybackRequest.REQUEST_WAYBACK_PORT, String.valueOf(httpRequest .getLocalPort())); - put(WaybackConstants.REQUEST_WAYBACK_CONTEXT, emptyIfNull(httpRequest + put(WaybackRequest.REQUEST_WAYBACK_CONTEXT, emptyIfNull(httpRequest .getContextPath())); - put(WaybackConstants.REQUEST_AUTH_TYPE, emptyIfNull(httpRequest + put(WaybackRequest.REQUEST_AUTH_TYPE, emptyIfNull(httpRequest .getAuthType())); - put(WaybackConstants.REQUEST_REMOTE_USER, emptyIfNull(httpRequest + put(WaybackRequest.REQUEST_REMOTE_USER, emptyIfNull(httpRequest .getRemoteUser())); - put(WaybackConstants.REQUEST_LOCALE_LANG,getUserLocale(httpRequest)); + put(WaybackRequest.REQUEST_LOCALE_LANG,getUserLocale(httpRequest)); Cookie[] cookies = httpRequest.getCookies(); if(cookies != null) { @@ -264,32 +390,32 @@ */ public void fixup(HttpServletRequest httpRequest) { extractHttpRequestInfo(httpRequest); - String startDate = get(WaybackConstants.REQUEST_START_DATE); - String endDate = get(WaybackConstants.REQUEST_END_DATE); - String exactDate = get(WaybackConstants.REQUEST_EXACT_DATE); - String partialDate = get(WaybackConstants.REQUEST_DATE); + String startDate = get(WaybackRequest.REQUEST_START_DATE); + String endDate = get(WaybackRequest.REQUEST_END_DATE); + String exactDate = get(WaybackRequest.REQUEST_EXACT_DATE); + String partialDate = get(WaybackRequest.REQUEST_DATE); if (partialDate == null) { partialDate = ""; } if (startDate == null || startDate.length() == 0) { - put(WaybackConstants.REQUEST_START_DATE, Timestamp + put(WaybackRequest.REQUEST_START_DATE, Timestamp .padStartDateStr(partialDate)); } else if (startDate.length() < 14) { - put(WaybackConstants.REQUEST_START_DATE, Timestamp + put(WaybackRequest.REQUEST_START_DATE, Timestamp .padStartDateStr(startDate)); } if (endDate == null || endDate.length() == 0) { - put(WaybackConstants.REQUEST_END_DATE, Timestamp + put(WaybackRequest.REQUEST_END_DATE, Timestamp .padEndDateStr(partialDate)); } else if (endDate.length() < 14) { - put(WaybackConstants.REQUEST_END_DATE, Timestamp + put(WaybackRequest.REQUEST_END_DATE, Timestamp .padEndDateStr(endDate)); } if (exactDate == null || exactDate.length() == 0) { - put(WaybackConstants.REQUEST_EXACT_DATE, Timestamp + put(WaybackRequest.REQUEST_EXACT_DATE, Timestamp .padEndDateStr(partialDate)); } else if (exactDate.length() < 14) { - put(WaybackConstants.REQUEST_EXACT_DATE, Timestamp + put(WaybackRequest.REQUEST_EXACT_DATE, Timestamp .padEndDateStr(exactDate)); } } @@ -359,8 +485,8 @@ } // If its not http, next line throws exception. TODO: Fix. UURI requestURI = UURIFactory.getInstance(urlStr); - put(WaybackConstants.REQUEST_URL_CLEANED, requestURI.toString()); - put(WaybackConstants.REQUEST_URL, urlStr); + put(WaybackRequest.REQUEST_URL_CLEANED, requestURI.toString()); + put(WaybackRequest.REQUEST_URL, urlStr); } /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayDispatcher.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayDispatcher.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayDispatcher.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -26,7 +26,6 @@ import org.archive.wayback.ReplayDispatcher; import org.archive.wayback.ReplayRenderer; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.Resource; import org.archive.wayback.core.WaybackRequest; @@ -60,7 +59,7 @@ // 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: - String reqDateStr = wbRequest.get(WaybackConstants.REQUEST_EXACT_DATE); + String reqDateStr = wbRequest.get(WaybackRequest.REQUEST_EXACT_DATE); String resDateStr = result.getCaptureTimestamp(); if((resDateStr.length() > reqDateStr.length()) || !resDateStr.equals(reqDateStr.substring(0, resDateStr.length()))) { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.httpclient.URIException; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; @@ -90,9 +89,9 @@ String requestUrl = getRequestString(host,httpRequest); - wbRequest.put(WaybackConstants.REQUEST_EXACT_DATE, dateStr); - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_REPLAY_QUERY); + wbRequest.put(WaybackRequest.REQUEST_EXACT_DATE, dateStr); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_REPLAY_QUERY); try { wbRequest.setRequestUrl(requestUrl); } catch (URIException e) { @@ -114,10 +113,10 @@ startDate = Timestamp.parseBefore(dateStr).getDateStr(); endDate = Timestamp.parseAfter(dateStr).getDateStr(); } - wbRequest.put(WaybackConstants.REQUEST_START_DATE,startDate); - wbRequest.put(WaybackConstants.REQUEST_END_DATE,endDate); - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_URL_QUERY); + wbRequest.put(WaybackRequest.REQUEST_START_DATE,startDate); + wbRequest.put(WaybackRequest.REQUEST_END_DATE,endDate); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_URL_QUERY); String requestUrl = getRequestString(host,httpRequest); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/BaseExceptionRenderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/BaseExceptionRenderer.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/BaseExceptionRenderer.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -34,7 +34,6 @@ import javax.servlet.http.HttpServletResponse; import org.archive.wayback.ExceptionRenderer; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.UIResults; import org.archive.wayback.core.WaybackRequest; @@ -69,13 +68,13 @@ if (wbRequest == null) { return false; } - String referer = wbRequest.get(WaybackConstants.REQUEST_REFERER_URL); + String referer = wbRequest.get(WaybackRequest.REQUEST_REFERER_URL); return (referer != null && referer.length() > 0); } protected boolean requestIsImage(HttpServletRequest httpRequest, WaybackRequest wbRequest) { - String requestUrl = wbRequest.get(WaybackConstants.REQUEST_URL); + String requestUrl = wbRequest.get(WaybackRequest.REQUEST_URL); if (requestUrl == null) return false; Matcher matcher = IMAGE_REGEX.matcher(requestUrl); @@ -85,14 +84,14 @@ protected boolean requestIsJavascript(HttpServletRequest httpRequest, WaybackRequest wbRequest) { - String requestUrl = wbRequest.get(WaybackConstants.REQUEST_URL); + String requestUrl = wbRequest.get(WaybackRequest.REQUEST_URL); return (requestUrl != null) && requestUrl.endsWith(".js"); } protected boolean requestIsCSS(HttpServletRequest httpRequest, WaybackRequest wbRequest) { - String requestUrl = wbRequest.get(WaybackConstants.REQUEST_URL); + String requestUrl = wbRequest.get(WaybackRequest.REQUEST_URL); return (requestUrl != null) && requestUrl.endsWith(".css"); } @@ -104,7 +103,7 @@ if(wbRequest.isQueryRequest()) { - if(wbRequest.containsKey(WaybackConstants.REQUEST_XML_DATA)) { + if(wbRequest.containsKey(WaybackRequest.REQUEST_XML_DATA)) { jspPath = xmlErrorJsp; } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/LiveWebCache.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/LiveWebCache.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/LiveWebCache.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -33,14 +33,12 @@ import org.archive.io.arc.ARCLocation; import org.archive.io.arc.ARCRecord; import org.archive.wayback.UrlCanonicalizer; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Resource; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.SearchResults; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.exception.AnchorWindowTooSmallException; import org.archive.wayback.exception.LiveDocumentNotAvailableException; import org.archive.wayback.exception.ResourceNotInArchiveException; import org.archive.wayback.exception.WaybackException; @@ -82,9 +80,9 @@ boolean bUseOlder) throws URIException { WaybackRequest req = new WaybackRequest(); req.setRequestUrl(url.toString()); - req.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_CLOSEST_QUERY); - req.put(WaybackConstants.REQUEST_EXACT_DATE, + req.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_CLOSEST_QUERY); + req.put(WaybackRequest.REQUEST_EXACT_DATE, Timestamp.currentTimestamp().getDateStr()); Timestamp earliest = null; if(bUseOlder) { @@ -93,11 +91,11 @@ Date d = new Date(System.currentTimeMillis() - maxCacheMS); earliest = new Timestamp(d); } - req.put(WaybackConstants.REQUEST_START_DATE,earliest.getDateStr()); + req.put(WaybackRequest.REQUEST_START_DATE,earliest.getDateStr()); // for now, assume all live web requests are only satisfiable by the // exact host -- no massaging. - req.put(WaybackConstants.REQUEST_EXACT_HOST_ONLY, - WaybackConstants.REQUEST_YES); + req.put(WaybackRequest.REQUEST_EXACT_HOST_ONLY, + WaybackRequest.REQUEST_YES); return req; } @@ -166,12 +164,7 @@ e.printStackTrace(); throw new IOException(e.getMessage()); } - CaptureSearchResult result; - try { - result = results.getClosest(wbRequest,false); - } catch (AnchorWindowTooSmallException e) { - throw new ResourceNotInArchiveException("Not In archive.."); - } + CaptureSearchResult result = results.getClosest(wbRequest); if(result != null) { if(isForgedFailedSearchResult(result)) { if(isForgedFailRecentEnough(result)) { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -30,7 +30,6 @@ import org.apache.commons.httpclient.URIException; import org.archive.util.InetAddressUtil; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; import org.archive.wayback.requestparser.BaseRequestParser; @@ -92,8 +91,8 @@ e.printStackTrace(); return null; } - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_REPLAY_QUERY); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_REPLAY_QUERY); wbRequest.setResultsPerPage(maxRecords); return wbRequest; } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletRequest; import org.archive.wayback.RequestParser; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; @@ -71,7 +70,7 @@ String id = httpRequest.getHeader("Proxy-Id"); if (id == null) id = httpRequest.getRemoteAddr(); - wbRequest.put(WaybackConstants.REQUEST_EXACT_DATE, Timestamp + wbRequest.put(WaybackRequest.REQUEST_EXACT_DATE, Timestamp .getTimestampForId(httpRequest.getContextPath(), id)); wbRequest.fixup(httpRequest); } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -33,7 +33,6 @@ import org.archive.wayback.QueryRenderer; import org.archive.wayback.ResultURIConverter; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.UrlSearchResults; import org.archive.wayback.core.WaybackRequest; @@ -76,7 +75,7 @@ UICaptureQueryResults uiResults = new UICaptureQueryResults(httpRequest, wbRequest, results, uriConverter); String jsp = captureJsp; - if(wbRequest.containsKey(WaybackConstants.REQUEST_XML_DATA)) { + if(wbRequest.containsKey(WaybackRequest.REQUEST_XML_DATA)) { jsp = xmlCaptureJsp; } @@ -96,7 +95,7 @@ UIUrlQueryResults uiResults = new UIUrlQueryResults(httpRequest, wbRequest, results, uriConverter); String jsp = urlJsp; - if(wbRequest.containsKey(WaybackConstants.REQUEST_XML_DATA)) { + if(wbRequest.containsKey(WaybackRequest.REQUEST_XML_DATA)) { jsp = xmlUrlJsp; } 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-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/UIQueryResults.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -28,7 +28,6 @@ import javax.servlet.http.HttpServletRequest; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.ResultURIConverter; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.SearchResults; @@ -80,11 +79,11 @@ WaybackRequest wbRequest, SearchResults results, ResultURIConverter uriConverter) { super(wbRequest,uriConverter); - this.searchUrl = wbRequest.get(WaybackConstants.REQUEST_URL); + this.searchUrl = wbRequest.get(WaybackRequest.REQUEST_URL); this.startTimestamp = Timestamp.parseBefore(results. - getFilter(WaybackConstants.REQUEST_START_DATE)); + getFilter(WaybackRequest.REQUEST_START_DATE)); this.endTimestamp = Timestamp.parseAfter(results.getFilter( - WaybackConstants.REQUEST_END_DATE)); + WaybackRequest.REQUEST_END_DATE)); this.resultsReturned = results.getReturnedCount(); this.resultsMatching = results.getMatchingCount(); @@ -92,7 +91,7 @@ this.firstResult = results.getFirstReturned() + 1; this.lastResult = ((firstResult - 1) + resultsReturned); this.exactRequestedTimestamp = Timestamp.parseAfter( - wbRequest.get(WaybackConstants.REQUEST_EXACT_DATE)); + wbRequest.get(WaybackRequest.REQUEST_EXACT_DATE)); // calculate total pages: numPages = (int) Math.ceil((double)resultsMatching/(double)resultsPerPage); curPage = (int) Math.floor(((double)(firstResult-1))/(double)resultsPerPage) + 1; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitionsFactory.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitionsFactory.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitionsFactory.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -29,7 +29,6 @@ import java.util.Date; import org.archive.util.ArchiveUtils; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; @@ -59,9 +58,9 @@ public static ArrayList<ResultsPartition> get(CaptureSearchResults results, WaybackRequest wbRequest) { Timestamp startTS = Timestamp.parseBefore(results.getFilter( - WaybackConstants.REQUEST_START_DATE)); + WaybackRequest.REQUEST_START_DATE)); Timestamp endTS = Timestamp.parseAfter(results.getFilter( - WaybackConstants.REQUEST_END_DATE)); + WaybackRequest.REQUEST_END_DATE)); String rsd = startTS.getDateStr(); String red = endTS.getDateStr(); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsTimelinePartitionsFactory.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsTimelinePartitionsFactory.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsTimelinePartitionsFactory.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -28,7 +28,6 @@ import java.util.Calendar; import org.archive.util.ArchiveUtils; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; @@ -145,15 +144,15 @@ int last = Timestamp.parseAfter(results.getLastResultTimestamp()).sse(); int diff = last - first; if(diff < MAX_HOUR_SECONDS) { - return WaybackConstants.REQUEST_RESOLUTION_HOURS; + return WaybackRequest.REQUEST_RESOLUTION_HOURS; } else if(diff < MAX_DAY_SECONDS) { - return WaybackConstants.REQUEST_RESOLUTION_DAYS; + return WaybackRequest.REQUEST_RESOLUTION_DAYS; } else if(diff < MAX_MONTH_SECONDS) { - return WaybackConstants.REQUEST_RESOLUTION_MONTHS; + return WaybackRequest.REQUEST_RESOLUTION_MONTHS; } else if(diff < MAX_TWO_MONTH_SECONDS) { - return WaybackConstants.REQUEST_RESOLUTION_TWO_MONTHS; + return WaybackRequest.REQUEST_RESOLUTION_TWO_MONTHS; } - return WaybackConstants.REQUEST_RESOLUTION_YEARS; + return WaybackRequest.REQUEST_RESOLUTION_YEARS; } private static ArrayList<ResultsPartition> get(ResultsPartitioner @@ -167,7 +166,7 @@ int totalPartitions = (partitionCount * 2) + 1; // total # of partitions // first calculate the "center" based on the exact request date: - String reqDate = results.getFilter(WaybackConstants.REQUEST_EXACT_DATE); + String reqDate = results.getFilter(WaybackRequest.REQUEST_EXACT_DATE); Calendar centerCal = partitioner.dateStrToCalendar(reqDate); partitioner.alignStart(centerCal); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletRequest; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.webapp.AccessPoint; @@ -61,15 +60,15 @@ String base = wbContext.translateRequestPath(httpRequest); if(base.startsWith(REPLAY_BASE)) { - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_REPLAY_QUERY); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_REPLAY_QUERY); } else if(base.startsWith(QUERY_BASE)) { - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_URL_QUERY); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_URL_QUERY); } else if(base.startsWith(XQUERY_BASE)){ - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_URL_QUERY); - wbRequest.put(WaybackConstants.REQUEST_XML_DATA,"1"); + wbRequest.put(WaybackRequest.REQUEST_TYPE, + WaybackRequest.REQUEST_URL_QUERY); + wbRequest.put(WaybackRequest.REQUEST_XML_DATA,"1"); } else { return null; @@ -86,12 +85,12 @@ String val = getMapParam(queryMap,key); wbRequest.put(key,val); } - if(wbRequest.get(WaybackConstants.REQUEST_START_DATE) == null) { - wbRequest.put(WaybackConstants.REQUEST_START_DATE, + if(wbRequest.get(WaybackRequest.REQUEST_START_DATE) == null) { + wbRequest.put(WaybackRequest.REQUEST_START_DATE, getEarliestTimestamp()); } - if(wbRequest.get(WaybackConstants.REQUEST_END_DATE) == null) { - wbRequest.put(WaybackConstants.REQUEST_END_DATE, + if(wbRequest.get(WaybackRequest.REQUEST_END_DATE) == null) { + wbRequest.put(WaybackRequest.REQUEST_END_DATE, getLatestTimestamp()); } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java 2008-07-07 21:53:54 UTC (rev 2416) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java 2008-07-07 21:57:30 UTC (rev 2417) @@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletRequest; -import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; import org.archive.wayback.webapp.AccessPoint; @@ -87,15 +86,15 @@ String base = wbContext.translateRequestPath(httpRequest); if(base... [truncated message content] |
From: <bra...@us...> - 2008-07-09 00:30:06
|
Revision: 2424 http://archive-access.svn.sourceforge.net/archive-access/?rev=2424&view=rev Author: bradtofel Date: 2008-07-08 17:30:15 -0700 (Tue, 08 Jul 2008) Log Message: ----------- FEATURE: added Shutdownable interface, which all worker threads now implement. added configurable list of Shutdownable objects to WaybackCollection, which will be shutdown() when the WaybackCollection is shutdown() Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/LocalResourceIndexUpdater.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexQueueUpdater.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexWorker.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/ResourceFileLocationDBUpdater.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/resourcefile/ResourceFileSourceUpdater.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackCollection.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/Shutdownable.java Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/Shutdownable.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/Shutdownable.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/Shutdownable.java 2008-07-09 00:30:15 UTC (rev 2424) @@ -0,0 +1,37 @@ +/* Shutdownable + * + * $Id$ + * + * Created on 4:54:13 PM Jul 8, 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; + +import java.io.IOException; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public interface Shutdownable { + public void shutdown() throws IOException; +} Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/LocalResourceIndexUpdater.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/LocalResourceIndexUpdater.java 2008-07-09 00:26:19 UTC (rev 2423) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/LocalResourceIndexUpdater.java 2008-07-09 00:30:15 UTC (rev 2424) @@ -28,6 +28,7 @@ import java.io.IOException; import java.util.logging.Logger; +import org.archive.wayback.Shutdownable; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.exception.ConfigurationException; import org.archive.wayback.resourceindex.LocalResourceIndex; @@ -48,7 +49,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class LocalResourceIndexUpdater { +public class LocalResourceIndexUpdater implements Shutdownable { /** * Logger for this class */ @@ -71,7 +72,7 @@ * Thread object of update thread -- also is flag indicating if the thread * has already been started. Access to it is synchronized. */ - private Thread updateThread = null; + private Thread thread = null; /** * start the background index merging thread @@ -88,10 +89,21 @@ throw new ConfigurationException("No incoming"); } if(runInterval > 0) { - updateThread = new UpdateThread(this,runInterval); - updateThread.start(); + thread = new UpdateThread(this,runInterval); + thread.start(); } } + + public void shutdown() { + if(thread != null) { + thread.interrupt(); + try { + thread.join(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } private boolean mergeFile(File cdxFile) { boolean added = false; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexQueueUpdater.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexQueueUpdater.java 2008-07-09 00:26:19 UTC (rev 2423) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexQueueUpdater.java 2008-07-09 00:30:15 UTC (rev 2424) @@ -31,6 +31,7 @@ import java.io.PrintWriter; import java.util.logging.Logger; +import org.archive.wayback.Shutdownable; import org.archive.wayback.resourcestore.locationdb.ResourceFileLocationDB; import org.archive.wayback.util.CloseableIterator; import org.archive.wayback.util.DirMaker; @@ -45,7 +46,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class IndexQueueUpdater { +public class IndexQueueUpdater implements Shutdownable { private static final Logger LOGGER = Logger.getLogger(IndexQueueUpdater.class.getName()); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexWorker.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexWorker.java 2008-07-09 00:26:19 UTC (rev 2423) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/indexer/IndexWorker.java 2008-07-09 00:30:15 UTC (rev 2424) @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.logging.Logger; +import org.archive.wayback.Shutdownable; import org.archive.wayback.UrlCanonicalizer; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.resourceindex.updater.IndexClient; @@ -45,7 +46,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class IndexWorker { +public class IndexWorker implements Shutdownable { private static final Logger LOGGER = Logger.getLogger(IndexWorker.class.getName()); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/ResourceFileLocationDBUpdater.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/ResourceFileLocationDBUpdater.java 2008-07-09 00:26:19 UTC (rev 2423) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/ResourceFileLocationDBUpdater.java 2008-07-09 00:30:15 UTC (rev 2424) @@ -29,6 +29,7 @@ import java.util.Iterator; import java.util.logging.Logger; +import org.archive.wayback.Shutdownable; import org.archive.wayback.resourcestore.resourcefile.ResourceFileList; import org.archive.wayback.resourcestore.resourcefile.ResourceFileLocation; import org.archive.wayback.util.DirMaker; @@ -52,7 +53,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class ResourceFileLocationDBUpdater { +public class ResourceFileLocationDBUpdater implements Shutdownable { private static final Logger LOGGER = Logger.getLogger(ResourceFileLocationDBUpdater.class.getName()); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/resourcefile/ResourceFileSourceUpdater.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/resourcefile/ResourceFileSourceUpdater.java 2008-07-09 00:26:19 UTC (rev 2423) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/resourcefile/ResourceFileSourceUpdater.java 2008-07-09 00:30:15 UTC (rev 2424) @@ -29,6 +29,7 @@ import java.util.List; import java.util.logging.Logger; +import org.archive.wayback.Shutdownable; import org.archive.wayback.resourcestore.locationdb.ResourceFileLocationDBUpdater; import org.archive.wayback.util.DirMaker; @@ -44,7 +45,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class ResourceFileSourceUpdater { +public class ResourceFileSourceUpdater implements Shutdownable { private static final Logger LOGGER = Logger.getLogger(ResourceFileSourceUpdater.class.getName()); private List<ResourceFileSource> sources = null; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackCollection.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackCollection.java 2008-07-09 00:26:19 UTC (rev 2423) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackCollection.java 2008-07-09 00:30:15 UTC (rev 2424) @@ -25,9 +25,11 @@ package org.archive.wayback.webapp; import java.io.IOException; +import java.util.List; import org.archive.wayback.ResourceIndex; import org.archive.wayback.ResourceStore; +import org.archive.wayback.Shutdownable; import org.archive.wayback.exception.ConfigurationException; /** @@ -40,7 +42,27 @@ public class WaybackCollection { private ResourceStore resourceStore = null; private ResourceIndex resourceIndex = null; + private List<Shutdownable> shutdownables = null; private boolean shutdownDone = false; + + public void shutdown() throws IOException { + if(shutdownDone) { + return; + } + if(resourceStore != null) { + resourceStore.shutdown(); + } + if(resourceIndex != null) { + resourceIndex.shutdown(); + } + if(shutdownables != null) { + for(Shutdownable s : shutdownables) { + s.shutdown(); + } + } + shutdownDone = true; + } + public ResourceStore getResourceStore() throws ConfigurationException { if(resourceStore == null) { throw new ConfigurationException("No resourceStore declared"); @@ -59,16 +81,12 @@ public void setResourceIndex(ResourceIndex resourceIndex) { this.resourceIndex = resourceIndex; } - public void shutdown() throws IOException { - if(shutdownDone) { - return; - } - if(resourceStore != null) { - resourceStore.shutdown(); - } - if(resourceIndex != null) { - resourceIndex.shutdown(); - } - shutdownDone = true; + + public List<Shutdownable> getShutdownables() { + return shutdownables; } + + public void setShutdownables(List<Shutdownable> shutdownables) { + this.shutdownables = shutdownables; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-07-10 18:41:47
|
Revision: 2425 http://archive-access.svn.sourceforge.net/archive-access/?rev=2425&view=rev Author: bradtofel Date: 2008-07-10 11:41:53 -0700 (Thu, 10 Jul 2008) Log Message: ----------- REFACTOR: moved org.archive.wayback.bdb.* to org.archive.wayback.util.bdb.* Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionAuthority.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBRecordToSearchResultAdapter.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/SearchResultToBDBRecordAdapter.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/BDBResourceFileLocationDB.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecord.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecordIterator.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecordSet.java Removed Paths: ------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecord.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordIterator.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordSet.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionAuthority.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionAuthority.java 2008-07-09 00:30:15 UTC (rev 2424) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionAuthority.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -27,10 +27,10 @@ import java.util.ArrayList; import org.apache.commons.httpclient.URIException; -import org.archive.wayback.bdb.BDBRecord; -import org.archive.wayback.bdb.BDBRecordSet; -import org.archive.wayback.bdb.BDBRecordIterator; import org.archive.wayback.surt.SURTTokenizer; +import org.archive.wayback.util.bdb.BDBRecord; +import org.archive.wayback.util.bdb.BDBRecordIterator; +import org.archive.wayback.util.bdb.BDBRecordSet; import com.sleepycat.je.DatabaseException; Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecord.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecord.java 2008-07-09 00:30:15 UTC (rev 2424) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecord.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -1,58 +0,0 @@ -/* BDBRecord - * - * $Id$ - * - * Created on 1:43:15 PM May 15, 2006. - * - * Copyright (C) 2006 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.bdb; - -import com.sleepycat.je.DatabaseEntry; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class BDBRecord { - private DatabaseEntry key; - private DatabaseEntry value; - /** - * @param key - * @param value - */ - public BDBRecord(DatabaseEntry key, DatabaseEntry value) { - this.key = key; - this.value = value; - } - /** - * @return Returns the key. - */ - public DatabaseEntry getKey() { - return key; - } - /** - * @return Returns the value. - */ - public DatabaseEntry getValue() { - return value; - } -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordIterator.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordIterator.java 2008-07-09 00:30:15 UTC (rev 2424) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordIterator.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -1,155 +0,0 @@ -/* BDBRecordIterator - * - * $Id$ - * - * Created on 1:27:24 PM May 15, 2006. - * - * Copyright (C) 2006 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.bdb; - -import java.util.NoSuchElementException; - -import org.archive.wayback.util.CloseableIterator; - -import com.sleepycat.je.Cursor; -import com.sleepycat.je.DatabaseEntry; -import com.sleepycat.je.DatabaseException; -import com.sleepycat.je.LockMode; -import com.sleepycat.je.OperationStatus; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class BDBRecordIterator implements CloseableIterator<BDBRecord> { - - DatabaseEntry key; - DatabaseEntry value; - boolean hitLast; - boolean gotNext; - Cursor cursor; - boolean backward; - BDBRecord record; - - /** - * @param cursor - * @param search - * @throws DatabaseException - */ - public BDBRecordIterator(Cursor cursor,String search) - throws DatabaseException { - initialize(cursor,search,false); - } - /** - * @param cursor - * @param search - * @param backward - * @throws DatabaseException - */ - public BDBRecordIterator(Cursor cursor,String search,boolean backward) - throws DatabaseException { - initialize(cursor,search,backward); - } - private void initialize(Cursor cursor,String search, boolean backward) - throws DatabaseException { - this.cursor = cursor; - this.backward = backward; - key = new DatabaseEntry(); - value = new DatabaseEntry(); - key.setData(search.getBytes()); - key.setPartial(false); - OperationStatus status = cursor.getSearchKeyRange(key, value, - LockMode.DEFAULT); - if(backward && (status == OperationStatus.SUCCESS)) { - // if we are in reverse, immediately back up one record: - status = cursor.getPrev(key, value, LockMode.DEFAULT); - } - if(status == OperationStatus.SUCCESS) { - gotNext = true; - } - record = new BDBRecord(key,value); - } - - /* (non-Javadoc) - * @see java.util.Iterator#hasNext() - */ - public boolean hasNext() { - if(hitLast) { - return false; - } - if(cursor == null) { - return false; - } - if(!gotNext) { - OperationStatus status; - // attempt to get the next: - try { - if(backward) { - status = cursor.getPrev(key, value, LockMode.DEFAULT); - } else { - status = cursor.getNext(key, value, LockMode.DEFAULT); - } - if(status == OperationStatus.SUCCESS) { - gotNext = true; - } else { - close(); - } - } catch (DatabaseException e) { - // SLOP: throw a runtime? - e.printStackTrace(); - close(); - } - } - return gotNext; - } - - public void close() { - if(!hitLast) { - hitLast = true; - try { - cursor.close(); - } catch (DatabaseException e) { - // TODO what to do? - // let's just eat it for now.. - e.printStackTrace(); - } - } - } - - /* (non-Javadoc) - * @see java.util.Iterator#next() - */ - public BDBRecord next() { - if(!gotNext) { - throw new NoSuchElementException(); - } - gotNext = false; - return record; - } - - /* (non-Javadoc) - * @see java.util.Iterator#remove() - */ - public void remove() { - throw new UnsupportedOperationException(); - } -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordSet.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordSet.java 2008-07-09 00:30:15 UTC (rev 2424) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordSet.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -1,263 +0,0 @@ -/* BDBRecordGenerator - * - * $Id$ - * - * Created on 1:22:39 PM May 15, 2006. - * - * Copyright (C) 2006 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.bdb; - -import java.io.File; -import java.io.UnsupportedEncodingException; -import java.util.Iterator; - -import com.sleepycat.je.Cursor; -import com.sleepycat.je.Database; -import com.sleepycat.je.DatabaseConfig; -import com.sleepycat.je.DatabaseEntry; -import com.sleepycat.je.DatabaseException; -import com.sleepycat.je.Environment; -import com.sleepycat.je.EnvironmentConfig; -import com.sleepycat.je.LockMode; -import com.sleepycat.je.OperationStatus; -import com.sleepycat.je.Transaction; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class BDBRecordSet { - /** - * Maximum BDBJE file size - */ - private final static String JE_LOG_FILEMAX = "256000000"; - /** - * path to directory containing the BDBJE files - */ - private String path; - - /** - * name of BDBJE db within the path directory - */ - private String dbName; - - /** - * BDBJE Environment - */ - Environment env = null; - - /** - * BDBJE Database - */ - Database db = null; - - /** - * @param thePath Directory where BDBJE files are stored - * @param theDbName Name of files in thePath - * @throws DatabaseException - */ - public void initializeDB(final String thePath, final String theDbName) - throws DatabaseException { - path = thePath; - dbName = theDbName; - - EnvironmentConfig environmentConfig = new EnvironmentConfig(); - environmentConfig.setAllowCreate(true); - environmentConfig.setTransactional(true); - environmentConfig.setConfigParam("je.log.fileMax",JE_LOG_FILEMAX); - File file = new File(path); - if(!file.isDirectory()) { - if(!file.mkdirs()) { - throw new DatabaseException("failed mkdirs(" + path + ")"); - } - } - env = new Environment(file, environmentConfig); - DatabaseConfig databaseConfig = new DatabaseConfig(); - databaseConfig.setAllowCreate(true); - databaseConfig.setTransactional(true); - // perform other database configurations - - db = env.openDatabase(null, dbName, databaseConfig); - } - - /** - * shut down the BDB. - * - * @throws DatabaseException - */ - public synchronized void shutdownDB() throws DatabaseException { - - if (db != null) { - db.close(); - db = null; - } - - if (env != null) { - env.close(); - env = null; - } - } - - /** - * @param s - * @return byte array representation of String s in UTF-8 - */ - public static byte[] stringToBytes(String s) { - try { - return s.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - // no UTF-8, huh? - e.printStackTrace(); - return s.getBytes(); - } - } - /** - * @param ba - * @return String of UTF-8 encoded bytes ba - */ - public static String bytesToString(byte[] ba) { - try { - return new String(ba,"UTF-8"); - } catch (UnsupportedEncodingException e) { - // not likely.. - e.printStackTrace(); - return new String(ba); - } - } - - /** - * @param startKey - * @return iterator for BDBRecords - * @throws DatabaseException - */ - public BDBRecordIterator recordIterator(final String startKey) - throws DatabaseException { - return recordIterator(startKey,true); - } - /** - * @param startKey - * @param forward - * @return iterator for BDBRecords - * @throws DatabaseException - */ - public BDBRecordIterator recordIterator(final String startKey, - final boolean forward) throws DatabaseException { - Cursor cursor = db.openCursor(null, null); - return new BDBRecordIterator(cursor,startKey,!forward); - } - - /** - * @param itr - */ - public void insertRecords(final Iterator<BDBRecord> itr) { - OperationStatus status = null; - try { - Transaction txn = env.beginTransaction(null, null); - try { - Cursor cursor = db.openCursor(txn, null); - while (itr.hasNext()) { - BDBRecord record = (BDBRecord) itr.next(); - status = cursor.put(record.getKey(), record.getValue()); - if (status != OperationStatus.SUCCESS) { - throw new RuntimeException("put() non-success status"); - } - } - cursor.close(); - txn.commit(); - } catch (DatabaseException e) { - if(txn != null) { - txn.abort(); - } - e.printStackTrace(); - } - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - /** - * persistantly store key-value pair - * @param keyStr - * @param valueStr - * @throws DatabaseException - */ - public void put(String keyStr, String valueStr) throws DatabaseException { - DatabaseEntry key = new DatabaseEntry(stringToBytes(keyStr)); - DatabaseEntry data = new DatabaseEntry(stringToBytes(valueStr)); - db.put(null, key, data); - } - - /** - * retrieve the value assoicated with keyStr from persistant storage - * @param keyStr - * @return String value associated with key, or null if no key is found - * or an error occurs - * @throws DatabaseException - */ - public String get(String keyStr) throws DatabaseException { - String result = null; - DatabaseEntry key = new DatabaseEntry(stringToBytes(keyStr)); - DatabaseEntry data = new DatabaseEntry(); - if (db.get(null, key, data, LockMode.DEFAULT) - == OperationStatus.SUCCESS) { - - result = bytesToString(data.getData()); - } - return result; - } - - /** - * @param keyStr - * @throws DatabaseException - */ - public void delete(String keyStr) throws DatabaseException { - db.delete(null,new DatabaseEntry(stringToBytes(keyStr))); - } - - /** - * @return Returns the dbName. - */ - public String getDbName() { - return dbName; - } - - /** - * @return Returns the path. - */ - public String getPath() { - return path; - } - - /** - * @param path the path to set - */ - public void setPath(String path) { - this.path = path; - } - - /** - * @param dbName the dbName to set - */ - public void setDbName(String dbName) { - this.dbName = dbName; - } -} Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBIndex.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBIndex.java 2008-07-09 00:30:15 UTC (rev 2424) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBIndex.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -31,8 +31,6 @@ import java.util.Iterator; import org.archive.wayback.UrlCanonicalizer; -import org.archive.wayback.bdb.BDBRecord; -import org.archive.wayback.bdb.BDBRecordSet; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.exception.ConfigurationException; import org.archive.wayback.exception.ResourceIndexNotAvailableException; @@ -42,6 +40,8 @@ import org.archive.wayback.util.AdaptedIterator; import org.archive.wayback.util.Adapter; import org.archive.wayback.util.CloseableIterator; +import org.archive.wayback.util.bdb.BDBRecord; +import org.archive.wayback.util.bdb.BDBRecordSet; import org.archive.wayback.util.flatfile.RecordIterator; import org.archive.wayback.util.url.AggressiveUrlCanonicalizer; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBRecordToSearchResultAdapter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBRecordToSearchResultAdapter.java 2008-07-09 00:30:15 UTC (rev 2424) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBRecordToSearchResultAdapter.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -26,10 +26,10 @@ import java.io.UnsupportedEncodingException; -import org.archive.wayback.bdb.BDBRecord; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.resourceindex.cdx.CDXLineToSearchResultAdapter; import org.archive.wayback.util.Adapter; +import org.archive.wayback.util.bdb.BDBRecord; /** * Adapter that converts a BDBRecord into a SearchResult Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/SearchResultToBDBRecordAdapter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/SearchResultToBDBRecordAdapter.java 2008-07-09 00:30:15 UTC (rev 2424) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/SearchResultToBDBRecordAdapter.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -28,10 +28,10 @@ import org.apache.commons.httpclient.URIException; import org.archive.wayback.UrlCanonicalizer; -import org.archive.wayback.bdb.BDBRecord; -import org.archive.wayback.bdb.BDBRecordSet; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.util.Adapter; +import org.archive.wayback.util.bdb.BDBRecord; +import org.archive.wayback.util.bdb.BDBRecordSet; import com.sleepycat.je.DatabaseEntry; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/BDBResourceFileLocationDB.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/BDBResourceFileLocationDB.java 2008-07-09 00:30:15 UTC (rev 2424) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/locationdb/BDBResourceFileLocationDB.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -28,10 +28,10 @@ import java.io.IOException; import java.io.InputStreamReader; -import org.archive.wayback.bdb.BDBRecordSet; import org.archive.wayback.resourcestore.locationdb.ResourceFileLocationDB; import org.archive.wayback.resourcestore.locationdb.ResourceFileLocationDBLog; import org.archive.wayback.util.CloseableIterator; +import org.archive.wayback.util.bdb.BDBRecordSet; import com.sleepycat.je.DatabaseException; Copied: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecord.java (from rev 2418, trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecord.java) =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecord.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecord.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -0,0 +1,58 @@ +/* BDBRecord + * + * $Id$ + * + * Created on 1:43:15 PM May 15, 2006. + * + * Copyright (C) 2006 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.util.bdb; + +import com.sleepycat.je.DatabaseEntry; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class BDBRecord { + private DatabaseEntry key; + private DatabaseEntry value; + /** + * @param key + * @param value + */ + public BDBRecord(DatabaseEntry key, DatabaseEntry value) { + this.key = key; + this.value = value; + } + /** + * @return Returns the key. + */ + public DatabaseEntry getKey() { + return key; + } + /** + * @return Returns the value. + */ + public DatabaseEntry getValue() { + return value; + } +} Copied: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecordIterator.java (from rev 2418, trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordIterator.java) =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecordIterator.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecordIterator.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -0,0 +1,155 @@ +/* BDBRecordIterator + * + * $Id$ + * + * Created on 1:27:24 PM May 15, 2006. + * + * Copyright (C) 2006 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.util.bdb; + +import java.util.NoSuchElementException; + +import org.archive.wayback.util.CloseableIterator; + +import com.sleepycat.je.Cursor; +import com.sleepycat.je.DatabaseEntry; +import com.sleepycat.je.DatabaseException; +import com.sleepycat.je.LockMode; +import com.sleepycat.je.OperationStatus; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class BDBRecordIterator implements CloseableIterator<BDBRecord> { + + DatabaseEntry key; + DatabaseEntry value; + boolean hitLast; + boolean gotNext; + Cursor cursor; + boolean backward; + BDBRecord record; + + /** + * @param cursor + * @param search + * @throws DatabaseException + */ + public BDBRecordIterator(Cursor cursor,String search) + throws DatabaseException { + initialize(cursor,search,false); + } + /** + * @param cursor + * @param search + * @param backward + * @throws DatabaseException + */ + public BDBRecordIterator(Cursor cursor,String search,boolean backward) + throws DatabaseException { + initialize(cursor,search,backward); + } + private void initialize(Cursor cursor,String search, boolean backward) + throws DatabaseException { + this.cursor = cursor; + this.backward = backward; + key = new DatabaseEntry(); + value = new DatabaseEntry(); + key.setData(search.getBytes()); + key.setPartial(false); + OperationStatus status = cursor.getSearchKeyRange(key, value, + LockMode.DEFAULT); + if(backward && (status == OperationStatus.SUCCESS)) { + // if we are in reverse, immediately back up one record: + status = cursor.getPrev(key, value, LockMode.DEFAULT); + } + if(status == OperationStatus.SUCCESS) { + gotNext = true; + } + record = new BDBRecord(key,value); + } + + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() { + if(hitLast) { + return false; + } + if(cursor == null) { + return false; + } + if(!gotNext) { + OperationStatus status; + // attempt to get the next: + try { + if(backward) { + status = cursor.getPrev(key, value, LockMode.DEFAULT); + } else { + status = cursor.getNext(key, value, LockMode.DEFAULT); + } + if(status == OperationStatus.SUCCESS) { + gotNext = true; + } else { + close(); + } + } catch (DatabaseException e) { + // SLOP: throw a runtime? + e.printStackTrace(); + close(); + } + } + return gotNext; + } + + public void close() { + if(!hitLast) { + hitLast = true; + try { + cursor.close(); + } catch (DatabaseException e) { + // TODO what to do? + // let's just eat it for now.. + e.printStackTrace(); + } + } + } + + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ + public BDBRecord next() { + if(!gotNext) { + throw new NoSuchElementException(); + } + gotNext = false; + return record; + } + + /* (non-Javadoc) + * @see java.util.Iterator#remove() + */ + public void remove() { + throw new UnsupportedOperationException(); + } +} Copied: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecordSet.java (from rev 2418, trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/bdb/BDBRecordSet.java) =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecordSet.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBRecordSet.java 2008-07-10 18:41:53 UTC (rev 2425) @@ -0,0 +1,264 @@ +/* BDBRecordGenerator + * + * $Id$ + * + * Created on 1:22:39 PM May 15, 2006. + * + * Copyright (C) 2006 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.util.bdb; + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.util.Iterator; + + +import com.sleepycat.je.Cursor; +import com.sleepycat.je.Database; +import com.sleepycat.je.DatabaseConfig; +import com.sleepycat.je.DatabaseEntry; +import com.sleepycat.je.DatabaseException; +import com.sleepycat.je.Environment; +import com.sleepycat.je.EnvironmentConfig; +import com.sleepycat.je.LockMode; +import com.sleepycat.je.OperationStatus; +import com.sleepycat.je.Transaction; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class BDBRecordSet { + /** + * Maximum BDBJE file size + */ + private final static String JE_LOG_FILEMAX = "256000000"; + /** + * path to directory containing the BDBJE files + */ + private String path; + + /** + * name of BDBJE db within the path directory + */ + private String dbName; + + /** + * BDBJE Environment + */ + Environment env = null; + + /** + * BDBJE Database + */ + Database db = null; + + /** + * @param thePath Directory where BDBJE files are stored + * @param theDbName Name of files in thePath + * @throws DatabaseException + */ + public void initializeDB(final String thePath, final String theDbName) + throws DatabaseException { + path = thePath; + dbName = theDbName; + + EnvironmentConfig environmentConfig = new EnvironmentConfig(); + environmentConfig.setAllowCreate(true); + environmentConfig.setTransactional(true); + environmentConfig.setConfigParam("je.log.fileMax",JE_LOG_FILEMAX); + File file = new File(path); + if(!file.isDirectory()) { + if(!file.mkdirs()) { + throw new DatabaseException("failed mkdirs(" + path + ")"); + } + } + env = new Environment(file, environmentConfig); + DatabaseConfig databaseConfig = new DatabaseConfig(); + databaseConfig.setAllowCreate(true); + databaseConfig.setTransactional(true); + // perform other database configurations + + db = env.openDatabase(null, dbName, databaseConfig); + } + + /** + * shut down the BDB. + * + * @throws DatabaseException + */ + public synchronized void shutdownDB() throws DatabaseException { + + if (db != null) { + db.close(); + db = null; + } + + if (env != null) { + env.close(); + env = null; + } + } + + /** + * @param s + * @return byte array representation of String s in UTF-8 + */ + public static byte[] stringToBytes(String s) { + try { + return s.getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + // no UTF-8, huh? + e.printStackTrace(); + return s.getBytes(); + } + } + /** + * @param ba + * @return String of UTF-8 encoded bytes ba + */ + public static String bytesToString(byte[] ba) { + try { + return new String(ba,"UTF-8"); + } catch (UnsupportedEncodingException e) { + // not likely.. + e.printStackTrace(); + return new String(ba); + } + } + + /** + * @param startKey + * @return iterator for BDBRecords + * @throws DatabaseException + */ + public BDBRecordIterator recordIterator(final String startKey) + throws DatabaseException { + return recordIterator(startKey,true); + } + /** + * @param startKey + * @param forward + * @return iterator for BDBRecords + * @throws DatabaseException + */ + public BDBRecordIterator recordIterator(final String startKey, + final boolean forward) throws DatabaseException { + Cursor cursor = db.openCursor(null, null); + return new BDBRecordIterator(cursor,startKey,!forward); + } + + /** + * @param itr + */ + public void insertRecords(final Iterator<BDBRecord> itr) { + OperationStatus status = null; + try { + Transaction txn = env.beginTransaction(null, null); + try { + Cursor cursor = db.openCursor(txn, null); + while (itr.hasNext()) { + BDBRecord record = (BDBRecord) itr.next(); + status = cursor.put(record.getKey(), record.getValue()); + if (status != OperationStatus.SUCCESS) { + throw new RuntimeException("put() non-success status"); + } + } + cursor.close(); + txn.commit(); + } catch (DatabaseException e) { + if(txn != null) { + txn.abort(); + } + e.printStackTrace(); + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + /** + * persistantly store key-value pair + * @param keyStr + * @param valueStr + * @throws DatabaseException + */ + public void put(String keyStr, String valueStr) throws DatabaseException { + DatabaseEntry key = new DatabaseEntry(stringToBytes(keyStr)); + DatabaseEntry data = new DatabaseEntry(stringToBytes(valueStr)); + db.put(null, key, data); + } + + /** + * retrieve the value assoicated with keyStr from persistant storage + * @param keyStr + * @return String value associated with key, or null if no key is found + * or an error occurs + * @throws DatabaseException + */ + public String get(String keyStr) throws DatabaseException { + String result = null; + DatabaseEntry key = new DatabaseEntry(stringToBytes(keyStr)); + DatabaseEntry data = new DatabaseEntry(); + if (db.get(null, key, data, LockMode.DEFAULT) + == OperationStatus.SUCCESS) { + + result = bytesToString(data.getData()); + } + return result; + } + + /** + * @param keyStr + * @throws DatabaseException + */ + public void delete(String keyStr) throws DatabaseException { + db.delete(null,new DatabaseEntry(stringToBytes(keyStr))); + } + + /** + * @return Returns the dbName. + */ + public String getDbName() { + return dbName; + } + + /** + * @return Returns the path. + */ + public String getPath() { + return path; + } + + /** + * @param path the path to set + */ + public void setPath(String path) { + this.path = path; + } + + /** + * @param dbName the dbName to set + */ + public void setDbName(String dbName) { + this.dbName = dbName; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-07-15 01:27:32
|
Revision: 2446 http://archive-access.svn.sourceforge.net/archive-access/?rev=2446&view=rev Author: bradtofel Date: 2008-07-14 18:27:41 -0700 (Mon, 14 Jul 2008) Log Message: ----------- REFACTOR(major...): eliminating the various UIResults subclasses, which were confusing/poorly designed, in favor of a single, more flexible class that adapts to the various modes. removed many convenience methods, as the same capabilities should now be available on the underlying objects. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java 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/exception/BaseExceptionRenderer.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/HTMLPage.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java 2008-07-15 01:25:18 UTC (rev 2445) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java 2008-07-15 01:27:41 UTC (rev 2446) @@ -171,4 +171,25 @@ this.numRequested = numRequested; putFilter(RESULTS_REQUESTED, String.valueOf(numRequested)); } + + public int getNumPages() { + double resultsMatching = getMatchingCount(); + double resultsPerPage = getNumRequested(); + if(resultsPerPage == 0) { + return 1; + } + // calculate total pages: + int numPages = (int) Math.ceil(resultsMatching/resultsPerPage); + return numPages; + } + public int getCurPageNum() { + double resultsPerPage = getNumRequested(); + double firstResult = getFirstReturned(); + if(resultsPerPage == 0) { + return 1; + } + // calculate total pages: + int curPage = (int) Math.floor(firstResult/resultsPerPage) + 1; + return curPage; + } } 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-15 01:25:18 UTC (rev 2445) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java 2008-07-15 01:27:41 UTC (rev 2446) @@ -24,36 +24,106 @@ */ package org.archive.wayback.core; +import java.io.IOException; import java.util.Properties; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.archive.wayback.ResultURIConverter; +import org.archive.wayback.exception.WaybackException; import org.archive.wayback.util.StringFormatter; import org.archive.wayback.webapp.AccessPoint; /** + * Simple class which acts as the go-between between Java request handling code + * and .jsp files which actually draw various forms of results for end user + * consumption. Designed to be flexible enough to handle forward various types + * of data to the eventual .jsp files, and provides a handful of convenience + * method to simplify .jsp code. + * + * 5 main "forms" of this object: + * 1) Generic: has WaybackRequest, uriConverter + * 2) Exception: has WaybackRequest, uriConverter, WaybackException + * 3) CaptureQuery: has WaybackRequest, uriConverter, CaptureSearchResults + * 4) UrlQuery: has WaybackRequest, uriConverter, UrlSearchResults + * 5) Replay: has WaybackRequest, uriConverter, CaptureSearchResult, + * CaptureSearchResults, Resource * + * There are constructors to create each of these forms from the appropriate + * component objects. + * + * There is also a common method "forward()" which will store the UIResults + * object into an HttpServletRequest, for later retrieval by .jsp files. * + * There are static methods to extract each of these from an HttpServletRequest, + * which will also verify that the appropriate internal objects are present. + * These methods are intended to be used by the target .jsp files. + * + * * @author brad * @version $Date$, $Revision$ */ public class UIResults { private final static String FERRET_NAME = "ui-results"; + // usually present private WaybackRequest wbRequest; + // usually present private ResultURIConverter uriConverter; + // target .jsp (or static file) we forwarded to private String contentJsp = null; + // original URL that was received, prior to the forwarding private String originalRequestURL = null; + + // present for CaptureQuery and Replay requests + private CaptureSearchResults captureResults = null; + // present for UrlQuery requests + private UrlSearchResults urlResults = null; + // Present for Replay requests, the "closest" result + private CaptureSearchResult result = null; + // Present for Replay requests, the actual Resource being replayed + private Resource resource = null; + // Present for... requests that resulted in an expected Exception. + private WaybackException exception = null; - - /** - * @param wbRequest Wayback Request argument - */ public UIResults(WaybackRequest wbRequest,ResultURIConverter uriConverter) { - super(); this.wbRequest = wbRequest; this.uriConverter = uriConverter; } + public UIResults(WaybackRequest wbRequest, ResultURIConverter uriConverter, + WaybackException exception) { + this.wbRequest = wbRequest; + this.uriConverter = uriConverter; + this.exception = exception; + } + public UIResults(WaybackRequest wbRequest, ResultURIConverter uriConverter, + CaptureSearchResults captureResults) { + this.wbRequest = wbRequest; + this.uriConverter = uriConverter; + this.captureResults = captureResults; + } + public UIResults(WaybackRequest wbRequest, ResultURIConverter uriConverter, + UrlSearchResults urlResults) { + this.wbRequest = wbRequest; + this.uriConverter = uriConverter; + this.urlResults = urlResults; + } + public UIResults(WaybackRequest wbRequest, ResultURIConverter uriConverter, + CaptureSearchResults captureResults, CaptureSearchResult result, + Resource resource) { + this.wbRequest = wbRequest; + this.uriConverter = uriConverter; + this.captureResults = captureResults; + this.result = result; + this.resource = resource; + } + + /* + * GENERAL GETTERS: + */ + /** * @return Returns the wbRequest. */ @@ -63,8 +133,58 @@ } return wbRequest; } - /** + * @return the ResultURIConverter + */ + public ResultURIConverter getURIConverter() { + return uriConverter; + } + /** + * @return the captureResults + */ + public CaptureSearchResults getCaptureResults() { + return captureResults; + } + /** + * @return the urlResults + */ + public UrlSearchResults getUrlResults() { + return urlResults; + } + /** + * @return the result + */ + public CaptureSearchResult getResult() { + return result; + } + /** + * @return the resource + */ + public Resource getResource() { + return resource; + } + /** + * @return the exception + */ + public WaybackException getException() { + return exception; + } + /** + * @return the contentJsp + */ + public String getContentJsp() { + return contentJsp; + } + + public String getOriginalRequestURL() { + return originalRequestURL; + } + + /* + * JSP CONVENIENCE METHODS: + */ + + /** * @param url * @return String url that will make a query for all captures of an URL. */ @@ -76,13 +196,49 @@ return newWBR.getContextPrefix() + "query?" + newWBR.getQueryArguments(1); } + /** + * @param configName + * @return String configuration for the context, if present, otherwise null + */ + public String getContextConfig(final String configName) { + String configValue = null; + AccessPoint context = getWbRequest().getAccessPoint(); + if(context != null) { + Properties configs = context.getConfigs(); + if(configs != null) { + configValue = configs.getProperty(configName); + } + } + return configValue; + } + /** + * @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 StringFormatter localized to user request + * @param pageNum + * @return String URL which will drive browser to search results for a + * different page of results for the same query */ - public StringFormatter getFormatter() { - return getWbRequest().getFormatter(); + public String urlForPage(int pageNum) { + WaybackRequest wbRequest = getWbRequest(); + return wbRequest.getContextPrefix() + "query?" + + wbRequest.getQueryArguments(pageNum); } + + /* + * FORWARD TO A .JSP + */ + /** * Store this UIResults in the HttpServletRequest argument. * @param httpRequest @@ -96,28 +252,149 @@ } /** + * @param request + * @param response + * @param targt + * @throws ServletException + * @throws IOException + */ + public void forward(HttpServletRequest request, + HttpServletResponse response, final String target) + throws ServletException, IOException { + + this.contentJsp = target; + this.originalRequestURL = request.getRequestURL().toString(); + request.setAttribute(FERRET_NAME, this); + RequestDispatcher dispatcher = request.getRequestDispatcher(target); + if(dispatcher == null) { + throw new IOException("No dispatcher for " + target); + } + dispatcher.forward(request, response); + } + + /* + * EXTRACT FROM HttpServletRequest + */ + /** * @param httpRequest - * @return UIResults from httpRequest, or a generic one if not present + * @return generic UIResult with info from httpRequest applied. */ - public static UIResults getFromRequest(HttpServletRequest httpRequest) { + public static UIResults getGeneric(HttpServletRequest httpRequest) { UIResults results = (UIResults) httpRequest.getAttribute(FERRET_NAME); if(results == null) { - results = getGeneric(httpRequest); - // why not store it in case someone else needs it... -// results.storeInRequest(httpRequest,""); + WaybackRequest wbRequest = new WaybackRequest(); + wbRequest.fixup(httpRequest); + results = new UIResults(wbRequest, null); } return results; } - + /** * @param httpRequest - * @return generic UIResult with info from httpRequest applied. + * @return UIResults from httpRequest + * @throws ServletException */ - public static UIResults getGeneric(HttpServletRequest httpRequest) { - WaybackRequest wbRequest = new WaybackRequest(); - wbRequest.fixup(httpRequest); - return new UIResults(wbRequest, null); + public static UIResults extractException(HttpServletRequest httpRequest) + throws ServletException { + + UIResults results = (UIResults) httpRequest.getAttribute(FERRET_NAME); + if(results == null) { + throw new ServletException("No attribute.."); + } + if(results.exception == null) { + throw new ServletException("No WaybackException.."); + } + if(results.wbRequest == null) { + throw new ServletException("No WaybackRequest.."); + } + if(results.uriConverter == null) { + throw new ServletException("No ResultURIConverter.."); + } + return results; } + /** + * @param httpRequest + * @return UIResults from httpRequest + * @throws ServletException + */ + public static UIResults extractCaptureQuery(HttpServletRequest httpRequest) + throws ServletException { + + UIResults results = (UIResults) httpRequest.getAttribute(FERRET_NAME); + if(results == null) { + throw new ServletException("No attribute.."); + } + if(results.wbRequest == null) { + throw new ServletException("No WaybackRequest.."); + } + if(results.uriConverter == null) { + throw new ServletException("No ResultURIConverter.."); + } + if(results.captureResults == null) { + throw new ServletException("No CaptureSearchResults.."); + } + return results; + } + /** + * @param httpRequest + * @return UIResults from httpRequest + * @throws ServletException + */ + public static UIResults extractUrlQuery(HttpServletRequest httpRequest) + throws ServletException { + + UIResults results = (UIResults) httpRequest.getAttribute(FERRET_NAME); + if(results == null) { + throw new ServletException("No attribute.."); + } + if(results.wbRequest == null) { + throw new ServletException("No WaybackRequest.."); + } + if(results.uriConverter == null) { + throw new ServletException("No ResultURIConverter.."); + } + if(results.urlResults == null) { + throw new ServletException("No UrlSearchResults.."); + } + return results; + } + /** + * @param httpRequest + * @return UIResults from httpRequest + * @throws ServletException + */ + public static UIResults extractReplay(HttpServletRequest httpRequest) + throws ServletException { + + UIResults results = (UIResults) httpRequest.getAttribute(FERRET_NAME); + if(results == null) { + throw new ServletException("No attribute.."); + } + if(results.wbRequest == null) { + throw new ServletException("No WaybackRequest.."); + } + if(results.uriConverter == null) { + throw new ServletException("No ResultURIConverter.."); + } + if(results.captureResults == null) { + throw new ServletException("No CaptureSearchResults.."); + } + if(results.result == null) { + throw new ServletException("No CaptureSearchResult.."); + } + if(results.resource == null) { + throw new ServletException("No Resource.."); + } + return results; + } + + + + /* + * STATIC CONVENIENCE METHODS + */ + + private static void replaceAll(StringBuffer s, final String o, final String n) { int olen = o.length(); @@ -175,79 +452,53 @@ replaceAll(encoded,"gt",">"); replaceAll(encoded,"quot","""); return encoded.toString(); - } + } + /* + * DEPRECATED + */ + /** * @return URL that points to the root of the current WaybackContext + * @deprecated */ public String getContextPrefix() { return getWbRequest().getContextPrefix(); } + + /** + * @return StringFormatter localized to user request + * @deprecated + */ + public StringFormatter getFormatter() { + return getWbRequest().getFormatter(); + } /** * @return URL that points to the root of the Server + * @deprecated */ public String getServerPrefix() { return getWbRequest().getServerPrefix(); } + /** - * @return the contentJsp - */ - public String getContentJsp() { - return contentJsp; - } - /** * @param contentJsp the contentJsp to set + * @deprecated */ public void setContentJsp(String contentJsp) { this.contentJsp = contentJsp; } - /** - * @param configName - * @return String configuration for the context, if present, otherwise null - */ - public String getContextConfig(final String configName) { - String configValue = null; - AccessPoint context = getWbRequest().getAccessPoint(); - if(context != null) { - Properties configs = context.getConfigs(); - if(configs != null) { - configValue = configs.getProperty(configName); - } - } - return configValue; - } - 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 + * @deprecated */ public String makeReplayUrl(String url, String timestamp) { if(uriConverter == null) { return null; } return uriConverter.makeReplayURI(timestamp, url); - } + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/BaseExceptionRenderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/BaseExceptionRenderer.java 2008-07-15 01:25:18 UTC (rev 2445) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/BaseExceptionRenderer.java 2008-07-15 01:27:41 UTC (rev 2446) @@ -28,7 +28,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -141,15 +140,8 @@ wbRequest, exception); httpRequest.setAttribute("exception", exception); - UIResults uiResults = new UIResults(wbRequest,null); - uiResults.storeInRequest(httpRequest, jspPath); - - RequestDispatcher dispatcher = httpRequest - .getRequestDispatcher(jspPath); - if(dispatcher == null) { - throw new ServletException("Null dispatcher for " + jspPath); - } - dispatcher.forward(httpRequest, httpResponse); + UIResults uiResults = new UIResults(wbRequest,null,exception); + uiResults.forward(httpRequest, httpResponse, jspPath); } public String getErrorJsp() { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java 2008-07-15 01:25:18 UTC (rev 2445) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/Renderer.java 2008-07-15 01:27:41 UTC (rev 2446) @@ -26,7 +26,6 @@ import java.io.IOException; -import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -34,6 +33,7 @@ import org.archive.wayback.QueryRenderer; import org.archive.wayback.ResultURIConverter; import org.archive.wayback.core.CaptureSearchResults; +import org.archive.wayback.core.UIResults; import org.archive.wayback.core.UrlSearchResults; import org.archive.wayback.core.WaybackRequest; @@ -52,36 +52,17 @@ private String xmlCaptureJsp = "/query/XMLCaptureResults.jsp"; private String xmlUrlJsp = "/query/XMLUrlResults.jsp"; - /** - * @param request - * @param response - * @param jspName - * @throws ServletException - * @throws IOException - */ - private void proxyRequest(HttpServletRequest request, - HttpServletResponse response, final String jspPath) - throws ServletException, IOException { - - RequestDispatcher dispatcher = request.getRequestDispatcher(jspPath); - dispatcher.forward(request, response); - } - public void renderCaptureResults(HttpServletRequest httpRequest, HttpServletResponse httpResponse, WaybackRequest wbRequest, CaptureSearchResults results, ResultURIConverter uriConverter) throws ServletException, IOException { - UICaptureQueryResults uiResults = new UICaptureQueryResults(httpRequest, - wbRequest, results, uriConverter); String jsp = captureJsp; if(wbRequest.isXMLMode()) { jsp = xmlCaptureJsp; } - - uiResults.storeInRequest(httpRequest,jsp); - proxyRequest(httpRequest, httpResponse, jsp); - + UIResults uiResults = new UIResults(wbRequest,uriConverter,results); + uiResults.forward(httpRequest, httpResponse, jsp); } /* (non-Javadoc) @@ -92,16 +73,12 @@ UrlSearchResults results, ResultURIConverter uriConverter) throws ServletException, IOException { - UIUrlQueryResults uiResults = new UIUrlQueryResults(httpRequest, wbRequest, - results, uriConverter); String jsp = urlJsp; if(wbRequest.isXMLMode()) { jsp = xmlUrlJsp; } - - uiResults.storeInRequest(httpRequest,jsp); - proxyRequest(httpRequest, httpResponse, jsp); - + UIResults uiResults = new UIResults(wbRequest,uriConverter,results); + uiResults.forward(httpRequest, httpResponse, jsp); } /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/HTMLPage.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/HTMLPage.java 2008-07-15 01:25:18 UTC (rev 2445) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/HTMLPage.java 2008-07-15 01:27:41 UTC (rev 2446) @@ -33,7 +33,6 @@ import java.text.ParseException; import java.util.Map; -import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -42,8 +41,8 @@ import org.archive.wayback.core.Resource; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.CaptureSearchResults; +import org.archive.wayback.core.UIResults; import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.replay.UIReplayResult; import org.mozilla.universalchardet.UniversalDetector; /** @@ -440,14 +439,15 @@ CaptureSearchResult result, Resource resource) throws ServletException, IOException { - UIReplayResult uiResults = new UIReplayResult(httpRequest, wbRequest, - result, results, resource, uriConverter); + UIResults uiResults = new UIResults(wbRequest,uriConverter,results, + result,resource); StringHttpServletResponseWrapper wrappedResponse = new StringHttpServletResponseWrapper(httpResponse); - uiResults.storeInRequest(httpRequest,jspPath); - RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(jspPath); - dispatcher.forward(httpRequest, wrappedResponse); + uiResults.forward(httpRequest, wrappedResponse, jspPath); +// uiResults.storeInRequest(httpRequest,jspPath); +// RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(jspPath); +// dispatcher.forward(httpRequest, wrappedResponse); return wrappedResponse.getStringResponse(); } 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 2008-07-15 01:25:18 UTC (rev 2445) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java 2008-07-15 01:27:41 UTC (rev 2446) @@ -28,7 +28,6 @@ import java.util.Properties; import java.util.logging.Logger; -import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -232,24 +231,32 @@ HttpServletResponse httpResponse) throws ServletException, IOException { + String translated = "/" + translateRequestPathQuery(httpRequest); + WaybackRequest wbRequest = new WaybackRequest(); wbRequest.setContextPrefix(getAbsoluteLocalPrefix(httpRequest)); wbRequest.setAccessPoint(this); + UIResults uiResults = new UIResults(wbRequest,uriConverter); - String translated = "/" + translateRequestPathQuery(httpRequest); - uiResults.storeInRequest(httpRequest,translated); - RequestDispatcher dispatcher = null; + try { + uiResults.forward(httpRequest, httpResponse, translated); + return true; + } catch(IOException e) { + // TODO: figure out if we got IO because of a missing dispatcher + } +// uiResults.storeInRequest(httpRequest,translated); +// RequestDispatcher dispatcher = null; // // special case for the front '/' page: // if(translated.length() == 0) { // translated = "/"; // } else { // translated = "/" + translated; // } - dispatcher = httpRequest.getRequestDispatcher(translated); - if(dispatcher != null) { - dispatcher.forward(httpRequest, httpResponse); - return true; - } +// dispatcher = httpRequest.getRequestDispatcher(translated); +// if(dispatcher != null) { +// dispatcher.forward(httpRequest, httpResponse); +// return true; +// } return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-07-15 01:37:32
|
Revision: 2448 http://archive-access.svn.sourceforge.net/archive-access/?rev=2448&view=rev Author: bradtofel Date: 2008-07-14 18:37:42 -0700 (Mon, 14 Jul 2008) Log Message: ----------- REFACTOR: Timestamp package change: org.archive.wayback.core => org.archive.wayback.util Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ExternalExcluder.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionRule.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionServlet.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDateRangeQueryRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDatePrefixQueryRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDateRangeQueryRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ReplayRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/BDBMap.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/core/SearchResult.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayRenderer.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/LiveWebCache.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitioner.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitionsFactory.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsTimelinePartitionsFactory.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/BaseRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/LocalResourceIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/NutchResourceIndex.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/DateRangeFilter.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/EndDateFilter.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/StartDateFilter.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/Timestamp.java Removed Paths: ------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Timestamp.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ExternalExcluder.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ExternalExcluder.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ExternalExcluder.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -25,8 +25,8 @@ package org.archive.wayback.accesscontrol; import org.archive.wayback.core.CaptureSearchResult; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.util.ObjectFilter; +import org.archive.wayback.util.Timestamp; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionRule.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionRule.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionRule.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -29,7 +29,7 @@ import java.net.URLEncoder; import java.text.ParseException; -import org.archive.wayback.core.Timestamp; +import org.archive.wayback.util.Timestamp; /** * Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionServlet.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionServlet.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionServlet.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -36,8 +36,8 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.httpclient.URIException; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.surt.SURTTokenizer; +import org.archive.wayback.util.Timestamp; import org.archive.wayback.webapp.ServletRequestContext; import com.sleepycat.je.DatabaseException; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -27,9 +27,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; +import org.archive.wayback.util.Timestamp; /** * RequestParser implementation that extracts request info from an Archival Url Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDateRangeQueryRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDateRangeQueryRequestParser.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDateRangeQueryRequestParser.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -27,9 +27,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; +import org.archive.wayback.util.Timestamp; /** * RequestParser implementation that extracts request info from an Archival Url Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDatePrefixQueryRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDatePrefixQueryRequestParser.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDatePrefixQueryRequestParser.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -27,9 +27,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; +import org.archive.wayback.util.Timestamp; /** * RequestParser implementation that extracts request info from an Archival Url Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDateRangeQueryRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDateRangeQueryRequestParser.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathPrefixDateRangeQueryRequestParser.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -27,9 +27,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; +import org.archive.wayback.util.Timestamp; /** * RequestParser implementation that extracts request info from an Archival Url Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ReplayRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ReplayRequestParser.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ReplayRequestParser.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -27,9 +27,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.requestparser.PathRequestParser; +import org.archive.wayback.util.Timestamp; /** * RequestParser implementation that extracts request info from a Replay Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/BDBMap.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/BDBMap.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/BDBMap.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -23,6 +23,8 @@ import java.io.UnsupportedEncodingException; import java.util.Properties; +import org.archive.wayback.util.Timestamp; + import com.sleepycat.je.Database; import com.sleepycat.je.DatabaseConfig; import com.sleepycat.je.DatabaseEntry; 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 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -29,6 +29,7 @@ import java.util.Iterator; import org.archive.wayback.exception.AnchorWindowTooSmallException; +import org.archive.wayback.util.Timestamp; /** * Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResult.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResult.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResult.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -28,6 +28,8 @@ import java.util.HashMap; import java.util.Map; +import org.archive.wayback.util.Timestamp; + /** * * Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Timestamp.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Timestamp.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Timestamp.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -1,459 +0,0 @@ -/* Timestamp - * - * Created on 2005/10/18 14:00:00 - * - * Copyright (C) 2005 Internet Archive. - * - * This file is part of the Wayback Machine (crawler.archive.org). - * - * Wayback Machine 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 Machine 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 Machine; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package org.archive.wayback.core; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.SimpleTimeZone; -import java.util.TimeZone; - - -/** - * Represents a moment in time as a 14-digit string, and interally as a Date. - * - * @author Brad Tofel - * @version $Date$, $Revision$ - */ -public class Timestamp { - - private final static String LOWER_TIMESTAMP_LIMIT = "10000000000000"; - private final static String UPPER_TIMESTAMP_LIMIT = "29991939295959"; - private final static String YEAR_LOWER_LIMIT = "1996"; - private final static String YEAR_UPPER_LIMIT = - String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); - private final static String MONTH_LOWER_LIMIT = "01"; - private final static String MONTH_UPPER_LIMIT = "12"; - private final static String DAY_LOWER_LIMIT = "01"; - private final static String HOUR_UPPER_LIMIT = "23"; - private final static String HOUR_LOWER_LIMIT = "00"; - private final static String MINUTE_UPPER_LIMIT = "59"; - private final static String MINUTE_LOWER_LIMIT = "00"; - private final static String SECOND_UPPER_LIMIT = "59"; - private final static String SECOND_LOWER_LIMIT = "00"; - - private final static int SSE_1996 = 820454400; - - private final static String[] months = { "Jan", "Feb", "Mar", "Apr", "May", - "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - - private String dateStr = null; - private Date date = null; - - /** - * Constructor - */ - public Timestamp() { - super(); - } - - /** - * Construct and initialize structure from a 14-digit String timestamp. If - * the argument is too short, or specifies an invalid timestamp, cleanup - * will be attempted to create the earliest legal timestamp given the input. - * @param dateStr - */ - public Timestamp(final String dateStr) { - super(); - - Calendar cal = dateStrToCalendar(dateStr); - setDate(cal.getTime()); - } - - /** - * Construct and initialize structure from an integer number of seconds - * since the epoch. - * @param sse - */ - public Timestamp(final int sse) { - super(); - setSse(sse); - } - - /** - * Construct and initialize structure from an Date - * @param date - */ - public Timestamp(final Date date) { - super(); - setDate(date); - } - - /** - * set internal structure using Date argument - * @param date - */ - public void setDate(final Date date) { - this.date = (Date) date.clone(); - Calendar cal = getCalendar(); - cal.setTime(this.date); - dateStr = calendarToDateStr(cal); - } - - - /** - * @return Date for this Timestamp - */ - public Date getDate() { - return date; - } - - /** - * set internal structure using seconds since the epoch integer argument - * @param sse - */ - public void setSse(final int sse) { - setDate(new Date(((long)sse) * 1000)); - } - - /** - * initialize interal data structures for this Timestamp from the 14-digit - * argument. Will clean up timestamp as needed to yield the ealiest - * possible timestamp given the possible partial or wrong argument. - * - * @param dateStr - */ - public void setDateStr(String dateStr) { - Calendar cal = dateStrToCalendar(dateStr); - setDate(cal.getTime()); - } - - /** - * @return the 14-digit String representation of this Timestamp. - */ - - public String getDateStr() { - return dateStr; - } - - /** - * @return the integer number of seconds since epoch represented by this - * Timestamp. - */ - public int sse() { - return Math.round(date.getTime() / 1000); - } - - /** - * function that calculates integer seconds between this records - * timeStamp and the arguments timeStamp. result is the absolute number of - * seconds difference. - * - * @param otherTimeStamp - * @return int absolute seconds between the argument and this records - * timestamp. - */ - public int absDistanceFromTimestamp(final Timestamp otherTimeStamp) { - return Math.abs(distanceFromTimestamp(otherTimeStamp)); - } - - /** - * function that calculates integer seconds between this records - * timeStamp and the arguments timeStamp. result is negative if this records - * timeStamp is less than the argument, positive if it is greater, and 0 if - * the same. - * - * @param otherTimeStamp - * @return int milliseconds - */ - public int distanceFromTimestamp(final Timestamp otherTimeStamp) { - return otherTimeStamp.sse() - sse(); - } - - /** - * @return the year portion(first 4 digits) of this Timestamp - */ - public String getYear() { - return this.dateStr.substring(0, 4); - } - - /** - * @return the month portion(digits 5-6) of this Timestamp - */ - public String getMonth() { - return this.dateStr.substring(4, 6); - } - - /** - * @return the day portion(digits 7-8) of this Timestamp - */ - public String getDay() { - return this.dateStr.substring(6, 8); - } - - /** - * @return user friendly String representation of the date of this - * Timestamp. eg: "Jan 13, 1999" - */ - public String prettyDate() { - String year = dateStr.substring(0, 4); - String month = dateStr.substring(4, 6); - String day = dateStr.substring(6, 8); - int monthInt = Integer.parseInt(month) - 1; - String prettyMonth = "UNK"; - if ((monthInt >= 0) && (monthInt < months.length)) { - prettyMonth = months[monthInt]; - } - return prettyMonth + " " + day + ", " + year; - } - - /** - * @return user friendly String representation of the Time of this - * Timestamp. - */ - public String prettyTime() { - return dateStr.substring(8, 10) + ":" + dateStr.substring(10, 12) + ":" - + dateStr.substring(12, 14); - } - - /** - * @return user friendly String representation of the Date and Time of this - * Timestamp. - */ - public String prettyDateTime() { - return prettyDate() + " " + prettyTime(); - } - - /* - * - * ALL STATIC METHOD BELOW HERE: - * ============================= - * - */ - - private static String frontZeroPad(final String input, final int digits) { - int missing = digits - input.length(); - String padded = ""; - for(int i = 0; i < missing; i++) { - padded += "0"; - } - padded += input; - return padded; - } - private static String frontZeroPad(final int input, final int digits) { - return frontZeroPad(String.valueOf(input) ,digits); - } - - private static Calendar getCalendar() { - String[] ids = TimeZone.getAvailableIDs(0); - if (ids.length < 1) { - return null; - } - TimeZone gmt = new SimpleTimeZone(0, ids[0]); - return new GregorianCalendar(gmt); - } - - /** - * cleanup the dateStr argument assuming earliest values, and return a - * GMT calendar set to the time described by the dateStr. - * - * @param dateStr - * @return Calendar - */ - public static Calendar dateStrToCalendar(final String dateStr) { - - String paddedDateStr = padStartDateStr(dateStr); - - Calendar cal = getCalendar(); - int iYear = Integer.parseInt(paddedDateStr.substring(0,4)); - int iMonth = Integer.parseInt(paddedDateStr.substring(4,6)); - int iDay = Integer.parseInt(paddedDateStr.substring(6,8)); - int iHour = Integer.parseInt(paddedDateStr.substring(8,10)); - int iMinute = Integer.parseInt(paddedDateStr.substring(10,12)); - int iSecond = Integer.parseInt(paddedDateStr.substring(12,14)); - - cal.set(Calendar.YEAR,iYear); - cal.set(Calendar.MONTH,iMonth - 1); - cal.set(Calendar.DAY_OF_MONTH,iDay); - cal.set(Calendar.HOUR_OF_DAY,iHour); - cal.set(Calendar.MINUTE,iMinute); - cal.set(Calendar.SECOND,iSecond); - - return cal; - } - private static String calendarToDateStr(Calendar cal) { - return frontZeroPad(cal.get(Calendar.YEAR),4) + - frontZeroPad(cal.get(Calendar.MONTH) + 1 ,2) + - frontZeroPad(cal.get(Calendar.DAY_OF_MONTH),2) + - frontZeroPad(cal.get(Calendar.HOUR_OF_DAY),2) + - frontZeroPad(cal.get(Calendar.MINUTE),2) + - frontZeroPad(cal.get(Calendar.SECOND),2); - } - - - private static String padDigits(String input, String min, String max, - String missing) { - if(input == null) { - input = ""; - } - String finalDigits = ""; - for(int i = 0; i < missing.length(); i++) { - if(input.length() <= i) { - finalDigits = finalDigits + missing.charAt(i); - } else { - char inc = input.charAt(i); - char maxc = max.charAt(i); - char minc = min.charAt(i); - if(inc > maxc) { - inc = maxc; - } else if (inc < minc) { - inc = minc; - } - finalDigits = finalDigits + inc; - } - } - - return finalDigits; - } - - private static String boundDigits(String input, String min, String max) { - String bounded = input; - if(input.compareTo(min) < 0) { - bounded = min; - } else if(input.compareTo(max) > 0) { - bounded = max; - } - return bounded; - } - - // check each of YEAR, MONTH, DAY, HOUR, MINUTE, SECOND to make sure they - // are not too large or too small, factoring in the month, leap years, etc. - private static String boundTimestamp(String input) { - String boundTimestamp = ""; - if(input == null) { - input = ""; - } - // MAKE SURE THE YEAR IS WITHIN LEGAL BOUNDARIES: - Calendar tmpCal = getCalendar(); - tmpCal.setTime(new Date()); - - boundTimestamp = boundDigits(input.substring(0,4), - YEAR_LOWER_LIMIT,YEAR_UPPER_LIMIT); - - // MAKE SURE THE MONTH IS WITHIN LEGAL BOUNDARIES: - boundTimestamp += boundDigits(input.substring(4,6), - MONTH_LOWER_LIMIT,MONTH_UPPER_LIMIT); - - // NOW DEPENDING ON THE YEAR + MONTH, MAKE SURE THE DAY OF MONTH IS - // WITHIN LEGAL BOUNDARIES: - Calendar cal = getCalendar(); - cal.clear(); - int iYear = Integer.parseInt(boundTimestamp.substring(0,4)); - int iMonth = Integer.parseInt(boundTimestamp.substring(4,6)); - cal.set(Calendar.YEAR,iYear); - cal.set(Calendar.MONTH,iMonth - 1); - cal.set(Calendar.DAY_OF_MONTH,1); - - String maxDayOfMonth = String.valueOf(cal.getActualMaximum(Calendar.DAY_OF_MONTH)); - if(maxDayOfMonth.length() == 1) { - maxDayOfMonth = "0" + maxDayOfMonth; - } - boundTimestamp += boundDigits(input.substring(6,8), - DAY_LOWER_LIMIT,maxDayOfMonth); - - // MAKE SURE THE HOUR IS WITHIN LEGAL BOUNDARIES: - boundTimestamp += boundDigits(input.substring(8,10), - HOUR_LOWER_LIMIT,HOUR_UPPER_LIMIT); - - // MAKE SURE THE MINUTE IS WITHIN LEGAL BOUNDARIES: - boundTimestamp += boundDigits(input.substring(10,12), - MINUTE_LOWER_LIMIT,MINUTE_UPPER_LIMIT); - - // MAKE SURE THE SECOND IS WITHIN LEGAL BOUNDARIES: - boundTimestamp += boundDigits(input.substring(12,14), - SECOND_LOWER_LIMIT,SECOND_UPPER_LIMIT); - - return boundTimestamp; - } - - /** - * clean up timestamp argument assuming latest possible values for missing - * or bogus digits. - * @param timestamp String - * @return String - */ - public static String padEndDateStr(String timestamp) { - return boundTimestamp(padDigits(timestamp,LOWER_TIMESTAMP_LIMIT, - UPPER_TIMESTAMP_LIMIT,UPPER_TIMESTAMP_LIMIT)); - } - - /** - * clean up timestamp argument assuming earliest possible values for missing - * or bogus digits. - * @param timestamp String - * @return String - */ - public static String padStartDateStr(String timestamp) { - return boundTimestamp(padDigits(timestamp,LOWER_TIMESTAMP_LIMIT, - UPPER_TIMESTAMP_LIMIT,LOWER_TIMESTAMP_LIMIT)); - } - - /** - * @param dateStr - * @return Timestamp object representing the earliest date represented by - * the (possibly) partial digit-string argument. - */ - public static Timestamp parseBefore(final String dateStr) { - return new Timestamp(padStartDateStr(dateStr)); - } - - /** - * @param dateStr - * @return Timestamp object representing the latest date represented by the - * (possibly) partial digit-string argument. - */ - public static Timestamp parseAfter(final String dateStr) { - return new Timestamp(padEndDateStr(dateStr)); - } - - /** - * @param sse - * @return Timestamp object representing the seconds since epoch argument. - */ - public static Timestamp fromSse(final int sse) { - //String dateStr = ArchiveUtils.get14DigitDate(sse * 1000); - return new Timestamp(sse); - } - - /** - * @return Timestamp object representing the current date. - */ - public static Timestamp currentTimestamp() { - return new Timestamp(new Date()); - } - - /** - * @return Timestamp object representing the latest possible date. - */ - public static Timestamp latestTimestamp() { - return currentTimestamp(); - } - - /** - * @return Timestamp object representing the earliest possible date. - */ - public static Timestamp earliestTimestamp() { - return new Timestamp(SSE_1996); - } -} Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -38,6 +38,7 @@ import org.archive.wayback.requestparser.OpenSearchRequestParser; import org.archive.wayback.util.ObjectFilter; import org.archive.wayback.util.StringFormatter; +import org.archive.wayback.util.Timestamp; import org.archive.wayback.webapp.AccessPoint; /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayRenderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayRenderer.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixReplayRenderer.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -38,12 +38,12 @@ import org.archive.wayback.core.Resource; import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.CaptureSearchResults; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadContentException; import org.archive.wayback.replay.HTMLPage; import org.archive.wayback.replay.HttpHeaderProcessor; import org.archive.wayback.replay.HttpHeaderOperation; +import org.archive.wayback.util.Timestamp; import org.archive.wayback.util.url.UrlOperations; /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -29,10 +29,10 @@ import javax.servlet.http.HttpServletRequest; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; import org.archive.wayback.requestparser.BaseRequestParser; +import org.archive.wayback.util.Timestamp; import org.archive.wayback.webapp.AccessPoint; /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/LiveWebCache.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/LiveWebCache.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/LiveWebCache.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -37,13 +37,13 @@ import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.SearchResults; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.LiveDocumentNotAvailableException; import org.archive.wayback.exception.ResourceNotInArchiveException; import org.archive.wayback.exception.WaybackException; import org.archive.wayback.resourcestore.indexer.ARCRecordToSearchResultAdapter; import org.archive.wayback.resourcestore.resourcefile.ArcResource; +import org.archive.wayback.util.Timestamp; import org.archive.wayback.util.url.AggressiveUrlCanonicalizer; /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitioner.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitioner.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitioner.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -29,8 +29,8 @@ import java.util.SimpleTimeZone; import java.util.TimeZone; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.util.Timestamp; /** * Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitionsFactory.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitionsFactory.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsPartitionsFactory.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -30,8 +30,8 @@ import org.archive.util.ArchiveUtils; import org.archive.wayback.core.CaptureSearchResults; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.util.Timestamp; /** * Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsTimelinePartitionsFactory.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsTimelinePartitionsFactory.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/resultspartitioner/ResultsTimelinePartitionsFactory.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -29,8 +29,8 @@ import org.archive.util.ArchiveUtils; import org.archive.wayback.core.CaptureSearchResults; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.util.Timestamp; /** * Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/BaseRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/BaseRequestParser.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/BaseRequestParser.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -29,9 +29,9 @@ import javax.servlet.http.HttpServletRequest; import org.archive.wayback.RequestParser; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; +import org.archive.wayback.util.Timestamp; import org.archive.wayback.webapp.AccessPoint; /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -30,8 +30,8 @@ import javax.servlet.http.HttpServletRequest; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.util.Timestamp; import org.archive.wayback.webapp.AccessPoint; /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/LocalResourceIndex.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/LocalResourceIndex.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/LocalResourceIndex.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -37,7 +37,6 @@ import org.archive.wayback.core.CaptureToUrlSearchResultAdapter; import org.archive.wayback.core.SearchResult; import org.archive.wayback.core.SearchResults; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.UrlSearchResult; import org.archive.wayback.core.UrlSearchResults; import org.archive.wayback.core.WaybackRequest; @@ -61,6 +60,7 @@ import org.archive.wayback.util.ObjectFilter; import org.archive.wayback.util.ObjectFilterChain; import org.archive.wayback.util.ObjectFilterIterator; +import org.archive.wayback.util.Timestamp; import org.archive.wayback.util.url.AggressiveUrlCanonicalizer; /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/NutchResourceIndex.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/NutchResourceIndex.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/NutchResourceIndex.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -40,13 +40,13 @@ import org.archive.wayback.core.CaptureSearchResult; import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.SearchResults; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.AccessControlException; import org.archive.wayback.exception.BadQueryException; import org.archive.wayback.exception.ConfigurationException; import org.archive.wayback.exception.ResourceIndexNotAvailableException; import org.archive.wayback.exception.ResourceNotInArchiveException; +import org.archive.wayback.util.Timestamp; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -71,10 +71,10 @@ private String searchUrlBase; private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); private DocumentBuilder builder; - private static final String NUTCH_ARCNAME = "arcname"; - private static final String NUTCH_ARCOFFSET = "arcoffset"; -// private static final String NUTCH_FILENAME = "filename"; -// private static final String NUTCH_FILEOFFSET = "fileoffset"; +// private static final String NUTCH_ARCNAME = "arcname"; +// private static final String NUTCH_ARCOFFSET = "arcoffset"; + private static final String NUTCH_FILENAME = "filename"; + private static final String NUTCH_FILEOFFSET = "fileoffset"; private static final String NUTCH_ARCDATE = "date"; // private static final String NUTCH_ARCDATE_ALT = "arcdate"; private static final String NUTCH_DIGEST = "digest"; @@ -194,11 +194,11 @@ private List<CaptureSearchResult> itemToSearchResults(Element e) throws ResourceIndexNotAvailableException { - String fileName = getNodeNutchContent(e,NUTCH_ARCNAME); + String fileName = getNodeNutchContent(e,NUTCH_FILENAME); String httpCode = NUTCH_DEFAULT_HTTP_CODE; String digest = getNodeNutchContent(e,NUTCH_DIGEST); String mimeType = getNodeNutchContent(e,NUTCH_MIME_TYPE); - String offsetStr = getNodeNutchContent(e,NUTCH_ARCOFFSET); + String offsetStr = getNodeNutchContent(e,NUTCH_FILEOFFSET); long offset = 0; if(offsetStr != null && offsetStr.length() > 0) { offset = Long.parseLong(offsetStr); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/DateRangeFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/DateRangeFilter.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/DateRangeFilter.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -25,8 +25,8 @@ package org.archive.wayback.resourceindex.filters; import org.archive.wayback.core.CaptureSearchResult; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.util.ObjectFilter; +import org.archive.wayback.util.Timestamp; /** * SearchResultFilter that excludes records outside of start and end range. Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/EndDateFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/EndDateFilter.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/EndDateFilter.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -25,8 +25,8 @@ package org.archive.wayback.resourceindex.filters; import org.archive.wayback.core.CaptureSearchResult; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.util.ObjectFilter; +import org.archive.wayback.util.Timestamp; /** Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/StartDateFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/StartDateFilter.java 2008-07-15 01:30:13 UTC (rev 2447) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/filters/StartDateFilter.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -25,8 +25,8 @@ package org.archive.wayback.resourceindex.filters; import org.archive.wayback.core.CaptureSearchResult; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.util.ObjectFilter; +import org.archive.wayback.util.Timestamp; /** * SearchResultFilter which includes all records until 1 is found before start Copied: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/Timestamp.java (from rev 2443, trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Timestamp.java) =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/Timestamp.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/Timestamp.java 2008-07-15 01:37:42 UTC (rev 2448) @@ -0,0 +1,459 @@ +/* Timestamp + * + * Created on 2005/10/18 14:00:00 + * + * Copyright (C) 2005 Internet Archive. + * + * This file is part of the Wayback Machine (crawler.archive.org). + * + * Wayback Machine 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 Machine 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 Machine; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package org.archive.wayback.util; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.SimpleTimeZone; +import java.util.TimeZone; + + +/** + * Represents a moment in time as a 14-digit string, and interally as a Date. + * + * @author Brad Tofel + * @version $Date$, $Revision$ + */ +public class Timestamp { + + private final static String LOWER_TIMESTAMP_LIMIT = "10000000000000"; + private final static String UPPER_TIMESTAMP_LIMIT = "29991939295959"; + private final static String YEAR_LOWER_LIMIT = "1996"; + private final static String YEAR_UPPER_LIMIT = + String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); + private final static String MONTH_LOWER_LIMIT = "01"; + private final static String MONTH_UPPER_LIMIT = "12"; + private final static String DAY_LOWER_LIMIT = "01"; + private final static String HOUR_UPPER_LIMIT = "23"; + private final static String HOUR_LOWER_LIMIT = "00"; + private final static String MINUTE_UPPER_LIMIT = "59"; + private final static String MINUTE_LOWER_LIMIT = "00"; + private final static String SECOND_UPPER_LIMIT = "59"; + private final static String SECOND_LOWER_LIMIT = "00"; + + private final static int SSE_1996 = 820454400; + + private final static String[] months = { "Jan", "Feb", "Mar", "Apr", "May", + "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + + private String dateStr = null; + private Date date = null; + + /** + * Constructor + */ + public Timestamp() { + super(); + } + + /** + * Construct and initialize structure from a 14-digit String timestamp. If + * the argument is too short, or specifies an invalid timestamp, cleanup + * will be attempted to create the earliest legal timestamp given the input. + * @param dateStr + */ + public Timestamp(final String dateStr) { + super(); + + Calendar cal = dateStrToCalendar(dateStr); + setDate(cal.getTime()); + } + + /** + * Construct and initialize structure from an integer number of seconds + * since the epoch. + * @param sse + */ + public Timestamp(final int sse) { + super(); + setSse(sse); + } + + /** + * Construct and initialize structure from an Date + * @param date + */ + public Timestamp(final Date date) { + super(); + setDate(date); + } + + /** + * set internal structure using Date argument + * @param date + */ + public void setDate(final Date date) { + this.date = (Date) date.clone(); + Calendar cal = getCalendar(); + cal.setTime(this.date); + dateStr = calendarToDateStr(cal); + } + + + /** + * @return Date for this Timestamp + */ + public Date getDate() { + return date; + } + + /** + * set internal structure using seconds since the epoch integer argument + * @param sse + */ + public void setSse(final int sse) { + setDate(new Date(((long)sse) * 1000)); + } + + /** + * initialize interal data structures for this Timestamp from the 14-digit + * argument. Will clean up timestamp as needed to yield the ealiest + * possible timestamp given the possible partial or wrong argument. + * + * @param dateStr + */ + public void setDateStr(String dateStr) { + Calendar cal = dateStrToCalendar(dateStr); + setDate(cal.getTime()); + } + + /** + * @return the 14-digit String representation of this Timestamp. + */ + + public String getDateStr() { + return dateStr; + } + + /** + * @return the integer number of seconds since epoch represented by this + * Timestamp. + */ + public int sse() { + return Math.round(date.getTime() / 1000); + } + + /** + * function that calculates integer seconds between this records + * timeStamp and the arguments timeStamp. result is the absolute number of + * seconds difference. + * + * @param otherTimeStamp + * @return int absolute seconds between the argument and this records + * timestamp. + */ + public int absDistanceFromTimestamp(final Timestamp otherTimeStamp) { + return Math.abs(distanceFromTimestamp(otherTimeStamp)); + } + + /** + * function that calculates integer seconds between this records + * timeStamp and the arguments timeStamp. result is negative if this records + * timeStamp is less than the argument, positive if it is greater, and 0 if + * the same. + * + * @param otherTimeStamp + * @return int milliseconds + */ + public int distanceFromTimestamp(final Timestamp otherTimeStamp) { + return otherTimeStamp.sse() - sse(); + } + + /** + * @return the year portion(first 4 digits) of this Timestamp + */ + public String getYear() { + return this.dateStr.substring(0, 4); + } + + /** + * @return the month portion(digits 5-6) of this Timestamp + */ + public String getMonth() { + return this.dateStr.substring(4, 6); + } + + /** + * @return the day portion(digits 7-8) of this Timestamp + */ + public String getDay() { + return this.dateStr.substring(6, 8); + } + + /** + * @return user friendly String representation of the date of this + * Timestamp. eg: "Jan 13, 1999" + */ + public String prettyDate() { + String year = dateStr.substring(0, 4); + String month = dateStr.substring(4, 6); + String day = dateStr.substring(6, 8); + int monthInt = Integer.parseInt(month) - 1; + String prettyMonth = "UNK"; + if ((monthInt >= 0) && (monthInt < months.length)) { + prettyMonth = months[monthInt]; + } + return prettyMonth + " " + day + ", " + year; + } + + /** + * @return user friendly String representation of the Time of this + * Timestamp. + */ + public String prettyTime() { + return dateStr.substring(8, 10) + ":" + dateStr.substring(10, 12) + ":" + + dateStr.substring(12, 14); + } + + /** + * @return user friendly String representation of the Date and Time of this + * Timestamp. + */ + public String prettyDateTime() { + return prettyDate() + " " + prettyTime(); + } + + /* + * + * ALL STATIC METHOD BELOW HERE: + * ============================= + * + */ + + private static String frontZeroPad(final String input, final int digits) { + int missing = digits - input.length(); + String padded = ""; + for(int i = 0; i < missing; i++) { + padded += "0"; + } + padded += input; + return padded; + } + private static String frontZeroPad(final int input, final int digits) { + return frontZeroPad(String.valueOf(input) ,digits); + } + + private static Calendar getCalendar() { + String[] ids = TimeZone.getAvailableIDs(0); + if (ids.length < 1) { + return null; + } + TimeZone gmt = new SimpleTimeZone(0, ids[0]); + return new GregorianCalendar(gmt); + } + + /** + * cleanup the dateStr argument assuming earliest values, and return a + * GMT calendar set to the time described by the dateStr. + * + * @param dateStr + * @return Calendar + */ + public static Calendar dateStrToCalendar(final String dateStr) { + + String paddedDateStr = padStartDateStr(dateStr); + + Calendar cal = getCalendar(); + int iYear = Integer.parseInt(paddedDateStr.substring(0,4)); + int iMonth = Integer.parseInt(paddedDateStr.substring(4,6)); + int iDay = Integer.parseInt(paddedDateStr.substring(6,8)); + int iHour = Integer.parseInt(paddedDateStr.substring(8,10)); + int iMinute = Integer.parseInt(paddedDateStr.substring(10,12)); + int iSecond = Integer.parseInt(paddedDateStr.substring(12,14)); + + cal.set(Calendar.YEAR,iYear); + cal.set(Calendar.MONTH,iMonth - 1); + cal.set(Calendar.DAY_OF_MONTH,iDay); + cal.set(Calendar.HOUR_OF_DAY,iHour); + cal.set(Calendar.MINUTE,iMinute); + cal.set(Calendar.SECOND,iSecond); + + return cal; + } + private static String calendarToDateStr(Calendar cal) { + return frontZeroPad(cal.get(Calendar.YEAR),4) + + frontZeroPad(cal.get(Calendar.MONTH) + 1 ,2) + + frontZeroPad(cal.get(Calendar.DAY_OF_MONTH),2) + + frontZeroPad(cal.get(Calendar.HOUR_OF_DAY),2) + + frontZeroPad(cal.get(Calendar.MINUTE),2) + + frontZeroPad(cal.get(Calendar.SECOND),2); + } + + + private static String padDigits(String input, String min, String max, + String missing) { + if(input == null) { + input = ""; + } + String finalDigits = ""; + for(int i = 0; i < missing.length(); i++) { + if(input.length() <= i) { + finalDigits = finalDigits + missing.charAt(i); + } else { + char inc = input.charAt(i); + char maxc = max.charAt(i); + char minc = min.charAt(i); + if(inc > maxc) { + inc = maxc; + } else if (inc < minc) { + inc = minc; + } + finalDigits = finalDigits + inc; + } + } + + return finalDigits; + } + + private static String boundDigits(String input, String min, String max) { + String bounded = input; + if(input.compareTo(min) < 0) { + bounded = min; + } else if(input.compareTo(max) > 0) { + bounded = max; + } + return bounded; + } + + // check each of YEAR, MONTH, DAY, HOUR, MINUTE, SECOND to make sure they + // are not too large or too small, factoring in the month, leap years, etc. + private static String boundTimestamp(String input) { + String boundTimestamp = ""; + if(input == null) { + input = ""; + } + // MAKE SURE THE YEAR IS WITHIN LEGAL BOUNDARIES: + Calendar tmpCal = getCalendar(); + tmpCal.setTime(new Date()); + + boundTimestamp = boundDigits(input.substring(0,4), + YEAR_LOWER_LIMIT,YEAR_UPPER_LIMIT); + + // MAKE SURE THE MONTH IS WITHIN LEGAL BOUNDARIES: + boundTimestamp += boundDigits(input.substring(4,6), + MONTH_LOWER_LIMIT,MONTH_UPPER_LIMIT); + + // NOW DEPENDING ON THE YEAR + MONTH, MAKE SURE THE DAY OF MONTH IS + // WITHIN LEGAL BOUNDARIES: + Calendar cal = getCalendar(); + cal.clear(); + int iYear = Integer.parseInt(boundTimestamp.substring(0,4)); + int iMonth = Integer.parseInt(boundTimestamp.substring(4,6)); + cal.set(Calendar.YEAR,iYear); + cal.set(Calendar.MONTH,iMonth - 1); + cal.set(Calendar.DAY_OF_MONTH,1); + + String maxDayOfMonth = String.valueOf(cal.getActualMaximum(Calendar.DAY_OF_MONTH)); + if(maxDayOfMonth.length() == 1) { + maxDayOfMonth = "0" + maxDayOfMonth; + } + boundTimestamp += boundDigits(input.substring(6,8), + DAY_LOWER_LIMIT,maxDayOfMonth); + + // MAKE SURE THE HOUR IS WITHIN LEGAL BOUNDARIES: + boundTimestamp += boundDigits(input.substring(8,10), + HOUR_LOWER_LIMIT,HOUR_UPPER_LIMIT); + + // MAKE SURE THE MINUTE IS WITHIN LEGAL BOUNDARIES: + boundTimestamp += boundDigits(input.substring(10,12), + MINUTE_LOWER_LIMIT,MINUTE_UPPER_LIMIT); + + // MAKE SURE THE SECOND IS WITHIN LEGAL BOUNDARIES: + boundTimestamp += boundDigits(input.substring(12,14), + SECOND_LOWER_LIMIT,SECOND_UPPER_LIMIT); + + return boundTimestamp; + } + + /** + * clean up timestamp argument assuming latest possible values for missing + * or bogus digits. + * @param timestamp String + * @return String + */ + public static String padEndDateStr(String timestamp) { + return boundTimestamp(padDigits(timestamp,LOWER_TIMESTAMP_LIMIT, + UPPER_TIMESTAMP_LIMIT,UPPER_TIMESTAMP_LIMIT)); + } + + /** + * clean up timestamp argument assuming earliest possible values for missing + * or bogus digits. + * @param timestamp String + * @return String + */ + public static String padStartDateStr(String timestamp) { + return boundTimestamp(padDigits(timestamp,LOWER_TIMESTAMP_LIMIT, + UPPER_TIMESTAMP_LIMIT,LOWER_TIMESTAMP_LIMIT)); + } + + /** + * @param dateStr + * @return Timestamp object representing the earliest date represented by + * the (possibly) partial digit-string argument. + */ + public static Timestamp parseBefore(final String dateStr) { + return new Timestamp(padStartDateStr(dateStr)); + } + + /** + * @param dateStr + * @return Timestamp object representing the latest date represented by the + * (possibly) partial digit-string argument. + */ + public static Timestamp parseAfter(final String dateStr) { + return new Timestamp(padEndDateStr(dateStr)); + } + + /** + * @param sse + * @return Timestamp object representing the seconds since epoch argument. + */ + public static Timestamp fromSse(final int sse) { + //String dateStr = ArchiveUtils.get14DigitDate(sse * 1000); + return new Timestamp(sse); + } + + /** + * @return Timestamp object representing the current date. + */ + public static Timestamp currentTimestamp() { + return new Timestamp(new Date()); + } + + /** + * @return Timestamp object representing the latest possible date. + */ + public static Timestamp latestTimestamp() { + return currentTimestamp(); + } + + /** + * @return Timestamp object representing the earliest possible date. + */ + public static Timestamp earliestTimestamp() { + return new Timestamp(SSE_1996); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-07-15 01:51:42
|
Revision: 2453 http://archive-access.svn.sourceforge.net/archive-access/?rev=2453&view=rev Author: bradtofel Date: 2008-07-14 18:51:52 -0700 (Mon, 14 Jul 2008) Log Message: ----------- REFACTOR: BDBMap package moved: org.archive.wayback.core => org.archive.wayback.util Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBMap.java Removed Paths: ------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/BDBMap.java Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/BDBMap.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/BDBMap.java 2008-07-15 01:46:45 UTC (rev 2452) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/BDBMap.java 2008-07-15 01:51:52 UTC (rev 2453) @@ -1,171 +0,0 @@ -/* - * Created on 2006-apr-05 - * - * Copyright (C) 2006 Royal Library of Sweden. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -package org.archive.wayback.core; - -import java.io.File; -import java.io.UnsupportedEncodingException; -import java.util.Properties; - -import org.archive.wayback.util.Timestamp; - -import com.sleepycat.je.Database; -import com.sleepycat.je.DatabaseConfig; -import com.sleepycat.je.DatabaseEntry; -import com.sleepycat.je.DatabaseException; -import com.sleepycat.je.Environment; -import com.sleepycat.je.EnvironmentConfig; -import com.sleepycat.je.LockMode; -import com.sleepycat.je.OperationStatus; - -/** - * Generic class for simple key-value pair lookup using BDBJE. - * - * @author osk...@kb... - * @version $Date$, $Revision$ - */ -public class BDBMap { - - // Acts as a mapping between an ID and a timestamp to surf at. - // The dir should probably be configurable somehow. - private static String BDB_DIR = System.getProperty("java.io.tmpdir") + - "/wayback/bdb"; - private static Properties bdbMaps = new Properties(); - - protected Environment env = null; - protected Database db = null; - protected String name; - protected String dir; - - /** - * consturctor - * @param name of database - * @param dir path of directory where dbd files should be stored. The - * directory is created if it does not exist. - */ - public BDBMap(String name, String dir) { - this.name = name; - this.dir = dir; - init(); - } - - protected void init() { - try { - EnvironmentConfig envConf = new EnvironmentConfig(); - envConf.setAllowCreate(true); - File envDir = new File(dir); - if (!envDir.exists()) - envDir.mkdirs(); - env = new Environment(envDir, envConf); - - DatabaseConfig dbConf = new DatabaseConfig(); - dbConf.setAllowCreate(true); - dbConf.setSortedDuplicates(false); - db = env.openDatabase(null, name, dbConf); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - /** - * persistantly store key-value pair - * @param keyStr - * @param valueStr - */ - public void put(String keyStr, String valueStr) { - try { - DatabaseEntry key = new DatabaseEntry(keyStr.getBytes("UTF-8")); - DatabaseEntry data = new DatabaseEntry(valueStr.getBytes("UTF-8")); - db.put(null, key, data); - } catch (DatabaseException e) { - e.printStackTrace(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - - /** - * retrieve the value assoicated with keyStr from persistant storage - * @param keyStr - * @return String value associated with key, or null if no key is found - * or an error occurs - */ - public String get(String keyStr) { - String result = null; - try { - DatabaseEntry key = new DatabaseEntry(keyStr.getBytes("UTF-8")); - DatabaseEntry data = new DatabaseEntry(); - if (db.get(null, key, data, LockMode.DEFAULT) == - OperationStatus.SUCCESS) { - - byte[] bytes = data.getData(); - result = new String(bytes, "UTF-8"); - } - } catch (DatabaseException e) { - e.printStackTrace(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return result; - } - - /** - * @param context - * @return singleton BDBMap for the context - */ - public static BDBMap getContextMap(String context) { - if(context == null) context = ""; - if(context.startsWith("/")) { - context = context.substring(1); - } - BDBMap map = null; - synchronized(BDBMap.class) { - if(!bdbMaps.containsKey(context)) { - File bdbDir = new File(BDB_DIR,context); - bdbMaps.put(context,new BDBMap(context, - bdbDir.getAbsolutePath())); - } - map = (BDBMap) bdbMaps.get(context); - } - return map; - } - /** - * return the timestamp associated with the identifier argument, or now - * if no value is associated or something goes wrong. - * @param context - * @param ip - * @return timestamp string value - */ - public static String getTimestampForId(String context, String ip) { - BDBMap bdbMap = getContextMap(context); - String dateStr = bdbMap.get(ip); - return (dateStr != null) ? dateStr : Timestamp.currentTimestamp().getDateStr(); - } - - /** - * associate timestamp time with idenfier ip persistantly - * @param context - * @param ip - * @param time - */ - public static void addTimestampForId(String context, String ip, String time) { - BDBMap bdbMap = getContextMap(context); - bdbMap.put(ip, time); - } -} Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java 2008-07-15 01:46:45 UTC (rev 2452) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java 2008-07-15 01:51:52 UTC (rev 2453) @@ -29,12 +29,12 @@ import javax.servlet.http.HttpServletRequest; import org.archive.wayback.RequestParser; -import org.archive.wayback.core.BDBMap; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; import org.archive.wayback.requestparser.CompositeRequestParser; import org.archive.wayback.requestparser.FormRequestParser; import org.archive.wayback.requestparser.OpenSearchRequestParser; +import org.archive.wayback.util.bdb.BDBMap; import org.archive.wayback.webapp.AccessPoint; /** Copied: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBMap.java (from rev 2452, trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/BDBMap.java) =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBMap.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/bdb/BDBMap.java 2008-07-15 01:51:52 UTC (rev 2453) @@ -0,0 +1,171 @@ +/* + * Created on 2006-apr-05 + * + * Copyright (C) 2006 Royal Library of Sweden. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +package org.archive.wayback.util.bdb; + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.util.Properties; + +import org.archive.wayback.util.Timestamp; + +import com.sleepycat.je.Database; +import com.sleepycat.je.DatabaseConfig; +import com.sleepycat.je.DatabaseEntry; +import com.sleepycat.je.DatabaseException; +import com.sleepycat.je.Environment; +import com.sleepycat.je.EnvironmentConfig; +import com.sleepycat.je.LockMode; +import com.sleepycat.je.OperationStatus; + +/** + * Generic class for simple key-value pair lookup using BDBJE. + * + * @author osk...@kb... + * @version $Date$, $Revision$ + */ +public class BDBMap { + + // Acts as a mapping between an ID and a timestamp to surf at. + // The dir should probably be configurable somehow. + private static String BDB_DIR = System.getProperty("java.io.tmpdir") + + "/wayback/bdb"; + private static Properties bdbMaps = new Properties(); + + protected Environment env = null; + protected Database db = null; + protected String name; + protected String dir; + + /** + * consturctor + * @param name of database + * @param dir path of directory where dbd files should be stored. The + * directory is created if it does not exist. + */ + public BDBMap(String name, String dir) { + this.name = name; + this.dir = dir; + init(); + } + + protected void init() { + try { + EnvironmentConfig envConf = new EnvironmentConfig(); + envConf.setAllowCreate(true); + File envDir = new File(dir); + if (!envDir.exists()) + envDir.mkdirs(); + env = new Environment(envDir, envConf); + + DatabaseConfig dbConf = new DatabaseConfig(); + dbConf.setAllowCreate(true); + dbConf.setSortedDuplicates(false); + db = env.openDatabase(null, name, dbConf); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + /** + * persistantly store key-value pair + * @param keyStr + * @param valueStr + */ + public void put(String keyStr, String valueStr) { + try { + DatabaseEntry key = new DatabaseEntry(keyStr.getBytes("UTF-8")); + DatabaseEntry data = new DatabaseEntry(valueStr.getBytes("UTF-8")); + db.put(null, key, data); + } catch (DatabaseException e) { + e.printStackTrace(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + + /** + * retrieve the value assoicated with keyStr from persistant storage + * @param keyStr + * @return String value associated with key, or null if no key is found + * or an error occurs + */ + public String get(String keyStr) { + String result = null; + try { + DatabaseEntry key = new DatabaseEntry(keyStr.getBytes("UTF-8")); + DatabaseEntry data = new DatabaseEntry(); + if (db.get(null, key, data, LockMode.DEFAULT) == + OperationStatus.SUCCESS) { + + byte[] bytes = data.getData(); + result = new String(bytes, "UTF-8"); + } + } catch (DatabaseException e) { + e.printStackTrace(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return result; + } + + /** + * @param context + * @return singleton BDBMap for the context + */ + public static BDBMap getContextMap(String context) { + if(context == null) context = ""; + if(context.startsWith("/")) { + context = context.substring(1); + } + BDBMap map = null; + synchronized(BDBMap.class) { + if(!bdbMaps.containsKey(context)) { + File bdbDir = new File(BDB_DIR,context); + bdbMaps.put(context,new BDBMap(context, + bdbDir.getAbsolutePath())); + } + map = (BDBMap) bdbMaps.get(context); + } + return map; + } + /** + * return the timestamp associated with the identifier argument, or now + * if no value is associated or something goes wrong. + * @param context + * @param ip + * @return timestamp string value + */ + public static String getTimestampForId(String context, String ip) { + BDBMap bdbMap = getContextMap(context); + String dateStr = bdbMap.get(ip); + return (dateStr != null) ? dateStr : Timestamp.currentTimestamp().getDateStr(); + } + + /** + * associate timestamp time with idenfier ip persistantly + * @param context + * @param ip + * @param time + */ + public static void addTimestampForId(String context, String ip, String time) { + BDBMap bdbMap = getContextMap(context); + bdbMap.put(ip, time); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |