version 1.78, 2010/08/12 10:08:24
|
version 1.112, 2010/10/08 13:49:44
|
Line 16 import logging
|
Line 16 import logging
|
import math |
import math |
import urlparse |
import urlparse |
import cStringIO |
import cStringIO |
|
import re |
|
|
def logger(txt,method,txt2): |
def logger(txt,method,txt2): |
"""logging""" |
"""logging""" |
Line 177 class documentViewer(Folder):
|
Line 178 class documentViewer(Folder):
|
"""get numpages""" |
"""get numpages""" |
return self.template.fulltextclient.getNumPages(docinfo) |
return self.template.fulltextclient.getNumPages(docinfo) |
|
|
|
def getNumTextPages(self, docinfo): |
|
"""get numpages text""" |
|
return self.template.fulltextclient.getNumTextPages(docinfo) |
|
|
def getTranslate(self, **args): |
def getTranslate(self, **args): |
"""get translate""" |
"""get translate""" |
return self.template.fulltextclient.getTranslate(**args) |
return self.template.fulltextclient.getTranslate(**args) |
Line 226 class documentViewer(Folder):
|
Line 231 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, characterNormalization=None): |
def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None, query=None, querySearch=None, characterNormalization=""): |
''' |
''' |
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 390 class documentViewer(Folder):
|
Line 395 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 420 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 445 class documentViewer(Folder):
|
Line 467 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 489 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 513 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 531 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['name']=getTextFromNode(dom.xpath("//%s"%bibmap['name'][0])[0]) |
|
except: pass |
|
|
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['indexMetaPath']=self.getIndexMetaPath(path); |
|
|
|
#result= dom.xpath("//result/resultPage") |
|
#docinfo['numPages']=int(getTextFromNode(result[0])) |
|
|
|
if len(name) > 0: |
|
try: |
|
result =dom.xpath("//name") |
|
docinfo['name']=getTextFromNode(result[0]) |
|
logging.debug("documentViewer docinfo[name] %s"%docinfo[name]) |
|
except: pass |
|
#logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype) |
|
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)) |
Line 517 class documentViewer(Folder):
|
Line 570 class documentViewer(Folder):
|
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 591 class documentViewer(Folder):
|
Line 644 class documentViewer(Folder):
|
docinfo['textURLPath'] = textUrl |
docinfo['textURLPath'] = textUrl |
if not docinfo['imagePath']: |
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.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 628 class documentViewer(Folder):
|
Line 682 class documentViewer(Folder):
|
docinfo['year']=getTextFromNode(dom.xpath("//date")[0]) |
docinfo['year']=getTextFromNode(dom.xpath("//date")[0]) |
except: |
except: |
pass |
pass |
|
try: |
|
docinfo['name']=getTextFromNode(dom.xpath("//name")[0]) |
|
except: |
|
pass |
return docinfo |
return docinfo |
|
|
def getDocinfoFromImagePath(self,path,docinfo=None,cut=0): |
def getDocinfoFromImagePath(self,path,docinfo=None,cut=0): |
Line 678 class documentViewer(Folder):
|
Line 736 class documentViewer(Folder):
|
self.REQUEST.SESSION['docinfo'] = docinfo |
self.REQUEST.SESSION['docinfo'] = docinfo |
return docinfo |
return docinfo |
|
|
def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None, viewMode=None, tocMode=None, characterNormalization=None): |
def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None, viewMode=None, tocMode=None,characterNormalization=""): |
"""returns pageinfo with the given parameters""" |
"""returns pageinfo with the given parameters""" |
pageinfo = {} |
pageinfo = {} |
current = getInt(current) |
current = getInt(current) |
Line 701 class documentViewer(Folder):
|
Line 759 class documentViewer(Folder):
|
pageinfo['numgroups'] += 1 |
pageinfo['numgroups'] += 1 |
pageinfo['viewMode'] = viewMode |
pageinfo['viewMode'] = viewMode |
pageinfo['tocMode'] = tocMode |
pageinfo['tocMode'] = tocMode |
pageinfo['characterNormalization'] =characterNormalization |
#pageinfo['characterNormalization'] =characterNormalization |
|
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') |