You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Felix Meschberger <fm...@gmail.com> on 2008/06/01 21:30:34 UTC

Re: what is the correct way to run non javascript embedded in html using sling.

Hi Janandith,

Am Sonntag, den 01.06.2008, 01:26 +0530 schrieb janandith jayawardena:
> Hi Felix ,
> 
> Thanks your explanation helped me a lot.

Good.

>  There is another thing to clarify.
> 
> I created a separate standalone project to test the scala Interpreter.
> According to what I observed the interpreter takes in the script as a string
> to evaluate.

You mean, the Scala interpreter takes a String argument being the script
to execute ? Doesn't the interpreter have a method taking a Reader,
which is the script to execute ?

> Therefore I guess I will have to read the script file and pass it to the
> interpreter in a String.

If there is no reader, yes.

> To do this where should I place my script file for automatic reading. Can I
> use the command.
> 
> "curl -X PUT -d @html.scala
> http://admin:admin@localhost:8888/apps/foo/bar/html.scala"

The placement of the script is independent of how the script is actually
executed.

> Is it possible for  Object eval(Reader reader , ScriptContext scriptContext)
> to read in the file automatically so I can get the string using "Reader" or
> should I implement an Object eval(String scalaScript , ScriptContext
> scriptContext) method in the script engine.

Sling calls the eval(Reader, ScriptContext) method with the reader
providing access to the script source. If you have to call the Scala
interpreter with a String being the script, you will have to read the
content of the Reader into a String (probaly reading from the Reder into
a StringBuffer until EOF and at the end using StringBuffer.toString() to
get the script) and call the interpreter then.

Hope this helps.

Regards
Felix


Re: what is the correct way to run non javascript embedded in html using sling.

Posted by Felix Meschberger <fm...@gmail.com>.
Hi Janandith,

Am Mittwoch, den 04.06.2008, 22:40 +0530 schrieb janandith jayawardena:
> Hi Felix,
> 
> I've created a jira issue and attached the code as scala.tar.gz  till I'm
> able  to  commit to  the  google project.

Cool. Thanks. Aparently Bertrand has fixed the google codes project.
Still having the JIRA issue is of course required to move any google
code over to the Sling code base.


> 
> Please have a look at it.

Will do. Thanks.

Regards
Felix


Re: what is the correct way to run non javascript embedded in html using sling.

Posted by janandith jayawardena <ja...@gmail.com>.
Hi Felix,

I've created a jira issue and attached the code as scala.tar.gz  till I'm
able  to  commit to  the  google project.

Please have a look at it.

janandith.

Re: what is the correct way to run non javascript embedded in html using sling.

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

The attached pom looks like the Rhino/Javascript pom, which certainly
does not load/include the Scala interpreter ...

The interpreter, ready-to-run, does not necessairily show in the web
console. Rather it is the fact, that the interpreter is registered by
the ScriptManager.

I suggest you start committing what you have to the google code project
such that we could be of better help.

Regards
Felix

Am Dienstag, den 03.06.2008, 19:29 +0530 schrieb janandith jayawardena:
> Hi,
> 
> I think the reason is because the scala library which contains the
> interpreter is not correctly loading for the script to run.
> 
> 
> This is because in the launchpad I don't see the scala.tools.nsc library
> loaded.
> 
> I can only see the following,
> 
> "imported Packagesjavax.script,version=0.0.0 from System Bundle (0)
> org.apache.sling.scripting.api,version=2.0.0.incubator-SNAPSHOT from
> org.apache.sling.scripting.api (3)"
> 
> 
> I guess my maven configuration is not correct. What is the correct way to
> add a dependancy to load in sling.
> 
> The pom.xml I created is as follows, Apart from this I added the path to the
> source folder in the pom.xml file found in sling main directory. please
> point out any error I've done.
> 
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
> 
>     <modelVersion>4.0.0</modelVersion>
>     <parent>
>         <groupId>org.apache.sling</groupId>
>         <artifactId>sling</artifactId>
>         <version>1-incubator-SNAPSHOT</version>
>         <relativePath>../../parent/pom.xml</relativePath>
>     </parent>
> 
>     <artifactId>org.apache.sling.scripting.javascript</artifactId>
>     <version>2.0.0-incubator-SNAPSHOT</version>
>     <packaging>bundle</packaging>
> 
>     <name>Sling - Scripting - JavaScript Support</name>
>     <description>Support for JavaScript scripting</description>
> 
>     <scm>
>         <connection>
>             scm:svn:
> http://svn.apache.org/repos/asf/incubator/sling/trunk/scripting/javascript
>         </connection>
>         <developerConnection>
>             scm:svn:
> https://svn.apache.org/repos/asf/incubator/sling/trunk/scripting/javascript
>         </developerConnection>
>         <url>
> 
> http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript
>         </url>
>     </scm>
> 
>     <build>
>         <plugins>
>             <plugin>
>                 <groupId>org.apache.felix</groupId>
>                 <artifactId>maven-scr-plugin</artifactId>
>             </plugin>
>             <plugin>
>                 <groupId>org.apache.felix</groupId>
>                 <artifactId>maven-bundle-plugin</artifactId>
>                 <extensions>true</extensions>
>                 <configuration>
>                     <instructions>
>                         <Private-Package>
>                             org.apache.sling.scripting.javascript.*,
>                             org.mozilla.classfile,
>                             !org.mozilla.javascript.xml.impl.xmlbeans,
>                             org.mozilla.javascript.*
>                         </Private-Package>
>                         <DynamicImport-Package>*</DynamicImport-Package>
>                         <ScriptEngine-Name>${pom.name}</ScriptEngine-Name>
> 
> <ScriptEngine-Version>${pom.version}</ScriptEngine-Version>
>                     </instructions>
>                 </configuration>
>             </plugin>
>         </plugins>
>     </build>
> 
>     <dependencies>
>         <dependency>
>             <groupId>org.apache.sling</groupId>
>             <artifactId>org.apache.sling.api</artifactId>
>             <version>2.0.0-incubator-SNAPSHOT</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.sling</groupId>
>             <artifactId>org.apache.sling.scripting.api</artifactId>
>             <version>2.0.0-incubator-SNAPSHOT</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.sling</groupId>
>             <artifactId>org.apache.sling.jcr.resource</artifactId>
>             <version>2.0.0-incubator-SNAPSHOT</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.sling</groupId>
>             <artifactId>org.apache.sling.commons.testing</artifactId>
>             <version>2.0.0-incubator-SNAPSHOT</version>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.jackrabbit</groupId>
>             <artifactId>jackrabbit-core</artifactId>
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.sling</groupId>
>             <artifactId>org.apache.sling.commons.json</artifactId>
>             <version>2.0.0-incubator-SNAPSHOT</version>
>         </dependency>
>         <dependency>
>             <groupId>javax.servlet</groupId>
>             <artifactId>servlet-api</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>javax.jcr</groupId>
>             <artifactId>jcr</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>rhino</groupId>
>             <artifactId>js</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>org.slf4j</groupId>
>             <artifactId>slf4j-api</artifactId>
>         </dependency>
>         <!-- Testing -->
>         <dependency>
>             <groupId>junit</groupId>
>             <artifactId>junit</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>org.slf4j</groupId>
>             <artifactId>slf4j-simple</artifactId>
>             <scope>test</scope>
>         </dependency>
>     </dependencies>
> </project>
> 
> thanks,
> janandith


Re: what is the correct way to run non javascript embedded in html using sling.

Posted by janandith jayawardena <ja...@gmail.com>.
Hi,

I think the reason is because the scala library which contains the
interpreter is not correctly loading for the script to run.


This is because in the launchpad I don't see the scala.tools.nsc library
loaded.

I can only see the following,

"imported Packagesjavax.script,version=0.0.0 from System Bundle (0)
org.apache.sling.scripting.api,version=2.0.0.incubator-SNAPSHOT from
org.apache.sling.scripting.api (3)"


I guess my maven configuration is not correct. What is the correct way to
add a dependancy to load in sling.

The pom.xml I created is as follows, Apart from this I added the path to the
source folder in the pom.xml file found in sling main directory. please
point out any error I've done.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.apache.sling</groupId>
        <artifactId>sling</artifactId>
        <version>1-incubator-SNAPSHOT</version>
        <relativePath>../../parent/pom.xml</relativePath>
    </parent>

    <artifactId>org.apache.sling.scripting.javascript</artifactId>
    <version>2.0.0-incubator-SNAPSHOT</version>
    <packaging>bundle</packaging>

    <name>Sling - Scripting - JavaScript Support</name>
    <description>Support for JavaScript scripting</description>

    <scm>
        <connection>
            scm:svn:
http://svn.apache.org/repos/asf/incubator/sling/trunk/scripting/javascript
        </connection>
        <developerConnection>
            scm:svn:
https://svn.apache.org/repos/asf/incubator/sling/trunk/scripting/javascript
        </developerConnection>
        <url>

http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript
        </url>
    </scm>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-scr-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Private-Package>
                            org.apache.sling.scripting.javascript.*,
                            org.mozilla.classfile,
                            !org.mozilla.javascript.xml.impl.xmlbeans,
                            org.mozilla.javascript.*
                        </Private-Package>
                        <DynamicImport-Package>*</DynamicImport-Package>
                        <ScriptEngine-Name>${pom.name}</ScriptEngine-Name>

<ScriptEngine-Version>${pom.version}</ScriptEngine-Version>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.api</artifactId>
            <version>2.0.0-incubator-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.scripting.api</artifactId>
            <version>2.0.0-incubator-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.jcr.resource</artifactId>
            <version>2.0.0-incubator-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.commons.testing</artifactId>
            <version>2.0.0-incubator-SNAPSHOT</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.commons.json</artifactId>
            <version>2.0.0-incubator-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.jcr</groupId>
            <artifactId>jcr</artifactId>
        </dependency>
        <dependency>
            <groupId>rhino</groupId>
            <artifactId>js</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <!-- Testing -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

thanks,
janandith