version 1.75, 2010/10/11 14:06:34
|
version 1.238.2.6, 2011/08/03 19:04:18
|
Line 1
|
Line 1
|
|
|
from OFS.SimpleItem import SimpleItem |
from OFS.SimpleItem import SimpleItem |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
|
|
from Ft.Xml import EMPTY_NAMESPACE, Parse |
from Ft.Xml import EMPTY_NAMESPACE, Parse |
|
from Ft.Xml.Domlette import NonvalidatingReader |
|
import Ft.Xml.Domlette |
|
import cStringIO |
|
|
|
import xml.etree.ElementTree as ET |
|
|
import sys |
import re |
import logging |
import logging |
import urllib |
import urllib |
import documentViewer |
|
from documentViewer import getTextFromNode, serializeNode |
from SrvTxtUtils import getInt, getText, getHttpData |
|
|
|
def serialize(node): |
|
"""returns a string containing an XML snippet of node""" |
|
s = ET.tostring(node, 'UTF-8') |
|
# snip off XML declaration |
|
if s.startswith('<?xml'): |
|
i = s.find('?>') |
|
return s[i+3:] |
|
|
|
return s |
|
|
|
|
|
def getTextFromNode(node): |
|
"""get the cdata content of a node""" |
|
if node is None: |
|
return "" |
|
# ET: |
|
# text = node.text or "" |
|
# for e in node: |
|
# text += gettext(e) |
|
# if e.tail: |
|
# text += e.tail |
|
|
|
# 4Suite: |
|
nodelist=node.childNodes |
|
text = "" |
|
for n in nodelist: |
|
if n.nodeType == node.TEXT_NODE: |
|
text = text + n.data |
|
|
|
return text |
|
|
|
def serializeNode(node, encoding="utf-8"): |
|
"""returns a string containing node as XML""" |
|
#s = ET.tostring(node) |
|
|
|
# 4Suite: |
|
stream = cStringIO.StringIO() |
|
Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding) |
|
s = stream.getvalue() |
|
stream.close() |
|
|
|
return s |
|
|
|
|
class MpdlXmlTextServer(SimpleItem): |
class MpdlXmlTextServer(SimpleItem): |
"""TextServer implementation for MPDL-XML eXist server""" |
"""TextServer implementation for MPDL-XML eXist server""" |
Line 19 class MpdlXmlTextServer(SimpleItem):
|
Line 69 class MpdlXmlTextServer(SimpleItem):
|
|
|
manage_changeMpdlXmlTextServerForm = PageTemplateFile("zpt/manage_changeMpdlXmlTextServer", globals()) |
manage_changeMpdlXmlTextServerForm = PageTemplateFile("zpt/manage_changeMpdlXmlTextServer", globals()) |
|
|
def __init__(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40): |
def __init__(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40): |
"""constructor""" |
"""constructor""" |
self.id=id |
self.id=id |
self.title=title |
self.title=title |
Line 31 class MpdlXmlTextServer(SimpleItem):
|
Line 81 class MpdlXmlTextServer(SimpleItem):
|
|
|
def getHttpData(self, url, data=None): |
def getHttpData(self, url, data=None): |
"""returns result from url+data HTTP request""" |
"""returns result from url+data HTTP request""" |
return documentViewer.getHttpData(url,data,timeout=self.timeout) |
return getHttpData(url,data,timeout=self.timeout) |
|
|
def getServerData(self, method, data=None): |
def getServerData(self, method, data=None): |
"""returns result from text server for method+data""" |
"""returns result from text server for method+data""" |
url = self.serverUrl+method |
url = self.serverUrl+method |
return documentViewer.getHttpData(url,data,timeout=self.timeout) |
return getHttpData(url,data,timeout=self.timeout) |
|
|
def getSearch(self, pn=1, pageinfo=None, docinfo=None, query=None, queryType=None, lemma=None): |
# WTF: what does this really do? can it be integrated in getPage? |
|
def getSearch(self, pageinfo=None, docinfo=None): |
"""get search list""" |
"""get search list""" |
|
logging.debug("getSearch()") |
docpath = docinfo['textURLPath'] |
docpath = docinfo['textURLPath'] |
url = docinfo['url'] |
url = docinfo['url'] |
logging.debug("documentViewer (gettoc) docpath: %s"%(docpath)) |
|
logging.debug("documentViewer (gettoc) url: %s"%(url)) |
|
pagesize = pageinfo['queryPageSize'] |
pagesize = pageinfo['queryPageSize'] |
pn = pageinfo['searchPN'] |
pn = pageinfo.get('searchPN',1) |
sn = pageinfo['sn'] |
sn = pageinfo['sn'] |
highlightQuery = pageinfo['highlightQuery'] |
highlightQuery = pageinfo['highlightQuery'] |
query =pageinfo['query'] |
query =pageinfo['query'] |
Line 53 class MpdlXmlTextServer(SimpleItem):
|
Line 103 class MpdlXmlTextServer(SimpleItem):
|
viewMode= pageinfo['viewMode'] |
viewMode= pageinfo['viewMode'] |
tocMode = pageinfo['tocMode'] |
tocMode = pageinfo['tocMode'] |
characterNormalization = pageinfo['characterNormalization'] |
characterNormalization = pageinfo['characterNormalization'] |
|
#optionToggle = pageinfo['optionToggle'] |
tocPN = pageinfo['tocPN'] |
tocPN = pageinfo['tocPN'] |
selfurl = self.absolute_url() |
selfurl = self.absolute_url() |
|
data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&characterNormalization=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, sn, viewMode,characterNormalization, urllib.quote(highlightQuery))) |
data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, sn, viewMode,urllib.quote(highlightQuery))) |
|
#page=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&highlightQuery=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn, viewMode,highlightQuery) ,outputUnicode=False) |
|
|
|
pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url) |
pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url) |
pagedom = Parse(pagexml) |
pagedom = Parse(pagexml) |
|
|
|
""" |
|
pagedivs = pagedom.xpath("//div[@class='queryResultHits']") |
|
if (pagedivs == pagedom.xpath("//div[@class='queryResultHits']")): |
|
if len(pagedivs)>0: |
|
docinfo['queryResultHits'] = int(getTextFromNode(pagedivs[0])) |
|
s = getTextFromNode(pagedivs[0]) |
|
s1 = int(s)/10+1 |
|
try: |
|
docinfo['queryResultHits'] = int(s1) |
|
logging.debug("SEARCH ENTRIES: %s"%(s1)) |
|
except: |
|
docinfo['queryResultHits'] = 0 |
|
""" |
if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"): |
if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"): |
pagedivs = pagedom.xpath("//div[@class='queryResultPage']") |
pagedivs = pagedom.xpath("//div[@class='queryResultPage']") |
if len(pagedivs)>0: |
if len(pagedivs)>0: |
Line 72 class MpdlXmlTextServer(SimpleItem):
|
Line 134 class MpdlXmlTextServer(SimpleItem):
|
href = hrefNode.nodeValue |
href = hrefNode.nodeValue |
if href.startswith('page-fragment.xql'): |
if href.startswith('page-fragment.xql'): |
selfurl = self.absolute_url() |
selfurl = self.absolute_url() |
pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN)) |
pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&characterNormalization=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN, characterNormalization)) |
hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) |
hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) |
|
#logging.debug("PUREXML :%s"%(serializeNode(pagenode))) |
return serializeNode(pagenode) |
return serializeNode(pagenode) |
if (queryType=="fulltextMorph"): |
if (queryType=="fulltextMorph"): |
pagedivs = pagedom.xpath("//div[@class='queryResult']") |
pagedivs = pagedom.xpath("//div[@class='queryResult']") |
Line 86 class MpdlXmlTextServer(SimpleItem):
|
Line 149 class MpdlXmlTextServer(SimpleItem):
|
href = hrefNode.nodeValue |
href = hrefNode.nodeValue |
if href.startswith('page-fragment.xql'): |
if href.startswith('page-fragment.xql'): |
selfurl = self.absolute_url() |
selfurl = self.absolute_url() |
pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN)) |
pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&characterNormalization=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN,characterNormalization)) |
hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) |
hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) |
if href.startswith('../lt/lemma.xql'): |
if href.startswith('../lt/lemma.xql'): |
hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma_New'%(selfurl)) |
hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_query'%(selfurl)) |
l.setAttributeNS(None, 'target', '_blank') |
l.setAttributeNS(None, 'target', '_blank') |
l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') |
pagedivs = pagedom.xpath("//div[@class='queryResultMorphExpansion']") |
pagedivs = pagedom.xpath("//div[@class='queryResultMorphExpansion']") |
return serializeNode(pagenode) |
return serializeNode(pagenode) |
if (queryType=="ftIndex")or(queryType=="ftIndexMorph"): |
if (queryType=="ftIndex")or(queryType=="ftIndexMorph"): |
Line 104 class MpdlXmlTextServer(SimpleItem):
|
Line 167 class MpdlXmlTextServer(SimpleItem):
|
hrefNode = l.getAttributeNodeNS(None, u"href") |
hrefNode = l.getAttributeNodeNS(None, u"href") |
if hrefNode: |
if hrefNode: |
href = hrefNode.nodeValue |
href = hrefNode.nodeValue |
hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s'%(viewMode,tocMode,tocPN,pn)) |
hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s&characterNormalization=%s'%(viewMode,tocMode,tocPN,pn,characterNormalization)) |
if href.startswith('../lt/lex.xql'): |
if href.startswith('../lt/lex.xql'): |
hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_voc'%selfurl) |
hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_lex'%selfurl) |
l.setAttributeNS(None, 'target', '_blank') |
l.setAttributeNS(None, 'target', '_blank') |
l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') |
if href.startswith('../lt/lemma.xql'): |
if href.startswith('../lt/lemma.xql'): |
hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma'%selfurl) |
hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma'%(selfurl)) |
l.setAttributeNS(None, 'target', '_blank') |
l.setAttributeNS(None, 'target', '_blank') |
l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') |
return serializeNode(pagenode) |
return serializeNode(pagenode) |
return "no text here" |
return "no text here" |
|
|
"""def getNumPages(self, docinfo): |
def getGisPlaces(self, docinfo=None, pageinfo=None): |
""get list of pages from fulltext and put in docinfo"" |
|
if 'numPages' in docinfo: |
|
# already there |
|
return docinfo |
|
xquery = '//pb' |
|
text = self.getServerData("xquery.xql","document=%s&xquery=%s"%(docinfo['textURLPath'],xquery)) |
|
docinfo['numPages'] = text.count("<pb ") |
|
return docinfo |
|
""" |
|
def getNumTextPages (self, docinfo): |
|
"""get list of pages from fulltext (texts without images) and put in docinfo""" |
|
if 'numPages' in docinfo: |
|
# allredy there |
|
return docinfo |
|
xpath ='/count(//pb)' |
|
text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'], xpath)) |
|
dom = Parse(text) |
|
result= dom.xpath("//result/resultPage") |
|
docinfo['numPages']=int(getTextFromNode(result[0])) |
|
return docinfo |
|
|
|
def getGisPlases(self, docinfo): |
|
""" Show all Gis Places of whole Page""" |
""" Show all Gis Places of whole Page""" |
xpath='//place' |
xpath='//place' |
|
docpath = docinfo.get('textURLPath',None) |
|
if not docpath: |
|
return None |
|
|
|
url = docinfo['url'] |
|
selfurl = self.absolute_url() |
|
pn = pageinfo['current'] |
|
hrefList=[] |
|
myList= "" |
|
text=self.getServerData("xpath.xql", "document=%s&xpath=%s&pn=%s"%(docinfo['textURLPath'],xpath,pn)) |
|
dom = ET.fromstring(text) |
|
result = dom.findall(".//result/resultPage/place") |
|
for l in result: |
|
href = l.get("id") |
|
hrefList.append(href) |
|
# WTF: what does this do? |
|
myList = ",".join(hrefList) |
|
#logging.debug("getGisPlaces :%s"%(myList)) |
|
return myList |
|
|
|
def getAllGisPlaces (self, docinfo=None, pageinfo=None): |
|
"""Show all Gis Places of whole Book """ |
|
xpath ='//echo:place' |
|
docpath =docinfo['textURLPath'] |
|
url = docinfo['url'] |
|
selfurl =self.absolute_url() |
|
pn =pageinfo['current'] |
|
hrefList=[] |
|
myList="" |
text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'], xpath)) |
text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'], xpath)) |
pagedom = Parse(text) |
dom = ET.fromstring(text) |
result =pagedom.xpath("//result/resultPage/") |
result = dom.findall(".//result/resultPage/place") |
|
|
for l in result: |
for l in result: |
hrefNode= l.getAttributeNodeNS(None, u"id") |
href = l.get("id") |
docinfo['place']=getTextFromNode(result[0]) |
hrefList.append(href) |
return docinfo |
# WTF: what does this do? |
|
myList = ",".join(hrefList) |
|
#logging.debug("getALLGisPlaces :%s"%(myList)) |
|
return myList |
|
|
|
def processPageInfo(self, dom, docinfo, pageinfo): |
|
"""processes page info divs from dom and stores in docinfo and pageinfo""" |
|
# assume first second level div is pageMeta |
|
alldivs = dom.find("div") |
|
for div in alldivs: |
|
dc = div.get('class') |
|
|
|
# pageNumberOrig |
|
if dc == 'pageNumberOrig': |
|
pageinfo['pageNumberOrig'] = div.text |
|
|
|
# pageNumberOrigNorm |
|
elif dc == 'pageNumberOrigNorm': |
|
pageinfo['pageNumberOrigNorm'] = div.text |
|
|
|
# pageNumberOrigNorm |
|
elif dc == 'countFigureEntries': |
|
docinfo['numFigureEntries'] = getInt(div.text) |
|
|
|
# pageNumberOrigNorm |
|
elif dc == 'countTocEntries': |
|
# WTF: s1 = int(s)/30+1 |
|
docinfo['numTocEntries'] = getInt(div.text) |
|
|
|
# pageHeaderTitle |
|
elif dc == 'pageHeaderTitle': |
|
docinfo['pageHeaderTitle'] = div.text |
|
|
|
# numTextPages |
|
elif dc == 'countPages': |
|
np = getInt(div.text) |
|
if np > 0: |
|
docinfo['numTextPages'] = np |
|
if docinfo.get('numPages', 0) == 0: |
|
# seems to be text-only - update page count |
|
docinfo['numPages'] = np |
|
pageinfo['end'] = min(pageinfo['end'], np) |
|
pageinfo['numgroups'] = int(np / pageinfo['groupsize']) |
|
if np % pageinfo['groupsize'] > 0: |
|
pageinfo['numgroups'] += 1 |
|
|
|
return |
|
|
|
|
def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None, highlightQuery=None,sn=None, viewMode=None, tocMode=None, tocPN=None, characterNormalization=""): |
def getTextPage(self, mode="text_dict", pn=1, docinfo=None, pageinfo=None): |
"""returns single page from fulltext""" |
"""returns single page from fulltext""" |
|
logging.debug("getTextPage mode=%s, pn=%s"%(mode,pn)) |
|
# check for cached text -- but this shouldn't be called twice |
|
if pageinfo.has_key('textPage'): |
|
logging.debug("getTextPage: using cached text") |
|
return pageinfo['textPage'] |
|
|
docpath = docinfo['textURLPath'] |
docpath = docinfo['textURLPath'] |
path = docinfo['textURLPath'] |
# just checking |
|
if pageinfo['current'] != pn: |
|
logging.warning("getTextPage: current!=pn!") |
|
|
|
# stuff for constructing full urls |
url = docinfo['url'] |
url = docinfo['url'] |
name = docinfo['name'] |
urlmode = docinfo['mode'] |
viewMode= pageinfo['viewMode'] |
sn = pageinfo.get('sn', None) |
tocMode = pageinfo['tocMode'] |
highlightQuery = pageinfo.get('highlightQuery', None) |
characterNormalization=pageinfo['characterNormalization'] |
tocMode = pageinfo.get('tocMode', None) |
tocPN = pageinfo['tocPN'] |
tocPN = pageinfo.get('tocPN',None) |
selfurl = self.absolute_url() |
characterNormalization = pageinfo.get('characterNormalization', None) |
|
selfurl = docinfo['viewerUrl'] |
|
|
if mode == "text_dict": |
if mode == "text_dict": |
|
# text_dict is called textPollux in the backend |
textmode = "textPollux" |
textmode = "textPollux" |
else: |
else: |
textmode = mode |
textmode = mode |
#logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization)) |
|
textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization) |
textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization) |
if highlightQuery is not None: |
if highlightQuery: |
textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn) |
textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn) |
|
|
|
# fetch the page |
pagexml = self.getServerData("page-fragment.xql",textParam) |
pagexml = self.getServerData("page-fragment.xql",textParam) |
#pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False) |
dom = ET.fromstring(pagexml) |
|
# extract additional info |
|
self.processPageInfo(dom, docinfo, pageinfo) |
|
# page content is in <div class="pageContent"> |
|
pagediv = None |
|
# ElementTree 1.2 in Python 2.6 can't do div[@class='pageContent'] |
|
# so we look at the second level divs |
|
alldivs = dom.findall("div") |
|
for div in alldivs: |
|
dc = div.get('class') |
|
# page content div |
|
if dc == 'pageContent': |
|
pagediv = div |
|
break |
|
|
pagedom = Parse(pagexml) |
|
# plain text mode |
# plain text mode |
if mode == "text": |
if mode == "text": |
# first div contains text |
if pagediv: |
pagedivs = pagedom.xpath("/div") |
links = pagediv.findall(".//a") |
if len(pagedivs) > 0: |
|
pagenode = pagedivs[0] |
|
links = pagenode.xpath("//a") |
|
for l in links: |
|
hrefNode = l.getAttributeNodeNS(None, u"href") |
|
if hrefNode: |
|
href= hrefNode.nodeValue |
|
if href.startswith('#note-'): |
|
hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn)) |
|
return serializeNode(pagenode) |
|
if mode == "xml": |
|
# first div contains text |
|
pagedivs = pagedom.xpath("/div") |
|
if len(pagedivs) > 0: |
|
pagenode = pagedivs[0] |
|
return serializeNode(pagenode) |
|
if mode == "gis": |
|
# first div contains text |
|
pagedivs = pagedom.xpath("/div") |
|
if len(pagedivs) > 0: |
|
pagenode = pagedivs[0] |
|
links =pagenode.xpath("//a") |
|
for l in links: |
for l in links: |
hrefNode =l.getAttributeNodeNS(None, u"href") |
href = l.get('href') |
if hrefNode: |
if href and href.startswith('#note-'): |
href=hrefNode.nodeValue |
href = href.replace('#note-',"?mode=%s&url=%s&viewMode=text&tocMode=%s&tocPN=%s&pn=%s#note-"%(urlmode,url,tocMode,tocPN,pn)) |
if href.startswith('http://chinagis.mpiwg-berlin.mpg.de'): |
l.set('href', href) |
hrefNode.nodeValue =href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl/%s'%name) |
|
#hrefNode.nodeValue =href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl%s'%url) |
return serialize(pagediv) |
logging.debug("YYYYY docinfo[name] %s"%docinfo['name']) |
|
l.setAttributeNS(None, 'target', '_blank') |
|
return serializeNode(pagenode) |
|
|
|
if mode == "pureXml": |
|
# first div contains text |
|
pagedivs = pagedom.xpath("/div") |
|
if len(pagedivs) > 0: |
|
pagenode = pagedivs[0] |
|
return serializeNode(pagenode) |
|
# text-with-links mode |
# text-with-links mode |
if mode == "text_dict": |
elif mode == "text_dict": |
# first div contains text |
if pagediv: |
pagedivs = pagedom.xpath("/div") |
|
if len(pagedivs) > 0: |
|
pagenode = pagedivs[0] |
|
# check all a-tags |
# check all a-tags |
links = pagenode.xpath("//a") |
links = pagediv.findall(".//a") |
for l in links: |
for l in links: |
hrefNode = l.getAttributeNodeNS(None, u"href") |
href = l.get('href') |
if hrefNode: |
|
|
if href: |
# is link with href |
# is link with href |
href = hrefNode.nodeValue |
if href.startswith('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql'): |
if href.startswith('lt/lex.xql'): |
|
# is pollux link |
# is pollux link |
selfurl = self.absolute_url() |
selfurl = self.absolute_url() |
# change href |
# change href |
hrefNode.nodeValue = href.replace('lt/lex.xql','%s/template/head_main_voc'%selfurl) |
l.set('href', href.replace('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql','%s/head_main_voc'%selfurl)) |
# add target |
# add target |
l.setAttributeNS(None, 'target', '_blank') |
l.set('target', '_blank') |
l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;") |
|
l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
if href.startswith('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql'): |
if href.startswith('lt/lemma.xql'): |
|
selfurl = self.absolute_url() |
selfurl = self.absolute_url() |
hrefNode.nodeValue = href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl) |
l.set('href', href.replace('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql','%s/head_main_lemma'%selfurl)) |
l.setAttributeNS(None, 'target', '_blank') |
l.set('target', '_blank') |
l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;") |
l.set('onclick',"popupWin = window.open(this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=no, scrollbars=1'); return false;") |
l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
l.set('ondblclick', 'popupWin.focus();') |
|
|
if href.startswith('#note-'): |
if href.startswith('#note-'): |
hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn)) |
l.set('href', href.replace('#note-',"?mode=%s&url=%s&viewMode=text_dict&tocMode=%s&tocPN=%s&pn=%s#note-"%(urlmode,url,tocMode,tocPN,pn))) |
return serializeNode(pagenode) |
|
|
return serialize(pagediv) |
|
|
|
# xml mode |
|
elif mode == "xml": |
|
if pagediv: |
|
return serialize(pagediv) |
|
|
|
# pureXml mode |
|
elif mode == "pureXml": |
|
if pagediv: |
|
return serialize(pagediv) |
|
|
|
# gis mode |
|
elif mode == "gis": |
|
name = docinfo['name'] |
|
if pagediv: |
|
# check all a-tags |
|
links = pagediv.findall(".//a") |
|
for l in links: |
|
href = l.get('href') |
|
if href: |
|
if href.startswith('http://chinagis.mpiwg-berlin.mpg.de'): |
|
l.set('href', href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl/%s'%name)) |
|
l.set('target', '_blank') |
|
|
|
return serialize(pagediv) |
|
|
return "no text here" |
return "no text here" |
|
|
def getTranslate(self, query=None, language=None): |
# WTF: is this needed? |
|
def getOrigPages(self, docinfo=None, pageinfo=None): |
|
logging.debug("CALLED: getOrigPages!") |
|
if not pageinfo.has_key('pageNumberOrig'): |
|
logging.warning("getOrigPages: not in pageinfo!") |
|
return None |
|
|
|
return pageinfo['pageNumberOrig'] |
|
|
|
# WTF: is this needed? |
|
def getOrigPagesNorm(self, docinfo=None, pageinfo=None): |
|
logging.debug("CALLED: getOrigPagesNorm!") |
|
if not pageinfo.has_key('pageNumberOrigNorm'): |
|
logging.warning("getOrigPagesNorm: not in pageinfo!") |
|
return None |
|
|
|
return pageinfo['pageNumberOrigNorm'] |
|
|
|
# TODO: should be getWordInfo |
|
def getTranslate(self, word=None, language=None): |
"""translate into another languages""" |
"""translate into another languages""" |
data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query)) |
data = self.getServerData("lt/wordInfo.xql","language="+str(language)+"&word="+urllib.quote(word)+"&output=html") |
#pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query))) |
|
return data |
return data |
|
|
|
# WTF: what does this do? |
def getLemma(self, lemma=None, language=None): |
def getLemma(self, lemma=None, language=None): |
"""simular words lemma """ |
"""simular words lemma """ |
data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(lemma)) |
data = self.getServerData("lt/lemma.xql","language="+str(language)+"&lemma="+urllib.quote(lemma)+"&output=html") |
#pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma))) |
|
return data |
return data |
|
|
def getLemmaNew(self, query=None, language=None): |
# WTF: what does this do? |
|
def getLemmaQuery(self, query=None, language=None): |
"""simular words lemma """ |
"""simular words lemma """ |
data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(query)) |
data = self.getServerData("lt/lemma.xql","language="+str(language)+"&query="+urllib.quote(query)+"&output=html") |
#pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query))) |
|
return data |
return data |
|
|
|
# WTF: what does this do? |
|
def getLex(self, query=None, language=None): |
|
#simular words lemma |
|
data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query)) |
|
return data |
|
|
|
# WTF: what does this do? |
def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1): |
def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1): |
"""number of""" |
#number of |
docpath = docinfo['textURLPath'] |
docpath = docinfo['textURLPath'] |
pagesize = pageinfo['queryPageSize'] |
pagesize = pageinfo['queryPageSize'] |
pn = pageinfo['searchPN'] |
pn = pageinfo['searchPN'] |
Line 280 class MpdlXmlTextServer(SimpleItem):
|
Line 442 class MpdlXmlTextServer(SimpleItem):
|
tocDiv = None |
tocDiv = None |
|
|
pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn)) |
pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn)) |
#pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, query, pagesize, pn) ,outputUnicode=False) |
|
pagedom = Parse(pagexml) |
pagedom = Parse(pagexml) |
numdivs = pagedom.xpath("//div[@class='queryResultHits']") |
numdivs = pagedom.xpath("//div[@class='queryResultHits']") |
tocSearch = int(getTextFromNode(numdivs[0])) |
tocSearch = int(getTextFromNode(numdivs[0])) |
tc=int((tocSearch/10)+1) |
tc=int((tocSearch/10)+1) |
logging.debug("documentViewer (gettoc) tc: %s"%(tc)) |
|
return tc |
return tc |
|
|
def getToc(self, mode="text", docinfo=None): |
def getToc(self, mode="text", docinfo=None): |
"""loads table of contents and stores in docinfo""" |
"""loads table of contents and stores XML in docinfo""" |
logging.debug("documentViewer (gettoc) mode: %s"%(mode)) |
logging.debug("getToc mode=%s"%mode) |
if mode == "none": |
if mode == "none": |
return docinfo |
return docinfo |
|
|
if 'tocSize_%s'%mode in docinfo: |
if 'tocSize_%s'%mode in docinfo: |
# cached toc |
# cached toc |
return docinfo |
return docinfo |
Line 308 class MpdlXmlTextServer(SimpleItem):
|
Line 469 class MpdlXmlTextServer(SimpleItem):
|
# number of entries in toc |
# number of entries in toc |
tocSize = 0 |
tocSize = 0 |
tocDiv = None |
tocDiv = None |
|
# fetch full toc |
pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn)) |
pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn)) |
#pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False) |
dom = ET.fromstring(pagexml) |
# post-processing downloaded xml |
# page content is in <div class="queryResultPage"> |
pagedom = Parse(pagexml) |
pagediv = None |
# get number of entries |
# ElementTree 1.2 in Python 2.6 can't do div[@class='queryResultPage'] |
numdivs = pagedom.xpath("//div[@class='queryResultHits']") |
alldivs = dom.findall("div") |
if len(numdivs) > 0: |
for div in alldivs: |
tocSize = int(getTextFromNode(numdivs[0])) |
dc = div.get('class') |
docinfo['tocSize_%s'%mode] = tocSize |
# page content div |
|
if dc == 'queryResultPage': |
|
pagediv = div |
|
|
|
elif dc == 'queryResultHits': |
|
docinfo['tocSize_%s'%mode] = getInt(div.text) |
|
|
|
if pagediv: |
|
# store XML in docinfo |
|
docinfo['tocXML_%s'%mode] = ET.tostring(pagediv, 'UTF-8') |
|
|
return docinfo |
return docinfo |
|
|
def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None): |
def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None): |
"""returns single page from the table of contents""" |
"""returns single page from the table of contents""" |
# TODO: this should use the cached TOC |
logging.debug("getTocPage mode=%s, pn=%s"%(mode,pn)) |
if mode == "text": |
if mode == "text": |
queryType = "toc" |
queryType = "toc" |
else: |
else: |
queryType = mode |
queryType = mode |
docpath = docinfo['textURLPath'] |
|
path = docinfo['textURLPath'] |
# check for cached TOC |
pagesize = pageinfo['tocPageSize'] |
if not docinfo.has_key('tocXML_%s'%mode): |
pn = pageinfo['tocPN'] |
self.getToc(mode=mode, docinfo=docinfo) |
|
|
|
tocxml = docinfo.get('tocXML_%s'%mode, None) |
|
if not tocxml: |
|
logging.error("getTocPage: unable to find tocXML") |
|
return "No ToC" |
|
|
|
pagesize = int(pageinfo['tocPageSize']) |
url = docinfo['url'] |
url = docinfo['url'] |
selfurl = self.absolute_url() |
urlmode = docinfo['mode'] |
|
selfurl = docinfo['viewerUrl'] |
viewMode= pageinfo['viewMode'] |
viewMode= pageinfo['viewMode'] |
characterNormalization = pageinfo ['characterNormalization'] |
|
tocMode = pageinfo['tocMode'] |
tocMode = pageinfo['tocMode'] |
tocPN = pageinfo['tocPN'] |
tocPN = int(pageinfo['tocPN']) |
|
pn = tocPN |
|
|
data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=%s"%(docpath,queryType, pagesize, pn,characterNormalization)) |
fulltoc = ET.fromstring(tocxml) |
page = data.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s'%(selfurl,url, viewMode, tocMode, tocPN)) |
|
text = page.replace('mode=image','mode=texttool') |
if fulltoc: |
logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization)) |
# paginate |
#logging.debug("documentViewer (characterNormalization) text: %s"%(text)) |
start = (pn - 1) * pagesize * 2 |
return text |
len = pagesize * 2 |
|
del fulltoc[:start] |
|
del fulltoc[len:] |
|
tocdivs = fulltoc |
|
|
def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): |
# check all a-tags |
|
links = tocdivs.findall(".//a") |
|
for l in links: |
|
href = l.get('href') |
|
if href: |
|
# take pn from href |
|
m = re.match(r'page-fragment\.xql.*pn=(\d+)', href) |
|
if m is not None: |
|
# and create new url |
|
l.set('href', '%s?mode=%s&url=%s&viewMode=%s&pn=%s&tocMode=%s&tocPN=%s'%(selfurl, urlmode, url, viewMode, m.group(1), tocMode, tocPN)) |
|
else: |
|
logging.warning("getTocPage: Problem with link=%s"%href) |
|
|
|
return serialize(tocdivs) |
|
|
|
|
|
def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): |
"""change settings""" |
"""change settings""" |
self.title=title |
self.title=title |
self.timeout = timeout |
self.timeout = timeout |
Line 359 def manage_addMpdlXmlTextServerForm(self
|
Line 557 def manage_addMpdlXmlTextServerForm(self
|
pt = PageTemplateFile("zpt/manage_addMpdlXmlTextServer", globals()).__of__(self) |
pt = PageTemplateFile("zpt/manage_addMpdlXmlTextServer", globals()).__of__(self) |
return pt() |
return pt() |
|
|
def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): |
def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): |
|
#def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/",timeout=40,RESPONSE=None): |
"""add zogiimage""" |
"""add zogiimage""" |
newObj = MpdlXmlTextServer(id,title,serverUrl,timeout) |
newObj = MpdlXmlTextServer(id,title,serverUrl,timeout) |
self.Destination()._setObject(id, newObj) |
self.Destination()._setObject(id, newObj) |
Line 367 def manage_addMpdlXmlTextServer(self,id,
|
Line 566 def manage_addMpdlXmlTextServer(self,id,
|
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |
|
|
|
|
|
|