version 1.2, 2004/03/25 18:32:13
|
version 1.60, 2005/11/08 18:10:10
|
Line 1
|
Line 1
|
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from AccessControl import ClassSecurityInfo |
|
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 types import * |
|
from Globals import package_home, ImageFile |
import xml.dom.minidom |
from xml_helpers import getUniqueElementText,getText |
from OFS.Folder import Folder |
import cgi |
from xml_helpers import getText |
|
import os |
import os |
|
import random |
import re |
import re |
import string |
import string |
import urllib |
import urllib |
from Globals import package_home |
import xml.dom.minidom |
|
|
def getString(self,key,default=''): |
ZOGIVERSION = "0.10.1b ROC 8.11.2005" |
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 (from 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'] = False |
|
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, '('):] |
|
ie = string.split(nav, "; ")[1] |
|
if string.find(ie, "MSIE") > -1: |
|
bt['versIE'] = string.split(ie, " ")[1] |
|
except: pass |
|
|
|
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(SimpleItem): |
|
"""einzelnes Image""" |
|
meta_type="zogiImage" |
|
|
manage_options=ZopePageTemplate.manage_options+( |
manage_options=SimpleItem.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 |
|
if baseUrl: |
|
self.baseUrl=baseUrl |
|
else: |
|
self.baseUrl="http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?" |
|
|
|
self.queryString=queryString |
|
self.content_type=content_type |
|
self.precondition=precondition |
|
|
## def changeECHO_pageTemplateWeight(self,weight,content_type,RESPONSE=None): |
#def getData(self): |
## """change""" |
# """getUrlData""" |
## self.weight=weight |
# return urllib.urlopen(self.baseUrl+self.queryString) |
## self.content_type=content_type |
|
|
|
## if RESPONSE is not None: |
def changeZogiImageForm(self): |
## RESPONSE.redirect('manage_main') |
"""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 |
|
|
def copyContent(self): |
if RESPONSE is not None: |
"""copycontent to path""" |
RESPONSE.redirect('manage_main') |
|
|
return "copied to:"+copyContent(self,'thumbtemplate.templ') |
def index_html(self, REQUEST, RESPONSE): |
|
"""service the request by redirecting to digilib server""" |
|
RESPONSE.redirect(self.baseUrl+self.queryString) |
|
return '' |
|
|
|
def rescale(self,width=None,height=None): |
|
"""andere parameter im querystring""" |
|
qs=cgi.parse_qs(self.queryString) |
|
for x in qs.keys(): |
|
if type(qs[x]) is ListType: |
|
qs[x]=qs[x][0] |
|
|
|
if width: |
|
qs['dw']=width |
|
if height: |
|
qs['dh']=height |
|
|
|
|
|
qsneu=urllib.urlencode(qs) |
|
self.queryString=qsneu |
|
return "done" |
|
|
def manage_addZogiLib_NavTemplateForm(self): |
def manage_addZogiImageForm(self): |
"""Form for adding""" |
"""Form for adding""" |
pt=PageTemplateFile('Products/ECHO_content/zpt/AddZogilib_NavTemplate.zpt').__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiImage.zpt')).__of__(self) |
return pt() |
return pt() |
|
|
|
|
|
def manage_addZogiImage(self,id,title,baseUrl, queryString,RESPONSE=None): |
|
"""add zogiimage""" |
|
newObj=zogiImage(id,title,baseUrl, queryString) |
|
self.Destination()._setObject(id,newObj) |
|
if RESPONSE is not None: |
|
RESPONSE.redirect('manage_main') |
|
|
|
|
def manage_addZogiLib_NavTemplate(self, id,title=None, text=None, |
|
REQUEST=None, submit=None): |
|
"Add a Page Template with optional file content." |
|
|
|
|
class zogiLib(Folder): |
|
"""digilib frontend with ZOPE""" |
|
|
id = str(id) |
meta_type="zogiLib" |
if REQUEST is None: |
#xxxx |
self._setObject(id, zogilib_NavTemplate(id, text)) |
security=ClassSecurityInfo() |
ob = getattr(self, id) |
|
|
|
if title: |
manage_options = Folder.manage_options+( |
ob.pt_setTitle(title) |
{'label':'Main Config','action':'changeZogiLibForm'}, |
return ob |
) |
else: |
|
file = REQUEST.form.get('file') |
|
headers = getattr(file, 'headers', None) |
|
if headers is None or not file.filename: |
|
zpt = zogilib_NavTemplate(id) |
|
else: |
|
zpt = zogilib_NavTemplate(id, file, headers.get('content_type')) |
|
|
|
self._setObject(id, zpt) |
def __init__(self, id, title, dlServerURL, layout="book", basePath="", dlTarget=None, dlToolbarBaseURL=None): |
ob = getattr(self, id) |
"""init""" |
|
|
|
self.id=id |
|
self.title=title |
|
self.dlServerURL = dlServerURL |
|
self.basePath=basePath |
|
self.layout=layout |
|
self.dlTarget = dlTarget |
|
|
try: |
if dlToolbarBaseURL: |
u = self.DestinationURL() |
self.dlToolbarBaseURL = dlToolbarBaseURL |
except AttributeError: |
else: |
u = REQUEST['URL1'] |
self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?" |
|
|
if submit == " Add and Edit ": |
self.manage_addFolder('template') |
u = "%s/%s" % (u, quote(id)) |
|
REQUEST.RESPONSE.redirect(u+'/manage_main') |
|
return '' |
|
|
|
def readNavTemp(fileName): |
|
"""navtemp""" |
|
print "HI reading",fileName |
|
|
|
if os.path.exists(fileName+"/index.meta"): |
# form templates |
dom=xml.dom.minidom.parse(fileName+"/index.meta") |
main_book = PageTemplateFile('zpt/main_book', globals()) |
else: |
main_image = PageTemplateFile('zpt/main_image', globals()) |
return None |
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 |
|
|
print "dom",dom |
def getContextStatic(self): |
try: |
"""get all the contexts which go to static pages""" |
navTag=getText(dom.getElementsByTagName('zogilibtemplate')[0].childNodes) |
|
except: |
|
navTag=None |
|
return navTag |
|
|
|
|
try: |
|
dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName())) |
|
contexts=dom.getElementsByTagName("context") |
|
|
class zogiLib(Folder): |
ret=[] |
"""StandardElement""" |
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 [] |
|
|
meta_type="zogiLib" |
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)) |
|
|
def generateImageFolder(self): |
return ret |
"""images ablegen""" |
except: |
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) |
|
|
|
|
return [] |
|
|
def __init__(self, id,title,digilibBaseUrl, localFileBase): |
|
"""init""" |
|
|
|
self.id=id |
def formatHTML(self,url,label=None,viewUrl=None): |
self.title=title |
|
self.digilibBaseUrl=digilibBaseUrl |
|
self.localFileBase=localFileBase |
|
self._setObject('topTemplate',zogiLib_navTemplate(id='topTemplate')) |
|
self.generateImageFolder() |
|
|
|
|
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 |
|
|
manage_options = Folder.manage_options+( |
|
{'label':'Main Config','action':'changeZogiLibForm'}, |
|
) |
|
|
|
def navigation_js(self): |
def getMetaData(self): |
"""Javascript""" |
"""getMetaData""" |
|
try: |
|
dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName())) |
|
except: |
|
return "error metadata" |
|
|
return file("../lib/python/Products/zogiLib/js/navigation.js").read() |
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="" |
|
|
def generateTopJavaScript(self): |
for context in contexts: |
"""generate script""" |
metaDataLinks=context.getElementsByTagName("meta-datalink") |
ret="""var baseUrl = '%s'; """% self.REQUEST['URL0'] |
for metaDataLink in metaDataLinks: |
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+=""" |
if (db==metaDataLink.getAttribute("db")) or (len(metaDataLinks)==1): |
|
|
var wwidth, wheight; |
link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url")) |
if (self.innerHeight) // all except Explorer |
label=getUniqueElementText(metaDataLink.getElementsByTagName("label")) |
{ |
url=getUniqueElementText(metaDataLink.getElementsByTagName("url")) |
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; |
|
} |
|
|
|
|
return self.formatHTML(link,label,url) |
|
|
""" |
metaDataLinks=context.getElementsByTagName("meta-baselink") |
return ret |
|
|
|
|
|
|
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 generateScalerImg(self,requestString): |
def getDLInfo(self): |
"""generate Scaler Tag""" |
"""get DLInfo from digilib server""" |
retStr=self.digilibBaseUrl+requestString |
paramH={} |
jS="""<script type="text/javascript"> |
baseUrl=self.getDLBaseUrl()+"/dlInfo-xml.jsp" |
document.write("<img id=\\\"pic\\\" src=\\\"%s&dw="+wwidth+"&dh="+wheight+"\\\"/>")</script>"""%retStr |
print "getdlinfo: ", baseUrl |
return jS |
try: |
|
url=urllib.urlopen(baseUrl+'?'+self.getAllDLParams()) |
|
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 {} |
|
|
def changeZogiLibForm(self): |
|
"""Main configuration""" |
|
pt=PageTemplateFile('Products/zogiLib/zpt/changeZogiLibForm.zpt').__of__(self) |
|
return pt() |
|
|
|
def changeZogiLib(self,title,digilibBaseUrl, localFileBase,RESPONSE=None): |
def zogilibPath(self, otherbase=None): |
"""change it""" |
"""returns an URL to the zogiLib instance""" |
self.title=title |
url = self.REQUEST['URL1'] |
self.digilibBaseUrl=digilibBaseUrl |
# should end with "/" |
self.localFileBase=localFileBase |
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 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 getDLBaseUrl(self): |
|
"""returns digilib base URL (sans servlet path)""" |
|
if self.dlServerURL[-1] == '?': |
|
# full Servlet URL -- remove last part |
|
si = self.dlServerURL.rindex('/servlet/') |
|
if si > 0: |
|
return self.dlServerURL[:si] |
|
else: |
|
# no servlet part :-( |
|
return "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" |
|
else: |
|
return self.dlServerURL |
|
|
if RESPONSE is not None: |
|
RESPONSE.redirect('manage_main') |
|
|
|
|
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 |
|
|
def nav_html(self,fileName): |
def scaledImage(self,requestString=None): |
"""navigations frame""" |
"""scaled Image""" |
|
|
# suche nach index.meta mit zogilib thumb info |
if not requestString: |
|
requestString=self.REQUEST['QUERY_STRING'] |
|
|
templ=readNavTemp(self.localFileBase+"/"+fileName) |
self.REQUEST.RESPONSE.redirect(self.getScalerUrl(requestString)) |
if not templ: |
|
templ=readNavTemp(self.localFileBase+"/"+fileName.split("/")[0]) |
return True |
if not templ: |
|
return self.topTemplate.document_src() |
|
|
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.getScalerUrl(requestString=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 |
|
|
return urllib.urlopen(templ).read() |
def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500): |
|
"""generate scaler img and table with navigation arrows""" |
|
self.checkQuery() |
|
if requestString != None or bottom != 0 or side != 0: |
|
self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height) |
|
else: |
|
if self.REQUEST.SESSION.has_key('scalerDiv'): |
|
# make shure to remove unused parameter |
|
del self.REQUEST.SESSION['scalerDiv'] |
|
|
|
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self) |
|
return pt() |
|
|
def index_html(self): |
def index_html(self): |
"""main action""" |
"""main action""" |
|
self.checkQuery() |
|
tp = "main_template" |
|
tpt = self.layout |
|
|
|
if not hasattr(self, 'template'): |
|
# create template folder if it doesn't exist |
|
print "no template folder" |
|
self.manage_addFolder('template') |
|
|
|
print "template!" |
pt=PageTemplateFile('Products/zogiLib/zpt/zogiLibMain.zpt').__of__(self) |
pt = getattr(self.template, 'main_'+tpt) |
return pt() |
return pt() |
|
|
def storeQuery(self): |
def checkQuery(self): |
"""storeQuery in session""" |
"""make shure that the query has been saved""" |
self.REQUEST.SESSION['query']={} |
if not self.REQUEST.has_key('dlParams'): |
|
self.storeQuery() |
|
if not self.REQUEST.SESSION.has_key('browserType'): |
|
bt = browserCheck(self) |
|
self.REQUEST.SESSION.set('browserType', bt) |
|
|
|
def storeQuery(self, more=None, withpt=False): |
|
"""parse query parameters into a hash in REQUEST""" |
|
params = {} |
for fm in self.REQUEST.form.keys(): |
for fm in self.REQUEST.form.keys(): |
self.REQUEST.SESSION['query'][fm]=self.REQUEST.form[fm] |
params[fm] = self.REQUEST.form[fm] |
|
# look for more |
def setParam(self,pn=None,ws=None,rot=None): |
if more: |
"""gotopage""" |
for fm in more.split('&'): |
ret="" |
try: |
|
pv = fm.split('=') |
if pn: |
params[pv[0]] = pv[1] |
self.REQUEST.SESSION['query']['pn']=pn |
except: |
|
pass |
|
|
if ws: |
# parse digilib mode parameter |
self.REQUEST.SESSION['query']['ws']=ws |
if 'mo' in params: |
|
if len(params['mo']) > 0: |
|
modes=params['mo'].split(',') |
|
else: |
|
modes = []; |
|
|
if rot: |
self.REQUEST.set('dlParams', params) |
self.REQUEST.SESSION['query']['rot']=rot |
self.REQUEST.set('dlModes', modes) |
|
|
for param in self.REQUEST.SESSION['query'].keys(): |
# trigger get pt (from dlInfo) if requested |
|
if withpt: |
|
pt = self.getPT() |
|
|
ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&" |
return params |
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
|
|
|
def mirrorPage(self,mi): |
def getDLParam(self, param, default=None): |
"""mirror""" |
"""returns parameter or default""" |
ret="" |
self.checkQuery() |
|
dlParams = self.REQUEST.get('dlParams') |
try: |
try: |
splitted=self.REQUEST.SESSION['query']['mo'].split(',') |
return dlParams[param] |
except: |
except: |
splitted=[] |
return default |
|
|
if mi=="h": |
def setDLParam(self, param, value): |
|
"""sets parameter""" |
|
self.checkQuery() |
|
dlParams = self.REQUEST.get('dlParams') |
|
dlParams[param] = value |
|
return |
|
|
|
def getAllDLParams(self): |
|
"""parameter string for digilib""" |
|
self.checkQuery() |
|
dlParams = self.REQUEST.get('dlParams') |
|
# save modes |
|
modes = self.REQUEST.get('dlModes') |
|
if modes: |
|
dlParams['mo'] = string.join(modes, ',') |
|
# assemble query string |
|
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 'hmir' in splitted: |
if pn: |
splitted.remove('hmir') |
# unmark |
else: |
self.setDLParam('mk', None) |
splitted.append('hmir') |
self.setDLParam('pn', pn) |
|
|
if mi=="v": |
return self.display() |
|
|
if 'vmir' in splitted: |
|
splitted.remove('vmir') |
|
else: |
|
splitted.append('vmir') |
|
|
|
|
def display(self): |
|
"""(re)display page""" |
|
params = self.getAllDLParams() |
|
|
self.REQUEST.SESSION['query']['mo']=string.join(splitted,",") |
if self.basePath: |
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params) |
|
else: |
|
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 getDLTarget(self): |
|
"""returns dlTarget""" |
|
self.checkQuery() |
|
s = self.dlTarget |
|
if s == None: |
|
s = "" |
|
# s = 'dl' |
|
# if self.getDLParam('fn'): |
|
# s += "_" + self.getDLParam('fn') |
|
# if self.getDLParam('pn'): |
|
# s += "_" + self.getDLParam('pn') |
|
return s |
|
|
|
def getPN(self): |
|
"""pagenums""" |
|
pn = int(self.getDLParam('pn', 1)) |
|
return pn |
|
|
|
def getPT(self): |
|
"""pagenums""" |
|
pt = self.getDLParam('pt', None) |
|
if pt is None: |
|
# get pt from dlInfo |
|
if self.REQUEST.has_key('dlInfo'): |
|
info = self.REQUEST.get('dlInfo') |
|
else: |
|
info = self.getDLInfo() |
|
self.REQUEST.set('dlInfo', info) |
|
pt = int(info.get('pt', 1)) |
|
self.setDLParam('pt', pt) |
|
return int(pt) |
|
|
|
def hasMode(self, mode): |
|
"""returns if mode is in the diglib mo parameter""" |
|
return (mode in self.REQUEST.get('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.getSubSession('dlModes') |
|
if 'hmir' in modes: |
|
modes.remove('hmir') |
|
else: |
|
modes.append('hmir') |
|
|
|
return self.display() |
|
|
|
def dl_VMirror(self): |
|
"""mirror action""" |
|
modes = self.getSubSession('dlModes') |
|
if 'vmir' in modes: |
|
modes.remove('vmir') |
|
else: |
|
modes.append('vmir') |
|
|
for param in self.REQUEST.SESSION['query'].keys(): |
return self.display() |
|
|
ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&" |
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_db(self,db): |
|
"""set db""" |
|
self.setDLParam('db',db) |
|
self.display() |
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
def changeZogiLibForm(self): |
|
"""Main configuration""" |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self) |
|
return pt() |
|
|
def decode(self,strR): |
def changeZogiLib(self,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL, RESPONSE=None): |
"""decode &""" |
"""change it""" |
print re.sub('\&','\&',strR) |
self.title=title |
return re.sub('\&','\&',strR) |
self.dlServerURL=dlServerURL |
|
self.basePath = basePath |
|
self.layout=version |
|
self.dlTarget = dlTarget |
|
|
def wholePage(self): |
if dlToolbarBaseURL: |
"""zoom out""" |
self.dlToolbarBaseURL = dlToolbarBaseURL |
ret="" |
else: |
|
self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?" |
|
|
self.REQUEST.SESSION['query']['ww']=1 |
if RESPONSE is not None: |
self.REQUEST.SESSION['query']['wh']=1 |
RESPONSE.redirect('manage_main') |
self.REQUEST.SESSION['query']['wx']=0 |
|
self.REQUEST.SESSION['query']['wy']=0 |
|
|
|
for param in self.REQUEST.SESSION['query'].keys(): |
|
|
|
ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&" |
|
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
## |
|
## 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?" |
|
|
def prevPage(self,pn=None): |
return msg+"\n\nfixed all zogilib instances in: "+obj.title |
"""next page""" |
|
ret="" |
|
|
|
if pn and pn>0: |
|
pn=str(int(pn)-1) |
|
|
|
|
def manage_addZogiLibForm(self): |
|
"""interface for adding zogilib""" |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self) |
|
return pt() |
|
|
self.REQUEST.form['pn']=pn |
def manage_addZogiLib(self,id,title,dlServerURL,version="book",basePath="",dlTarget=None,dlToolbarBaseURL=None,RESPONSE=None): |
print "hi",self.REQUEST.form.keys() |
"""add dgilib""" |
for param in self.REQUEST.form.keys(): |
newObj=zogiLib(id,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL) |
print param |
self.Destination()._setObject(id,newObj) |
ret+=param+"="+str(self.REQUEST.form[param])+"&" |
if RESPONSE is not None: |
|
RESPONSE.redirect('manage_main') |
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
|
|
|
|
class zogiLibPageTemplate(ZopePageTemplate): |
|
"""pageTemplate Objekt""" |
|
meta_type="zogiLib_pageTemplate" |
|
|
def nextPage(self,pn=None): |
|
"""next page""" |
|
ret="" |
|
|
|
try: |
## def __init__(self, id, text=None, contentType=None): |
pn=str(int(pn)+1) |
## self.id = str(id) |
except: |
## self.ZBindings_edit(self._default_bindings) |
pn=str(2) |
## if text is None: |
|
## text = open(self._default_cont).read() |
|
## self.pt_edit(text, contentType) |
|
|
self.REQUEST.form['pn']=pn |
def manage_addZogiLibPageTemplateForm(self): |
print "hi",self.REQUEST.form.keys() |
"""Form for adding""" |
for param in self.REQUEST.form.keys(): |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self) |
print param |
return pt() |
ret+=param+"="+str(self.REQUEST.form[param])+"&" |
|
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None, |
|
REQUEST=None, submit=None): |
|
"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: |
|
u = self.DestinationURL() |
|
except AttributeError: |
|
u = REQUEST['URL1'] |
|
|
def manage_addZogiLibForm(self): |
u = "%s/%s" % (u, urllib.quote(id)) |
"""interface for adding zogilib""" |
REQUEST.RESPONSE.redirect(u+'/manage_main') |
pt=PageTemplateFile('Products/zogiLib/zpt/addZogiLibForm').__of__(self) |
return '' |
return pt() |
|
|
|
def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,RESPONSE=None): |
|
"""add dgilib""" |
|
newObj=zogiLib(id,title,digilibBaseUrl, localFileBase) |
|
self.Destination()._setObject(id,newObj) |
|
if RESPONSE is not None: |
|
RESPONSE.redirect('manage_main') |
|