Mercurial > hg > mpdl-group
comparison software/mpdl-services/mpiwg-mpdl-cms-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/lt/GetDictionaryEntries.java @ 23:e845310098ba
diverse Korrekturen
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 27 Nov 2012 12:35:19 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
22:6a45a982c333 | 23:e845310098ba |
---|---|
1 package de.mpg.mpiwg.berlin.mpdl.servlets.lt; | |
2 | |
3 import java.io.IOException; | |
4 import java.io.PrintWriter; | |
5 import java.util.ArrayList; | |
6 import java.util.Arrays; | |
7 import java.util.Collections; | |
8 import java.util.Date; | |
9 | |
10 import javax.servlet.ServletConfig; | |
11 import javax.servlet.ServletException; | |
12 import javax.servlet.http.HttpServlet; | |
13 import javax.servlet.http.HttpServletRequest; | |
14 import javax.servlet.http.HttpServletResponse; | |
15 | |
16 import org.apache.commons.lang3.StringEscapeUtils; | |
17 | |
18 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; | |
19 import de.mpg.mpiwg.berlin.mpdl.lt.dict.app.Lexica; | |
20 import de.mpg.mpiwg.berlin.mpdl.lt.dict.app.Lexicon; | |
21 import de.mpg.mpiwg.berlin.mpdl.lt.dict.app.LexiconEntry; | |
22 import de.mpg.mpiwg.berlin.mpdl.lt.dict.db.LexHandler; | |
23 import de.mpg.mpiwg.berlin.mpdl.lt.general.Language; | |
24 import de.mpg.mpiwg.berlin.mpdl.lt.morph.app.Form; | |
25 import de.mpg.mpiwg.berlin.mpdl.lt.morph.app.Lemma; | |
26 import de.mpg.mpiwg.berlin.mpdl.lt.text.norm.Normalizer; | |
27 import de.mpg.mpiwg.berlin.mpdl.servlets.util.ServletUtil; | |
28 | |
29 public class GetDictionaryEntries extends HttpServlet { | |
30 private static final long serialVersionUID = 1L; | |
31 private LexHandler lexHandler; | |
32 | |
33 public GetDictionaryEntries() { | |
34 super(); | |
35 } | |
36 | |
37 public void init(ServletConfig config) throws ServletException { | |
38 super.init(config); | |
39 try { | |
40 lexHandler = LexHandler.getInstance(); | |
41 } catch (ApplicationException e) { | |
42 throw new ServletException(e); | |
43 } | |
44 } | |
45 | |
46 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
47 Date begin = new Date(); | |
48 request.setCharacterEncoding("utf-8"); | |
49 response.setCharacterEncoding("utf-8"); | |
50 String query = request.getParameter("query"); | |
51 String queryDisplay = request.getParameter("queryDisplay"); | |
52 String language = request.getParameter("language"); | |
53 String inputType = request.getParameter("inputType"); | |
54 String outputFormat = request.getParameter("outputFormat"); | |
55 String[] outputTypesArray = request.getParameterValues("outputType"); | |
56 String dictionary = request.getParameter("dictionary"); | |
57 String normalization = request.getParameter("normalization"); | |
58 String normalizationType = request.getParameter("normalizationType"); | |
59 String resultPageNumber = request.getParameter("resultPageNumber"); | |
60 String resultPageSize = request.getParameter("resultPageSize"); | |
61 if (query == null) | |
62 query = "a*"; | |
63 boolean isRangeQuery = false; | |
64 if (query.endsWith("*")) | |
65 isRangeQuery = true; | |
66 if (queryDisplay == null) | |
67 queryDisplay = query; | |
68 if (language == null) | |
69 language = "eng"; | |
70 if (inputType == null || ! (inputType.equals("form") || inputType.equals("lemma"))) | |
71 inputType = "form"; | |
72 if (outputFormat == null || ! (outputFormat.equals("xml") || outputFormat.equals("html") || outputFormat.equals("htmlFragment"))) | |
73 outputFormat = "xml"; | |
74 ArrayList<String> outputTypes = new ArrayList<String>(); | |
75 if (outputTypesArray == null) { | |
76 outputTypes.add("allCompact"); | |
77 } else if (isRangeQuery) { | |
78 outputTypes.add("dictCompact"); | |
79 } else { | |
80 outputTypes = new ArrayList<String>(Arrays.asList(outputTypesArray)); | |
81 } | |
82 if (normalization == null || ! (normalization.equals("none") || normalization.equals("reg") || normalization.equals("reg norm"))) | |
83 normalization = "norm"; | |
84 if (normalizationType == null || ! (normalizationType.equals("display") || normalizationType.equals("dictionary"))) | |
85 normalizationType = "dictionary"; | |
86 String xmlDict = "all"; | |
87 if (dictionary != null) | |
88 xmlDict = dictionary; | |
89 int pageNumber = 1; | |
90 int pageSize = 50; | |
91 if (resultPageNumber != null) | |
92 pageNumber = new Integer(resultPageNumber); | |
93 if (resultPageSize != null) | |
94 pageSize = new Integer(resultPageSize); | |
95 String xmlQueryString = "<query>"; | |
96 xmlQueryString = xmlQueryString + "<name>" + query + "</name>"; | |
97 xmlQueryString = xmlQueryString + "<display>" + queryDisplay + "</display>"; | |
98 xmlQueryString = xmlQueryString + "<language>" + language + "</language>"; | |
99 xmlQueryString = xmlQueryString + "<inputType>" + inputType + "</inputType>"; | |
100 xmlQueryString = xmlQueryString + "<outputFormat>" + outputFormat + "</outputFormat>"; | |
101 xmlQueryString = xmlQueryString + "<outputTypes>" + outputTypes + "</outputTypes>"; | |
102 xmlQueryString = xmlQueryString + "<dictionary>" + xmlDict + "</dictionary>"; | |
103 xmlQueryString = xmlQueryString + "<normalization>" + normalization + "</normalization>"; | |
104 xmlQueryString = xmlQueryString + "<normalizationType>" + normalizationType + "</normalizationType>"; | |
105 if (isRangeQuery) { | |
106 xmlQueryString = xmlQueryString + "<resultPageNumber>" + pageNumber + "</resultPageNumber>"; | |
107 xmlQueryString = xmlQueryString + "<resultPageSize>" + pageSize + "</resultPageSize>"; | |
108 } | |
109 xmlQueryString = xmlQueryString + "</query>"; | |
110 try { | |
111 if (outputFormat.equals("xml")) | |
112 response.setContentType("text/xml"); | |
113 else if (outputFormat.equals("html") || outputFormat.equals("htmlFragment")) | |
114 response.setContentType("text/html"); | |
115 else | |
116 response.setContentType("text/xml"); | |
117 PrintWriter out = response.getWriter(); | |
118 if (query == null || query.isEmpty()) { | |
119 out.print("request parameter \"query\" is empty. Please specify a query."); | |
120 out.close(); | |
121 return; | |
122 } | |
123 ArrayList<Lemma> lemmas = null; | |
124 ArrayList<Lexicon> dictionaries = null; | |
125 if (isRangeQuery) { | |
126 String queryTmp = query.substring(0, query.length() - 1); // without last star | |
127 if (dictionary != null) | |
128 dictionaries = lexHandler.getLexEntriesByLexiconBeginningWith(dictionary, queryTmp, pageNumber, pageSize); | |
129 else | |
130 dictionaries = lexHandler.getLexEntriesBeginningWith(language, queryTmp, pageNumber, pageSize); | |
131 } else { | |
132 String lang = language; | |
133 if (dictionary != null) { | |
134 Lexicon lexicon = Lexica.getInstance().getLexicon(dictionary); | |
135 if (lexicon != null) | |
136 lang = lexicon.getSourceLanguage(); | |
137 } | |
138 int normMode = Normalizer.DICTIONARY; | |
139 if (normalization.equals("none")) | |
140 normMode = Normalizer.NONE; | |
141 else if (normalizationType.equals("display")) | |
142 normMode = Normalizer.DISPLAY; | |
143 lemmas = lexHandler.getLemmas(query, inputType, lang, normMode, true); | |
144 dictionaries = lexHandler.getLexEntries(lemmas, lang, dictionary, query); | |
145 } | |
146 String baseUrl = ServletUtil.getInstance().getBaseUrl(request); | |
147 Date end = new Date(); | |
148 String elapsedTime = String.valueOf(end.getTime() - begin.getTime()); | |
149 String result = ""; | |
150 if (outputFormat == null || outputFormat.equals("xml")) | |
151 result = createXmlOutputString(query, lemmas, dictionaries, outputTypes, baseUrl, xmlQueryString, elapsedTime); | |
152 else if (outputFormat.equals("html") || outputFormat.equals("htmlFragment")) | |
153 result = createHtmlOutputString(query, queryDisplay, language, lemmas, dictionaries, pageNumber, pageSize, isRangeQuery, outputFormat, outputTypes, elapsedTime); | |
154 else | |
155 result = createXmlOutputString(query, lemmas, dictionaries, outputTypes, baseUrl, xmlQueryString, elapsedTime); | |
156 out.print(result); | |
157 out.close(); | |
158 } catch (ApplicationException e) { | |
159 throw new ServletException(e); | |
160 } | |
161 } | |
162 | |
163 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
164 doGet(request, response); | |
165 } | |
166 | |
167 private String createXmlOutputString(String query, ArrayList<Lemma> lemmas, ArrayList<Lexicon> lexicons, ArrayList<String> outputTypes, String baseUrl, String xmlQueryString, String elapsedTime) { | |
168 boolean outputTypeMorphCompact = false; | |
169 if (outputTypes.contains("allCompact") || outputTypes.contains("morphCompact")) | |
170 outputTypeMorphCompact = true; | |
171 boolean outputTypeMorphFull = false; | |
172 if (outputTypes.contains("allFull") || outputTypes.contains("morphFull")) | |
173 outputTypeMorphFull = true; | |
174 boolean outputTypeDictCompact = false; | |
175 if (outputTypes.contains("allCompact") || outputTypes.contains("dictCompact")) | |
176 outputTypeDictCompact = true; | |
177 boolean outputTypeDictFull = false; | |
178 if (outputTypes.contains("allFull") || outputTypes.contains("dictFull")) | |
179 outputTypeDictFull = true; | |
180 boolean outputTypeWikiCompact = false; | |
181 if (outputTypes.contains("allCompact") || outputTypes.contains("wikiCompact")) | |
182 outputTypeWikiCompact = true; | |
183 boolean outputTypeWikiFull = false; | |
184 if (outputTypes.contains("allFull") || outputTypes.contains("wikiFull")) | |
185 outputTypeWikiFull = true; | |
186 String result = "<result>"; | |
187 result = result + "<provider>" + "MPIWG MPDL language technology service (see: " + "" + baseUrl + "), Max Planck Institute for the History of Science, Berlin." + "</provider>"; | |
188 result = result + xmlQueryString; | |
189 result = result + "<elapsed-time-ms>" + elapsedTime + "</elapsed-time-ms>"; | |
190 if ((outputTypeMorphCompact || outputTypeMorphFull) && lemmas != null && ! lemmas.isEmpty()) { | |
191 result = result + "<morphology>"; | |
192 for (int i=0; i<lemmas.size(); i++) { | |
193 Lemma lemma = lemmas.get(i); | |
194 String lemmaName = lemma.getLemmaName(); | |
195 String language = lemma.getLanguage(); | |
196 result = result + "<lemma>"; | |
197 result = result + "<name>" + lemmaName + "</name>"; | |
198 if (outputTypeMorphFull) { | |
199 String lemmaProvider = lemma.getProvider(); | |
200 result = result + "<provider>" + lemmaProvider + "</provider>"; | |
201 result = result + "<language>" + language + "</language>"; | |
202 } | |
203 if (Language.getInstance().isArabic(language) || Language.getInstance().isLatin(language)) { | |
204 String remoteUrl = "http://www.perseus.tufts.edu/hopper/morph?l=" + lemmaName + "&la=" + language; | |
205 result = result + "<remoteUrl>" + remoteUrl + "</remoteUrl>"; | |
206 } else if (Language.getInstance().isGreek(language)) { | |
207 String remoteUrl = "http://www.perseus.tufts.edu/hopper/morph?l=" + lemmaName + "&la=" + "greek"; | |
208 result = result + "<remoteUrl>" + remoteUrl + "</remoteUrl>"; | |
209 } | |
210 if (outputTypeMorphFull) { | |
211 ArrayList<Form> forms = lemma.getFormsList(); | |
212 Collections.sort(forms); | |
213 if (forms != null && ! forms.isEmpty()) { | |
214 result = result + "<forms>"; | |
215 for (int j=0; j<forms.size(); j++) { | |
216 result = result + "<form>"; | |
217 Form f = forms.get(j); | |
218 String formName = f.getFormName(); | |
219 String formProvider = f.getProvider(); | |
220 result = result + "<provider>" + formProvider + "</provider>"; | |
221 result = result + "<language>" + language + "</language>"; | |
222 result = result + "<name>" + formName + "</name>"; | |
223 result = result + "</form>"; | |
224 } | |
225 result = result + "</forms>"; | |
226 } | |
227 } | |
228 result = result + "</lemma>"; | |
229 } | |
230 result = result + "</morphology>"; | |
231 } | |
232 if ((outputTypeDictCompact || outputTypeDictFull) && lexicons != null) { | |
233 result = result + "<dictionaries>"; | |
234 for (int i=0; i<lexicons.size(); i++) { | |
235 Lexicon lexicon = lexicons.get(i); | |
236 if (outputTypeDictFull) | |
237 result = result + lexicon.toXmlString(); | |
238 else if (outputTypeDictCompact) | |
239 result = result + lexicon.toXmlStringCompact(); | |
240 } | |
241 result = result + "</dictionaries>"; | |
242 } | |
243 if ((outputTypeWikiCompact || outputTypeWikiFull) && lemmas != null && ! lemmas.isEmpty()) { | |
244 result = result + "<wikipedia>"; | |
245 String language = null; | |
246 for (int i=0; i<lemmas.size(); i++) { | |
247 Lemma lemma = lemmas.get(i); | |
248 String lemmaName = lemma.getLemmaName(); | |
249 language = Language.getInstance().getLanguageId(lemma.getLanguage()); | |
250 result = result + "<article>"; | |
251 result = result + "<name>" + lemmaName + "</name>"; | |
252 String wikiHrefExact = "http://" + language + ".wikipedia.org/wiki/" + lemmaName; | |
253 String wikiHrefSearch = "http://" + language + ".wikipedia.org/wiki/index.php?search=" + lemmaName; | |
254 result = result + "<remoteUrl>" + wikiHrefExact + "</remoteUrl>"; | |
255 result = result + "<remoteUrlSearch>" + wikiHrefSearch + "</remoteUrlSearch>"; | |
256 result = result + "</article>"; | |
257 } | |
258 if (language != null && Language.getInstance().isGerman(language) && query != null) { | |
259 String[] queryFormNames = query.split(" "); | |
260 for (int j=0; j<queryFormNames.length; j++) { | |
261 String queryFormName = queryFormNames[j]; | |
262 result = result + "<article>"; | |
263 result = result + "<name>" + queryFormName + "</name>"; | |
264 String wikiHrefExact = "http://" + language + ".wikipedia.org/wiki/" + queryFormName; | |
265 String wikiHrefSearch = "http://" + language + ".wikipedia.org/wiki/index.php?search=" + queryFormName; | |
266 result = result + "<remoteUrl>" + wikiHrefExact + "</remoteUrl>"; | |
267 result = result + "<remoteUrlSearch>" + wikiHrefSearch + "</remoteUrlSearch>"; | |
268 result = result + "</article>"; | |
269 } | |
270 } | |
271 result = result + "</wikipedia>"; | |
272 } | |
273 result = result + "</result>"; | |
274 return result; | |
275 } | |
276 | |
277 private String createHtmlOutputString(String query, String queryDisplay, String language, ArrayList<Lemma> lemmas, ArrayList<Lexicon> lexicons, int pageNumber, int pageSize, boolean isRangeQuery, String outputFormat, ArrayList<String> outputTypes, String elapsedTime) { | |
278 boolean outputTypeMorphCompact = false; | |
279 if (outputTypes.contains("allCompact") || outputTypes.contains("morphCompact")) | |
280 outputTypeMorphCompact = true; | |
281 boolean outputTypeMorphFull = false; | |
282 if (outputTypes.contains("allFull") || outputTypes.contains("morphFull")) | |
283 outputTypeMorphFull = true; | |
284 boolean outputTypeDictCompact = false; | |
285 if (outputTypes.contains("allCompact") || outputTypes.contains("dictCompact")) | |
286 outputTypeDictCompact = true; | |
287 boolean outputTypeDictFull = false; | |
288 if (outputTypes.contains("allFull") || outputTypes.contains("dictFull")) | |
289 outputTypeDictFull = true; | |
290 boolean outputTypeWikiCompact = false; | |
291 if (outputTypes.contains("allCompact") || outputTypes.contains("wikiCompact")) | |
292 outputTypeWikiCompact = true; | |
293 boolean outputTypeWikiFull = false; | |
294 if (outputTypes.contains("allFull") || outputTypes.contains("wikiFull")) | |
295 outputTypeWikiFull = true; | |
296 String result = ""; | |
297 result = result + "<html>"; | |
298 result = result + "<head>"; | |
299 result = result + "<title>WordInfo for: \"" + queryDisplay + "\"</title>"; | |
300 result = result + "<link rel=\"stylesheet\" type=\"text/css\" href=\"/mpiwg-mpdl-cms-web/css/getDictionaryEntries.css\"/>"; | |
301 result = result + getJavascriptFunctions(); | |
302 result = result + "</head>"; | |
303 result = result + "<body class=\"body\">"; | |
304 result = result + "<table align=\"right\" valign=\"top\">"; | |
305 result = result + "<td>[<i>This is a MPIWG MPDL language technology service</i>] <a href=\"/mpiwg-mpdl-cms-web/index.html\"><img src=\"/mpiwg-mpdl-cms-web/images/info.png\" valign=\"bottom\" width=\"15\" height=\"15\" border=\"0\" alt=\"MPIWG MPDL language technology service\"/></a></td>"; | |
306 result = result + "</table>"; | |
307 result = result + "<p/>"; | |
308 result = result + "<div class=\"title\">WordInfo</div>"; | |
309 | |
310 result = result + "<form name=\"getDictionaryEntries\" action=\"GetDictionaryEntries\" method=\"get\">"; | |
311 result = result + "Query: <input name=\"query\" class=\"query\" type=\"text\" size=\"20\" value=\"" + query + "\"/>"; | |
312 String htmlSelectBox = Language.getInstance().getHtmlSelectBox(language); | |
313 result = result + " Language: " + htmlSelectBox; | |
314 result = result + "<input type=\"hidden\" name=\"outputFormat\" value=\"" + outputFormat + "\"/>"; | |
315 for (int i=0; i<outputTypes.size(); i++) { | |
316 String type = outputTypes.get(i); | |
317 result = result + "<input type=\"hidden\" name=\"outputType\" value=\"" + type + "\"/>"; | |
318 } | |
319 result = result + " <button type=\"submit\" onclick=\"var query = document.getDictionaryEntries.query.value; if(query.substring(query.length-1, query.length) == '*') {document.getDictionaryEntries.outputType.value = 'dictCompact';}\">Query</button>"; | |
320 result = result + "</form>"; | |
321 result = result + "<hr/>"; | |
322 | |
323 if ((outputTypeMorphCompact || outputTypeMorphFull) && lemmas != null && ! lemmas.isEmpty()) { | |
324 result = result + "<span class=\"inputType\">Morphology</span>"; | |
325 result = result + "<span class=\"tree\">"; | |
326 result = result + "<ul>"; | |
327 result = result + "<li>" + "<b>" + "Lemmata" + "</b>"; | |
328 result = result + "<ul>"; | |
329 for (int i=0; i<lemmas.size(); i++) { | |
330 Lemma lemma = lemmas.get(i); | |
331 String lemmaName = lemma.getLemmaName(); | |
332 String providerText = ""; | |
333 String externalLinkText = ""; | |
334 String formsText = ""; | |
335 if (outputTypeMorphFull) { | |
336 String lemmaProvider = lemma.getProvider(); | |
337 providerText = " (data provider: " + lemmaProvider + ")"; | |
338 } | |
339 if (Language.getInstance().isArabic(language) || Language.getInstance().isLatin(language)) | |
340 externalLinkText = " (external link: <a href=\"http://www.perseus.tufts.edu/hopper/morph?l=" + lemmaName + "&la=" + language + "\">" + lemmaName + "</a>)"; | |
341 else if (Language.getInstance().isGreek(language)) | |
342 externalLinkText = " (external link: <a href=\"http://www.perseus.tufts.edu/hopper/morph?l=" + lemmaName + "&la=" + "greek" + "\">" + lemmaName + "</a>)"; | |
343 ArrayList<Form> forms = lemma.getFormsList(); | |
344 Collections.sort(forms); | |
345 if (forms != null && ! forms.isEmpty()) { | |
346 formsText = formsText + "<ul>"; | |
347 formsText = formsText + "<b>" + "Forms: " + "</b>"; | |
348 for (int j=0; j<forms.size(); j++) { | |
349 Form f = forms.get(j); | |
350 String formName = f.getFormName(); | |
351 String formProvider = f.getProvider(); | |
352 formsText = formsText + formName + " (data provider: " + formProvider + "), "; | |
353 } | |
354 formsText = formsText.substring(0, formsText.length() - 2); // without last comma and blank | |
355 formsText = formsText + "</ul>"; | |
356 } | |
357 if (outputTypeMorphFull) { | |
358 result = result + "<li><input type=\"checkbox\" checked=\"checked\"/><label>" + lemmaName + providerText + externalLinkText + "</label>" + formsText + "</li>"; | |
359 } else if (outputTypeMorphCompact) { | |
360 result = result + "<li><input type=\"checkbox\"/><label>" + "<a href=\"GetDictionaryEntries?query=" + lemmaName + "&language=" + language + "&inputType=lemma" + "&outputFormat=html" + "&outputType=morphFull" + "\">" + lemmaName + "</a>" + providerText + externalLinkText + "</label>" + formsText + "</li>"; | |
361 } | |
362 } | |
363 result = result + "</ul>"; | |
364 result = result + "</li>"; | |
365 result = result + "</ul>"; | |
366 result = result + "</span>"; | |
367 } | |
368 if ((outputTypeDictCompact || outputTypeDictFull) && lexicons != null && ! lexicons.isEmpty()) { | |
369 if (isRangeQuery) { | |
370 int pageNumberUp = 1; | |
371 if (pageNumber > 1) | |
372 pageNumberUp = pageNumber - 1; | |
373 int pageNumberDown = pageNumber + 1; | |
374 int from = (pageNumber * pageSize) - pageSize + 1; | |
375 int to = pageNumber * pageSize; | |
376 result = result + "<table align=\"right\">"; | |
377 result = result + "<tr>"; | |
378 result = result + "<td valign=\"middle\">Page: </td>"; | |
379 result = result + "<td valign=\"middle\"><a href=\"/mpiwg-mpdl-cms-web/lt/GetDictionaryEntries?query=" + query + "&language=" + language + "&resultPageNumber=" + pageNumberUp + "&outputFormat=html\"><img alt=\"page up\" src=\"/mpiwg-mpdl-cms-web/images/left.gif\" height=\"20\" width=\"20\"></a></td>"; | |
380 result = result + "<td valign=\"middle\">" + pageNumber + "</td>"; | |
381 result = result + "<td valign=\"middle\"><a href=\"/mpiwg-mpdl-cms-web/lt/GetDictionaryEntries?query=" + query + "&language=" + language + "&resultPageNumber=" + pageNumberDown + "&outputFormat=html\"><img alt=\"page down\" src=\"/mpiwg-mpdl-cms-web/images/right.gif\" height=\"20\" width=\"20\"></a></td>"; | |
382 result = result + "<td valign=\"middle\">(" + from + " - " + to + ")</td>"; | |
383 result = result + "</tr>"; | |
384 result = result + "</table>"; | |
385 } | |
386 result = result + "<span class=\"inputType\">Dictionary</span>"; | |
387 result = result + "<span class=\"tree\">"; | |
388 result = result + "<ul>"; | |
389 for (int i=0; i<lexicons.size(); i++) { | |
390 Lexicon lexicon = lexicons.get(i); | |
391 result = result + "<li>"; | |
392 result = result + "<b>" + lexicon.getDescription() + "</b>"; | |
393 result = result + "<ul>"; | |
394 ArrayList<LexiconEntry> entries = lexicon.getEntries(); | |
395 for (int j=0; j<entries.size(); j++) { | |
396 String entryContent = ""; | |
397 LexiconEntry entry = entries.get(j); | |
398 if (lexicon.isLocalLexicon()) { | |
399 if (entry.isXmlValid()) { | |
400 String repairedEntry = entry.getRepairedEntry(); | |
401 repairedEntry = repairedEntry.replaceAll("<repaired-entry>", ""); | |
402 repairedEntry = repairedEntry.replaceAll("</repaired-entry>", ""); | |
403 entryContent = entryContent + repairedEntry; // valid unicode content of the original entry | |
404 } else { | |
405 entryContent = entryContent + "[Remark: <i> this dictionary entry has no valid XML/HTML content in database so a text version of this entry is shown.</i>]: <br/>"; | |
406 String originalEntry = entry.getOriginalEntry(); | |
407 originalEntry = originalEntry.replaceAll("<original-entry>", ""); | |
408 originalEntry = originalEntry.replaceAll("</original-entry>", ""); | |
409 originalEntry = StringEscapeUtils.escapeXml(originalEntry); // create text version of the invalid xml content | |
410 entryContent = entryContent + originalEntry; | |
411 } | |
412 if (entry.getRemoteUrl() != null) { | |
413 entryContent = entryContent + "<div>(external link: <a href=\"" + entry.getRemoteUrl() + "\">" + entry.getFormName() + "</a>)</div>"; | |
414 } | |
415 } else { | |
416 if (entry.getRemoteUrl() != null) { | |
417 entryContent = entryContent + "external link: <a href=\"" + entry.getRemoteUrl() + "\">" + entry.getFormName() + "</a>"; | |
418 } | |
419 } | |
420 String formName = entry.getFormName(); | |
421 String dictName = lexicon.getName(); | |
422 if (outputTypeDictFull) { | |
423 result = result + "<li><input type=\"checkbox\" checked=\"checked\"/><label><b>" + formName + "</b></label><ul><li>" + entryContent + "</li></ul></li>"; | |
424 } else if (outputTypeDictCompact) { | |
425 result = result + "<li><input type=\"checkbox\"/><label>" + "<a href=\"GetDictionaryEntries?query=" + formName + "&language=" + language + "&dictionary=" + dictName + "&inputType=lemma" + "&outputFormat=html" + "&outputType=dictFull" + "\">" + formName + "</a>" + "</label><ul><li>" + entryContent + "</li></ul></li>"; | |
426 } | |
427 } | |
428 result = result + "</ul>"; | |
429 result = result + "</li>"; // lexicon entry | |
430 } | |
431 result = result + "</ul>"; | |
432 result = result + "</span>"; | |
433 } | |
434 if ((outputTypeWikiCompact || outputTypeWikiFull) && lemmas != null && ! lemmas.isEmpty()) { | |
435 String langId = Language.getInstance().getLanguageId(language); | |
436 String wikiUrl = langId + ".wikipedia.org"; | |
437 result = result + "<span class=\"inputType\">Wikipedia</span>"; | |
438 result = result + "<span class=\"tree\">"; | |
439 result = result + "<ul>"; | |
440 result = result + "<li>" + "<b>" + wikiUrl + "</b>"; | |
441 result = result + "<ul>"; | |
442 for (int i=0; i<lemmas.size(); i++) { | |
443 Lemma lemma = lemmas.get(i); | |
444 String lemmaName = lemma.getLemmaName(); | |
445 String wikiHrefExact = "http://" + wikiUrl + "/wiki/" + lemmaName; | |
446 String wikiHrefSearch = "http://" + wikiUrl + "/wiki/index.php?search=" + lemmaName; | |
447 result = result + "<li><input type=\"checkbox\" checked=\"checked\"/><label>" + "External link: <a href=\"" + wikiHrefExact + "\">" + lemmaName + "</a> (or search for <a href=\"" + wikiHrefSearch + "\">" + lemmaName + "</a>)" + "</label>" + "</li>"; | |
448 } | |
449 if (language != null && Language.getInstance().isGerman(language) && query != null) { | |
450 String[] queryFormNames = query.split(" "); | |
451 for (int j=0; j<queryFormNames.length; j++) { | |
452 String queryFormName = queryFormNames[j]; | |
453 result = result + "<li>"; | |
454 String wikiHrefExact = "http://" + wikiUrl + "/wiki/" + queryFormName; | |
455 String wikiHrefSearch = "http://" + wikiUrl + "/wiki/index.php?search=" + queryFormName; | |
456 result = result + "<li><input type=\"checkbox\" checked=\"checked\"/><label>" + "External link: <a href=\"" + wikiHrefExact + "\">" + queryFormName + "</a> (or search for <a href=\"" + wikiHrefSearch + "\">" + queryFormName + "</a>)" + "</label>" + "</li>"; | |
457 result = result + "</li>"; | |
458 } | |
459 } | |
460 result = result + "</ul>"; | |
461 result = result + "</li>"; | |
462 result = result + "</ul>"; | |
463 result = result + "</span>"; | |
464 } | |
465 result = result + "<p/>"; | |
466 result = result + "[* external links may not function]"; | |
467 result = result + "<hr/>"; | |
468 result = result + "<p/>"; | |
469 result = result + "Elapsed time: " + elapsedTime + " ms, see the <a href=\"/mpiwg-mpdl-cms-web/index.html\">service description</a> of this page, if you find a bug <a href=\"https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/newticket\">let us know</a>"; | |
470 result = result + "</body>"; | |
471 result = result + "</html>"; | |
472 return result; | |
473 } | |
474 | |
475 private String getJavascriptFunctions() { | |
476 String result = "<script type=\"text/javascript\">"; | |
477 result = result + "<!-- "; | |
478 result = result + "function strEndsWith(str, suffix) {"; | |
479 result = result + " return str.match(suffix + \"$\") == suffix;"; | |
480 result = result + "}"; | |
481 result = result + " -->"; | |
482 result = result + "</script>"; | |
483 return result; | |
484 } | |
485 } |