Added debug info to the servlet version.

This commit is contained in:
amontano 2005-02-27 05:48:03 +00:00
parent 9507ff3694
commit 107fcce565
8 changed files with 210 additions and 200 deletions

View file

@ -61,12 +61,12 @@ public class DictionaryTableModel extends AbstractTableModel
{
switch(column)
{
case 0:
if (tibetanActivated) return arrayTibetan[row];
else return array[row].getWylie();
case 1: return array[row].getDefPreview();
default: return array[row].toString();
}
case 0:
if (tibetanActivated) return arrayTibetan[row];
else return array[row].getWylie();
case 1: return array[row].getDefPreview();
default: return array[row].toString();
}
}

View file

@ -208,50 +208,50 @@ public class DuffScannerPanel extends ScannerPanel implements ItemListener
public void clear()
{
txtInput.setText("");
duffInput.setText("");
fullDef.setText("");
model.newSearch(null);
table.tableChanged(new TableModelEvent(model));
txtInput.setText("");
duffInput.setText("");
fullDef.setText("");
model.newSearch(null);
table.tableChanged(new TableModelEvent(model));
table.repaint();
}
public void translate()
{
String in;
setDicts(scanner.getDictionarySource());
String in;
setDicts(scanner.getDictionarySource());
in = "";
if (showingTibetan)
in = duffInput.getWylie(new boolean[] { false });
else
in = txtInput.getText();
in = "";
if (showingTibetan)
in = duffInput.getWylie(new boolean[] { false });
else
in = txtInput.getText();
if (!in.equals(""))
{
doingStatus("Translating...");
scanner.scanBody(in);
scanner.finishUp();
model.newSearch(scanner.getWordArray());
// printAllDefs();
scanner.clearTokens();
returnStatusToNorm();
fullDef.setText("");
/* ListSelectionModel lsm = (ListSelectionModel)table.getSelectionModel();
if (!lsm.isSelectionEmpty())
{
int selectedRow = lsm.getMinSelectionIndex();
//TableModel tm = table.getModel();
if (selectedRow<model.getRowCount())
fullDef.setText(model.getValueAt(selectedRow, 1).toString());
}*/
}
else
{
model.newSearch(null);
fullDef.setText("");
}
table.tableChanged(new TableModelEvent(model));
if (!in.equals(""))
{
doingStatus("Translating...");
scanner.scanBody(in);
scanner.finishUp();
model.newSearch(scanner.getWordArray());
//printAllDefs();
scanner.clearTokens();
returnStatusToNorm();
fullDef.setText("");
/*ListSelectionModel lsm = (ListSelectionModel)table.getSelectionModel();
if (!lsm.isSelectionEmpty())
{
int selectedRow = lsm.getMinSelectionIndex();
//TableModel tm = table.getModel();
if (selectedRow<model.getRowCount())
fullDef.setText(model.getValueAt(selectedRow, 1).toString());
}*/
}
else
{
model.newSearch(null);
fullDef.setText("");
}
table.tableChanged(new TableModelEvent(model));
table.repaint();
}

View file

@ -207,55 +207,57 @@ public class FileSyllableListTree implements SyllableListTree
public Definitions getDefs()
{
if (def==null) return null;
DictionarySource defSourceAvail = defSource.intersection(defSourcesWanted);
String defs[];
int i, n=0;
if (versionNumber==2)
{
int defsAvail[] = ((BitDictionarySource) defSourceAvail).untangleDefs(), defsFound[] = ((BitDictionarySource) defSource).untangleDefs(def.length);
if (def==null) return null;
DictionarySource defSourceAvail = defSource.intersection(defSourcesWanted);
String defs[];
int i, n=0;
defs = new String[defsAvail.length];
try
{
for (i=0; i<defsAvail.length; i++)
{
while(defsAvail[i]!=defsFound[n]) n++;
defRaf.seek(def[n]);
defs[i] = defRaf.readUTF();
}
}
catch (Exception e)
{
System.out.println(e);
return null;
}
}
else
{
ByteDictionarySource defSourceAvailBy = (ByteDictionarySource) defSourceAvail;
defs = new String [defSourceAvailBy.countDefs()];
try
{
for (i=0; i < def.length; i++)
{
if (!defSourceAvailBy.isEmpty(i))
{
defRaf.seek(def[i]);
defs[n] = defRaf.readUTF();
n++;
}
}
}
catch (Exception e)
{
System.out.println(e);
return null;
}
}
return new Definitions(defs, defSourceAvail);
if (versionNumber==2)
{
int defsAvail[] = ((BitDictionarySource) defSourceAvail).untangleDefs(), defsFound[] = ((BitDictionarySource) defSource).untangleDefs(def.length);
defs = new String[defsAvail.length];
try
{
for (i=0; i<defsAvail.length; i++)
{
while(defsAvail[i]!=defsFound[n]) n++;
defRaf.seek(def[n]);
defs[i] = defRaf.readUTF();
}
}
catch (Exception e)
{
System.out.println(e);
e.printStackTrace();
return null;
}
}
else
{
ByteDictionarySource defSourceAvailBy = (ByteDictionarySource) defSourceAvail;
defs = new String [defSourceAvailBy.countDefs()];
try
{
for (i=0; i < def.length; i++)
{
if (!defSourceAvailBy.isEmpty(i))
{
defRaf.seek(def[i]);
defs[n] = defRaf.readUTF();
n++;
}
}
}
catch (Exception e)
{
System.out.println(e);
e.printStackTrace();
return null;
}
}
return new Definitions(defs, defSourceAvail);
}
public boolean hasDef()

View file

@ -274,19 +274,19 @@ public class LocalTibetanScanner extends TibetanScanner
fin = in.indexOf("\n",init);
if (fin<0)
{
linea = in.substring(init).trim();
hayMasLineas=false;
linea = in.substring(init).trim();
hayMasLineas=false;
}
else
linea = in.substring(init, fin).trim();
linea = in.substring(init, fin).trim();
if (linea.equals(""))
{
finishUp();
wordList.addLast(new PunctuationMark('\n'));
wordList.addLast(new PunctuationMark('\n'));
}
else
scanLine(linea);
scanLine(linea);
init = fin+1;
}
@ -304,7 +304,7 @@ public class LocalTibetanScanner extends TibetanScanner
{
finishUp();
wordList.addLast(new PunctuationMark('\n'));
return;
return;
}
outAHere:

View file

@ -53,7 +53,7 @@ public class OnLineScannerFilter extends HttpServlet
public OnLineScannerFilter() //throws Exception
{
rb = ResourceBundle.getBundle(propertyFile);
sl = new ScannerLogger();
sl = new ScannerLogger();
try
{
@ -377,9 +377,8 @@ public class OnLineScannerFilter extends HttpServlet
break;
default:
pw.print(pm + " ");
}
}
}
}
}
}
pw.println("</p>");
@ -389,7 +388,7 @@ public class OnLineScannerFilter extends HttpServlet
{
int i, j;
Word words[];
SwingWord word;
SwingWord word=null;
Definitions defs;
String tag;
DictionarySource ds;
@ -402,38 +401,48 @@ public class OnLineScannerFilter extends HttpServlet
for (j=0; j<words.length; j++)
{
word = new SwingWord(words[j]);
defs = word.getDefs();
ds = defs.getDictionarySource();
if (ds==null) continue;
pw.println(" <tr>");
tag = ds.getTag(0);
// else tag = null;
/*if (tag!=null)
{*/
pw.println(" <td width=\"20%\" rowspan=\""+ defs.def.length +"\" valign=\"top\">"+ word.getBookmark(tibetan) +"</td>");
pw.println(" <td width=\"12%\">"+ tag +"</td>");
pw.println(" <td width=\"68%\">" + defs.def[0] + "</td>");
/*}
else
{
pw.println(" <td width=\"20%\" rowspan=\""+ defs.def.length +"\" valign=\"top\">"+ words[j].getBookmark(tibetan) +"</td>");
pw.println(" <td width=\"80%\" colspan=\"2\">" + defs.def[0] + "</td>");
}*/
pw.println(" </tr>");
for (i=1; i<defs.def.length; i++)
{
pw.println(" <tr>");
if (ds!=null) tag = ds.getTag(i);
else tag = null;
if (tag!=null)
{
pw.println(" <td width=\"12%\">"+ tag +"</td>");
pw.println(" <td width=\"68%\">" + defs.def[i] + "</td>");
}
else pw.println(" <td width=\"80%\" colspan=\"2\">" + defs.def[i] + "</td>");
pw.println(" </tr>");
}
try
{
word = new SwingWord(words[j]);
defs = word.getDefs();
ds = defs.getDictionarySource();
if (ds==null || ds.isEmpty()) continue;
pw.println(" <tr>");
tag = ds.getTag(0);
// else tag = null;
/*if (tag!=null)
{*/
pw.println(" <td width=\"20%\" rowspan=\""+ defs.def.length +"\" valign=\"top\">"+ word.getBookmark(tibetan) +"</td>");
pw.println(" <td width=\"12%\">"+ tag +"</td>");
pw.println(" <td width=\"68%\">" + defs.def[0] + "</td>");
/*}
else
{
pw.println(" <td width=\"20%\" rowspan=\""+ defs.def.length +"\" valign=\"top\">"+ words[j].getBookmark(tibetan) +"</td>");
pw.println(" <td width=\"80%\" colspan=\"2\">" + defs.def[0] + "</td>");
}*/
pw.println(" </tr>");
for (i=1; i<defs.def.length; i++)
{
pw.println(" <tr>");
if (ds!=null) tag = ds.getTag(i);
else tag = null;
if (tag!=null)
{
pw.println(" <td width=\"12%\">"+ tag +"</td>");
pw.println(" <td width=\"68%\">" + defs.def[i] + "</td>");
}
else pw.println(" <td width=\"80%\" colspan=\"2\">" + defs.def[i] + "</td>");
pw.println(" </tr>");
}
}
catch (Exception e)
{
sl.writeLog("Crash\tOnLineScannerFilter\t" + word.getWylie());
sl.writeException(e);
}
}
pw.println("</table>");
}

View file

@ -62,8 +62,7 @@ public class RemoteScannerFilter extends GenericServlet
res.setContentType ("text/plain");
sl.setUserIP(req.getRemoteAddr());
Token token[] = null;
Word word = null;
Word word = null, words[] = null;
PrintWriter out;
try
@ -117,28 +116,29 @@ public class RemoteScannerFilter extends GenericServlet
}
/* FIXME: sometimes getDef returns raises a NullPointerException.
/* FIXME: sometimes getDef raises a NullPointerException.
In the meantime, I'll just keep it from crashing
*/
sl.writeLog("Translation\tRemoteScannerFilter");
try
{
scanner.clearTokens();
while((linea = br.readLine())!= null)
scanner.scanLine(linea);
br.close();
scanner.finishUp();
token = scanner.getTokenArray();
words = scanner.getWordArray();
for (i=0; i<token.length; i++)
for (i=0; i<words.length; i++)
{
if (!(token[i] instanceof Word)) continue;
word = (Word) token[i];
out.println(word.getWylie());
out.println(word.getDef());
out.println();
linea = words[i].getDef();
if (linea == null) continue;
out.println(words[i].getWylie());
out.println(linea);
out.println();
}
}
catch (Exception e)

View file

@ -33,7 +33,7 @@ public class ScannerLogger
public ScannerLogger()
{
ResourceBundle rb = ResourceBundle.getBundle("dictionary");
ResourceBundle rb = ResourceBundle.getBundle("dictionary");
fileName = rb.getString("remotescannerfilter.log-file-name");
lastIP = null;
}
@ -53,9 +53,10 @@ public class ScannerLogger
{
PrintStream pw = getPrintStream();
if (lastIP!=null) pw.print(lastIP);
pw.println("\t" + getCurrentTime() + "\t" + s);
pw.flush();
pw.close();
else pw.print("-");
pw.println("\t" + getCurrentTime() + "\t" + s);
pw.flush();
pw.close();
}
private PrintStream getPrintStream()

View file

@ -316,58 +316,56 @@ public abstract class TibetanScanner
Token token;
Word array[], word;
int n=0;
SimplifiedListIterator li = wordList.listIterator();
SimplifiedLinkedList ll2, ll = new SimplifiedLinkedList();
while(li.hasNext())
{
token = (Token) li.next();
if (token instanceof Word)
{
ll.addLast(token);
}
}
if (includeRepeated)
{
n = ll.size();
if (n==0) return null;
array = new Word[n];
li = ll.listIterator();
n=0;
while (li.hasNext())
{
array[n++] = (Word) li.next();
}
}
else
{
ll2 = new SimplifiedLinkedList();
li = ll.listIterator();
while(li.hasNext())
{
word = (Word) li.next();
if (!ll2.contains(word)) ll2.addLast(word);
}
n = ll2.size();
if (n==0) return null;
array = new Word[n];
li = ll2.listIterator();
while (li.hasNext())
{
array[--n] = (Word) li.next();
}
}
SimplifiedListIterator li = wordList.listIterator();
SimplifiedLinkedList ll2, ll = new SimplifiedLinkedList();
while(li.hasNext())
{
token = (Token) li.next();
if (token instanceof Word)
{
ll.addLast(token);
}
}
if (includeRepeated)
{
n = ll.size();
if (n==0) return null;
array = new Word[n];
li = ll.listIterator();
n=0;
while (li.hasNext())
{
array[n++] = (Word) li.next();
}
}
else
{
ll2 = new SimplifiedLinkedList();
li = ll.listIterator();
while(li.hasNext())
{
word = (Word) li.next();
if (!ll2.contains(word)) ll2.addLast(word);
}
n = ll2.size();
if (n==0) return null;
array = new Word[n];
li = ll2.listIterator();
while (li.hasNext())
{
array[--n] = (Word) li.next();
}
}