Dominique Pellé <dominique.pe...@gmail.com> wrote:
> Marcin Miłkowski <list-addr...@wp.pl> wrote:
>
>> W dniu 2012-05-30 00:07, Dominique Pellé pisze:
>>> Dominique Pellé<dominique.pe...@gmail.com> wrote:
>>>
>>>> Marcin Miłkowski wrote:
>>>>
>>>>> W dniu 2012-05-27 11:35, Jan Schreiber pisze:
>>>>>> > However, when I use LanguageTool in the command line, I
don't see
>>>>>> > anything about the URL information:
>>>>>> For all I know, the URL is displayed in LibreOffice only.
>>>>> I just added it to the commandline interface.
>>>> Thanks a lot, that was quick!
>>>>
>>>>> BTW, we might need to add a new element to our XML format (used by the
>>>>> API), to convey this piece of info.
>>>>>
>>>>> What about<url>?
>>>> Fine with me, that's the most natural choice.
>>>>
>>>> Regards
>>>> -- Dominique
>>> Actually, all the information about errors are currently inside
attributes
>>> of the<error ...> tag. So I think it's better to follow the same
principle.
>>>
>>> So how about this:
>>>
>>> <error fromy="..." fromx="..." toy="..." tox="..." ruleId="..."
>>> subId="1" msg="...." url="..." replacements="..." context="..."
>>> contextoffset="..." errorlength="..."/>
>>>
>>>
>>> (the url="..." is the new part)
>>>
>>
>> Yes, definitely!
>>
>>
>>> The following patch does just that. If you're OK with it,
>>> I can checkin:
>>>
>>> $ svn diff src/java/org/languagetool/tools/StringTools.java
>>> Index: src/java/org/languagetool/tools/StringTools.java
>>> ===================================================================
>>> --- src/java/org/languagetool/tools/StringTools.java (revision 7099)
>>> +++ src/java/org/languagetool/tools/StringTools.java (working copy)
>>> @@ -345,6 +345,11 @@
>>> final String msg =
match.getMessage().replaceAll("</?suggestion>", "'");
>>> xml.append(subId);
>>> xml.append(" msg=\"" + escapeXMLForAPIOutput(msg) + "\"");
>>> + if (match.getRule().getUrl() != null) {
>>> + xml.append(" url=\""
>>> + +
escapeXMLForAPIOutput(match.getRule().getUrl().toString())
>>> + + "\"");
>>> + }
>>> final String START_MARKER = "__languagetool_start_marker";
>>> String context = Tools.getContext(match.getFromPos(),
match.getToPos(),
>>> text, contextSize, START_MARKER, "", false);
>>
>> Sorry, Dominique, I didn't notice your patch, I was committing mine but
>> it is almost the same. I don't think we need escaping for API output as
>> URLs should be XML-safe. If you want, change it.
>
> No reason to be sorry. It looks like I sent my patch
> at the same time as you checked-in indeed. Thanks for taking
> care of it
>
> I think that we need to escape characters in the URL though as I did,
> because URLs may contain at least the ampersand character
> when passing parameters in the URL with the GET HTTP method.
>
> For example, a URL can look like this:
>
> http://www.foobar.org?a=1&b=2
>
> Current code will put this in the XML document...
>
> <error .... url="http://www.foobar.org?a=1&b=2"/>
>
> ... which is not valid XML. It should be:
>
> <error .... url="http://www.foobar.org?a=1&b=2"/>
>
> So I'll add the escapeXMLForAPIOutput(...) call soon if that's OK.
Here is an existing example of actual URL in de/grammar.xml
where output with --api was wrong because we didn't call
escapeXMLForAPIOutput(...) on content of <url>...</url>:
$ echo "Wir haben eine gewisse Zeitlang gesucht." | \
java -jar dist/LanguageTool.jar -l de --api
<?xml version="1.0" encoding="UTF-8"?>
<matches>
<error fromy="0" fromx="23" toy="0" tox="32" ruleId="ZEITLANG_ZEIT_LANG"
subId="1" msg="In der Wendung eine gewisse 'Zeit lang' schreiben Sie 'Zeit
lang' bitte getrennt." replacements="Zeit lang" context="Wir haben eine
gewisse Zeitlang gesucht. " contextoffset="23" errorlength="8" url="
http://www.canoo.net/services/Controller?dispatch=spelling&input=Zeitlang"/>
<!--
Time: 1226ms for 1 sentences (0.8 sentences/sec)
-->
I've just submitted the fix in SVN r7104.
$ svn diff -r7103:7104
Index: src/java/org/languagetool/tools/StringTools.java
===================================================================
--- src/java/org/languagetool/tools/StringTools.java (revision 7103)
+++ src/java/org/languagetool/tools/StringTools.java (revision 7104)
@@ -359,7 +359,9 @@
xml.append(" contextoffset=\"" + contextOffset + "\"");
xml.append(" errorlength=\"" + (match.getToPos() -
match.getFromPos()) + "\"");
if (match.getRule().getUrl() != null) {
- xml.append(" url=\"" + match.getRule().getUrl().toString() +
"\"");
+ xml.append(" url=\""
+ + escapeXMLForAPIOutput(match.getRule().getUrl().toString())
+ + "\"");
}
xml.append("/>\n");
}
Regards
-- Dominique
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-devel mailing list
Languagetool-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/languagetool-devel