the clerezza project (which has been accepted for apache incubation last
week) contains some scala support as well [1]. It's based on sling-code but
extended to provide a ScriptEngineFactory. It takes to declare the bound
variables using a type visible to the "interpreted" scala code in the OSGi
runtime.
This ScriptEngine is used for standard scripting but also for
"ScalaServerPages", here Scala is used with a DSL to render a
response-resource (a node in an RDF graph). The following is an example of a
ScalaServerPage:
def um(s: Any) = new UriRef("http://clerezza.org/2009/05/usermanager#"+s)
def perm(s: Any) = new UriRef("http://clerezza.org/2008/10/permission#"+s)
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Permissions for user {res/um("user")/FOAF.name}</title>
</head>
<body>
{for (permission <- res/um("permission")) yield
<div id="permission">
{permission/perm("javaPermissionEntry")*}
</div>
}
</body>
</html>
While ScalaServerPages would probably be hard to use withing Sling I think
it would be good to pool the efforts for having a single
javax.script.ScriptEngineFactory.
>From the clerezza-code the following wqould have to be done:
- refactor ScalaInterpreter (taken from Sling) for synchronization issues
- enhance algorithm to find best runtime-visible interface of a bound object
(and possibly use implicit conversions to cast the object from one
implemented interface to the other)
Cheers,
1. The code should be moved to the invubator svn very soon, currently its
here: http://scm.trialox.org/main/org.clerezza.scala/
On Tue, Dec 1, 2009 at 7:32 PM, Carsten Ziegeler <[email protected]>wrote:
> Michael Dürig wrote:
> >>> [1]. A simple hello world programm looks basically like this in Scala:
> >>>
> >>> println {
> >>> <html>
> >>> <h1>{ "Hello " + currentNode("title") }</h1>
> >>> Today is { Calendar.getInstance.getTime } <br />
> >>> My path is { currentNode.path }
> >>> { Tree(currentNode).render }
> >>> </html>
> >>> }
> >>>
> >> Yes, and this looks fine except the println statement surrounding
> >> everything. Maybe if we can get rid of that one we are already one step
> >> further?
> >
> > Well that shouldn't be too difficult to do I think. It was actually my
> > decision to *explicitly* println. I can try to come up with another
> > patch later.
> >
> Cool!
>
> Carsten
> --
> Carsten Ziegeler
> [email protected]
>