|
|
| version 1.94, 2010/08/24 12:34:32 | version 1.178, 2012/01/04 07:38:17 |
|---|---|
| Line 5 from Products.PageTemplates.PageTemplate | Line 5 from Products.PageTemplates.PageTemplate |
| from AccessControl import ClassSecurityInfo | from AccessControl import ClassSecurityInfo |
| from AccessControl import getSecurityManager | from AccessControl import getSecurityManager |
| from Globals import package_home | from Globals import package_home |
| from Products.zogiLib.zogiLib import browserCheck | |
| from Ft.Xml import EMPTY_NAMESPACE, Parse | from Ft.Xml import EMPTY_NAMESPACE, Parse |
| import Ft.Xml.Domlette | import Ft.Xml.Domlette |
| Line 16 import logging | Line 17 import logging |
| import math | import math |
| import urlparse | import urlparse |
| import cStringIO | import cStringIO |
| import re | |
| import string | |
| def logger(txt,method,txt2): | def logger(txt,method,txt2): |
| """logging""" | """logging""" |
| Line 40 def getTextFromNode(nodename): | Line 43 def getTextFromNode(nodename): |
| rc = rc + node.data | rc = rc + node.data |
| return rc | return rc |
| def serializeNode(node, encoding='utf-8'): | def serializeNode(node, encoding="utf-8"): |
| """returns a string containing node as XML""" | """returns a string containing node as XML""" |
| buf = cStringIO.StringIO() | stream = cStringIO.StringIO() |
| Ft.Xml.Domlette.Print(node, stream=buf, encoding=encoding) | #logging.debug("BUF: %s"%(stream)) |
| s = buf.getvalue() | Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding) |
| buf.close() | s = stream.getvalue() |
| #logging.debug("BUF: %s"%(s)) | |
| stream.close() | |
| return s | return s |
| 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 | |
| bt['versFirefox']="" | |
| bt['versIE']="" | |
| bt['versSafariChrome']="" | |
| bt['versOpera']="" | |
| if string.find(ua, 'MSIE') > -1: | |
| bt['isIE'] = True | |
| else: | |
| bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) | |
| # Safari oder Chrome identification | |
| try: | |
| nav = ua[string.find(ua, '('):] | |
| nav1=ua[string.find(ua,')'):] | |
| nav2=nav1[string.find(nav1,'('):] | |
| nav3=nav2[string.find(nav2,')'):] | |
| ie = string.split(nav, "; ")[1] | |
| ie1 =string.split(nav1, " ")[2] | |
| ie2 =string.split(nav3, " ")[1] | |
| ie3 =string.split(nav3, " ")[2] | |
| if string.find(ie3, "Safari") >-1: | |
| bt['versSafariChrome']=string.split(ie2, "/")[1] | |
| except: pass | |
| # IE identification | |
| 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 | |
| # Firefox identification | |
| try: | |
| nav = ua[string.find(ua, '('):] | |
| nav1=ua[string.find(ua,')'):] | |
| if string.find(ie1, "Firefox") >-1: | |
| nav5= string.split(ie1, "/")[1] | |
| logging.debug("FIREFOX: %s"%(nav5)) | |
| bt['versFirefox']=nav5[0:3] | |
| except:pass | |
| #Opera identification | |
| try: | |
| if string.find(ua,"Opera") >-1: | |
| nav = ua[string.find(ua, '('):] | |
| nav1=nav[string.find(nav,')'):] | |
| bt['versOpera']=string.split(nav1,"/")[2] | |
| 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 | |
| def getParentDir(path): | def getParentDir(path): |
| """returns pathname shortened by one""" | """returns pathname shortened by one""" |
| Line 68 def getHttpData(url, data=None, num_trie | Line 134 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 145 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 97 def getHttpData(url, data=None, num_trie | Line 163 def getHttpData(url, data=None, num_trie |
| raise IOError("ERROR fetching HTTP data from %s: %s"%(url,errmsg)) | raise IOError("ERROR fetching HTTP data from %s: %s"%(url,errmsg)) |
| #return None | #return None |
| ## | ## |
| ## documentViewer class | ## documentViewer class |
| ## | ## |
| Line 117 class documentViewer(Folder): | Line 181 class documentViewer(Folder): |
| toc_text = PageTemplateFile('zpt/toc_text', globals()) | toc_text = PageTemplateFile('zpt/toc_text', globals()) |
| toc_figures = PageTemplateFile('zpt/toc_figures', globals()) | toc_figures = PageTemplateFile('zpt/toc_figures', globals()) |
| page_main_images = PageTemplateFile('zpt/page_main_images', globals()) | page_main_images = PageTemplateFile('zpt/page_main_images', globals()) |
| page_main_double = PageTemplateFile('zpt/page_main_double', 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_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()) |
| page_main_pureXml = PageTemplateFile('zpt/page_main_pureXml', 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()) |
| info_xml = PageTemplateFile('zpt/info_xml', globals()) | info_xml = PageTemplateFile('zpt/info_xml', globals()) |
| Line 165 class documentViewer(Folder): | Line 231 class documentViewer(Folder): |
| """get page""" | """get page""" |
| return self.template.fulltextclient.getTextPage(**args) | return self.template.fulltextclient.getTextPage(**args) |
| def getOrigPages(self, **args): | |
| """get page""" | |
| return self.template.fulltextclient.getOrigPages(**args) | |
| def getOrigPagesNorm(self, **args): | |
| """get page""" | |
| return self.template.fulltextclient.getOrigPagesNorm(**args) | |
| def getQuery(self, **args): | def getQuery(self, **args): |
| """get query""" | """get query in search""" |
| return self.template.fulltextclient.getQuery(**args) | return self.template.fulltextclient.getQuery(**args) |
| def getSearch(self, **args): | def getSearch(self, **args): |
| """get search""" | """get search""" |
| return self.template.fulltextclient.getSearch(**args) | return self.template.fulltextclient.getSearch(**args) |
| def getNumPages(self, docinfo): | def getGisPlaces(self, **args): |
| """get numpages""" | """get gis places""" |
| return self.template.fulltextclient.getNumPages(docinfo) | return self.template.fulltextclient.getGisPlaces(**args) |
| def getAllGisPlaces(self, **args): | |
| """get all gis places """ | |
| return self.template.fulltextclient.getAllGisPlaces(**args) | |
| def getTranslate(self, **args): | def getTranslate(self, **args): |
| """get translate""" | """get translate""" |
| Line 185 class documentViewer(Folder): | Line 263 class documentViewer(Folder): |
| """get lemma""" | """get lemma""" |
| return self.template.fulltextclient.getLemma(**args) | return self.template.fulltextclient.getLemma(**args) |
| def getLemmaQuery(self, **args): | |
| """get query""" | |
| return self.template.fulltextclient.getLemmaQuery(**args) | |
| def getLex(self, **args): | |
| """get lex""" | |
| return self.template.fulltextclient.getLex(**args) | |
| def getToc(self, **args): | def getToc(self, **args): |
| """get toc""" | """get toc""" |
| return self.template.fulltextclient.getToc(**args) | return self.template.fulltextclient.getToc(**args) |
| Line 203 class documentViewer(Folder): | Line 289 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 214 class documentViewer(Folder): | Line 300 class documentViewer(Folder): |
| self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" | self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" |
| docinfo = self.getDocinfo(mode=mode,url=url) | docinfo = self.getDocinfo(mode=mode,url=url) |
| #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) | |
| pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) | pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) |
| ''' ZDES ''' | |
| pt = getattr(self.template, 'thumbs_main_rss') | pt = getattr(self.template, 'thumbs_main_rss') |
| if viewMode=="auto": # automodus gewaehlt | if viewMode=="auto": # automodus gewaehlt |
| if docinfo.has_key("textURL") or docinfo.has_key('textURLPath'): #texturl gesetzt und textViewer konfiguriert | if docinfo.has_key("textURL") or docinfo.get('textURLPath',None): #texturl gesetzt und textViewer konfiguriert |
| viewMode="text" | viewMode="text" |
| else: | else: |
| viewMode="images" | viewMode="images" |
| Line 226 class documentViewer(Folder): | Line 314 class documentViewer(Folder): |
| return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) | return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) |
| security.declareProtected('View','index_html') | security.declareProtected('View','index_html') |
| def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None, query=None, querySearch=None): | def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None): |
| ''' | ''' |
| view it | view it |
| @param mode: defines how to access the document behind url | @param mode: defines how to access the document behind url |
| Line 237 class documentViewer(Folder): | Line 325 class documentViewer(Folder): |
| @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 254 class documentViewer(Folder): | Line 342 class documentViewer(Folder): |
| docinfo = self.getToc(mode=tocMode, docinfo=docinfo) | docinfo = self.getToc(mode=tocMode, docinfo=docinfo) |
| if viewMode=="auto": # automodus gewaehlt | if viewMode=="auto": # automodus gewaehlt |
| if docinfo.has_key('textURL') or docinfo.has_key('textURLPath'): #texturl gesetzt und textViewer konfiguriert | if docinfo.has_key('textURL') or docinfo.get('textURLPath',None): #texturl gesetzt und textViewer konfiguriert |
| viewMode="text_dict" | viewMode="text_dict" |
| else: | else: |
| viewMode="images" | viewMode="images" |
| pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo,viewMode=viewMode,tocMode=tocMode) | pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo,viewMode=viewMode,tocMode=tocMode) |
| pt = getattr(self.template, 'viewer_main') | if (docinfo.get('textURLPath',None)): |
| page = self.getTextPage(docinfo=docinfo, pageinfo=pageinfo) | |
| pageinfo['textPage'] = page | |
| tt = getattr(self, 'template') | |
| pt = getattr(tt, 'viewer_main') | |
| return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode,mk=self.generateMarks(mk)) | return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode,mk=self.generateMarks(mk)) |
| def generateMarks(self,mk): | def generateMarks(self,mk): |
| Line 275 class documentViewer(Folder): | Line 367 class documentViewer(Folder): |
| return ret | return ret |
| def getBrowser(self): | |
| """getBrowser the version of browser """ | |
| bt = browserCheck(self) | |
| logging.debug("BROWSER VERSION: %s"%(bt)) | |
| return bt | |
| def findDigilibUrl(self): | def findDigilibUrl(self): |
| """try to get the digilib URL from zogilib""" | """try to get the digilib URL from zogilib""" |
| url = self.template.zogilib.getDLBaseUrl() | url = self.template.zogilib.getDLBaseUrl() |
| Line 292 class documentViewer(Folder): | Line 390 class documentViewer(Folder): |
| else: | else: |
| return style | return style |
| def getLink(self,param=None,val=None): | def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&'): |
| """link to documentviewer with parameter param set to val""" | """returns URL to documentviewer with parameter param set to val or from dict params""" |
| params=self.REQUEST.form.copy() | # copy existing request params |
| urlParams=self.REQUEST.form.copy() | |
| # change single param | |
| if param is not None: | if param is not None: |
| if val is None: | if val is None: |
| if params.has_key(param): | if urlParams.has_key(param): |
| del params[param] | del urlParams[param] |
| else: | else: |
| params[param] = str(val) | urlParams[param] = str(val) |
| # change more params | |
| if params is not None: | |
| for k in params.keys(): | |
| v = params[k] | |
| if v is None: | |
| # val=None removes param | |
| if urlParams.has_key(k): | |
| del urlParams[k] | |
| else: | |
| urlParams[k] = v | |
| # FIXME: does this belong here? | |
| if urlParams.get("mode", None) == "filepath": #wenn beim erst Aufruf filepath gesetzt wurde aendere das nun zu imagepath | |
| urlParams["mode"] = "imagepath" | |
| urlParams["url"] = getParentDir(urlParams["url"]) | |
| # quote values and assemble into query string (not escaping '/') | |
| ps = paramSep.join(["%s=%s"%(k,urllib.quote_plus(v,'/')) for (k, v) in urlParams.items()]) | |
| #ps = urllib.urlencode(urlParams) | |
| if baseUrl is None: | |
| baseUrl = self.REQUEST['URL1'] | |
| if params.get("mode", None) == "filepath": #wenn beim erst Aufruf filepath gesetzt wurde aendere das nun zu imagepath | url = "%s?%s"%(baseUrl, ps) |
| params["mode"] = "imagepath" | |
| params["url"] = getParentDir(params["url"]) | |
| # quote values and assemble into query string | |
| #ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) | |
| ps = urllib.urlencode(params) | |
| url=self.REQUEST['URL1']+"?"+ps | |
| return url | return url |
| def getLinkAmp(self,param=None,val=None): | |
| """link to documentviewer with parameter param set to val""" | |
| params=self.REQUEST.form.copy() | |
| if param is not None: | |
| if val is None: | |
| if params.has_key(param): | |
| del params[param] | |
| else: | |
| params[param] = str(val) | |
| # quote values and assemble into query string | def getLinkAmp(self, param=None, val=None, params=None, baseUrl=None): |
| #logging.debug("XYXXXXX: %s"%repr(params.items())) | """link to documentviewer with parameter param set to val""" |
| ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) | return self.getLink(param, val, params, baseUrl, '&') |
| url=self.REQUEST['URL1']+"?"+ps | |
| return url | |
| def getInfo_xml(self,url,mode): | def getInfo_xml(self,url,mode): |
| """returns info about the document as XML""" | """returns info about the document as XML""" |
| Line 338 class documentViewer(Folder): | Line 443 class documentViewer(Folder): |
| pt = getattr(self.template, 'info_xml') | pt = getattr(self.template, 'info_xml') |
| return pt(docinfo=docinfo) | return pt(docinfo=docinfo) |
| def getOptionToggle(self, newState=None, optionName='text_options_open', initialState=True): | |
| """returns new option state""" | |
| if not self.REQUEST.SESSION.has_key(optionName): | |
| # not in session -- initial | |
| opt = {'lastState': newState, 'state': initialState} | |
| else: | |
| opt = self.REQUEST.SESSION.get(optionName) | |
| if opt['lastState'] != newState: | |
| # state in session has changed -- toggle | |
| opt['state'] = not opt['state'] | |
| opt['lastState'] = newState | |
| self.REQUEST.SESSION[optionName] = opt | |
| return opt['state'] | |
| 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())) | 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.error("documentViewer (accessOK) unknown access type %s"%access) | logging.error("documentViewer (accessOK) unknown access type %s"%access) |
| return False | return False |
| Line 371 class documentViewer(Folder): | Line 490 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 379 class documentViewer(Folder): | Line 498 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 390 class documentViewer(Folder): | Line 509 class documentViewer(Folder): |
| return docinfo | return docinfo |
| def getIndexMetaPath(self,url): | |
| """gib nur den Pfad zurueck""" | |
| regexp = re.compile(r".*(experimental|permanent)/(.*)") | |
| regpath = regexp.match(url) | |
| if (regpath==None): | |
| return "" | |
| logging.debug("(getDomFromIndexMeta): URLXAXA: %s"%regpath.group(2)) | |
| return ("/mpiwg/online/"+regpath.group(1)+"/"+regpath.group(2)) | |
| def getIndexMetaUrl(self,url): | |
| """returns utr of index.meta document at url""" | |
| def getIndexMeta(self, url): | |
| """returns dom of index.meta document at url""" | |
| dom = None | |
| metaUrl = None | metaUrl = None |
| if url.startswith("http://"): | if url.startswith("http://"): |
| # real URL | # real URL |
| Line 405 class documentViewer(Folder): | Line 534 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) | return metaUrl |
| def getDomFromIndexMeta(self, url): | |
| """get dom from index meta""" | |
| dom = None | |
| metaUrl = self.getIndexMetaUrl(url) | |
| logging.debug("(getDomFromIndexMeta): 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 435 class documentViewer(Folder): | Line 571 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 445 class documentViewer(Folder): | Line 581 class documentViewer(Folder): |
| if dom is None: | if dom is None: |
| for x in range(cut): | for x in range(cut): |
| path=getParentDir(path) | path=getParentDir(path) |
| dom = self.getIndexMeta(path) | dom = self.getDomFromIndexMeta(path) |
| acctype = dom.xpath("//access-conditions/access/@type") | acctype = dom.xpath("//access-conditions/access/@type") |
| if acctype and (len(acctype)>0): | if acctype and (len(acctype)>0): |
| Line 467 class documentViewer(Folder): | Line 603 class documentViewer(Folder): |
| if dom is None: | if dom is None: |
| for x in range(cut): | for x in range(cut): |
| path=getParentDir(path) | path=getParentDir(path) |
| dom = self.getIndexMeta(path) | dom = self.getDomFromIndexMeta(path) |
| docinfo['indexMetaPath']=self.getIndexMetaPath(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" |
| Line 489 class documentViewer(Folder): | Line 627 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) |
| docinfo['bib_type'] = bibtype | docinfo['bib_type'] = bibtype |
| bibmap=metaData.generateMappingForType(bibtype) | bibmap=metaData.generateMappingForType(bibtype) |
| #logging.debug("documentViewer (getbibinfofromindexmeta) bibmap:"+repr(bibmap)) | |
| #logging.debug("documentViewer (getbibinfofromindexmeta) bibtype:"+repr(bibtype)) | |
| # if there is no mapping bibmap is empty (mapping sometimes has empty fields) | # 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: |
| try: | try: |
| Line 505 class documentViewer(Folder): | Line 645 class documentViewer(Folder): |
| docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) | docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) |
| except: | except: |
| docinfo['lang']='' | docinfo['lang']='' |
| try: | |
| docinfo['city']=getTextFromNode(dom.xpath("//bib/city")[0]) | |
| except: | |
| docinfo['city']='' | |
| try: | |
| docinfo['number_of_pages']=getTextFromNode(dom.xpath("//bib/number_of_pages")[0]) | |
| except: | |
| docinfo['number_of_pages']='' | |
| try: | |
| docinfo['series_volume']=getTextFromNode(dom.xpath("//bib/series_volume")[0]) | |
| except: | |
| docinfo['series_volume']='' | |
| try: | |
| docinfo['number_of_volumes']=getTextFromNode(dom.xpath("//bib/number_of_volumes")[0]) | |
| except: | |
| docinfo['number_of_volumes']='' | |
| try: | |
| docinfo['translator']=getTextFromNode(dom.xpath("//bib/translator")[0]) | |
| except: | |
| docinfo['translator']='' | |
| try: | |
| docinfo['edition']=getTextFromNode(dom.xpath("//bib/edition")[0]) | |
| except: | |
| docinfo['edition']='' | |
| try: | |
| docinfo['series_author']=getTextFromNode(dom.xpath("//bib/series_author")[0]) | |
| except: | |
| docinfo['series_author']='' | |
| try: | |
| docinfo['publisher']=getTextFromNode(dom.xpath("//bib/publisher")[0]) | |
| except: | |
| docinfo['publisher']='' | |
| try: | |
| docinfo['series_title']=getTextFromNode(dom.xpath("//bib/series_title")[0]) | |
| except: | |
| docinfo['series_title']='' | |
| try: | |
| docinfo['isbn_issn']=getTextFromNode(dom.xpath("//bib/isbn_issn")[0]) | |
| except: | |
| docinfo['isbn_issn']='' | |
| #logging.debug("I NEED BIBTEX %s"%docinfo) | |
| return docinfo | return docinfo |
| def getNameFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): | |
| """gets name info from the index.meta file at path or given by dom""" | |
| if docinfo is None: | |
| docinfo = {} | |
| if dom is None: | |
| for x in range(cut): | |
| path=getParentDir(path) | |
| dom = self.getDomFromIndexMeta(path) | |
| docinfo['name']=getTextFromNode(dom.xpath("/resource/name")[0]) | |
| logging.debug("documentViewer docinfo[name] %s"%docinfo['name']) | |
| return docinfo | |
| 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: |
| docinfo['lang'] = '' # default keine Sprache gesetzt | docinfo['lang'] = '' # default keine Sprache gesetzt |
| if dom is None: | if dom is None: |
| dom = self.getIndexMeta(url) | dom = self.getDomFromIndexMeta(url) |
| archivePath = None | archivePath = None |
| archiveName = None | archiveName = None |
| Line 538 class documentViewer(Folder): | Line 732 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 584 class documentViewer(Folder): | Line 778 class documentViewer(Folder): |
| docinfo['textURL'] = textUrl | docinfo['textURL'] = textUrl |
| #TODO: hack-DW for annalen | |
| if (textUrl is not None) and (textUrl.startswith("/permanent/einstein/annalen")): | |
| textUrl=textUrl.replace("/permanent/einstein/annalen/","/diverse/de/") | |
| splitted=textUrl.split("/fulltext") | |
| textUrl=splitted[0]+".xml" | |
| textUrlkurz = string.split(textUrl, ".")[0] | |
| docinfo['textURLPathkurz'] = textUrlkurz | |
| docinfo['textURLPath'] = textUrl | |
| logging.debug("hack") | |
| logging.debug(textUrl) | |
| # new style text-url-path | # new style text-url-path |
| textUrls = dom.xpath("//texttool/text-url-path") | textUrls = dom.xpath("//texttool/text-url-path") |
| if textUrls and (len(textUrls) > 0): | if textUrls and (len(textUrls) > 0): |
| textUrl = getTextFromNode(textUrls[0]) | textUrl = getTextFromNode(textUrls[0]) |
| docinfo['textURLPath'] = textUrl | docinfo['textURLPath'] = textUrl |
| if not docinfo['imagePath']: | textUrlkurz = string.split(textUrl, ".")[0] |
| docinfo['textURLPathkurz'] = textUrlkurz | |
| #if not docinfo['imagePath']: | |
| # text-only, no page images | # text-only, no page images |
| docinfo = self.getNumPages(docinfo) | #docinfo = self.getNumTextPages(docinfo) |
| presentationUrls = dom.xpath("//texttool/presentation") | presentationUrls = dom.xpath("//texttool/presentation") |
| docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get info von bib tag | docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get info von bib tag |
| #docinfo = self.getDownloadfromDocinfoToBibtex(url, docinfo=docinfo, dom=dom) | |
| docinfo = self.getNameFromIndexMeta(url, docinfo=docinfo, dom=dom) | |
| if presentationUrls and (len(presentationUrls) > 0): # ueberschreibe diese durch presentation informationen | if presentationUrls and (len(presentationUrls) > 0): # ueberschreibe diese durch presentation informationen |
| # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten | # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten |
| Line 632 class documentViewer(Folder): | Line 845 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 642 class documentViewer(Folder): | Line 855 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 |
| #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. |
| docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) | docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) |
| #docinfo = self.getDownloadfromDocinfoToBibtex(pathorig,docinfo=docinfo,cut=cut+1) | |
| docinfo = self.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) | docinfo = self.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) |
| return docinfo | return docinfo |
| 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 671 class documentViewer(Folder): | Line 885 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) | # FIXME: fake texturlpath |
| if not docinfo.has_key('textURLPath'): | |
| docinfo['textURLPath'] = None | |
| logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo) | |
| #logging.debug("documentViewer (getdocinfo) docinfo: %s"%) | |
| self.REQUEST.SESSION['docinfo'] = docinfo | self.REQUEST.SESSION['docinfo'] = docinfo |
| return docinfo | return docinfo |
| Line 682 class documentViewer(Folder): | Line 901 class documentViewer(Folder): |
| """returns pageinfo with the given parameters""" | """returns pageinfo with the given parameters""" |
| pageinfo = {} | pageinfo = {} |
| current = getInt(current) | current = getInt(current) |
| pageinfo['current'] = current | pageinfo['current'] = current |
| rows = int(rows or self.thumbrows) | rows = int(rows or self.thumbrows) |
| pageinfo['rows'] = rows | pageinfo['rows'] = rows |
| Line 701 class documentViewer(Folder): | Line 921 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['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') |
| #pageinfo['optionToggle'] = self.REQUEST.get('optionToggle','1') | |
| 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') |
| pageinfo['textPN'] = self.REQUEST.get('textPN','1') | pageinfo['textPN'] = self.REQUEST.get('textPN','1') |
| pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','') | pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','') |
| pageinfo ['highlightElementPos'] = self.REQUEST.get('highlightElementPos','') | |
| pageinfo ['highlightElement'] = self.REQUEST.get('highlightElement','') | |
| pageinfo ['xpointer'] = self.REQUEST.get('xpointer','') | |
| pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30') | pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30') |
| pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10') | pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10') |
| pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') | pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') |
| Line 723 class documentViewer(Folder): | Line 950 class documentViewer(Folder): |
| tocPages=tocSize/tocPageSize | tocPages=tocSize/tocPageSize |
| pageinfo['tocPN'] = min (tocPages,toc) | pageinfo['tocPN'] = min (tocPages,toc) |
| pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') | pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') |
| pageinfo['sn'] =self.REQUEST.get('sn','') | #pageinfo['sn'] =self.REQUEST.get('sn','') |
| pageinfo['s'] =self.REQUEST.get('s','') | |
| return pageinfo | return pageinfo |
| def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): | def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): |
| Line 767 def manage_addDocumentViewerTemplate(sel | Line 995 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) |