Skip to content

Commit

Permalink
Added new APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
acbart committed Jan 26, 2013
1 parent f31237d commit 6ec83f2
Show file tree
Hide file tree
Showing 70 changed files with 1,525 additions and 14 deletions.
Binary file modified BindingGenerator/bin/WSDLProcesser.class
Binary file not shown.
Binary file modified BindingGenerator/bin/XMLParser.class
Binary file not shown.
8 changes: 8 additions & 0 deletions WeatherAPI/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="C:/Users/acbart/Projects/WebInACan/Weatherer/libs/json-simple-1.1.1.jar"/>
<classpathentry kind="lib" path="C:/Users/acbart/Projects/WebInACan/Weatherer/libs/jdom-2.0.4.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions WeatherAPI/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JWeather</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions WeatherAPI/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Binary file added WeatherAPI/bin/Coordinate.class
Binary file not shown.
Binary file added WeatherAPI/bin/Requests.class
Binary file not shown.
Binary file added WeatherAPI/bin/WeatherCondition.class
Binary file not shown.
Binary file added WeatherAPI/bin/WeatherException.class
Binary file not shown.
Binary file added WeatherAPI/bin/WeatherForecast.class
Binary file not shown.
Binary file added WeatherAPI/bin/WeatherService.class
Binary file not shown.
28 changes: 28 additions & 0 deletions WeatherAPI/src/Coordinate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

public class Coordinate {

public Coordinate(double latitude, double longitude) {
this.longitude = longitude;
this.latitude = latitude;
}

public String toString() {
return longitude + ", " + latitude;
}

private double longitude;
private double latitude;
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}

}
75 changes: 75 additions & 0 deletions WeatherAPI/src/Requests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


public class Requests {
static String get(String request, String urlParameters) throws IOException {
// i.e.: request = "http://example.com/index.php?param1=a&param2=b&param3=c";
request = request + "?" + urlParameters;
URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "text/plain");
connection.setRequestProperty("charset", "utf-8");
connection.connect();

StringBuilder response = new StringBuilder();
String line;

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();

connection.disconnect();
return response.toString();
}

/**
* Source: http://stackoverflow.com/questions/4205980/java-sending-http-parameters-via-post-method-easily
* @param request
* @param urlParameters
* @return
* @throws IOException
*/
static String post(String request, String urlParameters ) throws IOException {
URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setUseCaches (false);

DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);
wr.flush();

StringBuilder response = new StringBuilder();
String line;

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = reader.readLine()) != null) {
response.append(line);
}

wr.close();
reader.close();
connection.disconnect();
return response.toString();
}

public static String makeParameter(String key, Object value) {
return key + "=" + value.toString();
}
}
12 changes: 12 additions & 0 deletions WeatherAPI/src/WeatherCondition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

public class WeatherCondition {
private String summary;

public String getSummary() {
return summary;
}

public void setSummary(String summary) {
this.summary = summary;
}
}
16 changes: 16 additions & 0 deletions WeatherAPI/src/WeatherException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import org.jdom2.Element;


public class WeatherException extends Exception {

private String error;

public WeatherException(String error) {
this.error = error;
}

public String toString() {
return "Weather Exception: "+this.error;
}

}
69 changes: 69 additions & 0 deletions WeatherAPI/src/WeatherForecast.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

import org.jdom2.*;
import org.jdom2.input.SAXBuilder;


public class WeatherForecast {
private Coordinate location;
private int maxTemperature;
private int minTemperature;
private int morningPrecipitation;
private int eveningPrecipitation;
private WeatherCondition condition;


public String toString() {
return "Weather["+location+"]";
}


public WeatherForecast(String rawXML) throws WeatherException {
SAXBuilder builder = new SAXBuilder();

InputStream xmlInputStream = new ByteArrayInputStream(rawXML.getBytes());

try {
Document document = (Document) builder.build(xmlInputStream);
Element rootNode = document.getRootElement();
if ("error" == rootNode.getName()) {
throw new WeatherException(rootNode.getChild("pre").getValue());
} else {
rootNode = rootNode.getChild("data");

Element elementLocation = rootNode.getChild("location").getChild("point");
Double latitude = Double.parseDouble(elementLocation.getAttributeValue("latitude"));
Double longitude = Double.parseDouble(elementLocation.getAttributeValue("longitude"));
this.location = new Coordinate(latitude, longitude);

List list = rootNode.getChildren("time-layout");

System.out.println(list);

for (int i = 0; i < list.size(); i++) {

Element node = (Element) list.get(i);
System.out.println(node.getValue());
//
// System.out.println("First Name : " + node.getChildText("firstname"));
// System.out.println("Last Name : " + node.getChildText("lastname"));
// System.out.println("Nick Name : " + node.getChildText("nickname"));
// System.out.println("Salary : " + node.getChildText("salary"));

}
}
} catch (JDOMException jdomex) {
System.out.println(jdomex.getMessage());
} catch (IOException e) {
// Why on earth does reading a string possibly throw an IOException?
// That's complete BS
System.out.println("There was a fundamental error with the API. Please report this problem and the following stack trace.");
e.printStackTrace();
}
}
}
50 changes: 50 additions & 0 deletions WeatherAPI/src/WeatherService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.io.IOException;
import java.util.Date;


public class WeatherService {

private final static String SERVICE_URL = "http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php";

public static void main(String[] args) {
WeatherService jw = new WeatherService();
try {
System.out.println(jw.getWeather(new Coordinate(40, -77)));
} catch (WeatherException e) {
System.out.println(e);
}
}

private boolean local = false;

public WeatherService() {
this.local = false;
}

public WeatherForecast getWeather(Coordinate location) throws WeatherException {
String parameters = Requests.makeParameter("lat", location.getLatitude()) + "&" +
Requests.makeParameter("lon", location.getLongitude()) + "&" +
Requests.makeParameter("format", "24+hourly");

String xmlData = "";
try {
xmlData = Requests.get(SERVICE_URL, parameters);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new WeatherForecast(xmlData);
}

/**
*
* @param local
*/
public void setLocal(boolean local) {
this.local = local;
}

public boolean getLocal(boolean local) {
return local;
}
}
2 changes: 2 additions & 0 deletions Weatherer/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
<classpathentry kind="lib" path="libs/saaj.jar"/>
<classpathentry kind="lib" path="libs/wsdl4j-1.5.1.jar"/>
<classpathentry kind="lib" path="libs/json-simple-1.1.1.jar"/>
<classpathentry kind="lib" path="C:/Users/acbart/Projects/WebInACan/Weatherer/libs/activation.jar"/>
<classpathentry kind="lib" path="C:/Users/acbart/Projects/WebInACan/Weatherer/libs/mail.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 3 additions & 0 deletions Weatherer/axis.log
Original file line number Diff line number Diff line change
Expand Up @@ -4019,3 +4019,6 @@ XML received:
0 [main] WARN org.apache.axis.utils.JavaUtils - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
0 [main] WARN org.apache.axis.utils.JavaUtils - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
0 [main] WARN org.apache.axis.utils.JavaUtils - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
0 [main] WARN org.apache.axis.utils.JavaUtils - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
0 [main] WARN org.apache.axis.utils.JavaUtils - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
0 [main] WARN org.apache.axis.utils.JavaUtils - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
Binary file modified Weatherer/bin/weather/CompTypeType.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/DisplayLevelType.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/FeatureTypeType.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/FormatType.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/NdfdXMLBindingStub.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/NdfdXMLLocator.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/ProductType.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/SectorType.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/UnitType.class
Binary file not shown.
Binary file added Weatherer/bin/weather/WeatherConnection.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/WeatherParametersType.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/Weatherer$1.class
Binary file not shown.
Binary file modified Weatherer/bin/weather/Weatherer.class
Binary file not shown.
Binary file added Weatherer/libs/activation.jar
Binary file not shown.
Binary file added Weatherer/libs/jaf-1_1_1.zip
Binary file not shown.
Binary file added Weatherer/libs/javamail1_4_5.zip
Binary file not shown.
Binary file added Weatherer/libs/jdom-2.0.4.jar
Binary file not shown.
Binary file added Weatherer/libs/jdom-2.0.4.zip
Binary file not shown.
54 changes: 54 additions & 0 deletions Weatherer/libs/jdom.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*--

Copyright (C) 2000-2012 Jason Hunter & Brett McLaughlin.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the disclaimer that follows
these conditions in the documentation and/or other materials
provided with the distribution.

3. The name "JDOM" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact <request_AT_jdom_DOT_org>.

4. Products derived from this software may not be called "JDOM", nor
may "JDOM" appear in their name, without prior written permission
from the JDOM Project Management <request_AT_jdom_DOT_org>.

In addition, we request (but do not require) that you include in the
end-user documentation provided with the redistribution and/or in the
software itself an acknowledgement equivalent to the following:
"This product includes software developed by the
JDOM Project (http://www.jdom.org/)."
Alternatively, the acknowledgment may be graphical using the logos
available at http://www.jdom.org/images/logos.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

This software consists of voluntary contributions made by many
individuals on behalf of the JDOM Project and was originally
created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
on the JDOM Project, please see <http://www.jdom.org/>.

*/

Binary file added Weatherer/libs/mail.jar
Binary file not shown.
Loading

0 comments on commit 6ec83f2

Please sign in to comment.