You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Levine, David" <LE...@consumer.org> on 2010/11/29 18:28:03 UTC
BindingValuesProvider
Hi. I'm a new Sling user. I wanted to use Velocity with Sling, and so I built the module in sling/contrib/scripting/velocity. I added three OSGi bundles:
* org.apache.sling.api-2.1.1-SNAPSHOT.jar
* org.apache.sling.scripting.api-2.1.1-SNAPSHOT.jar
* org.apache.sling.scripting.velocity-2.0.0-SNAPSHOT.jar
No problem! It worked great and I can use the Velocity templating language for my scripts/templates.
However, I'd like to now take this a step further and add a few additional scripting variables, as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
So I want to create a class which implements the BindingsValuesProvider interface. OK... but what do I do with it once I create it? How do I configure Sling to use the class when evaluating a Velocity script? Does the class need to actually be included with the Velocity OSGi bundle? Or can it be separate (say for example I want the new variables to be available to both Velocity and JSP scripts)?
Thanks for any pointers,
--David
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
RE: BindingValuesProvider
Posted by "Levine, David" <LE...@consumer.org>.
Thanks, Carsten, this turns out to be exactly what's happening - scripts included in another script cause this issue (possibly just in CQ, I haven't tried it in straight JR/Sling). So in my BindingsValuesProvider, I'll have it check if keys exist already before adding them.
--David
-----Original Message-----
From: Carsten Ziegeler [mailto:cziegeler@apache.org]
Sent: Tuesday, November 30, 2010 2:18 AM
To: users@sling.apache.org
Subject: Re: BindingValuesProvider
Levine, David wrote
> Hah. Actually, it seems like any possible value is protected in CQ. I tried updating my BindingsValuesProvider quickly before leaving for the day with a new key:
>
> "org.apache.sling.api.scripting.ScriptEvaluationException: java.lang.IllegalArgumentException: Key testCUData is protected."
>
You should check if the value is already set in the bindings before
setting this. Otherwise you get the error above if a script is included
from another script (which is the case in CQ).
Carsten
--
Carsten Ziegeler
cziegeler@apache.org
***
Scanned
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
Re: BindingValuesProvider
Posted by Carsten Ziegeler <cz...@apache.org>.
Levine, David wrote
> Hah. Actually, it seems like any possible value is protected in CQ. I tried updating my BindingsValuesProvider quickly before leaving for the day with a new key:
>
> "org.apache.sling.api.scripting.ScriptEvaluationException: java.lang.IllegalArgumentException: Key testCUData is protected."
>
You should check if the value is already set in the bindings before
setting this. Otherwise you get the error above if a script is included
from another script (which is the case in CQ).
Carsten
--
Carsten Ziegeler
cziegeler@apache.org
Re: BindingValuesProvider
Posted by Justin Edelson <ju...@justinedelson.com>.
FWIW, I was not able to reproduce this using either Velocity or JSP. I
would suggest either moving this to the CQ forum or DayCare.
Justin
On Mon, Nov 29, 2010 at 5:16 PM, Levine, David <LE...@consumer.org> wrote:
> Hah. Actually, it seems like any possible value is protected in CQ. I tried updating my BindingsValuesProvider quickly before leaving for the day with a new key:
>
> "org.apache.sling.api.scripting.ScriptEvaluationException: java.lang.IllegalArgumentException: Key testCUData is protected."
>
> --David
>
>
> -----Original Message-----
> From: Levine, David [mailto:LEVIDA@consumer.org]
> Sent: Monday, November 29, 2010 5:13 PM
> To: users@sling.apache.org
> Subject: RE: BindingValuesProvider
>
> I think this is what I was looking for. Perfect! I updated CQ using the Felix console (I had 2.0.9 for scripting.core), but got some odd NoSuchMethodErrors when evaluating scripts until I actually restarted CQ. I was under the impression that OSGi was supposed to prevent this kind of thing, but at least it worked once I restarted.
>
> Oddly, instead I now get an IllegalArgumentException "Key testData is protected", which comes from org.apache.sling.scripting.core.impl.helper.ProtectedBindings (the put(key,value) method).
>
> Does this mean that "testData" is reserved key in CQ, but not in a standalone Jackrabbit/Sling install? I'm not sure where the Set of protectedKeys is specified in CQ. Anyway, if this is the case then it is simply my bad luck to choose that key during testing, and I'll try again in the morning with an updated key.
>
> Thanks again!
> --David
>
>
> -----Original Message-----
> From: Justin Edelson [mailto:justinedelson@gmail.com]
> Sent: Monday, November 29, 2010 3:56 PM
> To: users@sling.apache.org
> Subject: Re: BindingValuesProvider
>
> Check the versions of the scripting.api and scripting.core bundles. You
> need versions 2.1.0 and 2.0.14, respectively.
>
> Justin
>
> On 11/29/10 3:42 PM, Levine, David wrote:
>> I've been doing initial development on Day CQ. In order to provide a test project for the mailing list, I decided to implement this just using Jackrabbit and Sling alone. When I did that, it worked with no problem (testing using both Velocity and ESP scripting, although I didn't check JSPs)! So my assumption is that this is something I will need to talk with Day/Adobe about... there may be a CQ-specific problem or simply something I need to do differently.
>>
>> When using CQ, I had developed my OSGi bundle with the BindingsValuesProvider service within CRXDE. For the "standalone" test I just created it using Maven with the SCR and bundle plugins. As one last test I decided to install the JAR bundle which worked within Jackrabbit into CQ. It appears to have installed correctly, but I'm still not getting access to the newly bound "testData" object. I'll talk to Day.
>>
>> Thanks for the offer of help, though!
>>
>> --David
>>
>>
>>
>> -----Original Message-----
>> From: Justin Edelson [mailto:justinedelson@gmail.com]
>> Sent: Monday, November 29, 2010 2:15 PM
>> To: users@sling.apache.org
>> Subject: Re: BindingValuesProvider
>>
>> Hi,
>>
>> Can you package up a test project demonstrating this?
>>
>> Justin
>>
>> On 11/29/10 1:53 PM, Levine, David wrote:
>>> Thanks, Bertrand.
>>>
>>> It is odd: my BindingsValuesProvider implementing class is in a separate OSGi bundle from the Velocity bundle, and it is defined as a service. I can see it in the Felix console - it has a Service ID assigned to it and a Component ID. So I would think this is a good thing. But I'm not seeing the binding in the scripts.
>>>
>>> My class is fairly simple:
>>>
>>> /*
>>> * @scr.component immediate="true" metatype="no"
>>> * @scr.service
>>> *
>>> * @scr.property name="service.description" value="Test Bindings"
>>> * @scr.property name="service.vendor" value="CU"
>>> *
>>> * @scr.property name="javax.script.name" value="any"
>>> */
>>> public class CUBindingsValuesProvider implements BindingsValuesProvider {
>>> public void addBindings(Bindings bindings) {
>>> bindings.put("testData","Hello world");
>>> }
>>> }
>>>
>>> In my Velocity template I attempt to access it via ${testData} and in JSP I attempt to access it via <c:out value="${bindings.testData}"/> but nothing shows up in either case.
>>>
>>> I have the "javax.script.name" property set to "any", similar to the CurrentNodeBindingsValuesProvider example on the wiki. I tried removing the property entirely (in case "any" is the incorrect way of specifying this... although this is what is done on the wiki page) but it did not help.
>>>
>>> --David
>>>
>>>
>>> -----Original Message-----
>>> From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
>>> Sent: Monday, November 29, 2010 1:02 PM
>>> To: users@sling.apache.org
>>> Subject: Re: BindingValuesProvider
>>>
>>> Hi David,
>>>
>>> On Mon, Nov 29, 2010 at 6:28 PM, Levine, David <LE...@consumer.org> wrote:
>>>> ...I'd like to now take this a step further and add a few additional scripting variables
>>>> as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
>>>>
>>>> So I want to create a class which implements the BindingsValuesProvider interface. OK...
>>>> but what do I do with it once I create it?...
>>>
>>> There are a few examples in [1] that are used in integration tests [2].
>>>
>>> No configuration is needed - all active OSGi services which implement
>>> BindingsValuesProvider are used by script engines, and the
>>> javax.script.name service property can be used to restrict them to a
>>> specific script engine. I guess the value of that would be "velocity"
>>> in your case, haven't checked.
>>>
>>> -Bertrand
>>>
>>> [1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting
>>>
>>> [2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
>>>
>>> ***
>>> Scanned
>>>
>>> **
>>> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
>>
>>
>> ***
>> Scanned
>>
>> **
>> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
>
>
> ***
> Scanned
>
> **
> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
>
> ***
> Scanned
>
> **
> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
>
RE: BindingValuesProvider
Posted by "Levine, David" <LE...@consumer.org>.
Hah. Actually, it seems like any possible value is protected in CQ. I tried updating my BindingsValuesProvider quickly before leaving for the day with a new key:
"org.apache.sling.api.scripting.ScriptEvaluationException: java.lang.IllegalArgumentException: Key testCUData is protected."
--David
-----Original Message-----
From: Levine, David [mailto:LEVIDA@consumer.org]
Sent: Monday, November 29, 2010 5:13 PM
To: users@sling.apache.org
Subject: RE: BindingValuesProvider
I think this is what I was looking for. Perfect! I updated CQ using the Felix console (I had 2.0.9 for scripting.core), but got some odd NoSuchMethodErrors when evaluating scripts until I actually restarted CQ. I was under the impression that OSGi was supposed to prevent this kind of thing, but at least it worked once I restarted.
Oddly, instead I now get an IllegalArgumentException "Key testData is protected", which comes from org.apache.sling.scripting.core.impl.helper.ProtectedBindings (the put(key,value) method).
Does this mean that "testData" is reserved key in CQ, but not in a standalone Jackrabbit/Sling install? I'm not sure where the Set of protectedKeys is specified in CQ. Anyway, if this is the case then it is simply my bad luck to choose that key during testing, and I'll try again in the morning with an updated key.
Thanks again!
--David
-----Original Message-----
From: Justin Edelson [mailto:justinedelson@gmail.com]
Sent: Monday, November 29, 2010 3:56 PM
To: users@sling.apache.org
Subject: Re: BindingValuesProvider
Check the versions of the scripting.api and scripting.core bundles. You
need versions 2.1.0 and 2.0.14, respectively.
Justin
On 11/29/10 3:42 PM, Levine, David wrote:
> I've been doing initial development on Day CQ. In order to provide a test project for the mailing list, I decided to implement this just using Jackrabbit and Sling alone. When I did that, it worked with no problem (testing using both Velocity and ESP scripting, although I didn't check JSPs)! So my assumption is that this is something I will need to talk with Day/Adobe about... there may be a CQ-specific problem or simply something I need to do differently.
>
> When using CQ, I had developed my OSGi bundle with the BindingsValuesProvider service within CRXDE. For the "standalone" test I just created it using Maven with the SCR and bundle plugins. As one last test I decided to install the JAR bundle which worked within Jackrabbit into CQ. It appears to have installed correctly, but I'm still not getting access to the newly bound "testData" object. I'll talk to Day.
>
> Thanks for the offer of help, though!
>
> --David
>
>
>
> -----Original Message-----
> From: Justin Edelson [mailto:justinedelson@gmail.com]
> Sent: Monday, November 29, 2010 2:15 PM
> To: users@sling.apache.org
> Subject: Re: BindingValuesProvider
>
> Hi,
>
> Can you package up a test project demonstrating this?
>
> Justin
>
> On 11/29/10 1:53 PM, Levine, David wrote:
>> Thanks, Bertrand.
>>
>> It is odd: my BindingsValuesProvider implementing class is in a separate OSGi bundle from the Velocity bundle, and it is defined as a service. I can see it in the Felix console - it has a Service ID assigned to it and a Component ID. So I would think this is a good thing. But I'm not seeing the binding in the scripts.
>>
>> My class is fairly simple:
>>
>> /*
>> * @scr.component immediate="true" metatype="no"
>> * @scr.service
>> *
>> * @scr.property name="service.description" value="Test Bindings"
>> * @scr.property name="service.vendor" value="CU"
>> *
>> * @scr.property name="javax.script.name" value="any"
>> */
>> public class CUBindingsValuesProvider implements BindingsValuesProvider {
>> public void addBindings(Bindings bindings) {
>> bindings.put("testData","Hello world");
>> }
>> }
>>
>> In my Velocity template I attempt to access it via ${testData} and in JSP I attempt to access it via <c:out value="${bindings.testData}"/> but nothing shows up in either case.
>>
>> I have the "javax.script.name" property set to "any", similar to the CurrentNodeBindingsValuesProvider example on the wiki. I tried removing the property entirely (in case "any" is the incorrect way of specifying this... although this is what is done on the wiki page) but it did not help.
>>
>> --David
>>
>>
>> -----Original Message-----
>> From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
>> Sent: Monday, November 29, 2010 1:02 PM
>> To: users@sling.apache.org
>> Subject: Re: BindingValuesProvider
>>
>> Hi David,
>>
>> On Mon, Nov 29, 2010 at 6:28 PM, Levine, David <LE...@consumer.org> wrote:
>>> ...I'd like to now take this a step further and add a few additional scripting variables
>>> as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
>>>
>>> So I want to create a class which implements the BindingsValuesProvider interface. OK...
>>> but what do I do with it once I create it?...
>>
>> There are a few examples in [1] that are used in integration tests [2].
>>
>> No configuration is needed - all active OSGi services which implement
>> BindingsValuesProvider are used by script engines, and the
>> javax.script.name service property can be used to restrict them to a
>> specific script engine. I guess the value of that would be "velocity"
>> in your case, haven't checked.
>>
>> -Bertrand
>>
>> [1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting
>>
>> [2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
>>
>> ***
>> Scanned
>>
>> **
>> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
>
>
> ***
> Scanned
>
> **
> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
***
Scanned
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
***
Scanned
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
RE: BindingValuesProvider
Posted by Felix Meschberger <fm...@gmail.com>.
Hi
Am Montag, den 29.11.2010, 17:12 -0500 schrieb Levine, David:
> I think this is what I was looking for. Perfect! I updated CQ using the Felix console (I had 2.0.9 for scripting.core), but got some odd NoSuchMethodErrors when evaluating scripts until I actually restarted CQ. I was under the impression that OSGi was supposed to prevent this kind of thing, but at least it worked once I restarted.
You don't really need to restart. But you have to tell the framework to
do the last step and actually rewire all users of the old version of the
bundle to the new version of the bundle. That's "Refresh Packages" (in
the upper left corner of the bundle table).
Once the packages are refreshed, you should be set.
Regards
Felix
>
> Oddly, instead I now get an IllegalArgumentException "Key testData is protected", which comes from org.apache.sling.scripting.core.impl.helper.ProtectedBindings (the put(key,value) method).
>
> Does this mean that "testData" is reserved key in CQ, but not in a standalone Jackrabbit/Sling install? I'm not sure where the Set of protectedKeys is specified in CQ. Anyway, if this is the case then it is simply my bad luck to choose that key during testing, and I'll try again in the morning with an updated key.
>
> Thanks again!
> --David
>
>
> -----Original Message-----
> From: Justin Edelson [mailto:justinedelson@gmail.com]
> Sent: Monday, November 29, 2010 3:56 PM
> To: users@sling.apache.org
> Subject: Re: BindingValuesProvider
>
> Check the versions of the scripting.api and scripting.core bundles. You
> need versions 2.1.0 and 2.0.14, respectively.
>
> Justin
>
> On 11/29/10 3:42 PM, Levine, David wrote:
> > I've been doing initial development on Day CQ. In order to provide a test project for the mailing list, I decided to implement this just using Jackrabbit and Sling alone. When I did that, it worked with no problem (testing using both Velocity and ESP scripting, although I didn't check JSPs)! So my assumption is that this is something I will need to talk with Day/Adobe about... there may be a CQ-specific problem or simply something I need to do differently.
> >
> > When using CQ, I had developed my OSGi bundle with the BindingsValuesProvider service within CRXDE. For the "standalone" test I just created it using Maven with the SCR and bundle plugins. As one last test I decided to install the JAR bundle which worked within Jackrabbit into CQ. It appears to have installed correctly, but I'm still not getting access to the newly bound "testData" object. I'll talk to Day.
> >
> > Thanks for the offer of help, though!
> >
> > --David
> >
> >
> >
> > -----Original Message-----
> > From: Justin Edelson [mailto:justinedelson@gmail.com]
> > Sent: Monday, November 29, 2010 2:15 PM
> > To: users@sling.apache.org
> > Subject: Re: BindingValuesProvider
> >
> > Hi,
> >
> > Can you package up a test project demonstrating this?
> >
> > Justin
> >
> > On 11/29/10 1:53 PM, Levine, David wrote:
> >> Thanks, Bertrand.
> >>
> >> It is odd: my BindingsValuesProvider implementing class is in a separate OSGi bundle from the Velocity bundle, and it is defined as a service. I can see it in the Felix console - it has a Service ID assigned to it and a Component ID. So I would think this is a good thing. But I'm not seeing the binding in the scripts.
> >>
> >> My class is fairly simple:
> >>
> >> /*
> >> * @scr.component immediate="true" metatype="no"
> >> * @scr.service
> >> *
> >> * @scr.property name="service.description" value="Test Bindings"
> >> * @scr.property name="service.vendor" value="CU"
> >> *
> >> * @scr.property name="javax.script.name" value="any"
> >> */
> >> public class CUBindingsValuesProvider implements BindingsValuesProvider {
> >> public void addBindings(Bindings bindings) {
> >> bindings.put("testData","Hello world");
> >> }
> >> }
> >>
> >> In my Velocity template I attempt to access it via ${testData} and in JSP I attempt to access it via <c:out value="${bindings.testData}"/> but nothing shows up in either case.
> >>
> >> I have the "javax.script.name" property set to "any", similar to the CurrentNodeBindingsValuesProvider example on the wiki. I tried removing the property entirely (in case "any" is the incorrect way of specifying this... although this is what is done on the wiki page) but it did not help.
> >>
> >> --David
> >>
> >>
> >> -----Original Message-----
> >> From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
> >> Sent: Monday, November 29, 2010 1:02 PM
> >> To: users@sling.apache.org
> >> Subject: Re: BindingValuesProvider
> >>
> >> Hi David,
> >>
> >> On Mon, Nov 29, 2010 at 6:28 PM, Levine, David <LE...@consumer.org> wrote:
> >>> ...I'd like to now take this a step further and add a few additional scripting variables
> >>> as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
> >>>
> >>> So I want to create a class which implements the BindingsValuesProvider interface. OK...
> >>> but what do I do with it once I create it?...
> >>
> >> There are a few examples in [1] that are used in integration tests [2].
> >>
> >> No configuration is needed - all active OSGi services which implement
> >> BindingsValuesProvider are used by script engines, and the
> >> javax.script.name service property can be used to restrict them to a
> >> specific script engine. I guess the value of that would be "velocity"
> >> in your case, haven't checked.
> >>
> >> -Bertrand
> >>
> >> [1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting
> >>
> >> [2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
> >>
> >> ***
> >> Scanned
> >>
> >> **
> >> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
> >
> >
> > ***
> > Scanned
> >
> > **
> > This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
>
>
> ***
> Scanned
>
> **
> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
RE: BindingValuesProvider
Posted by "Levine, David" <LE...@consumer.org>.
I think this is what I was looking for. Perfect! I updated CQ using the Felix console (I had 2.0.9 for scripting.core), but got some odd NoSuchMethodErrors when evaluating scripts until I actually restarted CQ. I was under the impression that OSGi was supposed to prevent this kind of thing, but at least it worked once I restarted.
Oddly, instead I now get an IllegalArgumentException "Key testData is protected", which comes from org.apache.sling.scripting.core.impl.helper.ProtectedBindings (the put(key,value) method).
Does this mean that "testData" is reserved key in CQ, but not in a standalone Jackrabbit/Sling install? I'm not sure where the Set of protectedKeys is specified in CQ. Anyway, if this is the case then it is simply my bad luck to choose that key during testing, and I'll try again in the morning with an updated key.
Thanks again!
--David
-----Original Message-----
From: Justin Edelson [mailto:justinedelson@gmail.com]
Sent: Monday, November 29, 2010 3:56 PM
To: users@sling.apache.org
Subject: Re: BindingValuesProvider
Check the versions of the scripting.api and scripting.core bundles. You
need versions 2.1.0 and 2.0.14, respectively.
Justin
On 11/29/10 3:42 PM, Levine, David wrote:
> I've been doing initial development on Day CQ. In order to provide a test project for the mailing list, I decided to implement this just using Jackrabbit and Sling alone. When I did that, it worked with no problem (testing using both Velocity and ESP scripting, although I didn't check JSPs)! So my assumption is that this is something I will need to talk with Day/Adobe about... there may be a CQ-specific problem or simply something I need to do differently.
>
> When using CQ, I had developed my OSGi bundle with the BindingsValuesProvider service within CRXDE. For the "standalone" test I just created it using Maven with the SCR and bundle plugins. As one last test I decided to install the JAR bundle which worked within Jackrabbit into CQ. It appears to have installed correctly, but I'm still not getting access to the newly bound "testData" object. I'll talk to Day.
>
> Thanks for the offer of help, though!
>
> --David
>
>
>
> -----Original Message-----
> From: Justin Edelson [mailto:justinedelson@gmail.com]
> Sent: Monday, November 29, 2010 2:15 PM
> To: users@sling.apache.org
> Subject: Re: BindingValuesProvider
>
> Hi,
>
> Can you package up a test project demonstrating this?
>
> Justin
>
> On 11/29/10 1:53 PM, Levine, David wrote:
>> Thanks, Bertrand.
>>
>> It is odd: my BindingsValuesProvider implementing class is in a separate OSGi bundle from the Velocity bundle, and it is defined as a service. I can see it in the Felix console - it has a Service ID assigned to it and a Component ID. So I would think this is a good thing. But I'm not seeing the binding in the scripts.
>>
>> My class is fairly simple:
>>
>> /*
>> * @scr.component immediate="true" metatype="no"
>> * @scr.service
>> *
>> * @scr.property name="service.description" value="Test Bindings"
>> * @scr.property name="service.vendor" value="CU"
>> *
>> * @scr.property name="javax.script.name" value="any"
>> */
>> public class CUBindingsValuesProvider implements BindingsValuesProvider {
>> public void addBindings(Bindings bindings) {
>> bindings.put("testData","Hello world");
>> }
>> }
>>
>> In my Velocity template I attempt to access it via ${testData} and in JSP I attempt to access it via <c:out value="${bindings.testData}"/> but nothing shows up in either case.
>>
>> I have the "javax.script.name" property set to "any", similar to the CurrentNodeBindingsValuesProvider example on the wiki. I tried removing the property entirely (in case "any" is the incorrect way of specifying this... although this is what is done on the wiki page) but it did not help.
>>
>> --David
>>
>>
>> -----Original Message-----
>> From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
>> Sent: Monday, November 29, 2010 1:02 PM
>> To: users@sling.apache.org
>> Subject: Re: BindingValuesProvider
>>
>> Hi David,
>>
>> On Mon, Nov 29, 2010 at 6:28 PM, Levine, David <LE...@consumer.org> wrote:
>>> ...I'd like to now take this a step further and add a few additional scripting variables
>>> as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
>>>
>>> So I want to create a class which implements the BindingsValuesProvider interface. OK...
>>> but what do I do with it once I create it?...
>>
>> There are a few examples in [1] that are used in integration tests [2].
>>
>> No configuration is needed - all active OSGi services which implement
>> BindingsValuesProvider are used by script engines, and the
>> javax.script.name service property can be used to restrict them to a
>> specific script engine. I guess the value of that would be "velocity"
>> in your case, haven't checked.
>>
>> -Bertrand
>>
>> [1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting
>>
>> [2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
>>
>> ***
>> Scanned
>>
>> **
>> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
>
>
> ***
> Scanned
>
> **
> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
***
Scanned
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
Re: BindingValuesProvider
Posted by Justin Edelson <ju...@gmail.com>.
Check the versions of the scripting.api and scripting.core bundles. You
need versions 2.1.0 and 2.0.14, respectively.
Justin
On 11/29/10 3:42 PM, Levine, David wrote:
> I've been doing initial development on Day CQ. In order to provide a test project for the mailing list, I decided to implement this just using Jackrabbit and Sling alone. When I did that, it worked with no problem (testing using both Velocity and ESP scripting, although I didn't check JSPs)! So my assumption is that this is something I will need to talk with Day/Adobe about... there may be a CQ-specific problem or simply something I need to do differently.
>
> When using CQ, I had developed my OSGi bundle with the BindingsValuesProvider service within CRXDE. For the "standalone" test I just created it using Maven with the SCR and bundle plugins. As one last test I decided to install the JAR bundle which worked within Jackrabbit into CQ. It appears to have installed correctly, but I'm still not getting access to the newly bound "testData" object. I'll talk to Day.
>
> Thanks for the offer of help, though!
>
> --David
>
>
>
> -----Original Message-----
> From: Justin Edelson [mailto:justinedelson@gmail.com]
> Sent: Monday, November 29, 2010 2:15 PM
> To: users@sling.apache.org
> Subject: Re: BindingValuesProvider
>
> Hi,
>
> Can you package up a test project demonstrating this?
>
> Justin
>
> On 11/29/10 1:53 PM, Levine, David wrote:
>> Thanks, Bertrand.
>>
>> It is odd: my BindingsValuesProvider implementing class is in a separate OSGi bundle from the Velocity bundle, and it is defined as a service. I can see it in the Felix console - it has a Service ID assigned to it and a Component ID. So I would think this is a good thing. But I'm not seeing the binding in the scripts.
>>
>> My class is fairly simple:
>>
>> /*
>> * @scr.component immediate="true" metatype="no"
>> * @scr.service
>> *
>> * @scr.property name="service.description" value="Test Bindings"
>> * @scr.property name="service.vendor" value="CU"
>> *
>> * @scr.property name="javax.script.name" value="any"
>> */
>> public class CUBindingsValuesProvider implements BindingsValuesProvider {
>> public void addBindings(Bindings bindings) {
>> bindings.put("testData","Hello world");
>> }
>> }
>>
>> In my Velocity template I attempt to access it via ${testData} and in JSP I attempt to access it via <c:out value="${bindings.testData}"/> but nothing shows up in either case.
>>
>> I have the "javax.script.name" property set to "any", similar to the CurrentNodeBindingsValuesProvider example on the wiki. I tried removing the property entirely (in case "any" is the incorrect way of specifying this... although this is what is done on the wiki page) but it did not help.
>>
>> --David
>>
>>
>> -----Original Message-----
>> From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
>> Sent: Monday, November 29, 2010 1:02 PM
>> To: users@sling.apache.org
>> Subject: Re: BindingValuesProvider
>>
>> Hi David,
>>
>> On Mon, Nov 29, 2010 at 6:28 PM, Levine, David <LE...@consumer.org> wrote:
>>> ...I'd like to now take this a step further and add a few additional scripting variables
>>> as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
>>>
>>> So I want to create a class which implements the BindingsValuesProvider interface. OK...
>>> but what do I do with it once I create it?...
>>
>> There are a few examples in [1] that are used in integration tests [2].
>>
>> No configuration is needed - all active OSGi services which implement
>> BindingsValuesProvider are used by script engines, and the
>> javax.script.name service property can be used to restrict them to a
>> specific script engine. I guess the value of that would be "velocity"
>> in your case, haven't checked.
>>
>> -Bertrand
>>
>> [1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting
>>
>> [2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
>>
>> ***
>> Scanned
>>
>> **
>> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
>
>
> ***
> Scanned
>
> **
> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
RE: BindingValuesProvider
Posted by "Levine, David" <LE...@consumer.org>.
I've been doing initial development on Day CQ. In order to provide a test project for the mailing list, I decided to implement this just using Jackrabbit and Sling alone. When I did that, it worked with no problem (testing using both Velocity and ESP scripting, although I didn't check JSPs)! So my assumption is that this is something I will need to talk with Day/Adobe about... there may be a CQ-specific problem or simply something I need to do differently.
When using CQ, I had developed my OSGi bundle with the BindingsValuesProvider service within CRXDE. For the "standalone" test I just created it using Maven with the SCR and bundle plugins. As one last test I decided to install the JAR bundle which worked within Jackrabbit into CQ. It appears to have installed correctly, but I'm still not getting access to the newly bound "testData" object. I'll talk to Day.
Thanks for the offer of help, though!
--David
-----Original Message-----
From: Justin Edelson [mailto:justinedelson@gmail.com]
Sent: Monday, November 29, 2010 2:15 PM
To: users@sling.apache.org
Subject: Re: BindingValuesProvider
Hi,
Can you package up a test project demonstrating this?
Justin
On 11/29/10 1:53 PM, Levine, David wrote:
> Thanks, Bertrand.
>
> It is odd: my BindingsValuesProvider implementing class is in a separate OSGi bundle from the Velocity bundle, and it is defined as a service. I can see it in the Felix console - it has a Service ID assigned to it and a Component ID. So I would think this is a good thing. But I'm not seeing the binding in the scripts.
>
> My class is fairly simple:
>
> /*
> * @scr.component immediate="true" metatype="no"
> * @scr.service
> *
> * @scr.property name="service.description" value="Test Bindings"
> * @scr.property name="service.vendor" value="CU"
> *
> * @scr.property name="javax.script.name" value="any"
> */
> public class CUBindingsValuesProvider implements BindingsValuesProvider {
> public void addBindings(Bindings bindings) {
> bindings.put("testData","Hello world");
> }
> }
>
> In my Velocity template I attempt to access it via ${testData} and in JSP I attempt to access it via <c:out value="${bindings.testData}"/> but nothing shows up in either case.
>
> I have the "javax.script.name" property set to "any", similar to the CurrentNodeBindingsValuesProvider example on the wiki. I tried removing the property entirely (in case "any" is the incorrect way of specifying this... although this is what is done on the wiki page) but it did not help.
>
> --David
>
>
> -----Original Message-----
> From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
> Sent: Monday, November 29, 2010 1:02 PM
> To: users@sling.apache.org
> Subject: Re: BindingValuesProvider
>
> Hi David,
>
> On Mon, Nov 29, 2010 at 6:28 PM, Levine, David <LE...@consumer.org> wrote:
>> ...I'd like to now take this a step further and add a few additional scripting variables
>> as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
>>
>> So I want to create a class which implements the BindingsValuesProvider interface. OK...
>> but what do I do with it once I create it?...
>
> There are a few examples in [1] that are used in integration tests [2].
>
> No configuration is needed - all active OSGi services which implement
> BindingsValuesProvider are used by script engines, and the
> javax.script.name service property can be used to restrict them to a
> specific script engine. I guess the value of that would be "velocity"
> in your case, haven't checked.
>
> -Bertrand
>
> [1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting
>
> [2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
>
> ***
> Scanned
>
> **
> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
***
Scanned
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
Re: BindingValuesProvider
Posted by Justin Edelson <ju...@gmail.com>.
Hi,
Can you package up a test project demonstrating this?
Justin
On 11/29/10 1:53 PM, Levine, David wrote:
> Thanks, Bertrand.
>
> It is odd: my BindingsValuesProvider implementing class is in a separate OSGi bundle from the Velocity bundle, and it is defined as a service. I can see it in the Felix console - it has a Service ID assigned to it and a Component ID. So I would think this is a good thing. But I'm not seeing the binding in the scripts.
>
> My class is fairly simple:
>
> /*
> * @scr.component immediate="true" metatype="no"
> * @scr.service
> *
> * @scr.property name="service.description" value="Test Bindings"
> * @scr.property name="service.vendor" value="CU"
> *
> * @scr.property name="javax.script.name" value="any"
> */
> public class CUBindingsValuesProvider implements BindingsValuesProvider {
> public void addBindings(Bindings bindings) {
> bindings.put("testData","Hello world");
> }
> }
>
> In my Velocity template I attempt to access it via ${testData} and in JSP I attempt to access it via <c:out value="${bindings.testData}"/> but nothing shows up in either case.
>
> I have the "javax.script.name" property set to "any", similar to the CurrentNodeBindingsValuesProvider example on the wiki. I tried removing the property entirely (in case "any" is the incorrect way of specifying this... although this is what is done on the wiki page) but it did not help.
>
> --David
>
>
> -----Original Message-----
> From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
> Sent: Monday, November 29, 2010 1:02 PM
> To: users@sling.apache.org
> Subject: Re: BindingValuesProvider
>
> Hi David,
>
> On Mon, Nov 29, 2010 at 6:28 PM, Levine, David <LE...@consumer.org> wrote:
>> ...I'd like to now take this a step further and add a few additional scripting variables
>> as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
>>
>> So I want to create a class which implements the BindingsValuesProvider interface. OK...
>> but what do I do with it once I create it?...
>
> There are a few examples in [1] that are used in integration tests [2].
>
> No configuration is needed - all active OSGi services which implement
> BindingsValuesProvider are used by script engines, and the
> javax.script.name service property can be used to restrict them to a
> specific script engine. I guess the value of that would be "velocity"
> in your case, haven't checked.
>
> -Bertrand
>
> [1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting
>
> [2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
>
> ***
> Scanned
>
> **
> This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
RE: BindingValuesProvider
Posted by "Levine, David" <LE...@consumer.org>.
Thanks, Bertrand.
It is odd: my BindingsValuesProvider implementing class is in a separate OSGi bundle from the Velocity bundle, and it is defined as a service. I can see it in the Felix console - it has a Service ID assigned to it and a Component ID. So I would think this is a good thing. But I'm not seeing the binding in the scripts.
My class is fairly simple:
/*
* @scr.component immediate="true" metatype="no"
* @scr.service
*
* @scr.property name="service.description" value="Test Bindings"
* @scr.property name="service.vendor" value="CU"
*
* @scr.property name="javax.script.name" value="any"
*/
public class CUBindingsValuesProvider implements BindingsValuesProvider {
public void addBindings(Bindings bindings) {
bindings.put("testData","Hello world");
}
}
In my Velocity template I attempt to access it via ${testData} and in JSP I attempt to access it via <c:out value="${bindings.testData}"/> but nothing shows up in either case.
I have the "javax.script.name" property set to "any", similar to the CurrentNodeBindingsValuesProvider example on the wiki. I tried removing the property entirely (in case "any" is the incorrect way of specifying this... although this is what is done on the wiki page) but it did not help.
--David
-----Original Message-----
From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
Sent: Monday, November 29, 2010 1:02 PM
To: users@sling.apache.org
Subject: Re: BindingValuesProvider
Hi David,
On Mon, Nov 29, 2010 at 6:28 PM, Levine, David <LE...@consumer.org> wrote:
> ...I'd like to now take this a step further and add a few additional scripting variables
> as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
>
> So I want to create a class which implements the BindingsValuesProvider interface. OK...
> but what do I do with it once I create it?...
There are a few examples in [1] that are used in integration tests [2].
No configuration is needed - all active OSGi services which implement
BindingsValuesProvider are used by script engines, and the
javax.script.name service property can be used to restrict them to a
specific script engine. I guess the value of that would be "velocity"
in your case, haven't checked.
-Bertrand
[1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting
[2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
***
Scanned
**
This e-mail message is intended only for the designated recipient(s) named above. The information contained in this e-mail and any attachments may be confidential or legally privileged. If you are not the intended recipient, you may not review, retain, copy, redistribute or use this e-mail or any attachment for any purpose, or disclose all or any part of its contents. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and permanently delete this e-mail and any attachments from your computer system.
Re: BindingValuesProvider
Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi David,
On Mon, Nov 29, 2010 at 6:28 PM, Levine, David <LE...@consumer.org> wrote:
> ...I'd like to now take this a step further and add a few additional scripting variables
> as discussed here: https://cwiki.apache.org/SLING/adding-new-scripting-variables.html
>
> So I want to create a class which implements the BindingsValuesProvider interface. OK...
> but what do I do with it once I create it?...
There are a few examples in [1] that are used in integration tests [2].
No configuration is needed - all active OSGi services which implement
BindingsValuesProvider are used by script engines, and the
javax.script.name service property can be used to restrict them to a
specific script engine. I guess the value of that would be "velocity"
in your case, haven't checked.
-Bertrand
[1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting
[2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java