package org.archive.url;

import org.apache.commons.httpclient.URIException;

public class WaybackURLKeyMaker implements URLKeyMaker {
//	URLCanonicalizer canonicalizer = new NonMassagingIAURLCanonicalizer();
	URLCanonicalizer canonicalizer = new DefaultIAURLCanonicalizer();
	
	private boolean surtMode = true;
	
	public WaybackURLKeyMaker()
	{

	}
	
	public boolean isSurtMode()
	{
		return surtMode;
	}
	
	public WaybackURLKeyMaker(boolean surtMode)
	{
		this.surtMode = surtMode;
	}

	public String makeKey(String url) throws URIException {
		if(url == null) {
			return "-";
		}
		if(url.length() == 0) {
			return "-";
		}
		if(url.startsWith("filedesc")) {
			return url;
		}
		if(url.startsWith("warcinfo")) {
			return url;
		}
		if(url.startsWith("dns:")) {
			String authority = url.substring(4);
			if (!surtMode) {
				return authority;
			}
			String surt = URLRegexTransformer.hostToSURT(authority);
			return surt + ")";
		}
		HandyURL hURL;

			hURL = URLParser.parse(url);
			canonicalizer.canonicalize(hURL);
			String key = hURL.getURLString(surtMode, surtMode, false);
			if (!surtMode) {
				return key;
			}
			int parenIdx = key.indexOf('(');
			if(parenIdx == -1) {
				// something very wrong..
				return url;
			}
			return key.substring(parenIdx+1);
//		} catch (URIException e) {
//			e.printStackTrace();
//		}
//		return url;
	}
}

@@ -271,16 +271,196 @@
 er();%0A%09%0A
+%09public URLCanonicalizer getCanonicalizer() %7B%0A%09%09return canonicalizer;%0A%09%7D%0A%0A%09public void setCanonicalizer(URLCanonicalizer canonicalizer) %7B%0A%09%09this.canonicalizer = canonicalizer;%0A%09%7D%0A%0A
 %09private

make canonicalizer in WaybackURLKeyMaker settable