version 1.7, 2006/04/10 19:51:50
|
version 1.8, 2006/04/11 17:27:57
|
Line 1
|
Line 1
|
|
|
genericDigilib="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/" |
|
|
|
from OFS.Folder import Folder |
from OFS.Folder import Folder |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from AccessControl import ClassSecurityInfo |
from AccessControl import ClassSecurityInfo |
|
from AccessControl import getSecurityManager |
from Globals import package_home |
from Globals import package_home |
|
|
from Ft.Xml.Domlette import NonvalidatingReader |
from Ft.Xml.Domlette import NonvalidatingReader |
Line 28 def getInt(number, default=0):
|
Line 26 def getInt(number, default=0):
|
|
|
|
|
def getTextFromNode(nodename): |
def getTextFromNode(nodename): |
|
if nodename is None: |
|
return "" |
nodelist=nodename.childNodes |
nodelist=nodename.childNodes |
rc = "" |
rc = "" |
for node in nodelist: |
for node in nodelist: |
Line 37 def getTextFromNode(nodename):
|
Line 37 def getTextFromNode(nodename):
|
|
|
import socket |
import socket |
|
|
def urlopen(url): |
def urlopen(url,timeout=2): |
"""urlopen mit timeout""" |
"""urlopen mit timeout""" |
socket.setdefaulttimeout(2) |
socket.setdefaulttimeout(timeout) |
ret=urllib.urlopen(url) |
ret=urllib.urlopen(url) |
socket.setdefaulttimeout(5) |
socket.setdefaulttimeout(5) |
return ret |
return ret |
Line 69 class documentViewer(Folder):
|
Line 69 class documentViewer(Folder):
|
changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) |
changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) |
|
|
|
|
def __init__(self,id,imageViewerUrl,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=10): |
def __init__(self,id,imageViewerUrl,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=10,authgroups="mpiwg"): |
"""init document viewer""" |
"""init document viewer""" |
self.id=id |
self.id=id |
self.title=title |
self.title=title |
Line 80 class documentViewer(Folder):
|
Line 80 class documentViewer(Folder):
|
self.digilibBaseUrl = digilibBaseUrl |
self.digilibBaseUrl = digilibBaseUrl |
self.thumbcols = thumbcols |
self.thumbcols = thumbcols |
self.thumbrows = thumbrows |
self.thumbrows = thumbrows |
|
# authgroups is list of authorized groups (delimited by ,) |
|
self.authgroups = [s.strip().lower() for s in authgroups.split(',')] |
# add template folder so we can always use template.something |
# add template folder so we can always use template.something |
self.manage_addFolder('template') |
self.manage_addFolder('template') |
|
|
Line 131 class documentViewer(Folder):
|
Line 133 class documentViewer(Folder):
|
else: |
else: |
return style |
return style |
|
|
|
def accessOK(self, docinfo): |
|
"""returns if access to the resource is granted""" |
|
access = docinfo.get('accessType', None) |
|
if access is None: |
|
# no information - no access (not yet) |
|
return True |
|
elif access == 'free': |
|
return True |
|
|
|
print "access: ", access, " authgroups: ", self.authgroups |
|
if access in self.authgroups: |
|
# local access OK |
|
user = getSecurityManager().getUser().getUserName() |
|
print "user: ", user |
|
return (user != "Anonymous User") |
|
|
|
zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access group %s"%access) |
|
return False |
|
|
|
|
def getDirinfoFromDigilib(self,path,docinfo=None): |
def getDirinfoFromDigilib(self,path,docinfo=None): |
"""gibt param von dlInfo aus""" |
"""gibt param von dlInfo aus""" |
Line 151 class documentViewer(Folder):
|
Line 172 class documentViewer(Folder):
|
zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo:size"%params) |
zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo:size"%params) |
|
|
if params: |
if params: |
docinfo['numPages'] = getTextFromNode(params[0]) |
docinfo['numPages'] = int(getTextFromNode(params[0])) |
else: |
else: |
docinfo['numPages'] = 0 |
docinfo['numPages'] = 0 |
|
|
return docinfo |
return docinfo |
|
|
|
|
|
def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): |
|
"""gets authorization info from the index.meta file at url or given by dom""" |
|
zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) |
|
|
|
access = None |
|
|
|
if docinfo is None: |
|
docinfo = {} |
|
|
|
if dom is None: |
|
server=self.digilibBaseUrl+"/servlet/Texter?fn=" |
|
path="/".join(path.split("/")[0:-1]) |
|
metaUrl=server+path+"/index.meta" |
|
try: |
|
dom = NonvalidatingReader.parseUri(metaUrl) |
|
except: |
|
return docinfo |
|
|
|
acctype = dom.xpath("//access-conditions/access/@type") |
|
if acctype and (len(acctype)>0): |
|
access=acctype[0].value |
|
if access == 'group': |
|
access = getTextFromNode(dom.xpath("//access-conditions/access/name")[0]).lower() |
|
|
|
docinfo['accessType'] = access |
|
return docinfo |
|
|
|
|
def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): |
def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): |
"""gets bibliographical info from the index.meta file at url or given by dom""" |
"""gets bibliographical info from the index.meta file at url or given by dom""" |
zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) |
zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) |
Line 183 class documentViewer(Folder):
|
Line 232 class documentViewer(Folder):
|
bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) |
bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) |
bibmap=metaData.generateMappingForType(bibtype) |
bibmap=metaData.generateMappingForType(bibtype) |
print "bibmap: ", bibmap, " for: ", bibtype |
print "bibmap: ", bibmap, " for: ", bibtype |
|
# if there is no mapping bibmap is empty (mapping sometimes has empty fields) |
if len(bibmap) > 0 and len(bibmap['author'][0]) > 0: |
if len(bibmap) > 0 and len(bibmap['author'][0]) > 0: |
docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0]) |
docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0]) |
docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0]) |
docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0]) |
Line 191 class documentViewer(Folder):
|
Line 241 class documentViewer(Folder):
|
return docinfo |
return docinfo |
|
|
|
|
def getDocinfoFromTextTool(self,url,docinfo=None): |
def getDocinfoFromTextTool(self,url,dom=None,docinfo=None): |
"""parse texttool tag in index meta""" |
"""parse texttool tag in index meta""" |
zLOG.LOG("documentViewer (getdocinfofromtexttool)", zLOG.INFO,"url: %s"%(url)) |
zLOG.LOG("documentViewer (getdocinfofromtexttool)", zLOG.INFO,"url: %s"%(url)) |
if docinfo is None: |
if docinfo is None: |
docinfo = {} |
docinfo = {} |
|
|
|
if dom is None: |
try: |
try: |
dom = NonvalidatingReader.parseUri(url) |
dom = NonvalidatingReader.parseUri(url) |
except: |
except: |
zLOG.LOG("documentViewer (parseUrlTexttool)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) |
zLOG.LOG("documentViewer (parseUrlTexttool)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) |
raise IOError("Unable to get texttool info from %s"%(url)) |
raise IOError("Unable to get texttool info from %s"%(url)) |
|
|
|
archiveNames=dom.xpath("//resource/name") |
|
if archiveNames and (len(archiveNames)>0): |
|
archiveName=getTextFromNode(archiveNames[0]) |
|
|
archivePaths=dom.xpath("//resource/archive-path") |
archivePaths=dom.xpath("//resource/archive-path") |
if archivePaths and (len(archivePaths)>0): |
if archivePaths and (len(archivePaths)>0): |
archivePath=getTextFromNode(archivePaths[0]) |
archivePath=getTextFromNode(archivePaths[0]) |
|
# clean up archive path |
|
if archivePath[0] != '/': |
|
archivePath = '/' + archivePath |
|
if not archivePath.endswith(archiveName): |
|
archivePath += "/" + archiveName |
else: |
else: |
archivePath=None |
archivePath=None |
|
|
Line 216 class documentViewer(Folder):
|
Line 276 class documentViewer(Folder):
|
image=None |
image=None |
|
|
if image and archivePath: |
if image and archivePath: |
|
print "image: ", image, " archivepath: ", archivePath |
image=os.path.join(archivePath,image) |
image=os.path.join(archivePath,image) |
image=image.replace("/mpiwg/online",'') |
image=image.replace("/mpiwg/online",'') |
docinfo=self.getDirinfoFromDigilib(image,docinfo=docinfo) |
docinfo=self.getDirinfoFromDigilib(image,docinfo=docinfo) |
Line 233 class documentViewer(Folder):
|
Line 294 class documentViewer(Folder):
|
docinfo['textURL'] = textUrl |
docinfo['textURL'] = textUrl |
|
|
docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) |
docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) |
|
docinfo = self.getAuthinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) |
return docinfo |
return docinfo |
|
|
|
|
Line 248 class documentViewer(Folder):
|
Line 310 class documentViewer(Folder):
|
docinfo['imageURL'] = imageUrl |
docinfo['imageURL'] = imageUrl |
|
|
docinfo = self.getBibinfoFromIndexMeta(path,docinfo=docinfo) |
docinfo = self.getBibinfoFromIndexMeta(path,docinfo=docinfo) |
|
docinfo = self.getAuthinfoFromIndexMeta(path,docinfo=docinfo) |
return docinfo |
return docinfo |
|
|
|
|
Line 360 class documentViewer(Folder):
|
Line 423 class documentViewer(Folder):
|
except: |
except: |
return None |
return None |
|
|
def changeDocumentViewer(self,imageViewerUrl,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=10,RESPONSE=None): |
def changeDocumentViewer(self,imageViewerUrl,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=10,authgroups='mpiwg',RESPONSE=None): |
"""init document viewer""" |
"""init document viewer""" |
self.title=title |
self.title=title |
self.imageViewerUrl=imageViewerUrl |
self.imageViewerUrl=imageViewerUrl |
self.digilibBaseUrl = digilibBaseUrl |
self.digilibBaseUrl = digilibBaseUrl |
self.thumbrows = thumbrows |
self.thumbrows = thumbrows |
self.thumbcols = thumbcols |
self.thumbcols = thumbcols |
|
self.authgroups = [s.strip().lower() for s in authgroups.split(',')] |
if RESPONSE is not None: |
if RESPONSE is not None: |
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |
|
|