[Zope] Embedding java applet into python Product

Ausum Studio ausum_studio at hotmail.com
Tue May 11 22:18:39 EDT 2004


Create a public method inside your product class that renders just the 
binary, i.e 'jclass_binary'.
Then you use, according yo your appletHeader method:

self.absolute_url() + '/jclass_binary'

... as the url that you need in the 'code' attribute of the applet tag.

Have in mind that by doing this way you won't be able to manage the cache 
settings of the binary, unless you deal with that within the method itself, 
so chances are that you'll prefer to upload your java class as a visible 
zope file.

There might be other ways to do the same thing.


Ausum



>From: Josef Meile <jmeile at hotmail.com>
>To: zope at zope.org
>Subject: [Zope] Embedding java applet into python Product
>Date: Tue, 11 May 2004 20:26:59 +0200
>
>Hi,
>
>the idea of this is to have the instances of a python product to use a java 
>applet, which comes with the product itself.
>
>This is what I've done, but I haven't had any success:
>
>On MyInstanceHome/Products/MyProduct/MyProduct.py:
>
>from OFS.Image import File
>import os,Globals
>
>def loadAppletClass():
>   #Gets the physic path where the applet is:
>   #MyInstanceHome/Products/MyProduct/java/myApplet.class
>   productHome=Globals.package_home(globals())
>   appletName='myApplet.class'
>   appletPath=os.path.join(productHome,'java/'+appletName)
>
>   #Then loads the data
>   appletData=file(appletPath)
>   return File(appletName,'',appletData)
>   #return appletData -> I tried this as well
>
>#Creates a global variable to store the
>#file reference
>APPLET_CLASS=loadAppletClass()
>
>#Here comes the usual code for manage_add
>
># Then the class definition
>class MyProduct(SimpleItem):
>   """ MyProduct class definition"""
>
>   #__init__ and other class methods come here
>
>   #Inside this method, I use some class variables that
>   #I have already initialize on the __init__ method
>   def appletHeader(self):
>     """Renders the applet tag"""
>     return \
>     """
>           <applet code="%s" width="%s" height="%s" name="myApplet">
>             <param name="showValue" value="no">
>             <param name="sampleHeight" value="10">
>             <param name="bgColor" value="%s">
>             no applet
>           </applet>
>     """ % (APPLET_CLASS,self.appletWidth,self.appletHeight,self.bgColor)
>
>then I called it from a Page template like this:
>
><applet tal:replace='structure python:here.appletHeader()'>
>   Some Applet
></applet>
>
>but I get:
>
><applet code="---> The whole binary data comes here <---"
>         width="325" height="100" name="myApplet">
>             <param name="showValue" value="no">
>             <param name="sampleHeight" value="10">
>             <param name="bgColor" value="#eeeeee">
>             no applet
>           </applet>
>
>I think this result is pretty normal because on one hand I'm returning the 
>object contents and not a reference. On the other hand, the binary data is 
>being treated as ASCII. How do I return a reference instead of returning 
>the File object itself?
>
>Thanks in advanced,
>Josef
>
>_______________________________________________
>Zope maillist  -  Zope at zope.org
>http://mail.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
>http://mail.zope.org/mailman/listinfo/zope-dev )

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar – get it now! 
http://toolbar.msn.com/go/onm00200415ave/direct/01/




More information about the Zope mailing list