Skip to content

Commit a4e4657

Browse files
committed
Initial commit
1 parent e1a24ed commit a4e4657

34 files changed

Lines changed: 2625 additions & 0 deletions

SweLib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

SweLib/build.gradle

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'com.github.dcendents.android-maven'
3+
4+
group='org.sofwerx.ogc.sos'
5+
6+
android {
7+
compileSdkVersion 28
8+
buildToolsVersion '28.0.3'
9+
defaultConfig {
10+
minSdkVersion 24
11+
targetSdkVersion 28
12+
versionCode 1
13+
versionName '0.1'
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
compileOptions {
22+
targetCompatibility 1.8
23+
sourceCompatibility 1.8
24+
}
25+
}
26+
27+
dependencies {
28+
//implementation 'androidx.annotation:annotation:1.0.2'
29+
}
30+
31+
task sourcesJar(type: Jar) {
32+
from android.sourceSets.main.java.srcDirs
33+
classifier = 'sources'
34+
}
35+
36+
task javadoc(type: Javadoc) {
37+
options.charSet = 'UTF-8'
38+
failOnError false
39+
source = android.sourceSets.main.java.sourceFiles
40+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
41+
}
42+
43+
task javadocJar(type: Jar, dependsOn: javadoc) {
44+
classifier = 'javadoc'
45+
from javadoc.destinationDir
46+
}
47+
48+
artifacts {
49+
archives sourcesJar
50+
archives javadocJar
51+
}

SweLib/ic_launcher-web.png

44.4 KB
Loading

SweLib/pom.xml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<version>1.4.2-SNAPSHOT</version>
5+
<groupId>org.sofwerx.ogc.sos</groupId>
6+
<artifactId>SweLib</artifactId>
7+
<name>SweLib</name>
8+
<description>A helper to allow simple sensors to register and communicate via OGC SOS-T standard and also facilitate IPC comms with other SOS-T aware apps under development for SOFWERX</description>
9+
<url>https://github.com/sofwerx/swe-android</url>
10+
<packaging>apklib</packaging>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
</properties>
15+
16+
<build>
17+
<sourceDirectory>src</sourceDirectory>
18+
<plugins>
19+
<plugin>
20+
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
21+
<artifactId>android-maven-plugin</artifactId>
22+
<version>3.9.0-rc.2</version>
23+
<extensions>true</extensions>
24+
<configuration>
25+
<!--<sdk>-->
26+
<!--<path>${env.ANDROID_HOME}</path>-->
27+
<!--<platform>16</platform>-->
28+
<!--</sdk>-->
29+
<undeployBeforeDeploy>true</undeployBeforeDeploy>
30+
</configuration>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
35+
<dependencies>
36+
<dependency>
37+
<groupId>com.google.android</groupId>
38+
<artifactId>android</artifactId>
39+
<scope>provided</scope>
40+
<version>4.1.1.4</version>
41+
</dependency>
42+
</dependencies>
43+
44+
45+
<issueManagement>
46+
<url>https://github.com/sofwerx/swe-android/issues</url>
47+
<system>GitHub Issues</system>
48+
</issueManagement>
49+
50+
<licenses>
51+
<license>
52+
<name>Apache License Version 2.0</name>
53+
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
54+
<distribution>repo</distribution>
55+
</license>
56+
</licenses>
57+
58+
<scm>
59+
<url>https://github.com/sofwerx/swe-android</url>
60+
<connection>scm:git:git://github.com/sofwerx/swe-android.git</connection>
61+
<developerConnection>scm:git:git@github.com:sofwerx/swe-android.git</developerConnection>
62+
</scm>
63+
64+
<developers>
65+
<developer>
66+
<name>Scott Landis</name>
67+
<email>scottalandis118@gmail.com</email>
68+
<url>https://github.com/scottlandis</url>
69+
<id>scottlandis</id>
70+
</developer>
71+
</developers>
72+
</project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="org.sofwerx.ogc.sos"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
</manifest>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.sofwerx.ogc.sos;
2+
3+
import org.json.JSONException;
4+
import org.json.JSONObject;
5+
6+
import java.util.ArrayList;
7+
import java.util.Iterator;
8+
9+
public abstract class AbstractSensorResult {
10+
protected String label;
11+
protected AbstractSensorResult(String label) { this.label = label; }
12+
public String getLabel() { return label; }
13+
public abstract void addPropertyToObject(JSONObject obj) throws JSONException;
14+
public static ArrayList<AbstractSensorResult> getProperties(JSONObject obj) throws JSONException {
15+
if (obj == null)
16+
return null;
17+
18+
ArrayList<AbstractSensorResult> results = null;
19+
Iterator<String> keys = obj.keys();
20+
String key;
21+
while(keys.hasNext()) {
22+
key = keys.next();
23+
AbstractSensorResult result = null;
24+
Object value = obj.get(key);
25+
if (value instanceof Double)
26+
result = new SensorResultDouble(key,obj.getDouble(key));
27+
else if (value instanceof String)
28+
result = new SensorResultString(key,obj.getString(key));
29+
//TODO add other property data types if needed
30+
if (result != null) {
31+
if (results == null)
32+
results = new ArrayList<>();
33+
results.add(result);
34+
}
35+
}
36+
return results;
37+
}
38+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package org.sofwerx.ogc.sos;
2+
3+
import android.util.Log;
4+
5+
import org.w3c.dom.Document;
6+
import org.w3c.dom.Element;
7+
import org.xml.sax.InputSource;
8+
import org.xml.sax.SAXException;
9+
10+
import java.io.IOException;
11+
import java.io.StringReader;
12+
13+
import javax.xml.parsers.DocumentBuilder;
14+
import javax.xml.parsers.DocumentBuilderFactory;
15+
import javax.xml.parsers.ParserConfigurationException;
16+
17+
public abstract class AbstractSosOperation {
18+
private static SosSensor defaultSensor;
19+
20+
public static AbstractSosOperation newFromXmlString(String text) {
21+
if (text != null) {
22+
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
23+
try {
24+
DocumentBuilder builder = null;
25+
builder = factory.newDocumentBuilder();
26+
Document doc = builder.parse(new InputSource(new StringReader(text)));
27+
return newFromXML(doc);
28+
} catch (ParserConfigurationException | IOException | SAXException e) {
29+
e.printStackTrace();
30+
}
31+
}
32+
return null;
33+
}
34+
35+
public static AbstractSosOperation newFromXML(Document doc) {
36+
AbstractSosOperation operation = null;
37+
if (doc != null) {
38+
Element element = doc.getDocumentElement();
39+
if (element != null) {
40+
String tagName = element.getTagName();
41+
if (tagName != null) {
42+
if (tagName.contains(OperationInsertSensorResponse.NAMESPACE))
43+
operation = new OperationInsertSensorResponse();
44+
else if (tagName.contains(OperationInsertSensor.NAMESPACE))
45+
operation = new OperationInsertSensor();
46+
else if (tagName.contains(OperationInsertResultTemplateResponse.NAMESPACE))
47+
operation = new OperationInsertResultTemplateResponse();
48+
else if (tagName.contains(OperationInsertResultTemplate.NAMESPACE))
49+
operation = new OperationInsertResultTemplate();
50+
else if (tagName.contains(OperationInsertResultResponse.NAMESPACE))
51+
operation = new OperationInsertResultResponse();
52+
else if (tagName.contains(OperationInsertResult.NAMESPACE))
53+
operation = new OperationInsertResult(defaultSensor);
54+
if (operation != null)
55+
operation.parse(element);
56+
}
57+
}
58+
}
59+
return operation;
60+
}
61+
62+
/**
63+
* Used so that templates requiring some context can have that context available
64+
* @return
65+
*/
66+
public static SosSensor getDefaultSensor() {
67+
return defaultSensor;
68+
}
69+
70+
/**
71+
* Used so that templates requiring some context can have that context available
72+
* @param defaultSensor
73+
*/
74+
public static void setDefaultSensor(SosSensor defaultSensor) {
75+
AbstractSosOperation.defaultSensor = defaultSensor;
76+
Log.d(SosIpcTransceiver.TAG,"Default sensor is now: "+((defaultSensor==null)?"null":defaultSensor.getUniqueId()));
77+
}
78+
79+
/**
80+
* Does this operation contain all the information it needs
81+
* @return
82+
*/
83+
public abstract boolean isValid();
84+
85+
protected abstract void parse(Element element);
86+
public Document toXML() throws ParserConfigurationException {
87+
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
88+
DocumentBuilder parser = factory.newDocumentBuilder();
89+
return parser.newDocument();
90+
}
91+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package org.sofwerx.ogc.sos;
2+
3+
import android.util.Log;
4+
5+
import java.io.BufferedReader;
6+
import java.io.BufferedWriter;
7+
import java.io.IOException;
8+
import java.io.InputStreamReader;
9+
import java.io.OutputStream;
10+
import java.io.OutputStreamWriter;
11+
import java.io.StringWriter;
12+
import java.net.HttpURLConnection;
13+
import java.net.URL;
14+
15+
import javax.net.ssl.HttpsURLConnection;
16+
17+
public class HttpHelper {
18+
public static String post(String serverURL, String body) throws IOException {
19+
if (serverURL == null)
20+
throw new IOException("Cannot connect to a null server URL");
21+
if (body == null)
22+
throw new IOException("Cannot send an empty body");
23+
24+
StringWriter payload = new StringWriter();
25+
//payload.append(SOAP_HEADER);
26+
payload.append(body);
27+
//payload.append(SOAP_FOOTER);
28+
29+
URL url;
30+
String response = "";
31+
url = new URL(serverURL);
32+
33+
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
34+
conn.setReadTimeout(15000);
35+
conn.setConnectTimeout(15000);
36+
conn.setRequestMethod("POST");
37+
conn.setRequestProperty("Content-Type","application/soap+xml");
38+
conn.setDoInput(true);
39+
//conn.setDoOutput(true);
40+
conn.setInstanceFollowRedirects(false);
41+
42+
OutputStream os = conn.getOutputStream();
43+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
44+
writer.write(payload.toString());
45+
46+
writer.flush();
47+
writer.close();
48+
os.close();
49+
int responseCode=conn.getResponseCode();
50+
51+
if (responseCode == HttpsURLConnection.HTTP_OK) {
52+
String line;
53+
BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
54+
while ((line=br.readLine()) != null) {
55+
response+=line;
56+
}
57+
} else {
58+
Log.e(SosIpcTransceiver.TAG,"Http connection attempt failed: "+responseCode);
59+
response = null;
60+
}
61+
62+
conn.disconnect();
63+
Log.d(SosIpcTransceiver.TAG,"HttpURLConnection disconnected");
64+
65+
if ((response != null) && (response.length() < 1))
66+
response = null;
67+
return response;
68+
}
69+
70+
//Not pretty, but efficient
71+
private final static String SOAP_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd\"> <env:Body>";
72+
private final static String SOAP_FOOTER = "</env:Body></env:Envelope>";
73+
}

0 commit comments

Comments
 (0)