Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting spaces in adressing #4

Open
sarni opened this issue Feb 21, 2014 · 0 comments
Open

Supporting spaces in adressing #4

sarni opened this issue Feb 21, 2014 · 0 comments

Comments

@sarni
Copy link
Contributor

sarni commented Feb 21, 2014

make a small change to the GML Handler
(https://gsn.svn.sourceforge.net/svnroot/gsn/trunk/src/gsn/http/GMLHandler.java)
In order to prevent future sensor misconfigurations where people can put spaces in the
content of the latitude and longitude elements,

suggested solution by user :

to the code reading these values. You can do for example:

for (KeyValue df : sensorConfig.getAddressing()) {
if
(StringEscapeUtils.escapeXml(df.getKey().toString().toLowerCase()).contentEquals("latitude"))
lat = (new
String(StringEscapeUtils.escapeXml(df.getValue().toString()))).trim();
if
(StringEscapeUtils.escapeXml(df.getKey().toString().toLowerCase()).contentEquals("longitude"))
lon = (new
String(StringEscapeUtils.escapeXml(df.getValue().toString()))).trim();
}

or whatever you think is more appropriate to remove the leading and
trailing spaces from the values of those coordinates.

And because I can also assume that people might put non-numeric
characters inside the coordinates by mistake (for example the letter
"o" instead of "0"), you can do this also:

for (KeyValue df : sensorConfig.getAddressing()) {
if
(StringEscapeUtils.escapeXml(df.getKey().toString().toLowerCase()).contentEquals("latitude"))
lat = (new
String(StringEscapeUtils.escapeXml(df.getValue().toString()))).trim();
if (lat != null && (!(lat.matches("-?\d+(.\d+)?"))))
lat = null;
if
(StringEscapeUtils.escapeXml(df.getKey().toString().toLowerCase()).contentEquals("longitude"))
lon = (new
String(StringEscapeUtils.escapeXml(df.getValue().toString()))).trim();
if (lon != null && (!(lon.matches("-?\d+(.\d+)?"))))
lon = null;
}

Please check the logic, because I didn't compile nor tested the above
code. I have used the pattern "-?\d+(.\d+)?" because latitude and
longitude can also be negative in other parts of the world outside
Europe, hence the optional "-".

@sarni sarni added this to the Unscheduled milestone Feb 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant