You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Damian Harden <dh...@gmail.com> on 2008/01/31 00:54:06 UTC

Binding extensions / resourceTypes to Servlets / ScriptEngines?

Apologies - subject line for previous post was misleading ;-)

---

All,

Can anyone point me towards a simple tutorial / document / example
code which shows how to bind either an extension (*.xyz) and/or
sling:resourceType (sling:resourceType=xyz) to a Servlet or
ScriptEngine?

For example, how does the VelocityTemplatesScriptEngine class get
mapped to *.vm files (and perhaps specific resourceTypes?)

Thanks in advance,

Damian

Re: Binding extensions / resourceTypes to Servlets / ScriptEngines?

Posted by Damian Harden <dh...@gmail.com>.
Great stuff Felix! :-)  Appreciate the response and will have a crack at it!

Damian

On 31/01/2008, Felix Meschberger <fm...@gmail.com> wrote:
> HI Damian,
>
> Am Donnerstag, den 31.01.2008, 10:54 +1100 schrieb Damian Harden:
> > Apologies - subject line for previous post was misleading ;-)
>
> Ok, ignoring the other one and taking a stab at this one ;-)
>
> > Can anyone point me towards a simple tutorial / document / example
> > code which shows how to bind either an extension (*.xyz) and/or
> > sling:resourceType (sling:resourceType=xyz) to a Servlet or
> > ScriptEngine?
>
> For servlets you might want to see [1]. Basically, you have to register
> your servlets with one or more OSGi service registration properties:
>
> Either    sling.servlet.paths - a list of paths under which to register
> the servlet. These
>                    paths are used similarly as if you would create a
> script. Thus they contain
>                    supported resource types, selectors, extensions and
> methods
>
> Or        sling.servlet.resourceTypes,
>           sling.servlet.selectors,
>           sling.servlet.methods,
>           sling.servlet.extensions - these four properties are combined
> to form paths under
>                     which to register the servlet.
>
> If the sling.servlet.paths property is defined, all other properties are
> ignored (currently). If neither sling.servlet.paths nor
> sling.servlet.resourceTypes is defined, the servlet is ignored and not
> registered.
>
> Servlets are not registered with their own extensions like scripts are
> done. In this context you should not mix the sling.servlet.extensions
> property with script path extensions: The former is used to support
> request URL extensions like in "html" in /a/b/c/html or "txt"
> in /a/b/c/txt.js. The latter is used to indicate the scripting language
> used such as "js" in /a/b/c/txt.js.
>
> >
> > For example, how does the VelocityTemplatesScriptEngine class get
> > mapped to *.vm files (and perhaps specific resourceTypes?)
>
> The extensions of the script file (such as "vm" in /a/b/c/json.vm) is
> used to find the scripting language implementation - or ScriptEngine in
> JSR-223 terms - to evaluate the script. These extensions are defined by
> the JSR-223 ScriptEngineFactory implementations.
>
> Hope this helps.
>
> Regards
> Felix
>
>
> [1] http://incubator.apache.org/sling/site/servlet-resolution.html
>
>

Re: Binding extensions / resourceTypes to Servlets / ScriptEngines?

Posted by Felix Meschberger <fm...@gmail.com>.
HI Damian,

Am Donnerstag, den 31.01.2008, 10:54 +1100 schrieb Damian Harden:
> Apologies - subject line for previous post was misleading ;-)

Ok, ignoring the other one and taking a stab at this one ;-)

> Can anyone point me towards a simple tutorial / document / example
> code which shows how to bind either an extension (*.xyz) and/or
> sling:resourceType (sling:resourceType=xyz) to a Servlet or
> ScriptEngine?

For servlets you might want to see [1]. Basically, you have to register
your servlets with one or more OSGi service registration properties:

Either    sling.servlet.paths - a list of paths under which to register
the servlet. These
                   paths are used similarly as if you would create a
script. Thus they contain
                   supported resource types, selectors, extensions and
methods

Or        sling.servlet.resourceTypes,
          sling.servlet.selectors,
          sling.servlet.methods,
          sling.servlet.extensions - these four properties are combined
to form paths under
                    which to register the servlet.

If the sling.servlet.paths property is defined, all other properties are
ignored (currently). If neither sling.servlet.paths nor
sling.servlet.resourceTypes is defined, the servlet is ignored and not
registered.

Servlets are not registered with their own extensions like scripts are
done. In this context you should not mix the sling.servlet.extensions
property with script path extensions: The former is used to support
request URL extensions like in "html" in /a/b/c/html or "txt"
in /a/b/c/txt.js. The latter is used to indicate the scripting language
used such as "js" in /a/b/c/txt.js.

> 
> For example, how does the VelocityTemplatesScriptEngine class get
> mapped to *.vm files (and perhaps specific resourceTypes?)

The extensions of the script file (such as "vm" in /a/b/c/json.vm) is
used to find the scripting language implementation - or ScriptEngine in
JSR-223 terms - to evaluate the script. These extensions are defined by
the JSR-223 ScriptEngineFactory implementations.

Hope this helps.

Regards
Felix


[1] http://incubator.apache.org/sling/site/servlet-resolution.html