Diff for /zogiLib/zogiLib.py between versions 1.2 and 1.31

version 1.2, 2004/03/25 18:32:13 version 1.31, 2004/07/16 13:47:50
Line 1 Line 1
   
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile  from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from Products.PageTemplates.PageTemplate import PageTemplate  from Products.PageTemplates.PageTemplate import PageTemplate
 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate  from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
   from OFS.Image import Image
   from webdav.common import rfc1123_date
   
 import xml.dom.minidom  import xml.dom.minidom
 from OFS.Folder import Folder  from OFS.Folder import Folder
Line 10  import os Line 12  import os
 import re  import re
 import string  import string
 import urllib  import urllib
   import types
 from Globals import package_home  from Globals import package_home
   
 def getString(self,key,default=''):  ZOGIVERSION = "0.9.5 ROC:25.6.2004"
     try:  
         return self.REQUEST[key]  
     except:  
         return default  
   
   def cropf(f):
       """returns a float with reduced precision"""
       return float(int(f * 10000)/10000.0)
           
 class zogiLib_navTemplate(ZopePageTemplate):  
     """pageTemplate Objekt"""  
     meta_type="zogiLib_navTemplate"  
   
     _default_content_fn = os.path.join(package_home(globals()),  def sendFile(self, filename, type):
                                        'zpt/zogiLib_NavTemplateDefault.zpt')      """sends an object or a local file (in the product) as response"""
       paths = filename.split('/')
       object = self
       # look for an object called filename
       for path in paths:
           if hasattr(object, path):
           object = getattr(object, path)
       else:
           object = None
           break
       if object:
       # if the object exists then send it
       return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE)
       else:
       # send a local file with the given content-type
       fn = os.path.join(package_home(globals()), filename)
       self.REQUEST.RESPONSE.setHeader("Content-Type", type)
       self.REQUEST.RESPONSE.write(file(fn).read())
       return
   
   def browserCheck(self):
       """check the browsers request to find out the browser type"""
       bt = {}
       ua = self.REQUEST.get_header("HTTP_USER_AGENT")
       bt['ua'] = ua
       bt['isIE'] = string.find(ua, 'MSIE') > -1
       bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) and not bt['isIE']
       nav = ua[string.find(ua, '('):]
       ie = string.split(nav, "; ")[1]
       if string.find(ie, "MSIE") > -1:
           bt['versIE'] = string.split(ie, " ")[1]
       bt['isMac'] = string.find(ua, 'Macintosh') > -1
       bt['isWin'] = string.find(ua, 'Windows') > -1
       bt['isIEWin'] = bt['isIE'] and bt['isWin']
       bt['isIEMac'] = bt['isIE'] and bt['isMac']
       bt['staticHTML'] = False
   
       return bt
   
       
   class zogiImage(Image):
       """einzelnes Image"""
       meta_type="zogiImage"
   
     manage_options=ZopePageTemplate.manage_options+(      manage_options=ZopePageTemplate.manage_options+(
         {'label':'Copy to Filesystem','action':'copyContent'},          {'label':'Main config','action':'changeZogiImageForm'},
        )         )
   
     def getPath(self):  
         """get path"""  
         return getPath(self,'thumbtemplate.templ')  
           
     ## def changeECHO_pageTemplateWeightForm(self):      def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''):
 ##         """change"""          """init"""
 ##         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_pageTemplateWeight.zpt').__of__(self)          self.id=id
 ##         return pt()          self.title=title
           self.baseUrl=baseUrl
           self.queryString=queryString
           self.content_type=content_type
           self.precondition=precondition
   
       def getData(self):
           """getUrlData"""
           return urllib.urlopen(self.baseUrl+self.queryString)
   
 ##     def changeECHO_pageTemplateWeight(self,weight,content_type,RESPONSE=None):      def changeZogiImageForm(self):
 ##         """change"""          """Main configuration"""
 ##         self.weight=weight          pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiImageForm.zpt')).__of__(self)
 ##         self.content_type=content_type          return pt()
   
 ##         if RESPONSE is not None:      def changeZogiImage(self,title,baseUrl, queryString,RESPONSE=None):
 ##             RESPONSE.redirect('manage_main')          """change it"""
           self.title=title
           self.baseUrl=baseUrl
           self.queryString=queryString
   
           if RESPONSE is not None:
               RESPONSE.redirect('manage_main')
                   
   
     def copyContent(self):      def index_html(self, REQUEST, RESPONSE):
         """copycontent to path"""          """
           Modified version of OFS/Image.py
   
         return "copied to:"+copyContent(self,'thumbtemplate.templ')          The default view of the contents of a File or Image.
                   
           Returns the contents of the file or image.  Also, sets the
           Content-Type HTTP header to the objects content type.
           """
           
 def manage_addZogiLib_NavTemplateForm(self):          # HTTP If-Modified-Since header handling.
     """Form for adding"""          header=REQUEST.get_header('If-Modified-Since', None)
     pt=PageTemplateFile('Products/ECHO_content/zpt/AddZogilib_NavTemplate.zpt').__of__(self)          if header is not None:
     return pt()              header=header.split( ';')[0]
               # Some proxies seem to send invalid date strings for this
               # header. If the date string is not valid, we ignore it
               # rather than raise an error to be generally consistent
               # with common servers such as Apache (which can usually
               # understand the screwy date string as a lucky side effect
               # of the way they parse it).
               # This happens to be what RFC2616 tells us to do in the face of an
               # invalid date.
               try:    mod_since=long(DateTime(header).timeTime())
               except: mod_since=None
               if mod_since is not None:
                   if self._p_mtime:
                       last_mod = long(self._p_mtime)
                   else:
                       last_mod = long(0)
                   if last_mod > 0 and last_mod <= mod_since:
                       # Set header values since apache caching will return Content-Length
                       # of 0 in response if size is not set here
                       RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
                       RESPONSE.setHeader('Content-Type', self.content_type)
                       RESPONSE.setHeader('Content-Length', self.size)
                       RESPONSE.setHeader('Accept-Ranges', 'bytes')
                       self.ZCacheable_set(None)
                       RESPONSE.setStatus(304)
                       return ''
   
           if self.precondition and hasattr(self,self.precondition):
               # Grab whatever precondition was defined and then
               # execute it.  The precondition will raise an exception
               # if something violates its terms.
               c=getattr(self,self.precondition)
               if hasattr(c,'isDocTemp') and c.isDocTemp:
                   c(REQUEST['PARENTS'][1],REQUEST)
               else:
                   c()
   
           # HTTP Range header handling
           range = REQUEST.get_header('Range', None)
           request_range = REQUEST.get_header('Request-Range', None)
           if request_range is not None:
               # Netscape 2 through 4 and MSIE 3 implement a draft version
               # Later on, we need to serve a different mime-type as well.
               range = request_range
           if_range = REQUEST.get_header('If-Range', None)
           if range is not None:
               ranges = HTTPRangeSupport.parseRange(range)
   
               if if_range is not None:
                   # Only send ranges if the data isn't modified, otherwise send
                   # the whole object. Support both ETags and Last-Modified dates!
                   if len(if_range) > 1 and if_range[:2] == 'ts':
                       # ETag:
                       if if_range != self.http__etag():
                           # Modified, so send a normal response. We delete
                           # the ranges, which causes us to skip to the 200
                           # response.
                           ranges = None
                   else:
                       # Date
                       date = if_range.split( ';')[0]
                       try: mod_since=long(DateTime(date).timeTime())
                       except: mod_since=None
                       if mod_since is not None:
                           if self._p_mtime:
                               last_mod = long(self._p_mtime)
                           else:
                               last_mod = long(0)
                           if last_mod > mod_since:
                               # Modified, so send a normal response. We delete
                               # the ranges, which causes us to skip to the 200
                               # response.
                               ranges = None
   
               if ranges:
                   # Search for satisfiable ranges.
                   satisfiable = 0
                   for start, end in ranges:
                       if start < self.size:
                           satisfiable = 1
                           break
   
                   if not satisfiable:
                       RESPONSE.setHeader('Content-Range',
                           'bytes */%d' % self.size)
                       RESPONSE.setHeader('Accept-Ranges', 'bytes')
                       RESPONSE.setHeader('Last-Modified',
                           rfc1123_date(self._p_mtime))
                       RESPONSE.setHeader('Content-Type', self.content_type)
                       RESPONSE.setHeader('Content-Length', self.size)
                       RESPONSE.setStatus(416)
                       return ''
   
                   ranges = HTTPRangeSupport.expandRanges(ranges, self.size)
   
 def manage_addZogiLib_NavTemplate(self, id,title=None, text=None,                  if len(ranges) == 1:
                            REQUEST=None, submit=None):                      # Easy case, set extra header and return partial set.
     "Add a Page Template with optional file content."                      start, end = ranges[0]
                       size = end - start
   
                       RESPONSE.setHeader('Last-Modified',
                           rfc1123_date(self._p_mtime))
                       RESPONSE.setHeader('Content-Type', self.content_type)
                       RESPONSE.setHeader('Content-Length', size)
                       RESPONSE.setHeader('Accept-Ranges', 'bytes')
                       RESPONSE.setHeader('Content-Range',
                           'bytes %d-%d/%d' % (start, end - 1, self.size))
                       RESPONSE.setStatus(206) # Partial content
   
                       data = urllib.urlopen(self.baseUrl+self.queryString).read()
                       if type(data) is StringType:
                           return data[start:end]
   
                       # Linked Pdata objects. Urgh.
                       pos = 0
                       while data is not None:
                           l = len(data.data)
                           pos = pos + l
                           if pos > start:
                               # We are within the range
                               lstart = l - (pos - start)
   
                               if lstart < 0: lstart = 0
   
                               # find the endpoint
                               if end <= pos:
                                   lend = l - (pos - end)
   
                                   # Send and end transmission
                                   RESPONSE.write(data[lstart:lend])
                                   break
   
                               # Not yet at the end, transmit what we have.
                               RESPONSE.write(data[lstart:])
           
     id = str(id)                          data = data.next
     if REQUEST is None:  
         self._setObject(id, zogilib_NavTemplate(id, text))                      return ''
         ob = getattr(self, id)  
                   else:
                       boundary = choose_boundary()
   
                       # Calculate the content length
                       size = (8 + len(boundary) + # End marker length
                           len(ranges) * (         # Constant lenght per set
                               49 + len(boundary) + len(self.content_type) +
                               len('%d' % self.size)))
                       for start, end in ranges:
                           # Variable length per set
                           size = (size + len('%d%d' % (start, end - 1)) +
                               end - start)
   
   
                       # Some clients implement an earlier draft of the spec, they
                       # will only accept x-byteranges.
                       draftprefix = (request_range is not None) and 'x-' or ''
   
                       RESPONSE.setHeader('Content-Length', size)
                       RESPONSE.setHeader('Accept-Ranges', 'bytes')
                       RESPONSE.setHeader('Last-Modified',
                           rfc1123_date(self._p_mtime))
                       RESPONSE.setHeader('Content-Type',
                           'multipart/%sbyteranges; boundary=%s' % (
                               draftprefix, boundary))
                       RESPONSE.setStatus(206) # Partial content
   
                       data = urllib.urlopen(self.baseUrl+self.queryString).read()
                       # The Pdata map allows us to jump into the Pdata chain
                       # arbitrarily during out-of-order range searching.
                       pdata_map = {}
                       pdata_map[0] = data
   
                       for start, end in ranges:
                           RESPONSE.write('\r\n--%s\r\n' % boundary)
                           RESPONSE.write('Content-Type: %s\r\n' %
                               self.content_type)
                           RESPONSE.write(
                               'Content-Range: bytes %d-%d/%d\r\n\r\n' % (
                                   start, end - 1, self.size))
   
                           if type(data) is StringType:
                               RESPONSE.write(data[start:end])
                 
         if title:  
             ob.pt_setTitle(title)  
         return ob  
     else:      else:
         file = REQUEST.form.get('file')                              # Yippee. Linked Pdata objects. The following
         headers = getattr(file, 'headers', None)                              # calculations allow us to fast-forward through the
         if headers is None or not file.filename:                              # Pdata chain without a lot of dereferencing if we
             zpt = zogilib_NavTemplate(id)                              # did the work already.
                               first_size = len(pdata_map[0].data)
                               if start < first_size:
                                   closest_pos = 0
         else:          else:
             zpt = zogilib_NavTemplate(id, file, headers.get('content_type'))                                  closest_pos = (
                                       ((start - first_size) >> 16 << 16) +
                                       first_size)
                               pos = min(closest_pos, max(pdata_map.keys()))
                               data = pdata_map[pos]
   
                               while data is not None:
                                   l = len(data.data)
                                   pos = pos + l
                                   if pos > start:
                                       # We are within the range
                                       lstart = l - (pos - start)
   
                                       if lstart < 0: lstart = 0
   
                                       # find the endpoint
                                       if end <= pos:
                                           lend = l - (pos - end)
   
                                           # Send and loop to next range
                                           RESPONSE.write(data[lstart:lend])
                                           break
   
                                       # Not yet at the end, transmit what we have.
                                       RESPONSE.write(data[lstart:])
   
                                   data = data.next
                                   # Store a reference to a Pdata chain link so we
                                   # don't have to deref during this request again.
                                   pdata_map[pos] = data
   
         self._setObject(id, zpt)                      # Do not keep the link references around.
         ob = getattr(self, id)                      del pdata_map
   
                       RESPONSE.write('\r\n--%s--\r\n' % boundary)
                       return ''
   
         try:          RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
             u = self.DestinationURL()          RESPONSE.setHeader('Content-Type', self.content_type)
         except AttributeError:          RESPONSE.setHeader('Content-Length', self.size)
             u = REQUEST['URL1']          RESPONSE.setHeader('Accept-Ranges', 'bytes')
   
           # Don't cache the data itself, but provide an opportunity
           # for a cache manager to set response headers.
           self.ZCacheable_set(None)
   
           data=urllib.urlopen(self.baseUrl+self.queryString).read()
           
           if type(data) is type(''): 
               RESPONSE.setBase(None)
               return data
   
           while data is not None:
               RESPONSE.write(data.data)
               data=data.next
   
         if submit == " Add and Edit ":  
             u = "%s/%s" % (u, quote(id))  
         REQUEST.RESPONSE.redirect(u+'/manage_main')  
     return ''      return ''
   
 def readNavTemp(fileName):  
     """navtemp"""  
     print "HI reading",fileName  
           
     if os.path.exists(fileName+"/index.meta"):  def manage_addZogiImageForm(self):
         dom=xml.dom.minidom.parse(fileName+"/index.meta")      """Form for adding"""
     else:      pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiImage.zpt')).__of__(self)
         return None      return pt()
   
   
   def manage_addZogiImage(self,id,title,baseUrl, queryString,RESPONSE=None):
       """add dgilib"""
       newObj=zogiImage(id,title,baseUrl, queryString)
       self.Destination()._setObject(id,newObj)
       if RESPONSE is not None:
           RESPONSE.redirect('manage_main')
           
     print "dom",dom  
     try:  
         navTag=getText(dom.getElementsByTagName('zogilibtemplate')[0].childNodes)  
     except:  
         navTag=None  
     return navTag  
           
                   
 class zogiLib(Folder):  class zogiLib(Folder):
Line 119  class zogiLib(Folder): Line 384  class zogiLib(Folder):
   
     meta_type="zogiLib"      meta_type="zogiLib"
   
     def generateImageFolder(self):      manage_options = Folder.manage_options+(
         """images ablegen"""              {'label':'Main Config','action':'changeZogiLibForm'},
         self.manage_addFolder('images')              )
         for image in os.listdir("../lib/python/Products/zogiLib/images"):  
             fn=file("../lib/python/Products/zogiLib/images/"+image)  
             print fn  
             self.images.manage_addImage(image,fn)  
           
   
     def __init__(self, id,title,digilibBaseUrl, localFileBase):      def __init__(self, id, title, digilibBaseUrl, localFileBase, version="book", basePath="", dlTarget=None):
         """init"""          """init"""
   
         self.id=id          self.id=id
         self.title=title          self.title=title
         self.digilibBaseUrl=digilibBaseUrl          self.digilibBaseUrl=digilibBaseUrl
         self.localFileBase=localFileBase          self.localFileBase=localFileBase
         self._setObject('topTemplate',zogiLib_navTemplate(id='topTemplate'))          self.basePath=basePath
         self.generateImageFolder()          self.layout=version
           if dlTarget:
               self.dlTarget = dlTarget
     manage_options = Folder.manage_options+(          else:
             {'label':'Main Config','action':'changeZogiLibForm'},              self.dlTarget = "digilib"
             )  
   
     def navigation_js(self):  
         """Javascript"""  
           
         return file("../lib/python/Products/zogiLib/js/navigation.js").read()  
   
               
     def generateTopJavaScript(self):  
         """generate script"""  
         ret="""var baseUrl = '%s'; """% self.REQUEST['URL0']  
         ret+="""newParameter('fn', '%s', '', 1);  
                 newParameter('pn', '%s', '1', 1);  
                 newParameter('ws', '%s', '1.0', 1);  
                 newParameter('mo', '%s', '', 1);  
                 newParameter('mk', '%s', '', 3);  
                 newParameter('wx', '%s', '0.0', 2);  
                 newParameter('wy', '%s', '0.0', 2);  
                 newParameter('ww', '%s', '1.0', 2);  
                 newParameter('wh', '%s', '1.0', 2);  
                 newParameter('pt', '%s', '%s', 9);  
                 newParameter('brgt', '%s', '0.0', 1);  
                 newParameter('cont', '%s', '0.0', 1);  
                 newParameter('rot', '%s', '0.0', 1);  
                 newParameter('rgba', '%s', '', 1);  
                 newParameter('rgbm', '%s', '', 1);  
                 newParameter('ddpix', '%s', '', 9);  
                 newParameter('ddpiy', '%s', '', 9);"""%(getString(self,'fn'),  
                  getString(self,'pn',1),  
                  getString(self,'ws',1.0),  
                  getString(self,'mo',''),  
                  getString(self,'mk',''),  
                  getString(self,'wx',0.0),  
                  getString(self,'wy',0.0),  
                  getString(self,'ww',1.0),  
                  getString(self,'wh',1.0),  
                  getString(self,'pt',100),getString(self,'pt',100),  
                  getString(self,'brgt',0.0),  
                  getString(self,'cont',0.0),  
                  getString(self,'rot',0.0),  
                  getString(self,'rgba','0/0/0'),  
                  getString(self,'rgbm','0/0/0'),  
                  getString(self,'ddpix',0.0),  
                  getString(self,'ddpiy',0.0)  
                  )  
   
         ret+="""  
   
         var wwidth, wheight;  
         if (self.innerHeight) // all except Explorer  
         {  
         wwidth = self.innerWidth;  
         wheight = self.innerHeight;  
         }  
         else if (document.documentElement && document.documentElement.clientHeight)  
         // Explorer 6 Strict Mode  
         {  
         wwidth = document.documentElement.clientWidth;  
         wheight = document.documentElement.clientHeight;  
         }  
         else if (document.body) // other Explorers  
         {  
         wwidth = document.body.clientWidth;  
         wheight = document.body.clientHeight;  
         }  
   
       def version(self):
           """version information"""
           return ZOGIVERSION
   
       def getDLInfo(self):
           """get DLInfo from digilib server"""
           paramH={}
           baseUrl=re.sub("servlet/Scaler","dlInfo-xml.jsp",self.digilibBaseUrl)
           try:
               url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING'])
               dom=xml.dom.minidom.parse(url)
               params=dom.getElementsByTagName('parameter')
               for param in params:
                   paramH[param.getAttribute('name')]=param.getAttribute('value')
               return paramH
           except:
               return null
                   
         """  
         return ret  
   
       def createHeadJS(self):
           """generate all javascript tags for head"""
       self.checkQuery()
       bt = self.REQUEST.SESSION['browserType']
           if bt['staticHTML']:
               return
   
           pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self)
           return pt()
           
       def createParamJS(self):
           """generate javascript for parameters only"""
       self.checkQuery()
       bt = self.REQUEST.SESSION['browserType']
           if bt['staticHTML']:
               return
                                   
           pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self)
           return pt()
                                   
                   
       def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500):
           """generate Scaler IMG Tag"""
       self.checkQuery()
       bt = self.REQUEST.SESSION['browserType']
           # override with parameters from session
           if  self.REQUEST.SESSION.has_key('scalerDiv'):
               (requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv']
           # if not explicitly defined take normal request
           if not requestString:
               requestString = self.getAllDLParams()
           url = self.digilibBaseUrl+requestString
           # construct bottom and side insets
           b_par = ""
           s_par = ""
           if (bottom != 0) or (side != 0):
               b_par = "-" + str(int(bottom))
               s_par = "-" + str(int(side))
           tag = ""
           if bt['staticHTML']:
               tag += '<div id="scaler"><img id="pic" src="%s&dw=%i&dh=%i" /></div>'%(url, int(width-side), int(height-bottom))
           else:
               if bt['isN4']:
                   # N4 needs layers
                   tag += '<ilayer id="scaler">'
               else:
                   tag += '<div id="scaler">'
               tag += '<script type="text/javascript">'
               tag += "var ps = bestPicSize(getElement('scaler'));"
               # write img tag with javascript
               tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par)
               tag += '</script>'
               if bt['isN4']:
                   tag += '</ilayer>'
               else:
                   tag += '</div>'
           return tag
                   
     def generateScalerImg(self,requestString):      def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500):
         """generate Scaler Tag"""          """generate scaler img and table with navigation arrows"""
         retStr=self.digilibBaseUrl+requestString      self.checkQuery()
         jS="""<script type="text/javascript">          if requestString != None or bottom != 0 or side != 0:
         document.write("<img id=\\\"pic\\\" src=\\\"%s&dw="+wwidth+"&dh="+wheight+"\\\"/>")</script>"""%retStr              self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height)
         return jS          else:
               if self.REQUEST.SESSION.has_key('scalerDiv'):
                   # make shure to remove unused parameter
                   del self.REQUEST.SESSION['scalerDiv']
   
     def changeZogiLibForm(self):          pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self)
         """Main configuration"""  
         pt=PageTemplateFile('Products/zogiLib/zpt/changeZogiLibForm.zpt').__of__(self)  
         return pt()          return pt()
           
     def changeZogiLib(self,title,digilibBaseUrl, localFileBase,RESPONSE=None):      def createAuxDiv(self):
         """change it"""          """generate other divs"""
         self.title=title      self.checkQuery()
         self.digilibBaseUrl=digilibBaseUrl      bt = self.REQUEST.SESSION['browserType']
         self.localFileBase=localFileBase          if bt['staticHTML']:
               return
         if RESPONSE is not None:          if bt['isN4']:
             RESPONSE.redirect('manage_main')              f = 'zpt/zogilib_divsN4.zpt'
           else:
               f = 'zpt/zogilib_divs.zpt'
           pt=PageTemplateFile(os.path.join(package_home(globals()),f)).__of__(self)
           return pt()
   
                           
     def nav_html(self,fileName):      def option_js(self):
         """navigations frame"""          """javascript"""
           return sendFile(self, 'js/option.js', 'text/plain')
   
       def dl_lib_js(self):
           """javascript"""
           return sendFile(self, 'js/dl_lib.js', 'text/plain')
   
       def js_lib_js(self):
           """javascript"""
           return sendFile(self, 'js/js_lib.js', 'text/plain')
   
       def optionwindow(self):
           """showoptions"""
       self.checkQuery()
       bt = self.REQUEST.SESSION['browserType']
           if bt['staticHTML']:
               pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow_static.zpt')).__of__(self)
           else:
           finds=self.ZopeFind(self,obj_ids=['viewingTools.zpt'])
           if finds:
   
         # suche nach index.meta mit zogilib thumb info          return finds[0][1]()
           else:
                   pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self)
                   return pt()
                   
         templ=readNavTemp(self.localFileBase+"/"+fileName)      def mark1(self):
         if not templ:          """mark image"""
             templ=readNavTemp(self.localFileBase+"/"+fileName.split("/")[0])          return sendFile(self, 'images/mark1.gif', 'image/gif')
             if not templ:  
                 return self.topTemplate.document_src()      def mark2(self):
           """mark image"""
           return sendFile(self, 'images/mark2.gif', 'image/gif')
   
       def mark3(self):
           """mark image"""
           return sendFile(self, 'images/mark3.gif', 'image/gif')
   
       def mark4(self):
           """mark image"""
           return sendFile(self, 'images/mark4.gif', 'image/gif')
   
       def mark5(self):
           """mark image"""
           return sendFile(self, 'images/mark5.gif', 'image/gif')
   
       def mark6(self):
           """mark image"""
           return sendFile(self, 'images/mark6.gif', 'image/gif')
   
       def mark7(self):
           """mark image"""
           return sendFile(self, 'images/mark7.gif', 'image/gif')
   
       def mark8(self):
           """mark image"""
           return sendFile(self, 'images/mark8.gif', 'image/gif')
   
       def corner1(self):
           """mark image"""
           return sendFile(self, 'images/olinks.gif', 'image/gif')
   
       def corner2(self):
           """mark image"""
           return sendFile(self, 'images/orechts.gif', 'image/gif')
   
       def corner3(self):
           """mark image"""
           return sendFile(self, 'images/ulinks.gif', 'image/gif')
   
       def corner4(self):
           """mark image"""
           return sendFile(self, 'images/urechts.gif', 'image/gif')
   
       def up_img(self):
           """mark image"""
           return sendFile(self, 'images/up.gif', 'image/gif')
   
       def down_img(self):
           """mark image"""
           return sendFile(self, 'images/down.gif', 'image/gif')
   
       def left_img(self):
           """mark image"""
           return sendFile(self, 'images/left.gif', 'image/gif')
   
       def right_img(self):
           """mark image"""
           return sendFile(self, 'images/right.gif', 'image/gif')
   
         return urllib.urlopen(templ).read()  
           
           
     def index_html(self):      def index_html(self):
         """main action"""          """main action"""
       self.checkQuery()
       bt = self.REQUEST.SESSION['browserType']
           tp = "zogiLibMainTemplate"
           if hasattr(self, tp):
           pt = getattr(self, tp)
           else:
               tpt = self.layout
               if bt['staticHTML']:
                   tpt = "static"
   
               pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%tpt)).__of__(self)
   
         pt=PageTemplateFile('Products/zogiLib/zpt/zogiLibMain.zpt').__of__(self)  
         return pt()          return pt()
   
     def storeQuery(self):  
   
       def storeQuery(self, more = None):
         """storeQuery in session"""          """storeQuery in session"""
         self.REQUEST.SESSION['query']={}          dlParams = {}
         for fm in self.REQUEST.form.keys():          for fm in self.REQUEST.form.keys():
             self.REQUEST.SESSION['query'][fm]=self.REQUEST.form[fm]              dlParams[fm] = self.REQUEST.form[fm]
           # look for more
           if more:
               for fm in more.split('&'):
                   try:
                       pv = fm.split('=')
                       dlParams[pv[0]] = pv[1]
                   except:
                       pass
                   
           # parse digilib mode parameter
           if 'mo' in dlParams:
               if len(dlParams['mo']) > 0:
                   modes=dlParams['mo'].split(',')
           else:
               modes=[]
   
           self.REQUEST.SESSION['query'] = dlParams
           self.REQUEST.SESSION['dlModes'] = modes
           self.REQUEST.SESSION['dlInfo'] = self.getDLInfo()
           if not self.REQUEST.SESSION.has_key('browserType'):
               self.REQUEST.SESSION['browserType'] = browserCheck(self)
               
           return
   
       def checkQuery(self):
       """check if the query has been stored"""
       if not (self.REQUEST.SESSION and self.REQUEST.SESSION.has_key('query')) :
           print "ZOGILIB: have to store query!!"
           self.storeQuery()
           return
   
       def zogilibPath(self, otherbase=None):
           """returns an URL to the zogiLib instance"""
           url = self.REQUEST['URL1']
           # should end with "/"
           if len(url) > 0 and url[-1] != '/':
               url += '/'
           if type(otherbase) is str:
               url += otherbase
           else:
               url += self.basePath
           # should end with "/"
           if len(url) > 0 and url[-1] != '/':
               url += '/'
           return url
           
       def getDLParam(self, param):
           """returns parameter"""
           try:
               return self.REQUEST.SESSION['query'][param]
           except:
               return
   
     def setParam(self,pn=None,ws=None,rot=None):      def setDLParam(self, param, value):
         """gotopage"""          """sets parameter"""
           self.REQUEST.SESSION['query'][param] = value
           return
   
       def getAllDLParams(self):
           """parameter string for digilib"""
           dlParams = self.REQUEST.SESSION['query']
           # save modes
           modes = self.REQUEST.SESSION['dlModes']
           dlParams['mo'] = string.join(modes, ',')
           # assemble query string
         ret=""          ret=""
           for param in dlParams.keys():
               if dlParams[param] is None: continue
               val = str(dlParams[param])
               if val != "":
                   ret += param + "=" + val + "&"
   
           # omit trailing "&"
           return ret.rstrip('&')
   
           
       def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
           """setze Parameter"""
   
           self.setDLParam('brgt', brgt)
           self.setDLParam('cont', cont)
           self.setDLParam('ws', ws)
           self.setDLParam('rot', rot)
   
         if pn:          if pn:
             self.REQUEST.SESSION['query']['pn']=pn              # unmark
               self.setDLParam('mk', None)
               self.setDLParam('pn', pn)
               
           return self.display()
   
         if ws:  
             self.REQUEST.SESSION['query']['ws']=ws  
   
         if rot:      def display(self):
             self.REQUEST.SESSION['query']['rot']=rot          """(re)display page"""
           params = self.getAllDLParams()
           if self.basePath:
               self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
           else:
               self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
                           
         for param in self.REQUEST.SESSION['query'].keys():  
                           
             ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&"      def getDLTarget(self):
           """returns dlTarget"""
           self.checkQuery()
           s = self.dlTarget
   #         s = 'dl'
   #         if self.getDLParam('fn'):
   #             s += "_" + self.getDLParam('fn')
   #         if self.getDLParam('pn'):
   #             s += "_" + self.getDLParam('pn')
           return s
   
       def setStaticHTML(self, static=True):
           """sets the preference to static HTML"""
           self.checkQuery()
       self.REQUEST.SESSION['browserType']['staticHTML'] = static
           return
   
       def isStaticHTML(self):
           """returns if the page is using static HTML only"""
           self.checkQuery()
       return self.REQUEST.SESSION['browserType']['staticHTML']
   
       def getPT(self):
           """pagenums"""
           di = self.REQUEST.SESSION['dlInfo']
           if di:
               return int(di['pt'])
           else:
               return 1
                   
         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)      def getPN(self):
           """Pagenum"""
           pn = self.getDLParam('pn')
           try:
               return int(pn)
           except:
               return 1
   
     def mirrorPage(self,mi):      def getBiggerWS(self):
         """mirror"""          """ws+1"""
         ret=""          ws = self.getDLParam('ws')
         try:          try:
             splitted=self.REQUEST.SESSION['query']['mo'].split(',')              return float(ws)+0.5
         except:          except:
             splitted=[]              return 1.5
                   
         if mi=="h":      def getSmallerWS(self):
           """ws-1"""
           ws=self.getDLParam('ws')
           try:
               return max(float(ws)-0.5, 1)
           except:
               return 1
                                           
             if 'hmir' in splitted:      def hasMode(self, mode):
                 splitted.remove('hmir')          """returns if mode is in the diglib mo parameter"""
           return (mode in self.REQUEST.SESSION['dlModes'])
   
       def hasNextPage(self):
           """returns if there is a next page"""
           pn = self.getPN()
           pt = self.getPT()
           return (pn < pt)
      
       def hasPrevPage(self):
           """returns if there is a previous page"""
           pn = self.getPN()
           return (pn > 1)
   
       def canMoveLeft(self):
           """returns if its possible to move left"""
           wx = float(self.getDLParam('wx') or 0)
           return (wx > 0)
   
       def canMoveRight(self):
           """returns if its possible to move right"""
           wx = float(self.getDLParam('wx') or 0)
           ww = float(self.getDLParam('ww') or 1)
           return (wx + ww < 1)
   
       def canMoveUp(self):
           """returns if its possible to move up"""
           wy = float(self.getDLParam('wy') or 0)
           return (wy > 0)
   
       def canMoveDown(self):
           """returns if its possible to move down"""
           wy = float(self.getDLParam('wy') or 0)
           wh = float(self.getDLParam('wh') or 1)
           return (wy + wh < 1)
   
   
       def dl_StaticHTML(self):
           """set rendering to static HTML"""
           self.checkQuery()
           self.REQUEST.SESSION['browserType']['staticHTML'] = True
           return self.display()
   
       def dl_DynamicHTML(self):
           """set rendering to dynamic HTML"""
           self.checkQuery()
           self.REQUEST.SESSION['browserType']['staticHTML'] = False
           return self.display()
           
       def dl_HMirror(self):
           """mirror action"""
           modes = self.REQUEST.SESSION['dlModes']
           if 'hmir' in modes:
               modes.remove('hmir')
             else:              else:
                 splitted.append('hmir')              modes.append('hmir')
   
         if mi=="v":          return self.display()
   
             if 'vmir' in splitted:      def dl_VMirror(self):
                 splitted.remove('vmir')          """mirror action"""
           modes = self.REQUEST.SESSION['dlModes']
           if 'vmir' in modes:
               modes.remove('vmir')
             else:              else:
                 splitted.append('vmir')              modes.append('vmir')
   
           return self.display()
   
         self.REQUEST.SESSION['query']['mo']=string.join(splitted,",")      def dl_Zoom(self, z):
           """general zoom action"""
           ww1 = float(self.getDLParam('ww') or 1)
           wh1 = float(self.getDLParam('wh') or 1)
           wx = float(self.getDLParam('wx') or 0)
           wy = float(self.getDLParam('wy') or 0)
           ww2 = ww1 * z
           wh2 = wh1 * z
           wx += (ww1 - ww2) / 2
           wy += (wh1 - wh2) / 2
           ww2 = max(min(ww2, 1), 0)
           wh2 = max(min(wh2, 1), 0)
           wx = max(min(wx, 1), 0)
           wy = max(min(wy, 1), 0)
           self.setDLParam('ww', cropf(ww2))
           self.setDLParam('wh', cropf(wh2))
           self.setDLParam('wx', cropf(wx))
           self.setDLParam('wy', cropf(wy))
           return self.display()
           
       def dl_ZoomIn(self):
           """zoom in action"""
           z = 0.7071
           return self.dl_Zoom(z)
   
       def dl_ZoomOut(self):
           """zoom out action"""
           z = 1.4142
           return self.dl_Zoom(z)
   
       def dl_Move(self, dx, dy):
           """general move action"""
           ww = float(self.getDLParam('ww') or 1)
           wh = float(self.getDLParam('wh') or 1)
           wx = float(self.getDLParam('wx') or 0)
           wy = float(self.getDLParam('wy') or 0)
           wx += dx * 0.5 * ww
           wy += dy * 0.5 * wh
           wx = max(min(wx, 1), 0)
           wy = max(min(wy, 1), 0)
           self.setDLParam('wx', cropf(wx))
           self.setDLParam('wy', cropf(wy))
           return self.display()
           
       def dl_MoveLeft(self):
           """move left action"""
           return self.dl_Move(-1, 0)
       
       def dl_MoveRight(self):
           """move left action"""
           return self.dl_Move(1, 0)
       
       def dl_MoveUp(self):
           """move left action"""
           return self.dl_Move(0, -1)
       
       def dl_MoveDown(self):
           """move left action"""
           return self.dl_Move(0, 1)
       
       def dl_WholePage(self):
           """zoom out action"""
           self.setDLParam('ww', 1)
           self.setDLParam('wh', 1)
           self.setDLParam('wx', 0)
           self.setDLParam('wy', 0)
           return self.display()
           
       def dl_PrevPage(self):
           """next page action"""
           pn = self.getPN() - 1
           if pn < 1:
               pn = 1
           self.setDLParam('pn', pn)
           # unmark
           self.setDLParam('mk', None)
           return self.display()
           
       def dl_NextPage(self):
           """next page action"""
           pn = self.getPN() + 1
           pt = self.getPT()
           if pn > pt:
               pn = pt
           self.setDLParam('pn', pn)
           # unmark
           self.setDLParam('mk', None)
           return self.display()
   
       def dl_FirstPage(self):
           """first page action"""
           self.setDLParam('pn', 1)
           # unmark
           self.setDLParam('mk', None)
           return self.display()
       
       def dl_LastPage(self):
           """last page action"""
           self.setDLParam('pn', self.getPT())
           # unmark
           self.setDLParam('mk', None)
           return self.display()
   
       def dl_Unmark(self):
           """action to remove last mark"""
           mk = self.getDLParam('mk')
           if mk:
               marks = mk.split(',')
               marks.pop()
               mk = string.join(marks, ',')
               self.setDLParam('mk', mk)
           return self.display()
                   
                   
                   
       def changeZogiLibForm(self):
           """Main configuration"""
           pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
           return pt()
                   
         for param in self.REQUEST.SESSION['query'].keys():      def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, basePath, dlTarget, RESPONSE=None):
                       """change it"""
             ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&"          self.title=title
                   self.digilibBaseUrl=digilibBaseUrl
         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)          self.localFileBase=localFileBase
                   self.basePath = basePath
     def decode(self,strR):          self.layout=version
         """decode &"""          if dlTarget:
         print re.sub('\&amp','\&',strR)              self.dlTarget = dlTarget
         return re.sub('\&amp','\&',strR)          else:
                   self.dlTarget = "digilib"
     def wholePage(self):  
         """zoom out"""  
         ret=""  
           
         self.REQUEST.SESSION['query']['ww']=1  
         self.REQUEST.SESSION['query']['wh']=1  
         self.REQUEST.SESSION['query']['wx']=0  
         self.REQUEST.SESSION['query']['wy']=0  
                           
         for param in self.REQUEST.SESSION['query'].keys():          if RESPONSE is not None:
               RESPONSE.redirect('manage_main')
                           
             ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&"  
                   
         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)  def manage_addZogiLibForm(self):
       """interface for adding zogilib"""
       pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
       return pt()
                   
     def prevPage(self,pn=None):  def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",basePath="",dlTarget="digilib",RESPONSE=None):
         """next page"""      """add dgilib"""
         ret=""      newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version, basePath, dlTarget)
       self.Destination()._setObject(id,newObj)
       if RESPONSE is not None:
           RESPONSE.redirect('manage_main')
   
         if pn and pn>0:  
             pn=str(int(pn)-1)  
                   
   class zogiLibPageTemplate(ZopePageTemplate):
       """pageTemplate Objekt"""
       meta_type="zogiLib_pageTemplate"
   
         self.REQUEST.form['pn']=pn  
         print "hi",self.REQUEST.form.keys()  
         for param in self.REQUEST.form.keys():  
             print param  
             ret+=param+"="+str(self.REQUEST.form[param])+"&"  
                   
         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)  ## def __init__(self, id, text=None, contentType=None):
   ##         self.id = str(id)
   ##         self.ZBindings_edit(self._default_bindings)
   ##         if text is None:
   ##             text = open(self._default_cont).read()
   ##         self.pt_edit(text, contentType)
   
   def manage_addZogiLibPageTemplateForm(self):
       """Form for adding"""
       pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self)
       return pt()
           
     def nextPage(self,pn=None):  def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None,
         """next page"""                             REQUEST=None, submit=None):
         ret=""      "Add a Page Template with optional file content."
                   
       id = str(id)
       self._setObject(id, zogiLibPageTemplate(id))
       ob = getattr(self, id)
       if not layout: layout = "book"
       ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/zogiLibMain_%s.zpt'%layout)).read(),None)
       if title:
           ob.pt_setTitle(title)
         try:          try:
             pn=str(int(pn)+1)          u = self.DestinationURL()
         except:      except AttributeError:
             pn=str(2)          u = REQUEST['URL1']
   
         self.REQUEST.form['pn']=pn  
         print "hi",self.REQUEST.form.keys()  
         for param in self.REQUEST.form.keys():  
             print param  
             ret+=param+"="+str(self.REQUEST.form[param])+"&"  
           
         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)  
   
           
 def manage_addZogiLibForm(self):  
     """interface for adding zogilib"""  
     pt=PageTemplateFile('Products/zogiLib/zpt/addZogiLibForm').__of__(self)  
     return pt()  
   
 def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,RESPONSE=None):      u = "%s/%s" % (u, urllib.quote(id))
     """add dgilib"""      REQUEST.RESPONSE.redirect(u+'/manage_main')
     newObj=zogiLib(id,title,digilibBaseUrl, localFileBase)      return ''
     self.Destination()._setObject(id,newObj)  
     if RESPONSE is not None:  
         RESPONSE.redirect('manage_main')  

Removed from v.1.2  
changed lines
  Added in v.1.31


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