I'm trying to implement java URL into my gwt project. This is what I've done so far in terms of experimenting, trial-error, etc: HTML:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="Test_project.css">
<title>John Mathew's Google AJAX Search API Sample</title>
<script src="http://www.google.com/jsapi?key=*insert google api key*" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1');
google.setOnLoadCallback(function(){
var searchControl = new google.search.SearchControl();
searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
searchControl.addSearcher(new google.search.WebSearch());
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
searchControl.draw(document.getElementById("content"), drawOptions);
}, true);
</script>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en', style : google.loader.themes.SHINY});
google.setOnLoadCallback(function() {
var customSearchControl = new google.search.CustomSearchControl('*insert google cse id*');
CustomSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.draw('cse');
}, true);
</script>
<script type="text/javascript" language="javascript" src="test_project/test_project.nocache.js"></script>
Loading...
document.writeln('search engine 2');
Loading...
document.writeln('search engine 3');
<div id="customSearch"></div>
Now both parts of the javascript generates a google textbox and button. Upon entering information, it will return results. This isn't what I want. I would like to obtain the results for me to manipulate and play around with. So I did a bit of research and discovered PHP get_file_contents() and JAVA URL(). I've never had PHP experience so I went with Java (there is JQuery get() but I am confused on how to implement and couldn't find examples).
To understand how Java URL() works, I created a Java project and learned of this code:
URL urlsearch = new URL("*insert website*");
BufferedReader buffreader = new BufferedReader(new InputStreamReader(urlsearch.openStream()));
String HTMLdisplay;
while ((HTMLdisplay = buffreader.readLine()) != null) {
System.out.println(HTMLdisplay);
}
buffreader.close();
It works exactly how I wanted as it retrieves the html page source of a page (example: http://www.bing.com/search?q=gygax). To implement this, I created a project based on how http://code.google.com/webtoolkit/doc/latest/tutorial/create.html instructs thus in the HTML code above there is the line . The command that links the two is in the class onModuleLoad():
// Associate the Main panel with the HTML host page.
RootPanel.get("customSearch").add(mainPanel);
This sounds a bit confusing so I'll summarize a bit: using Google Widgets on my .java I created a textbox and button when I run it as a web application. When you click the button, it is suppose execute the java url code and retrieve the pagesource on what it queries. Instead I get these errors:
[DEBUG] [test_project] - Validating newly compiled units
[ERROR] [test_project] - Errors in 'file:/C:/*file path*/Test_project.java'
[ERROR] [test_project] - Line 92: No source code is available for type java.net.URL; did you forget to inherit a required module?
[ERROR] [test_project] - Line 93: No source code is available for type java.io.BufferedReader; did you forget to inherit a required module?
[ERROR] [test_project] - Line 93: No source code is available for type java.io.InputStreamReader; did you forget to inherit a required module?
[ERROR] [test_project] - Line 99: No source code is available for type java.net.MalformedURLException; did you forget to inherit a required module?
[ERROR] [test_project] - Line 102: The method exit(int) is undefined for the type System
[ERROR] [test_project] - Line 107: The method exit(int) is undefined for the type System
[TRACE] [test_project] - Finding entry point classes
[ERROR] [test_project] - Unable to find type 'com.example.test_project.client.Test_project'
[ERROR] [test_project] - Hint: Previous compiler errors may have made this type unavailable
[ERROR] [test_project] - Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
[ERROR] [test_project] - Failed to load module 'test_project' from user agent 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15 ( .NET CLR 3.5.30729; .NET4.0E)' at localhost:3410
I have import java.io.* and import java.net.* (have tried specific packages too) along with the many com.google.gwt packages.
MY QUESTION: How do I overcome these errors that prevent me from using JAVA URL in my GWT project?