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 // 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; Definitions defs;
ByteDictionarySource dict_source; ByteDictionarySource dict_source;
if (jwf!=null) format = JSON; if (jwf!=null) format = JSON;
@ -132,9 +132,9 @@ public class RemoteScannerFilter extends GenericServlet
{ {
out.println(jwf + "({\"words\":{"); out.println(jwf + "({\"words\":{");
} }
scanner.clearTokens();
try try
{ {
scanner.clearTokens();
switch (format) switch (format)
{ {
case INTERNAL: case INTERNAL:
@ -154,35 +154,48 @@ public class RemoteScannerFilter extends GenericServlet
scanner.scanLine(linea); scanner.scanLine(linea);
} }
} }
scanner.finishUp(); }
catch (Exception e)
{
if (linea!=null) sl.writeLog("1\t2\t" + linea);
sl.writeException(e);
}
scanner.finishUp();
try
{
words = scanner.getWordArray(); words = scanner.getWordArray();
if (words!=null) if (words!=null)
{ {
for (i=0; i<words.length; i++) for (i=0; i<words.length; i++)
{ {
linea = words[i].getDef(); word = words[i];
linea = word.getDef();
if (linea == null) continue; if (linea == null) continue;
switch (format) switch (format)
{ {
case INTERNAL: case INTERNAL:
out.println(words[i].getWylie()); out.println(word.getWylie());
out.println(linea); out.println(linea);
out.println(); out.println();
break; break;
case JSON: case JSON:
out.println("\"" + BasicTibetanTranscriptionConverter.wylieToHTMLUnicode(words[i].token) + "\": ["); defs = word.getDefs();
defs = words[i].getDefs();
dict_source = (ByteDictionarySource)defs.getDictionarySource(); dict_source = (ByteDictionarySource)defs.getDictionarySource();
k=0; if(dict_source==null) out.println("\"" + word.token + "\": [");
for (j=0; j<defs.def.length; j++) else
{ {
while (dict_source.isEmpty(k)) k++; out.println("\"" + BasicTibetanTranscriptionConverter.wylieToHTMLUnicode(word.token) + "\": [");
tag = dict_source.getTag(k); k=0;
k++; for (j=0; j<defs.def.length; j++)
out.println("\"" + tag + "\","); {
out.print("\"" + Manipulate.toJSON(defs.def[j]) + "\""); while (dict_source.isEmpty(k)) k++;
if (j==defs.def.length-1) out.println(); tag = dict_source.getTag(k);
else out.println(","); k++;
out.println("\"" + tag + "\",");
out.print("\"" + Manipulate.toJSON(defs.def[j]) + "\"");
if (j==defs.def.length-1) out.println();
else out.println(",");
}
} }
out.print("]"); out.print("]");
if (i<words.length-1) out.println(","); 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()); if (word!=null) sl.writeLog("1\t2\t" + word.getWylie());
sl.writeException(e); sl.writeException(e);
} }
scanner.clearTokens(); scanner.clearTokens();
out.close(); out.close();
} }