From: <bra...@us...> - 2008-07-22 01:41:32
|
Revision: 2472 http://archive-access.svn.sourceforge.net/archive-access/?rev=2472&view=rev Author: bradtofel Date: 2008-07-22 01:41:41 +0000 (Tue, 22 Jul 2008) Log Message: ----------- INITIAL REV: ReplayRendererSelector interface, base class, and several subclasses. Allows config-time mappings of various ReplayRenderer implementations, based on Mime, DateMismatch, and Path Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ReplayRendererSelector.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/AlwaysMatchSelector.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/BaseReplayRendererSelector.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/DateMismatchSelector.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/MimeTypeSelector.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/PathMatchSelector.java Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ReplayRendererSelector.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ReplayRendererSelector.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ReplayRendererSelector.java 2008-07-22 01:41:41 UTC (rev 2472) @@ -0,0 +1,42 @@ +/* ReplayRendererSelector + * + * $Id$ + * + * Created on 11:49:40 AM Jul 18, 2008. + * + * Copyright (C) 2008 Internet Archive. + * + * This file is part of wayback. + * + * wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.replay; + +import org.archive.wayback.ReplayRenderer; +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.Resource; +import org.archive.wayback.core.WaybackRequest; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public interface ReplayRendererSelector { + public boolean canHandle(WaybackRequest wbRequest, + CaptureSearchResult result, Resource resource); + public ReplayRenderer getRenderer(); +} Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/AlwaysMatchSelector.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/AlwaysMatchSelector.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/AlwaysMatchSelector.java 2008-07-22 01:41:41 UTC (rev 2472) @@ -0,0 +1,47 @@ +/* AlwaysMatchSelector + * + * $Id$ + * + * Created on 12:36:59 PM Jul 18, 2008. + * + * Copyright (C) 2008 Internet Archive. + * + * This file is part of wayback. + * + * wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.replay.selector; + +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.Resource; +import org.archive.wayback.core.WaybackRequest; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class AlwaysMatchSelector extends BaseReplayRendererSelector { + + /* (non-Javadoc) + * @see org.archive.wayback.replay.selector.BaseReplayRendererSelector#canHandle(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.CaptureSearchResult, org.archive.wayback.core.Resource) + */ + @Override + public boolean canHandle(WaybackRequest wbRequest, + CaptureSearchResult result, Resource resource) { + return true; + } +} Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/BaseReplayRendererSelector.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/BaseReplayRendererSelector.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/BaseReplayRendererSelector.java 2008-07-22 01:41:41 UTC (rev 2472) @@ -0,0 +1,71 @@ +/* BaseReplayRendererSelector + * + * $Id$ + * + * Created on 11:55:37 AM Jul 18, 2008. + * + * Copyright (C) 2008 Internet Archive. + * + * This file is part of wayback. + * + * wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.replay.selector; + +import org.archive.wayback.ReplayRenderer; +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.Resource; +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.replay.ReplayRendererSelector; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public abstract class BaseReplayRendererSelector implements ReplayRendererSelector { + private final static long MAX_HTML_MARKUP_LENGTH = 1024 * 1024 * 5; + + protected long maxSize = MAX_HTML_MARKUP_LENGTH; + private ReplayRenderer renderer; + + /* (non-Javadoc) + * @see org.archive.wayback.replay.ReplayRendererSelector#canHandle(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.CaptureSearchResult, org.archive.wayback.core.Resource) + */ + public abstract boolean canHandle(WaybackRequest wbRequest, + CaptureSearchResult result, Resource resource); + + /* (non-Javadoc) + * @see org.archive.wayback.replay.ReplayRendererSelector#getRenderer() + */ + public ReplayRenderer getRenderer() { + return renderer; + } + + public void setRenderer(ReplayRenderer renderer) { + this.renderer = renderer; + } + public boolean isResourceTooBig(Resource resource) { + return (maxSize > 0) + && (resource.getRecordLength() > maxSize); + } + public long getMaxSize() { + return maxSize; + } + public void setMaxSize(long maxSize) { + this.maxSize = maxSize; + } +} Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/DateMismatchSelector.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/DateMismatchSelector.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/DateMismatchSelector.java 2008-07-22 01:41:41 UTC (rev 2472) @@ -0,0 +1,52 @@ +/* DateMismatchSelector + * + * $Id$ + * + * Created on 11:53:04 AM Jul 18, 2008. + * + * Copyright (C) 2008 Internet Archive. + * + * This file is part of wayback. + * + * wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.replay.selector; + +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.Resource; +import org.archive.wayback.core.WaybackRequest; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class DateMismatchSelector extends BaseReplayRendererSelector { + + /* (non-Javadoc) + * @see org.archive.wayback.replay.selector.BaseReplayRendererSelector#canHandle(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.CaptureSearchResult, org.archive.wayback.core.Resource) + */ + @Override + public boolean canHandle(WaybackRequest wbRequest, + CaptureSearchResult result, Resource resource) { + // if the result is not for the exact date requested, redirect to the + // exact date. some capture dates are not 14 digits, only compare as + // many digits as are in the result date: + String reqDateStr = wbRequest.getReplayTimestamp(); + String resDateStr = result.getCaptureTimestamp(); + return !resDateStr.equals(reqDateStr.substring(0, resDateStr.length())); + } +} Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/MimeTypeSelector.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/MimeTypeSelector.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/MimeTypeSelector.java 2008-07-22 01:41:41 UTC (rev 2472) @@ -0,0 +1,84 @@ +/* MimeTypeSelector + * + * $Id$ + * + * Created on 12:04:56 PM Jul 18, 2008. + * + * Copyright (C) 2008 Internet Archive. + * + * This file is part of wayback. + * + * wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.replay.selector; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.Resource; +import org.archive.wayback.core.WaybackRequest; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class MimeTypeSelector extends BaseReplayRendererSelector { + private Map<String,Object> mimeMatches = null; + private List<String> mimeContains = null; + + /* (non-Javadoc) + * @see org.archive.wayback.replay.selector.BaseReplayRendererSelector#canHandle(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.CaptureSearchResult, org.archive.wayback.core.Resource) + */ + @Override + public boolean canHandle(WaybackRequest wbRequest, + CaptureSearchResult result, Resource resource) { + if(isResourceTooBig(resource)) { + return false; + } + String mime = result.getMimeType(); + if(mimeMatches != null) { + if(mimeMatches.containsKey(mime)) { + return true; + } + } + if(mimeContains != null) { + for(String contains : mimeContains) { + if(mime.indexOf(contains) != -1) { + return true; + } + } + } + return false; + } + public void setMimeMatches(List<String> mimes) { + mimeMatches = new HashMap<String,Object>(); + for(String mime : mimes) { + mimeMatches.put(mime,null); + } + } + public List<String> getMimeMatches() { + return null; + } + public void setMimeContains(List<String> mimes) { + mimeContains = mimes; + } + public List<String> getMimeContains() { + return mimeContains; + } +} Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/PathMatchSelector.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/PathMatchSelector.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/selector/PathMatchSelector.java 2008-07-22 01:41:41 UTC (rev 2472) @@ -0,0 +1,91 @@ +/* PathMatchSelector + * + * $Id$ + * + * Created on 12:19:54 PM Jul 18, 2008. + * + * Copyright (C) 2008 Internet Archive. + * + * This file is part of wayback. + * + * wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.replay.selector; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import org.archive.wayback.core.CaptureSearchResult; +import org.archive.wayback.core.Resource; +import org.archive.wayback.core.WaybackRequest; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class PathMatchSelector extends BaseReplayRendererSelector { + + private List<String> pathContains = null; + private List<String> queryContains = null; + /* (non-Javadoc) + * @see org.archive.wayback.replay.selector.BaseReplayRendererSelector#canHandle(org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.CaptureSearchResult, org.archive.wayback.core.Resource) + */ + @Override + public boolean canHandle(WaybackRequest wbRequest, + CaptureSearchResult result, Resource resource) { + if(isResourceTooBig(resource)) { + return false; + } + try { + URL url = new URL(result.getOriginalUrl()); + if(pathContains != null) { + String path = url.getPath(); + for(String test : pathContains) { + if(path.indexOf(test) != -1) { + return true; + } + } + } + if(queryContains != null) { + String query = url.getQuery(); + if(query != null) { + for(String test : queryContains) { + if(query.indexOf(test) != -1) { + return true; + } + } + } + } + } catch (MalformedURLException e) { + // just eat it. + } + return false; + } + public List<String> getPathContains() { + return pathContains; + } + public void setPathContains(List<String> pathContains) { + this.pathContains = pathContains; + } + public List<String> getQueryContains() { + return queryContains; + } + public void setQueryContains(List<String> queryContains) { + this.queryContains = queryContains; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |