You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(10) |
Sep
(36) |
Oct
(339) |
Nov
(103) |
Dec
(152) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(141) |
Feb
(102) |
Mar
(125) |
Apr
(203) |
May
(57) |
Jun
(30) |
Jul
(139) |
Aug
(46) |
Sep
(64) |
Oct
(105) |
Nov
(34) |
Dec
(162) |
| 2007 |
Jan
(81) |
Feb
(57) |
Mar
(141) |
Apr
(72) |
May
(9) |
Jun
(1) |
Jul
(144) |
Aug
(88) |
Sep
(40) |
Oct
(43) |
Nov
(34) |
Dec
(20) |
| 2008 |
Jan
(44) |
Feb
(45) |
Mar
(16) |
Apr
(36) |
May
(8) |
Jun
(77) |
Jul
(177) |
Aug
(66) |
Sep
(8) |
Oct
(33) |
Nov
(13) |
Dec
(37) |
| 2009 |
Jan
(2) |
Feb
(5) |
Mar
(8) |
Apr
|
May
(36) |
Jun
(19) |
Jul
(46) |
Aug
(8) |
Sep
(1) |
Oct
(66) |
Nov
(61) |
Dec
(10) |
| 2010 |
Jan
(13) |
Feb
(16) |
Mar
(38) |
Apr
(76) |
May
(47) |
Jun
(32) |
Jul
(35) |
Aug
(45) |
Sep
(20) |
Oct
(61) |
Nov
(24) |
Dec
(16) |
| 2011 |
Jan
(22) |
Feb
(34) |
Mar
(11) |
Apr
(8) |
May
(24) |
Jun
(23) |
Jul
(11) |
Aug
(42) |
Sep
(81) |
Oct
(48) |
Nov
(21) |
Dec
(20) |
| 2012 |
Jan
(30) |
Feb
(25) |
Mar
(4) |
Apr
(6) |
May
(1) |
Jun
(5) |
Jul
(5) |
Aug
(8) |
Sep
(6) |
Oct
(6) |
Nov
|
Dec
|
|
From: <bra...@us...> - 2010-04-27 22:45:47
|
Revision: 3080
http://archive-access.svn.sourceforge.net/archive-access/?rev=3080&view=rev
Author: bradtofel
Date: 2010-04-27 22:45:40 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
JAVADOC
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/PerformanceLogger.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackCollection.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/PerformanceLogger.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/PerformanceLogger.java 2010-04-27 22:35:18 UTC (rev 3079)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/PerformanceLogger.java 2010-04-27 22:45:40 UTC (rev 3080)
@@ -28,6 +28,9 @@
import org.apache.log4j.Logger;
/**
+ * Brutally simple, barely functional class to allow simple recording of
+ * millisecond level timing within a particular request, enabling rough logging
+ * of the time spent in various parts of the handling of a WaybackRequest
* @author brad
*
*/
@@ -42,19 +45,41 @@
private long query = 0;
private long retrieve = -1;
private long render = 0;
+ /**
+ * Construct a Performance logger with the specified String "type"
+ * @param type the String type to report with the logged output
+ */
public PerformanceLogger(String type) {
this.type = type;
this.start = System.currentTimeMillis();
}
+ /**
+ * record the time when the query associated with this request completed
+ */
public void queried() {
this.query = System.currentTimeMillis();
}
+ /**
+ * record the time when the retrieval of a Resource required for this
+ * request completed, implies a Replay request...
+ */
public void retrieved() {
this.retrieve = System.currentTimeMillis();
}
+ /**
+ * record the time when the replayed resource, or the query results were
+ * returned to the client, implies the bulk of the request processing is
+ * complete.
+ */
public void rendered() {
this.render = System.currentTimeMillis();
}
+ /**
+ * Produce a debug message to this classes logger, computing the time
+ * taken to query the index, retrieve the resource (if a replay request)
+ * and render the results to the client.
+ * @param info String suffix to append to the log message
+ */
public void write(String info) {
StringBuilder sb = new StringBuilder(40);
sb.append(type).append(delim);
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 2010-04-27 22:35:18 UTC (rev 3079)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackCollection.java 2010-04-27 22:45:40 UTC (rev 3080)
@@ -33,8 +33,8 @@
import org.archive.wayback.exception.ConfigurationException;
/**
- * Abstraction point for sharing document collection and index across multiple
- * AccessPoints.
+ * Composite class containing a ResourceStore, and a ResourceIndex, to simplify
+ * sharing them as a pair across multiple AccessPoints.
*
* @author brad
* @version $Date$, $Revision$
@@ -45,6 +45,10 @@
private List<Shutdownable> shutdownables = null;
private boolean shutdownDone = false;
+ /**
+ * close/release any resources held by this WaybackCollection
+ * @throws IOException when thrown by an internal class being shut down.
+ */
public void shutdown() throws IOException {
if(shutdownDone) {
return;
@@ -63,29 +67,51 @@
shutdownDone = true;
}
+ /**
+ * @return the ResourceStore used with this WaybackCollection
+ * @throws ConfigurationException if none is configured
+ */
public ResourceStore getResourceStore() throws ConfigurationException {
if(resourceStore == null) {
throw new ConfigurationException("No resourceStore declared");
}
return resourceStore;
}
+ /**
+ * @param resourceStore the ResourceStore to use with this WaybackCollection
+ */
public void setResourceStore(ResourceStore resourceStore) {
this.resourceStore = resourceStore;
}
+ /**
+ * @return the ResourceIndex used with this WaybackCollection
+ * @throws ConfigurationException if none is configured
+ */
public ResourceIndex getResourceIndex() throws ConfigurationException {
if(resourceIndex == null) {
throw new ConfigurationException("No resourceIndex declared");
}
return resourceIndex;
}
+ /**
+ * @param resourceIndex the ResourceIndex to use with this WaybackCollection
+ */
public void setResourceIndex(ResourceIndex resourceIndex) {
this.resourceIndex = resourceIndex;
}
+ /**
+ * @return List of Shutdownable objects associated with this
+ * WaybackCollection, or null, if none are configured
+ */
public List<Shutdownable> getShutdownables() {
return shutdownables;
}
+ /**
+ * @param shutdownables set a List of Shutdownable objects associated with
+ * this WaybackCollection
+ */
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.
|
Revision: 3079
http://archive-access.svn.sourceforge.net/archive-access/?rev=3079&view=rev
Author: bradtofel
Date: 2010-04-27 22:35:18 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
TODO Comment
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java 2010-04-27 22:34:03 UTC (rev 3078)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java 2010-04-27 22:35:18 UTC (rev 3079)
@@ -77,6 +77,8 @@
public static String getRequiredMapParam(Map<String,String[]> queryMap,
String field)
throws BadQueryException {
+ // TODO: Throw something different, org.archive.wayback.util should have
+ // no references outside of org.archive.wayback.util
String value = getMapParam(queryMap,field);
if(value == null) {
throw new BadQueryException("missing field " + field);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
Revision: 3078
http://archive-access.svn.sourceforge.net/archive-access/?rev=3078&view=rev
Author: bradtofel
Date: 2010-04-27 22:34:03 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
REFACTOR: moved HTTP GET form parsing static helper methods to this class
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java 2010-04-27 22:19:46 UTC (rev 3077)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java 2010-04-27 22:34:03 UTC (rev 3078)
@@ -3,10 +3,14 @@
*/
package org.archive.wayback.util.webapp;
+import java.util.Map;
+
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
+import org.archive.wayback.exception.BadQueryException;
+
/**
* Abstract RequestHandler implementation which performs the minimal behavior
* for self registration with a RequestMapper, requiring subclasses to implement
@@ -44,4 +48,55 @@
public String translateRequestPathQuery(HttpServletRequest httpRequest) {
return RequestMapper.getRequestContextPathQuery(httpRequest);
}
+
+ /**
+ * Extract the first value in the array mapped to by field in queryMap
+ * @param queryMap the Map in which to search
+ * @param field the field value desired
+ * @return the first value in the array mapped to field in queryMap, if
+ * present, null otherwise
+ */
+ public static String getMapParam(Map<String,String[]> queryMap,
+ String field) {
+ String arr[] = queryMap.get(field);
+ if (arr == null || arr.length == 0) {
+ return null;
+ }
+ return arr[0];
+ }
+
+ /**
+ * Extract the first value in the array mapped to by field in queryMap
+ * @param queryMap the Map in which to search
+ * @param field the field value desired
+ * @return the first value in the array mapped to field in queryMap, if
+ * present. A BadQueryException is thrown if there is no appropriate value
+ * @throws BadQueryException if there is nothing mapped to field, or if the
+ * Array mapped to field is empty
+ */
+ public static String getRequiredMapParam(Map<String,String[]> queryMap,
+ String field)
+ throws BadQueryException {
+ String value = getMapParam(queryMap,field);
+ if(value == null) {
+ throw new BadQueryException("missing field " + field);
+ }
+ if(value.length() == 0) {
+ throw new BadQueryException("empty field " + field);
+ }
+ return value;
+ }
+
+ /**
+ * Extract the first value in the array mapped to by field in queryMap
+ * @param map the Map in which to search
+ * @param param the field value desired
+ * @return the first value in the array mapped to field in queryMap, if
+ * present, or an empty string otherwise
+ */
+ public static String getMapParamOrEmpty(Map<String,String[]> map,
+ String param) {
+ String val = getMapParam(map,param);
+ return (val == null) ? "" : val;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-27 22:19:52
|
Revision: 3077
http://archive-access.svn.sourceforge.net/archive-access/?rev=3077&view=rev
Author: bradtofel
Date: 2010-04-27 22:19:46 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
DELETED. Superceded by AccessControlOracle
Removed Paths:
-------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-27 22:18:51
|
Revision: 3076
http://archive-access.svn.sourceforge.net/archive-access/?rev=3076&view=rev
Author: bradtofel
Date: 2010-04-27 22:18:44 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
DELETED. Superceded by AccessControlOracle
Removed 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/accesscontrol/ui/AdministrativeExclusionRule.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionRules.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/accesscontrol/ui/ExclusionAuthority.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionResponse.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionServlet.java
Deleted: 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 2010-04-27 22:14:50 UTC (rev 3075)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionAuthority.java 2010-04-27 22:18:44 UTC (rev 3076)
@@ -1,169 +0,0 @@
-/* AdministrativeExclusionAuthority
- *
- * $Id$
- *
- * Created on 2:47:39 PM May 10, 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.accesscontrol.ui;
-
-import java.util.ArrayList;
-
-import org.apache.commons.httpclient.URIException;
-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;
-
-
-/**
- *
- * @deprecated superseded by ExclusionOracle
- * @author brad
- * @version $Date$, $Revision$
- */
-public class AdministrativeExclusionAuthority implements ExclusionAuthority {
-
- // TODO: read from ResounceBundle
- private static String ADMIN_NO_ROBOTS_MSG = "Administrative Robots Ignore:";
- private static String ADMIN_INCLUDE_MSG = "Administrative Include:";
- private static String ADMIN_EXCLUDE_MSG = "Administrative Exclude:";
-
-// RoboCache roboCache;
- private BDBRecordSet db = null;
-
- /* (non-Javadoc)
- * @see org.archive.wayback.accesscontrol.ExclusionAuthority#checkExclusion(java.lang.String, java.lang.String, java.lang.String)
- */
- public ExclusionResponse checkExclusion(String userAgent, String urlString,
- String captureDate) throws Exception {
- SURTTokenizer tokenizer;
- try {
- tokenizer = new SURTTokenizer(urlString);
- } catch (URIException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- throw new Exception(e);
- }
-
- while(true) {
- String surtPrefix = tokenizer.nextSearch();
- if(surtPrefix == null) {
- break;
- }
- AdministrativeExclusionRule rule = getRuleFor(surtPrefix,captureDate);
- if(rule != null) {
- if(rule.isRobots()) {
- break;
- } else if(rule.isNoRobots()) {
- return new ExclusionResponse("-",
- ExclusionResponse.EXLCUSION_AUTHORITATIVE,
- ExclusionResponse.EXLCUSION_AUTHORIZED,
- ADMIN_NO_ROBOTS_MSG + rule.getWhy());
- } else if(rule.isInclude()) {
- return new ExclusionResponse("-",
- ExclusionResponse.EXLCUSION_AUTHORITATIVE,
- ExclusionResponse.EXLCUSION_AUTHORIZED,
- ADMIN_INCLUDE_MSG + rule.getWhy());
- } else if(rule.isExclude()) {
- return new ExclusionResponse("-",
- ExclusionResponse.EXLCUSION_AUTHORITATIVE,
- ExclusionResponse.EXLCUSION_NOT_AUTHORIZED,
- ADMIN_EXCLUDE_MSG + rule.getWhy());
- } else {
- // whoops.. how'd this happen.. just ignore it.
- }
- }
- }
-
- // we only get here when we are suppose to return the value from the
- // current robots.txt document:
-// return roboCache.checkExclusion(userAgent,urlString,captureDate);
- return null;
- }
-
- /**
- * @param surt to check
- * @return String representation of rules
- * @throws DatabaseException if BDB problems.
- */
- public ArrayList<AdministrativeExclusionRules> matchRules(String surt) throws DatabaseException {
- BDBRecordIterator itr = db.recordIterator(surt);
- ArrayList<AdministrativeExclusionRules> matching =
- new ArrayList<AdministrativeExclusionRules>();
- while(itr.hasNext()) {
- BDBRecord record = (BDBRecord) itr.next();
- AdministrativeExclusionRules rules = recordToRules(record);
- if(rules.getSurtPrefix().startsWith(surt)) {
- matching.add(rules);
- }
- }
- return matching;
- }
-
- private AdministrativeExclusionRules recordToRules(BDBRecord record) {
- String surtPrefix = new String(record.getKey().getData());
- String encodedRules = new String(record.getValue().getData());
- AdministrativeExclusionRules rules = new AdministrativeExclusionRules(surtPrefix);
- rules.loadRules(encodedRules);
- return rules;
- }
-
- private AdministrativeExclusionRule getRuleFor(final String surtPrefix,
- final String dateStr) throws DatabaseException {
- AdministrativeExclusionRules rules = new AdministrativeExclusionRules(surtPrefix);
- String encoded = (String) db.get(surtPrefix);
- if(encoded != null) {
- rules.loadRules(encoded);
- }
- return rules.getApplicableRule(dateStr);
- }
-
- /**
- * @param surtPrefix to add
- * @param rule for SURT
- * @throws DatabaseException on BDB errors
- */
- public void addRuleFor(final String surtPrefix, AdministrativeExclusionRule rule) throws DatabaseException {
- AdministrativeExclusionRules rules = new AdministrativeExclusionRules(surtPrefix);
- String encoded = (String) db.get(surtPrefix);
- if(encoded != null) {
- rules.loadRules(encoded);
- }
- rules.addRule(rule);
- db.put(surtPrefix,rules.encodeRules());
- }
-
- /**
- * @return the db
- */
- public BDBRecordSet getDb() {
- return db;
- }
-
- /**
- * @param db the db to set
- */
- public void setDb(BDBRecordSet db) {
- this.db = db;
- }
-}
Deleted: 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 2010-04-27 22:14:50 UTC (rev 3075)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionRule.java 2010-04-27 22:18:44 UTC (rev 3076)
@@ -1,333 +0,0 @@
-/* AdministrativeExclusionRuling
- *
- * $Id$
- *
- * Created on 11:20:22 AM May 11, 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.accesscontrol.ui;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.text.ParseException;
-
-import org.archive.wayback.util.Timestamp;
-
-/**
- *
- *
- * @deprecated superseded by ExclusionOracle
- * @author brad
- * @version $Date$, $Revision$
- */
-public class AdministrativeExclusionRule {
-
-//
-// VALUE: <RULE>[,VALUE]
-// RULE: <TS-START>-<TS-END>:<TYPE>:<MOD>:<WHO>:<WHEN>:<COMMENT>
-// TS-START: [0-9]{0,14}
-// TS-END: [0-9]{0,14}
-// TYPE: ROBOTS|NOROBOTS|EXCLUDE|INCLUDE
-// MOD: ADD|DELETE
-// WHO: hex-encoded email address of person who create this rule
-// WHEN: seconds since epoch when this rule was submitted
-// COMMENT: hex-encoded string arbitrary comment
-
- private final static char SEPARATOR = ':';
- private final static String ENCODING = "UTF-8";
-
- private final static int TYPE_ROBOTS = 0;
- private final static int TYPE_NOROBOTS = 1;
- private final static int TYPE_INCLUDE = 2;
- private final static int TYPE_EXCLUDE = 3;
-
- private final static int MOD_ADD = 0;
- private final static int MOD_DELETE = 1;
-
- private String startDateStr;
- private String endDateStr;
- private int type;
- private int mod;
- private String who;
- private long when;
- private String why;
-
- /**
- * @return string "key" including start, end and type information
- */
- public String key() {
- return startDateStr + SEPARATOR + endDateStr + SEPARATOR + type;
- }
-
- /**
- * sets type to Robots
- */
- public void setRobots() {
- type = TYPE_ROBOTS;
- }
- /**
- * sets type to NoRobots
- */
- public void setNoRobots() {
- type = TYPE_NOROBOTS;
- }
- /**
- * sets type to Include
- */
- public void setInclude() {
- type = TYPE_INCLUDE;
- }
- /**
- * sets type to Exclude
- */
- public void setExclude() {
- type = TYPE_EXCLUDE;
- }
- /**
- * sets mod to ADD
- */
- public void setAdd() {
- mod = MOD_ADD;
- }
- /**
- * sets mod to DELETE
- */
- public void setDelete() {
- mod = MOD_DELETE;
- }
-
- /**
- * extract values from this object into encoded String representation
- *
- * @return String representation of values in this object
- */
- public String encode() {
- StringBuilder encoded = new StringBuilder(100);
- try {
- encoded.append(startDateStr).append(SEPARATOR);
- encoded.append(endDateStr).append(SEPARATOR);
- encoded.append(type).append(SEPARATOR);
- encoded.append(mod).append(SEPARATOR);
- encoded.append(URLEncoder.encode(who,ENCODING)).append(SEPARATOR);
- encoded.append(when).append(SEPARATOR);
- encoded.append(URLEncoder.encode(why,ENCODING));
- } catch (UnsupportedEncodingException e) {
- // this should not happen with a hard-coded UTF-8...
- e.printStackTrace();
- }
- return encoded.toString();
- }
-
- /**
- * set all values from encoded String version
- *
- * @param encoded rule
- * @throws ParseException if rule cannot be parsed
- */
- public void decode(final String encoded) throws ParseException {
- String parts[] = encoded.split(String.valueOf(SEPARATOR));
- if(parts.length != 7) {
- throw new ParseException("Unable decode (" + encoded + ")",0);
- }
- startDateStr = Timestamp.padStartDateStr(parts[0]);
- endDateStr = Timestamp.padStartDateStr(parts[1]);
- type = Integer.valueOf(parts[2]).intValue();
- if(type < TYPE_ROBOTS || type > TYPE_EXCLUDE) {
- throw new ParseException("bad type in (" + encoded + ")",3);
- }
- mod = Integer.valueOf(parts[3]).intValue();
- if(mod < MOD_ADD || mod > MOD_DELETE) {
- throw new ParseException("bad mod in (" + encoded + ")",4);
- }
- try {
- who = URLDecoder.decode(parts[4],ENCODING);
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- throw new ParseException(e.getMessage(),5);
- }
- when = Long.valueOf(parts[5]).longValue();
- try {
- why = URLDecoder.decode(parts[6],ENCODING);
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- throw new ParseException(e.getMessage(),7);
- }
- }
-
- /**
- * @return Returns the when.
- */
- public long getWhen() {
- return when;
- }
- /**
- * @param when The when to set.
- */
- public void setWhen(long when) {
- this.when = when;
- }
- /**
- * @return Returns the who.
- */
- public String getWho() {
- return who;
- }
- /**
- * @param who The who to set.
- */
- public void setWho(String who) {
- this.who = who;
- }
- /**
- * @return Returns the why.
- */
- public String getWhy() {
- return why;
- }
- /**
- * @param why The why to set.
- */
- public void setWhy(String why) {
- this.why = why;
- }
- /**
- * @return true if this is an ADD rule
- */
- public boolean isAdd() {
- return mod == MOD_ADD;
- }
- /**
- * @return true if this is a DELETE rule
- */
- public boolean isDelete() {
- return mod == MOD_DELETE;
- }
- /**
- * @return true if this is a ROBOTS rule
- */
- public boolean isRobots() {
- return type == TYPE_ROBOTS;
- }
- /**
- * @return true if this is a NOROBOTS rule
- */
- public boolean isNoRobots() {
- return type == TYPE_NOROBOTS;
- }
- /**
- * @return true if this is an INCLUDE rule
- */
- public boolean isInclude() {
- return type == TYPE_INCLUDE;
- }
- /**
- * @return true if this is an EXCLUDE rule
- */
- public boolean isExclude() {
- return type == TYPE_EXCLUDE;
- }
-
- /**
- * @return String user friendly version of the mod
- */
- public String getPrettyMod() {
- if(mod == MOD_ADD) {
- return "add";
- }
- return "delete";
- }
- /**
- * @return pretty String representation of the Type
- */
- public String getPrettyType() {
- String prettyType = null;
- switch (type) {
- case TYPE_INCLUDE:
- prettyType = "Include";
- break;
- case TYPE_EXCLUDE:
- prettyType = "Exclude";
- break;
- case TYPE_ROBOTS:
- prettyType = "Use Robots";
- break;
- case TYPE_NOROBOTS:
- prettyType = "No Robots";
- break;
- default:
- break;
- }
- return prettyType;
- }
-
- /**
- * @return Returns the endDateStr.
- */
- public String getEndDateStr() {
- return endDateStr;
- }
-
- /**
- * @return Returns pretty version of the endDateStr.
- */
- public String getPrettyEndDateStr() {
- // TODO: Localization
- return Timestamp.parseAfter(endDateStr).prettyDateTime();
- }
- /**
- * @return Returns pretty version of the startDateStr.
- */
- public String getPrettyStartDateStr() {
- // TODO: Localization
- return Timestamp.parseBefore(startDateStr).prettyDateTime();
- }
-
- /**
- * @param endDateStr The endDateStr to set.
- */
- public void setEndDateStr(String endDateStr) {
- this.endDateStr = endDateStr;
- }
-
- /**
- * @return Returns the startDateStr.
- */
- public String getStartDateStr() {
- return startDateStr;
- }
-
- /**
- * @param startDateStr The startDateStr to set.
- */
- public void setStartDateStr(String startDateStr) {
- this.startDateStr = startDateStr;
- }
-
- /**
- * @param arg a dateString (possibly < 14 digits)
- * @return true if arg is in range to which this rule applies
- */
- public boolean appliesToDateStr(final String arg) {
- return (arg.compareTo(startDateStr.substring(0,arg.length())) >= 0 )
- && (arg.compareTo(endDateStr.substring( 0,arg.length())) <= 0 );
- }
-
-}
Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionRules.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionRules.java 2010-04-27 22:14:50 UTC (rev 3075)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionRules.java 2010-04-27 22:18:44 UTC (rev 3076)
@@ -1,233 +0,0 @@
-/* AdministrativeExclusionRules
- *
- * $Id$
- *
- * Created on 12:28:48 PM May 11, 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.accesscontrol.ui;
-
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-
-/**
- *
- *
- * @deprecated superseded by ExclusionOracle
- * @author brad
- * @version $Date$, $Revision$
- */
-public class AdministrativeExclusionRules {
-
- private static String DELIMITER = ",";
- private ArrayList<AdministrativeExclusionRule> rules = null;
- private String surtPrefix;
- /**
- * @param surtPrefix for rules
- */
- public AdministrativeExclusionRules(String surtPrefix) {
- this.surtPrefix = surtPrefix;
- }
- /**
- * prune down rules to only those which apply for a particular timestamp
- * first eliminating those outside the timestamp range, and then removing
- * ADD which have a (subsequent) DELETE
- *
- * @param dateStr to check
- * @return ArrayList of applicable and current rules for dateStr
- */
- public ArrayList<AdministrativeExclusionRule> filterRules(final String
- dateStr) {
-
- if(rules == null) {
- return new ArrayList<AdministrativeExclusionRule>();
- }
-
- // first separate the rules into ADD and DELETE, only keeping the newest
- // for any START-END-TYPE
-
- HashMap<String, AdministrativeExclusionRule> adds =
- new HashMap<String, AdministrativeExclusionRule>();
-
- HashMap<String, AdministrativeExclusionRule> deletes =
- new HashMap<String, AdministrativeExclusionRule>();
- HashMap<String, AdministrativeExclusionRule> cur = null;
-
- for(int i = 0; i < rules.size(); i++) {
- AdministrativeExclusionRule rule = rules.get(i);
- if(!rule.appliesToDateStr(dateStr)) {
- continue;
- }
- String key = rule.key();
- if(rule.isAdd()) {
- cur = adds;
- } else {
- cur = deletes;
- }
- if(cur.containsKey(key)) {
- AdministrativeExclusionRule last =
- (AdministrativeExclusionRule) cur.get(key);
- if(rule.getWhen() > last.getWhen()) {
- cur.put(key,rule);
- }
- } else {
- cur.put(key,rule);
- }
- }
-
- // now, remove any ADD for which there is a later DELETE:
-
- Iterator<AdministrativeExclusionRule> itr = deletes.values().iterator();
- while(itr.hasNext()) {
- AdministrativeExclusionRule deleteRule = itr.next();
- String key = deleteRule.key();
- if(adds.containsKey(key)) {
- AdministrativeExclusionRule addRule = adds.get(key);
- if(deleteRule.getWhen() > addRule.getWhen()) {
- adds.remove(key);
- }
- }
- }
-
- // now the "adds" HashMap contains only rules that apply now, for the
- // current time we are interested in.
-
- return new ArrayList<AdministrativeExclusionRule>(adds.values());
- }
-
- /**
- * finds the most applicable rule for the date in question, and returns it
- *
- * @param dateStr to check
- * @return most applicable AdministrativeExclusionRule, or null if none
- * applied
- */
- public AdministrativeExclusionRule getApplicableRule(final String dateStr) {
- ArrayList<AdministrativeExclusionRule> applicable = filterRules(dateStr);
- // first look for Excludes:
- Iterator<AdministrativeExclusionRule> itr = applicable.iterator();
- while(itr.hasNext()) {
- AdministrativeExclusionRule rule = itr.next();
- if(rule.isExclude()) {
- return rule;
- }
- }
- // then Includes:
- itr = applicable.iterator();
- while(itr.hasNext()) {
- AdministrativeExclusionRule rule =
- (AdministrativeExclusionRule) itr.next();
- if(rule.isInclude()) {
- return rule;
- }
- }
- // then NoRobots:
- itr = applicable.iterator();
- while(itr.hasNext()) {
- AdministrativeExclusionRule rule =
- (AdministrativeExclusionRule) itr.next();
- if(rule.isNoRobots()) {
- return rule;
- }
- }
- // then Robots:
- itr = applicable.iterator();
- while(itr.hasNext()) {
- AdministrativeExclusionRule rule =
- (AdministrativeExclusionRule) itr.next();
- if(rule.isRobots()) {
- return rule;
- }
- }
- // nothing:
- return null;
- }
-
- /**
- * load rules found in the encoded string argument
- *
- * @param encodedRules string
- */
- public void loadRules(final String encodedRules) {
- rules = new ArrayList<AdministrativeExclusionRule>();
- String ruleChunks[] = encodedRules.split(DELIMITER);
- for(int i = 0; i < ruleChunks.length; i++) {
- AdministrativeExclusionRule rule = parseRule(ruleChunks[i]);
- if(rule != null) {
- rules.add(rule);
- }
- }
- }
-
- /**
- * @param rule to add
- */
- public void addRule(AdministrativeExclusionRule rule) {
- if(rules == null) {
- rules = new ArrayList<AdministrativeExclusionRule>();
- }
- rules.add(rule);
- }
-
- /**
- * @return String encoded version of the rules.
- */
- public String encodeRules() {
- if(rules == null) {
- return "";
- }
- StringBuilder builder = new StringBuilder(rules.size() * 120);
- Iterator<AdministrativeExclusionRule> itr = rules.iterator();
- while(itr.hasNext()) {
- AdministrativeExclusionRule rule = itr.next();
- if(builder.length() > 0) {
- builder.append(DELIMITER);
- }
- builder.append(rule.encode());
- }
- return builder.toString();
- }
-
- private AdministrativeExclusionRule parseRule(final String encoded) {
- AdministrativeExclusionRule rule = new AdministrativeExclusionRule();
- try {
- rule.decode(encoded);
- return rule;
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * @return Returns the surtPrefix.
- */
- public String getSurtPrefix() {
- return surtPrefix;
- }
- /**
- * @return Returns the rules.
- */
- public ArrayList<AdministrativeExclusionRule> getRules() {
- return rules;
- }
-}
Deleted: 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 2010-04-27 22:14:50 UTC (rev 3075)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/AdministrativeExclusionServlet.java 2010-04-27 22:18:44 UTC (rev 3076)
@@ -1,526 +0,0 @@
-/* AdministrativeExclusionServlet
- *
- * $Id$
- *
- * Created on 4:31:48 PM May 12, 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.accesscontrol.ui;
-
-import java.io.IOException;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.httpclient.URIException;
-import org.archive.wayback.surt.SURTTokenizer;
-import org.archive.wayback.util.Timestamp;
-import org.archive.wayback.webapp.ServletRequestContext;
-
-import com.sleepycat.je.DatabaseException;
-
-/**
- * Servlet responsible for UI generation of the Administrative Exclustion
- * system.
- *
- * Primarily this includes:
- * 1) generating query form
- * 2) displaying current exclusion rules based on queries
- * 3) recieving POST requests from clients to add rules
- *
- * @deprecated superseded by ExclusionOracle
- * @author brad
- * @version $Date$, $Revision$
- */
-public class AdministrativeExclusionServlet extends ServletRequestContext {
-
- private static final String DEFAULT_USER_AGENT = "ia_archiver";
- private static final String HTML_BR = "<br></br>";
- private static final long serialVersionUID = 1L;
-
- private static String FORM_OPERATION = "operation";
-
- private static String MODIFY_FORM_START = "start";
- private static String MODIFY_FORM_END = "end";
- private static String MODIFY_FORM_URL = "modify_url";
- private static String MODIFY_FORM_SURT = "modify_surt";
- private static String MODIFY_FORM_TYPE = "type";
- private static String MODIFY_FORM_MOD = "mod";
- private static String MODIFY_FORM_WHO = "who";
- private static String MODIFY_FORM_WHY = "why";
- private static String MODIFY_FORM_PREFIX = "prefix";
-
-
- private static String DELETE_FORM_OPERATION = "delete";
- private static String MODIFY_FORM_OPERATION = "modify";
-
- private static String MODIFY_FORM_MOD_ADD_VALUE = "add";
- private static String MODIFY_FORM_MOD_DELETE_VALUE = "delete";
-
- private static String MODIFY_FORM_TYPE_EXCLUDE_VALUE = "exclude";
- private static String MODIFY_FORM_TYPE_INCLUDE_VALUE = "include";
- private static String MODIFY_FORM_TYPE_NOROBOTS_VALUE = "norobots";
- private static String MODIFY_FORM_TYPE_ROBOTS_VALUE = "robots";
-
- private static String MODIFY_FORM_PREFIX_YES_VALUE = "yes";
-
- private static String QUERY_FORM_URL = "query_url";
- private static String QUERY_FORM_ALL = "query_all";
- private static String QUERY_FORM_ALL_VALUE = "yes";
- private static String QUERY_FORM_OPERATION = "query";
-
- private static String CHECK_FORM_URL = "check_url";
- private static String CHECK_FORM_TIMESTAMP = "timestamp";
- private static String CHECK_FORM_OPERATION = "check";
-
- private static final int RULE_STATUS_HEADER = -1;
- private static final int RULE_STATUS_ACTIVE = 0;
- private static final int RULE_STATUS_INACTIVE = 1;
- private static final int RULE_STATUS_DELETE = 2;
-
- private AdministrativeExclusionAuthority exclusionAuthority = null;
-
- private void showPage(HttpServletResponse response, StringBuilder page)
- throws IOException {
- response.setContentType("text/html");
- response.getOutputStream().print(page.toString());
- }
-
- private String formatException(Exception e) {
- return e.getMessage();
- }
-
- public boolean handleRequest(HttpServletRequest httpRequest,
- HttpServletResponse httpResponse) throws ServletException,
- IOException {
- AdministrativeExclusionAuthority exclAuth = exclusionAuthority;
-
- StringBuilder page = new StringBuilder(1024);
- page.append("<html><head><title>Wayback: Administrative Exclusions</title></head><body>");
- @SuppressWarnings("unchecked")
- Map<String,String[]> queryArgs = httpRequest.getParameterMap();
- String operation = getMapParam(queryArgs,FORM_OPERATION);
- if(operation == null) {
- page.append(makeCheckForm(queryArgs));
- page.append(makeQueryForm(queryArgs));
- page.append(makeCreateForm(queryArgs));
- } else if(operation.equals(QUERY_FORM_OPERATION)) {
- page.append(makeCheckForm(queryArgs));
- page.append(makeQueryForm(queryArgs));
- try {
- page.append(handleRuleQuery(exclAuth,queryArgs));
- } catch (URIException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- page.append(formatException(e));
- } catch (ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- page.append(formatException(e));
- } catch (DatabaseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- page.append(formatException(e));
- }
- page.append(makeCreateForm(queryArgs));
- } else if(operation.equals(CHECK_FORM_OPERATION)) {
- page.append(makeCheckForm(queryArgs));
- try {
- page.append(handleRuleCheck(exclAuth,queryArgs));
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- page.append(formatException(e));
- }
- page.append(makeQueryForm(queryArgs));
- page.append(makeCreateForm(queryArgs));
-
- } else if((operation.equals(MODIFY_FORM_OPERATION)
- || operation.equals(DELETE_FORM_OPERATION))) {
-
- try {
- handleRuleCreate(exclAuth,queryArgs);
- page.append("OK - added rule");
- } catch (URIException e) {
- e.printStackTrace();
- page.append(formatException(e));
- } catch (ParseException e) {
- e.printStackTrace();
- page.append(formatException(e));
- } catch (DatabaseException e) {
- e.printStackTrace();
- page.append(formatException(e));
- }
-
- } else {
- page.append("Unknown operation");
- }
- page.append("</body></html>");
- showPage(httpResponse,page);
- return true;
- }
-
- // HTML GENERATION METHODS:
-
- private String htmlEncode(String orig) {
- return orig;
- }
- private String propertyHTMLEncode(String orig) {
- return orig;
- }
-
- private String makeFormTextInput(String label, String name,
- Map<String,String[]> queryArgs,
- String suffix) {
- String value = "";
- if(queryArgs != null) {
- value = propertyHTMLEncode(getMapParamOrEmpty(queryArgs,name));
- }
- return label + ":<input type=\"text\" name=\"" + name + "\" VALUE=\"" +
- value + "\"></input>" + suffix;
- }
- private String makeFormTextAreaInput(String label, String name,
- Map<String,String[]> queryArgs, String suffix) {
- String value = "";
- if(queryArgs != null) {
- value = htmlEncode(getMapParamOrEmpty(queryArgs,name));
- }
- return label + ":<textarea cols=80 rows=4 name=\"" + name + "\">" +
- value + "</textarea>" + suffix;
- }
-
- private String makeFormCheckInput(String label, String name, String value,
- Map<String,String[]> queryArgs, String suffix) {
- String curValue = getMapParam(queryArgs,name);
- String checked = "";
- if(curValue != null && curValue.equals(value)) {
- checked = "checked";
- }
- return label + ":<input type=\"checkbox\" name=\"" + name + "\" VALUE=\"" +
- value + "\" " + checked + "></input>" + suffix;
- }
-
- private String makeHiddenInput(String name, String value) {
- return "<input type=\"hidden\" name=\"" + name + "\" value=\"" +
- propertyHTMLEncode(value) + "\"></input>";
- }
-
-
- private String makeForm(String method, String submitValue, String content) {
- StringBuilder sb = new StringBuilder(1024);
- sb.append("<form method=\"").append(method);
- sb.append("\" action=\"admin-exclusion\">\n");
- sb.append(content);
- sb.append("<input type=\"SUBMIT\" name=\"").append(FORM_OPERATION);
- sb.append("\" value=\"").append(submitValue).append("\"></input>\n");
- sb.append("</form>");
- return sb.toString();
- }
- private String makeHeaderForm(String title,String method, String submitValue,
- String content) {
- return "<hr></hr><p><h2>"+title+"</h2>" + makeForm(method,submitValue,content) + "</p>";
- }
-
- // CHECK FORM AND HANDLING
-
- private String makeCheckForm(Map<String,String[]> queryArgs) {
- String content = makeFormTextInput("Url",CHECK_FORM_URL,queryArgs," ") +
- makeFormTextInput("Timestamp",CHECK_FORM_TIMESTAMP,queryArgs," ");
- return makeHeaderForm("Test Exclusion","GET",CHECK_FORM_OPERATION,content);
- }
-
- private String handleRuleCheck(AdministrativeExclusionAuthority excl,
- Map<String,String[]> queryArgs) throws Exception {
- String url = getRequiredMapParam(queryArgs,CHECK_FORM_URL);
- String timestamp = getRequiredMapParam(queryArgs,CHECK_FORM_TIMESTAMP);
- String userAgent = DEFAULT_USER_AGENT;
-
- ExclusionResponse response = excl.checkExclusion(userAgent,url,timestamp);
- return response.getContentText();
- }
-
- // RULE QUERY FORM AND HANDLING
-
- private String makeQueryForm(Map<String,String[]> queryArgs) {
- StringBuilder content = new StringBuilder(1024);
- content.append(makeFormTextInput("Url",QUERY_FORM_URL,queryArgs,""));
- content.append(makeFormCheckInput("all",QUERY_FORM_ALL,QUERY_FORM_ALL_VALUE,queryArgs,""));
- return makeHeaderForm("Rule Query","GET",QUERY_FORM_OPERATION,content.toString());
- }
-
- private String handleRuleQuery(AdministrativeExclusionAuthority excl,
- Map<String,String[]> queryArgs) throws ParseException, URIException,
- DatabaseException {
- String url = getRequiredMapParam(queryArgs,QUERY_FORM_URL);
- String all = getMapParam(queryArgs,QUERY_FORM_ALL);
- boolean showAll = (all != null && all.equals(QUERY_FORM_ALL_VALUE));
- String surt = SURTTokenizer.prefixKey(url);
- ArrayList<AdministrativeExclusionRules> matching = excl.matchRules(surt);
- StringBuilder matchHTML = new StringBuilder();
- rulesToTable(matchHTML,matching,url,showAll);
- return matchHTML.toString();
- }
-
- private String ruleToType(AdministrativeExclusionRule rule) {
- String type = MODIFY_FORM_TYPE_EXCLUDE_VALUE;
- if(rule.isExclude()) {
- type = MODIFY_FORM_TYPE_EXCLUDE_VALUE;
- } else if(rule.isInclude()) {
- type = MODIFY_FORM_TYPE_INCLUDE_VALUE;
- } else if(rule.isNoRobots()) {
- type = MODIFY_FORM_TYPE_NOROBOTS_VALUE;
- } else if(rule.isRobots()) {
- type = MODIFY_FORM_TYPE_ROBOTS_VALUE;
- }
- return type;
- }
-
- // RULE DELETION/CREATION FORM AND HANDLING
-
- private String makeDeleteForm(String surt, AdministrativeExclusionRule rule) {
- StringBuilder sb = new StringBuilder(1024);
- sb.append(makeHiddenInput(MODIFY_FORM_SURT,surt));
- sb.append(makeHiddenInput(MODIFY_FORM_START,rule.getStartDateStr()));
- sb.append(makeHiddenInput(MODIFY_FORM_END,rule.getEndDateStr()));
- sb.append(makeHiddenInput(MODIFY_FORM_TYPE,ruleToType(rule)));
- sb.append(makeHiddenInput(MODIFY_FORM_MOD,MODIFY_FORM_MOD_DELETE_VALUE));
- sb.append(makeFormTextInput("Who",MODIFY_FORM_WHO,null," "));
- sb.append(makeFormTextInput("Why",MODIFY_FORM_WHY,null," "));
- return makeForm("POST", DELETE_FORM_OPERATION, sb.toString());
- }
-
- private String makeCreateForm(Map<String,String[]> queryArgs) {
- StringBuilder sb = new StringBuilder(1024);
- sb.append(makeFormTextInput("Url",MODIFY_FORM_URL,queryArgs,""));
- sb.append(makeFormCheckInput("(prefix)",MODIFY_FORM_PREFIX,
- MODIFY_FORM_PREFIX_YES_VALUE,queryArgs,HTML_BR));
-
- sb.append(makeFormTextInput("Start",MODIFY_FORM_START,queryArgs,""));
- sb.append(makeFormTextInput("End",MODIFY_FORM_END,queryArgs,HTML_BR));
-
- sb.append("Type: <select name=\""+MODIFY_FORM_TYPE+"\">" +
- "<option>"+MODIFY_FORM_TYPE_EXCLUDE_VALUE+"</option>" +
- "<option>"+MODIFY_FORM_TYPE_INCLUDE_VALUE+"</option>" +
- "<option>"+MODIFY_FORM_TYPE_ROBOTS_VALUE+"</option>" +
-// "<option>"+MODIFY_FORM_TYPE_NOROBOTS_VALUE+"</option>" +
- "</select>").append(HTML_BR).append("\n");
-
-// sb.append("Add/Remove: <select NAME=\""+MODIFY_FORM_MOD+"\">" +
-// "<option>"+MODIFY_FORM_MOD_ADD_VALUE+"</option>" +
-// "<option>"+MODIFY_FORM_MOD_DELETE_VALUE+"</option>" +
-// "</select><br></br>\n");
- sb.append(makeHiddenInput(MODIFY_FORM_MOD,MODIFY_FORM_MOD_ADD_VALUE));
-
- sb.append(makeFormTextInput("Who",MODIFY_FORM_WHO,queryArgs,HTML_BR));
- sb.append(makeFormTextAreaInput("Why",MODIFY_FORM_WHY,queryArgs,HTML_BR));
-
- return makeHeaderForm("Compose Rule","POST",MODIFY_FORM_OPERATION,
- sb.toString());
- }
-
- private void handleRuleCreate(AdministrativeExclusionAuthority auth,
- Map<String,String[]> queryMap) throws ParseException, URIException, DatabaseException {
-
- AdministrativeExclusionRule rule = new AdministrativeExclusionRule();
-
- String start = getRequiredMapParam(queryMap,MODIFY_FORM_START);
- String startDateStr = Timestamp.padStartDateStr(start);
- if(!startDateStr.equals(start)) {
- throw new ParseException("invalid value: " + MODIFY_FORM_START,0);
- }
-
- String end = getRequiredMapParam(queryMap,MODIFY_FORM_END);
- String endDateStr = Timestamp.padEndDateStr(end);
- if(!endDateStr.equals(end)) {
- throw new ParseException("invalid value: " + MODIFY_FORM_END,0);
- }
-
- String type = getRequiredMapParam(queryMap,MODIFY_FORM_TYPE);
- if(type.equals(MODIFY_FORM_TYPE_EXCLUDE_VALUE)) {
- rule.setExclude();
- } else if(type.equals(MODIFY_FORM_TYPE_INCLUDE_VALUE)) {
- rule.setInclude();
- } else if(type.equals(MODIFY_FORM_TYPE_ROBOTS_VALUE)) {
- rule.setRobots();
- } else if(type.equals(MODIFY_FORM_TYPE_NOROBOTS_VALUE)) {
- rule.setNoRobots();
- } else {
- throw new ParseException("invalid value: " + MODIFY_FORM_TYPE,0);
- }
-
- String mod = getRequiredMapParam(queryMap,MODIFY_FORM_MOD);
- if(mod.equals(MODIFY_FORM_MOD_ADD_VALUE)) {
- rule.setAdd();
- } else if(mod.equals(MODIFY_FORM_MOD_DELETE_VALUE)) {
- rule.setDelete();
- } else {
- throw new ParseException("invalid value: " + MODIFY_FORM_MOD,0);
- }
-
- String who = getRequiredMapParam(queryMap,MODIFY_FORM_WHO);
- String why = getRequiredMapParam(queryMap,MODIFY_FORM_WHY);
-
- String url = getMapParam(queryMap,MODIFY_FORM_URL);
- String surt = getMapParam(queryMap,MODIFY_FORM_SURT);
- if(surt == null) {
- if(url == null) {
- throw new ParseException("Missing argument " + MODIFY_FORM_URL,0);
- }
- String prefix = getMapParam(queryMap,MODIFY_FORM_PREFIX);
- if(prefix == null || !prefix.equals(MODIFY_FORM_PREFIX_YES_VALUE)) {
- surt = SURTTokenizer.exactKey(url);
- } else {
- surt = SURTTokenizer.prefixKey(url);
- }
- }
- rule.setWho(who);
- rule.setWhy(why);
- rule.setWhen(new Date().getTime());
- rule.setStartDateStr(startDateStr);
- rule.setEndDateStr(endDateStr);
-
- auth.addRuleFor(surt,rule);
- }
-
-
- private int statusForRule(AdministrativeExclusionRule rule,
- AdministrativeExclusionRules rules) {
- int status = RULE_STATUS_ACTIVE;
- if(rule.isDelete()) {
- status = RULE_STATUS_DELETE;
- } else {
- // has rule been deleted?
- String key = rule.key();
- boolean deleted = false;
-
- Iterator<AdministrativeExclusionRule> itr =
- rules.getRules().iterator();
- while(itr.hasNext()) {
- AdministrativeExclusionRule daRule =
- (AdministrativeExclusionRule) itr.next();
- if(daRule.isDelete() && key.equals(daRule.key()) &&
- daRule.getWhen() > rule.getWhen()) {
- deleted = true;
- break;
- }
- }
-
- if(deleted) {
- status = RULE_STATUS_INACTIVE;
- }
- }
- return status;
- }
-
- private void tableCell(StringBuilder page,String content, int status) {
- content = htmlEncode(content);
- String style = "";
- if(status == RULE_STATUS_DELETE) {
- style = "style=\"color:red;\"";
- } else if (status == RULE_STATUS_INACTIVE) {
- style = "style=\"text-decoration:line-through;\"";
- } else if (status == RULE_STATUS_HEADER) {
- style = "style=\"bold:yes;\"";
- }
- page.append("<td ").append(style).append(">");
- page.append(htmlEncode(content));
- page.append("</td>");
- }
-
- private void ruleHeaderRow(StringBuilder page) {
- int status = RULE_STATUS_HEADER;
- page.append("<tr>");
- tableCell(page,"Url Prefix",status);
- tableCell(page,"Starts",status);
- tableCell(page,"Ends",status);
- tableCell(page,"Rule Type",status);
- tableCell(page,"Add/Delete",status);
- tableCell(page,"When",status);
- tableCell(page,"Admin",status);
- tableCell(page,"Comment",status);
- page.append("</tr>\n");
- }
-
- private void ruleToRow(StringBuilder page, String surt,
- AdministrativeExclusionRule rule,int status) {
- String surtPrefix = surt;
- if(surtPrefix.endsWith("\t")) {
- surtPrefix = surtPrefix.substring(0,surtPrefix.length()-1);
- } else {
- surtPrefix = surtPrefix + "*";
- }
-
- page.append("<tr>");
- tableCell(page,surtPrefix,status);
- tableCell(page,rule.getPrettyStartDateStr(),status);
- tableCell(page,rule.getPrettyEndDateStr(),status);
- tableCell(page,rule.getPrettyType(),status);
- tableCell(page,rule.getPrettyMod(),status);
- int sse = (int) (rule.getWhen()/1000);
- // TODO: Localization
- tableCell(page, Timestamp.fromSse(sse).prettyDateTime(), status);
- tableCell(page,rule.getWho(),status);
- // TODO: shrink
- if(status == RULE_STATUS_ACTIVE) {
- page.append("<td>").append(rule.getWhy()).append(" ").
- append(makeDeleteForm(surt,rule)).append("</td>");
- } else {
- tableCell(page,rule.getWhy(),status);
- }
- page.append("</tr>\n");
- }
-
- private void rulesToTable(StringBuilder page,
- ArrayList<AdministrativeExclusionRules> matching, String url,
- boolean showAll) {
-
- if(matching.size() > 0) {
- page.append("<table border=1>");
- ruleHeaderRow(page);
- Iterator<AdministrativeExclusionRules> itr = matching.iterator();
- while(itr.hasNext()) {
- AdministrativeExclusionRules rules = itr.next();
-
- String surtPrefix = rules.getSurtPrefix();
- Iterator<AdministrativeExclusionRule> ruleItr = null;
- if(showAll) {
- ruleItr = rules.getRules().iterator();
- } else {
- ruleItr = rules.filterRules("").iterator();
- }
- while(ruleItr.hasNext()) {
- AdministrativeExclusionRule rule =
- (AdministrativeExclusionRule) ruleItr.next();
- int status = statusForRule(rule,rules);
- ruleToRow(page,surtPrefix,rule, status);
- }
- }
- page.append("</table>\n");
- } else {
- page.append("<p>No records match("+url+")</p>\n");
- }
- }
-}
Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionAuthority.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionAuthority.java 2010-04-27 22:14:50 UTC (rev 3075)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionAuthority.java 2010-04-27 22:18:44 UTC (rev 3076)
@@ -1,48 +0,0 @@
-/* ExclusionAuthority
- *
- * $Id$
- *
- * Created on 3:34:19 PM May 9, 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.accesscontrol.ui;
-
-
-/**
- *
- *
- * @deprecated superseded by ExclusionOracle
- * @author brad
- * @version $Date$, $Revision$
- */
-public interface ExclusionAuthority {
- /**
- * determines whether userAgent can view urlString for captureDate,
- * encapsulating the response in a returned ExclusionResponse object
- *
- * @param userAgent to check
- * @param urlString to check
- * @param captureDate to check
- * @return ExclusionResponse with answer to the query
- * @throws Exception if problems happen
- */
- public ExclusionResponse checkExclusion(String userAgent, String urlString,
- String captureDate) throws Exception;
-}
Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionResponse.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionResponse.java 2010-04-27 22:14:50 UTC (rev 3075)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionResponse.java 2010-04-27 22:18:44 UTC (rev 3076)
@@ -1,282 +0,0 @@
-/* ExclusionResponse
- *
- * $Id$
- *
- * Created on 4:30:17 PM Feb 13, 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.accesscontrol.ui;
-
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- * Abstraction for the result of an exclusion query, and generating the
- * differentiating parts of an HTTP response. The original implementation
- * returned XML. Without the XML, this class is really not needed, but as
- * I suspect we'll return to an XML HTTML response in the future, including
- * this for now.
- *
- *
- * @deprecated superseded by ExclusionOracle
- * @author brad
- * @version $Date$, $Revision$
- */
-public class ExclusionResponse {
-
- /**
- * Reponse is considered "authoritative"
- */
- public final static String EXLCUSION_AUTHORITATIVE = "Authoritative";
- /**
- * Response is not "authoritative" -- some assumptions may have been made
- */
- public final static String EXLCUSION_NON_AUTHORITATIVE = "Non-Authoritative";
- /**
- * Response indicates that access is granted
- */
- public final static boolean EXLCUSION_AUTHORIZED = true;
- /**
- * Response indicates that access is not granted
- */
- public final static boolean EXLCUSION_NOT_AUTHORIZED = false;
-
- private final static boolean USE_XML = false;
-
- private String responseType;
-
- private String hostname;
-
- private boolean authorized;
-
- private String message;
-
- /**
- * Constructor
- *
- * @param hostname to check
- * @param responseType for response
- * @param authorized if OK to show
- * @param message arbitrary string...
- */
- public ExclusionResponse(final String hostname, final String responseType,
- final boolean authorized,final String message) {
- this.hostname = hostname;
- this.responseType = responseType;
- this.authorized = authorized;
- this.message = message;
- }
-
- /**
- * Constuctor
- *
- * @param hostname to check
- * @param responseType for response
- * @param authorized if OK to show
- */
- public ExclusionResponse(final String hostname, final String responseType,
- final boolean authorized) {
-
- this.hostname = hostname;
- this.responseType = responseType;
- this.authorized = authorized;
- this.message = "";
- }
-
- /**
- * Send the HTTP message body to requesting client, via the OutputStream
- *
- * @param os where bytes should be written
- */
- public void writeResponse(OutputStream os) {
- if(USE_XML) {
- writeResponseXML(os);
- } else {
- writeResponseText(os);
- }
- }
-
- /**
- * @return String HTTP Content-Type field: "text/xml" or "text/plain"
- */
- public String getContentType() {
- if(USE_XML) {
- return getContentTypeXML();
- } else {
- return getContentTypeText();
- }
- }
-
- private String getContentTypeText() {
- return "text/plain";
- }
-
- /**
- * @return String version of response
- */
- public String getContentText() {
- return authorized ? "OK" : "BLOCKED - " + message;
- }
-
- private void writeResponseText(OutputStream os) {
-
- String content = getContentText();
- try {
- os.write(content.getBytes());
- } catch (IOException e) {
- // TODO what now?
- e.printStackTrace();
- }
- }
-
- private String getContentTypeXML() {
- return "text/xml";
- }
-
- private void writeResponseXML(OutputStream os) {
-
- Document doc;
- try {
- doc = getResponseXMLDocument();
- DOMSource source = new DOMSource(doc);
- TransformerFactory transFactory = TransformerFactory.newInstance();
- Transformer transformer = transFactory.newTransformer();
- transformer.setOutputProperty("indent", "yes");
- StreamResult result = new StreamResult(os);
- transformer.transform(source, result);
- } catch (ParserConfigurationException e) {
- // TODO is anything output here?
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (TransformerConfigurationException e) {
- // TODO is anything output here?
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (TransformerException e) {
- // TODO is anything output here?
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- private Document getResponseXMLDocument() throws ParserConfigurationException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- Document doc = factory.newDocumentBuilder().newDocument();
- Element response = addNode(doc, doc, "response");
- addAttribute(doc,response,"type",responseType);
- addAttribute(doc,response,"hostname",hostname);
- addAttribute(doc,response,"authorized",authorized?"true":"false");
- addAttribute(doc,response,"message",message);
- return doc;
- }
-
- private static Element addNode(Document doc, Node parent, String name) {
- Element child = doc.createElement(name);
- parent.appendChild(child);
- return child;
- }
-
- // All below here stolen from NutchwaxOpenSearchServlet...
-
-// private static void addNode(Document doc, Node parent, String name,
-// String text) {
-// Element child = doc.createElement(name);
-// child.appendChild(doc.createTextNode(getLegalXml(text)));
-// parent.appendChild(child);
-// }
-
- private static void addAttribute(Document doc, Element node, String name,
- String value) {
- Attr attribute = doc.createAttribute(name);
- attribute.setValue(getLegalXml(value));
- node.getAttributes().setNamedItem(attribute);
- }
-
- /*
- * Ensure string is legal xml.
- * First look to see if string has illegal characters. If it doesn't,
- * just return it. Otherwise, create new string with illegal characters
- * @param text String to verify.
- * @return Passed <code>text</code> or a new string with illegal
- * characters removed if any found in <code>text</code>.
- * @see http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char
- */
- private static String getLegalXml(final String text) {
- if (text == null) {
- return null;
- }
- boolean allLegal = true;
- for (int i = 0; i < text.length(); i++) {
- if (!isLegalXml(text.charAt(i))) {
- allLegal = false;
- break;
- }
- }
- return allLegal ? text : createLegalXml(text);
- }
-
- private static String createLegalXml(final String text) {
- if (text == null) {
- return null;
- }
- StringBuffer buffer = new StringBuffer(text.length());
- for (int i = 0; i < text.length(); i++) {
- char c = text.charAt(i);
- if (isLegalXml(c)) {
- buffer.append(c);
- }
- }
- return buffer.toString();
- }
-
- private static boolean isLegalXml(final char c) {
- return c == 0x9 || c == 0xa || c == 0xd || (c >= 0x20 && c <= 0xd7ff)
- || (c >= 0xe000 && c <= 0xfffd)
- || (c >= 0x10000 && c <= 0x10ffff);
- }
- /**
- * @return Returns the authorized.
- */
- public boolean isAuthorized() {
- return authorized;
- }
- /**
- * @return Returns the message.
- */
- public String getMessage() {
- return message;
- }
-}
Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionServlet.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionServlet.java 2010-04-27 22:14:50 UTC (rev 3075)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/accesscontrol/ui/ExclusionServlet.java 2010-04-27 22:18:44 UTC (rev 3076)
@@ -1,139 +0,0 @@
-/* ExclusionServlet
- *
- * $Id$
- *
- * Created on 5:28:10 PM Feb 13, 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.accesscontrol.ui;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.archive.wayback.webapp.ServletRequestContext;
-
-/**
- *
- *
- * @deprecated superseded by ExclusionOracle
- * @author brad
- * @version $Date$, $Revision$
- */
-public class ExclusionServlet extends ServletRequestContext {
- private static final long serialVersionUID = 1L;
-
- private static final String OPERATION_ARGUMENT = "operation";
-
- private static final String URL_ARGUMENT = "url";
-
- private static final String USER_AGENT_ARGUMENT = "useragent";
-
- private static final String TIMESTAMP_ARGUMENT = "timestamp";
-
- private static final String OPERATION_CHECK = "check";
-
- private ExclusionAuthority exclusionAuthority = null;
-// private static final String OPERATION_PURGE = "purge";
-
-
- public boolean handleRequest(HttpServletRequest httpRequest,
- HttpServletResponse httpResponse) throws IOException,
- ServletException {
- ExclusionAuthority exclAuth = exclusionAuthority;
-
- @SuppressWarnings("unchecked")
- Map<String,String[]> queryArgs = httpRequest.getParameterMap();
- String url = getMapParam(queryArgs, URL_ARGUMENT);
- String operation = getMapParam(queryArgs, OPERATION_ARGUMENT);
- String userAgent = getMapParam(queryArgs, USER_AGENT_ARGUMENT);
- String timestamp = getMapParam(queryArgs, TIMESTAMP_ARGUMENT);
- ExclusionResponse eclResponse = null;
- if (operation == null) {
- eclResponse = new ExclusionResponse("-", "AccessError", false,
- "No " + OPERATION_ARGUMENT + " argument supplied");
- } else if (url == null) {
- eclResponse = new ExclusionResponse("-", "AccessError", false,
- "No " + URL_ARGUMENT + " argument supplied");
- } else {
- if (operation.equals(OPERATION_CHECK)) {
- if (userAgent == null) {
- eclResponse = new ExclusionResponse("-", "AccessError",
- false, "No " + USER_AGENT_ARGUMENT
- + " argument supplied");
- } else if (timestamp == null) {
- eclResponse = new ExclusionResponse("-", "AccessError",
- false, "No " + TIMESTAMP_ARGUMENT
- + " argument supplied");
- } else {
- try {
-
- eclResponse = exclAuth.checkExclusion(userAgent, url,
- timestamp);
-
- } catch (Exception e) {
- e.printStackTrace();
- eclResponse = new ExclusionResponse("-", "ServerError",
- false, e.getMessage());
- }
- }
- // } else if(operation.equals(OPERATION_PURGE)) {
- // try {
- // eclResponse = roboCache.purgeUrl(url);
- // } catch (MalformedURLException e) {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // eclResponse = new ExclusionResponse("-","ServerError",
- // false,e.getMessage());
- // } catch (DatabaseException e) {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // eclResponse = new ExclusionResponse("-","ServerError",
- // false,e.getMessage());
- // }
- } else {
- eclResponse = new ExclusionResponse("-", "AccessError", false,
- "Unknown " + OPERATION_ARGUMENT);
- }
- }
- httpResponse.setContentType(eclResponse.getContentType());
- OutputStream os = httpResponse.getOutputStream();
- eclResponse.writeResponse(os);
- return true;
- }
-
- /**
- * @param exclusionAuthority the exclusionAuthority to set
- */
- public void setExclusionAuthority(ExclusionAuthority exclusionAuthority) {
- this.exclusionAuthority = exclusionAuthority;
- }
-
- /**
- * @return the exclusionAuthority
- */
- public ExclusionAuthority getExclusionAuthority() {
- return exclusionAuthority;
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-27 22:14:57
|
Revision: 3075
http://archive-access.svn.sourceforge.net/archive-access/?rev=3075&view=rev
Author: bradtofel
Date: 2010-04-27 22:14:50 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
REFACTORED: to package org.archive.wayback.util.webapp
Removed Paths:
-------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestContext.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestFilter.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/ServletRequestContext.java
Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestContext.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestContext.java 2010-04-27 22:12:31 UTC (rev 3074)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestContext.java 2010-04-27 22:14:50 UTC (rev 3075)
@@ -1,50 +0,0 @@
-/* RequestContext
- *
- * $Id$
- *
- * Created on 4:46:47 PM Jul 19, 2007.
- *
- * Copyright (C) 2007 Internet Archive.
- *
- * This file is part of wayback-core.
- *
- * wayback-core 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-core 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-core; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package org.archive.wayback.webapp;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- *
- * @author brad
- * @version $Date$, $Revision$
- */
-public interface RequestContext {
- /**
- * @param httpRequest
- * @param httpResponse
- * @return true if the RequestContent returned data to the client.
- * @throws ServletException
- * @throws IOException
- */
- public boolean handleRequest(HttpServletRequest httpRequest,
- HttpServletResponse httpResponse)
- throws ServletException, IOException;
-}
Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestFilter.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestFilter.java 2010-04-27 22:12:31 UTC (rev 3074)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestFilter.java 2010-04-27 22:14:50 UTC (rev 3075)
@@ -1,165 +0,0 @@
-/* RequestHandler
- *
- * $Id$
- *
- * Created on 4:24:06 PM Apr 20, 2007.
- *
- * Copyright (C) 2007 Internet Archive.
- *
- * This file is part of wayback-webapp.
- *
- * wayback-webapp 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-webapp 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-webapp; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package org.archive.wayback.webapp;
-
-import java.io.IOException;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.httpclient.URIException;
-import org.apache.log4j.Logger;
-import org.archive.net.UURI;
-import org.archive.net.UURIFactory;
-import org.archive.util.ArchiveUtils;
-import org.archive.wayback.exception.ConfigurationException;
-import org.archive.wayback.util.url.UrlOperations;
-
-/**
- *
- *
- * @author brad
- * @version $Date$, $Revision$
- */
-public class RequestFilter implements Filter {
- private static final Logger LOGGER = Logger.getLogger(RequestFilter.class
- .getName());
- private RequestMapper mapper = null;
-
- /* (non-Javadoc)
- * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
- */
- public void init(FilterConfig config) throws ServletException {
-
- LOGGER.info("Wayback Filter initializing...");
- try {
- mapper = new RequestMapper(config.getServletContext());
- } catch (ConfigurationException e) {
- throw new ServletException(e.getMessage());
- }
- LOGGER.info("Wayback Filter initialization complete.");
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.Filter#destroy()
- */
- public void destroy() {
- LOGGER.info("Wayback Filter de-initialization starting...");
- mapper.destroy();
- LOGGER.info("Wayback Filter de-initialization complete.");
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
- */
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
- boolean handled = false;
-
- if(request instanceof HttpServletRequest) {
- if(response instanceof HttpServletResponse) {
- handled = handle((HttpServletRequest) request,
- (HttpServletResponse) response);
- }
- }
- if(!handled) {
- chain.doFilter(request,response);
- }
- }
-
- protected boolean handle(HttpServletRequest httpRequest,
- HttpServletResponse httpResponse)
- throws IOException, ServletException {
-
- boolean handled = false;
- RequestContext context = mapper.mapContext(httpRequest);
- if(context == null) {
- try {
- handled =
- handleServerRelativeArchivalRedirect(httpRequest, httpResponse);
- } catch(URIException e) {
- // TODO: Log this?
- handled = false;
- }
- } else {
- handled = context.handleRequest(httpRequest,httpResponse);
- }
- return handled;
- }
-
- private boolean handleServerRelativeArchivalRedirect(
- HttpServletRequest httpRequest, HttpServletResponse httpResponse)
- throws IOException {
-
- boolean handled = false;
- // hope that it's a server relative request, with a valid referrer:
- String referer = httpRequest.getHeader("Referer");
- if(referer != null) {
- UURI uri = UURIFactory.getInstance(referer);
- String path = uri.getPath();
- int secondSlash = path.indexOf('/',1);
- if(secondSlash > -1) {
- String collection = path.substring(0,secondSlash);
- String remainder = path.substring(secondSlash+1);
- int thirdSlash = remainder.indexOf('/');
- if(thirdSlash > -1) {
- String datespec = remainder.substring(0,thirdSlash);
- String url = ArchiveUtils.addImpliedHttpIfNecessary(
- remainder.substring(thirdSlash+1));
- String thisPath = httpRequest.getRequestURI();
- String queryString = httpRequest.getQueryString();
- if (queryString != null) {
- thisPath += "?" + queryString;
- }
-
- String resolved = UrlOperations.resolveUrl(url, thisPath);
- String contextPath = httpRequest.getContextPath();
- String finalUrl = uri.getScheme() + "://" +
- uri.getAuthority() + contextPath + collection + "/"
- + datespec + "/" + resolved;
- // cross your fingers!!!
- LOGGER.info("Server-Relative-Redirect:\t" + referer + "\t"
- + thisPath + "\t" + finalUrl);
-
- // Gotta make sure this is properly cached, or
- // weird things happen:
- httpResponse.addHeader("Vary", "Referer");
- httpResponse.sendRedirect(finalUrl);
- handled = true;
-
- }
- }
- }
-
- return handled;
-
- }
-}
Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2010-04-27 22:12:31 UTC (rev 3074)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2010-04-27 22:14:50 UTC (rev 3075)
@@ -1,168 +0,0 @@
-/* RequestMapper
- *
- * $Id$
- *
- * Created on 5:36:36 PM Apr 20, 2007.
- *
- * Copyright (C) 2007 Internet Archive.
- *
- * This file is part of wayback-webapp.
- *
- * wayback-webapp 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-webapp 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-webapp; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package org.archive.wayback.webapp;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.log4j.Logger;
-import org.archive.wayback.exception.ConfigurationException;
-import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
-import org.springframework.beans.factory.xml.XmlBeanFactory;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-
-/**
- * RequestMapper accepts a request, and maps that request to
- * a WaybackContext suitable for that request.
- *
- * This object is a singleton, and the class provides methods for constructing
- * and accessing the singleton.
- *
- * @author brad
- * @version $Date$, $Revision$
- */
-public class RequestMapper {
- private static final Logger LOGGER = Logger.getLogger(RequestMapper.class
- .getName());
-
- private final static String PORT_SEPARATOR = ":";
-
- private final static String CONFIG_PATH = "config-path";
-
- private XmlBeanFactory factory = null;
- /**
- * @param configPath
- * @param servletContext
- * @throws ConfigurationException
- */
- @SuppressWarnings("unchecked")
- public RequestMapper(ServletContext servletContext) throws ConfigurationException {
-
- String configPath = servletContext.getInitParameter(CONFIG_PATH);
- if(configPath == null) {
- throw new ConfigurationException("Missing " + CONFIG_PATH
- + " parameter");
- }
- String resolvedPath = servletContext.getRealPath(configPath);
- Resource resource = new FileSystemResource(resolvedPath);
- factory = new XmlBeanFactory(resource);
- Map map = factory.getBeansOfType(PropertyPlaceholderConfigurer.class);
- if(map != null) {
- Collection<PropertyPlaceholderConfigurer> macros = map.values();
- for(PropertyPlaceholderConfigurer macro : macros) {
- macro.postProcessBeanFactory(factory);
- }
- }
- factory.preInstantiateSingletons();
- }
-
- private String getContextID(HttpServletRequest request) {
- String requestPath = request.getRequestURI();
- String contextPath = request.getContextPath();
- if(requestPath.startsWith(contextPath)) {
- requestPath = requestPath.substring(contextPath.length());
- }
- String collection = "";
- if(requestPath.startsWith("/")) {
- int secondSlash = requestPath.indexOf("/",1);
- if(secondSlash != -1) {
- collection = PORT_SEPARATOR +
- requestPath.substring(1,requestPath.indexOf("/",1));
- } else {
- collection = PORT_SEPARATOR + requestPath.substring(1);
- }
- }
- return String.valueOf(request.getLocalPort()) + collection;
- }
-
- /**
- * @param request
- * @return WaybackContext that handles the specific incoming HTTP request
- */
- public RequestContext mapContext(HttpServletRequest request) {
-
- RequestContext context = null;
- String portStr = String.valueOf(request.getLocalPort());
- if(factory.containsBean(portStr)) {
- Object o = factory.getBean(portStr);
- if(o instanceof RequestContext) {
- context = (RequestContext) o;
- }
- } else {
- String contextID = getContextID(request);
- if(factory.containsBean(contextID)) {
- Object o = factory.getBean(contextID);
- if(o instanceof RequestContext) {
- context = (RequestContext) o;
- }
- }
- }
- if(context == null) {
- ArrayList<String> names = getAccessPointNamesOnPort(portStr);
- request.setAttribute("AccessPointNames", names);
- }
- return context;
- }
-
- public ArrayList<String> getAccessPointNamesOnPort(String portStr) {
- ArrayList<String> names = new ArrayList<String>();
- String[] apNames = factory.getBeanNamesForType(AccessPoint.class);
- String portStrColon = portStr + ":";
- for(String apName : apNames) {
- if(apName.startsWith(portStrColon)) {
- names.add(apName.substring(portStrColon.length()));
- }
- }
- return names;
- }
- /**
- * clean up all WaybackContexts, which should release resources gracefully.
- */
- @SuppressWarnings("unchecked")
- public void destroy() {
- LOGGER.info("shutting down contexts...");
- Map beanMap = factory.getBeansOfType(AccessPoint.class);
- Collection accessPoints = beanMap.values();
- for(Object o : accessPoints) {
- if(o instanceof AccessPoint) {
- AccessPoint ap = (AccessPoint) o;
- try {
- String apName = ap.getBeanName();
- LOGGER.info("Shutting down AccessPoint " + apName);
- ap.shutdown();
- LOGGER.info("Successfully shut down " + apName);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-}
Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/ServletRequestContext.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/ServletRequestContext.java 2010-04-27 22:12:31 UTC (rev 3074)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/ServletRequestContext.java 2010-04-27 22:14:50 UTC (rev 3075)
@@ -1,77 +0,0 @@
-/* ServletRequestContext
- *
- * $Id$
- *
- * Created on 4:51:05 PM Jul 19, 2007.
- *
- * Copyright (C) 2007 Internet Archive.
- *
- * This file is part of wayback-core.
- *
- * wayback-core 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-core 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-core; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package org.archive.wayback.webapp;
-
-import java.io.IOException;
-import java.text.ParseException;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- *
- * @author brad
- * @version $Date$, $Revision$
- */
-public abstract class ServletRequestContext implements RequestContext {
-
- protected static String getMapParam(Map<String,String[]> queryMap,
- String field) {
- String arr[] = (String[]) queryMap.get(field);
- if (arr == null || arr.length == 0) {
- return null;
- }
- return arr[0];
- }
-
- protected static String getRequiredMapParam(Map<String,String[]> queryMap,
- String field)
- throws ParseException {
- String value = getMapParam(queryMap,field);
- if(value == null) {
- throw new ParseException("missing field " + field,0);
- }
- if(value.length() == 0) {
- throw new ParseException("empty field " + field,0);
- }
- return value;
- }
-
- protected static String getMapParamOrEmpty(Map<String,String[]> map,
- String param) {
- String val = getMapParam(map,param);
- return (val == null) ? "" : val;
- }
- /* (non-Javadoc)
- * @see org.archive.wayback.webapp.RequestContext#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
- */
- public abstract boolean handleRequest(HttpServletRequest httpRequest,
- HttpServletResponse httpResponse) throws ServletException,
- IOException;
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-27 22:12:38
|
Revision: 3074
http://archive-access.svn.sourceforge.net/archive-access/?rev=3074&view=rev
Author: bradtofel
Date: 2010-04-27 22:12:31 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
REFACTOR: moved all the glue functionality, which ties Wayback to a ServletContext, into this package, including:
* Top-level RequestFilter Filter implementation
* Spring XML parsing
* setting up mapping between RequestHandler (formerly ServletRequestContext) and the RequestMapper (see below)
* RequestMapper functionality
** Now provides for more flexible mapping of RequestHandler to host, port, and path
** includes registration of notification of ServletContext destruction
** includes ability to register a global RequestHandler to possibly handle incoming requests before normal mapping, and after normal mapping, should no RequestHandler match the incoming request
Added Paths:
-----------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/BeanNameRegistrar.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/PortMapper.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestFilter.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandler.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandlerContext.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestMapper.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/ShutdownListener.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/SpringReader.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/StaticFileRequestHandler.java
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,47 @@
+/**
+ *
+ */
+package org.archive.wayback.util.webapp;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * Abstract RequestHandler implementation which performs the minimal behavior
+ * for self registration with a RequestMapper, requiring subclasses to implement
+ * only handleRequest().
+ *
+ * @author brad
+ *
+ */
+public abstract class AbstractRequestHandler implements RequestHandler {
+ private String beanName = null;
+ private ServletContext servletContext = null;
+
+ public void setBeanName(final String beanName) {
+ this.beanName = beanName;
+ }
+ public String getBeanName() {
+ return beanName;
+ }
+
+ public void setServletContext(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public void registerPortListener(RequestMapper requestMapper) {
+ BeanNameRegistrar.registerHandler(this, requestMapper);
+ }
+
+ public String translateRequestPath(HttpServletRequest httpRequest) {
+ return RequestMapper.getRequestContextPath(httpRequest);
+ }
+
+ public String translateRequestPathQuery(HttpServletRequest httpRequest) {
+ return RequestMapper.getRequestContextPathQuery(httpRequest);
+ }
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/AbstractRequestHandler.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/BeanNameRegistrar.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/BeanNameRegistrar.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/BeanNameRegistrar.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,150 @@
+/**
+ *
+ */
+package org.archive.wayback.util.webapp;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Helper static methods to implement registration of a RequestHandler with a
+ * RequestMapper, based on the beanName() method.
+ *
+ * @author brad
+ *
+ */
+public class BeanNameRegistrar {
+
+ private static final Logger LOGGER = Logger.getLogger(
+ BeanNameRegistrar.class.getName());
+
+ private static final String PORT_PATTERN_STRING =
+ "([0-9]+):?";
+ private static final String PORT_PATH_PATTERN_STRING =
+ "([0-9]+):([0-9a-zA-Z_.-]+)";
+ private static final String HOST_PORT_PATTERN_STRING =
+ "([0-9a-z_.-]+):([0-9]+):?";
+ private static final String HOST_PORT_PATH_PATTERN_STRING =
+ "([0-9a-z_.-]+):([0-9]+):([0-9a-zA-Z_.-]+)";
+
+ private static final Pattern PORT_PATTERN =
+ Pattern.compile(PORT_PATTERN_STRING);
+ private static final Pattern PORT_PATH_PATTERN =
+ Pattern.compile(PORT_PATH_PATTERN_STRING);
+ private static final Pattern HOST_PORT_PATTERN =
+ Pattern.compile(HOST_PORT_PATTERN_STRING);
+ private static final Pattern HOST_PORT_PATH_PATTERN =
+ Pattern.compile(HOST_PORT_PATH_PATTERN_STRING);
+
+ /*
+ * matches:
+ * 8080
+ * 8080:
+ */
+ private static boolean registerPort(String name, RequestHandler handler,
+ RequestMapper mapper) {
+ Matcher m = null;
+ m = PORT_PATTERN.matcher(name);
+ if(m.matches()) {
+ int port = Integer.parseInt(m.group(1));
+ mapper.addRequestHandler(port, null, null, handler);
+ return true;
+ }
+ return false;
+ }
+ /*
+ * matches:
+ * 8080:blue
+ * 8080:fish
+ */
+ private static boolean registerPortPath(String name, RequestHandler handler,
+ RequestMapper mapper) {
+ Matcher m = null;
+ m = PORT_PATH_PATTERN.matcher(name);
+ if(m.matches()) {
+ int port = Integer.parseInt(m.group(1));
+ mapper.addRequestHandler(port, null, m.group(2), handler);
+ return true;
+ }
+ return false;
+ }
+ /*
+ * matches:
+ * localhost.archive.org:8080
+ * static.localhost.archive.org:8080
+ */
+ private static boolean registerHostPort(String name, RequestHandler handler,
+ RequestMapper mapper) {
+ Matcher m = null;
+ m = HOST_PORT_PATTERN.matcher(name);
+ if(m.matches()) {
+ int port = Integer.parseInt(m.group(2));
+ mapper.addRequestHandler(port, m.group(1), null, handler);
+ return true;
+ }
+ return false;
+ }
+ /*
+ * matches:
+ * localhost.archive.org:8080:two
+ * static.localhost.archive.org:8080:fish
+ */
+ private static boolean registerHostPortPath(String name,
+ RequestHandler handler, RequestMapper mapper) {
+ Matcher m = null;
+ m = HOST_PORT_PATH_PATTERN.matcher(name);
+ if(m.matches()) {
+ int port = Integer.parseInt(m.group(2));
+ mapper.addRequestHandler(port, m.group(1), m.group(3), handler);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Extract the RequestHandler objects beanName, parse it, and register the
+ * RequestHandler with the RequestMapper according to the beanNames
+ * semantics.
+ * @param handler The RequestHandler to register
+ * @param mapper the RequestMapper where the RequestHandler should be
+ * registered.
+ */
+ public static void registerHandler(RequestHandler handler,
+ RequestMapper mapper) {
+ String name = handler.getBeanName();
+ if(name != null) {
+ if(name.equals(RequestMapper.GLOBAL_PRE_REQUEST_HANDLER)) {
+
+ mapper.addGlobalPreRequestHandler(handler);
+
+ } else if(name.equals(RequestMapper.GLOBAL_POST_REQUEST_HANDLER)) {
+
+ mapper.addGlobalPostRequestHandler(handler);
+
+ } else {
+ try {
+
+ boolean registered =
+ registerPort(name, handler, mapper) ||
+ registerPortPath(name, handler, mapper) ||
+ registerHostPort(name, handler, mapper) ||
+ registerHostPortPath(name, handler, mapper);
+
+ if(!registered) {
+ LOGGER.error("Unable to register (" + name + ")");
+ }
+ } catch(NumberFormatException e) {
+ LOGGER.error("FAILED parseInt(" + name + ")");
+ }
+ }
+ } else {
+ LOGGER.info("Unable to register RequestHandler - null beanName");
+ }
+ if(handler instanceof ShutdownListener) {
+ ShutdownListener s = (ShutdownListener) handler;
+ mapper.addShutdownListener(s);
+ }
+ }
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/BeanNameRegistrar.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/PortMapper.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/PortMapper.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/PortMapper.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,164 @@
+/* PortMapper
+ *
+ * $Id$:
+ *
+ * Created on Mar 23, 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.util.webapp;
+
+import java.util.HashMap;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * Class which allows semi-efficient translation of requests on a specific local
+ * port to a RequestHandler object.
+ *
+ * Mapping within a port is based on the HTTP 1.1 Host field and the first
+ * segment of the requested PATH, that is, whatever is after the context where
+ * the wayback webapp was deployed, and before the first '/'.
+ *
+ * @author brad
+ */
+public class PortMapper {
+ private static final Logger LOGGER = Logger.getLogger(
+ PortMapper.class.getName());
+ private int port = -1;
+ private HashMap<String, RequestHandler> pathMap = null;
+ /**
+ * @param port which this PortMapper is responsible for handling
+ */
+ public PortMapper(int port) {
+ this.port = port;
+ pathMap = new HashMap<String, RequestHandler>();
+ }
+ private String hostPathToKey(String host, String firstPath) {
+ StringBuilder sb = null;
+ if((host == null) && (firstPath == null)) {
+ return null;
+ }
+ sb = new StringBuilder();
+ if(host != null) {
+ sb.append(host);
+ }
+ sb.append("/");
+ if(firstPath != null) {
+ sb.append(firstPath);
+ }
+ return sb.toString();
+ }
+ /**
+ * Register the RequestHandler to accept requests for the given host and
+ * port.
+ * @param host the HTTP 1.1 "Host" header which the RequestHandler should
+ * match. If null, the RequestHandler matches any "Host" header value.
+ * @param firstPath the first path of the GET request path which the
+ * RequestHandler should match. This is the first path AFTER the name the
+ * Wayback webapp is deployed under. If null, the RequestHandler matches
+ * all paths.
+ * @param requestHandler The RequestHandler to register.
+ */
+ public void addRequestHandler(String host, String firstPath,
+ RequestHandler requestHandler) {
+ String key = hostPathToKey(host,firstPath);
+ if(pathMap.containsKey(key)) {
+ LOGGER.warn("Duplicate port:path map for " + port +
+ ":" + key);
+ } else {
+ LOGGER.info("Registered requestHandler(port/host/path) (" +
+ port + "/" + host + "/" + firstPath + "): " + key);
+ pathMap.put(key,requestHandler);
+ }
+ }
+
+ private String requestToFirstPath(HttpServletRequest request) {
+ String firstPath = null;
+ String requestPath = request.getRequestURI();
+ String contextPath = request.getContextPath();
+ if((contextPath.length() > 0) && requestPath.startsWith(contextPath)) {
+ requestPath = requestPath.substring(contextPath.length());
+ }
+ while(requestPath.startsWith("/")) {
+ requestPath = requestPath.substring(1);
+ }
+
+ int slashIdx = requestPath.indexOf("/",1);
+ if(slashIdx == -1) {
+ firstPath = requestPath;
+ } else {
+ firstPath = requestPath.substring(0,slashIdx);
+ }
+ return firstPath;
+ }
+
+ private String requestToHost(HttpServletRequest request) {
+ return request.getServerName();
+ }
+
+ /**
+ * Attempts to locate the most strictly matching RequestHandler mapped to
+ * this port. Strictly matching means the lowest number in the following
+ * list:
+ *
+ * 1) request handler matching both HOST and PATH
+ * 2) request handler matching host, registered with an empty PATH
+ * 3) request handler matching path, registered with an empty HOST
+ * 4) request handler registered with empty HOST and PATH
+ *
+ * @param request the HttpServletRequest to be mapped to a RequestHandler
+ * @return the RequestHandlerContext, containing the RequestHandler and the
+ * prefix of the original request path that indicated the RequestHandler,
+ * or null, if no RequestHandler matches.
+ */
+ public RequestHandlerContext getRequestHandlerContext(
+ HttpServletRequest request) {
+ String host = requestToHost(request);
+ String contextPath = request.getContextPath();
+ StringBuilder pathPrefix = new StringBuilder(contextPath);
+ if(contextPath.length() == 0) {
+ pathPrefix.append("/");
+ }
+ String firstPath = requestToFirstPath(request);
+ RequestHandler handler = pathMap.get(hostPathToKey(host,firstPath));
+ if(handler != null) {
+ return new RequestHandlerContext(handler,
+ pathPrefix.append(firstPath).toString());
+ }
+ handler = pathMap.get(hostPathToKey(host,null));
+ if(handler != null) {
+ return new RequestHandlerContext(handler,contextPath);
+ }
+ handler = pathMap.get(hostPathToKey(null,firstPath));
+ if(handler != null) {
+ return new RequestHandlerContext(handler,
+ pathPrefix.append(firstPath).toString());
+ }
+ handler = pathMap.get(null);
+ if(handler != null) {
+ return new RequestHandlerContext(handler,contextPath);
+ }
+ return null;
+ }
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/PortMapper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestFilter.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestFilter.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestFilter.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,91 @@
+/* RequestHandler
+ *
+ * $Id$
+ *
+ * Created on 4:24:06 PM Apr 20, 2007.
+ *
+ * Copyright (C) 2007 Internet Archive.
+ *
+ * This file is part of wayback-webapp.
+ *
+ * wayback-webapp 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-webapp 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-webapp; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.archive.wayback.util.webapp;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Top-Level integration point between a series of RequestHandler mappings and
+ * a generic ServletContext. This filter is assumed to be responsible for
+ * matching ALL requests received by the webapp ("*") and uses a RequestMapper
+ * to delegate incoming HttpServletRequests to the appropriate RequestHandler,
+ * via the doFilter() method.
+ *
+ * @author brad
+ */
+public class RequestFilter implements Filter {
+ private static final Logger LOGGER = Logger.getLogger(RequestFilter.class
+ .getName());
+ private RequestMapper mapper = null;
+ private final static String CONFIG_PATH = "config-path";
+
+ public void init(FilterConfig config) throws ServletException {
+ ServletContext servletContext = config.getServletContext();
+
+ String configPath = servletContext.getInitParameter(CONFIG_PATH);
+ if(configPath == null) {
+ throw new ServletException("Missing " + CONFIG_PATH
+ + " parameter");
+ }
+ String resolvedPath = servletContext.getRealPath(configPath);
+
+ LOGGER.info("Initializing Spring config at: " + resolvedPath);
+ mapper = SpringReader.readSpringConfig(resolvedPath,servletContext);
+ LOGGER.info("Initialized Spring config at: " + resolvedPath);
+ }
+
+ public void destroy() {
+ LOGGER.info("Shutdown starting.");
+ mapper.shutdown();
+ LOGGER.info("Shutdown complete.");
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ boolean handled = false;
+
+ if(request instanceof HttpServletRequest) {
+ if(response instanceof HttpServletResponse) {
+ handled = mapper.handleRequest((HttpServletRequest) request,
+ (HttpServletResponse) response);
+ }
+ }
+ if(!handled) {
+ chain.doFilter(request,response);
+ }
+ }
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestFilter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandler.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandler.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandler.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,85 @@
+/**
+ *
+ */
+package org.archive.wayback.util.webapp;
+
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.factory.BeanNameAware;
+
+/**
+ * A generic handler of HttpServletRequests. very similar to an HttpServlet, but
+ * the handleRequest() method returns a boolean indicating if the RequestHandler
+ * returned data to the user.
+ *
+ * This interface further defines methods to facilitate automatic registration
+ * when loaded as a Spring configuration, and maintains a reference to the
+ * ServletContext under which it accepts incoming requests.
+ *
+ * @author brad
+ *
+ */
+public interface RequestHandler extends BeanNameAware {
+
+ /**
+ * Possibly handle an incoming HttpServletRequest, much like a normal
+ * HttpServlet, but includes a return value.
+ * @param httpRequest the incoming HttpServletRequest
+ * @param httpResponse the HttpServletResponse to return data to the client.
+ * @return true if the RequestHandler returned a response to the client,
+ * false otherwise
+ * @throws ServletException for usual reasons.
+ * @throws IOException for usual reasons.
+ */
+ public boolean handleRequest(HttpServletRequest httpRequest,
+ HttpServletResponse httpResponse)
+ throws ServletException, IOException;
+
+ /**
+ * @return the "name" property of the bean from the SpringConfiguration
+ */
+ public String getBeanName();
+
+ /**
+ * Called before registerPortListener(), to enable the registration process
+ * and subsequent handleRequest() calls to access the ServletContext, via
+ * the getServletContext() method.
+ * @param servletContext the ServletContext where the RequestHandler is
+ * registered.
+ */
+ public void setServletContext(ServletContext servletContext);
+
+ /**
+ * @return the ServletContext where the RequestHandler is registered.
+ */
+ public ServletContext getServletContext();
+
+ /**
+ * Called at webapp context initialization, to allow the RequestHandler to
+ * register itself with the RequestMapper, which will delegate request
+ * handling to the appropriate RequestHandler.
+ * @param requestMapper the RequestMapper on which this RequestHandler
+ * should register itself, including to register for notification of context
+ * shutdown.
+ */
+ public void registerPortListener(RequestMapper requestMapper);
+
+ /**
+ * @param httpRequest the HttpServletRequest being handled
+ * @return the portion of the original incoming request that falls within
+ * this RequestHandler, not including any query information
+ */
+ public String translateRequestPath(HttpServletRequest httpRequest);
+
+ /**
+ * @param httpRequest the HttpServletRequest being handled
+ * @return the portion of the original incoming request that falls within
+ * this RequestHandler, including any query information
+ */
+ public String translateRequestPathQuery(HttpServletRequest httpRequest);
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandler.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandlerContext.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandlerContext.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandlerContext.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,66 @@
+/* RequestHandlerContext
+ *
+ * $Id$:
+ *
+ * Created on Apr 26, 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.util.webapp;
+
+/**
+ * A simple composition of the RequestHandler which an HttpServletRequest was
+ * mapped to, and the path prefix which indicated the RequestHandler. This
+ * allows computing the portion of the original request path within the
+ * RequestHandler.
+ *
+ * @author brad
+ *
+ */
+public class RequestHandlerContext {
+
+ private RequestHandler handler = null;
+ private String pathPrefix = null;
+
+ /**
+ * Constructor
+ * @param handler the RequestHandler to which the incoming request was
+ * mapped
+ * @param pathPrefix the leading portion of the original request path that
+ * indicated the RequestHandler
+ */
+ public RequestHandlerContext(RequestHandler handler, String pathPrefix) {
+ this.handler = handler;
+ this.pathPrefix = pathPrefix;
+ }
+ /**
+ * @return the RequestHandler to which the incoming request was mapped.
+ */
+ public RequestHandler getRequestHandler() {
+ return handler;
+ }
+ /**
+ * @return the leading portion of the original request path that
+ * indicated the RequestHandler
+ */
+ public String getPathPrefix() {
+ return pathPrefix;
+ }
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestHandlerContext.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestMapper.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestMapper.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestMapper.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,266 @@
+/* RequestMapper
+ *
+ * $Id$:
+ *
+ * Created on Mar 23, 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.util.webapp;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+
+/**
+ * This class maintains a mapping of RequestHandlers and ShutDownListeners, to
+ * allow (somewhat) efficient mapping and delegation of incoming requests to
+ * the appropriate RequestHandler.
+ *
+ * This class uses PortMapper to delegate some of the responsibility of mapping
+ * requests received on a particular port, and also allows configuration of a
+ * global PRE RequestHandler, which gets first dibs on EVERY incoming request,
+ * as well as a global POST RequestHandler, which may attempt to handle any
+ * incoming request not handled by the normal RequestHandler mapping.
+ *
+ * @author brad
+ *
+ */
+public class RequestMapper {
+
+ private static final Logger LOGGER = Logger.getLogger(
+ RequestMapper.class.getName());
+
+ private ArrayList<ShutdownListener> shutdownListeners = null;
+
+ private HashMap<Integer,PortMapper> portMap = null;
+ private RequestHandler globalPreRequestHandler = null;
+ private RequestHandler globalPostRequestHandler = null;
+
+ private final static String REQUEST_CONTEXT_PREFIX =
+ "webapp-request-context-path-prefix";
+
+ /**
+ * Bean name used to register the special global PRE RequestHandler.
+ */
+ public final static String GLOBAL_PRE_REQUEST_HANDLER = "-";
+ /**
+ * Bean name used to register the special global POST RequestHandler.
+ */
+ public final static String GLOBAL_POST_REQUEST_HANDLER = "+";
+
+ /**
+ * Construct a RequestMapper, for the given RequestHandler objects, on the
+ * specified ServletContext. This method will call setServletContext() on
+ * each RequestMapper, followed immediately by registerPortListener()
+ *
+ * @param requestHandlers Collection of RequestHandlers which handle
+ * requests
+ * @param servletContext the webapp ServletContext where this RequestMapper
+ * is configured.
+ */
+ public RequestMapper(Collection<RequestHandler> requestHandlers,
+ ServletContext servletContext) {
+ portMap = new HashMap<Integer, PortMapper>();
+ shutdownListeners = new ArrayList<ShutdownListener>();
+ Iterator<RequestHandler> itr = requestHandlers.iterator();
+ LOGGER.info("Registering handlers.");
+ while(itr.hasNext()) {
+ RequestHandler requestHandler = itr.next();
+ requestHandler.setServletContext(servletContext);
+ requestHandler.registerPortListener(this);
+ }
+ LOGGER.info("Registering handlers complete.");
+ }
+
+ /**
+ * Request the shutdownListener object to be notified of ServletContext
+ * shutdown.
+ * @param shutdownListener the object which needs to have shutdown() called
+ * when the ServletContext is destroyed.
+ */
+ public void addShutdownListener(ShutdownListener shutdownListener) {
+ shutdownListeners.add(shutdownListener);
+ }
+ /**
+ * Configure the specified RequestHandler to handle ALL incoming requests
+ * before any other normal mapping.
+ * @param requestHandler the global PRE RequestHandler
+ */
+ public void addGlobalPreRequestHandler(RequestHandler requestHandler) {
+ globalPreRequestHandler = requestHandler;
+ }
+ /**
+ * Configure the specified RequestHandler to handle ALL incoming requests
+ * after all other normal mapping has been attempted
+ * @param requestHandler the global POST RequestHandler
+ */
+ public void addGlobalPostRequestHandler(RequestHandler requestHandler) {
+ globalPostRequestHandler = requestHandler;
+ }
+ /**
+ * Register the RequestHandler to accept requests on the given port, for the
+ * specified host and path.
+ * @param port the integer port on which the RequestHandler gets requests.
+ * @param host the String Host which the RequestHandler matches, or null, if
+ * the RequestHandler should match ALL hosts.
+ * @param path the String path which the RequestHandler matches, or null, if
+ * the RequestHandler should match ALL paths.
+ * @param requestHandler the RequestHandler to register.
+ */
+ public void addRequestHandler(int port, String host, String path,
+ RequestHandler requestHandler) {
+ LOGGER.info("Registered:" + port + ":" +
+ (host == null ? "(null)" : host) + ":"
+ + (path == null ? "(null)" : path));
+ Integer portInt = Integer.valueOf(port);
+ PortMapper portMapper = portMap.get(portInt);
+ if(portMapper == null) {
+ portMapper = new PortMapper(portInt);
+ portMap.put(portInt, portMapper);
+ }
+ portMapper.addRequestHandler(host, path, requestHandler);
+ }
+
+ private RequestHandlerContext mapRequest(HttpServletRequest request) {
+ RequestHandlerContext handlerContext = null;
+
+ int port = request.getLocalPort();
+ Integer portInt = Integer.valueOf(port);
+ PortMapper portMapper = portMap.get(portInt);
+ if(portMapper != null) {
+ handlerContext = portMapper.getRequestHandlerContext(request);
+ }
+ return handlerContext;
+ }
+
+ /**
+ * Map the incoming request to the appropriate RequestHandler, including
+ * the PRE and POST RequestHandlers, if configured.
+ * @param request the incoming HttpServletRequest
+ * @param response the HttpServletResponse to return data to the client
+ * @return true if a response was returned to the client.
+ * @throws ServletException for usual reasons.
+ * @throws IOException for usual reasons.
+ */
+ public boolean handleRequest(HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ boolean handled = false;
+ if(globalPreRequestHandler != null) {
+ handled =
+ globalPreRequestHandler.handleRequest(request, response);
+ }
+ if(handled == false) {
+ RequestHandlerContext handlerContext = mapRequest(request);
+ if(handlerContext != null) {
+ RequestHandler requestHandler =
+ handlerContext.getRequestHandler();
+ request.setAttribute(REQUEST_CONTEXT_PREFIX,
+ handlerContext.getPathPrefix() + "/");
+ handled = requestHandler.handleRequest(request, response);
+ }
+ }
+ if(handled == false) {
+ if(globalPostRequestHandler != null) {
+ handled =
+ globalPostRequestHandler.handleRequest(request, response);
+ }
+ }
+ return handled;
+ }
+
+ /**
+ * notify all registered ShutdownListener objects that the ServletContext is
+ * being destroyed.
+ */
+ public void shutdown() {
+ for(ShutdownListener shutdownListener : shutdownListeners) {
+ try {
+ shutdownListener.shutdown();
+ } catch(Exception e) {
+ LOGGER.error("failed shutdown", e);
+ }
+ }
+ }
+
+ /**
+ * Extract the request path prefix, as computed at RequestHandler mapping,
+ * from the HttpServletRequest object.
+ *
+ * @param request HttpServlet request object being handled
+ * @return the portion of the original request path which indicated the
+ * RequestHandler, including the trailing '/'.
+ */
+ public static String getRequestPathPrefix(HttpServletRequest request) {
+ return (String) request.getAttribute(REQUEST_CONTEXT_PREFIX);
+ }
+
+ /**
+ * @param request HttpServlet request object being handled
+ * @return the portion of the incoming path within the RequestHandler
+ * handling the request, not including a leading "/", and not including
+ * query arguments.
+ */
+ public static String getRequestContextPath(HttpServletRequest request) {
+ String prefix = (String) request.getAttribute(REQUEST_CONTEXT_PREFIX);
+ String requestUrl = request.getRequestURI();
+ if(prefix == null) {
+ return requestUrl;
+ }
+ if(requestUrl.startsWith(prefix)) {
+ return requestUrl.substring(prefix.length());
+ }
+ return requestUrl;
+ }
+
+ /**
+ * @param request HttpServlet request object being handled
+ * @return the portion of the incoming path within the RequestHandler
+ * handling the request, not including a leading "/", including query
+ * arguments.
+ */
+ public static String getRequestContextPathQuery(HttpServletRequest request) {
+ String prefix = (String) request.getAttribute(REQUEST_CONTEXT_PREFIX);
+ StringBuilder sb = new StringBuilder(request.getRequestURI());
+ String requestUrl = null;
+ String query = request.getQueryString();
+ if(query != null) {
+ requestUrl = sb.append("?").append(query).toString();
+ } else {
+ requestUrl = sb.toString();
+ }
+ if(prefix == null) {
+ return requestUrl;
+ }
+ if(requestUrl.startsWith(prefix)) {
+ return requestUrl.substring(prefix.length());
+ }
+ return requestUrl;
+ }
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/RequestMapper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/ShutdownListener.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/ShutdownListener.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/ShutdownListener.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.archive.wayback.util.webapp;
+
+/**
+ * Interface representing a desire to be notified when the containing
+ * ServletContext is being destroyed.
+ *
+ * @author brad
+ *
+ */
+public interface ShutdownListener {
+ /**
+ * Called when the ServletContext is being destroyed.
+ */
+ public void shutdown();
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/ShutdownListener.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/SpringReader.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/SpringReader.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/SpringReader.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,61 @@
+/**
+ *
+ */
+package org.archive.wayback.util.webapp;
+import java.util.Collection;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+import org.springframework.beans.factory.xml.XmlBeanFactory;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+
+/**
+ * Single static method to read a Spring XML configuration, extract
+ * RequestHandlers, and return a RequestMapper which delegates requests to
+ * those RequestHandlers.
+ *
+ * @author brad
+ *
+ */
+public class SpringReader {
+ private static final Logger LOGGER = Logger.getLogger(
+ SpringReader.class.getName());
+
+ /**
+ * Read the single Spring XML configuration file located at the specified
+ * path, performing PropertyPlaceHolder interpolation, extracting all beans
+ * which implement the RequestHandler interface, and construct a
+ * RequestMapper for those RequestHandlers, on the specified ServletContext.
+ * @param configPath the path to the Spring XML file containing the
+ * configuration.
+ * @param servletContext the ServletContext where the RequestHandlers should
+ * be mapped
+ * @return a new ReqeustMapper which delegates requests for the
+ * ServletContext
+ */
+ @SuppressWarnings("unchecked")
+ public static RequestMapper readSpringConfig(String configPath,
+ ServletContext servletContext) {
+ LOGGER.info("Loading from config file " + configPath);
+
+ Resource resource = new FileSystemResource(configPath);
+ XmlBeanFactory factory = new XmlBeanFactory(resource);
+ Map map = factory.getBeansOfType(PropertyPlaceholderConfigurer.class);
+ if(map != null) {
+ Collection<PropertyPlaceholderConfigurer> macros = map.values();
+ for(PropertyPlaceholderConfigurer macro : macros) {
+ macro.postProcessBeanFactory(factory);
+ }
+ }
+ LOGGER.info("Pre-instanting Singletons starting");
+ factory.preInstantiateSingletons();
+ LOGGER.info("Pre-instanting Singletons complete");
+ Map<String,RequestHandler> beans =
+ factory.getBeansOfType(RequestHandler.class,false,false);
+ return new RequestMapper(beans.values(), servletContext);
+ }
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/SpringReader.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/StaticFileRequestHandler.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/StaticFileRequestHandler.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/StaticFileRequestHandler.java 2010-04-27 22:12:31 UTC (rev 3074)
@@ -0,0 +1,49 @@
+/**
+ *
+ */
+package org.archive.wayback.util.webapp;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+
+/**
+ * RequestHandler implementation which allows serving of static files, and
+ * .jsp files within a ServletContext.
+ *
+ * @author brad
+ */
+public class StaticFileRequestHandler extends AbstractRequestHandler {
+
+ private static final Logger LOGGER = Logger.getLogger(
+ StaticFileRequestHandler.class.getName());
+
+ public boolean handleRequest(HttpServletRequest httpRequest,
+ HttpServletResponse httpResponse) throws ServletException, IOException {
+ boolean handled = false;
+ String contextRelativePath = httpRequest.getServletPath();
+ String absPath = getServletContext().getRealPath(contextRelativePath);
+ File test = new File(absPath);
+ // TODO: check for index.jsp(or configurable equivalent),
+ // if it's a directory?
+ if(test.isFile()) {
+ LOGGER.trace("static path:" + absPath);
+ RequestDispatcher dispatcher =
+ httpRequest.getRequestDispatcher(contextRelativePath);
+// try {
+ dispatcher.forward(httpRequest, httpResponse);
+ handled = true;
+// } catch(Exception e) {
+// }
+ } else {
+ LOGGER.trace("Not-static path:" + absPath);
+ }
+ return handled;
+ }
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/webapp/StaticFileRequestHandler.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.
|
|
From: <bra...@us...> - 2010-04-27 22:06:36
|
Revision: 3073
http://archive-access.svn.sourceforge.net/archive-access/?rev=3073&view=rev
Author: bradtofel
Date: 2010-04-27 22:06:30 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
INITIAL REV: new Archival URL RequestParser component implementation, which allows requests without a datespec, and redirects the client to a replay request for the supplied URL, for the current timestamp
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/requestparser/DatelessReplayRequestParser.java
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-04-27 22:03:42 UTC (rev 3072)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlRequestParser.java 2010-04-27 22:06:30 UTC (rev 3073)
@@ -25,6 +25,7 @@
package org.archive.wayback.archivalurl;
import org.archive.wayback.RequestParser;
+import org.archive.wayback.archivalurl.requestparser.DatelessReplayRequestParser;
import org.archive.wayback.archivalurl.requestparser.PathDatePrefixQueryRequestParser;
import org.archive.wayback.archivalurl.requestparser.PathDateRangeQueryRequestParser;
import org.archive.wayback.archivalurl.requestparser.PathPrefixDatePrefixQueryRequestParser;
@@ -76,7 +77,8 @@
new PathPrefixDatePrefixQueryRequestParser(this),
new PathPrefixDateRangeQueryRequestParser(this),
new OpenSearchRequestParser(this),
- new FormRequestParser(this)
+ new FormRequestParser(this),
+ new DatelessReplayRequestParser(this)
};
return theParsers;
}
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/DatelessReplayRequestParser.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/DatelessReplayRequestParser.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/DatelessReplayRequestParser.java 2010-04-27 22:06:30 UTC (rev 3073)
@@ -0,0 +1,106 @@
+/* DatelessReplayRequestParser
+ *
+ * $Id$:
+ *
+ * Created on Apr 26, 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 java.net.MalformedURLException;
+import java.net.URL;
+
+import org.archive.wayback.core.WaybackRequest;
+import org.archive.wayback.exception.BadQueryException;
+import org.archive.wayback.exception.BetterRequestException;
+import org.archive.wayback.requestparser.BaseRequestParser;
+import org.archive.wayback.requestparser.PathRequestParser;
+import org.archive.wayback.util.Timestamp;
+import org.archive.wayback.util.url.UrlOperations;
+import org.archive.wayback.webapp.AccessPoint;
+
+
+/**
+ * @author brad
+ *
+ */
+public class DatelessReplayRequestParser extends PathRequestParser {
+
+ /**
+ * @param wrapped the BaseRequestParser being wrapped
+ */
+ public DatelessReplayRequestParser(BaseRequestParser wrapped) {
+ super(wrapped);
+ }
+
+ public WaybackRequest parse(String requestPath, AccessPoint accessPoint)
+ throws BetterRequestException, BadQueryException {
+ /*
+ *
+ * We're trying to catch requests without a datespec, in which case,
+ * we just redirect to the same request, inserting today's datespec,
+ * and then we'll let the normal redirection occur.
+ *
+ * The one tricky point is that we don't want to defeat the
+ * server-relative redirection handling, so we want to do some
+ * inspection to make sure it actually looks like an URL, and not like:
+ *
+ * images/foo.gif
+ * redirect.php?blargity=blargblarg
+ *
+ * What would be perfect is if the user supplied http:// at the front.
+ *
+ * So, we'll assume that if we see that, we either match, or throw a
+ * BadQueryException.
+ *
+ */
+
+ String scheme = UrlOperations.urlToScheme(requestPath);
+ if(scheme == null) {
+ try {
+ URL u = new URL(UrlOperations.HTTP_SCHEME + requestPath);
+ // does the authority look legit?
+ if(u.getUserInfo() != null) {
+ throw new BadQueryException("Unable to handle URLs with user information");
+ }
+ if(UrlOperations.isAuthority(u.getAuthority())) {
+ // ok, we're going to assume this is good:
+ String nowTS = Timestamp.currentTimestamp().getDateStr();
+ String newUrl =
+ accessPoint.getUriConverter().makeReplayURI(nowTS, requestPath);
+ throw new BetterRequestException(newUrl);
+ }
+ } catch(MalformedURLException e) {
+ // eat it silently
+ }
+ } else {
+ // OK, we're going to assume this is a replay request, sans timestamp,
+ // ALWAYS redirect:
+
+ String nowTS = Timestamp.currentTimestamp().getDateStr();
+ String newUrl =
+ accessPoint.getUriConverter().makeReplayURI(nowTS, requestPath);
+ throw new BetterRequestException(newUrl);
+ }
+ return null;
+ }
+
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/DatelessReplayRequestParser.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.
|
Revision: 3072
http://archive-access.svn.sourceforge.net/archive-access/?rev=3072&view=rev
Author: bradtofel
Date: 2010-04-27 22:03:42 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
JAVADOC
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/WrappedRequestParser.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/WrappedRequestParser.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/WrappedRequestParser.java 2010-04-27 22:02:57 UTC (rev 3071)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/WrappedRequestParser.java 2010-04-27 22:03:42 UTC (rev 3072)
@@ -45,28 +45,19 @@
private BaseRequestParser wrapped = null;
+ /**
+ * @param wrapped the delegate to retrieve RequestParser configuration
+ */
public WrappedRequestParser(BaseRequestParser wrapped) {
this.wrapped = wrapped;
}
- /**
- * @return
- * @see org.archive.wayback.requestparser.BaseRequestParser#getEarliestTimestamp()
- */
public String getEarliestTimestamp() {
return wrapped.getEarliestTimestamp();
}
- /**
- * @return
- * @see org.archive.wayback.requestparser.BaseRequestParser#getLatestTimestamp()
- */
public String getLatestTimestamp() {
return wrapped.getLatestTimestamp();
}
- /**
- * @return
- * @see org.archive.wayback.requestparser.BaseRequestParser#getMaxRecords()
- */
public int getMaxRecords() {
return wrapped.getMaxRecords();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
Revision: 3071
http://archive-access.svn.sourceforge.net/archive-access/?rev=3071&view=rev
Author: bradtofel
Date: 2010-04-27 22:02:57 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
JAVADOC
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java
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 2010-04-27 22:02:30 UTC (rev 3070)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java 2010-04-27 22:02:57 UTC (rev 3071)
@@ -34,15 +34,18 @@
import org.archive.wayback.webapp.AccessPoint;
/**
+ * RequestParser which attempts to extract data from an HTML form, that is, from
+ * HTTP GET request arguments containing a query, an optional count (results
+ * per page), and an optional current page argument. All other reqeust fields
+ * are expected to be encoded within the query ("q") field.
*
- *
* @author brad
* @version $Date$, $Revision$
*/
public class OpenSearchRequestParser extends WrappedRequestParser {
/**
- * @param wrapped
+ * @param wrapped the BaseRequestParser being wrapped
*/
public OpenSearchRequestParser(BaseRequestParser wrapped) {
super(wrapped);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
Revision: 3070
http://archive-access.svn.sourceforge.net/archive-access/?rev=3070&view=rev
Author: bradtofel
Date: 2010-04-27 22:02:30 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
JAVADOC
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java
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 2010-04-27 22:02:07 UTC (rev 3069)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java 2010-04-27 22:02:30 UTC (rev 3070)
@@ -35,14 +35,15 @@
import org.archive.wayback.webapp.AccessPoint;
/**
+ * RequestParser which attempts to extract data from an HTML form, that is, from
+ * HTTP GET request arguments
*
- *
* @author brad
* @version $Date$, $Revision$
*/
public class FormRequestParser extends WrappedRequestParser {
/**
- * @param wrapped
+ * @param wrapped the BaseRequestParser being wrapped
*/
public FormRequestParser(BaseRequestParser wrapped) {
super(wrapped);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
Revision: 3069
http://archive-access.svn.sourceforge.net/archive-access/?rev=3069&view=rev
Author: bradtofel
Date: 2010-04-27 22:02:07 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
JAVADOC
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/BaseRequestParser.java
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 2010-04-27 20:52:20 UTC (rev 3068)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/BaseRequestParser.java 2010-04-27 22:02:07 UTC (rev 3069)
@@ -47,12 +47,26 @@
*/
public abstract class BaseRequestParser implements RequestParser {
+ /**
+ * String path matching a query request, by form or OpenSearch
+ */
public final static String QUERY_BASE = "query";
+ /**
+ * String path matching a query request, by form or OpenSearch, indicating
+ * user requests XML data in response
+ */
public final static String XQUERY_BASE = "xmlquery";
+ /**
+ * String path matching a replay request, by form or OpenSearch
+ */
public final static String REPLAY_BASE = "replay";
+ /**
+ * Default maximum number of records to assume, overridden by configuration,
+ * when not specified in the client request
+ */
public final static int DEFAULT_MAX_RECORDS = 10;
@@ -60,9 +74,6 @@
private String earliestTimestamp = null;
private String latestTimestamp = null;
- /* (non-Javadoc)
- * @see org.archive.wayback.RequestParser#parse(javax.servlet.http.HttpServletRequest)
- */
public abstract WaybackRequest parse(HttpServletRequest httpRequest,
AccessPoint wbContext) throws BadQueryException,
BetterRequestException;
@@ -96,42 +107,46 @@
}
/**
- * @return the maxRecords
+ * @return the maxRecords to use with this RequestParser, when not specified
+ * by the client request
*/
public int getMaxRecords() {
return maxRecords;
}
/**
- * @param maxRecords the maxRecords to set
+ * @param maxRecords the maxRecords to use with this RequestParser, when not
+ * specified by the client request
*/
public void setMaxRecords(int maxRecords) {
this.maxRecords = maxRecords;
}
/**
- * @param default earliest timestamp
+ * @param timestamp the earliest timestamp to use with this RequestParser
+ * when none is supplied by the user request
*/
public void setEarliestTimestamp(String timestamp) {
earliestTimestamp = Timestamp.parseBefore(timestamp).getDateStr();
}
/**
- * @return the default earliest timestamp
+ * @return the default earliest timestamp to use with this RequestParser
*/
public String getEarliestTimestamp() {
return earliestTimestamp;
}
/**
- * @param default latest timestamp
+ * @return default latest timestamp for this RequestParser
*/
public String getLatestTimestamp() {
return latestTimestamp;
}
/**
- * @return the default latest timestamp
+ * @param timestamp the default latest timestamp to use with this
+ * RequestParser
*/
public void setLatestTimestamp(String timestamp) {
this.latestTimestamp = Timestamp.parseAfter(timestamp).getDateStr();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-27 20:52:26
|
Revision: 3068
http://archive-access.svn.sourceforge.net/archive-access/?rev=3068&view=rev
Author: bradtofel
Date: 2010-04-27 20:52:20 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
JAVADOC
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/url/UrlOperations.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/url/UrlOperations.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/url/UrlOperations.java 2010-04-27 20:51:27 UTC (rev 3067)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/url/UrlOperations.java 2010-04-27 20:52:20 UTC (rev 3068)
@@ -24,8 +24,6 @@
*/
package org.archive.wayback.util.url;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -45,18 +43,44 @@
private static final Logger LOGGER = Logger.getLogger(
UrlOperations.class.getName());
+ /**
+ * ARC/WARC specific DNS resolution record.
+ */
public final static String DNS_SCHEME = "dns:";
+ /**
+ * HTTP
+ */
public final static String HTTP_SCHEME = "http://";
+ /**
+ * HTTPS
+ */
public final static String HTTPS_SCHEME = "https://";
+ /**
+ * FTP
+ */
public final static String FTP_SCHEME = "ftp://";
+ /**
+ * MMS
+ */
public final static String MMS_SCHEME = "mms://";
+ /**
+ * RTSP
+ */
public final static String RTSP_SCHEME = "rtsp://";
+ /**
+ * Default scheme to assume if unspecified. No context implied...
+ */
public final static String DEFAULT_SCHEME = HTTP_SCHEME;
- // go brewster
+ /**
+ * go brewster
+ */
public final static String WAIS_SCHEME = "wais://";
+ /**
+ * array of static Strings for all "known" schemes
+ */
public final static String ALL_SCHEMES[] = {
HTTP_SCHEME,
HTTPS_SCHEME,
@@ -67,7 +91,14 @@
};
+ /**
+ * character separating host from port within a URL authority
+ */
public final static char PORT_SEPARATOR = ':';
+ /**
+ * character which delimits the path from the authority in a... in some
+ * URLs.
+ */
public final static char PATH_START = '/';
@@ -97,27 +128,35 @@
Pattern.compile("(([0-9a-z_.-]+)\\.(" + ALL_TLD_PATTERN + "))|" +
"(" + IP_PATTERN + ")");
- private static final Pattern AUTHORITY_REGEX_SIMPLE =
- Pattern.compile("([0-9a-z_.-]++)");
+// private static final Pattern AUTHORITY_REGEX_SIMPLE =
+// Pattern.compile("([0-9a-z_.-]++)");
private static final Pattern HOST_REGEX_SIMPLE =
Pattern.compile("(?:[0-9a-z_.:-]+@)?([0-9a-z_.-]++)");
private static final Pattern USERINFO_REGEX_SIMPLE =
Pattern.compile("([0-9a-z_.:-]+)(?:@[0-9a-z_.-]++)");
/**
- * @param urlPart
+ * Tests if the String argument looks like it could be a legitimate
+ * authority fragment of a URL, that is, is it an IP address, or, are the
+ * characters legal in an authority, and does the string end with a legal
+ * TLD.
+ *
+ * @param authString String representation of a fragment of a URL
* @return boolean indicating whether urlPart might be an Authority.
*/
- public static boolean isAuthority(String urlPart) {
- Matcher m = AUTHORITY_REGEX.matcher(urlPart);
+ public static boolean isAuthority(String authString) {
+ Matcher m = AUTHORITY_REGEX.matcher(authString);
return (m != null) && m.matches();
}
/**
- * @param baseUrl
- * @param url
- * @return url resolved against baseUrl, unless it is absolute already
+ * Resolve a possibly relative url argument against a base URL.
+ * @param baseUrl the base URL against which the url should be resolved
+ * @param url the URL, possibly relative, to make absolute.
+ * @return url resolved against baseUrl, unless it is absolute already, and
+ * further transformed by whatever escaping normally takes place with a
+ * UURI.
*/
public static String resolveUrl(String baseUrl, String url) {
for(final String scheme : ALL_SCHEMES) {
@@ -144,6 +183,11 @@
return resolvedURI.getEscapedURI();
}
+ /**
+ * Attempt to find the scheme (http://, https://, etc) from a given URL.
+ * @param url URL String to parse for a scheme.
+ * @return the scheme, including trailing "://" if known, null otherwise.
+ */
public static String urlToScheme(final String url) {
for(final String scheme : ALL_SCHEMES) {
if(url.startsWith(scheme)) {
@@ -153,6 +197,11 @@
return null;
}
+ /**
+ * Return the default port for the scheme String argument, if known.
+ * @param scheme String scheme, including '://', as in, "http://", "ftp://"
+ * @return the default port for the scheme, or -1 if the scheme isn't known.
+ */
public static int schemeToDefaultPort(final String scheme) {
if(scheme.equals(HTTP_SCHEME)) {
return 80;
@@ -172,6 +221,11 @@
return -1;
}
+ /**
+ * Attempt to extract the path component of a url String argument.
+ * @param url the URL which may contain a path, sans scheme.
+ * @return the path component of the URL, or "" if it contains no path.
+ */
public static String getURLPath(String url) {
int portIdx = url.indexOf(UrlOperations.PORT_SEPARATOR);
int pathIdx = url.indexOf(UrlOperations.PATH_START);
@@ -191,6 +245,12 @@
}
}
+ /**
+ * Attempt to extract the hostname component of an absolute URL argument.
+ * @param url the url String from which to extract the hostname
+ * @return the hostname within the URL, or the url argument if the host
+ * cannot be found.
+ */
public static String urlToHost(String url) {
String lcUrl = url.toLowerCase();
if(lcUrl.startsWith("dns:")) {
@@ -210,6 +270,13 @@
return url;
}
+ /**
+ * Extract userinfo from the absolute URL argument, that is, "username@", or
+ * "username:password@" if present.
+ * @param url the URL from which to extract the userinfo
+ * @return the userinfo found, not including the "@", or null if no userinfo
+ * is found
+ */
public static String urlToUserInfo(String url) {
String lcUrl = url.toLowerCase();
if(lcUrl.startsWith("dns:")) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
Revision: 3067
http://archive-access.svn.sourceforge.net/archive-access/?rev=3067&view=rev
Author: bradtofel
Date: 2010-04-27 20:51:27 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
JAVADOC
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/url/AggressiveUrlCanonicalizer.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/url/AggressiveUrlCanonicalizer.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/url/AggressiveUrlCanonicalizer.java 2010-04-24 01:07:50 UTC (rev 3066)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/url/AggressiveUrlCanonicalizer.java 2010-04-27 20:51:27 UTC (rev 3067)
@@ -193,13 +193,6 @@
return false;
}
- /**
- * return the canonical string key for the URL argument.
- *
- * @param urlString
- * @return String lookup key for URL argument.
- * @throws URIException
- */
public String urlStringToKey(final String urlString) throws URIException {
if(urlString.startsWith("dns:")) {
@@ -323,7 +316,7 @@
System.exit(3);
}
/**
- * @param args
+ * @param args program arguments
*/
public static void main(String[] args) {
AggressiveUrlCanonicalizer canonicalizer = new AggressiveUrlCanonicalizer();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
Revision: 3057
http://archive-access.svn.sourceforge.net/archive-access/?rev=3057&view=rev
Author: bradtofel
Date: 2010-04-24 00:20:49 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
BUGFIX: Was not setting 'id' member to something unique in the constructor.
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/RobotAccessControlException.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/RobotAccessControlException.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/RobotAccessControlException.java 2010-04-24 00:20:03 UTC (rev 3056)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/RobotAccessControlException.java 2010-04-24 00:20:49 UTC (rev 3057)
@@ -30,11 +30,13 @@
*
*/
public class RobotAccessControlException extends AccessControlException {
+ protected static final String ID = "accessRobots";
/**
* @param message
*/
public RobotAccessControlException(String message) {
super("Blocked By Robots",message);
+ id = ID;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-24 01:22:17
|
Revision: 3060
http://archive-access.svn.sourceforge.net/archive-access/?rev=3060&view=rev
Author: bradtofel
Date: 2010-04-24 00:26:35 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
INITIAL REV: sinple jsp which uses the Graph library to generate and return a graph image
Added Paths:
-----------
trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/jsp/graph.jsp
Added: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/jsp/graph.jsp
===================================================================
--- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/jsp/graph.jsp (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/jsp/graph.jsp 2010-04-24 00:26:35 UTC (rev 3060)
@@ -0,0 +1,24 @@
+<%@
+page import="java.util.Date"
+%><%@
+page import="org.archive.wayback.util.graph.Graph"
+%><%@
+page import="org.archive.wayback.util.graph.GraphRenderer"
+%><%@
+page import="org.archive.wayback.util.graph.GraphEncoder"
+%><%
+Date now = new Date();
+String arg = request.getParameter("graphdata");
+if(arg == null) {
+ arg = "(No Data specified)";
+}
+GraphRenderer r = new GraphRenderer();
+response.setContentType(GraphRenderer.RENDERED_IMAGE_MIME);
+Graph graph = GraphEncoder.decode(arg);
+try {
+ r.render(response.getOutputStream(),graph);
+} catch(Exception e) {
+ e.printStackTrace(System.out);
+ //e.printStackTrace(response.getWriter());
+}
+%>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
Revision: 3059
http://archive-access.svn.sourceforge.net/archive-access/?rev=3059&view=rev
Author: bradtofel
Date: 2010-04-24 00:24:24 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
FEATURE: Now accepts 14-digits-plus-asterisk as a valid *query* datespec, allowing a query to include additional date context.
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java
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 2010-04-24 00:22:40 UTC (rev 3058)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/PathDatePrefixQueryRequestParser.java 2010-04-24 00:24:24 UTC (rev 3059)
@@ -53,7 +53,7 @@
* URL
*/
private final static Pattern WB_QUERY_REGEX = Pattern
- .compile("^(\\d{0,13})\\*/(.*[^*])$");
+ .compile("^(\\d{0,14})\\*/(.*[^*])$");
public WaybackRequest parse(String requestPath, AccessPoint ap) {
@@ -66,16 +66,24 @@
String urlStr = matcher.group(2);
String startDate;
- String endDate;
+ String endDate;
+ String requestDate;
if(dateStr.length() == 0) {
startDate = getEarliestTimestamp();
endDate = getLatestTimestamp();
+ requestDate = endDate;
+ } else if(dateStr.length() == 14) {
+ startDate = getEarliestTimestamp();
+ endDate = getLatestTimestamp();
+ requestDate = Timestamp.parseAfter(dateStr).getDateStr();
} else {
startDate = Timestamp.parseBefore(dateStr).getDateStr();
endDate = Timestamp.parseAfter(dateStr).getDateStr();
+ requestDate = endDate;
}
wbRequest.setStartTimestamp(startDate);
wbRequest.setEndTimestamp(endDate);
+ wbRequest.setReplayTimestamp(requestDate);
wbRequest.setCaptureQueryRequest();
wbRequest.setRequestUrl(urlStr);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-24 01:07:56
|
Revision: 3066
http://archive-access.svn.sourceforge.net/archive-access/?rev=3066&view=rev
Author: bradtofel
Date: 2010-04-24 01:07:50 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
TWEAK: added text from the GraphDisclaimer.jsp
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/classes/WaybackUI.properties
Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/classes/WaybackUI.properties
===================================================================
--- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/classes/WaybackUI.properties 2010-04-24 00:51:12 UTC (rev 3065)
+++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/classes/WaybackUI.properties 2010-04-24 01:07:50 UTC (rev 3066)
@@ -134,6 +134,13 @@
PartitionSize.dateHeader.week={0,date,MMM d} - {1,date,MMM d}
PartitionSize.dateHeader.year={0,date,yyyy}
+GraphTimeline.urlLabel=Url:
+GraphTimeline.dateLabel=Date:
+GraphTimeline.dateShortFormat={0,date,MMM d, yyyy}
+GraphTimeline.dateLongFormat={0,date,H:mm:ss MMM d, yyyy}
+GraphTimeline.searchLabel=Search:
+GraphTimeline.searchButtonText=Go
+
graph.title=Jump to first record in {0,date,yyyy} : ({0,date,MMM d})
graph.prevYear= ‹‹‹‹Year
graph.prevMonth=‹‹‹Month
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-24 00:51:18
|
Revision: 3065
http://archive-access.svn.sourceforge.net/archive-access/?rev=3065&view=rev
Author: bradtofel
Date: 2010-04-24 00:51:12 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
BUGFIX: was missing META Refresh rewriting. Also made the new GraphDisclaimer the default
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlSaxReplay.xml
Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlSaxReplay.xml
===================================================================
--- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlSaxReplay.xml 2010-04-24 00:49:18 UTC (rev 3064)
+++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlSaxReplay.xml 2010-04-24 00:51:12 UTC (rev 3065)
@@ -33,6 +33,9 @@
<bean id="jsBlockHandler"
class="org.archive.wayback.replay.html.transformer.JSStringTransformer">
</bean>
+ <bean id="metaRefreshHandler"
+ class="org.archive.wayback.replay.html.transformer.MetaRefreshUrlStringTransformer">
+ </bean>
@@ -40,13 +43,29 @@
class="org.archive.wayback.replay.html.ReplayParseEventDelegator">
<property name="parserVisitors">
<list>
+ <!-- this bean dumps each tag as it was found, inside comments,
+ before meddling, which can help with debugging.
<bean class="org.archive.wayback.replay.html.rules.CommentRule">
</bean>
+ -->
<bean
class="org.archive.wayback.replay.html.rules.AfterBodyStartTagJSPExecRule">
+ <property name="jspPath" value="/WEB-INF/replay/DisclaimChooser.jsp" />
+ <!--
<property name="jspPath" value="/WEB-INF/replay/DebugBanner.jsp" />
+ <property name="jspPath" value="/WEB-INF/replay/Disclaimer.jsp" />
+ -->
</bean>
+ <bean class="org.archive.wayback.replay.html.rules.AttributeModifyingRule">
+ <property name="tagName" value="META" />
+ <property name="whereAttributeName" value="http-equiv" />
+ <property name="whereAttributeValue" value="refresh" />
+
+ <property name="modifyAttributeName" value="content" />
+ <property name="transformer" ref="metaRefreshHandler" />
+ </bean>
+
<bean class="org.archive.wayback.replay.html.rules.AttributeModifyingRule">
<property name="tagName" value="A" />
<property name="modifyAttributeName" value="HREF" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-24 00:49:24
|
Revision: 3064
http://archive-access.svn.sourceforge.net/archive-access/?rev=3064&view=rev
Author: bradtofel
Date: 2010-04-24 00:49:18 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
FEATURE: Added "id_" datespec flag to force transparent replay of any old content
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlReplay.xml
Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlReplay.xml
===================================================================
--- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlReplay.xml 2010-04-24 00:48:09 UTC (rev 3063)
+++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/ArchivalUrlReplay.xml 2010-04-24 00:49:18 UTC (rev 3064)
@@ -50,6 +50,11 @@
<bean id="archivaltransparentreplayrenderer" class="org.archive.wayback.replay.TransparentReplayRenderer">
<constructor-arg><ref bean="archivalurlhttpheaderprocessor"/></constructor-arg>
</bean>
+ <bean id="identityreplayrenderer" class="org.archive.wayback.replay.TransparentReplayRenderer">
+ <constructor-arg>
+ <bean id="identityhttpheaderprocessor" class="org.archive.wayback.replay.IdentityHttpHeaderProcessor"/>
+ </constructor-arg>
+ </bean>
<!--
The following bean is an example of the experimental Regex-Based
@@ -136,6 +141,11 @@
<property name="renderer" ref="archivaltransparentreplayrenderer"/>
</bean>
+ <!-- Explicit (via "id_" flag) IDENTITY/RAW REPLAY -->
+ <bean class="org.archive.wayback.replay.selector.IdentityRequestSelector">
+ <property name="renderer" ref="identityreplayrenderer"/>
+ </bean>
+
<!-- HTML REPLAY -->
<bean class="org.archive.wayback.replay.selector.MimeTypeSelector">
<property name="mimeContains">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-24 00:48:15
|
Revision: 3063
http://archive-access.svn.sourceforge.net/archive-access/?rev=3063&view=rev
Author: bradtofel
Date: 2010-04-24 00:48:09 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
INITIAL REV: .jsp disclaimer which "forks" to either a "cool new" GraphTimeline disclaimer, or to a simple disclaimer which indicates a live web capture
Added Paths:
-----------
trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/DisclaimChooser.jsp
trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/GraphDisclaimer.jsp
trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/LiveWebDisclaimer.jsp
Added: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/DisclaimChooser.jsp
===================================================================
--- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/DisclaimChooser.jsp (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/DisclaimChooser.jsp 2010-04-24 00:48:09 UTC (rev 3063)
@@ -0,0 +1,14 @@
+<%@
+ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"
+%><%@
+ page import="org.archive.wayback.core.UIResults"
+%><%@
+ page import="org.archive.wayback.core.WaybackRequest"
+%><%
+UIResults results = UIResults.extractReplay(request);
+WaybackRequest wbr = results.getWbRequest();
+if(wbr.isLiveWebRequest()) {
+ %><jsp:include page="/WEB-INF/replay/LiveWebDisclaimer.jsp" flush="true" /><%
+} else {
+ %><jsp:include page="/WEB-INF/replay/GraphDisclaimer.jsp" flush="true" /><%
+}%>
\ No newline at end of file
Added: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/GraphDisclaimer.jsp
===================================================================
--- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/GraphDisclaimer.jsp (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/GraphDisclaimer.jsp 2010-04-24 00:48:09 UTC (rev 3063)
@@ -0,0 +1,258 @@
+<%@
+ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"
+ %><%@
+ page import="java.util.Iterator"
+ %><%@
+ page import="java.util.ArrayList"
+ %><%@
+ page import="java.util.Date"
+ %><%@
+ page import="java.util.List"
+ %><%@
+ page import="java.text.ParseException"
+ %><%@
+ page import="org.archive.wayback.ResultURIConverter"
+ %><%@
+ page import="org.archive.wayback.WaybackConstants"
+ %><%@
+ page import="org.archive.wayback.core.CaptureSearchResult"
+ %><%@
+ page import="org.archive.wayback.core.CaptureSearchResults"
+ %><%@
+ page import="org.archive.wayback.core.UIResults"
+ %><%@
+ page import="org.archive.wayback.core.WaybackRequest"
+ %><%@
+ page import="org.archive.wayback.partition.CaptureSearchResultPartitionMap"
+ %><%@
+ page import="org.archive.wayback.partition.PartitionPartitionMap"
+ %><%@
+ page import="org.archive.wayback.partition.PartitionsToGraph"
+ %><%@
+ page import="org.archive.wayback.util.graph.Graph"
+ %><%@
+ page import="org.archive.wayback.util.graph.GraphEncoder"
+ %><%@
+ page import="org.archive.wayback.util.graph.GraphRenderer"
+ %><%@
+ page import="org.archive.wayback.util.partition.Partition"
+ %><%@
+ page import="org.archive.wayback.util.partition.Partitioner"
+ %><%@
+ page import="org.archive.wayback.util.partition.PartitionSize"
+ %><%@
+ page import="org.archive.wayback.util.StringFormatter"
+ %><%
+UIResults results = UIResults.extractReplay(request);
+WaybackRequest wbRequest = results.getWbRequest();
+ResultURIConverter uriConverter = results.getURIConverter();
+String contextRoot = wbRequest.getContextPrefix();
+StringFormatter fmt = wbRequest.getFormatter();
+String staticPrefix = results.getContextConfig("static-prefix");
+if(staticPrefix == null) {
+ staticPrefix = contextRoot;
+}
+
+String graphJspPrefix = results.getContextConfig("graphJspPrefix");
+if(graphJspPrefix == null) {
+ graphJspPrefix = contextRoot;
+}
+CaptureSearchResults cResults = results.getCaptureResults();
+
+String exactDateStr = results.getResult().getCaptureTimestamp();
+Date exactDate = results.getResult().getCaptureDate();
+String searchUrl = wbRequest.getRequestUrl();
+String searchUrlSafe = fmt.escapeHtml(wbRequest.getRequestUrl());
+String searchUrlJS = fmt.escapeJavaScript(wbRequest.getRequestUrl());
+String resolution = wbRequest.getTimelineResolution();
+
+CaptureSearchResult first = null;
+CaptureSearchResult prev = null;
+CaptureSearchResult next = null;
+CaptureSearchResult last = null;
+
+Date firstDate = cResults.getFirstResultDate();
+Date lastDate = cResults.getLastResultDate();
+
+long resultCount = cResults.getReturnedCount();
+int resultIndex = 1;
+
+CaptureSearchResultPartitionMap monthMap =
+ new CaptureSearchResultPartitionMap();
+PartitionSize monthSize = Partitioner.monthSize;
+Partitioner<CaptureSearchResult> monthPartitioner =
+ new Partitioner<CaptureSearchResult>(monthMap);
+
+PartitionPartitionMap yearMap =
+ new PartitionPartitionMap();
+PartitionSize yearSize = Partitioner.yearSize;
+Partitioner<Partition<CaptureSearchResult>> yearPartitioner =
+ new Partitioner<Partition<CaptureSearchResult>>(yearMap);
+
+List<Partition<Partition<CaptureSearchResult>>> yearPartitions =
+ yearPartitioner.getRange(yearSize,firstDate,lastDate);
+
+int imgWidth = 800;
+int imgHeight = 35;
+Date firstYearDate = yearPartitions.get(0).getStart();
+Date lastYearDate = yearPartitions.get(yearPartitions.size()-1).getEnd();
+
+List<Partition<CaptureSearchResult>> monthPartitions =
+ monthPartitioner.getRange(monthSize,firstYearDate,lastYearDate);
+
+Iterator<CaptureSearchResult> it = cResults.iterator();
+
+monthPartitioner.populate(monthPartitions,it);
+
+yearPartitioner.populate(yearPartitions,monthPartitions.iterator());
+
+String yearFormatKey = "PartitionSize.dateHeader.yearGraphLabel";
+Graph graph = PartitionsToGraph.partsOfPartsToGraph(yearPartitions,fmt,yearFormatKey,imgWidth,imgHeight);
+String encodedGraph = GraphEncoder.encode(graph);
+String imgUrl = graphJspPrefix + "jsp/graph.jsp?graphdata=" + encodedGraph;
+String starLink = fmt.escapeHtml(contextRoot + "*/" + searchUrl);
+%>
+<!-- BEGIN WAYBACK TIMELINE DISCLAIMER INSERT -->
+<style type="text/css">
+#wm-disclaim {
+display:none;
+line-height:normal !important;
+border:1px solid #000 !important;
+padding:5px !important;
+position:relative !important;
+z-index:99999 !important;
+color:#000 !important;
+background-color:#efefef !important;
+font-size:12px !important;
+font-family:helvetica !important;
+text-align:left !important;
+}
+.wm-disclaim-value {
+font-size: 18px !important;
+font-weight: bold !important;
+color: #333 !important;
+}
+.wm-disclaim-label {
+font-size: 18px !important;
+color: #999 !important;
+}
+#wm-disclaim a {
+color:#00f !important;
+text-decoration:underline !important;
+font-size:12px !important;
+}
+#wm-disclaim-hide {
+float:right !important;
+margin:0 0 5px 5px !important;
+border:1px solid #ccc !important;
+padding:1px 5px !important;
+cursor:default !important;
+font-size:10px !important;
+font-weight:bold !important;
+color:#666 !important;
+}
+#wm-disclaim-hide:hover {
+border:1px outset #ccc !important;
+}
+#wm-disclaim-hide:focus, #wm-disclaim-hide:active {
+border:1px inset #ccc !important;
+}
+.wm-nav-link-div {
+padding:3px !important;
+text-align:center !important;
+}
+</style>
+<script type="text/javascript" src="<%= contextRoot %>js/graph-calc.js" ></script>
+<script type="text/javascript">
+var firstDate = <%= firstYearDate.getTime() %>;
+var lastDate = <%= lastYearDate.getTime() %>;
+var wbPrefix = "<%= contextRoot %>";
+var wbCurrentUrl = "<%= searchUrlJS %>";
+</script>
+<div id="wm-disclaim" dir="ltr" >
+ <table width="100%" border="0" cellpadding="0" cellspacing="3">
+ <tr>
+ <!-- WAYBACK LOGO -->
+ <td rowspan="2" valign="top" align="left"><a href="<%= contextRoot %>"><img style="padding-right:15px;" src="<%= staticPrefix %>images/wayback_logo_tr.gif" width="153" height="54" border="0"></a></td>
+ <!-- /WAYBACK LOGO -->
+ <td width="99%">
+ <table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td>
+ <table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td width="90%" style="text-align:left; vertical-align:top;">
+ <span class="wm-disclaim-label"><%= fmt.format("GraphTimeline.urlLabel") %></span> <span class="wm-disclaim-value"><%= searchUrlSafe %></span>
+ </td>
+ <td width="10%">
+ <!-- URL FORM -->
+ <table border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <form action="<%= contextRoot %>query" method="get">
+ <td class="wm-disclaim-label"><%= fmt.format("GraphTimeline.searchLabel") %></td>
+ <td><input type="hidden" name="<%= WaybackRequest.REQUEST_TYPE %>" value="<%= WaybackRequest.REQUEST_CAPTURE_QUERY %>"><input type="text" name="<%= WaybackRequest.REQUEST_URL %>" value="http://" size="24" maxlength="256"></td>
+ <td><input type="submit" name="submit" value="<%= fmt.format("GraphTimeline.searchButtonText") %>"></td>
+ </form>
+ </tr>
+ </table>
+ <!-- /URL FORM -->
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td width="300" title="<%= fmt.format("GraphTimeline.dateLongFormat",exactDate) %>" class="wm-disclaim-label"><%= fmt.format("GraphTimeline.dateLabel") %> <span class="wm-disclaim-value"><%= fmt.spaceToNBSP(fmt.format("GraphTimeline.dateShortFormat",exactDate)) %></span></td>
+ <td width="40%">
+ <div class="wm-nav-link-div">
+ <a id="wm-graph-anchor" href="">
+ <img width="<%= imgWidth %>"
+ height="<%= imgHeight %>"
+ src="<%= imgUrl %>"
+ border="0"
+ onmousemove="document.getElementById('wm-graph-anchor').href= wbPrefix + calcTimestamp(event,this,firstDate,lastDate) + '/' + wbCurrentUrl"></img>
+ </a>
+ </div>
+ <div class="wm-nav-link-div">
+ <%
+ String navs[] = PartitionsToGraph.getNavigators(fmt,results.getResult());
+ String links[] = PartitionsToGraph.getNavigatorLinks(yearPartitions,uriConverter);
+ links[PartitionsToGraph.NAV_CURRENT] = starLink;
+ for(int i = 0; i < navs.length; i++) {
+ if(i > 0) {
+ %> <%
+ }
+ if(links[i] == null) {
+ %><%= navs[i] %><%
+ } else {
+ %> <a href="<%= links[i] %>"><%= navs[i] %></a> <%
+ }
+ }
+ %>
+ </div>
+ </td>
+ <td width="%1" align="right" valign="bottom">
+ <div id="wm-disclaim-hide" onclick="document.getElementById('wm-disclaim').style.display='none'">
+ hide
+ </div>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+</div>
+<script type="text/javascript" src="<%= contextRoot %>js/disclaim-element.js" ></script>
+<script type="text/javascript">
+ var wmDisclaimBanner = document.getElementById("wm-disclaim");
+ if(wmDisclaimBanner != null) {
+ disclaimElement(wmDisclaimBanner);
+ }
+</script>
+<!-- END WAYBACK TIMELINE DISCLAIMER INSERT -->
Added: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/LiveWebDisclaimer.jsp
===================================================================
--- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/LiveWebDisclaimer.jsp (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/replay/LiveWebDisclaimer.jsp 2010-04-24 00:48:09 UTC (rev 3063)
@@ -0,0 +1,36 @@
+<%@
+ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"
+%><%@
+ page import="org.archive.wayback.core.CaptureSearchResult"
+%><%@
+ page import="org.archive.wayback.core.UIResults"
+%><%@
+ page import="org.archive.wayback.core.WaybackRequest"
+%><%@
+ page import="org.archive.wayback.util.StringFormatter"
+%><%
+UIResults results = UIResults.extractReplay(request);
+CaptureSearchResult result = results.getResult();
+WaybackRequest wbr = results.getWbRequest();
+StringFormatter fmt = wbr.getFormatter();
+String contextRoot = wbr.getContextPrefix();
+
+String urlString = fmt.escapeHtml(wbr.getRequestUrl());
+String prettyDateTime =
+ fmt.format("MetaReplay.captureDateDisplay", result.getCaptureDate());
+%>
+<!-- Start of LiveWebDisclaimer.jsp output -->
+<div id="wm-disclaim-banner" style="display:none; position:relative; z-index:99999; background-color:#ffffff; font-size:10px; text-align:center; width:100%;">
+ The URL you requested, <%= urlString %> does not exist in this archive.
+ Wayback is showing you a document captured <b>very recently</b> from the live web. The version of the document
+ you are now seeing, archived at <%= prettyDateTime %>, will become part of
+ the permanent archive after it has been added to the archive index.
+</div>
+<script type="text/javascript" src="<%= contextRoot %>js/disclaim-element.js" ></script>
+<script type="text/javascript">
+ var wmDisclaimBanner = document.getElementById("wm-disclaim-banner");
+ if(wmDisclaimBanner != null) {
+ disclaimElement(wmDisclaimBanner);
+ }
+</script>
+<!-- End of LiveWebDisclaimer.jsp output -->
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-24 00:42:33
|
Revision: 3062
http://archive-access.svn.sourceforge.net/archive-access/?rev=3062&view=rev
Author: bradtofel
Date: 2010-04-24 00:42:27 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
INITIAL REV: Code to translate a mouse horizontal location within an image, into a date, given a "start date" at the left edge of the image, and an "end date" at the right edge.
Added Paths:
-----------
trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/js/graph-calc.js
Added: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/js/graph-calc.js
===================================================================
--- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/js/graph-calc.js (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/js/graph-calc.js 2010-04-24 00:42:27 UTC (rev 3062)
@@ -0,0 +1,50 @@
+function getEventX(event) {
+ var posx = 0;
+ if (event.pageX || event.pageY) {
+ posx = event.pageX;
+ }
+ else if (event.clientX || event.clientY) {
+ posx = event.clientX + document.body.scrollLeft
+ + document.documentElement.scrollLeft;
+ }
+ return posx;
+}
+function getElementX(obj) {
+ var x = 0;
+ if (obj.offsetParent) {
+ do {
+ x += obj.offsetLeft;
+ } while (obj = obj.offsetParent);
+ }
+ return x;
+}
+function zeroPad(str,len) {
+ var i;
+ var pad = "";
+ var s = str.toString();
+ for(i=s.length; i < len; i++) {
+ pad = "0".toString() + pad.toString();
+ }
+ return pad.toString() + s.toString();
+}
+
+function dateToTimestamp(date) {
+ return date.getFullYear() +
+ zeroPad(date.getMonth()+1,2) +
+ zeroPad(date.getDay()+1,2) +
+ zeroPad(date.getHours(),2) +
+ zeroPad(date.getMinutes(),2) +
+ zeroPad(date.getSeconds(),2);
+}
+
+function calcTimestamp(event,element,firstMS,lastMS) {
+ var eventX = getEventX(event);
+ var elementX = getElementX(element);
+ var elementWidth = element.width;
+ var msWidth = lastMS - firstMS;
+ var x = eventX - elementX;
+ var pct = x / elementWidth;
+ var pctDate = pct * msWidth;
+ var date = pctDate + firstMS;
+ return dateToTimestamp(new Date(date));
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-24 00:29:52
|
Revision: 3061
http://archive-access.svn.sourceforge.net/archive-access/?rev=3061&view=rev
Author: bradtofel
Date: 2010-04-24 00:29:46 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
TWEAK: added new messages for
live web cache exceptions
robots blocked content
labels inside graphs
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/classes/WaybackUI.properties
Modified: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/classes/WaybackUI.properties
===================================================================
--- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/classes/WaybackUI.properties 2010-04-24 00:26:35 UTC (rev 3060)
+++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/WEB-INF/classes/WaybackUI.properties 2010-04-24 00:29:46 UTC (rev 3061)
@@ -1,7 +1,9 @@
Exception.wayback.title=Wayback Exception
Exception.wayback.message=An unknown exception has occured. {0}
-Exception.accessControl.title=Access Control Exception
+Exception.accessControl.title=Blocked Content
Exception.accessControl.message=Access to this content has been blocked. {0}
+Exception.accessRobots.title=Blocked Content
+Exception.accessRobots.message=Access to this content has been blocked by the sites robots.txt document.
Exception.authenticationControl.title=Authentication Control Exception
Exception.authenticationControl.message=This content is not accessible as the current user or from your current location. {0}
Exception.badContent.title=Bad Content Exception
@@ -12,6 +14,10 @@
Exception.betterRequest.message=The request you made can be better expressed with another request. {0}
Exception.configuration.title=Configuration Exception
Exception.configuration.message=This service has not been properly configured. {0}
+Exception.liveDocumentNotAvailable.title=Not In Archive
+Exception.liveDocumentNotAvailable.message=The document you requested is not in this archive, and is not available from the live web.
+Exception.liveWebCacheNotAvailable.title=Internal Service Problem
+Exception.liveWebCacheNotAvailable.message=The gateway to the live web is not available. Please try again later.
Exception.resourceIndexNotAvailable.title=Resource Index Not Available Exception
Exception.resourceIndexNotAvailable.message=The Resource Index required to satisfy this request is temporarily unavailable. Please try again later.
Exception.resourceNotAvailable.title=Resource Not Available
@@ -133,9 +139,11 @@
graph.prevMonth=‹‹‹Month
graph.prevDay=‹‹Day
graph.prevCapture=‹Prev
-graph.current=Showing Date {1,date,MMM yyyy}
+graph.current=See All Versions
graph.nextCapture=Next›
graph.nextDay=Day››
graph.nextMonth=Month›››
graph.nextYear=Year››››
+PartitionSize.dateHeader.yearGraphLabel={0,date,yyyy}
+PartitionSize.dateHeader.monthGraphLabel={0,date,MMM}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-24 00:22:46
|
Revision: 3058
http://archive-access.svn.sourceforge.net/archive-access/?rev=3058&view=rev
Author: bradtofel
Date: 2010-04-24 00:22:40 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
BUGFIX: was not ensuring the ChunkedInputStream was buffered, which is required for charset detection..
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Resource.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Resource.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Resource.java 2010-04-24 00:20:49 UTC (rev 3057)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Resource.java 2010-04-24 00:22:40 UTC (rev 3058)
@@ -124,7 +124,7 @@
}
is.reset();
if(isChunked) {
- is = new ChunkedInputStream(is);
+ setInputStream(new ChunkedInputStream(is));
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bra...@us...> - 2010-04-24 00:20:09
|
Revision: 3056
http://archive-access.svn.sourceforge.net/archive-access/?rev=3056&view=rev
Author: bradtofel
Date: 2010-04-24 00:20:03 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
INITIAL REV: Wayback-specific glue code to map CaptureSearchResults into partitions, and to map partitions into Graph, and HTML, (hopefully) simplifying .JSP pages wanting to use Partitions and Graphs.
Added Paths:
-----------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/CaptureSearchResultPartitionMap.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionPartitionMap.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionsToGraph.java
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/CaptureSearchResultPartitionMap.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/CaptureSearchResultPartitionMap.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/CaptureSearchResultPartitionMap.java 2010-04-24 00:20:03 UTC (rev 3056)
@@ -0,0 +1,54 @@
+/* CaptureSearchResultPartitionMap
+ *
+ * $Id$:
+ *
+ * Created on Apr 8, 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.partition;
+
+import java.util.Date;
+
+import org.archive.wayback.core.CaptureSearchResult;
+import org.archive.wayback.util.partition.ElementPartitionMap;
+import org.archive.wayback.util.partition.Partition;
+
+/**
+ * @author brad
+ *
+ */
+public class CaptureSearchResultPartitionMap
+ implements ElementPartitionMap<CaptureSearchResult> {
+
+ public void addElementToPartition(CaptureSearchResult element,
+ Partition<CaptureSearchResult> partition) {
+ partition.add(element);
+ partition.addTotal(1);
+ if(element.isClosest()) {
+ partition.setContainsClosest(true);
+ }
+ }
+
+ public Date elementToDate(CaptureSearchResult element) {
+ return element.getCaptureDate();
+ }
+
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/CaptureSearchResultPartitionMap.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionPartitionMap.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionPartitionMap.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionPartitionMap.java 2010-04-24 00:20:03 UTC (rev 3056)
@@ -0,0 +1,60 @@
+/* PartitionPartitionMap
+ *
+ * $Id$:
+ *
+ * Created on Apr 8, 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.partition;
+
+import java.util.Date;
+
+import org.archive.wayback.core.CaptureSearchResult;
+import org.archive.wayback.util.partition.ElementPartitionMap;
+import org.archive.wayback.util.partition.Partition;
+
+/**
+ * @author brad
+ *
+ */
+public class PartitionPartitionMap
+implements ElementPartitionMap<Partition<CaptureSearchResult>> {
+
+ /* (non-Javadoc)
+ * @see org.archive.wayback.util.partition.ElementPartitionMap#addElementToPartition(java.lang.Object, org.archive.wayback.util.partition.Partition)
+ */
+ public void addElementToPartition(Partition<CaptureSearchResult> element,
+ Partition<Partition<CaptureSearchResult>> partition) {
+ partition.add(element);
+ partition.addTotal(element.getTotal());
+ if(element.isContainsClosest()) {
+ partition.setContainsClosest(true);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.archive.wayback.util.partition.ElementPartitionMap#elementToDate(java.lang.Object)
+ */
+ public Date elementToDate(Partition<CaptureSearchResult> element) {
+ return element.getStart();
+ }
+
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionPartitionMap.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision Id
Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionsToGraph.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionsToGraph.java (rev 0)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionsToGraph.java 2010-04-24 00:20:03 UTC (rev 3056)
@@ -0,0 +1,567 @@
+/* PartitionsToGraph
+ *
+ * $Id$:
+ *
+ * Created on Apr 9, 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.partition;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.archive.wayback.ResultURIConverter;
+import org.archive.wayback.core.CaptureSearchResult;
+import org.archive.wayback.util.StringFormatter;
+import org.archive.wayback.util.Timestamp;
+import org.archive.wayback.util.graph.Graph;
+import org.archive.wayback.util.graph.GraphConfiguration;
+import org.archive.wayback.util.graph.RegionData;
+import org.archive.wayback.util.partition.Partition;
+import org.archive.wayback.util.partition.PartitionSize;
+import org.archive.wayback.util.partition.Partitioner;
+
+/**
+ * @author brad
+ *
+ */
+public class PartitionsToGraph {
+
+ public final static int NAV_COUNT = 9;
+
+ public final static int NAV_PREV_YEAR = 0;
+ public final static int NAV_PREV_MONTH = 1;
+ public final static int NAV_PREV_DAY = 2;
+ public final static int NAV_PREV_CAPTURE = 3;
+ public final static int NAV_CURRENT = 4;
+ public final static int NAV_NEXT_CAPTURE = 5;
+ public final static int NAV_NEXT_DAY = 6;
+ public final static int NAV_NEXT_MONTH = 7;
+ public final static int NAV_NEXT_YEAR = 8;
+
+
+ private static final TimeZone TZ_UTC = TimeZone.getTimeZone("UTC");
+
+ private static String joinInts(int[] a) {
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for(int i : a) {
+ if(first) {
+ sb.append(i);
+ first = false;
+ } else {
+ sb.append(",").append(i);
+ }
+ }
+ return sb.toString();
+ }
+ private static void printAr(String name, int o[], int n[]) {
+ System.out.format("%s=========\nORIG(%s)\nNORM(%s)\n",
+ name,joinInts(o),joinInts(n));
+ }
+
+ private static int normalizeInt(int input, int localMax, int maxOutput) {
+ double ln = Math.log(localMax);
+ if(input == 0) {
+ return 0;
+
+ } else if(input == 1) {
+ return 1;
+ } else {
+ double iln = Math.log(input);
+ double pct = iln / ln;
+ double num = pct * maxOutput;
+ int idx = (int) num;
+ System.out.format("%d - %f - %f - %f - %f : %d\n",
+ input,ln,iln,pct,num,idx);
+ if(input < idx) {
+ return input;
+ } else {
+ return idx;
+ }
+ }
+ }
+
+ private static int[] normalizeTo(int input[], int max) {
+ int localMax = -1;
+ for(int i = 0; i < input.length; i++) {
+ if(input[i] > localMax) localMax = input[i];
+ }
+ if(localMax < max) {
+ printAr("No normalization",input,input);
+ return input;
+ }
+ int normalized[] = new int[input.length];
+ double ln = Math.log(localMax);
+ for(int i = 0; i < input.length; i++) {
+ if(input[i] == 0) {
+ normalized[i] = 0;
+ } else if(input[i] == 1) {
+ normalized[i] = 1;
+ } else {
+ double iln = Math.log(input[i]);
+ double pct = iln / ln;
+ double num = pct * max;
+ int idx = (int) num;
+ System.out.format("%d - %d - %f - %f - %f - %f : %d\n",
+ i,input[i],ln,iln,pct,num,idx);
+ if(input[i] < idx) {
+ normalized[i] = input[i];
+ } else {
+ normalized[i] = idx;
+ }
+ }
+ }
+ printAr("NORMALIZED",input,normalized);
+ return normalized;
+ }
+
+ public static Calendar getUTCCalendar() {
+ return Calendar.getInstance(TZ_UTC);
+ }
+
+ public static Graph partsOfPartsToGraph(List<Partition<Partition<CaptureSearchResult>>> ppcs,
+ StringFormatter formatter, String formatKey, int width, int height) {
+
+ Calendar cal = Calendar.getInstance(TZ_UTC);
+ // FIRST PASS TO CALCULATE MONTH DOMAIN MAX:
+ int maxValue = -1;
+ for(Partition<Partition<CaptureSearchResult>> ppc : ppcs) {
+ for(Partition<CaptureSearchResult> pc : ppc.list()) {
+ if(pc.getTotal() > maxValue) {
+ maxValue = pc.getTotal();
+ }
+ }
+ }
+
+ RegionData data[] = new RegionData[ppcs.size()];
+ for(int y = 0; y < ppcs.size(); y++) {
+ int activeP = -1;
+ Partition<Partition<CaptureSearchResult>> ppc = ppcs.get(y);
+ String label = formatter.format(formatKey, ppc.getStart());
+// cal.setTime(ppc.getStart());
+// String label = String.valueOf(cal.get(Calendar.YEAR));
+ List<Partition<CaptureSearchResult>> pcs = ppc.list();
+ int count = pcs.size();
+ int values[] = new int[count];
+ for(int m = 0; m < count; m++) {
+ Partition<CaptureSearchResult> pc = pcs.get(m);
+ values[m] = normalizeInt(pc.getTotal(), maxValue, 15);
+ if(pc.isContainsClosest()) {
+ activeP = m;
+ }
+ }
+ data[y] = new RegionData(label, activeP, values);
+ }
+ GraphConfiguration config = new GraphConfiguration();
+ return new Graph(width, height, data, config);
+ }
+
+ public static List<Partition<Partition<CaptureSearchResult>>> reversePartsOfParts(List<Partition<Partition<CaptureSearchResult>>> parts) {
+ List<Partition<Partition<CaptureSearchResult>>> reversed =
+ new ArrayList<Partition<Partition<CaptureSearchResult>>>();
+ for(Partition<Partition<CaptureSearchResult>> p : parts) {
+ reversed.add(0, p);
+ }
+ return reversed;
+ }
+ public static List<Partition<CaptureSearchResult>> reversePartsOfCaps(List<Partition<CaptureSearchResult>> parts) {
+ List<Partition<CaptureSearchResult>> reversed =
+ new ArrayList<Partition<CaptureSearchResult>>();
+ for(Partition<CaptureSearchResult> p : parts) {
+ reversed.add(0, p);
+ }
+ return reversed;
+ }
+ public static List<CaptureSearchResult> reverseCaps(List<CaptureSearchResult> caps) {
+ List<CaptureSearchResult> reversed =
+ new ArrayList<CaptureSearchResult>();
+ for(CaptureSearchResult cap : caps) {
+ reversed.add(0, cap);
+ }
+ return reversed;
+ }
+
+ public static List<Partition<Partition<CaptureSearchResult>>> trimPartsOfParts(List<Partition<Partition<CaptureSearchResult>>> parts) {
+ int first = -1;
+ int last = -1;
+ for(int i = 0; i < parts.size(); i++) {
+ Partition<Partition<CaptureSearchResult>> p = parts.get(i);
+ if(p.getTotal() > 0) {
+ if(first == -1) {
+ first = i;
+ }
+ last = i;
+ }
+ }
+ return parts.subList(first, last+1);
+ }
+ public static List<Partition<CaptureSearchResult>> trimPartsOfCaps(List<Partition<CaptureSearchResult>> parts) {
+ int first = -1;
+ int last = -1;
+ for(int i = 0; i < parts.size(); i++) {
+ Partition<CaptureSearchResult> p = parts.get(i);
+ if(p.getTotal() > 0) {
+ if(first == -1) {
+ first = i;
+ }
+ last = i;
+ }
+ }
+ return parts.subList(first, last+1);
+ }
+
+ public static Graph convertYearMonth(List<Partition<Partition<CaptureSearchResult>>> years,
+ int width, int height) {
+
+ Calendar cal = Calendar.getInstance(TZ_UTC);
+ // FIRST PASS TO CALCULATE MONTH DOMAIN MAX:
+ int maxValue = -1;
+ for(Partition<Partition<CaptureSearchResult>> year : years) {
+ for(Partition<CaptureSearchResult> month : year.list()) {
+ if(month.getTotal() > maxValue) {
+ maxValue = month.getTotal();
+ }
+ }
+ }
+
+ RegionData yearRD[] = new RegionData[years.size()];
+ for(int y = 0; y < years.size(); y++) {
+ int activeMonth = -1;
+ Partition<Partition<CaptureSearchResult>> year = years.get(y);
+ cal.setTime(year.getStart());
+ String label = String.valueOf(cal.get(Calendar.YEAR));
+ List<Partition<CaptureSearchResult>> months = year.list();
+ if(months.size() != 12) {
+ throw new RuntimeException("Not 12 months...");
+ }
+ int values[] = new int[12];
+ for(int m = 0; m < 12; m++) {
+ Partition<CaptureSearchResult> month = months.get(m);
+ values[m] = normalizeInt(month.getTotal(), maxValue, 15);
+ if(month.isContainsClosest()) {
+ activeMonth = m;
+ }
+ }
+ yearRD[y] = new RegionData(label, activeMonth, values);
+ }
+ GraphConfiguration config = new GraphConfiguration();
+ return new Graph(width, height, yearRD, config);
+ }
+
+ public static String[] getTitles(CaptureSearchResult results[],
+ StringFormatter formatter, String property) {
+ int len = results.length;
+ String urls[] = new String[len];
+ for(int i = 0; i < len; i++) {
+ String url = null;
+ if(results[i] != null) {
+ url = formatter.format(property, results[i].getCaptureDate());
+ }
+ urls[i] = url;
+ }
+ return urls;
+ }
+ public static String[] getUrls(CaptureSearchResult results[], String suffix,
+ ResultURIConverter c) {
+ int len = results.length;
+ String urls[] = new String[len];
+ for(int i = 0; i < len; i++) {
+ String url = null;
+ if(results[i] != null) {
+ if(suffix == null) {
+ url = c.makeReplayURI(results[i].getCaptureTimestamp(),
+ results[i].getOriginalUrl());
+ } else {
+ url = c.makeReplayURI(results[i].getCaptureTimestamp() +
+ suffix, results[i].getOriginalUrl());
+ }
+ }
+ urls[i] = url;
+ }
+ return urls;
+ }
+ public static String[] getUrls(CaptureSearchResult results[],
+ ResultURIConverter c) {
+ return getUrls(results,null,c);
+ }
+
+ public static CaptureSearchResult[] getResults(
+ List<Partition<Partition<CaptureSearchResult>>> years) {
+
+ int count = years.size();
+ CaptureSearchResult results[] = new CaptureSearchResult[count];
+ for(int i = 0; i < count; i++) {
+ Partition<Partition<CaptureSearchResult>> year = years.get(i);
+ CaptureSearchResult first = null;
+ if(year.getTotal() > 0) {
+ for(Partition<CaptureSearchResult> month : year.list()) {
+ if(month.getTotal() > 0) {
+ first = month.list().get(0);
+ break;
+ }
+ }
+ }
+ results[i] = first;
+ }
+ return results;
+ }
+
+
+
+ public static String getFirstUrlMonth(Partition<CaptureSearchResult> month,
+ ResultURIConverter c) {
+ if(month.getTotal() > 0) {
+ CaptureSearchResult first = month.list().get(0);
+ return c.makeReplayURI(first.getCaptureTimestamp(),
+ first.getOriginalUrl());
+ }
+ return null;
+ }
+
+ public static String getLastUrlMonth(Partition<CaptureSearchResult> month,
+ ResultURIConverter c) {
+ if(month.getTotal() > 0) {
+ CaptureSearchResult last = month.list().get(month.list().size()-1);
+ return c.makeReplayURI(last.getCaptureTimestamp(),
+ last.getOriginalUrl());
+ }
+ return null;
+ }
+
+ public static String getFirstUrlYear(Partition<Partition<CaptureSearchResult>> year,
+ ResultURIConverter c) {
+ for(Partition<CaptureSearchResult> month : year.list()) {
+ String firstInMonth = getFirstUrlMonth(month,c);
+ if(firstInMonth != null) return firstInMonth;
+ }
+ return null;
+ }
+ public static String getLastUrlYear(Partition<Partition<CaptureSearchResult>> year,
+ ResultURIConverter c) {
+ List<Partition<CaptureSearchResult>> months = year.list();
+ for(int i = months.size()-1; i >= 0; i--) {
+ String firstInMonth = getLastUrlMonth(months.get(i),c);
+ if(firstInMonth != null) return firstInMonth;
+ }
+ return null;
+ }
+
+
+ public static String[] getNavigatorLinks(
+ List<Partition<Partition<CaptureSearchResult>>> years, ResultURIConverter uc) {
+ String navs[] = new String[NAV_COUNT];
+ for(int i = 0; i < NAV_COUNT; i++) {
+ navs[i] = null;
+ }
+ /*
+ * first traverse the years, grabbing:
+ * * the one *before*
+ * * the *current*
+ * * the one *after*
+ *
+ * the "active" year:
+ */
+
+ Partition<Partition<CaptureSearchResult>> prevYear = null;
+ Partition<Partition<CaptureSearchResult>> curYear = null;
+ Partition<Partition<CaptureSearchResult>> nextYear = null;
+
+ for(Partition<Partition<CaptureSearchResult>> year : years) {
+ if(year.isContainsClosest()) {
+ curYear = year;
+ } else {
+ // have we seen the current one?
+ if(curYear == null) {
+ // no, track this as the "prev", and continue:
+ if(year.getTotal() > 0) {
+ prevYear = year;
+ }
+ } else {
+ // yes, this is the "next", remember and break:
+ if(year.getTotal() > 0) {
+ nextYear = year;
+ break;
+ }
+ }
+ }
+ }
+ if(prevYear != null) {
+ navs[NAV_PREV_YEAR] = getLastUrlYear(prevYear, uc);
+ }
+ if(nextYear != null) {
+ navs[NAV_NEXT_YEAR] = getFirstUrlYear(nextYear, uc);
+ }
+ // now on to months:
+ List<Partition<CaptureSearchResult>> months = curYear.list();
+
+ Partition<CaptureSearchResult> prevMonth = null;
+ Partition<CaptureSearchResult> curMonth = null;
+ Partition<CaptureSearchResult> nextMonth = null;
+
+ for(Partition<CaptureSearchResult> month : months) {
+ if(month.isContainsClosest()) {
+ curMonth = month;
+ } else {
+ // have we seen the current one?
+ if(curMonth == null) {
+ // no, track this as the "prev", and continue:
+ if(month.getTotal() > 0) {
+ prevMonth = month;
+ }
+ } else {
+ // yes, this is the "next", remember and break:
+ if(month.getTotal() > 0) {
+ nextMonth = month;
+ break;
+ }
+ }
+ }
+ }
+
+ if(prevMonth != null) {
+ navs[NAV_PREV_MONTH] = getLastUrlMonth(prevMonth, uc);
+ } else {
+ // assume whatever we found for prev Year is OK, even if null:
+ navs[NAV_PREV_MONTH] = navs[NAV_PREV_YEAR];
+ }
+ if(nextMonth != null) {
+ navs[NAV_NEXT_MONTH] = getFirstUrlMonth(nextMonth, uc);
+ } else {
+ // assume whatever we found for next Year is OK, even if null:
+ navs[NAV_NEXT_MONTH] = navs[NAV_NEXT_YEAR];
+ }
+
+ // OK... now we're down to days... split the current month into days:
+ List<Partition<CaptureSearchResult>> days = splitToDays(curMonth);
+
+ Partition<CaptureSearchResult> prevDay = null;
+ Partition<CaptureSearchResult> curDay = null;
+ Partition<CaptureSearchResult> nextDay = null;
+
+ for(Partition<CaptureSearchResult> day : days) {
+ if(day.isContainsClosest()) {
+ curDay = day;
+ } else {
+ // have we seen the current one?
+ if(curDay == null) {
+ // no, track this as the "prev", and continue:
+ if(day.getTotal() > 0) {
+ prevDay = day;
+ }
+ } else {
+ // yes, this is the "next", remember and break:
+ if(day.getTotal() > 0) {
+ nextDay = day;
+ break;
+ }
+ }
+ }
+ }
+
+ if(prevDay != null) {
+ navs[NAV_PREV_DAY] = getLastUrlMonth(prevDay, uc);
+ } else {
+ // assume whatever we found for prev Month is OK, even if null:
+ navs[NAV_PREV_DAY] = navs[NAV_PREV_MONTH];
+ }
+ if(nextDay != null) {
+ navs[NAV_NEXT_DAY] = getFirstUrlMonth(nextDay, uc);
+ } else {
+ // assume whatever we found for next Month is OK, even if null:
+ navs[NAV_NEXT_DAY] = navs[NAV_NEXT_MONTH];
+ }
+
+ // FINALLY! We just need the next and prev links:
+ CaptureSearchResult prevResult = null;
+ CaptureSearchResult curResult = null;
+ CaptureSearchResult nextResult = null;
+ for(CaptureSearchResult result : curDay.list()) {
+ if(result.isClosest()) {
+ curResult = result;
+ } else {
+ // have we seen the current one?
+ if(curResult == null) {
+ // no, track this as the "prev", and continue:
+ prevResult = result;
+ } else {
+ // yes, this is the "next", remember and break:
+ nextResult = result;
+ break;
+ }
+ }
+ }
+ if(prevResult != null) {
+ navs[NAV_PREV_CAPTURE] =
+ uc.makeReplayURI(prevResult.getCaptureTimestamp(),
+ prevResult.getOriginalUrl());
+ } else {
+ // assume whatever we found for prev Day is OK, even if null:
+ navs[NAV_PREV_CAPTURE] = navs[NAV_PREV_DAY];
+ }
+ if(nextResult != null) {
+ navs[NAV_NEXT_CAPTURE] =
+ uc.makeReplayURI(nextResult.getCaptureTimestamp(),
+ nextResult.getOriginalUrl());
+ } else {
+ // assume whatever we found for prev Day is OK, even if null:
+ navs[NAV_NEXT_CAPTURE] = navs[NAV_NEXT_DAY];
+ }
+
+ return navs;
+ }
+
+ /**
+ * @param list
+ * @return
+ */
+ private static List<Partition<CaptureSearchResult>> splitToDays(
+ Partition<CaptureSearchResult> month) {
+ CaptureSearchResultPartitionMap map =
+ new CaptureSearchResultPartitionMap();
+ Partitioner<CaptureSearchResult> partitioner =
+ new Partitioner<CaptureSearchResult>(map);
+ PartitionSize daySize = Partitioner.daySize;
+ List<Partition<CaptureSearchResult>> days = partitioner.getRange(daySize,
+ month.getStart(), month.getEnd());
+ partitioner.populate(days, month.iterator());
+ return days;
+ }
+
+ public static String[] getNavigators(StringFormatter formatter, CaptureSearchResult current) {
+ String navs[] = new String[NAV_COUNT];
+ navs[NAV_PREV_YEAR] = formatter.format("graph.prevYear");
+ navs[NAV_PREV_MONTH] = formatter.format("graph.prevMonth");
+ navs[NAV_PREV_DAY] = formatter.format("graph.prevDay");
+ navs[NAV_PREV_CAPTURE] = formatter.format("graph.prevCapture");
+
+ navs[NAV_CURRENT] = formatter.format("graph.current", current.getOriginalUrl(),
+ current.getCaptureDate());
+
+ navs[NAV_NEXT_CAPTURE] = formatter.format("graph.nextCapture");
+ navs[NAV_NEXT_DAY] = formatter.format("graph.nextDay");
+ navs[NAV_NEXT_MONTH] = formatter.format("graph.nextMonth");
+ navs[NAV_NEXT_YEAR] = formatter.format("graph.nextYear");
+ return navs;
+ }
+}
Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/partition/PartitionsToGraph.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.
|