Index: MpiwgXmlTextServer.py
===================================================================
--- MpiwgXmlTextServer.py	(revision 565)
+++ MpiwgXmlTextServer.py	(revision 566)
@@ -307,41 +307,14 @@
         logging.debug("pagediv: %s"%repr(pagediv))
         
-        # plain text mode
-        if textmode == "text":
+        # plain text or text-with-links mode
+        if textmode == "text" or textmode == "dict":
             if pagediv is not None:
-                # handle pb-tag
-                self._extractPbTag(pagediv, pageinfo)
+                self._processPbTag(pagediv, pageinfo)
+                self._processFigures(pagediv, docinfo)
+                #self._fixEmptyDivs(pagediv)
                 # get full url assuming documentViewer is parent
                 selfurl = self.getLink()
-                if punditMode:
-                    self._addPunditAttributes(pagediv, pageinfo, docinfo)
-                    
-                # fix empty div tags
-                self._fixEmptyDivs(pagediv)
                 # check all a-tags
                 links = pagediv.findall('.//a')
-                for l in links:
-                    href = l.get('href')
-                    # handle notes FIXME!
-                    if href and href.startswith('#note-'):
-                        href = href.replace('#note-',"%s#note-"%selfurl)
-                        l.set('href', href)
-                        
-                return serialize(pagediv)
-            
-        # text-with-links mode
-        elif textmode == "dict":
-            if pagediv is not None:
-                # handle pb-div
-                self._extractPbTag(pagediv, pageinfo)
-                viewerurl = docinfo['viewerUrl']
-                selfurl = self.getLink()
-                if punditMode:
-                    pagediv = self.addPunditAttributes(pagediv, pageinfo, docinfo)
-                    
-                # fix empty div tags
-                self._fixEmptyDivs(pagediv)   
-                # check all a-tags
-                links = pagediv.findall(".//a")
                 for l in links:
                     href = l.get('href')
@@ -349,5 +322,4 @@
                         # is link with href
                         linkurl = urlparse.urlparse(href)
-                        #logging.debug("getTextPage: linkurl=%s"%repr(linkurl))
                         if linkurl.path.endswith('GetDictionaryEntries'):
                             #TODO: replace wordInfo page
@@ -357,8 +329,11 @@
                             l.set('target', '_blank')
                                                           
-                        if href.startswith('#note-'):
-                            # note link
+                        elif href.startswith('#note-'):
+                            # note link FIXME!
                             l.set('href', href.replace('#note-',"%s#note-"%selfurl))
-                              
+                        
+                if punditMode:
+                    self._addPunditAttributes(pagediv, pageinfo, docinfo)
+                    
                 return serialize(pagediv)
             
@@ -373,5 +348,5 @@
                 return serialize(pagediv)
                   
-        # gis mode
+        # gis mode FIXME!
         elif textmode == "gis":
             if pagediv is not None:
@@ -394,5 +369,5 @@
         return None
 
-    def _extractPbTag(self, pagediv, pageinfo):
+    def _processPbTag(self, pagediv, pageinfo):
         """extracts information from pb-tag and removes it from pagediv"""
         pbdiv = pagediv.find(".//span[@class='pb']")
@@ -421,4 +396,5 @@
             id = d.get('id')
             if id:
+                # TODO: check path (cf RFC2396)
                 d.set('about', "http://echo.mpiwg-berlin.mpg.de/%s/pn=%s/#%s"%(textid,pn,id))
                 cls = d.get('class','')
@@ -428,4 +404,34 @@
         return pagediv
 
+    def _processFigures(self, pagediv, docinfo):
+        """processes figure-tags"""
+        divs = pagediv.findall(".//span[@class='figure']")
+        scalerUrl = docinfo['digilibScalerUrl']
+        viewerUrl = docinfo['digilibViewerUrl']
+        for d in divs:
+            try:
+                a = d.find('a')
+                img = a.find('img')
+                imgsrc = img.get('src')
+                imgurl = urlparse.urlparse(imgsrc)
+                imgq = imgurl.query
+                imgparams = urlparse.parse_qs(imgq)
+                fn = imgparams.get('fn', None)
+                if fn is not None:
+                    # parse_qs puts parameters in lists
+                    fn = fn[0]
+                    # TODO: check valid path
+                    # fix img@src
+                    newsrc = '%s?fn=%s&dw=200&dh=200'%(scalerUrl,fn)
+                    img.set('src', newsrc)
+                    # fix a@href
+                    newlink = '%s?fn=%s'%(viewerUrl,fn)
+                    a.set('href', newlink)
+                    a.set('target', '_blank')
+                    
+            except:
+                logging.warn("processFigures: strange figure!")
+                
+    
     def _fixEmptyDivs(self, pagediv):
         """fixes empty div-tags by inserting a space"""
Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 565)
+++ documentViewer.py	(revision 566)
@@ -200,4 +200,6 @@
         if digilibBaseUrl is not None:
             self.digilibBaseUrl = digilibBaseUrl
+            self.digilibScalerUrl = digilibBaseUrl + '/servlet/Scaler'
+            self.digilibViewerUrl = digilibBaseUrl + '/jquery/digilib.html'
             
         
@@ -361,5 +363,5 @@
             
         if url is None:
-            url = "%s/servlet/Scaler?"%self.digilibBaseUrl
+            url = self.digilibScalerUrl
             if fn is None and docinfo is not None:
                 fn = docinfo.get('imagePath','')
@@ -544,4 +546,6 @@
         docinfo['viewerUrl'] = self.getDocumentViewerURL()
         docinfo['digilibBaseUrl'] = self.digilibBaseUrl
+        docinfo['digilibScalerUrl'] = self.digilibScalerUrl
+        docinfo['digilibViewerUrl'] = self.digilibViewerUrl
         # get index.meta DOM
         docUrl = None
@@ -563,5 +567,5 @@
         elif mode=="filepath":
             # url points to image file, index.meta optional
-            docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + url
+            docinfo['imageURL'] = "%s?fn=%s"%(self.digilibScalerUrl, url)
             docinfo['numPages'] = 1
             # asssume index.meta is two path segments up
@@ -637,5 +641,5 @@
             if docinfo.get('imagePath', None):
                 imgpath = docinfo['imagePath'].replace('/mpiwg/online/', '', 1)
-                docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + imgpath
+                docinfo['imageURL'] = "%s?fn=%s"%(self.digilibScalerUrl, imgpath)
                 docinfo = self.getDocinfoFromDigilib(docinfo, imgpath)
             else:
@@ -646,5 +650,5 @@
                     # there are pages
                     docinfo['imagePath'] = imgPath
-                    docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + docinfo['imagePath']
+                    docinfo['imageURL'] = "%s?fn=%s"%(self.digilibScalerUrl, docinfo['imagePath'])
 
         # check numPages
@@ -1045,4 +1049,6 @@
         self.title=title
         self.digilibBaseUrl = digilibBaseUrl
+        self.digilibScalerUrl = digilibBaseUrl + '/servlet/Scaler'
+        self.digilibViewerUrl = digilibBaseUrl + '/jquery/digilib.html'
         self.thumbrows = thumbrows
         self.thumbcols = thumbcols
