sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Sling > Adding New Scripting Variables
Date Thu, 28 Jan 2010 18:33:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=SLING&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">Adding
New Scripting Variables</a></h2>
     <h4>Page <b>edited</b> by             <a href="">Justin
     <div class="notificationGreySide">
         <p>As of r902947, Sling Scripting allows bundles to contribute objects to the
variables available to scripts.</p>

<p>This is done by implementing the interface <tt></tt>
and exposing the implementation as an OSGi Service. Implementations are able to add one or
more name/value pairs to the <tt>javax.script.Bindings</tt> object, but they <b>cannot</b>
overwrite or remove any of the default scripting variables (defined here: <a href="/confluence/display/SLING/Scripting+variables"
title="Scripting variables">Scripting variables</a>). These custom bindings can be
configured to apply to <b>any</b> scripting language or a specific scripting language.</p>

<p>An example of the binding of a custom object can be found in the extensions.groovy
bundle (<a href=""
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">import</span> javax.script.Bindings;

<span class="code-keyword">import</span>;
<span class="code-keyword">import</span>;

 * BindingsValuesProvider which binds an instance of JSONGroovyBuilder.
 * @scr.component immediate=<span class="code-quote">"<span class="code-keyword">true</span>"</span>
metatype=<span class="code-quote">"no"</span>
 * @scr.service
 * name=<span class="code-quote">"service.description"</span> value=<span
class="code-quote">"JSONGroovyBuilder BindingsValuesProvider"</span>
 * name=<span class="code-quote">"service.vendor"</span> value=<span
class="code-quote">"The Apache Software Foundation"</span>
 * name=<span class="code-quote">""</span> value=<span
<span class="code-keyword">public</span> class JSONGroovyBuilderBindingsValuesProvider
<span class="code-keyword">implements</span> BindingsValuesProvider {

     * {@inheritDoc}
    <span class="code-keyword">public</span> void addBindings(Bindings bindings)
        bindings.put(<span class="code-quote">"jsonBuilder"</span>, <span class="code-keyword">new</span>


<p>In this example, the <tt>jsonBuilder</tt> key is bound to an instance
of <tt>JSONGroovyBuilder</tt> only for Groovy scripts.</p>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>

       <a href="">View
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message