File:  [Repository] / zogiLib / zogiLib.py
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Tue Mar 30 13:56:24 2004 UTC (20 years, 3 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
class digiimage addedCVS: ----------------------------------------------------------------------

    1: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
    2: from Products.PageTemplates.PageTemplate import PageTemplate
    3: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
    4: from OFS.Image import Image
    5: from webdav.common import rfc1123_date
    6: 
    7: import xml.dom.minidom
    8: from OFS.Folder import Folder
    9: from xml_helpers import getText
   10: import os
   11: import re
   12: import string
   13: import urllib
   14: from Globals import package_home
   15: 
   16: def getString(self,key,default=''):
   17:     try:
   18:         return self.REQUEST[key]
   19:     except:
   20:         return default
   21: 
   22:     
   23: class zogiLib_navTemplate(ZopePageTemplate):
   24:     """pageTemplate Objekt"""
   25:     meta_type="zogiLib_navTemplate"
   26: 
   27:     _default_content_fn = os.path.join(package_home(globals()),
   28:                                        'zpt/zogiLib_NavTemplateDefault.zpt')
   29: 
   30:     manage_options=ZopePageTemplate.manage_options+(
   31:         {'label':'Copy to Filesystem','action':'copyContent'},
   32:        )
   33: 
   34:     def getPath(self):
   35:         """get path"""
   36:         return getPath(self,'thumbtemplate.templ')
   37:     
   38:     ## def changeECHO_pageTemplateWeightForm(self):
   39: ##         """change"""
   40: ##         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_pageTemplateWeight.zpt').__of__(self)
   41: ##         return pt()
   42: 
   43: ##     def changeECHO_pageTemplateWeight(self,weight,content_type,RESPONSE=None):
   44: ##         """change"""
   45: ##         self.weight=weight
   46: ##         self.content_type=content_type
   47: 
   48: ##         if RESPONSE is not None:
   49: ##             RESPONSE.redirect('manage_main')
   50:         
   51: 
   52:     def copyContent(self):
   53:         """copycontent to path"""
   54: 
   55:         return "copied to:"+copyContent(self,'thumbtemplate.templ')
   56:         
   57:     
   58: def manage_addZogiLib_NavTemplateForm(self):
   59:     """Form for adding"""
   60:     pt=PageTemplateFile('Products/zogiLib/zpt/AddZogilib_NavTemplate.zpt').__of__(self)
   61:     return pt()
   62: 
   63: 
   64: 
   65: 
   66: def manage_addZogiLib_NavTemplate(self, id,title=None, text=None,
   67:                            REQUEST=None, submit=None):
   68:     "Add a Page Template with optional file content."
   69: 
   70:     
   71:     id = str(id)
   72:     if REQUEST is None:
   73:         self._setObject(id, zogilib_NavTemplate(id, text))
   74:         ob = getattr(self, id)
   75:        
   76:         if title:
   77:             ob.pt_setTitle(title)
   78:         return ob
   79:     else:
   80:         file = REQUEST.form.get('file')
   81:         headers = getattr(file, 'headers', None)
   82:         if headers is None or not file.filename:
   83:             zpt = zogilib_NavTemplate(id)
   84:         else:
   85:             zpt = zogilib_NavTemplate(id, file, headers.get('content_type'))
   86: 
   87:         self._setObject(id, zpt)
   88:         ob = getattr(self, id)
   89: 
   90: 
   91:         try:
   92:             u = self.DestinationURL()
   93:         except AttributeError:
   94:             u = REQUEST['URL1']
   95: 
   96:         if submit == " Add and Edit ":
   97:             u = "%s/%s" % (u, quote(id))
   98:         REQUEST.RESPONSE.redirect(u+'/manage_main')
   99:     return ''
  100: 
  101: 
  102:         
  103: def readNavTemp(fileName):
  104:     """navtemp"""
  105:     
  106:     
  107:     if os.path.exists(fileName+"/index.meta"):
  108:         dom=xml.dom.minidom.parse(fileName+"/index.meta")
  109:     else:
  110:         return None
  111:     
  112:     
  113:     try:
  114:         navTag=getText(dom.getElementsByTagName('zogilibtemplate')[0].childNodes)
  115:     except:
  116:         navTag=None
  117:     return navTag
  118:     
  119: class zogiImage(Image):
  120:     """einzelnes Image"""
  121:     meta_type="zogiImage"
  122: 
  123:     
  124:     
  125:     def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''):
  126:         """init"""
  127:         self.id=id
  128:         self.title=title
  129:         self.baseUrl=baseUrl
  130:         self.queryString=queryString
  131:         self.content_type=content_type
  132:         self.precondition=precondition
  133: 
  134:     def getData(self):
  135:         """getUrlData"""
  136:         return urllib.urlopen(self.baseUrl+self.queryString)
  137: 
  138:     def changeZogiImageForm(self):
  139:         """Main configuration"""
  140:         pt=PageTemplateFile('Products/zogiLib/zpt/changeZogiImageForm.zpt').__of__(self)
  141:         return pt()
  142:     
  143:     def changeZogiImage(self,title,baseUrl, queryString,RESPONSE=None):
  144:         """change it"""
  145:         self.title=title
  146:         self.baseUrl=baseUrl
  147:         self.queryString=queryString
  148: 
  149:         if RESPONSE is not None:
  150:             RESPONSE.redirect('manage_main')
  151: 
  152: 
  153:     manage_options=ZopePageTemplate.manage_options+(
  154:         {'label':'Main config','action':'changeZogiImageForm'},
  155:        )
  156: 
  157:     
  158: 
  159:         
  160:     def index_html(self, REQUEST, RESPONSE):
  161:         """
  162:         Modified version of OFS/Image.py
  163:         
  164:         The default view of the contents of a File or Image.
  165: 
  166:         Returns the contents of the file or image.  Also, sets the
  167:         Content-Type HTTP header to the objects content type.
  168:         """
  169: 
  170:         # HTTP If-Modified-Since header handling.
  171:         header=REQUEST.get_header('If-Modified-Since', None)
  172:         if header is not None:
  173:             header=header.split( ';')[0]
  174:             # Some proxies seem to send invalid date strings for this
  175:             # header. If the date string is not valid, we ignore it
  176:             # rather than raise an error to be generally consistent
  177:             # with common servers such as Apache (which can usually
  178:             # understand the screwy date string as a lucky side effect
  179:             # of the way they parse it).
  180:             # This happens to be what RFC2616 tells us to do in the face of an
  181:             # invalid date.
  182:             try:    mod_since=long(DateTime(header).timeTime())
  183:             except: mod_since=None
  184:             if mod_since is not None:
  185:                 if self._p_mtime:
  186:                     last_mod = long(self._p_mtime)
  187:                 else:
  188:                     last_mod = long(0)
  189:                 if last_mod > 0 and last_mod <= mod_since:
  190:                     # Set header values since apache caching will return Content-Length
  191:                     # of 0 in response if size is not set here
  192:                     RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
  193:                     RESPONSE.setHeader('Content-Type', self.content_type)
  194:                     RESPONSE.setHeader('Content-Length', self.size)
  195:                     RESPONSE.setHeader('Accept-Ranges', 'bytes')
  196:                     self.ZCacheable_set(None)
  197:                     RESPONSE.setStatus(304)
  198:                     return ''
  199: 
  200:         if self.precondition and hasattr(self,self.precondition):
  201:             # Grab whatever precondition was defined and then
  202:             # execute it.  The precondition will raise an exception
  203:             # if something violates its terms.
  204:             c=getattr(self,self.precondition)
  205:             if hasattr(c,'isDocTemp') and c.isDocTemp:
  206:                 c(REQUEST['PARENTS'][1],REQUEST)
  207:             else:
  208:                 c()
  209: 
  210:         # HTTP Range header handling
  211:         range = REQUEST.get_header('Range', None)
  212:         request_range = REQUEST.get_header('Request-Range', None)
  213:         if request_range is not None:
  214:             # Netscape 2 through 4 and MSIE 3 implement a draft version
  215:             # Later on, we need to serve a different mime-type as well.
  216:             range = request_range
  217:         if_range = REQUEST.get_header('If-Range', None)
  218:         if range is not None:
  219:             ranges = HTTPRangeSupport.parseRange(range)
  220: 
  221:             if if_range is not None:
  222:                 # Only send ranges if the data isn't modified, otherwise send
  223:                 # the whole object. Support both ETags and Last-Modified dates!
  224:                 if len(if_range) > 1 and if_range[:2] == 'ts':
  225:                     # ETag:
  226:                     if if_range != self.http__etag():
  227:                         # Modified, so send a normal response. We delete
  228:                         # the ranges, which causes us to skip to the 200
  229:                         # response.
  230:                         ranges = None
  231:                 else:
  232:                     # Date
  233:                     date = if_range.split( ';')[0]
  234:                     try: mod_since=long(DateTime(date).timeTime())
  235:                     except: mod_since=None
  236:                     if mod_since is not None:
  237:                         if self._p_mtime:
  238:                             last_mod = long(self._p_mtime)
  239:                         else:
  240:                             last_mod = long(0)
  241:                         if last_mod > mod_since:
  242:                             # Modified, so send a normal response. We delete
  243:                             # the ranges, which causes us to skip to the 200
  244:                             # response.
  245:                             ranges = None
  246: 
  247:             if ranges:
  248:                 # Search for satisfiable ranges.
  249:                 satisfiable = 0
  250:                 for start, end in ranges:
  251:                     if start < self.size:
  252:                         satisfiable = 1
  253:                         break
  254: 
  255:                 if not satisfiable:
  256:                     RESPONSE.setHeader('Content-Range',
  257:                         'bytes */%d' % self.size)
  258:                     RESPONSE.setHeader('Accept-Ranges', 'bytes')
  259:                     RESPONSE.setHeader('Last-Modified',
  260:                         rfc1123_date(self._p_mtime))
  261:                     RESPONSE.setHeader('Content-Type', self.content_type)
  262:                     RESPONSE.setHeader('Content-Length', self.size)
  263:                     RESPONSE.setStatus(416)
  264:                     return ''
  265: 
  266:                 ranges = HTTPRangeSupport.expandRanges(ranges, self.size)
  267:                                 
  268:                 if len(ranges) == 1:
  269:                     # Easy case, set extra header and return partial set.
  270:                     start, end = ranges[0]
  271:                     size = end - start
  272: 
  273:                     RESPONSE.setHeader('Last-Modified',
  274:                         rfc1123_date(self._p_mtime))
  275:                     RESPONSE.setHeader('Content-Type', self.content_type)
  276:                     RESPONSE.setHeader('Content-Length', size)
  277:                     RESPONSE.setHeader('Accept-Ranges', 'bytes')
  278:                     RESPONSE.setHeader('Content-Range',
  279:                         'bytes %d-%d/%d' % (start, end - 1, self.size))
  280:                     RESPONSE.setStatus(206) # Partial content
  281: 
  282:                     data = urllib.urlopen(self.baseUrl+self.queryString).read()
  283:                     if type(data) is StringType:
  284:                         return data[start:end]
  285: 
  286:                     # Linked Pdata objects. Urgh.
  287:                     pos = 0
  288:                     while data is not None:
  289:                         l = len(data.data)
  290:                         pos = pos + l
  291:                         if pos > start:
  292:                             # We are within the range
  293:                             lstart = l - (pos - start)
  294: 
  295:                             if lstart < 0: lstart = 0
  296: 
  297:                             # find the endpoint
  298:                             if end <= pos:
  299:                                 lend = l - (pos - end)
  300: 
  301:                                 # Send and end transmission
  302:                                 RESPONSE.write(data[lstart:lend])
  303:                                 break
  304: 
  305:                             # Not yet at the end, transmit what we have.
  306:                             RESPONSE.write(data[lstart:])
  307: 
  308:                         data = data.next
  309: 
  310:                     return ''
  311: 
  312:                 else:
  313:                     boundary = choose_boundary()
  314: 
  315:                     # Calculate the content length
  316:                     size = (8 + len(boundary) + # End marker length
  317:                         len(ranges) * (         # Constant lenght per set
  318:                             49 + len(boundary) + len(self.content_type) +
  319:                             len('%d' % self.size)))
  320:                     for start, end in ranges:
  321:                         # Variable length per set
  322:                         size = (size + len('%d%d' % (start, end - 1)) +
  323:                             end - start)
  324: 
  325: 
  326:                     # Some clients implement an earlier draft of the spec, they
  327:                     # will only accept x-byteranges.
  328:                     draftprefix = (request_range is not None) and 'x-' or ''
  329: 
  330:                     RESPONSE.setHeader('Content-Length', size)
  331:                     RESPONSE.setHeader('Accept-Ranges', 'bytes')
  332:                     RESPONSE.setHeader('Last-Modified',
  333:                         rfc1123_date(self._p_mtime))
  334:                     RESPONSE.setHeader('Content-Type',
  335:                         'multipart/%sbyteranges; boundary=%s' % (
  336:                             draftprefix, boundary))
  337:                     RESPONSE.setStatus(206) # Partial content
  338: 
  339:                     data = urllib.urlopen(self.baseUrl+self.queryString).read()
  340:                     # The Pdata map allows us to jump into the Pdata chain
  341:                     # arbitrarily during out-of-order range searching.
  342:                     pdata_map = {}
  343:                     pdata_map[0] = data
  344: 
  345:                     for start, end in ranges:
  346:                         RESPONSE.write('\r\n--%s\r\n' % boundary)
  347:                         RESPONSE.write('Content-Type: %s\r\n' %
  348:                             self.content_type)
  349:                         RESPONSE.write(
  350:                             'Content-Range: bytes %d-%d/%d\r\n\r\n' % (
  351:                                 start, end - 1, self.size))
  352: 
  353:                         if type(data) is StringType:
  354:                             RESPONSE.write(data[start:end])
  355: 
  356:                         else:
  357:                             # Yippee. Linked Pdata objects. The following
  358:                             # calculations allow us to fast-forward through the
  359:                             # Pdata chain without a lot of dereferencing if we
  360:                             # did the work already.
  361:                             first_size = len(pdata_map[0].data)
  362:                             if start < first_size:
  363:                                 closest_pos = 0
  364:                             else:
  365:                                 closest_pos = (
  366:                                     ((start - first_size) >> 16 << 16) +
  367:                                     first_size)
  368:                             pos = min(closest_pos, max(pdata_map.keys()))
  369:                             data = pdata_map[pos]
  370: 
  371:                             while data is not None:
  372:                                 l = len(data.data)
  373:                                 pos = pos + l
  374:                                 if pos > start:
  375:                                     # We are within the range
  376:                                     lstart = l - (pos - start)
  377: 
  378:                                     if lstart < 0: lstart = 0
  379: 
  380:                                     # find the endpoint
  381:                                     if end <= pos:
  382:                                         lend = l - (pos - end)
  383: 
  384:                                         # Send and loop to next range
  385:                                         RESPONSE.write(data[lstart:lend])
  386:                                         break
  387: 
  388:                                     # Not yet at the end, transmit what we have.
  389:                                     RESPONSE.write(data[lstart:])
  390: 
  391:                                 data = data.next
  392:                                 # Store a reference to a Pdata chain link so we
  393:                                 # don't have to deref during this request again.
  394:                                 pdata_map[pos] = data
  395: 
  396:                     # Do not keep the link references around.
  397:                     del pdata_map
  398: 
  399:                     RESPONSE.write('\r\n--%s--\r\n' % boundary)
  400:                     return ''
  401: 
  402:         RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
  403:         RESPONSE.setHeader('Content-Type', self.content_type)
  404:         RESPONSE.setHeader('Content-Length', self.size)
  405:         RESPONSE.setHeader('Accept-Ranges', 'bytes')
  406: 
  407:         # Don't cache the data itself, but provide an opportunity
  408:         # for a cache manager to set response headers.
  409:         self.ZCacheable_set(None)
  410: 
  411:         data=urllib.urlopen(self.baseUrl+self.queryString).read()
  412:         
  413:         if type(data) is type(''): 
  414:             RESPONSE.setBase(None)
  415:             return data
  416: 
  417:         while data is not None:
  418:             RESPONSE.write(data.data)
  419:             data=data.next
  420: 
  421:         return ''
  422: 
  423: 
  424: def manage_addZogiImageForm(self):
  425:     """Form for adding"""
  426:     pt=PageTemplateFile('Products/zogiLib/zpt/addZogiImage.zpt').__of__(self)
  427:     return pt()
  428: 
  429: 
  430: def manage_addZogiImage(self,id,title,baseUrl, queryString,RESPONSE=None):
  431:     """add dgilib"""
  432:     newObj=zogiImage(id,title,baseUrl, queryString)
  433:     self.Destination()._setObject(id,newObj)
  434:     if RESPONSE is not None:
  435:         RESPONSE.redirect('manage_main')
  436: 
  437: 
  438: 
  439: class zogiLib(Folder):
  440:     """StandardElement"""
  441: 
  442:     meta_type="zogiLib"
  443: 
  444:     def getDlInfo(self):
  445:         """DLInfo"""
  446:         paramH={}
  447:         baseUrl=re.sub("servlet/Scaler","/dlInfo-xml.jsp",self.digilibBaseUrl)
  448:         
  449:         url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING'])
  450:         dom=xml.dom.minidom.parse(url)
  451:         params=dom.getElementsByTagName('parameter')
  452:         for param in params:
  453:             paramH[param.getAttribute('name')]=param.getAttribute('value')
  454:         return paramH
  455: 
  456:     def getPageNumTotal(self):
  457:         """pagenums"""
  458:         return self.getDlInfo()['pt']
  459:     
  460:     
  461:     def generateImageFolder(self):
  462:         """images ablegen"""
  463:         self.manage_addFolder('images')
  464:         for image in os.listdir("../lib/python/Products/zogiLib/images"):
  465:             fn=file("../lib/python/Products/zogiLib/images/"+image)
  466:             
  467:             self.images.manage_addImage(image,fn)
  468:         
  469: 
  470:     def __init__(self, id,title,digilibBaseUrl, localFileBase):
  471:         """init"""
  472: 
  473:         self.id=id
  474:         self.title=title
  475:         self.digilibBaseUrl=digilibBaseUrl
  476:         self.localFileBase=localFileBase
  477:         self._setObject('topTemplate',zogiLib_navTemplate(id='topTemplate'))
  478:         self.generateImageFolder()
  479: 
  480: 
  481:     manage_options = Folder.manage_options+(
  482:             {'label':'Main Config','action':'changeZogiLibForm'},
  483:             )
  484: 
  485:     def option_js(self):
  486:         """option_js"""
  487:         ret="""function setParam(e) {
  488:         if (document.all) s=e.srcElement;
  489: 	                else s=e.target;
  490:                         if (window.opener) location=window.opener.location
  491:                         else location=document.location
  492:                         location=" %s/setParam?"+s.name+'='+s.value;
  493:                         }"""%self.REQUEST['URL1']
  494:         return ret
  495:                         
  496:                         
  497:     def navigation_js(self):
  498:         """Javascript"""
  499:         
  500:         return file("../lib/python/Products/zogiLib/js/navigation.js").read()
  501: 
  502: 
  503:             
  504:     def generateTopJavaScript(self):
  505:         """generate script"""
  506:         ret="""var baseUrl = '%s'; """% self.REQUEST['URL0']
  507:         ret+="""newParameter('fn', '%s', '', 1);
  508:                 newParameter('pn', '%s', '1', 1);
  509:                 newParameter('ws', '%s', '1.0', 1);
  510:                 newParameter('mo', '%s', '', 1);
  511:                 newParameter('mk', '%s', '', 3);
  512:                 newParameter('wx', '%s', '0.0', 2);
  513:                 newParameter('wy', '%s', '0.0', 2);
  514:                 newParameter('ww', '%s', '1.0', 2);
  515:                 newParameter('wh', '%s', '1.0', 2);
  516:                 newParameter('pt', '%s', '%s', 9);
  517:                 newParameter('brgt', '%s', '0.0', 1);
  518:                 newParameter('cont', '%s', '0.0', 1);
  519:                 newParameter('rot', '%s', '0.0', 1);
  520:                 newParameter('rgba', '%s', '', 1);
  521:                 newParameter('rgbm', '%s', '', 1);
  522:                 newParameter('ddpix', '%s', '', 9);
  523:                 newParameter('ddpiy', '%s', '', 9);"""%(getString(self,'fn'),
  524:                  getString(self,'pn',1),
  525:                  getString(self,'ws',1.0),
  526:                  getString(self,'mo',''),
  527:                  getString(self,'mk',''),
  528:                  getString(self,'wx',0.0),
  529:                  getString(self,'wy',0.0),
  530:                  getString(self,'ww',1.0),
  531:                  getString(self,'wh',1.0),
  532:                  getString(self,'pt',100),getString(self,'pt',100),
  533:                  getString(self,'brgt',0.0),
  534:                  getString(self,'cont',0.0),
  535:                  getString(self,'rot',0.0),
  536:                  getString(self,'rgba','0/0/0'),
  537:                  getString(self,'rgbm','0/0/0'),
  538:                  getString(self,'ddpix',0.0),
  539:                  getString(self,'ddpiy',0.0)
  540:                  )
  541: 
  542:         ret+="""
  543: 
  544:         var wwidth, wheight;
  545:         if (self.innerHeight) // all except Explorer
  546:         {
  547:         wwidth = self.innerWidth;
  548:         wheight = self.innerHeight;
  549:         }
  550:         else if (document.documentElement && document.documentElement.clientHeight)
  551:         // Explorer 6 Strict Mode
  552:         {
  553:         wwidth = document.documentElement.clientWidth;
  554:         wheight = document.documentElement.clientHeight;
  555:         }
  556:         else if (document.body) // other Explorers
  557:         {
  558:         wwidth = document.body.clientWidth;
  559:         wheight = document.body.clientHeight;
  560:         }
  561: 
  562:         document.id="digilib"
  563:         
  564:         """
  565:         return ret
  566: 
  567: 
  568:     
  569:                 
  570:                 
  571:         
  572:         
  573:     def generateScalerImg(self,requestString):
  574:         """generate Scaler Tag"""
  575:         retStr=self.digilibBaseUrl+requestString
  576:         jS="""<script type="text/javascript">
  577:         document.write("<img id=\\\"pic\\\" src=\\\"%s&dw="+wwidth+"&dh="+wheight+"\\\"/>")</script>"""%retStr
  578:         return jS
  579: 
  580:     def changeZogiLibForm(self):
  581:         """Main configuration"""
  582:         pt=PageTemplateFile('Products/zogiLib/zpt/changeZogiLibForm.zpt').__of__(self)
  583:         return pt()
  584:     
  585:     def changeZogiLib(self,title,digilibBaseUrl, localFileBase,RESPONSE=None):
  586:         """change it"""
  587:         self.title=title
  588:         self.digilibBaseUrl=digilibBaseUrl
  589:         self.localFileBase=localFileBase
  590: 
  591:         if RESPONSE is not None:
  592:             RESPONSE.redirect('manage_main')
  593: 
  594:             
  595:     def nav_html(self,fileName):
  596:         """navigations frame"""
  597: 
  598:         # suche nach index.meta mit zogilib thumb info
  599:         
  600:         templ=readNavTemp(self.localFileBase+"/"+fileName)
  601:         if not templ:
  602:             templ=readNavTemp(self.localFileBase+"/"+fileName.split("/")[0])
  603:             if not templ:
  604:                 return self.topTemplate.document_src()
  605: 
  606:         return urllib.urlopen(templ).read()
  607:     
  608:     
  609:     def index_html(self):
  610:         """main action"""
  611: 
  612: 
  613:         pt=PageTemplateFile('Products/zogiLib/zpt/zogiLibMain_book.zpt').__of__(self)
  614:         return pt()
  615: 
  616:     def storeQuery(self):
  617:         """storeQuery in session"""
  618:         self.REQUEST.SESSION['query']={}
  619:         for fm in self.REQUEST.form.keys():
  620:             self.REQUEST.SESSION['query'][fm]=self.REQUEST.form[fm]
  621: 
  622:         self.REQUEST.SESSION['dlInfo']=self.getDlInfo()
  623:         
  624:     def getParam(self,param):
  625:         """Gebe Parameter aus"""
  626:         try:
  627:             return self.REQUEST.SESSION['query'][param]
  628:         except:
  629:             return None
  630: 
  631:     def getPageNum(self):
  632:         """PAgenum"""
  633:         pn=self.getParam('pn')
  634:         if pn:
  635:             return pn
  636:         else:
  637:             return 1
  638: 
  639:     def biggerWS(self):
  640:         """ws+1"""
  641:         ws=self.getParam('ws')
  642:         if ws:
  643:             return int(ws)+1
  644:         else:
  645:             return 2
  646: 
  647:     def options(self):
  648:         """showoptions"""
  649:         pt=PageTemplateFile('Products/zogiLib/zpt/optionwindow.zpt').__of__(self)
  650:         return pt()
  651: 
  652:         
  653:     def smallerWS(self):
  654:         """ws-11"""
  655:         ws=self.getParam('ws')
  656:         if ws:
  657:             if int(ws)==1:
  658:                 return
  659:             else:
  660:                 return int(ws)-1
  661:         else:
  662:             return 1
  663:         
  664:         
  665:     def setParam(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
  666:         """setze Parameter"""
  667:         ret=""
  668: 
  669:         if brgt:
  670:             self.REQUEST.SESSION['query']['brgt']=brgt
  671: 
  672:         if cont:
  673:             self.REQUEST.SESSION['query']['cont']=cont
  674: 
  675:         if pn:
  676:             self.REQUEST.SESSION['query']['pn']=pn
  677: 
  678:         if ws:
  679:             self.REQUEST.SESSION['query']['ws']=ws
  680: 
  681:         if rot:
  682:             self.REQUEST.SESSION['query']['rot']=rot
  683:             
  684:         for param in self.REQUEST.SESSION['query'].keys():
  685:             
  686:             ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&"
  687:         
  688:         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
  689: 
  690:    
  691:     def mirrorPage(self,mi):
  692:         """mirror"""
  693:         ret=""
  694:         try:
  695:             splitted=self.REQUEST.SESSION['query']['mo'].split(',')
  696:         except:
  697:             splitted=[]
  698:         
  699:         if mi=="h":
  700:                     
  701:             if 'hmir' in splitted:
  702:                 splitted.remove('hmir')
  703:             else:
  704:                 splitted.append('hmir')
  705: 
  706:         if mi=="v":
  707: 
  708:             if 'vmir' in splitted:
  709:                 splitted.remove('vmir')
  710:             else:
  711:                 splitted.append('vmir')
  712: 
  713: 
  714:         self.REQUEST.SESSION['query']['mo']=string.join(splitted,",")
  715:         
  716:         
  717:         
  718:         
  719:         for param in self.REQUEST.SESSION['query'].keys():
  720:             
  721:             ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&"
  722:         
  723:         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
  724:         
  725:     def decode(self,strR):
  726:         """decode &"""
  727:         
  728:         return re.sub('\&amp','\&',strR)
  729:     
  730:     def wholePage(self):
  731:         """zoom out"""
  732:         ret=""
  733:         
  734:         self.REQUEST.SESSION['query']['ww']=1
  735:         self.REQUEST.SESSION['query']['wh']=1
  736:         self.REQUEST.SESSION['query']['wx']=0
  737:         self.REQUEST.SESSION['query']['wy']=0
  738:             
  739:         for param in self.REQUEST.SESSION['query'].keys():
  740:             
  741:             ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&"
  742:         
  743:         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
  744:         
  745:     def prevPage(self,pn=None):
  746:         """next page"""
  747:         ret=""
  748: 
  749:         if pn and pn>0:
  750:             pn=str(int(pn)-1)
  751:         
  752: 
  753:         self.REQUEST.form['pn']=pn
  754:         
  755:         for param in self.REQUEST.form.keys():
  756:             
  757:             ret+=param+"="+str(self.REQUEST.form[param])+"&"
  758:         
  759:         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
  760: 
  761:     def firstPage(self):
  762:         """erste Seite"""
  763:         return self.setParam(pn="1")
  764:     
  765:     def lastPage(self):
  766:         """letzte Seite"""
  767: 
  768:         
  769:     def nextPage(self,pn=None):
  770:         """next page"""
  771:         ret=""
  772:         
  773:         try:
  774:             pn=str(int(pn)+1)
  775:         except:
  776:             pn=str(2)
  777: 
  778:         self.REQUEST.form['pn']=pn
  779:         
  780:         for param in self.REQUEST.form.keys():
  781:             ret+=param+"="+str(self.REQUEST.form[param])+"&"
  782:         
  783:         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
  784: 
  785:         
  786: def manage_addZogiLibForm(self):
  787:     """interface for adding zogilib"""
  788:     pt=PageTemplateFile('Products/zogiLib/zpt/addZogiLibForm').__of__(self)
  789:     return pt()
  790: 
  791: def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,RESPONSE=None):
  792:     """add dgilib"""
  793:     newObj=zogiLib(id,title,digilibBaseUrl, localFileBase)
  794:     self.Destination()._setObject(id,newObj)
  795:     if RESPONSE is not None:
  796:         RESPONSE.redirect('manage_main')

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