--- documentViewer/documentViewer.py 2011/01/12 14:10:45 1.165 +++ documentViewer/documentViewer.py 2012/01/04 07:38:17 1.178 @@ -7,7 +7,7 @@ from AccessControl import getSecurityMan 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 os.path import sys @@ -43,12 +43,14 @@ def getTextFromNode(nodename): rc = rc + node.data return rc -def serializeNode(node, encoding='utf-8'): +def serializeNode(node, encoding="utf-8"): """returns a string containing node as XML""" - buf = cStringIO.StringIO() - Ft.Xml.Domlette.Print(node, stream=buf, encoding=encoding) - s = buf.getvalue() - buf.close() + stream = cStringIO.StringIO() + #logging.debug("BUF: %s"%(stream)) + Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding) + s = stream.getvalue() + #logging.debug("BUF: %s"%(s)) + stream.close() return s def browserCheck(self): @@ -94,7 +96,7 @@ def browserCheck(self): if string.find(ie1, "Firefox") >-1: nav5= string.split(ie1, "/")[1] logging.debug("FIREFOX: %s"%(nav5)) - bt['versFirefox']=string.split(nav5, ".")[1] + bt['versFirefox']=nav5[0:3] except:pass #Opera identification try: @@ -161,8 +163,6 @@ def getHttpData(url, data=None, num_trie raise IOError("ERROR fetching HTTP data from %s: %s"%(url,errmsg)) #return None - - ## ## documentViewer class ## @@ -231,6 +231,14 @@ class documentViewer(Folder): """get page""" 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): """get query in search""" return self.template.fulltextclient.getQuery(**args) @@ -255,6 +263,14 @@ class documentViewer(Folder): """get lemma""" 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): """get toc""" return self.template.fulltextclient.getToc(**args) @@ -336,7 +352,8 @@ class documentViewer(Folder): if (docinfo.get('textURLPath',None)): page = self.getTextPage(docinfo=docinfo, pageinfo=pageinfo) pageinfo['textPage'] = page - pt = getattr(self.template, 'viewer_main') + tt = getattr(self, 'template') + pt = getattr(tt, 'viewer_main') return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode,mk=self.generateMarks(mk)) def generateMarks(self,mk): @@ -578,7 +595,7 @@ class documentViewer(Folder): def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): """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: docinfo = {} @@ -590,7 +607,7 @@ class documentViewer(Folder): 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" bib = dom.xpath("//bib/*") if bib and len(bib)>0: @@ -610,8 +627,8 @@ class documentViewer(Folder): bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) docinfo['bib_type'] = bibtype bibmap=metaData.generateMappingForType(bibtype) - logging.debug("documentViewer (getbibinfofromindexmeta) bibmap:"+repr(bibmap)) - logging.debug("documentViewer (getbibinfofromindexmeta) bibtype:"+repr(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 len(bibmap) > 0 and len(bibmap['author'][0]) > 0: try: @@ -623,15 +640,55 @@ class documentViewer(Folder): try: docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0]) except: pass - logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype) + #logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype) try: docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) except: 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 - + 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: @@ -720,12 +777,27 @@ class documentViewer(Folder): textUrl = textUrl.replace("/mpiwg/online", '', 1) 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 textUrls = dom.xpath("//texttool/text-url-path") if textUrls and (len(textUrls) > 0): textUrl = getTextFromNode(textUrls[0]) docinfo['textURLPath'] = textUrl + textUrlkurz = string.split(textUrl, ".")[0] + docinfo['textURLPathkurz'] = textUrlkurz #if not docinfo['imagePath']: # text-only, no page images #docinfo = self.getNumTextPages(docinfo) @@ -733,6 +805,7 @@ class documentViewer(Folder): presentationUrls = dom.xpath("//texttool/presentation") 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) @@ -788,6 +861,7 @@ class documentViewer(Folder): #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.getDownloadfromDocinfoToBibtex(pathorig,docinfo=docinfo,cut=cut+1) docinfo = self.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) return docinfo @@ -848,21 +922,24 @@ class documentViewer(Folder): pageinfo['viewMode'] = viewMode pageinfo['tocMode'] = tocMode pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') - pageinfo['optionToggle'] = self.REQUEST.get('optionToggle','') + #pageinfo['optionToggle'] = self.REQUEST.get('optionToggle','1') pageinfo['query'] = self.REQUEST.get('query','') 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','') + + 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['queryPageSize'] =self.REQUEST.get('queryPageSize', '10') - pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') - + pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') toc = int (pageinfo['tocPN']) pageinfo['textPages'] =int (toc) - - if 'tocSize_%s'%tocMode in docinfo: tocSize = int(docinfo['tocSize_%s'%tocMode]) tocPageSize = int(pageinfo['tocPageSize']) @@ -873,7 +950,8 @@ class documentViewer(Folder): tocPages=tocSize/tocPageSize pageinfo['tocPN'] = min (tocPages,toc) 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 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):