version 1.75, 2010/06/18 14:23:20
|
version 1.94, 2010/08/24 12:34:32
|
Line 68 def getHttpData(url, data=None, num_trie
|
Line 68 def getHttpData(url, data=None, num_trie
|
errmsg = None |
errmsg = None |
for cnt in range(num_tries): |
for cnt in range(num_tries): |
try: |
try: |
logging.debug("getHttpData(#%s %ss) url=%s"%(cnt+1,timeout,url)) |
#logging.debug("getHttpData(#%s %ss) url=%s"%(cnt+1,timeout,url)) |
if sys.version_info < (2, 6): |
if sys.version_info < (2, 6): |
# set timeout on socket -- ugly :-( |
# set timeout on socket -- ugly :-( |
import socket |
import socket |
Line 79 def getHttpData(url, data=None, num_trie
|
Line 79 def getHttpData(url, data=None, num_trie
|
# check result? |
# check result? |
break |
break |
except urllib2.HTTPError, e: |
except urllib2.HTTPError, e: |
logging.error("getHttpData: HTTP error(%s): %s"%(e.code,e)) |
#logging.error("getHttpData: HTTP error(%s): %s"%(e.code,e)) |
errmsg = str(e) |
errmsg = str(e) |
# stop trying |
# stop trying |
break |
break |
except urllib2.URLError, e: |
except urllib2.URLError, e: |
logging.error("getHttpData: URLLIB error(%s): %s"%(e.reason,e)) |
#logging.error("getHttpData: URLLIB error(%s): %s"%(e.reason,e)) |
errmsg = str(e) |
errmsg = str(e) |
# stop trying |
# stop trying |
#break |
#break |
Line 119 class documentViewer(Folder):
|
Line 119 class documentViewer(Folder):
|
page_main_images = PageTemplateFile('zpt/page_main_images', globals()) |
page_main_images = PageTemplateFile('zpt/page_main_images', globals()) |
page_main_text = PageTemplateFile('zpt/page_main_text', globals()) |
page_main_text = PageTemplateFile('zpt/page_main_text', globals()) |
page_main_text_dict = PageTemplateFile('zpt/page_main_text_dict', globals()) |
page_main_text_dict = PageTemplateFile('zpt/page_main_text_dict', globals()) |
|
page_main_gis =PageTemplateFile ('zpt/page_main_gis', globals()) |
page_main_xml = PageTemplateFile('zpt/page_main_xml', globals()) |
page_main_xml = PageTemplateFile('zpt/page_main_xml', globals()) |
head_main = PageTemplateFile('zpt/head_main', globals()) |
head_main = PageTemplateFile('zpt/head_main', globals()) |
docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) |
docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) |
Line 202 class documentViewer(Folder):
|
Line 203 class documentViewer(Folder):
|
@param viewMode: if images display images, if text display text, default is images (text,images or auto) |
@param viewMode: if images display images, if text display text, default is images (text,images or auto) |
|
|
''' |
''' |
logging.debug("HHHHHHHHHHHHHH:load the rss") |
#logging.debug("HHHHHHHHHHHHHH:load the rss") |
logger("documentViewer (index)", logging.INFO, "mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) |
#logger("documentViewer (index)", logging.INFO, "mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) |
|
|
if not hasattr(self, 'template'): |
if not hasattr(self, 'template'): |
# create template folder if it doesn't exist |
# create template folder if it doesn't exist |
Line 232 class documentViewer(Folder):
|
Line 233 class documentViewer(Folder):
|
@param url: url which contains display information |
@param url: url which contains display information |
@param viewMode: if images display images, if text display text, default is auto (text,images or auto) |
@param viewMode: if images display images, if text display text, default is auto (text,images or auto) |
@param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
@param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
|
@param characterNormalization type of text display (reg, norm, none) |
@param querySearch: type of different search modes (fulltext, fulltextMorph, xpath, xquery, ftIndex, ftIndexMorph, fulltextMorphLemma) |
@param querySearch: type of different search modes (fulltext, fulltextMorph, xpath, xquery, ftIndex, ftIndexMorph, fulltextMorphLemma) |
''' |
''' |
|
|
logging.debug("documentViewer (index) mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) |
#logging.debug("documentViewer (index) mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) |
|
|
if not hasattr(self, 'template'): |
if not hasattr(self, 'template'): |
# this won't work |
# this won't work |
Line 321 class documentViewer(Folder):
|
Line 323 class documentViewer(Folder):
|
params[param] = str(val) |
params[param] = str(val) |
|
|
# quote values and assemble into query string |
# quote values and assemble into query string |
logging.debug("XYXXXXX: %s"%repr(params.items())) |
#logging.debug("XYXXXXX: %s"%repr(params.items())) |
ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) |
ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) |
url=self.REQUEST['URL1']+"?"+ps |
url=self.REQUEST['URL1']+"?"+ps |
return url |
return url |
Line 340 class documentViewer(Folder):
|
Line 342 class documentViewer(Folder):
|
def isAccessible(self, docinfo): |
def isAccessible(self, docinfo): |
"""returns if access to the resource is granted""" |
"""returns if access to the resource is granted""" |
access = docinfo.get('accessType', None) |
access = docinfo.get('accessType', None) |
logging.debug("documentViewer (accessOK) access type %s"%access) |
#logging.debug("documentViewer (accessOK) access type %s"%access) |
if access is not None and access == 'free': |
if access is not None and access == 'free': |
logging.debug("documentViewer (accessOK) access is free") |
#logging.debug("documentViewer (accessOK) access is free") |
return True |
return True |
elif access is None or access in self.authgroups: |
elif access is None or access in self.authgroups: |
# only local access -- only logged in users |
# only local access -- only logged in users |
user = getSecurityManager().getUser() |
user = getSecurityManager().getUser() |
|
#logging.debug("documentViewer (accessOK) user=%s ip=%s"%(user,self.REQUEST.getClientAddr())) |
if user is not None: |
if user is not None: |
#print "user: ", user |
#print "user: ", user |
return (user.getUserName() != "Anonymous User") |
return (user.getUserName() != "Anonymous User") |
else: |
else: |
return False |
return False |
|
|
logging.debug("documentViewer (accessOK) unknown access type %s"%access) |
#logging.error("documentViewer (accessOK) unknown access type %s"%access) |
return False |
return False |
|
|
|
|
Line 368 class documentViewer(Folder):
|
Line 371 class documentViewer(Folder):
|
|
|
infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path |
infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path |
|
|
logging.debug("documentViewer (getparamfromdigilib) dirInfo from %s"%(infoUrl)) |
#logging.debug("documentViewer (getparamfromdigilib) dirInfo from %s"%(infoUrl)) |
|
|
txt = getHttpData(infoUrl) |
txt = getHttpData(infoUrl) |
if txt is None: |
if txt is None: |
Line 376 class documentViewer(Folder):
|
Line 379 class documentViewer(Folder):
|
|
|
dom = Parse(txt) |
dom = Parse(txt) |
sizes=dom.xpath("//dir/size") |
sizes=dom.xpath("//dir/size") |
logging.debug("documentViewer (getparamfromdigilib) dirInfo:size"%sizes) |
#logging.debug("documentViewer (getparamfromdigilib) dirInfo:size"%sizes) |
|
|
if sizes: |
if sizes: |
docinfo['numPages'] = int(getTextFromNode(sizes[0])) |
docinfo['numPages'] = int(getTextFromNode(sizes[0])) |
Line 402 class documentViewer(Folder):
|
Line 405 class documentViewer(Folder):
|
if not metaUrl.endswith("index.meta"): |
if not metaUrl.endswith("index.meta"): |
metaUrl += "/index.meta" |
metaUrl += "/index.meta" |
|
|
logging.debug("(getIndexMeta): METAURL: %s"%metaUrl) |
#logging.debug("(getIndexMeta): METAURL: %s"%metaUrl) |
txt=getHttpData(metaUrl) |
txt=getHttpData(metaUrl) |
if txt is None: |
if txt is None: |
raise IOError("Unable to read index meta from %s"%(url)) |
raise IOError("Unable to read index meta from %s"%(url)) |
Line 432 class documentViewer(Folder):
|
Line 435 class documentViewer(Folder):
|
|
|
def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): |
def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): |
"""gets authorization info from the index.meta file at path or given by dom""" |
"""gets authorization info from the index.meta file at path or given by dom""" |
logging.debug("documentViewer (getauthinfofromindexmeta) path: %s"%(path)) |
#logging.debug("documentViewer (getauthinfofromindexmeta) path: %s"%(path)) |
|
|
access = None |
access = None |
|
|
Line 456 class documentViewer(Folder):
|
Line 459 class documentViewer(Folder):
|
|
|
def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): |
def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): |
"""gets bibliographical info from the index.meta file at path or given by dom""" |
"""gets bibliographical info from the index.meta file at path or given by dom""" |
logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path)) |
#logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path)) |
|
|
if docinfo is None: |
if docinfo is None: |
docinfo = {} |
docinfo = {} |
Line 466 class documentViewer(Folder):
|
Line 469 class documentViewer(Folder):
|
path=getParentDir(path) |
path=getParentDir(path) |
dom = self.getIndexMeta(path) |
dom = self.getIndexMeta(path) |
|
|
logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path)) |
#logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path)) |
# put in all raw bib fields as dict "bib" |
# put in all raw bib fields as dict "bib" |
bib = dom.xpath("//bib/*") |
bib = dom.xpath("//bib/*") |
if bib and len(bib)>0: |
if bib and len(bib)>0: |
Line 497 class documentViewer(Folder):
|
Line 500 class documentViewer(Folder):
|
try: |
try: |
docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0]) |
docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0]) |
except: pass |
except: pass |
logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype) |
#logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype) |
try: |
try: |
docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) |
docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) |
except: |
except: |
Line 508 class documentViewer(Folder):
|
Line 511 class documentViewer(Folder):
|
|
|
def getDocinfoFromTextTool(self, url, dom=None, docinfo=None): |
def getDocinfoFromTextTool(self, url, dom=None, docinfo=None): |
"""parse texttool tag in index meta""" |
"""parse texttool tag in index meta""" |
logging.debug("documentViewer (getdocinfofromtexttool) url: %s" % (url)) |
#logging.debug("documentViewer (getdocinfofromtexttool) url: %s" % (url)) |
if docinfo is None: |
if docinfo is None: |
docinfo = {} |
docinfo = {} |
if docinfo.get('lang', None) is None: |
if docinfo.get('lang', None) is None: |
Line 535 class documentViewer(Folder):
|
Line 538 class documentViewer(Folder):
|
archivePath += "/" + archiveName |
archivePath += "/" + archiveName |
else: |
else: |
# try to get archive-path from url |
# try to get archive-path from url |
logging.warning("documentViewer (getdocinfofromtexttool) resource/archive-path missing in: %s" % (url)) |
#logging.warning("documentViewer (getdocinfofromtexttool) resource/archive-path missing in: %s" % (url)) |
if (not url.startswith('http')): |
if (not url.startswith('http')): |
archivePath = url.replace('index.meta', '') |
archivePath = url.replace('index.meta', '') |
|
|
Line 629 class documentViewer(Folder):
|
Line 632 class documentViewer(Folder):
|
|
|
def getDocinfoFromImagePath(self,path,docinfo=None,cut=0): |
def getDocinfoFromImagePath(self,path,docinfo=None,cut=0): |
"""path ist the path to the images it assumes that the index.meta file is one level higher.""" |
"""path ist the path to the images it assumes that the index.meta file is one level higher.""" |
logging.debug("documentViewer (getdocinfofromimagepath) path: %s"%(path)) |
#logging.debug("documentViewer (getdocinfofromimagepath) path: %s"%(path)) |
if docinfo is None: |
if docinfo is None: |
docinfo = {} |
docinfo = {} |
path=path.replace("/mpiwg/online","") |
path=path.replace("/mpiwg/online","") |
Line 639 class documentViewer(Folder):
|
Line 642 class documentViewer(Folder):
|
pathorig=path |
pathorig=path |
for x in range(cut): |
for x in range(cut): |
path=getParentDir(path) |
path=getParentDir(path) |
logging.debug("documentViewer (getdocinfofromimagepath) PATH:"+path) |
#logging.debug("documentViewer (getdocinfofromimagepath) PATH:"+path) |
imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path |
imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path |
docinfo['imageURL'] = imageUrl |
docinfo['imageURL'] = imageUrl |
|
|
Line 651 class documentViewer(Folder):
|
Line 654 class documentViewer(Folder):
|
|
|
def getDocinfo(self, mode, url): |
def getDocinfo(self, mode, url): |
"""returns docinfo depending on mode""" |
"""returns docinfo depending on mode""" |
logging.debug("documentViewer (getdocinfo) mode: %s, url: %s"%(mode,url)) |
#logging.debug("documentViewer (getdocinfo) mode: %s, url: %s"%(mode,url)) |
# look for cached docinfo in session |
# look for cached docinfo in session |
if self.REQUEST.SESSION.has_key('docinfo'): |
if self.REQUEST.SESSION.has_key('docinfo'): |
docinfo = self.REQUEST.SESSION['docinfo'] |
docinfo = self.REQUEST.SESSION['docinfo'] |
# check if its still current |
# check if its still current |
if docinfo is not None and docinfo.get('mode') == mode and docinfo.get('url') == url: |
if docinfo is not None and docinfo.get('mode') == mode and docinfo.get('url') == url: |
logging.debug("documentViewer (getdocinfo) docinfo in session: %s"%docinfo) |
#logging.debug("documentViewer (getdocinfo) docinfo in session: %s"%docinfo) |
return docinfo |
return docinfo |
# new docinfo |
# new docinfo |
docinfo = {'mode': mode, 'url': url} |
docinfo = {'mode': mode, 'url': url} |
Line 668 class documentViewer(Folder):
|
Line 671 class documentViewer(Folder):
|
elif mode=="filepath": |
elif mode=="filepath": |
docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo,cut=1) |
docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo,cut=1) |
else: |
else: |
logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode) |
#logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode) |
raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode)) |
raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode)) |
|
|
logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo) |
#logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo) |
self.REQUEST.SESSION['docinfo'] = docinfo |
self.REQUEST.SESSION['docinfo'] = docinfo |
return docinfo |
return docinfo |
|
|
Line 698 class documentViewer(Folder):
|
Line 701 class documentViewer(Folder):
|
pageinfo['numgroups'] += 1 |
pageinfo['numgroups'] += 1 |
pageinfo['viewMode'] = viewMode |
pageinfo['viewMode'] = viewMode |
pageinfo['tocMode'] = tocMode |
pageinfo['tocMode'] = tocMode |
|
pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','') |
pageinfo['query'] = self.REQUEST.get('query',' ') |
pageinfo['query'] = self.REQUEST.get('query',' ') |
pageinfo['queryType'] = self.REQUEST.get('queryType',' ') |
pageinfo['queryType'] = self.REQUEST.get('queryType',' ') |
pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') |
pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') |
Line 763 def manage_addDocumentViewerTemplate(sel
|
Line 767 def manage_addDocumentViewerTemplate(sel
|
self._setObject(id, DocumentViewerTemplate(id)) |
self._setObject(id, DocumentViewerTemplate(id)) |
ob = getattr(self, id) |
ob = getattr(self, id) |
txt=file(os.path.join(package_home(globals()),'zpt/viewer_main.zpt'),'r').read() |
txt=file(os.path.join(package_home(globals()),'zpt/viewer_main.zpt'),'r').read() |
logging.info("txt %s:"%txt) |
#logging.info("txt %s:"%txt) |
ob.pt_edit(txt,"text/html") |
ob.pt_edit(txt,"text/html") |
if title: |
if title: |
ob.pt_setTitle(title) |
ob.pt_setTitle(title) |