55import android .content .Intent ;
66import android .util .Log ;
77
8+ import org .json .JSONArray ;
9+ import org .json .JSONException ;
10+ import org .json .JSONObject ;
11+
812import java .io .StringWriter ;
913import java .text .ParseException ;
1014import java .text .SimpleDateFormat ;
@@ -77,11 +81,27 @@ public void onMessageReceived(Context context,String source,String input) {
7781 }
7882
7983 public final static String getOperationDescribeSensor () {
80- return "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?><DescribeSensor version=\" 1.0.0\" service=\" SOS\" mobileEnabled=\" true\" xmlns=\" http://www.opengis.net/sos/1.0\" xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\" http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosDescribeSensor.xsd\" outputFormat=\" text/xml;subtype="sensorML/1.0.1"\" ><procedure>urn:ogc:object:feature:Sensor:IFGI:ifgi-sensor-1</procedure></DescribeSensor>" ;
84+ JSONObject obj = new JSONObject ();
85+ try {
86+ obj .put ("request" ,"DescribeSensor" );
87+ obj .put ("service" ,"SOS" );
88+ obj .put ("version" ,"2.0.0" );
89+ } catch (JSONException e ) {
90+ e .printStackTrace ();
91+ }
92+ return obj .toString ();
8193 }
8294
8395 public final static String getOperationGetCapabilities () {
84- return "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?><GetCapabilities xmlns=\" http://www.opengis.net/sos/1.0\" xmlns:ows=\" http://www.opengis.net/ows/1.1\" xmlns:ogc=\" http://www.opengis.net/ogc\" xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\" http://www.opengis.net/sos/1.0http://schemas.opengis.net/sos/1.0.0/sosGetCapabilities.xsd\" service=\" SOS\" updateSequence=\" \" ><ows:AcceptVersions><ows:Version>1.0.0</ows:Version></ows:AcceptVersions><ows:Sections><ows:Section>OperationsMetadata</ows:Section><ows:Section>ServiceIdentification</ows:Section><ows:Section>Filter_Capabilities</ows:Section><ows:Section>Contents</ows:Section></ows:Sections></GetCapabilities>" ;
96+ JSONObject obj = new JSONObject ();
97+ try {
98+ obj .put ("request" ,"GetCapabilities" );
99+ obj .put ("service" ,"SOS" );
100+ } catch (JSONException e ) {
101+ e .printStackTrace ();
102+ }
103+
104+ return obj .toString ();
85105 }
86106
87107 public static long parseTime (String time ) {
@@ -105,7 +125,7 @@ public static String formatTime(long time) {
105125 * @return
106126 */
107127 public static String getOperationGetObservations () {
108- return getOperationGetObservations (Long .MIN_VALUE , Long .MIN_VALUE );
128+ return getOperationGetObservations (Long .MIN_VALUE , Long .MAX_VALUE );
109129 }
110130
111131 /**
@@ -115,31 +135,26 @@ public static String getOperationGetObservations() {
115135 * @return
116136 */
117137 public static String getOperationGetObservations (long start , long end ) {
118- StringWriter writer = new StringWriter ();
119- writer .append ("<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n " +
120- "<GetObservation xmlns=\" http://www.opengis.net/sos/1.0\" xmlns:ows=\" http://www.opengis.net/ows/1.1\" xmlns:gml=\" http://www.opengis.net/gml\" xmlns:ogc=\" http://www.opengis.net/ogc\" xmlns:om=\" http://www.opengis.net/om/1.0\" xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\" http://www.opengis.net/sos/1.0\n " +
121- "http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd\" service=\" SOS\" version=\" 1.0.0\" srsName=\" urn:ogc:def:crs:EPSG:4326\" >\n " +
122- " <offering>TORGI</offering>\n " ); //TODO change this type of offering
123- if (end > Long .MIN_VALUE ) {
124- writer .append (" <eventTime>\n " +
125- " <ogc:TM_During>\n " +
126- " <ogc:PropertyName>urn:ogc:data:time:iso8601</ogc:PropertyName>\n " +
127- " <gml:TimePeriod>\n " +
128- " <gml:beginPosition>" );
129- writer .append (formatTime (start ));
130- writer .append ("</gml:beginPosition>\n " +
131- " <gml:endPosition>" );
132- writer .append (formatTime (end ));
133- writer .append ("</gml:endPosition>\n " +
134- " </gml:TimePeriod>\n " +
135- " </ogc:TM_During>\n " +
136- " </eventTime>\n " );
138+ JSONObject obj = new JSONObject ();
139+ try {
140+ obj .put ("request" ,"GetObservation" );
141+ obj .put ("service" ,"SOS" );
142+ obj .put ("version" ,"2.0.0" );
143+ if ((start != Long .MIN_VALUE ) && (end != Long .MAX_VALUE )) {
144+ JSONObject temporalFilter = new JSONObject ();
145+ JSONObject during = new JSONObject ();
146+ during .put ("ref" ,"om:phenomenonTime" );
147+ JSONArray values = new JSONArray ();
148+ values .put (formatTime (start ));
149+ values .put (formatTime (end ));
150+ during .put ("value" ,values );
151+ temporalFilter .put ("during" ,during );
152+ obj .put ("temporalFilter" ,temporalFilter );
153+ }
154+ } catch (JSONException e ) {
155+ e .printStackTrace ();
137156 }
138- //TODO need to implement " <procedure>urn:ogc:object:feature:Sensor:IFGI:ifgi-sensor-1</procedure>\n" +
139- //TODO need to implement " <observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:waterlevel</observedProperty>\n" +
140- writer .append (" <responseFormat>text/xml;subtype="om/1.0.0"</responseFormat>\n " +
141- "</GetObservation>" );
142157
143- return writer .toString ();
158+ return obj .toString ();
144159 }
145160}
0 commit comments