Hi, I am facing a basic problem with Zope that I'm unable to solve. I want to embed a java applet (jar) in my zope product. The jar file lives as "<Product Basedir>/www/foo.jar" on the filesystem. I want to make this available as "<Product Instance Dir>/foo.jar" inside zope. To include ZPT files, I'm able to do - from Products.PageTemplates.PageTemplateFile import PageTemplateFile ... class Foo(Folder): ... index_html = PageTemplateFile('zpt/index_html', globals()) and make zpt files available inside zope. How can I do the same for arbitrary files such as java archives and others? I don't know how to use the "File" object for this purpose. Can someone please help? Thanks in advance. - Raja
Raja Subramanian wrote:
Hi,
I am facing a basic problem with Zope that I'm unable to solve.
I want to embed a java applet (jar) in my zope product. The jar file lives as "<Product Basedir>/www/foo.jar" on the filesystem. I want to make this available as "<Product Instance Dir>/foo.jar" inside zope.
To include ZPT files, I'm able to do -
from Products.PageTemplates.PageTemplateFile import PageTemplateFile ... class Foo(Folder): ... index_html = PageTemplateFile('zpt/index_html', globals())
and make zpt files available inside zope. How can I do the same for arbitrary files such as java archives and others?
I don't know how to use the "File" object for this purpose. Can someone please help?
For Images you can use from Globals import ImageFile file=ImageFile('www/image.gif', globals()) I guess you can use the FS* object from CMF Core to add other types of files, but I haven't tried it my self. Of course the CMF also includes DirectoryView and there is a standalone version of CMFs external file management that's called FileSystemSite (I think?) This is a solution that import whole directories at a time. You could also write you own custom version of ImageFile, the code (in App/ImageFile.py) isn't specialy complex. Regards, Johan Carlsson -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72 Email: johanc@easypublisher.com SE-113 37 STOCKHOLM
Johan Carlsson wrote at 2004-9-3 08:55 +0200:
... For Images you can use
from Globals import ImageFile file=ImageFile('www/image.gif', globals())
Despite its name, you can use "ImageFile" for arbitrary files and not only for images. -- Dieter
Dieter Maurer wrote:
Johan Carlsson wrote at 2004-9-3 08:55 +0200:
... For Images you can use
from Globals import ImageFile
file=ImageFile('www/image.gif', globals())
Despite its name, you can use "ImageFile" for arbitrary files and not only for images.
Provide it actually can guess the content_type. If content_type is not important it may not be a big problem if the guess fails (in which case the content_type will be set to: 'image/%s' % path[path.rfind('.')+1:] ). I would subclass ImageFile and override the __init__ with an extra content_type argument. But that's me :-) -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72 Email: johanc@easypublisher.com SE-113 37 STOCKHOLM
Hi, Johan Carlsson wrote:
Johan Carlsson wrote at 2004-9-3 08:55 +0200:
For Images you can use
from Globals import ImageFile file=ImageFile('www/image.gif', globals())
Despite its name, you can use "ImageFile" for arbitrary files and not only for images.
Provide it actually can guess the content_type.
I'm running zope 2.6.4, python 2.2.3 on debian sarge. file = ImageFile('www/applet.jar', globals()) produced the following http headers - Content-Type: application/x-java-archive For PDF files, it produced "application/pdf" and for MS Word documents it produces "application/msword". ImageFile is pretty clever :-)
I would subclass ImageFile and override the __init__ with an extra content_type argument. But that's me :-)
I found that on debian I can make ImageFile understand new content types simply by modifying /etc/mime.types. Thanks to everyone for helping. - Raja
Raja Subramanian wrote:
Hi,
Johan Carlsson wrote:
Johan Carlsson wrote at 2004-9-3 08:55 +0200:
For Images you can use
from Globals import ImageFile
file=ImageFile('www/image.gif', globals())
Despite its name, you can use "ImageFile" for arbitrary files and not only for images.
Provide it actually can guess the content_type.
I'm running zope 2.6.4, python 2.2.3 on debian sarge.
file = ImageFile('www/applet.jar', globals())
produced the following http headers -
Content-Type: application/x-java-archive
For PDF files, it produced "application/pdf" and for MS Word documents it produces "application/msword". ImageFile is pretty clever :-)
Yes. It looks it uses from OFS.content_types import guess_content_type which in turn uses Python mime_types module which defines 120 or so mimetype2ext mappings. I'm just one of those guys who prefers explicit from implicit :-)
I would subclass ImageFile and override the __init__ with an extra content_type argument. But that's me :-)
I found that on debian I can make ImageFile understand new content types simply by modifying /etc/mime.types.
Yeah, mimetypes seems to look for mime types in: "/etc/mime.types", "/usr/local/etc/httpd/conf/mime.types", "/usr/local/lib/netscape/mime.types", "/usr/local/etc/httpd/conf/mime.types", # Apache 1.2 "/usr/local/etc/mime.types", # Apache 1.3 and there's also a mime.types in OFS. Even though, in a Product I would rather not require the user to configure mime.types just to install my prodct :-) -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72 Email: johanc@easypublisher.com SE-113 37 STOCKHOLM
participants (3)
-
Dieter Maurer -
Johan Carlsson -
Raja Subramanian