Calling Java Functions

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling Java Functions

Michael Joyce-2
Hello list.

I'm calling out to a java function and having some trouble. Here's a working example of the problem.

xquery version "3.0";

declare namespace normalizer = "java:java.text.Normalizer";
declare namespace form = "java:java.text.Normalizer$Form";

let $string := 'Wilde & Taylor'

let $normalized := normalizer:normalize($string, form:value-of('NFC'))

return <result>
  <original>{ $string }</original>
  <normalized>{ $normalized }</normalized>
</result>

Running the query above as is, I get this exception: "err:XPST0003 Ampersands (&) must be escaped (following character was not a name start character)."

That's not terribly helpful, &amp; should be OK. I'm not sure where to turn with this one. I'm sure it isn't something in the normalizer call. It is also broken with other java calls like this one.

xquery version "3.0";

declare namespace normalizer = "java:java.text.Normalizer";
declare namespace form = "java:java.text.Normalizer$Form";
declare namespace string = "java:java.lang.String";

let $string := 'Wilde &amp; Taylor'
let $normalized := string:to-lower-case($string)

return <result>
  <original>{ $string }</original>
  <normalized>{ $normalized }</normalized>
</result>

Any advice or recommendations you can offer are greatly appreciated.

Cheers,

Michael
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java Functions

Martin Holmes
Hi Michael,

I think you may have to double-escape in this context:

let $string := 'Wilde &amp;amp; Taylor'

because a single escape in XQuery will presumably give you a literal
ampersand, which comes back as a literal into your result element.

Hope this helps,
Martin

On 2016-12-12 02:43 PM, Michael Joyce wrote:

> Hello list.
>
> I'm calling out to a java function and having some trouble. Here's a working example of the problem.
>
> xquery version "3.0";
>
> declare namespace normalizer = "java:java.text.Normalizer";
> declare namespace form = "java:java.text.Normalizer$Form";
>
> let $string := 'Wilde &amp; Taylor'
>
> let $normalized := normalizer:normalize($string, form:value-of('NFC'))
>
> return <result>
>   <original>{ $string }</original>
>   <normalized>{ $normalized }</normalized>
> </result>
>
> Running the query above as is, I get this exception: "err:XPST0003 Ampersands (&) must be escaped (following character was not a name start character)."
>
> That's not terribly helpful, &amp; should be OK. I'm not sure where to turn with this one. I'm sure it isn't something in the normalizer call. It is also broken with other java calls like this one.
>
> xquery version "3.0";
>
> declare namespace normalizer = "java:java.text.Normalizer";
> declare namespace form = "java:java.text.Normalizer$Form";
> declare namespace string = "java:java.lang.String";
>
> let $string := 'Wilde &amp; Taylor'
> let $normalized := string:to-lower-case($string)
>
> return <result>
>   <original>{ $string }</original>
>   <normalized>{ $normalized }</normalized>
> </result>
>
> Any advice or recommendations you can offer are greatly appreciated.
>
> Cheers,
>
> Michael
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java Functions

Michael Joyce-2
Thanks Martin, but it doesn't work either, generating the same exception. I guess both entities are getting encoded together &&.

Michael

> On Dec 12, 2016, at 4:16 PM, Martin Holmes <[hidden email]> wrote:
>
> Hi Michael,
>
> I think you may have to double-escape in this context:
>
> let $string := 'Wilde &amp;amp; Taylor'
>
> because a single escape in XQuery will presumably give you a literal
> ampersand, which comes back as a literal into your result element.
>
> Hope this helps,
> Martin
>
> On 2016-12-12 02:43 PM, Michael Joyce wrote:
>> Hello list.
>>
>> I'm calling out to a java function and having some trouble. Here's a working example of the problem.
>>
>> xquery version "3.0";
>>
>> declare namespace normalizer = "java:java.text.Normalizer";
>> declare namespace form = "java:java.text.Normalizer$Form";
>>
>> let $string := 'Wilde &amp; Taylor'
>>
>> let $normalized := normalizer:normalize($string, form:value-of('NFC'))
>>
>> return <result>
>>  <original>{ $string }</original>
>>  <normalized>{ $normalized }</normalized>
>> </result>
>>
>> Running the query above as is, I get this exception: "err:XPST0003 Ampersands (&) must be escaped (following character was not a name start character)."
>>
>> That's not terribly helpful, &amp; should be OK. I'm not sure where to turn with this one. I'm sure it isn't something in the normalizer call. It is also broken with other java calls like this one.
>>
>> xquery version "3.0";
>>
>> declare namespace normalizer = "java:java.text.Normalizer";
>> declare namespace form = "java:java.text.Normalizer$Form";
>> declare namespace string = "java:java.lang.String";
>>
>> let $string := 'Wilde &amp; Taylor'
>> let $normalized := string:to-lower-case($string)
>>
>> return <result>
>>  <original>{ $string }</original>
>>  <normalized>{ $normalized }</normalized>
>> </result>
>>
>> Any advice or recommendations you can offer are greatly appreciated.
>>
>> Cheers,
>>
>> Michael
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Exist-open mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/exist-open


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java Functions

Martin Holmes
No, not two entities; this is the sequence:

&amp;amp;

The first one is complete; the second one is missing its initial literal
ampersand. That should give you an entity going into the Java.

Cheers,
Martin

On 2016-12-12 04:24 PM, Michael Joyce wrote:

> Thanks Martin, but it doesn't work either, generating the same exception. I guess both entities are getting encoded together &&.
>
> Michael
>
>> On Dec 12, 2016, at 4:16 PM, Martin Holmes <[hidden email]> wrote:
>>
>> Hi Michael,
>>
>> I think you may have to double-escape in this context:
>>
>> let $string := 'Wilde &amp;amp; Taylor'
>>
>> because a single escape in XQuery will presumably give you a literal
>> ampersand, which comes back as a literal into your result element.
>>
>> Hope this helps,
>> Martin
>>
>> On 2016-12-12 02:43 PM, Michael Joyce wrote:
>>> Hello list.
>>>
>>> I'm calling out to a java function and having some trouble. Here's a working example of the problem.
>>>
>>> xquery version "3.0";
>>>
>>> declare namespace normalizer = "java:java.text.Normalizer";
>>> declare namespace form = "java:java.text.Normalizer$Form";
>>>
>>> let $string := 'Wilde &amp; Taylor'
>>>
>>> let $normalized := normalizer:normalize($string, form:value-of('NFC'))
>>>
>>> return <result>
>>>  <original>{ $string }</original>
>>>  <normalized>{ $normalized }</normalized>
>>> </result>
>>>
>>> Running the query above as is, I get this exception: "err:XPST0003 Ampersands (&) must be escaped (following character was not a name start character)."
>>>
>>> That's not terribly helpful, &amp; should be OK. I'm not sure where to turn with this one. I'm sure it isn't something in the normalizer call. It is also broken with other java calls like this one.
>>>
>>> xquery version "3.0";
>>>
>>> declare namespace normalizer = "java:java.text.Normalizer";
>>> declare namespace form = "java:java.text.Normalizer$Form";
>>> declare namespace string = "java:java.lang.String";
>>>
>>> let $string := 'Wilde &amp; Taylor'
>>> let $normalized := string:to-lower-case($string)
>>>
>>> return <result>
>>>  <original>{ $string }</original>
>>>  <normalized>{ $normalized }</normalized>
>>> </result>
>>>
>>> Any advice or recommendations you can offer are greatly appreciated.
>>>
>>> Cheers,
>>>
>>> Michael
>>> ------------------------------------------------------------------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Exist-open mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/exist-open
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java Functions

Michael Joyce-2
Well that's just bloody brilliant Martin! I can work with this. Thank you!

I still think it's a bug though, as calling string:to-lower-case() shouldn't change
characters that aren't letters.

xquery version "3.0";

declare namespace string = "java:java.lang.String";

let $string := 'Wilde &amp;amp; Taylor'
let $normalized := string:to-lower-case($string)

return <result>
  <original>{ $string }</original>
  <normalized>{ $normalized }</normalized>
</result>

The result is

<result>
<original>Wilde &amp;amp; Taylor</original>
<normalized>wilde &amp; taylor</normalized>
</result>




> On Dec 12, 2016, at 5:02 PM, Martin Holmes <[hidden email]> wrote:
>
> No, not two entities; this is the sequence:
>
> &amp;amp;
>
> The first one is complete; the second one is missing its initial literal
> ampersand. That should give you an entity going into the Java.
>
> Cheers,
> Martin
>
> On 2016-12-12 04:24 PM, Michael Joyce wrote:
>> Thanks Martin, but it doesn't work either, generating the same exception. I guess both entities are getting encoded together &&.
>>
>> Michael
>>
>>> On Dec 12, 2016, at 4:16 PM, Martin Holmes <[hidden email]> wrote:
>>>
>>> Hi Michael,
>>>
>>> I think you may have to double-escape in this context:
>>>
>>> let $string := 'Wilde &amp;amp; Taylor'
>>>
>>> because a single escape in XQuery will presumably give you a literal
>>> ampersand, which comes back as a literal into your result element.
>>>
>>> Hope this helps,
>>> Martin
>>>
>>> On 2016-12-12 02:43 PM, Michael Joyce wrote:
>>>> Hello list.
>>>>
>>>> I'm calling out to a java function and having some trouble. Here's a working example of the problem.
>>>>
>>>> xquery version "3.0";
>>>>
>>>> declare namespace normalizer = "java:java.text.Normalizer";
>>>> declare namespace form = "java:java.text.Normalizer$Form";
>>>>
>>>> let $string := 'Wilde &amp; Taylor'
>>>>
>>>> let $normalized := normalizer:normalize($string, form:value-of('NFC'))
>>>>
>>>> return <result>
>>>> <original>{ $string }</original>
>>>> <normalized>{ $normalized }</normalized>
>>>> </result>
>>>>
>>>> Running the query above as is, I get this exception: "err:XPST0003 Ampersands (&) must be escaped (following character was not a name start character)."
>>>>
>>>> That's not terribly helpful, &amp; should be OK. I'm not sure where to turn with this one. I'm sure it isn't something in the normalizer call. It is also broken with other java calls like this one.
>>>>
>>>> xquery version "3.0";
>>>>
>>>> declare namespace normalizer = "java:java.text.Normalizer";
>>>> declare namespace form = "java:java.text.Normalizer$Form";
>>>> declare namespace string = "java:java.lang.String";
>>>>
>>>> let $string := 'Wilde &amp; Taylor'
>>>> let $normalized := string:to-lower-case($string)
>>>>
>>>> return <result>
>>>> <original>{ $string }</original>
>>>> <normalized>{ $normalized }</normalized>
>>>> </result>
>>>>
>>>> Any advice or recommendations you can offer are greatly appreciated.
>>>>
>>>> Cheers,
>>>>
>>>> Michael
>>>> ------------------------------------------------------------------------------
>>>> Check out the vibrant tech community on one of the world's most
>>>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>>> _______________________________________________
>>> Exist-open mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/exist-open
>>
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Exist-open mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/exist-open


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java Functions

Hungerburg
Out of curiosity and because the snippet is so readily abused, I tried
that on a eXist 3 RC2; the result looks different though:

<result>
   <original>Wilde &amp; Taylor</original>
   <normalized>wilde & taylor</normalized>
</result>

Notice, that the "original" already is not the "original" and
"normalized" has all Encoding flattened. The error, that comes up when
the original is not double-encoded stays the same though.

Peter

Am 2016-12-13 um 02:10 schrieb Michael Joyce:

> Well that's just bloody brilliant Martin! I can work with this. Thank you!
>
> I still think it's a bug though, as calling string:to-lower-case() shouldn't change
> characters that aren't letters.
>
> xquery version "3.0";
>
> declare namespace string = "java:java.lang.String";
>
> let $string := 'Wilde &amp;amp; Taylor'
> let $normalized := string:to-lower-case($string)
>
> return <result>
>   <original>{ $string }</original>
>   <normalized>{ $normalized }</normalized>
> </result>
>
> The result is
>
> <result>
> <original>Wilde &amp;amp; Taylor</original>
> <normalized>wilde &amp; taylor</normalized>
> </result>
>
>>>> On 2016-12-12 02:43 PM, Michael Joyce wrote:
>>>>> Hello list.
>>>>>
>>>>> I'm calling out to a java function and having some trouble. Here's a working example of the problem.
>>>>>
>>>>> xquery version "3.0";
>>>>>
>>>>> declare namespace normalizer = "java:java.text.Normalizer";
>>>>> declare namespace form = "java:java.text.Normalizer$Form";
>>>>>
>>>>> let $string := 'Wilde &amp; Taylor'
>>>>>
>>>>> let $normalized := normalizer:normalize($string, form:value-of('NFC'))
>>>>>
>>>>> return <result>
>>>>> <original>{ $string }</original>
>>>>> <normalized>{ $normalized }</normalized>
>>>>> </result>
>>>>>
>>>>> Running the query above as is, I get this exception: "err:XPST0003 Ampersands (&) must be escaped (following character was not a name start character)."
>>>>>
>>>>> That's not terribly helpful, &amp; should be OK. I'm not sure where to turn with this one. I'm sure it isn't something in the normalizer call. It is also broken with other java calls like this one.
>>>>>
>>>>> xquery version "3.0";
>>>>>
>>>>> declare namespace normalizer = "java:java.text.Normalizer";
>>>>> declare namespace form = "java:java.text.Normalizer$Form";
>>>>> declare namespace string = "java:java.lang.String";
>>>>>
>>>>> let $string := 'Wilde &amp; Taylor'
>>>>> let $normalized := string:to-lower-case($string)
>>>>>
>>>>> return <result>
>>>>> <original>{ $string }</original>
>>>>> <normalized>{ $normalized }</normalized>
>>>>> </result>
>>>>>
>>>>> Any advice or recommendations you can offer are greatly appreciated.
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Michael




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open