annotate MpiwgXmlTextServer.py @ 635:8d460ddb45b7 default tip

update digilib dirInfo-xml path.
author casties
date Fri, 06 May 2016 18:59:35 +0200
parents 4a75a760def2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
1 from OFS.SimpleItem import SimpleItem
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
2 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
3
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
4 import xml.etree.ElementTree as ET
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
5
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
6 import re
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
7 import logging
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
8 import urllib
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
9 import urlparse
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
10 import base64
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
11
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
12 from datetime import datetime
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
13
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 610
diff changeset
14 from SrvTxtUtils import getInt, getText, getHttpData, serialize
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
15
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
16 # mapping of fields in the output of /mpiwg-mpdl-cms-web/query/GetDocInfo to documentViewer docinfo
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
17 textinfoFieldMap = {
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
18 'countPages' : 'numTextPages',
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
19 'countFigures' : 'numFigureEntries',
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
20 'countNotesHandwritten' : 'numHandwritten',
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
21 'countNotes' : 'numNotes',
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
22 'countPlaces' : 'numPlaces',
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
23 'countTocEntries' : 'numTocEntries'
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
24 }
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
25
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
26
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
27 class MpiwgXmlTextServer(SimpleItem):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
28 """TextServer implementation for MPIWG-XML server"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
29 meta_type="MPIWG-XML TextServer"
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
30
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
31 manage_options=(
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
32 {'label':'Config','action':'manage_changeMpiwgXmlTextServerForm'},
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
33 )+SimpleItem.manage_options
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
34
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
35 manage_changeMpiwgXmlTextServerForm = PageTemplateFile("zpt/manage_changeMpiwgXmlTextServer", globals())
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
36
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
37 def __init__(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpiwg-mpdl-cms-web/", timeout=40, serverName=None, repositoryType='production'):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
38 """constructor"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
39 self.id=id
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
40 self.title=title
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
41 self.timeout = timeout
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
42 self.repositoryType = repositoryType
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
43 if serverName is None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
44 self.serverUrl = serverUrl
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
45 else:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
46 self.serverUrl = "http://%s/mpiwg-mpdl-cms-web/"%serverName
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
47
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
48 def getHttpData(self, url, data=None):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
49 """returns result from url+data HTTP request"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
50 return getHttpData(url,data,timeout=self.timeout)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
51
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
52 def getServerData(self, method, data=None):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
53 """returns result from text server for method+data"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
54 url = self.serverUrl+method
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
55 return getHttpData(url,data,timeout=self.timeout)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
56
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
57
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
58 def getRepositoryType(self):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
59 """returns the repository type, e.g. 'production'"""
572
51800c42bcda deal with empty repositoryType
casties
parents: 570
diff changeset
60 return getattr(self, 'repositoryType', None)
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
61
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
62 def getTextDownloadUrl(self, type='xml', docinfo=None):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
63 """returns a URL to download the current text"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
64 docpath = docinfo.get('textURLPath', None)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
65 if not docpath:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
66 return None
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
67
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
68 docpath = docpath.replace('.xml','.'+type)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
69 url = '%sdoc/GetDocument?id=%s'%(self.serverUrl.replace('interface/',''), docpath)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
70 return url
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
71
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
72
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
73 def getPlacesOnPage(self, docinfo=None, pn=None):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
74 """Returns list of GIS places of page pn"""
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
75 logging.debug("getPlacesOnPage(pn=%s"%pn)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
76 if not 'places' in docinfo:
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
77 self.getTextInfo('places', docinfo)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
78
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
79 allplaces = docinfo.get('places', None)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
80 if len(allplaces) == 0:
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
81 return []
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
82
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
83 # search for places on this page TODO: is there a better way?
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
84 places = [p for p in allplaces if p['pn'] == pn]
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
85 return places
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
86 """OLD:
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
87 docpath = docinfo.get('textURLPath',None)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
88 if not docpath:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
89 return None
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
90
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
91 places=[]
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
92 text=self.getServerData("xpath.xql", "document=%s&xpath=//place&pn=%s"%(docpath,pn))
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
93 dom = ET.fromstring(text)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
94 result = dom.findall(".//resultPage/place")
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
95 for l in result:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
96 id = l.get("id")
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
97 name = l.text
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
98 place = {'id': id, 'name': name}
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
99 places.append(place)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
100
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
101 return places"""
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
102
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
103
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
104 def getTextInfo(self, mode=None, docinfo=None):
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
105 """reads document info, including page concordance, from text server"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
106 logging.debug("getTextInfo mode=%s"%mode)
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
107
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
108 field = ''
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
109 if mode in ['pages', 'toc', 'figures', 'notes', 'handwritten', 'places']:
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
110 # translate mode to field param
609
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
111 if mode == 'handwritten':
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
112 field = '&field=notesHandwritten'
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
113 else:
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
114 field = '&field=%s'%mode
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
115 else:
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
116 mode = None
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
117
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
118 # check cached info
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
119 if mode:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
120 # cached toc-request?
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
121 if 'full_%s'%mode in docinfo:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
122 return docinfo
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
123
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
124 else:
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
125 # cached but no toc-request?
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
126 if 'numTextPages' in docinfo:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
127 return docinfo
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
128
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
129 docpath = docinfo.get('textURLPath', None)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
130 if docpath is None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
131 logging.error("getTextInfo: no textURLPath!")
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
132 return docinfo
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
133
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
134 # fetch docinfo
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
135 pagexml = self.getServerData("query/GetDocInfo","docId=%s%s"%(docpath,field))
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
136 dom = ET.fromstring(pagexml)
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
137 # all info in tag <doc>
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
138 doc = dom
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
139 if doc is None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
140 logging.error("getTextInfo: unable to find document-tag!")
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
141 else:
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
142 if mode is None:
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
143 # get general info from system-tag
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
144 sys = doc.find('system')
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
145 if sys is not None:
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
146 for (k,v) in textinfoFieldMap.items():
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
147 # copy into docinfo (even if empty)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
148 docinfo[v] = getInt(getText(sys.find(k)))
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
149
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
150 else:
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
151 # result is in list-tag
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
152 l = doc.find('list')
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
153 if l is not None:
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
154 # look for general info
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
155 for (k,v) in textinfoFieldMap.items():
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
156 # copy into docinfo (only if not empty)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
157 s = doc.find(k)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
158 if s is not None:
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
159 docinfo[v] = getInt(getText(s))
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
160
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
161 lt = l.get('type')
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
162 #
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
163 # pageNumbers
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
164 #
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
165 if lt == 'pages':
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
166 # contains tags with page numbers
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
167 # <item n="14" o="2" o-norm="2" file="0014"/>
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
168 # n=scan number, o=original page no, on=normalized original page no
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
169 # pageNumbers is a dict indexed by scan number
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
170 pages = {}
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
171 for i in l:
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
172 page = {}
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
173 pn = getInt(i.get('n'))
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
174 page['pn'] = pn
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
175 no = i.get('o')
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
176 page['no'] = no
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
177 non = i.get('o-norm')
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
178 page['non'] = non
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
179
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
180 if pn > 0:
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
181 pages[pn] = page
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
182
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
183 docinfo['pageNumbers'] = pages
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
184
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
185 #
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
186 # toc
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
187 #
609
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
188 elif lt in ['toc', 'figures', 'notes', 'notesHandwritten']:
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
189 # contains tags with table of contents/figures
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
190 # <item n="2.1." lv="2">CAP.I. <ref o="119">132</ref></item>
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
191 tocs = []
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
192 for te in l:
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
193 if te.tag == 'item':
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
194 toc = {}
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
195 toc['level-string'] = te.get('n')
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
196 toc['level'] = te.get('lv')
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
197 toc['content'] = te.text.strip()
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
198 ref = te.find('ref')
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
199 toc['pn'] = getInt(ref.text)
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
200 toc['no'] = ref.get('o')
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
201 toc['non'] = ref.get('o-norm')
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
202 tocs.append(toc)
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
203
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
204 # save as full_toc/full_figures
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
205 docinfo['full_%s'%mode] = tocs
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
206
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
207 #
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
208 # places
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
209 #
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
210 #
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
211 # toc
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
212 #
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
213 elif lt in ['places']:
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
214 # contains tags with place-ids
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
215 # <item id="N40004F-01"><ref>4</ref></item>
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
216 places = []
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
217 for p in l:
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
218 if p.tag == 'item':
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
219 place = {}
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
220 place['id'] = p.get('id')
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
221 ref = p.find('ref')
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
222 place['pn'] = getInt(ref.text)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
223 places.append(place)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
224
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
225 docinfo['places'] = places
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
226
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
227 return docinfo
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
228
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
229
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
230 def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
231 """returns single page from fulltext"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
232
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
233 logging.debug("getTextPage mode=%s, pn=%s"%(mode,pn))
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
234 startTime = datetime.now()
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
235 # check for cached text -- but ideally this shouldn't be called twice
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
236 if pageinfo.has_key('textPage'):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
237 logging.debug("getTextPage: using cached text")
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
238 return pageinfo['textPage']
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
239
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
240 docpath = docinfo.get('textURLPath', None)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
241 if not docpath:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
242 return None
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
243
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
244 # stuff for constructing full urls
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
245 selfurl = docinfo['viewerUrl']
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
246 textParams = {'docId': docpath,
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
247 'page': pn}
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
248
575
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
249 normMode = pageinfo.get('characterNormalization', 'reg')
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
250 # TODO: change values in form
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
251 if normMode == 'regPlusNorm':
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
252 normMode = 'norm'
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
253
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
254 # TODO: this should not be necessary when the backend is fixed
579
fc861a6cef17 update in w-tag format.
casties
parents: 577
diff changeset
255 #textParams['normalization'] = normMode
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
256
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
257 if not mode:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
258 # default is dict
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
259 mode = 'text'
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
260
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
261 modes = mode.split(',')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
262 # check for multiple layers
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
263 if len(modes) > 1:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
264 logging.debug("getTextPage: more than one mode=%s"%mode)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
265
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
266 # mode defaults
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
267 gisMode = False
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
268 punditMode = False
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
269
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
270 # search mode
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
271 if 'search' in modes:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
272 # add highlighting
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
273 highlightQuery = pageinfo.get('highlightQuery', None)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
274 if highlightQuery:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
275 textParams['highlightQuery'] = highlightQuery
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
276 textParams['highlightElem'] = pageinfo.get('highlightElement', '')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
277 textParams['highlightElemPos'] = pageinfo.get('highlightElementPos', '')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
278
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
279 # ignore mode in the following
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
280 modes.remove('search')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
281
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
282 # pundit mode
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
283 if 'pundit' in modes:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
284 punditMode = True
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
285 # ignore mode in the following
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
286 modes.remove('pundit')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
287
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
288 # other modes don't combine
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
289 if 'dict' in modes:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
290 textmode = 'dict'
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
291 textParams['outputFormat'] = 'html'
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
292 elif 'xml' in modes:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
293 textmode = 'xml'
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
294 textParams['outputFormat'] = 'xmlDisplay'
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
295 normMode = 'orig'
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
296 elif 'gis' in modes:
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
297 gisMode = True
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
298 # gis mode uses plain text
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
299 textmode = 'plain'
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
300 textParams['outputFormat'] = 'html'
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
301 else:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
302 # text is default mode
575
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
303 textmode = 'plain'
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
304 textParams['outputFormat'] = 'html'
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
305
632
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
306
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
307
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
308 try:
570
61d53ccbdd70 more resilience to server errors.
casties
parents: 568
diff changeset
309 # fetch the page
632
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
310
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
311
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
312
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
313
570
61d53ccbdd70 more resilience to server errors.
casties
parents: 568
diff changeset
314 pagexml = self.getServerData("query/GetPage",urllib.urlencode(textParams))
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
315 dom = ET.fromstring(pagexml)
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
316 except Exception, e:
570
61d53ccbdd70 more resilience to server errors.
casties
parents: 568
diff changeset
317 logging.error("Error reading page: %s"%e)
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
318 return None
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
319
566
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
320 # plain text or text-with-links mode
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
321 if textmode == 'plain' or textmode == 'dict':
574
4778900ae3e2 viewMode=xml works now
casties
parents: 572
diff changeset
322 # the text is in div@class=text
4778900ae3e2 viewMode=xml works now
casties
parents: 572
diff changeset
323 pagediv = dom.find(".//div[@class='text']")
4778900ae3e2 viewMode=xml works now
casties
parents: 572
diff changeset
324 logging.debug("pagediv: %s"%repr(pagediv))
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
325 if pagediv is not None:
575
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
326 # add textmode and normMode classes
579
fc861a6cef17 update in w-tag format.
casties
parents: 577
diff changeset
327 #pagediv.set('class', 'text %s %s'%(textmode, normMode))
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
328 self._processWTags(textmode, normMode, pagediv)
567
8b1e20bf300d more new textserver
casties
parents: 566
diff changeset
329 #self._processPbTag(pagediv, pageinfo)
566
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
330 self._processFigures(pagediv, docinfo)
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
331 #self._fixEmptyDivs(pagediv)
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
332 # get full url assuming documentViewer is parent
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
333 selfurl = self.getLink()
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
334 # check all a-tags
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
335 links = pagediv.findall('.//a')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
336 for l in links:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
337 href = l.get('href')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
338 if href:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
339 # is link with href
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
340 linkurl = urlparse.urlparse(href)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
341 if linkurl.path.endswith('GetDictionaryEntries'):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
342 #TODO: replace wordInfo page
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
343 # add target to open new page
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
344 l.set('target', '_blank')
566
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
345
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
346 if punditMode:
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
347 self._addPunditAttributes(pagediv, pageinfo, docinfo)
577
9251719154a3 toc with list of handwritten notes.
casties
parents: 576
diff changeset
348
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
349 if gisMode:
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
350 self._addGisTags(pagediv, pageinfo, docinfo)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
351
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
352 s = serialize(pagediv)
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
353 logging.debug("getTextPage done in %s"%(datetime.now()-startTime))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
354 return s
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
355
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
356 # xml mode
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
357 elif textmode == "xml":
574
4778900ae3e2 viewMode=xml works now
casties
parents: 572
diff changeset
358 # the text is in body
4778900ae3e2 viewMode=xml works now
casties
parents: 572
diff changeset
359 pagediv = dom.find(".//body")
4778900ae3e2 viewMode=xml works now
casties
parents: 572
diff changeset
360 logging.debug("pagediv: %s"%repr(pagediv))
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
361 if pagediv is not None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
362 return serialize(pagediv)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
363
579
fc861a6cef17 update in w-tag format.
casties
parents: 577
diff changeset
364 logging.error("getTextPage: error in text mode %s or in text!"%(textmode))
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
365 return None
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
366
575
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
367 def _processWTags(self, textMode, normMode, pagediv):
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
368 """selects the necessary information from w-spans and removes the rest from pagediv"""
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
369 logging.debug("processWTags(textMode=%s,norm=%s,pagediv"%(repr(textMode),repr(normMode)))
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
370 startTime = datetime.now()
575
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
371 wtags = pagediv.findall(".//span[@class='w']")
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
372 for wtag in wtags:
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
373 if textMode == 'dict':
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
374 # delete non-a-tags
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
375 wtag.remove(wtag.find("span[@class='nodictionary orig']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
376 wtag.remove(wtag.find("span[@class='nodictionary reg']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
377 wtag.remove(wtag.find("span[@class='nodictionary norm']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
378 # delete non-matching children of a-tag and suppress remaining tag name
579
fc861a6cef17 update in w-tag format.
casties
parents: 577
diff changeset
379 atag = wtag.find("*[@class='dictionary']")
632
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
380
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
381 if atag is None: #nicht gefunden weil noch andere Eintraege im class tag
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
382 for w in wtag.findall("a"):
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
383 val = w.attrib.get("class","")
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
384 if val.startswith("dictionary"):
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
385 atag=w
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
386 break
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
387
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
388
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
389
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
390
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
391
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
392 if normMode == 'orig':
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
393 atag.remove(atag.find("span[@class='reg']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
394 atag.remove(atag.find("span[@class='norm']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
395 atag.find("span[@class='orig']").tag = None
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
396 elif normMode == 'reg':
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
397 atag.remove(atag.find("span[@class='orig']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
398 atag.remove(atag.find("span[@class='norm']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
399 atag.find("span[@class='reg']").tag = None
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
400 elif normMode == 'norm':
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
401 atag.remove(atag.find("span[@class='orig']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
402 atag.remove(atag.find("span[@class='reg']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
403 atag.find("span[@class='norm']").tag = None
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
404
575
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
405 else:
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
406 # delete a-tag
632
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
407
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
408
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
409 wt = wtag.find("*[@class='dictionary']")
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
410
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
411 if wt is None: #nicht gefunden weil noch andere Eintraege im class tag vorhanden sind
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
412 for w in wtag.findall("a"):
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
413 val = w.attrib.get("class","")
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
414 if val.startswith("dictionary"):
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
415 wt=w
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
416 break
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
417
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
418
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
419
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
420
4a75a760def2 dictionary handling added
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 613
diff changeset
421 wtag.remove(wt)
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
422 # delete non-matching children and suppress remaining tag name
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
423 if normMode == 'orig':
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
424 wtag.remove(wtag.find("span[@class='nodictionary reg']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
425 wtag.remove(wtag.find("span[@class='nodictionary norm']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
426 wtag.find("span[@class='nodictionary orig']").tag = None
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
427 elif normMode == 'reg':
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
428 wtag.remove(wtag.find("span[@class='nodictionary orig']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
429 wtag.remove(wtag.find("span[@class='nodictionary norm']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
430 wtag.find("span[@class='nodictionary reg']").tag = None
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
431 elif normMode == 'norm':
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
432 wtag.remove(wtag.find("span[@class='nodictionary orig']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
433 wtag.remove(wtag.find("span[@class='nodictionary reg']"))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
434 wtag.find("span[@class='nodictionary norm']").tag = None
575
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
435
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
436 # suppress w-tag name
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
437 wtag.tag = None
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
438
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
439 logging.debug("processWTags in %s"%(datetime.now()-startTime))
575
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
440 return pagediv
f0e5e9c6737f new w-tag solution with css.
casties
parents: 574
diff changeset
441
566
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
442 def _processPbTag(self, pagediv, pageinfo):
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
443 """extracts information from pb-tag and removes it from pagediv"""
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
444 pbdiv = pagediv.find(".//span[@class='pb']")
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
445 if pbdiv is None:
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
446 logging.warning("getTextPage: no pb-span!")
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
447 return pagediv
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
448
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
449 # extract running head
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
450 rh = pbdiv.find(".//span[@class='rhead']")
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
451 if rh is not None:
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
452 pageinfo['pageHeaderTitle'] = getText(rh)
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
453
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
454 # remove pb-div from parent
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
455 ppdiv = pagediv.find(".//span[@class='pb']/..")
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
456 ppdiv.remove(pbdiv)
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
457 return pagediv
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
458
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
459 def _addPunditAttributes(self, pagediv, pageinfo, docinfo):
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
460 """add about-attributes to divs for pundit annotation tool"""
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
461 textid = docinfo.get('DRI', "fn=%s"%docinfo.get('documentPath', '???'))
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
462 pn = pageinfo.get('pn', '1')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
463 # check all div-tags
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
464 divs = pagediv.findall(".//div")
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
465 for d in divs:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
466 id = d.get('id')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
467 if id:
566
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
468 # TODO: check path (cf RFC2396)
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
469 d.set('about', "http://echo.mpiwg-berlin.mpg.de/%s/pn=%s/#%s"%(textid,pn,id))
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
470 cls = d.get('class','')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
471 cls += ' pundit-content'
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
472 d.set('class', cls.strip())
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
473
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
474 return pagediv
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
475
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
476 def _addGisTags(self, pagediv, pageinfo, docinfo):
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
477 """add links for gis places"""
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
478 # use last part of documentPath as db-id
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
479 docpath = docinfo.get('documentPath', '')
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
480 textid = docpath.split('/')[-1]
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
481 # add our URL as backlink
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
482 selfurl = self.getLink()
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
483 doc = base64.b64encode(selfurl)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
484 # check all span@class=place
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
485 spans = pagediv.findall(".//span[@class='place']")
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
486 for s in spans:
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
487 id = s.get('id')
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
488 if id:
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
489 # make links like http://mappit.mpiwg-berlin.mpg.de/db/RESTdb/db/mpdl/songy_tiang_zh_1637?id=N400061-02&doc=aHR...&format=gis
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
490 s.tag = 'a'
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
491 # TODO: make links configurable
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
492 url = "http://mappit.mpiwg-berlin.mpg.de/db/RESTdb/db/mpdl/%s?id=%s&doc=%s&format=gis"%(textid,id,doc)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
493 s.set('href', url)
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
494 s.set('target', '_blank')
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
495
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
496 return pagediv
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
497
566
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
498 def _processFigures(self, pagediv, docinfo):
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
499 """processes figure-tags"""
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
500 # unfortunately etree can not select class.startswith('figure')
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
501 divs = pagediv.findall(".//span[@class]")
566
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
502 scalerUrl = docinfo['digilibScalerUrl']
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
503 viewerUrl = docinfo['digilibViewerUrl']
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
504 for d in divs:
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
505 if not d.get('class').startswith('figure'):
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
506 continue
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
507
566
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
508 try:
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
509 a = d.find('a')
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
510 img = a.find('img')
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
511 imgsrc = img.get('src')
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
512 imgurl = urlparse.urlparse(imgsrc)
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
513 imgq = imgurl.query
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
514 imgparams = urlparse.parse_qs(imgq)
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
515 fn = imgparams.get('fn', None)
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
516 if fn is not None:
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
517 # parse_qs puts parameters in lists
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
518 fn = fn[0]
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
519 # TODO: check valid path
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
520 # fix img@src
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
521 newsrc = '%s?fn=%s&dw=200&dh=200'%(scalerUrl,fn)
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
522 img.set('src', newsrc)
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
523 # fix a@href
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
524 newlink = '%s?fn=%s'%(viewerUrl,fn)
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
525 a.set('href', newlink)
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
526 a.set('target', '_blank')
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
527
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
528 except:
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
529 logging.warn("processFigures: strange figure!")
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
530
583
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
531
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
532 def _cleanSearchResult(self, pagediv):
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
533 """fixes search result html (change pbs and figures)"""
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
534 # replace figure-tag with figureNumText
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
535 for fig in pagediv.findall(".//span[@class='figure']"):
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
536 txt = fig.findtext(".//span[@class='figureNumText']")
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
537 tail = fig.tail
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
538 fig.clear()
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
539 fig.set('class', 'figure')
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
540 fig.text = txt
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
541 fig.tail = tail
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
542
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
543 # replace lb-tag with "//"
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
544 for lb in pagediv.findall(".//br[@class='lb']"):
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
545 lb.tag = 'span'
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
546 lb.text = '//'
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
547
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
548 # replace pb-tag with "///"
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
549 for pb in pagediv.findall(".//span[@class='pb']"):
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
550 tail = pb.tail
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
551 pb.clear()
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
552 pb.set('class', 'pb')
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
553 pb.text = '///'
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
554 pb.tail = tail
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
555
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
556 return pagediv
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
557
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
558 def _cleanSearchResult2(self, pagediv):
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
559 """fixes search result html (change pbs and figures)"""
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
560 # unfortunately etree can not select class.startswith('figure')
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
561 divs = pagediv.findall(".//span[@class]")
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
562 for d in divs:
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
563 cls = d.get('class')
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
564 if cls.startswith('figure'):
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
565 # replace figure-tag with figureNumText
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
566 txt = d.findtext(".//span[@class='figureNumText']")
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
567 d.clear()
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
568 d.set('class', 'figure')
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
569 d.text = txt
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
570
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
571 elif cls.startswith('pb'):
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
572 # replace pb-tag with "//"
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
573 d.clear()
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
574 d.set('class', 'pb')
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
575 d.text = '//'
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
576
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
577 return pagediv
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
578
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
579
566
4a31608f8b0e more new MpiwgXmlTextServer.
casties
parents: 565
diff changeset
580
565
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
581 def _fixEmptyDivs(self, pagediv):
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
582 """fixes empty div-tags by inserting a space"""
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
583 divs = pagediv.findall('.//div')
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
584 for d in divs:
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
585 if len(d) == 0 and not d.text:
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
586 # make empty divs non-empty
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
587 d.text = ' '
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
588
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
589 return pagediv
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
590
1b483194901c more new MpiwgXmlTextServer.
casties
parents: 564
diff changeset
591
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
592 def getSearchResults(self, mode, query=None, pageinfo=None, docinfo=None):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
593 """loads list of search results and stores XML in docinfo"""
583
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
594 normMode = pageinfo.get('characterNormalization', 'reg')
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
595 logging.debug("getSearchResults mode=%s query=%s norm=%s"%(mode, query, normMode))
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
596 if mode == "none":
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
597 return docinfo
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
598
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
599 #TODO: put mode into query
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
600
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
601 cachedQuery = docinfo.get('cachedQuery', None)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
602 if cachedQuery is not None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
603 # cached search result
583
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
604 if cachedQuery == '%s_%s_%s'%(mode,query,normMode):
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
605 # same query
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
606 return docinfo
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
607
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
608 else:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
609 # different query
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
610 del docinfo['resultSize']
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
611 del docinfo['results']
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
612
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
613 # cache query
583
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
614 docinfo['cachedQuery'] = '%s_%s_%s'%(mode,query,normMode)
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
615
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
616 # fetch full results
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
617 docpath = docinfo['textURLPath']
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
618 params = {'docId': docpath,
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
619 'query': query,
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
620 'pageSize': 1000,
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
621 'page': 1,
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
622 'outputFormat': 'html'}
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
623 pagexml = self.getServerData("query/QueryDocument",urllib.urlencode(params))
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
624 results = []
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
625 try:
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
626 dom = ET.fromstring(pagexml)
583
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
627 # clean html output
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
628 self._processWTags('plain', normMode, dom)
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
629 self._cleanSearchResult(dom)
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
630 # page content is currently in multiple <td align=left>
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
631 alldivs = dom.findall(".//tr[@class='hit']")
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
632 for div in alldivs:
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
633 # change tr to div
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
634 div.tag = 'div'
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
635 # change td to span
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
636 for d in div.findall('td'):
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
637 d.tag = 'span'
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
638
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
639 # TODO: can we put etree in the session?
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
640 results.append(div)
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
641
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
642 except Exception, e:
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
643 logging.error("GetSearchResults: Error parsing search result: %s"%e)
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
644
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
645 # store results in docinfo
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
646 docinfo['resultSize'] = len(results)
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
647 docinfo['results'] = results
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
648
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
649 return docinfo
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
650
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
651
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
652 def getResultsPage(self, mode="text", query=None, pn=None, start=None, size=None, pageinfo=None, docinfo=None):
583
ca0274423382 follow changes in html format of new text-backend.
casties
parents: 579
diff changeset
653 """returns single page from the list of search results"""
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
654 logging.debug("getResultsPage mode=%s, pn=%s"%(mode,pn))
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
655 # get (cached) result
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
656 self.getSearchResults(mode=mode, query=query, pageinfo=pageinfo, docinfo=docinfo)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
657
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
658 resultxml = docinfo.get('results', None)
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
659 if not resultxml:
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
660 logging.error("getResultPage: unable to find results")
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
661 return "Error: no result!"
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
662
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
663 if size is None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
664 size = pageinfo.get('resultPageSize', 10)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
665
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
666 if start is None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
667 start = (pn - 1) * size
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
668
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
669 if resultxml is not None:
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
670 # paginate
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
671 first = start-1
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
672 last = first+size
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
673 tocdivs = resultxml[first:last]
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
674
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
675 toc = ET.Element('div', attrib={'class':'queryResultPage'})
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
676 for div in tocdivs:
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
677 # check all a-tags
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
678 links = div.findall(".//a")
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
679 for l in links:
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
680 href = l.get('href')
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
681 if href:
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
682 # assume all links go to pages
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
683 linkUrl = urlparse.urlparse(href)
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
684 linkParams = urlparse.parse_qs(linkUrl.query)
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
685 # take some parameters (make sure it works even if the link was already parsed)
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
686 params = {'pn': linkParams.get('page',linkParams.get('pn', None)),
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
687 'highlightQuery': linkParams.get('highlightQuery',None),
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
688 'highlightElement': linkParams.get('highlightElem',linkParams.get('highlightElement',None)),
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
689 'highlightElementPos': linkParams.get('highlightElemPos',linkParams.get('highlightElementPos',None))
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
690 }
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
691 if not params['pn']:
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
692 logging.warn("getResultsPage: link has no page: %s"%href)
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
693
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
694 url = self.getLink(params=params)
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
695 l.set('href', url)
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
696
576
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
697 toc.append(div)
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
698
b2c7e272e075 new w-tag solution with etree. search works now.
casties
parents: 575
diff changeset
699 return serialize(toc)
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
700
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
701 return "ERROR: no results!"
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
702
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
703
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
704 def getToc(self, mode='text', docinfo=None):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
705 """returns list of table of contents from docinfo"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
706 logging.debug("getToc mode=%s"%mode)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
707 if mode == 'text':
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
708 queryType = 'toc'
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
709 else:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
710 queryType = mode
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
711
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
712 if not 'full_%s'%queryType in docinfo:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
713 # get new toc
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
714 docinfo = self.getTextInfo(queryType, docinfo)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
715
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
716 return docinfo.get('full_%s'%queryType, [])
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
717
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
718
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
719 def getTocPage(self, mode='text', pn=None, start=None, size=None, pageinfo=None, docinfo=None):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
720 """returns single page from the table of contents"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
721 logging.debug("getTocPage mode=%s, pn=%s start=%s size=%s"%(mode,repr(pn),repr(start),repr(size)))
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
722 fulltoc = self.getToc(mode=mode, docinfo=docinfo)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
723 if len(fulltoc) < 1:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
724 logging.error("getTocPage: unable to find toc!")
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
725 return "Error: no table of contents!"
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
726
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
727 if size is None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
728 size = pageinfo.get('tocPageSize', 30)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
729
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
730 if start is None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
731 start = (pn - 1) * size
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
732
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
733 # paginate
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
734 first = (start - 1)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
735 last = first + size
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
736 tocs = fulltoc[first:last]
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
737 tp = '<div>'
609
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
738 label = {'figures': 'Figure', 'notes': 'Note', 'handwritten': 'Handwritten note'}.get(mode, 'Item')
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
739 for toc in tocs:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
740 pageurl = self.getLink('pn', toc['pn'])
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
741 tp += '<div class="tocline">'
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
742 content = toc['content']
609
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
743 lvs = toc['level-string']
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
744 if content:
609
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
745 tp += '<div class="toc name">[%s] %s</div>'%(lvs, toc['content'])
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
746 elif lvs:
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
747 tp += '<div class="toc name">[%s %s]</div>'%(label, lvs)
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
748 else:
609
7962e6891d99 works with new notes and notesHandwritten.
casties
parents: 587
diff changeset
749 tp += '<div class="toc name">[%s]</div>'%(label)
568
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
750
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
751 if toc.get('no', None):
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
752 tp += '<div class="toc page"><a href="%s">Page: %s (%s)</a></div>'%(pageurl, toc['pn'], toc['no'])
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
753 else:
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
754 tp += '<div class="toc page"><a href="%s">Page: %s</a></div>'%(pageurl, toc['pn'])
694935574177 more new MpiwgXmlTextServer.
casties
parents: 567
diff changeset
755
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
756 tp += '</div>\n'
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
757
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
758 tp += '</div>\n'
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
759
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
760 return tp
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
761
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
762
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
763 def manage_changeMpiwgXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,repositoryType=None,RESPONSE=None):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
764 """change settings"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
765 self.title=title
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
766 self.timeout = timeout
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
767 self.serverUrl = serverUrl
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
768 if repositoryType:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
769 self.repositoryType = repositoryType
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
770 if RESPONSE is not None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
771 RESPONSE.redirect('manage_main')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
772
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
773 # management methods
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
774 def manage_addMpiwgXmlTextServerForm(self):
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
775 """Form for adding"""
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
776 pt = PageTemplateFile("zpt/manage_addMpiwgXmlTextServer", globals()).__of__(self)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
777 return pt()
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
778
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
779 def manage_addMpiwgXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
577
9251719154a3 toc with list of handwritten notes.
casties
parents: 576
diff changeset
780 """add MpiwgXmlTextServer"""
564
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
781 newObj = MpiwgXmlTextServer(id=id,title=title,serverUrl=serverUrl,timeout=timeout)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
782 self.Destination()._setObject(id, newObj)
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
783 if RESPONSE is not None:
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
784 RESPONSE.redirect('manage_main')
31f562fa7214 first version of MpiwgXmlTextServer.
casties
parents:
diff changeset
785
610
0488cd12355b gis mode works again.
casties
parents: 609
diff changeset
786