changeset 3:3ba8479c7aba modularisierung

new function
author abukhman
date Wed, 16 Jun 2010 11:16:02 +0200
parents 8cc283757c39
children e9085ba2bb51
files extraFunction.py
diffstat 1 files changed, 44 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/extraFunction.py	Mon Jun 14 12:50:06 2010 +0200
+++ b/extraFunction.py	Wed Jun 16 11:16:02 2010 +0200
@@ -21,7 +21,8 @@
 import logging
 import math
 import documentViewer
-
+import urllib2
+import urllib
 import urlparse 
 from types import *
 
@@ -69,8 +70,13 @@
         tocMode = pageinfo['tocMode']
         tocPN = pageinfo['tocPN']
         selfurl = self.absolute_url()
-        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 = page.replace('?document=%s'%str(docpath),'?url=%s'%url)
+        
+        page = urllib2.urlopen("http://mpdl-proto.mpiwg-berlin.mpg.de/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))
+        #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)                
+        data = page.read()
+        page.close()
+        
+        pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url)
         pagedom = Parse(pagexml)
         if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"):   
             pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
@@ -132,7 +138,8 @@
     def getNumPages(self,docinfo=None):
         """get list of pages from fulltext and put in docinfo"""
         xquery = '//pb'
-        text = self.template.fulltextclient.eval("/mpdl/interface/xquery.xql", "document=%s&xquery=%s"%(docinfo['textURLPath'],xquery))
+        text = urllib2.urlopen("http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/xquery.xql","document=%s&xquery=%s"%(docinfo['textURLPath'],xquery))
+        #text = self.template.fulltextclient.eval("/mpdl/interface/xquery.xql", "document=%s&xquery=%s"%(docinfo['textURLPath'],xquery))
         docinfo['numPages'] = text.count("<pb ")
         return docinfo
        
@@ -153,7 +160,10 @@
         textParam = "document=%s&mode=%s&pn=%s"%(docpath,textmode,pn)
         if highlightQuery is not None:
             textParam +="&highlightQuery=%s&sn=%s"%(highlightQuery,sn)           
-        pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False)
+        
+        pagexml = urllib2.urlopen("http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/page-fragment.xql",textParam)
+        """pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False)"""
+        
         pagedom = Parse(pagexml)
         # plain text mode
         if mode == "text":
@@ -216,18 +226,28 @@
 
     def getTranslate(self, query=None, language=None):
         """translate into another languages"""
-        pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
-        return pagexml
+        pagexml = urllib2.urlopen("http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
+        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
+        data = pagexml.read()
+        pagexml.close()
+        return data
     
     def getLemma(self, lemma=None, language=None):
         """simular words lemma """
-        pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma)))
-        return pagexml
+        pagexml = urllib2.urlopen("http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma)))
+        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma)))
+        data = pagexml.read()
+        pagexml.close()
+        return data
     
     def getLemmaNew(self, query=None, language=None):
         """simular words lemma """
-        pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query)))
-        return pagexml
+        
+        pagexml = urllib2.urlopen("http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query)))
+        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query)))
+        data = pagexml.read()
+        pagexml.close()
+        return data
 
     def getQuery (self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1):
          """number of"""
@@ -238,7 +258,9 @@
          queryType =pageinfo['queryType']
          tocSearch = 0
          tocDiv = None
-         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)
+         
+         pagexml = urllib2.urlopen("http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, 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)
          numdivs = pagedom.xpath("//div[@class='queryResultHits']")
          tocSearch = int(getTextFromNode(numdivs[0]))
@@ -266,7 +288,9 @@
         # number of entries in toc
         tocSize = 0
         tocDiv = None
-        pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False)
+        
+        pagexml = urllib2.urlopen("http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/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)
         # post-processing downloaded xml
         pagedom = Parse(pagexml)
         # get number of entries
@@ -291,9 +315,13 @@
         selfurl = self.absolute_url()  
         viewMode=  pageinfo['viewMode']
         tocMode = pageinfo['tocMode']
-        tocPN = pageinfo['tocPN']    
-        pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn), outputUnicode=False)
-        page = pagexml.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s'%(selfurl,url, viewMode, tocMode, tocPN))
+        tocPN = pageinfo['tocPN']  
+        
+        pagexml = urllib2.urlopen("http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))  
+        data = pagexml.read()
+        pagexml.close()
+
+        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')
         return text