Diff for /ECHO_content/VLPExtension.py between versions 1.64 and 1.71

version 1.64, 2007/10/04 14:15:33 version 1.71, 2008/08/05 16:47:15
Line 47  def makeXML(str): Line 47  def makeXML(str):
                               </page>"""%str                                </page>"""%str
                           
                                             
   def checkXMLfrag(str):
       """checks and returns str as XML fragment"""
       
       xmltempl = """<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
       <txt>%s</txt>"""
       try:
           dom=xml.dom.minidom.parseString(xmltempl%str)
           return str
       except:
           str=str.replace("& ","&amp; ")
   
       dom=xml.dom.minidom.parseString(xmltempl%str)
       return str
       
                        
                           
 def getText(nodelist):  def getText(nodelist):
   
Line 217  class VLP_essay(Folder): Line 232  class VLP_essay(Folder):
         if RESPONSE is not None:          if RESPONSE is not None:
             RESPONSE.redirect('manage_main')              RESPONSE.redirect('manage_main')
   
       def getPageList(self):
           """returns sorted list of (id,object) of page objects"""
   
           def sortFind(x,y):
               return cmp(x[0],y[0])
           
   #        pages=[]
   #        pagestmp=self.ZopeFind(self,obj_metatypes=['DTML Document','File'])
   #        for page in pagestmp:
   #            if not (page[1].getId()[0]=="."):
   #                pages.append(page)
   
           pages = self.objectItems(['DTML Document','File'])                        
           pages.sort(sortFind)
           return pages
           
           
       def getPageXMLfrag(self, pageNum=None, pageId=None, pageObj=None):
           """returns XML fragment of page with id"""
           xml = None
           
           if pageNum is not None:
               pl = self.getPageList()
               pageObj = pl[int(pageNum)-1][1]
               
           if pageId is not None:
               pageObj = getattr(self, pageId, None)
               
           if pageObj is not None:
               txt = ""
               data = pageObj.data
               while data is not None:
                   txt += data
                   if isinstance(data, str):
                       data = None
                   else:
                       data = data.next
           
               xml = checkXMLfrag(txt)
   
           return xml
   
   
     def getPage(self,pagenum):      def getPage(self,pagenum):
         """gibt essay page mit num aus"""          """gibt essay page mit num aus"""
Line 232  class VLP_essay(Folder): Line 289  class VLP_essay(Folder):
         #print str(pages[int(pagenum)][1]())          #print str(pages[int(pagenum)][1]())
                   
         if pages[int(pagenum)-1][1].meta_type=='File':          if pages[int(pagenum)-1][1].meta_type=='File':
                   
                 #return makeXML(str(pages[int(pagenum)-1][1]))                  #return makeXML(str(pages[int(pagenum)-1][1]))
                 #txt=pages[int(pagenum)-1][1].data.decode('utf-8')                  #txt=pages[int(pagenum)-1][1].data.decode('utf-8')
                 txt=pages[int(pagenum)-1][1].data                  txt=pages[int(pagenum)-1][1].data
                 #print txt.encode('utf-8')                  #print txt.encode('utf-8')
                   
                 return self.xml2html(makeXML(txt),quote="no")                  return self.xml2html(makeXML(txt),quote="no")
         else:          else:
                   
                   
   
                 return self.xml2html(makeXML(pages[int(pagenum)-1][1]()),quote="no")                  return self.xml2html(makeXML(pages[int(pagenum)-1][1]()),quote="no")
                   
     def nextPage(self,pagenum,url):      def nextPage(self,pagenum,url):
Line 430  class VLP_collection(ECHO_collection): Line 482  class VLP_collection(ECHO_collection):
   
   
   
     def generateSubCollections(self,errorsTXT=""):      def generateSubCollections(self,errorsTXT="",forceUpdate=False,RESPONSE=None):
         """erzeuge subcollectionen"""          """erzeuge subcollectionen"""
         logging.debug("generateSubCollections")          logging.debug("generateSubCollections")
         founds=self.ZSQLSimpleSearch("select * from vl_literature where referencetype in ('(Edited Book)','(Book)','(Collection)','(JournalVolume)','(Generic Container)')")          founds=self.ZSQLSimpleSearch("select * from vl_literature where referencetype in ('(Edited Book)','(Book)','(Collection)','(JournalVolume)','(Generic Container)')")
                   
           if RESPONSE is not None:
               RESPONSE.setHeader('Content-Type','text/html')
         self.REQUEST.RESPONSE.write("<h2>Create Subcollections</h2>\n")          self.REQUEST.RESPONSE.write("<h2>Create Subcollections</h2>\n")
         for found in founds:          for found in founds:
   
             try:              try:
                 litid = str(found.reference)                  litid = str(found.reference)
                 foundCol=self.ZopeFind(self,obj_ids=[litid])                  foundCol=self.ZopeFind(self,obj_ids=[litid])
                 if foundCol:                  if foundCol:
                     logging.debug("generateSubCollections: deleting collection %s"%found.reference)                      col = foundCol[0][1]
                       logging.debug("generateSubCollections: subcollection %s exists (%s)"%(col.getId(),found.reference))
                       if (col.title != found.titlerefdisplay) or (col.label != found.titlerefdisplay):
                           # subcollection seems to have changed    
                           logging.debug("generateSubCollections: subcollection has changed, recreating!")
                     self.manage_delObjects([foundCol[0][0]])                      self.manage_delObjects([foundCol[0][0]])
   
                 logging.debug("generateSubCollections: creating collection %s"%found.reference)  
                 manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay)                  manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay)
                 #getattr(self,found.reference).generateSubCollectionFromDB()                  else:
                       logging.debug("generateSubCollections: creating new subcollection %s"%found.reference)
                       manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay)
                                   
                 #teste ob es Images auf dem Server gibt mit gleichem Namen (frontmatter)                  #teste ob es Images auf dem Server gibt mit gleichem Namen (frontmatter)
                 if os.path.exists(os.path.join(self.vlp_basis,litid)):                  if os.path.exists(os.path.join(self.vlp_basis,litid)):
                     logging.debug("generateSubCollections: found collection dir %s"%litid)                      logging.debug("generateSubCollections: found frontmatter in %s"%litid)
   
                     obj=getattr(self,litid)                      obj=getattr(self,litid)
                     if not self.ZopeFind(obj,obj_ids=[litid]):                      if not self.ZopeFind(obj,obj_ids=[litid]):
                         metalink=self.REQUEST['URL1']+"/"+litid+"/"+litid+"/index_meta"                          metalink=self.REQUEST['URL1']+"/"+litid+"/"+litid+"/index_meta"
Line 460  class VLP_collection(ECHO_collection): Line 516  class VLP_collection(ECHO_collection):
                         obj._setObject(litid,newObj)                          obj._setObject(litid,newObj)
                                                   
                     genObj=getattr(obj,litid)                      genObj=getattr(obj,litid)
                     genObj.createIndexFile()                      genObj.createIndexFile(forceUpdate=forceUpdate)
   
                   if RESPONSE is not None:
                 self.REQUEST.RESPONSE.write("<p>%s</p>\n"%litid)                  self.REQUEST.RESPONSE.write("<p>%s</p>\n"%litid)
   
             except:              except:
                 error=sys.exc_info()[0:2]                  error=sys.exc_info()[0:2]
                 logging.error("generateSubCollections: ERROR in %s"%litid)                  logging.error("generateSubCollections: ERROR in %s"%litid)
                   if RESPONSE is not None:
                       RESPONSE.write("<p>(ERROR (%s): %s %s)</p>\n"%(litid,error[0],error[1]))
                 #logging.error("generateSubCollections: %s %s"%error)                  #logging.error("generateSubCollections: %s %s"%error)
                 #self.REQUEST.RESPONSE.write("(ERROR (%s): %s %s)\n"%(litid,repr(error[0]),repr(error[1])))                  #self.REQUEST.RESPONSE.write("(ERROR (%s): %s %s)\n"%(litid,repr(error[0]),repr(error[1])))
                 errorsTXT+="<p>No subcollection of %s  "%litid                  errorsTXT+="<p>ERROR: No subcollection of %s (ERROR: %s %s)</p>\n"%(litid,error[0],error[1])
                 #errorsTXT+="<p>No subcollection of %s  "%litid+"(ERROR: %s %s)</p>"%error                  #errorsTXT+="<p>No subcollection of %s  "%litid+"(ERROR: %s %s)</p>"%error
                                   
         return errorsTXT          return errorsTXT
Line 484  class VLP_collection(ECHO_collection): Line 544  class VLP_collection(ECHO_collection):
         if RESPONSE is not None:          if RESPONSE is not None:
             RESPONSE.redirect('manage_main')              RESPONSE.redirect('manage_main')
   
     def updateCollection(self,RESPONSE=None):      def updateCollection(self,forceUpdate=False,RESPONSE=None):
         """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner"""          """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner"""
         errorsTXT="<h2>Errors</h2>"          errorsTXT="<h2>Errors</h2>"
           if RESPONSE is not None:
               RESPONSE.setHeader('Content-Type','text/html')
         RESPONSE.write("<html><body>")          RESPONSE.write("<html><body>")
         files=os.listdir(self.vlp_basis)  
   
         errorsTXT+="<h3>New Ressources</h3>"  
   
           files=os.listdir(self.vlp_basis)
         for fileName in files:          for fileName in files:
               
             if fileName[0:3]=="lit":              if fileName[0:3]=="lit":
                   
                 metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta"                  metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta"
                 try:                  try:
                     if not hasattr(self,fileName):                      if not hasattr(self,fileName):
                           # create new resource
                         logging.debug("updateCollection: new %s"%fileName)                          logging.debug("updateCollection: new %s"%fileName)
                         RESPONSE.write("<p>new: %s\n</p>"%fileName)                          if RESPONSE is not None:
                               RESPONSE.write("<p>new: %s</p>\n"%fileName)
                         newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','')                          newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','')
                         self._setObject(fileName,newObj)                          self._setObject(fileName,newObj)
                                   
                     RESPONSE.write("<p>got: %s\n</p>"%fileName)                      if RESPONSE is not None:
                           RESPONSE.write("<p>got: %s "%fileName)
                     genObj=getattr(self,fileName)                      genObj=getattr(self,fileName)
                     logging.debug("updateCollection: inspecting %s"%fileName)                      logging.debug("updateCollection: inspecting %s"%fileName)
                       # create index
                     if hasattr(genObj,'createIndexFile'):                      if hasattr(genObj,'createIndexFile'):
                         try:                          try:
                             logging.debug("updateCollection: creating index for %s"%fileName)                              logging.debug("updateCollection: creating index for %s"%fileName)
                             genObj.createIndexFile()                              msg = genObj.createIndexFile(forceUpdate=forceUpdate)
                               if msg and RESPONSE is not None:
                                   RESPONSE.write(msg)
                         except:                          except:
                             error=sys.exc_info()[0:2]                              error=sys.exc_info()[0:2]
                             RESPONSE.write("<p>(ERROR (%s): %s %s)</p>\n"%(fileName,error[0],error[1]))                              if RESPONSE is not None:
                             errorsTXT+="<p>No indexfile of %s  "+"(ERROR: %s %s)</p>"%error                                  RESPONSE.write("(ERROR (%s): %s %s) "%(fileName,error[0],error[1]))
                               errorsTXT+="<p>ERROR creating index for %s "%fileName+"(ERROR: %s %s)</p>\n"%error
   
                       # update pageSizeSum for subcollections
                     if genObj.meta_type=="VLP_subcollection":                      if genObj.meta_type=="VLP_subcollection":
                           if RESPONSE is not None:
                               RESPONSE.write(" is subcollection")
                         logging.debug("updateCollection: %s is subcollection"%fileName)                          logging.debug("updateCollection: %s is subcollection"%fileName)
                         genObj.pageSizeSum=getattr(genObj,fileName).getPageSizeSum()                          genObj.pageSizeSum=getattr(genObj,fileName).getPageSizeSum()
                     else:                      else:
                         genObj.pageSizeSum=genObj.getPageSizeSum()                          genObj.pageSizeSum=genObj.getPageSizeSum()
                                                   
                       if RESPONSE is not None:
                           RESPONSE.write("</p>\n")
                          
                 except:                  except:
                     error=sys.exc_info()[0:2]                      error=sys.exc_info()[0:2]
                       logging.error("updateCollection: ERROR in %s (%s %s)"%(fileName,error[0],error[1]))
                       if RESPONSE is not None:
                     RESPONSE.write("<p>(ERROR (%s): %s %s)</p>\n"%(fileName,error[0],error[1]))                      RESPONSE.write("<p>(ERROR (%s): %s %s)</p>\n"%(fileName,error[0],error[1]))
                     errorsTXT+="<p>File not created:%s  (ERROR: %s %s)</p>"%(fileName,error[0],error[1])                      errorsTXT+="<p>File not created:%s  (ERROR: %s %s)</p>\n"%(fileName,error[0],error[1])
                                                                   
         errorsTXT+=self.generateSubCollections()          # update subcollections    
           errorsTXT+=self.generateSubCollections(forceUpdate=forceUpdate,RESPONSE=RESPONSE)
         errorsTXT+="\n"          errorsTXT+="\n"
           if RESPONSE is not None:
         RESPONSE.write(errorsTXT)          RESPONSE.write(errorsTXT)
               RESPONSE.write("</body></html>")
   
     def updateCollectionMD(self,RESPONSE=None):      def updateCollectionMD(self,RESPONSE=None):
         """updateMD"""          """updateMD"""
Line 605  class VLP_resource(ECHO_resource,Cacheab Line 680  class VLP_resource(ECHO_resource,Cacheab
                           
             if os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pageimg')):              if os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pageimg')):
                     return os.path.join(self.vlp_basis,self.resourceID,'pageimg')                      return os.path.join(self.vlp_basis,self.resourceID,'pageimg')
             elif os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi')):              elif os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pages')):
                     return os.path.join(self.vlp_basis,self.resourceID,'pagesHi')                      return os.path.join(self.vlp_basis,self.resourceID,'pages')
             else:              else:
                     return "<error>no images </error>"                      return "<error>no images </error>"
           
Line 680  class VLP_resource(ECHO_resource,Cacheab Line 755  class VLP_resource(ECHO_resource,Cacheab
   
         if self.REQUEST.get('p',None):          if self.REQUEST.get('p',None):
             #self.REQUEST.set('pn',self.file2page(self.REQUEST.get('p',None)))              #self.REQUEST.set('pn',self.file2page(self.REQUEST.get('p',None)))
             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL']+"?pn="+self.file2page(self.REQUEST.get('p',None)))              params = "pn=%s"%self.file2page(self.REQUEST.get('p',None))
               mk = self.REQUEST.get('mk',None)
               if mk:
                   params += "&mk=%s"%mk
               self.REQUEST.RESPONSE.redirect(self.REQUEST['URL']+'?'+params)
                         
         if hasattr(self,'libraryTemplate.html'):          if hasattr(self,'libraryTemplate.html'):
                 return getattr(self,'libraryTemplate.html')()                  return getattr(self,'libraryTemplate.html')()
Line 740  class VLP_resource(ECHO_resource,Cacheab Line 818  class VLP_resource(ECHO_resource,Cacheab
             #size of hi resolution              #size of hi resolution
             files=[]              files=[]
             try:              try:
                     pathHi=os.path.join(self.vlp_basis,self.resourceID,'pagesHi')                      pathHi=os.path.join(self.vlp_basis,self.resourceID,'pages')
                     files=os.listdir(pathHi)                      files=os.listdir(pathHi)
                     hi=0                      hi=0
                     for f in files:                      for f in files:
Line 787  class VLP_resource(ECHO_resource,Cacheab Line 865  class VLP_resource(ECHO_resource,Cacheab
             ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pageimg'))              ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pageimg'))
             self.imagePath='pageimg'              self.imagePath='pageimg'
         except:          except:
             ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi'))              ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pages'))
             self.imagePath='pagesHi'              self.imagePath='pages'
         temp=[]          temp=[]
         ret.sort()          ret.sort()
         for x in ret:          for x in ret:
Line 800  class VLP_resource(ECHO_resource,Cacheab Line 878  class VLP_resource(ECHO_resource,Cacheab
     def firstPage(self,url=None):      def firstPage(self,url=None):
         """showlink to the first image"""          """showlink to the first image"""
         if self.REQUEST.get('pn','1')=="1": #erste seinte dann kein a tag          if self.REQUEST.get('pn','1')=="1": #erste seinte dann kein a tag
             return """<img src="../../images/first.gif" alt="first" width="14" height="14" border="0"><br>first"""              return """<img src="/images/first.gif" alt="first" width="14" height="14" border="0"><br>first"""
   
         else:          else:
                 ws=self.REQUEST.get('ws','1')                  ws=self.REQUEST.get('ws','1')
                 return """<a href=%s>                  return """<a href=%s>
                          <img src="../../images/first.gif" alt="first" width="14" height="14" border="0"><br>first                           <img src="/images/first.gif" alt="first" width="14" height="14" border="0"><br>first
                          </a>                           </a>
                          """%(self.REQUEST['URL']+"?pn=1&ws=%s"%ws)                           """%(self.REQUEST['URL']+"?pn=1&ws=%s"%ws)
   
Line 816  class VLP_resource(ECHO_resource,Cacheab Line 894  class VLP_resource(ECHO_resource,Cacheab
             ln=len(pages)              ln=len(pages)
                   
         if (self.REQUEST.get('pn')==str(ln)) or (ln==1): #letzte seite dann kein a tag oder nur eine Seite          if (self.REQUEST.get('pn')==str(ln)) or (ln==1): #letzte seite dann kein a tag oder nur eine Seite
             return """<img src="../../images/last.gif" alt="last" width="14" height="14" border="0"><br>last"""              return """<img src="/images/last.gif" alt="last" width="14" height="14" border="0"><br>last"""
   
         else:          else:
                 ws=self.REQUEST.get('ws','1')                  ws=self.REQUEST.get('ws','1')
                 return """<a href=%s>                  return """<a href=%s>
                          <img src="../../images/last.gif" alt="last" width="14" height="14" border="0"><br>last                           <img src="/images/last.gif" alt="last" width="14" height="14" border="0"><br>last
                          </a>                           </a>
                          """%(self.REQUEST['URL']+"?pn="+str(ln)+"&ws="+ws)                           """%(self.REQUEST['URL']+"?pn="+str(ln)+"&ws="+ws)
                           
Line 831  class VLP_resource(ECHO_resource,Cacheab Line 909  class VLP_resource(ECHO_resource,Cacheab
   
         nn = int(self.REQUEST.get('pn','1'))-1          nn = int(self.REQUEST.get('pn','1'))-1
         if nn < 1: #letzte  seite dann kein a tag          if nn < 1: #letzte  seite dann kein a tag
             return """<img src="../../images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev"""              return """<img src="/images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev"""
   
         else:          else:
                 ws=self.REQUEST.get('ws','1')                  ws=self.REQUEST.get('ws','1')
                 return """<a href=%s>                  return """<a href=%s>
                          <img src="../../images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev                           <img src="/images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev
                          </a>                           </a>
                          """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)                           """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)
   
Line 848  class VLP_resource(ECHO_resource,Cacheab Line 926  class VLP_resource(ECHO_resource,Cacheab
   
         nn = int(self.REQUEST.get('pn','1'))+1          nn = int(self.REQUEST.get('pn','1'))+1
         if (nn>int(ln)) or (ln==1): #letzte  seite dann kein a tag          if (nn>int(ln)) or (ln==1): #letzte  seite dann kein a tag
             return """<img src="../../images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next"""              return """<img src="/images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next"""
   
         else:          else:
                 ws=self.REQUEST.get('ws','1')                  ws=self.REQUEST.get('ws','1')
                 return """<a href=%s>                  return """<a href=%s>
                          <img src="../../images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next                           <img src="/images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next
                          </a>                           </a>
                          """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)                           """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)
                   
Line 899  class VLP_resource(ECHO_resource,Cacheab Line 977  class VLP_resource(ECHO_resource,Cacheab
            pageinfo=self.readIndexFile()[pn-1]             pageinfo=self.readIndexFile()[pn-1]
            return pageinfo[2]             return pageinfo[2]
         
     def createIndexFile(self,RESPONSE=None):      def createIndexFile(self,forceUpdate=False,RESPONSE=None):
         """create index file"""          """create index file"""
   
         logging.debug("createindexfile of %s"%self.id)          logging.debug("createindexfile of %s"%self.id)
         pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_template.zpt')).__of__(self)()  
   
         if not hasattr(self,'index.xml'):          if hasattr(self,'index.xml'):
               # index exists
               zt=getattr(self,'index.xml')
               if not forceUpdate:
                   # check if directory is newer (self.imagePath sould be set by now)
                   imgdir = os.path.join(self.vlp_basis, self.resourceID, self.imagePath)
                   dirtime = os.path.getmtime(imgdir)
                   zttime = zt.bobobase_modification_time()
                   logging.debug("createindexfile: dir %s of %s index of %s"%(imgdir,dirtime,zttime))
                   if dirtime < zttime:
                       # nothing to do
                       logging.debug("createindexfile: dir %s older than index"%(imgdir))
                       return "index is up to date"
                   
           else:
               # create new index template
             zt=ZopePageTemplate('index.xml')              zt=ZopePageTemplate('index.xml')
             self._setObject('index.xml',zt)              self._setObject('index.xml',zt)
         else:  
             zt=getattr(self,'index.xml')  
                           
           # fill index template
           pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_template.zpt')).__of__(self)()
         #logging.debug("createindexfile uses %s"%pt)          #logging.debug("createindexfile uses %s"%pt)
         zt.pt_edit(pt, 'text/xml')          zt.pt_edit(pt, 'text/xml')
         transaction.get().commit()          transaction.get().commit()

Removed from v.1.64  
changed lines
  Added in v.1.71


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