Fixed json api to handle words not found.

This commit is contained in:
amontano 2009-08-27 22:20:12 +00:00
parent ea46ddebb0
commit aed2e307ba

View file

@ -73,7 +73,7 @@ public class RemoteScannerFilter extends GenericServlet
{
// do nothing
}
String linea, dicts = req.getParameter("dicts"), dicDescrip[], jwf = req.getParameter("jwf"), tag;
String linea = null, dicts = req.getParameter("dicts"), dicDescrip[], jwf = req.getParameter("jwf"), tag;
Definitions defs;
ByteDictionarySource dict_source;
if (jwf!=null) format = JSON;
@ -132,9 +132,9 @@ public class RemoteScannerFilter extends GenericServlet
{
out.println(jwf + "({\"words\":{");
}
scanner.clearTokens();
try
{
scanner.clearTokens();
switch (format)
{
case INTERNAL:
@ -154,25 +154,37 @@ public class RemoteScannerFilter extends GenericServlet
scanner.scanLine(linea);
}
}
}
catch (Exception e)
{
if (linea!=null) sl.writeLog("1\t2\t" + linea);
sl.writeException(e);
}
scanner.finishUp();
try
{
words = scanner.getWordArray();
if (words!=null)
{
for (i=0; i<words.length; i++)
{
linea = words[i].getDef();
word = words[i];
linea = word.getDef();
if (linea == null) continue;
switch (format)
{
case INTERNAL:
out.println(words[i].getWylie());
out.println(word.getWylie());
out.println(linea);
out.println();
break;
case JSON:
out.println("\"" + BasicTibetanTranscriptionConverter.wylieToHTMLUnicode(words[i].token) + "\": [");
defs = words[i].getDefs();
defs = word.getDefs();
dict_source = (ByteDictionarySource)defs.getDictionarySource();
if(dict_source==null) out.println("\"" + word.token + "\": [");
else
{
out.println("\"" + BasicTibetanTranscriptionConverter.wylieToHTMLUnicode(word.token) + "\": [");
k=0;
for (j=0; j<defs.def.length; j++)
{
@ -184,6 +196,7 @@ public class RemoteScannerFilter extends GenericServlet
if (j==defs.def.length-1) out.println();
else out.println(",");
}
}
out.print("]");
if (i<words.length-1) out.println(",");
}
@ -196,7 +209,6 @@ public class RemoteScannerFilter extends GenericServlet
if (word!=null) sl.writeLog("1\t2\t" + word.getWylie());
sl.writeException(e);
}
scanner.clearTokens();
out.close();
}