changeset 551:f558624d3f73

add attributes for pundit.
author casties
date Wed, 19 Sep 2012 10:13:52 +0200
parents a35ec08c782d
children 13eb36c0b00c
files MpdlXmlTextServer.py version.txt
diffstat 2 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MpdlXmlTextServer.py	Fri Sep 07 18:14:12 2012 +0200
+++ b/MpdlXmlTextServer.py	Wed Sep 19 10:13:52 2012 +0200
@@ -250,6 +250,13 @@
             # ignore mode in the following
             modes.remove('search')
                             
+        # pundit mode
+        punditMode = False
+        if 'pundit' in modes:
+            punditMode = True
+            # ignore mode in the following
+            modes.remove('pundit')
+                            
         # other modes don't combine
         if 'dict' in modes:
             # dict is called textPollux in the backend
@@ -288,6 +295,10 @@
             # get full url assuming documentViewer is parent
             selfurl = self.getLink()
             if pagediv is not None:
+                if punditMode:
+                    pagediv = self.addPunditAttributes(pagediv, pageinfo, docinfo)
+                    
+                # check all a-tags
                 links = pagediv.findall(".//a")
                 for l in links:
                     href = l.get('href')
@@ -302,6 +313,9 @@
             if pagediv is not None:
                 viewerurl = docinfo['viewerUrl']
                 selfurl = self.getLink()
+                if punditMode:
+                    pagediv = self.addPunditAttributes(pagediv, pageinfo, docinfo)
+                    
                 # check all a-tags
                 links = pagediv.findall(".//a")
                 for l in links:
@@ -361,6 +375,22 @@
                     
         return None
     
+    def addPunditAttributes(self, pagediv, pageinfo, docinfo):
+        """add about attributes for pundit annotation tool"""
+        textid = docinfo.get('DRI', "fn=%s"%docinfo.get('documentPath', '???'))
+        pn = pageinfo.get('pn', '1')
+        #  TODO: use pn as well?
+        # check all div-tags
+        divs = pagediv.findall(".//div")
+        for d in divs:
+            id = d.get('id')
+            if id:
+                d.set('about', "http://echo.mpiwg-berlin.mpg.de/%s/pn=%s/#%s"%(textid,pn,id))
+                cls = d.get('class','')
+                cls += ' pundit-content'
+                d.set('class', cls.strip())
+
+        return pagediv
 
     def getSearchResults(self, mode, query=None, pageinfo=None, docinfo=None):
         """loads list of search results and stores XML in docinfo"""
--- a/version.txt	Fri Sep 07 18:14:12 2012 +0200
+++ b/version.txt	Wed Sep 19 10:13:52 2012 +0200
@@ -1,1 +1,1 @@
-DocumentViewer 2.2.2
\ No newline at end of file
+DocumentViewer 2.2.3
\ No newline at end of file