|
|
| version 1.26, 2004/06/07 17:56:55 | version 1.70, 2008/11/20 10:44:24 |
|---|---|
| Line 1 | Line 1 |
| from AccessControl import ClassSecurityInfo | |
| from Products.PageTemplates.PageTemplateFile import PageTemplateFile | from Globals import package_home |
| from OFS.Folder import Folder | |
| from OFS.Image import Image | |
| from OFS.Image import File | |
| from OFS.SimpleItem import SimpleItem | |
| from Products.PageTemplates.PageTemplate import PageTemplate | from Products.PageTemplates.PageTemplate import PageTemplate |
| from Products.PageTemplates.PageTemplateFile import PageTemplateFile | |
| from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate | from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
| from OFS.Image import Image | from types import * |
| from webdav.common import rfc1123_date | from Globals import package_home, ImageFile |
| from xml_helpers import getUniqueElementText,getText | |
| import xml.dom.minidom | import cgi |
| from OFS.Folder import Folder | |
| from xml_helpers import getText | |
| import os | import os |
| import random | |
| import re | import re |
| import string | import string |
| import urllib | import urllib |
| import types | import xml.dom.minidom |
| from Globals import package_home | |
| ZOGIVERSION = "0.10.4b ROC 13.11.2006" | |
| def cropf(f): | |
| """returns a float with reduced precision""" | |
| return float(int(f * 10000)/10000.0) | |
| def sendFile(self, filename, type): | |
| """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): | def browserCheck(self): |
| """check the browsers request to find out the browser type""" | """check the browsers request to find out the browser type""" |
| bt = {} | bt = {} |
| ua = self.REQUEST.get_header("HTTP_USER_AGENT") | ua = self.REQUEST.get_header("HTTP_USER_AGENT") |
| bt['ua'] = ua | bt['ua'] = ua |
| bt['isIE'] = string.find(ua, 'MSIE') > -1 | bt['isIE'] = False |
| bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) and not bt['isIE'] | bt['isN4'] = False |
| if string.find(ua, 'MSIE') > -1: | |
| bt['isIE'] = True | |
| else: | |
| bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) | |
| try: | |
| nav = ua[string.find(ua, '('):] | nav = ua[string.find(ua, '('):] |
| ie = string.split(nav, "; ")[1] | ie = string.split(nav, "; ")[1] |
| if string.find(ie, "MSIE") > -1: | if string.find(ie, "MSIE") > -1: |
| bt['versIE'] = string.split(ie, " ")[1] | bt['versIE'] = string.split(ie, " ")[1] |
| except: pass | |
| bt['isMac'] = string.find(ua, 'Macintosh') > -1 | bt['isMac'] = string.find(ua, 'Macintosh') > -1 |
| bt['isWin'] = string.find(ua, 'Windows') > -1 | bt['isWin'] = string.find(ua, 'Windows') > -1 |
| bt['isIEWin'] = bt['isIE'] and bt['isWin'] | bt['isIEWin'] = bt['isIE'] and bt['isWin'] |
| Line 55 def browserCheck(self): | Line 52 def browserCheck(self): |
| return bt | return bt |
| def manage_addZogiLibMainTemplateForm(self): | |
| """Form for adding""" | |
| #FIXME:??? | |
| pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/AddOSAS_thumbTemplate.zpt')).__of__(self) | |
| return pt() | |
| def manage_addZogiLibMainTemplate(self, id,title=None, text=None, | class zogiImage(SimpleItem): |
| REQUEST=None, submit=None): | |
| "Add a Page Template with optional file content." | |
| #FIXME:??? | |
| id = str(id) | |
| if REQUEST is None: | |
| self._setObject(id, zogiLib_mainTemplate(id, text)) | |
| ob = getattr(self, id) | |
| if title: | |
| ob.pt_setTitle(title) | |
| return ob | |
| else: | |
| file = REQUEST.form.get('file') | |
| headers = getattr(file, 'headers', None) | |
| if headers is None or not file.filename: | |
| zpt = zogiLib_mainTemplate(id) | |
| else: | |
| zpt = zogiLib_mainTemplate(id, file, headers.get('content_type')) | |
| self._setObject(id, zpt) | |
| ob = getattr(self, id) | |
| try: | |
| u = self.DestinationURL() | |
| except AttributeError: | |
| u = REQUEST['URL1'] | |
| if submit == " Add and Edit ": | |
| u = "%s/%s" % (u, quote(id)) | |
| REQUEST.RESPONSE.redirect(u+'/manage_main') | |
| return '' | |
| class zogiImage(Image): | |
| """einzelnes Image""" | """einzelnes Image""" |
| meta_type="zogiImage" | meta_type="zogiImage" |
| manage_options=ZopePageTemplate.manage_options+( | manage_options=( |
| {'label':'Main config','action':'changeZogiImageForm'}, | {'label':'Main config','action':'changeZogiImageForm'}, |
| ) | )+SimpleItem.manage_options |
| def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''): | def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''): |
| """init""" | """init""" |
| self.id=id | self.id=id |
| self.title=title | self.title=title |
| if baseUrl: | |
| self.baseUrl=baseUrl | self.baseUrl=baseUrl |
| else: | |
| self.baseUrl="http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?" | |
| self.queryString=queryString | self.queryString=queryString |
| self.content_type=content_type | self.content_type=content_type |
| self.precondition=precondition | self.precondition=precondition |
| def getData(self): | #def getData(self): |
| """getUrlData""" | # """getUrlData""" |
| return urllib.urlopen(self.baseUrl+self.queryString) | # return urllib.urlopen(self.baseUrl+self.queryString) |
| def changeZogiImageForm(self): | |
| """Main configuration""" | |
| pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiImageForm.zpt')).__of__(self) | |
| return pt() | |
| def changeZogiImage(self,title,baseUrl, queryString,RESPONSE=None): | |
| """change it""" | |
| self.title=title | |
| self.baseUrl=baseUrl | |
| self.queryString=queryString | |
| if RESPONSE is not None: | |
| RESPONSE.redirect('manage_main') | |
| changeZogiImageForm = PageTemplateFile('zpt/changeZogiImageForm.zpt', globals()) | |
| def index_html(self, REQUEST, RESPONSE): | def index_html(self, REQUEST, RESPONSE): |
| """ | """service the request by redirecting to digilib server""" |
| Modified version of OFS/Image.py | # use status 307 = moved temporarily |
| RESPONSE.redirect(self.baseUrl+self.queryString, status=307) | |
| 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. | |
| """ | |
| # HTTP If-Modified-Since header handling. | |
| header=REQUEST.get_header('If-Modified-Since', None) | |
| if header is not None: | |
| 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) | |
| if len(ranges) == 1: | |
| # Easy case, set extra header and return partial set. | |
| 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:]) | |
| data = data.next | |
| return '' | return '' |
| else: | |
| boundary = choose_boundary() | |
| # Calculate the content length | def rescale(self,width=None,height=None): |
| size = (8 + len(boundary) + # End marker length | """andere parameter im querystring""" |
| len(ranges) * ( # Constant lenght per set | qs=cgi.parse_qs(self.queryString) |
| 49 + len(boundary) + len(self.content_type) + | for x in qs.keys(): |
| len('%d' % self.size))) | if type(qs[x]) is ListType: |
| for start, end in ranges: | qs[x]=qs[x][0] |
| # Variable length per set | |
| size = (size + len('%d%d' % (start, end - 1)) + | if width: |
| end - start) | qs['dw']=width |
| if height: | |
| qs['dh']=height | |
| # Some clients implement an earlier draft of the spec, they | |
| # will only accept x-byteranges. | qsneu=urllib.urlencode(qs) |
| draftprefix = (request_range is not None) and 'x-' or '' | self.queryString=qsneu |
| return "done" | |
| RESPONSE.setHeader('Content-Length', size) | |
| RESPONSE.setHeader('Accept-Ranges', 'bytes') | |
| RESPONSE.setHeader('Last-Modified', | def setWithDigilibURL(self,digilibUrl): |
| rfc1123_date(self._p_mtime)) | """take all parameters from digilib URL string""" |
| RESPONSE.setHeader('Content-Type', | base = re.match('(.*?/Scaler\?)(.*)', digilibUrl) |
| 'multipart/%sbyteranges; boundary=%s' % ( | if base is not None: |
| draftprefix, boundary)) | params = base.group(2).split('&') |
| RESPONSE.setStatus(206) # Partial content | newparams = [] |
| # filter out the parameters we want | |
| data = urllib.urlopen(self.baseUrl+self.queryString).read() | for p in params: |
| # The Pdata map allows us to jump into the Pdata chain | (key, val) = p.split('=') |
| # arbitrarily during out-of-order range searching. | if key in ['fn','pn','dw','dh','ww','wh','wx','wy','mo']: |
| pdata_map = {} | newparams.append(p) |
| pdata_map[0] = data | # set the new parameters |
| if len(newparams) > 1: | |
| for start, end in ranges: | self.baseUrl = base.group(1) |
| RESPONSE.write('\r\n--%s\r\n' % boundary) | self.queryString = '&'.join(newparams) |
| RESPONSE.write('Content-Type: %s\r\n' % | return True |
| 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]) | |
| else: | |
| # Yippee. Linked Pdata objects. The following | |
| # calculations allow us to fast-forward through the | |
| # Pdata chain without a lot of dereferencing if we | |
| # did the work already. | |
| first_size = len(pdata_map[0].data) | |
| if start < first_size: | |
| closest_pos = 0 | |
| else: | |
| 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 | |
| # Do not keep the link references around. | return False |
| del pdata_map | |
| RESPONSE.write('\r\n--%s--\r\n' % boundary) | |
| return '' | |
| RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime)) | def changeZogiImage(self,title,baseUrl, queryString, digilibUrl=None, RESPONSE=None): |
| RESPONSE.setHeader('Content-Type', self.content_type) | """change it""" |
| RESPONSE.setHeader('Content-Length', self.size) | self.title=title |
| RESPONSE.setHeader('Accept-Ranges', 'bytes') | self.baseUrl=baseUrl |
| self.queryString=queryString | |
| # Don't cache the data itself, but provide an opportunity | if digilibUrl is not None and len(digilibUrl) > 0: |
| # for a cache manager to set response headers. | self.setWithDigilibURL(digilibUrl) |
| 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 | |
| return '' | if RESPONSE is not None: |
| RESPONSE.redirect('manage_main') | |
| def manage_addZogiImageForm(self): | def manage_addZogiImageForm(self): |
| Line 406 def manage_addZogiImageForm(self): | Line 143 def manage_addZogiImageForm(self): |
| return pt() | return pt() |
| def manage_addZogiImage(self,id,title,baseUrl, queryString,RESPONSE=None): | def manage_addZogiImage(self,id,title,baseUrl,queryString,digilibUrl=None,RESPONSE=None): |
| """add dgilib""" | """add zogiimage""" |
| newObj=zogiImage(id,title,baseUrl, queryString) | newObj=zogiImage(id,title,baseUrl, queryString) |
| self.Destination()._setObject(id,newObj) | self.Destination()._setObject(id,newObj) |
| if digilibUrl is not None and len(digilibUrl) > 0: | |
| newObj.setWithDigilibURL(digilibUrl) | |
| if RESPONSE is not None: | if RESPONSE is not None: |
| RESPONSE.redirect('manage_main') | RESPONSE.redirect('manage_main') |
| class zogiLib(Folder): | class zogiLib(Folder): |
| """StandardElement""" | """digilib frontend with ZOPE""" |
| meta_type="zogiLib" | meta_type="zogiLib" |
| #xxxx | |
| security=ClassSecurityInfo() | |
| manage_options = Folder.manage_options+( | manage_options = Folder.manage_options+( |
| {'label':'Main Config','action':'changeZogiLibForm'}, | {'label':'Main Config','action':'changeZogiLibForm'}, |
| ) | ) |
| def __init__(self, id, title, digilibBaseUrl, localFileBase, version="book", basePath=""): | def __init__(self, id, title, dlServerURL, layout="book", basePath="", dlTarget=None, dlToolbarBaseURL=None): |
| """init""" | """init""" |
| self.id=id | self.id=id |
| self.title=title | self.title=title |
| self.digilibBaseUrl=digilibBaseUrl | self.dlServerURL = dlServerURL |
| self.localFileBase=localFileBase | |
| self.basePath=basePath | self.basePath=basePath |
| self.layout=version | self.layout = layout |
| self.dlTarget = dlTarget | |
| if dlToolbarBaseURL: | |
| self.dlToolbarBaseURL = dlToolbarBaseURL | |
| else: | |
| self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?" | |
| self.manage_addFolder('template') | |
| # form templates | |
| main_book = PageTemplateFile('zpt/main_book', globals()) | |
| main_image = PageTemplateFile('zpt/main_image', globals()) | |
| main_metaData = PageTemplateFile('zpt/main_metadata', globals()) | |
| #main_static = PageTemplateFile('zpt/main_static', globals()) | |
| options = PageTemplateFile('zpt/options', globals()) | |
| #changeForm = PageTemplateFile('zpt/changeForm', globals()) | |
| # display templates | |
| aux_divs = PageTemplateFile('zpt/aux_divs', globals()) | |
| #aux_divsN4 = PageTemplateFile('zpt/aux_divsN4', globals()) | |
| img_div = PageTemplateFile('zpt/img_div', globals()) | |
| # javascripts | |
| head_js = PageTemplateFile('zpt/head_js', globals()) | |
| jslib_js = PageTemplateFile('js/baselib.js', globals()) | |
| dllib_js = PageTemplateFile('js/dllib.js', globals()) | |
| # graphic files | |
| arr_right = ImageFile('images/right.gif', globals()) | |
| arr_left = ImageFile('images/left.gif', globals()) | |
| arr_up = ImageFile('images/up.gif', globals()) | |
| arr_down = ImageFile('images/down.gif', globals()) | |
| mark1 = ImageFile('images/mark1.gif', globals()) | |
| mark2 = ImageFile('images/mark2.gif', globals()) | |
| mark3 = ImageFile('images/mark3.gif', globals()) | |
| mark4 = ImageFile('images/mark4.gif', globals()) | |
| mark5 = ImageFile('images/mark5.gif', globals()) | |
| mark6 = ImageFile('images/mark6.gif', globals()) | |
| mark7 = ImageFile('images/mark7.gif', globals()) | |
| mark8 = ImageFile('images/mark8.gif', globals()) | |
| corner1 = ImageFile('images/olinks.gif', globals()) | |
| corner2 = ImageFile('images/orechts.gif', globals()) | |
| corner3 = ImageFile('images/ulinks.gif', globals()) | |
| corner4 = ImageFile('images/urechts.gif', globals()) | |
| security.declareProtected('View','getLayout') | |
| def getLayout(self): | |
| """get Layout""" | |
| return self.layout | |
| def version(self): | |
| """version information""" | |
| return ZOGIVERSION | |
| def getContextStatic(self): | |
| """get all the contexts which go to static pages""" | |
| try: | |
| dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName())) | |
| contexts=dom.getElementsByTagName("context") | |
| ret=[] | |
| for context in contexts: | |
| name=getUniqueElementText(context.getElementsByTagName("name")) | |
| link=getUniqueElementText(context.getElementsByTagName("link")) | |
| if name or link: | |
| ret.append((name,link)) | |
| return ret | |
| except: | |
| return [] | |
| def getContextDatabases(self): | |
| """get all dynamic contexts""" | |
| try: | |
| dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName())) | |
| contexts=dom.getElementsByTagName("context") | |
| ret=[] | |
| for context in contexts: | |
| metaDataLinks=context.getElementsByTagName("meta-datalink") | |
| for metaDataLink in metaDataLinks: | |
| db=metaDataLink.getAttribute("db") | |
| link=self.REQUEST['URL1']+"/dl_db?db=%s"%db | |
| if db: | |
| ret.append((db,link)) | |
| metaDataLinks=context.getElementsByTagName("meta-baselink") | |
| for metaDataLink in metaDataLinks: | |
| db=metaDataLink.getAttribute("db") | |
| link=self.REQUEST['URL1']+"/dl_db?db=%s"%db | |
| if db: | |
| ret.append((db,link)) | |
| return ret | |
| except: | |
| return [] | |
| def formatHTML(self,url,label=None,viewUrl=None): | |
| sets=xml.dom.minidom.parse(urllib.urlopen(url)).getElementsByTagName('dataset') | |
| ret="" | |
| #print label | |
| if label: | |
| ret+="""<a href="%s">%s</a>"""%(viewUrl,label) | |
| for set in sets: | |
| ret+="<table>" | |
| for node in set.childNodes: | |
| if hasattr(node,'tagName'): | |
| tag=node.tagName | |
| label=node.getAttribute("label") | |
| if not label: | |
| label=tag | |
| text=getText(node.childNodes) | |
| ret+="""<tr><td><b>%s:</b></td><td>%s</td></tr>"""%(label,text) | |
| ret+="</table>" | |
| return ret | |
| def getMetaData(self): | |
| """getMetaData""" | |
| try: | |
| dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName())) | |
| except: | |
| return "error metadata" | |
| contexts=dom.getElementsByTagName("context") | |
| ret=[] | |
| db=self.getDLParam("db") | |
| ob=self.getDLParam("object") | |
| fn=self.getDLParam("fn") | |
| pn=self.getDLParam("pn") | |
| if not fn: | |
| fn="" | |
| if not pn: | |
| pn="" | |
| if not ob: | |
| ob="" | |
| for context in contexts: | |
| metaDataLinks=context.getElementsByTagName("meta-datalink") | |
| for metaDataLink in metaDataLinks: | |
| if (db==metaDataLink.getAttribute("db")) or (len(metaDataLinks)==1): | |
| link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url")) | |
| label=getUniqueElementText(metaDataLink.getElementsByTagName("label")) | |
| url=getUniqueElementText(metaDataLink.getElementsByTagName("url")) | |
| return self.formatHTML(link,label,url) | |
| metaDataLinks=context.getElementsByTagName("meta-baselink") | |
| for metaDataLink in metaDataLinks: | |
| if db==metaDataLink.getAttribute("db") or (len(metaDataLinks)==1): | |
| link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url")) | |
| label=getUniqueElementText(metaDataLink.getElementsByTagName("label")) | |
| url=getUniqueElementText(metaDataLink.getElementsByTagName("url")) | |
| return self.formatHTML(link+'fn=%s&pn=%s&object=%s'%(fn,pn,ob),label,url) | |
| return ret | |
| def getDLInfo(self): | def getDLInfo(self): |
| """get DLInfo from digilib server""" | """get DLInfo from digilib server""" |
| paramH={} | paramH={} |
| baseUrl=re.sub("servlet/Scaler","dlInfo-xml.jsp",self.digilibBaseUrl) | baseUrl=self.getDLBaseUrl()+"/dlInfo-xml.jsp" |
| #print "getdlinfo: ", baseUrl | |
| try: | try: |
| url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING']) | url=urllib.urlopen(baseUrl+'?'+self.getAllDLParams()) |
| dom=xml.dom.minidom.parse(url) | dom=xml.dom.minidom.parse(url) |
| params=dom.getElementsByTagName('parameter') | params=dom.getElementsByTagName('parameter') |
| for param in params: | for param in params: |
| paramH[param.getAttribute('name')]=param.getAttribute('value') | paramH[param.getAttribute('name')]=param.getAttribute('value') |
| return paramH | return paramH |
| except: | except: |
| return null | return {} |
| def createHeadJS(self): | def zogilibPathOLD(self, otherbase=None): |
| """generate all javascript tags for head""" | """returns an URL to the zogiLib instance""" |
| self.checkQuery() | url = self.REQUEST['URL1'] |
| bt = self.REQUEST.SESSION['browserType'] | # should end with "/" |
| if bt['staticHTML']: | if len(url) > 0 and url[-1] != '/': |
| return | url += '/' |
| if type(otherbase) is str: | |
| url += otherbase | |
| else: | |
| url += self.basePath | |
| # should still end with "/" | |
| if len(url) > 0 and url[-1] != '/': | |
| url += '/' | |
| return url | |
| pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self) | def zogilibPath(self, otherbase=None): |
| return pt() | """returns an URL to the zogiLib instance""" |
| url = self.absolute_url() | |
| # should end with "/" | |
| if len(url) > 0 and url[-1] != '/': | |
| url += '/' | |
| if type(otherbase) is str: | |
| url += otherbase | |
| else: | |
| url += self.basePath | |
| # should still end with "/" | |
| if len(url) > 0 and url[-1] != '/': | |
| url += '/' | |
| return url | |
| def zogilibAction(self, action, otherbase=None): | |
| """returns a URL with zogilib path and action""" | |
| url = self.zogilibPath(otherbase) | |
| url += action | |
| url += '?' + self.getAllDLParams(); | |
| return url | |
| def createParamJS(self): | def getDLBaseUrl(self): |
| """generate javascript for parameters only""" | """returns digilib base URL (sans servlet path)""" |
| self.checkQuery() | if self.dlServerURL[-1] == '?': |
| bt = self.REQUEST.SESSION['browserType'] | # full Servlet URL -- remove last part |
| if bt['staticHTML']: | si = self.dlServerURL.rindex('/servlet/') |
| return | if si > 0: |
| return self.dlServerURL[:si] | |
| else: | |
| # no servlet part :-( | |
| return "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" | |
| else: | |
| return self.dlServerURL | |
| def getScalerUrl(self,requestString=""): | |
| """send scaler url""" | |
| if self.dlServerURL[-1] == '?': | |
| # full Servlet URL | |
| return self.dlServerURL + requestString | |
| else: | |
| return self.dlServerURL+'/servlet/Scaler?'+requestString | |
| pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self) | def scaledImage(self,requestString=None): |
| return pt() | """scaled Image""" |
| if not requestString: | |
| requestString=self.REQUEST['QUERY_STRING'] | |
| self.REQUEST.RESPONSE.redirect(self.getScalerUrl(requestString)) | |
| return True | |
| def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500): | |
| def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500, options=None): | |
| """generate Scaler IMG Tag""" | """generate Scaler IMG Tag""" |
| self.checkQuery() | self.checkQuery() |
| bt = self.REQUEST.SESSION['browserType'] | bt = self.getBrowserType() |
| # override with parameters from session | # override with parameters from session |
| if self.REQUEST.SESSION.has_key('scalerDiv'): | if self.REQUEST.SESSION.has_key('scalerDiv'): |
| (requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv'] | (requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv'] |
| # if not explicitly defined take normal request | # if not explicitly defined take normal request |
| if not requestString: | if not requestString: |
| requestString = self.getAllDLParams() | requestString = self.getAllDLParams() |
| url = self.digilibBaseUrl+requestString | url = self.getScalerUrl(requestString=requestString) |
| # take insets from options if present | |
| if options is not None: | |
| side = options.get('side', side) | |
| bottom = options.get('bottom', bottom) | |
| # construct bottom and side insets | # construct bottom and side insets |
| b_par = "" | b_par = "" |
| s_par = "" | s_par = "" |
| Line 518 class zogiLib(Folder): | Line 478 class zogiLib(Folder): |
| # make shure to remove unused parameter | # make shure to remove unused parameter |
| del self.REQUEST.SESSION['scalerDiv'] | del self.REQUEST.SESSION['scalerDiv'] |
| pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self) | pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/img_div')).__of__(self) |
| return pt() | return pt() |
| def createAuxDiv(self): | |
| """generate other divs""" | |
| self.checkQuery() | |
| bt = self.REQUEST.SESSION['browserType'] | |
| if bt['staticHTML']: | |
| return | |
| if bt['isN4']: | |
| 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 option_js(self): | |
| """option_js""" | |
| pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/option_js')).__of__(self) | |
| return pt() | |
| 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: | |
| pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self) | |
| return pt() | |
| def mark1(self): | |
| """mark image""" | |
| return sendFile(self, 'images/mark1.gif', 'image/gif') | |
| 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') | |
| def index_html(self): | def index_html(self): |
| """main action""" | """main action""" |
| self.checkQuery() | self.checkQuery() |
| bt = self.REQUEST.SESSION['browserType'] | tp = "main_template" |
| tp = "zogiLibMainTemplate" | |
| if hasattr(self, tp): | |
| pt = getattr(self, tp) | |
| else: | |
| tpt = self.layout | tpt = self.layout |
| if bt['staticHTML']: | |
| tpt = "static" | |
| pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%tpt)).__of__(self) | if not hasattr(self, 'template'): |
| # create template folder if it doesn't exist | |
| print "no template folder -- creating" | |
| self.manage_addFolder('template') | |
| pt = getattr(self.template, 'main_'+tpt) | |
| return pt() | return pt() |
| def checkQuery(self): | |
| """make shure that the query has been saved""" | |
| if not self.REQUEST.has_key('dlParams'): | |
| self.storeQuery() | |
| def storeQuery(self, more=None, withpt=False): | |
| def storeQuery(self, more = None): | """parse query parameters into a hash in REQUEST""" |
| """storeQuery in session""" | params = {} |
| dlParams = {} | |
| for fm in self.REQUEST.form.keys(): | for fm in self.REQUEST.form.keys(): |
| dlParams[fm] = self.REQUEST.form[fm] | params[fm] = self.REQUEST.form[fm] |
| # look for more | # look for more |
| if more: | if more: |
| for fm in more.split('&'): | for fm in more.split('&'): |
| try: | try: |
| pv = fm.split('=') | pv = fm.split('=') |
| dlParams[pv[0]] = pv[1] | params[pv[0]] = pv[1] |
| except: | except: |
| pass | pass |
| # parse digilib mode parameter | # parse digilib mode parameter |
| if 'mo' in dlParams: | if 'mo' in params: |
| if len(dlParams['mo']) > 0: | if len(params['mo']) > 0: |
| modes=dlParams['mo'].split(',') | modes=params['mo'].split(',') |
| else: | else: |
| modes=[] | 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 | self.REQUEST.set('dlParams', params) |
| self.REQUEST.set('dlModes', modes) | |
| def checkQuery(self): | # trigger get pt (from dlInfo) if requested |
| """check if the query has been stored""" | if withpt: |
| if not (self.REQUEST.SESSION and self.REQUEST.SESSION.has_key('query')) : | pt = self.getPT() |
| print "ZOGILIB: have to store query!!" | |
| self.storeQuery() | |
| return | |
| def zogilibPath(self, otherbase=None): | return params |
| """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""" | def getDLParam(self, param, default=None): |
| """returns parameter or default""" | |
| self.checkQuery() | |
| dlParams = self.REQUEST.get('dlParams') | |
| try: | try: |
| return self.REQUEST.SESSION['query'][param] | return dlParams[param] |
| except: | except: |
| return | return default |
| def setDLParam(self, param, value): | def setDLParam(self, param, value): |
| """sets parameter""" | """sets parameter""" |
| self.REQUEST.SESSION['query'][param] = value | self.checkQuery() |
| dlParams = self.REQUEST.get('dlParams') | |
| dlParams[param] = value | |
| return | return |
| def getAllDLParams(self): | def getAllDLParams(self): |
| """parameter string for digilib""" | """parameter string for digilib""" |
| dlParams = self.REQUEST.SESSION['query'] | self.checkQuery() |
| dlParams = self.REQUEST.get('dlParams') | |
| # save modes | # save modes |
| modes = self.REQUEST.SESSION['dlModes'] | modes = self.REQUEST.get('dlModes') |
| if modes: | |
| dlParams['mo'] = string.join(modes, ',') | dlParams['mo'] = string.join(modes, ',') |
| # assemble query string | # assemble query string |
| ret = "" | ret = "" |
| for param in dlParams.keys(): | for param in dlParams.keys(): |
| if dlParams[param] is None: continue | |
| val = str(dlParams[param]) | val = str(dlParams[param]) |
| if val != "": | if val != "": |
| ret += param + "=" + val + "&" | ret += param + "=" + val + "&" |
| # omit trailing "&" | # omit trailing "&" |
| return ret.rstrip('&') | return ret.rstrip('&') |
| def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None): | def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None): |
| """setze Parameter""" | """setze Parameter""" |
| Line 736 class zogiLib(Folder): | Line 581 class zogiLib(Folder): |
| return self.display() | return self.display() |
| def getBrowserType(self): | |
| """get browser type object""" | |
| if self.REQUEST.SESSION.has_key('browserType'): | |
| return self.REQUEST.SESSION['browserType'] | |
| else: | |
| bt = browserCheck(self) | |
| self.REQUEST.SESSION.set('browserType', bt) | |
| return bt | |
| def display(self): | def display(self): |
| """(re)display page""" | """(re)display page""" |
| params = self.getAllDLParams() | params = self.getAllDLParams() |
| if self.basePath: | if self.basePath: |
| self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params) | self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params) |
| else: | else: |
| self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params) | self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params) |
| def getMetaFileName(self): | |
| url=self.dlServerURL+'/dlContext-xml.jsp?'+self.getAllDLParams() | |
| return urlbase | |
| def getToolbarPageURL(self): | |
| """returns a toolbar-enabled page URL""" | |
| url=self.dlToolbarBaseURL+self.getAllDLParams() | |
| return url | |
| def setStaticHTML(self, static=True): | def getDLTarget(self): |
| """sets the preference to static HTML""" | """returns dlTarget""" |
| self.checkQuery() | self.checkQuery() |
| self.REQUEST.SESSION['browserType']['staticHTML'] = static | s = self.dlTarget |
| return | if (s is None) or (s == ""): |
| # s = "" | |
| s = 'dl' | |
| if self.getDLParam('fn'): | |
| s += "_" + self.getDLParam('fn') | |
| if self.getDLParam('pn'): | |
| s += "_" + self.getDLParam('pn') | |
| def isStaticHTML(self): | return s |
| """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 | |
| def getPN(self): | def getPN(self): |
| """Pagenum""" | """pagenumber""" |
| pn = self.getDLParam('pn') | pn = int(self.getDLParam('pn', 1)) |
| try: | return pn |
| return int(pn) | |
| except: | |
| return 1 | |
| def getBiggerWS(self): | def getPT(self): |
| """ws+1""" | """number of total pages""" |
| ws = self.getDLParam('ws') | pt = self.getDLParam('pt', None) |
| try: | if pt is None: |
| return float(ws)+0.5 | # get pt from dlInfo |
| except: | if self.REQUEST.has_key('dlInfo'): |
| return 1.5 | info = self.REQUEST.get('dlInfo') |
| else: | |
| def getSmallerWS(self): | info = self.getDLInfo() |
| """ws-1""" | self.REQUEST.set('dlInfo', info) |
| ws=self.getDLParam('ws') | pt = int(info.get('pt', 1)) |
| try: | self.setDLParam('pt', pt) |
| return max(float(ws)-0.5, 1) | return int(pt) |
| except: | |
| return 1 | |
| def hasMode(self, mode): | def hasMode(self, mode): |
| """returns if mode is in the diglib mo parameter""" | """returns if mode is in the diglib mo parameter""" |
| return (mode in self.REQUEST.SESSION['dlModes']) | return (mode in self.REQUEST.get('dlModes')) |
| def hasNextPage(self): | def hasNextPage(self): |
| """returns if there is a next page""" | """returns if there is a next page""" |
| Line 830 class zogiLib(Folder): | Line 683 class zogiLib(Folder): |
| def dl_StaticHTML(self): | def dl_StaticHTML(self): |
| """set rendering to static HTML""" | """set rendering to static HTML""" |
| self.checkQuery() | self.checkQuery() |
| self.REQUEST.SESSION['browserType']['staticHTML'] = True | self.getBrowserType()['staticHTML'] = True |
| return self.display() | return self.display() |
| def dl_DynamicHTML(self): | def dl_DynamicHTML(self): |
| """set rendering to dynamic HTML""" | """set rendering to dynamic HTML""" |
| self.checkQuery() | self.checkQuery() |
| self.REQUEST.SESSION['browserType']['staticHTML'] = False | self.getBrowserType()['staticHTML'] = False |
| return self.display() | return self.display() |
| def dl_HMirror(self): | def dl_HMirror(self): |
| """mirror action""" | """mirror action""" |
| modes = self.REQUEST.SESSION['dlModes'] | modes = self.getSubSession('dlModes') |
| if 'hmir' in modes: | if 'hmir' in modes: |
| modes.remove('hmir') | modes.remove('hmir') |
| else: | else: |
| Line 851 class zogiLib(Folder): | Line 704 class zogiLib(Folder): |
| def dl_VMirror(self): | def dl_VMirror(self): |
| """mirror action""" | """mirror action""" |
| modes = self.REQUEST.SESSION['dlModes'] | modes = self.getSubSession('dlModes') |
| if 'vmir' in modes: | if 'vmir' in modes: |
| modes.remove('vmir') | modes.remove('vmir') |
| else: | else: |
| Line 873 class zogiLib(Folder): | Line 726 class zogiLib(Folder): |
| wh2 = max(min(wh2, 1), 0) | wh2 = max(min(wh2, 1), 0) |
| wx = max(min(wx, 1), 0) | wx = max(min(wx, 1), 0) |
| wy = max(min(wy, 1), 0) | wy = max(min(wy, 1), 0) |
| self.setDLParam('ww', ww2) | self.setDLParam('ww', cropf(ww2)) |
| self.setDLParam('wh', wh2) | self.setDLParam('wh', cropf(wh2)) |
| self.setDLParam('wx', wx) | self.setDLParam('wx', cropf(wx)) |
| self.setDLParam('wy', wy) | self.setDLParam('wy', cropf(wy)) |
| return self.display() | return self.display() |
| def dl_ZoomIn(self): | def dl_ZoomIn(self): |
| Line 899 class zogiLib(Folder): | Line 752 class zogiLib(Folder): |
| wy += dy * 0.5 * wh | wy += dy * 0.5 * wh |
| wx = max(min(wx, 1), 0) | wx = max(min(wx, 1), 0) |
| wy = max(min(wy, 1), 0) | wy = max(min(wy, 1), 0) |
| self.setDLParam('wx', wx) | self.setDLParam('wx', cropf(wx)) |
| self.setDLParam('wy', wy) | self.setDLParam('wy', cropf(wy)) |
| return self.display() | return self.display() |
| def dl_MoveLeft(self): | def dl_MoveLeft(self): |
| Line 962 class zogiLib(Folder): | Line 815 class zogiLib(Folder): |
| self.setDLParam('mk', None) | self.setDLParam('mk', None) |
| return self.display() | return self.display() |
| def dl_Unmark(self): | def dl_db(self,db): |
| """action to remove last mark""" | """set db""" |
| mk = self.getDLParam('mk') | self.setDLParam('db',db) |
| if mk: | self.display() |
| marks = mk.split(',') | |
| marks.pop() | |
| mk = string.join(marks, ',') | |
| self.setDLParam('mk', mk) | |
| return self.display() | |
| def changeZogiLibForm(self): | def changeZogiLibForm(self): |
| """Main configuration""" | """Main configuration""" |
| pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self) | pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self) |
| return pt() | return pt() |
| def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, basePath, RESPONSE=None): | def changeZogiLib(self,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL, RESPONSE=None): |
| """change it""" | """change it""" |
| self.title=title | self.title=title |
| self.digilibBaseUrl=digilibBaseUrl | self.dlServerURL=dlServerURL |
| self.localFileBase=localFileBase | |
| self.basePath = basePath | self.basePath = basePath |
| self.layout=version | self.layout=version |
| self.dlTarget = dlTarget | |
| if dlToolbarBaseURL: | |
| self.dlToolbarBaseURL = dlToolbarBaseURL | |
| else: | |
| self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?" | |
| if RESPONSE is not None: | if RESPONSE is not None: |
| RESPONSE.redirect('manage_main') | RESPONSE.redirect('manage_main') |
| ## | |
| ## odds and ends | |
| ## | |
| def repairZogilib(self, obj=None): | |
| """change stuff that broke on upgrading""" | |
| msg = "" | |
| if not obj: | |
| obj = self.getPhysicalRoot() | |
| print "starting in ", obj | |
| entries=obj.ZopeFind(obj,obj_metatypes=['zogiLib'],search_sub=1) | |
| for entry in entries: | |
| print " found ", entry | |
| # | |
| # replace digilibBaseUrl by dlServerURL | |
| if hasattr(entry[1], 'digilibBaseUrl'): | |
| msg += " fixing digilibBaseUrl in "+entry[0]+"\n" | |
| entry[1].dlServerURL = re.sub('/servlet/Scaler\?','',entry[1].digilibBaseUrl) | |
| del entry[1].digilibBaseUrl | |
| # | |
| # add dlToolbarBaseURL | |
| if not hasattr(entry[1], 'dlToolbarBaseURL'): | |
| msg += " fixing dlToolbarBaseURL in "+entry[0]+"\n" | |
| entry[1].dlToolbarBaseURL = entry[1].dlServerURL + "/digimage.jsp?" | |
| return msg+"\n\nfixed all zogilib instances in: "+obj.title | |
| def manage_addZogiLibForm(self): | def manage_addZogiLibForm(self): |
| """interface for adding zogilib""" | """interface for adding zogilib""" |
| pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self) | pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self) |
| return pt() | return pt() |
| def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",basePath="",RESPONSE=None): | def manage_addZogiLib(self,id,title,dlServerURL,version="book",basePath="",dlTarget=None,dlToolbarBaseURL=None,RESPONSE=None): |
| """add dgilib""" | """add dgilib""" |
| newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version, basePath) | newObj=zogiLib(id,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL) |
| self.Destination()._setObject(id,newObj) | self.Destination()._setObject(id,newObj) |
| if RESPONSE is not None: | if RESPONSE is not None: |
| RESPONSE.redirect('manage_main') | RESPONSE.redirect('manage_main') |
| class zogiLibPageTemplate(ZopePageTemplate): | |
| """pageTemplate Objekt""" | |
| meta_type="zogiLib_pageTemplate" | |
| ## 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 manage_addZogiLibPageTemplate(self, title=None, layout=None, text=None, | |
| REQUEST=None, submit=None): | |
| "Add a Page Template with optional file content." | |
| if not layout: layout = "book" | |
| id = 'main_%s'%layout | |
| self._setObject(id, zogiLibPageTemplate(id)) | |
| ob = getattr(self, id) | |
| ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/main_%s.zpt'%layout)).read(),'text/html') | |
| if title: | |
| ob.pt_setTitle(title) | |
| try: | |
| url = self.DestinationURL() | |
| except AttributeError: | |
| url = REQUEST['URL1'] | |
| url = "%s/%s" % (url, urllib.quote(id)) | |
| REQUEST.RESPONSE.redirect(url+'/manage_main') | |
| return '' | |