package net.google.safebrowsing;

import java.util.Map;

import net.google.safebrowsing2.Expression;
import net.google.safebrowsing2.ExpressionGenerator;
import net.google.safebrowsing2.JavaHelper;
import net.google.safebrowsing2.Lookup;
import net.google.safebrowsing2.SafeBrowsing2;
import net.google.safebrowsing2.db.Storage;

public class JavaCompatabilityTest {
	
	String apikey = "123456";
	String url = "jdbc:mysql://localhost:3306/googlesafebrowsing2";
	String tablePrefix = "gsb2_";
	
	public void safebrowsing2() throws Exception {
		Storage storage = JavaHelper.buildStorageMySQL(url, "user", "password", tablePrefix);
		SafeBrowsing2 sb2 = new SafeBrowsing2(apikey, storage);
		
		// update the database
		boolean forceUpdate = false;
		boolean useMac = false;
		String[] updateLists = null; // update all lists
		int wait = sb2.update(updateLists, forceUpdate, useMac);
		System.out.println("Seconds to wait before next update: " + wait);
		
		// lookup url in database
		String[] lookupLists = null; // lookup in all lists
		String match = sb2.jlookup("http://ianfette.org", lookupLists, useMac);
		if (match != null)
			System.out.println("Match found in list: " + match);
	}
	
	public void lookup() {
		Lookup lookup = new Lookup(apikey, "appname");
		Map<String, String> r = lookup.jlookup(new String[]{"http://ianfette.org"}, 0);
		for (String key : r.keySet()) {
			System.out.println(key + " -> " + r.get(key));
		}
	}
	
	public void getKeys() {
		String url = "http://www.google.com";
		ExpressionGenerator gen = new ExpressionGenerator(url);
		System.out.println("Host key for url: " + gen.getHostKey());
		System.out.println("Expressions for URL:");
		for (Expression exp : gen.getExpressions()) {
			System.out.println("	" + exp.value() + " -> " + exp.hexHash());
		}
	}
}

@@ -1206,19 +1206,142 @@
  lookup(
-) %7B
+String baseUrl) %7B%0A%09%09if (baseUrl == null %7C%7C baseUrl.isEmpty())%7B%0A%09%09%09baseUrl = %22https://sb-ssl.google.com/safebrowsing/api/%22;%0A%09%09%7D
 %0A%09%09Looku
@@ -1379,16 +1379,32 @@
 appname%22
+, baseUrl, %223.0%22
 );%0A%09%09Map
@@ -1927,10 +1927,125 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09new JavaCompatabilityTest().lookup(%22http://192.168.1.114:8082/%22);%0A%09%7D%0A
 %7D%0A

fix java compatability test