This question is answered. Helpful answers available: 0. Correct answers available: 1.


Permlink Replies: 8 - Pages: 1 - Last Post: 23 Nov 22, 21:27 Last Post By: MarkusD Threads: [ Previous | Next ]
MarkusD

Posts: 720
Registered: 13-Apr-2006
Make OSM file.groovy find title/comment with "
Posted: 20 Nov 22, 17:20
 
  Click to reply to this thread Reply
Hi Rob,

I try to identify titles and comments which have a " included, because this will result in a non working points.js file. I tried to solve that by myself, to no avail. Please help.
// Check for " in title
if ao.getTitle().indexOf('"') != -1 {
	if (debug) System.out.println("\" found for [" + name + "] in title");
}
 
// Check for " in comment
if ao.getComment().indexOf('"') != -1 {
	if (debug) System.out.println("\" found for [" + name + "] in comment");
}


Thanks in advance.

Attached my modified file so far.
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Make OSM file.groovy find title/comment with "
Posted: 20 Nov 22, 19:54   in response to: MarkusD in response to: MarkusD
Helpful
  Click to reply to this thread Reply
I can't remember if there was a reason not to use HTML entities, so try the attached.
Using the last released file, lines 130 and 131 now have (a space added after the & to show the code for a quote.
pointsTxt += "\t\t\"t\": \"" + ao.getTitle().replaceAll("\"","& quot;").replaceAll("'","'") + "\",\n";
pointsTxt += "\t\t\"c\": \"" + ao.getComment().replaceAll("\"","& quot;").replaceAll("'","'") + "\",\n";
JeffTucker

Posts: 8,458
Registered: 31-Jan-2006
Re: Make OSM file.groovy find title/comment with "
Posted: 20 Nov 22, 20:40   in response to: MarkusD in response to: MarkusD
Helpful
  Click to reply to this thread Reply
Java, and, by extension, Groovy, can be very fussy about single and double quotes. Single quotes are used to define a character, whereas double quotes are used to define a String.

The test you probably want is:
if(ao.getTitle().contains("\"")) {
     do something;
}
MarkusD

Posts: 720
Registered: 13-Apr-2006
Re: Make OSM file.groovy find title/comment with "
Posted: 21 Nov 22, 20:14   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Hi Jeff,

yes, that code did what I was after. Thanks.
MarkusD

Posts: 720
Registered: 13-Apr-2006
Re: Make OSM file.groovy find title/comment with "
Posted: 21 Nov 22, 20:18   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Hi Rob,

the aim is not to correct comments or titles with quotes. Because it will not "heal" something like this:
 <a href="https://goo.gl/maps/cE8cKUH4WA92" target="_blank" class="mylink" rel="noreferrer noopener nofollow">Karte</a>


So what I try is to identify the objects with quotes and correct them in the first place. Anyway, Rob, thanks for your support.

Attached the actual file.
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Make OSM file.groovy find title/comment with "
Posted: 22 Nov 22, 09:10   in response to: MarkusD in response to: MarkusD
 
  Click to reply to this thread Reply
The title and comment text could have all html tags removed, instead of manually editing the file. It would remove bold, italic, paragraph too.
MarkusD

Posts: 720
Registered: 13-Apr-2006
Re: Make OSM file.groovy find title/comment with "
Posted: 22 Nov 22, 19:34   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
The title and comment text could have all html tags removed, instead of manually editing the file. It would remove bold, italic, paragraph too.
Rob, that sounds very nice, but I would like to keep all html tags as they are. And this is no problem at all. This is one of the more complex comments I have:
points = [{
		"l": [62.068633,9.125700],
		"dt": "09.12.2011 01:00",
		"t": "Bergen – Trondheim",
		"c": "Überblick über die Tour des Tages<br>Freitag: … <a href='http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Floro/' style='color:#00CCFF;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Florø</a>, <a href='http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Maloy/' style='color:#00CCFF;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Måløy</a>, <a href='http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Torvik/' style='color:#00CCFF;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Torvik</a>, <a href='http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Alesund/' style='color:#00CCFF;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Ålesund</a>,  Ålesund - Åndalsnes, <a href='http://www.nsb.no/stasjoner_uaa/aandalsnes-stasjon-article24943-2676.html' style='color:#FFFF99;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Åndalsnes</a> - <a href='http://www.nsb.no/stations_df/dombaas-station-article25230-2768.html' style='color:#FFFF99;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Dombås</a>, <a href='http://www.nsb.no/stations_df/dombaas-station-article25230-2768.html' style='color:#FFFF99;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Dombås</a> - <a href='http://www.nsb.no/stasjoner_st/trondheim-stasjon-article25018-2675.html' style='color:#FFFF99;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Trondheim</a>, …",
		"f": "Google%20Maps%20-%20Opera.jpg",
		"ca": "0"
	}


Works perfectly well. :-)

So with my addition to "OSM file.groovy" I'm able to find out which comments still have quotes. I change the quotes to ' in my comment, create the point-js files again, and I'm done.
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Make OSM file.groovy find title/comment with "
Posted: 22 Nov 22, 20:51   in response to: MarkusD in response to: MarkusD
 
  Click to reply to this thread Reply
MarkusD wrote:
So with my addition to "OSM file.groovy" I'm able to find out which comments still have quotes. I change the quotes to ' in my comment, create the point-js files again, and I'm done.
The attached will convert titles and comments with double quotes to single quotes.
If your comment is
Überblick über die Tour des Tages<br>Freitag: … <a href="http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Floro/" style="color:#00CCFF;text-align:left" target="_blank" class="mylink" rel="noreferrer noopener nofollow">Florø</a>, <a href="http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Maloy/" style="color:#00CCFF;text-align:left" target="_blank" class="mylink" rel="noreferrer noopener nofollow">Måløy</a>, <a href="http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Torvik/" style="color:#00CCFF;text-align:left" target="_blank" class="mylink" rel="noreferrer noopener nofollow">Torvik</a>, <a href="http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Alesund/" style="color:#00CCFF;text-align:left" target="_blank" class="mylink" rel="noreferrer noopener nofollow">Ålesund</a>,  Ålesund - Åndalsnes, <a href="http://www.nsb.no/stasjoner_uaa/aandalsnes-stasjon-article24943-2676.html" style="color:#FFFF99;text-align:left" target="_blank" class="mylink" rel="noreferrer noopener nofollow">Åndalsnes</a> - <a href="http://www.nsb.no/stations_df/dombaas-station-article25230-2768.html" style="color:#FFFF99;text-align:left" target="_blank" class="mylink" rel="noreferrer noopener nofollow">Dombås</a>, <a href="http://www.nsb.no/stations_df/dombaas-station-article25230-2768.html" style="color:#FFFF99;text-align:left" target="_blank" class="mylink" rel="noreferrer noopener nofollow">Dombås</a> - <a href="http://www.nsb.no/stasjoner_st/trondheim-stasjon-article25018-2675.html" style="color:#FFFF99;text-align:left" target="_blank" class="mylink" rel="noreferrer noopener nofollow">Trondheim</a>, …

The points.js will become
"c": "Überblick über die Tour des Tages<br>Freitag: … <a href='http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Floro/' style='color:#00CCFF;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Florø</a>, <a href='http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Maloy/' style='color:#00CCFF;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Måløy</a>, <a href='http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Torvik/' style='color:#00CCFF;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Torvik</a>, <a href='http://www.hurtigruten.de/norwegen/Postschiffreisen/Reiseprogramme-2012/Hafen/Alesund/' style='color:#00CCFF;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Ålesund</a>,  Ålesund - Åndalsnes, <a href='http://www.nsb.no/stasjoner_uaa/aandalsnes-stasjon-article24943-2676.html' style='color:#FFFF99;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Åndalsnes</a> - <a href='http://www.nsb.no/stations_df/dombaas-station-article25230-2768.html' style='color:#FFFF99;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Dombås</a>, <a href='http://www.nsb.no/stations_df/dombaas-station-article25230-2768.html' style='color:#FFFF99;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Dombås</a> - <a href='http://www.nsb.no/stasjoner_st/trondheim-stasjon-article25018-2675.html' style='color:#FFFF99;text-align:left' target='_blank' class='mylink' rel='noreferrer noopener nofollow'>Trondheim</a>, …",

No need to manually change anything, apart from malformed HTML ;)

If I have (again) misunderstood just ignore the attached.
MarkusD

Posts: 720
Registered: 13-Apr-2006
Re: Make OSM file.groovy find title/comment with "
Posted: 23 Nov 22, 21:19   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Thanks Rob for the enhancements. I saved your code in my file, as a comment. I'm not sure if it makes sense for me to use it. I'm still in the process to check if all of my produced points.js files work.

Right now I try to add another feature to it. It does work quite well but I might come back with another question. :-)

Thanks again.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums