String query;
String terms;
StringBuffer buffer;
HttpURLConnection connection;
URL url;
Lexer lexer;
URL[][] results;
prefs = Preferences.userNodeForPackage (getClass ());
query = prefs.get (GOOGLEQUERY, DEFAULTGOOGLEQUERY);
try
{
query = (String)JOptionPane.showInputDialog (
this,
"Enter the search term:",
"Search Google",
JOptionPane.PLAIN_MESSAGE,
null,
null,
query);
if (null != query)
{
// replace spaces with +
terms = query.replace (' ', '+');
buffer = new StringBuffer (1024);
buffer.append ("http://www.google.ca/search?");
buffer.append ("q=");
buffer.append (terms);
buffer.append ("&ie=UTF-8");
buffer.append ("&oe=UTF-8");
buffer.append ("&hl=en");
buffer.append ("&btnG=Google+Search");
buffer.append ("&meta=");
url = new URL (buffer.toString ());
connection = (HttpURLConnection)url.openConnection ();
if (USE_MOZILLA_HEADERS)
{
// These are the Mozilla header fields:
//Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1
//Accept-Language: en-us, en;q=0.50
//Connection: keep-alive
//Host: grc.com
//Referer: https://grc.com/x/ne.dll?bh0bkyd2
//User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225
//Content-Length: 27
//Content-Type: application/x-www-form-urlencoded
//Accept-Encoding: gzip, deflate, compress;q=0.9
//Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66
//Keep-Alive: 300
connection.setRequestProperty ("Referer", "http://www.google.ca");
connection.setRequestProperty ("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1");
connection.setRequestProperty ("Accept-Language", "en-us, en;q=0.50");
connection.setRequestProperty ("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225");
connection.setRequestProperty ("Accept-Charset", "ISO-8859-1, utf-8;q=0.66, *;q=0.66");
}
else
{
// These are the IE header fields:
//Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
//Accept-Language: en-ca
//Connection: Keep-Alive
//Host: grc.com
//User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; trieste; .NET CLR 1.1.4322; .NET CLR 1.0.3705)
//Content-Length: 32
//Content-Type: application/x-www-form-urlencoded
//Accept-Encoding: gzip, deflate
//Cache-Control: no-cache
connection.setRequestProperty ("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
connection.setRequestProperty ("Accept-Language", "en-ca");
connection.setRequestProperty ("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; trieste; .NET CLR 1.1.4322; .NET CLR 1.0.3705)");
}
connection.setDoOutput (true);
connection.setDoInput (true);
connection.setUseCaches (false);
lexer = new Lexer (connection);
results = getThumbelina ().extractImageLinks (lexer, url);
// add 'em
getThumbelina ().reset ();
// remove google links, not just append (results[1]);
for (int i = 0; i < results[1].length; i++)