--- documentViewer/documentViewer.py 2010/10/11 12:45:15 1.115 +++ documentViewer/documentViewer.py 2010/11/02 15:32:44 1.151 @@ -5,6 +5,7 @@ from Products.PageTemplates.PageTemplate from AccessControl import ClassSecurityInfo from AccessControl import getSecurityManager from Globals import package_home +from Products.zogiLib.zogiLib import browserCheck from Ft.Xml import EMPTY_NAMESPACE, Parse import Ft.Xml.Domlette @@ -17,6 +18,7 @@ import math import urlparse import cStringIO import re +import string def logger(txt,method,txt2): """logging""" @@ -49,7 +51,34 @@ def serializeNode(node, encoding='utf-8' buf.close() 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 + 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 + + def getParentDir(path): """returns pathname shortened by one""" return '/'.join(path.split('/')[0:-1]) @@ -169,11 +198,27 @@ class documentViewer(Folder): def getQuery(self, **args): """get query""" return self.template.fulltextclient.getQuery(**args) + + def getPDF(self, **args): + """get query""" + return self.template.fulltextclient.getPDF(**args) def getSearch(self, **args): """get search""" return self.template.fulltextclient.getSearch(**args) - + + def getGisPlaces(self, **args): + """get gis places""" + return self.template.fulltextclient.getGisPlaces(**args) + + def getAllGisPlaces(self, **args): + """get all gis places """ + return self.template.fulltextclient.getAllGisPlaces(**args) + + def getOrigPages(self, **args): + """get original page number """ + return self.template.fulltextclient.getOrigPages(**args) + def getNumPages(self, docinfo): """get numpages""" return self.template.fulltextclient.getNumPages(docinfo) @@ -219,7 +264,9 @@ class documentViewer(Folder): self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" 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') if viewMode=="auto": # automodus gewaehlt @@ -264,7 +311,7 @@ class documentViewer(Folder): else: 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') return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode,mk=self.generateMarks(mk)) @@ -278,8 +325,15 @@ class documentViewer(Folder): for m in mk: ret+="mk=%s"%m return ret - - + + + def getBrowser(self): + """getBrowser the version of browser """ + names="" + names = browserCheck(self) + #logging.debug("XXXXXXXXXXXXXXXX: %s"%names) + return names + def findDigilibUrl(self): """try to get the digilib URL from zogilib""" url = self.template.zogilib.getDLBaseUrl() @@ -544,17 +598,9 @@ class documentViewer(Folder): for x in range(cut): path=getParentDir(path) dom = self.getDomFromIndexMeta(path) - - #docinfo['indexMetaPath']=self.getIndexMetaPath(path); - - #result= dom.xpath("//result/resultPage") - #docinfo['numPages']=int(getTextFromNode(result[0])) - - #result =dom.xpath("//name") + docinfo['name']=getTextFromNode(dom.xpath("/resource/name")[0]) - logging.debug("documentViewer docinfo[name] %s"%docinfo[name]) - - #logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype) + logging.debug("documentViewer docinfo[name] %s"%docinfo['name']) return docinfo def getDocinfoFromTextTool(self, url, dom=None, docinfo=None): @@ -645,6 +691,7 @@ class documentViewer(Folder): docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get info von bib tag docinfo = self.getNameFromIndexMeta(url, docinfo=docinfo, dom=dom) + 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 # durch den relativen Pfad auf die presentation infos @@ -724,6 +771,7 @@ class documentViewer(Folder): 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"%) self.REQUEST.SESSION['docinfo'] = docinfo return docinfo @@ -731,6 +779,7 @@ class documentViewer(Folder): """returns pageinfo with the given parameters""" pageinfo = {} current = getInt(current) + pageinfo['current'] = current rows = int(rows or self.thumbrows) pageinfo['rows'] = rows @@ -750,10 +799,11 @@ class documentViewer(Folder): pageinfo['numgroups'] += 1 pageinfo['viewMode'] = viewMode pageinfo['tocMode'] = tocMode - #pageinfo['characterNormalization'] =characterNormalization - pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization',' ') - pageinfo['query'] = self.REQUEST.get('query',' ') - pageinfo['queryType'] = self.REQUEST.get('queryType',' ') + #pageinfo ['originalPage'] = self.getOrigPages(docinfo=None, pageinfo=None) + pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','') + pageinfo['query'] = self.REQUEST.get('query','') + #pageinfo['optionsClose']= self.REQUEST.get('optionsClose','') + pageinfo['queryType'] = self.REQUEST.get('queryType','') pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') pageinfo['textPN'] = self.REQUEST.get('textPN','1') pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','') @@ -763,6 +813,8 @@ class documentViewer(Folder): toc = int (pageinfo['tocPN']) pageinfo['textPages'] =int (toc) + + if 'tocSize_%s'%tocMode in docinfo: tocSize = int(docinfo['tocSize_%s'%tocMode]) tocPageSize = int(pageinfo['tocPageSize'])