cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lassi Immonen <lassi.immo...@valkeus.com>
Subject Using Jython in Cocoon
Date Thu, 27 Jun 2002 09:07:25 GMT
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

Mime
View raw message