You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Lassi Immonen <la...@valkeus.com> on 2002/06/27 11:07:25 UTC

Using Jython in Cocoon

Hi,

I've been using Jython in cocoon for some time by using my own 
JythonGenerator. And I feel it's simplicity and speed that I can test 
things is very nice.

ScriptGenerator have several shortcomings regarding using Jythons Lib 
modules and I tried to fix them, but they messed ScriptGenerator too 
much ,so I decided to move all those modifications to JythonGenerator.

I'm using JythonGenerator like this:
<map:generate src="tests/test.py" type="python">
   <parameter name="databasepool" value="valkeus"/>
   <parameter name="python.path" value="c:/prog/jython/lib"/>
   <parameter name="classpath" value="c:/prog/jython/jython.jar"/>

Not sure are those settings best to be there or somewhere else?

I can also import all .py files that are in python.path or in the same 
directory as my test.py.

Example script using database:
test.py
-----
import com.ziclix.python.sql as sql
import mymodule

#connection is pooled connection from sitemap
con = sql.PyConnection(connection)
cur = con.cursor(1);

user = request.getParameter("user")
data = mymodule.getdata()

output.append("<db>")

cur.execute("select * from users where name=? and data=?",(user,data))
for users in cur.fetchall():
    output.append("<user>%s</user>"%users[0])

output.append("</db>")
-----

I feel quite good on using Jython with Cocoon, it let me escape from XSP 
verbosity. The question of speed arises though. Now script is loaded 
everytime request comes. Any advise on that?

In attachment you can find the JythonGenerator.

Thanks,
  Lassi Immonen

RE: Using Jython in Cocoon

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Lassi Immonen [mailto:lassi.immonen@valkeus.com]
> 
> Hi,
> 
> I've been using Jython in cocoon for some time by using my own
> JythonGenerator. And I feel it's simplicity and speed that I can test
> things is very nice.

Have you tried Python XSPs in Cocoon 2.1-dev?


> ScriptGenerator have several shortcomings regarding using Jythons Lib
> modules and I tried to fix them, but they messed ScriptGenerator too
> much ,so I decided to move all those modifications to JythonGenerator.
> 
> I'm using JythonGenerator like this:
> <map:generate src="tests/test.py" type="python">
>    <parameter name="databasepool" value="valkeus"/>
>    <parameter name="python.path" value="c:/prog/jython/lib"/>
>    <parameter name="classpath" value="c:/prog/jython/jython.jar"/>
> 
> Not sure are those settings best to be there or somewhere else?
> 
> I can also import all .py files that are in python.path or in the same
> directory as my test.py.
> 
> Example script using database:
> test.py
> -----
> import com.ziclix.python.sql as sql
> import mymodule
> 
> #connection is pooled connection from sitemap
> con = sql.PyConnection(connection)
> cur = con.cursor(1);
> 
> user = request.getParameter("user")
> data = mymodule.getdata()
> 
> output.append("<db>")
> 
> cur.execute("select * from users where name=? and data=?",(user,data))
> for users in cur.fetchall():
>     output.append("<user>%s</user>"%users[0])
> 
> output.append("</db>")
> -----
> 
> I feel quite good on using Jython with Cocoon, it let me escape from
XSP
> verbosity. The question of speed arises though. Now script is loaded
> everytime request comes. Any advise on that?

Have a look at PythonGenerator in 2.1. IIRC, it pre-"compiles" Python
scripts.

Vadim


> In attachment you can find the JythonGenerator.
> 
> Thanks,
>   Lassi Immonen


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org