From: <bra...@us...> - 2010-06-05 01:20:22
|
Revision: 3151 http://archive-access.svn.sourceforge.net/archive-access/?rev=3151&view=rev Author: bradtofel Date: 2010-06-05 01:20:16 +0000 (Sat, 05 Jun 2010) Log Message: ----------- Started refactoring some common ArchivalUrl code into it's own class: ArchivalUrl (finally!!) subclassed FormRequestParser, with specialized ArchivalUrl version, which just throws a BetterRequestException to bounce the user to a "prettier" form of their request. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlRequestParser.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrl.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ArchivalUrlFormRequestParser.java Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrl.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrl.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrl.java 2010-06-05 01:20:16 UTC (rev 3151) @@ -0,0 +1,95 @@ +/* ArchivalUrl + * + * $Id$: + * + * Created on Jun 4, 2010. + * + * 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.archivalurl; + +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.util.url.UrlOperations; + +/** + * @author brad + * + */ +public class ArchivalUrl { + public final static String STAR = "*"; + private WaybackRequest wbRequest; +// public ArchivalUrl(String path) { +// +// } + public ArchivalUrl(WaybackRequest wbRequest) { + this.wbRequest = wbRequest; + } + + public String toString() { + if(wbRequest.isReplayRequest()) { + return toReplayString(wbRequest.getRequestUrl()); + } else if(wbRequest.isCaptureQueryRequest()) { + return toQueryString(wbRequest.getRequestUrl()); + } + return toPrefixQueryString(wbRequest.getRequestUrl()); + } + public String toPrefixQueryString(String url) { + return toQueryString("url" + STAR); + } + public String toQueryString(String url) { + String datespec = STAR; + if((wbRequest.getStartTimestamp() != null) && + (wbRequest.getEndTimestamp() != null)) { + datespec = String.format("%s-%s%s", + wbRequest.getStartTimestamp(),wbRequest.getEndTimestamp(), + STAR); + } + return toString(datespec,url); + } + + public String toReplayString(String url) { + return toString(wbRequest.getReplayTimestamp(),url); + } + + public String toString(String datespec, String url) { + StringBuilder sb = + new StringBuilder(url.length() + datespec.length()+10); + sb.append(datespec); + if(wbRequest.isCSSContext()) { + sb.append(ArchivalUrlRequestParser.CSS_CONTEXT); + sb.append(ArchivalUrlRequestParser.FLAG_DELIM); + } + if(wbRequest.isJSContext()) { + sb.append(ArchivalUrlRequestParser.JS_CONTEXT); + sb.append(ArchivalUrlRequestParser.FLAG_DELIM); + } + if(wbRequest.isIMGContext()) { + sb.append(ArchivalUrlRequestParser.IMG_CONTEXT); + sb.append(ArchivalUrlRequestParser.FLAG_DELIM); + } + if(wbRequest.isIdentityContext()) { + sb.append(ArchivalUrlRequestParser.IDENTITY_CONTEXT); + sb.append(ArchivalUrlRequestParser.FLAG_DELIM); + } + sb.append("/"); + sb.append(UrlOperations.stripDefaultPortFromUrl(url)); + return sb.toString(); + } +} Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrl.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Id Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlRequestParser.java 2010-06-05 01:16:53 UTC (rev 3150) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlRequestParser.java 2010-06-05 01:20:16 UTC (rev 3151) @@ -25,6 +25,7 @@ package org.archive.wayback.archivalurl; import org.archive.wayback.RequestParser; +import org.archive.wayback.archivalurl.requestparser.ArchivalUrlFormRequestParser; import org.archive.wayback.archivalurl.requestparser.DatelessReplayRequestParser; import org.archive.wayback.archivalurl.requestparser.PathDatePrefixQueryRequestParser; import org.archive.wayback.archivalurl.requestparser.PathDateRangeQueryRequestParser; @@ -77,7 +78,7 @@ new PathPrefixDatePrefixQueryRequestParser(this), new PathPrefixDateRangeQueryRequestParser(this), new OpenSearchRequestParser(this), - new FormRequestParser(this), + new ArchivalUrlFormRequestParser(this), new DatelessReplayRequestParser(this) }; return theParsers; Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ArchivalUrlFormRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ArchivalUrlFormRequestParser.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ArchivalUrlFormRequestParser.java 2010-06-05 01:20:16 UTC (rev 3151) @@ -0,0 +1,73 @@ +/* ArchivalUrlFormRequestParser + * + * $Id$: + * + * Created on Jun 4, 2010. + * + * 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.archivalurl.requestparser; + +import javax.servlet.http.HttpServletRequest; + +import org.archive.wayback.archivalurl.ArchivalUrl; +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BetterRequestException; +import org.archive.wayback.requestparser.BaseRequestParser; +import org.archive.wayback.requestparser.FormRequestParser; +import org.archive.wayback.webapp.AccessPoint; + +/** + * @author brad + * + */ +public class ArchivalUrlFormRequestParser extends FormRequestParser { + /** + * @param wrapped BaseRequestParser to wrap + */ + public ArchivalUrlFormRequestParser(BaseRequestParser wrapped) { + super(wrapped); + } + public WaybackRequest parse(HttpServletRequest httpRequest, + AccessPoint accessPoint) throws BetterRequestException { + WaybackRequest wbRequest = super.parse(httpRequest, accessPoint); + if(wbRequest != null) { + String replayTimestamp = wbRequest.getReplayTimestamp(); + if((replayTimestamp != null) && replayTimestamp.length() == 0) { + // lets call it a star query: + // TODO: should we clone? + wbRequest.setStartTimestamp(null); + wbRequest.setEndTimestamp(null); + } + String requestPath = + accessPoint.translateRequestPathQuery(httpRequest); + ArchivalUrl aUrl = new ArchivalUrl(wbRequest); + String bestPath = aUrl.toString(); + if(!bestPath.equals(requestPath)) { + String betterURI = (wbRequest.isReplayRequest() ? + accessPoint.getReplayPrefix() : + accessPoint.getQueryPrefix()) + + bestPath; + throw new BetterRequestException(betterURI); + } + } + return wbRequest; + } +} Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/ArchivalUrlFormRequestParser.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |