Diff for /ECHO_content/ECHO_collection.py between versions 1.191 and 1.192

version 1.191, 2004/11/28 21:56:07 version 1.192, 2004/11/29 20:39:08
Line 9  class ECHO_externalLink contains informa Line 9  class ECHO_externalLink contains informa
   
   
 """  """
   from reportlab.pdfgen import canvas
   from reportlab.lib.pagesizes import A4
       
       
   
 import string  import string
   import tempfile
 import re  import re
 import os  import os
 import OFS.Image  import OFS.Image
Line 272  def manage_addECHO_fullText(self, id, ti Line 278  def manage_addECHO_fullText(self, id, ti
         REQUEST.RESPONSE.redirect(u+'/manage_main')          REQUEST.RESPONSE.redirect(u+'/manage_main')
     return ''      return ''
   
   
 class ECHO_resource(Folder,Persistent,ECHO_basis):  class ECHO_resource(Folder,Persistent,ECHO_basis):
     """ECHO Ressource"""      """ECHO Ressource"""
     security=ClassSecurityInfo()      security=ClassSecurityInfo()
Line 283  class ECHO_resource(Folder,Persistent,EC Line 290  class ECHO_resource(Folder,Persistent,EC
   
     security.declareProtected('View','index_html')      security.declareProtected('View','index_html')
   
       
     
       security.declareProtected('View','createPDF')
       def createPDF(self,RESPONSE=None,local=None,dpi=150):
           """erzeuge pdf file"""
           pages=1
           
           imagePath=self.getImagePath().replace("/mpiwg/online","")
           
           
           image="http://nausikaa2.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?fn="+imagePath+"&dw=%i&dh=%i&pn=%i"
           xmlInfo="http://nausikaa2.mpiwg-berlin.mpg.de/digitallibrary/dlInfo-xml.jsp?fn="+imagePath
           dom=xml.dom.minidom.parse(urllib.urlopen(xmlInfo))
           for parameter in dom.getElementsByTagName('parameter'):
               if parameter.getAttribute('name')=="pt":
                   pages=int(parameter.getAttribute('value'))
                   break
           
           tempfile.tempdir="/tmp/archivesImageServer"
           
           tmpPath=tempfile.mktemp()
           
   
           tmpZip=tempfile.mktemp()+".pdf"
           tmpFn=os.path.split(tmpZip)[1]
   
   
           if not os.path.exists(tempfile.tempdir):
               os.mkdir(tempfile.tempdir) 
   
           if not os.path.exists(tmpPath):
               os.mkdir(tmpPath) 
   
           if RESPONSE:
               RESPONSE.setHeader("Content-Type","text/html")
               RESPONSE.write("<h1>I am creating  the pdf</h1>")
               txt="<h3>1. step: getting the images( %i pages)</h3>"%pages
               RESPONSE.write(txt)
   
           c=canvas.Canvas(tmpZip)
           for i in range(1,pages):
               if RESPONSE:
                   RESPONSE.write(str("<p>Get Page: %i<br>\n"%i))
               faktor=dpi/72.0
               
               fn=tmpPath+"/%i.png"%i
   
               width,height=A4
               #print image%(width*faktor,height*faktor,i)
               url=urllib.urlopen(image%(width*faktor,height*faktor,i)).read()
               fh=file(fn,"w")
               fh.write(url)
               fh.close()
   
       
   
               c.drawImage(fn,0,0,width=width,height=height)
               c.showPage()
           c.save()
           if RESPONSE:
               RESPONSE.write("<p>finished<br>\n")
   
           if RESPONSE:
               len=os.stat(tmpZip)[6]
               downloadUrl=self.absolute_url()+"/downloadPDF"
               RESPONSE.write("""<h1><a href="downloadPDF?fn=%s">Click here for download ( %i Byte)</a></h1>\n"""%(tmpFn,len))
               RESPONSE.write("""<p>The file will be stored for a while, you can download it later, the URL is:</p>
               <p><a href="downloadPDF?fn=%s">%s?fn=%s</a></h1>\n"""%(tmpFn,downloadUrl,tmpFn))
               RESPONSE.close()
   
   
       def downloadPDF(self,fn):
           """download prepared set"""
           filename="/tmp/archivesImageServer/"+fn
           namePDF=self.getId()+".pdf"
           self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%namePDF)
           self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
           len=os.stat(filename)[6]
           self.REQUEST.RESPONSE.setHeader("Content-Length",len)
           images=file(filename).read()
           self.REQUEST.RESPONSE.write(images)
           self.REQUEST.RESPONSE.close()
   
   
     def getRDF(self,urn=None):      def getRDF(self,urn=None):
         """rdf"""          """rdf"""
         ret=getRDFDescription(self,self.link,urn=urn)          ret=getRDFDescription(self,self.link,urn=urn)
Line 636  class ECHO_resource(Folder,Persistent,EC Line 727  class ECHO_resource(Folder,Persistent,EC
             else:              else:
                 return "<error>no fulltext available</error>"                  return "<error>no fulltext available</error>"
   
       def getImagePath(self):
           """gibt pfad zum image aus"""
           return self.getImageView(noredirect="yes",onlyPath="yes")
   
     def getImageView(self,noredirect=None):      def getImageView(self,noredirect=None,onlyPath=None):
         """getImages; give Imageviewr  and <error></error> if somthing goes wrong."""          """getImages; give Imageviewr  and <error></error> if somthing goes wrong."""
         try:          try:
             fh=ECHO_helpers.urlopen(self.metalink)              fh=ECHO_helpers.urlopen(self.metalink)
Line 656  class ECHO_resource(Folder,Persistent,EC Line 750  class ECHO_resource(Folder,Persistent,EC
                             self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')                                self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')  
                 self.REQUEST.RESPONSE.redirect(imageurl)                  self.REQUEST.RESPONSE.redirect(imageurl)
             else:              else:
                   if not onlyPath:
                 return imageurl                  return imageurl
                   else:
                       return archivepath+"/"+imagetemp
         except:          except:
   
             if not noredirect:              if not noredirect:
Line 1190  class ECHO_resource(Folder,Persistent,EC Line 1287  class ECHO_resource(Folder,Persistent,EC
         return getattr(self,item)          return getattr(self,item)
   
     def checkRDF(self,path):      def checkRDF(self,path):
         """check if pdf behind path"""          """check if pdf in the path"""
         try:          try:
             for fileName in os.listdir(path):              for fileName in os.listdir(path):
                 if os.path.splitext(fileName)[1]==".pdf":                  if os.path.splitext(fileName)[1]==".pdf":

Removed from v.1.191  
changed lines
  Added in v.1.192


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>