updated the servlet version. logging still needs work.
This commit is contained in:
parent
28d46bb207
commit
78373b3094
9 changed files with 251 additions and 57 deletions
|
@ -37,13 +37,18 @@ public class CachedSyllableListTree implements SyllableListTree
|
||||||
SyllableListTree syllables[];
|
SyllableListTree syllables[];
|
||||||
|
|
||||||
public CachedSyllableListTree(String archivo) throws Exception
|
public CachedSyllableListTree(String archivo) throws Exception
|
||||||
|
{
|
||||||
|
this (archivo, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CachedSyllableListTree(String archivo, boolean backwardCompatible) throws Exception
|
||||||
{
|
{
|
||||||
String sil;
|
String sil;
|
||||||
long pos, defSources[];
|
long pos, defSources[];
|
||||||
DictionarySource sourceDef;
|
DictionarySource sourceDef;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
FileSyllableListTree.openFiles(archivo);
|
FileSyllableListTree.openFiles(archivo, backwardCompatible);
|
||||||
|
|
||||||
SimplifiedLinkedList syllables = new SimplifiedLinkedList();
|
SimplifiedLinkedList syllables = new SimplifiedLinkedList();
|
||||||
do
|
do
|
||||||
|
|
|
@ -84,6 +84,24 @@ public class FileSyllableListTree implements SyllableListTree
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openFiles(String archivo) throws Exception
|
public static void openFiles(String archivo) throws Exception
|
||||||
|
{
|
||||||
|
openFiles(archivo, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void closeFiles()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
wordRaf.close();
|
||||||
|
defRaf.close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openFiles(String archivo, boolean backwardCompatible) throws Exception
|
||||||
{
|
{
|
||||||
long fileSize;
|
long fileSize;
|
||||||
int pos;
|
int pos;
|
||||||
|
@ -108,6 +126,8 @@ public class FileSyllableListTree implements SyllableListTree
|
||||||
{
|
{
|
||||||
// Updates the dictionary for backward compatibility.
|
// Updates the dictionary for backward compatibility.
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
if (backwardCompatible)
|
||||||
{
|
{
|
||||||
wordRaf.close();
|
wordRaf.close();
|
||||||
wordRaf = new RandomAccessFile(archivo + ".wrd", "rw");
|
wordRaf = new RandomAccessFile(archivo + ".wrd", "rw");
|
||||||
|
@ -121,6 +141,21 @@ public class FileSyllableListTree implements SyllableListTree
|
||||||
wordRaf.close();
|
wordRaf.close();
|
||||||
wordRaf = new RandomAccessFile(archivo + ".wrd", "r");
|
wordRaf = new RandomAccessFile(archivo + ".wrd", "r");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// something is wrong
|
||||||
|
ScannerLogger sl = new ScannerLogger();
|
||||||
|
sl.writeLog("Crash\tFileSyllableListTree\t" + "size: " + fileSize + "; bytes: " + Integer.toHexString(pos));
|
||||||
|
|
||||||
|
// try to open again, but not corrupting the file
|
||||||
|
wordRaf = new RandomAccessFile(archivo + ".wrd", "r");
|
||||||
|
|
||||||
|
fileSize = wordRaf.length();
|
||||||
|
wordRaf.seek(fileSize-8L);
|
||||||
|
pos = wordRaf.readInt();
|
||||||
|
versionNumber = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// dictionary is stored on a non-writable media. Do nothing.
|
// dictionary is stored on a non-writable media. Do nothing.
|
||||||
|
|
|
@ -48,14 +48,18 @@ public class LocalTibetanScanner extends TibetanScanner
|
||||||
return raiz.getDictionarySourcesWanted();
|
return raiz.getDictionarySourcesWanted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LocalTibetanScanner(String arch) throws Exception
|
public LocalTibetanScanner(String arch) throws Exception
|
||||||
|
{
|
||||||
|
this (arch, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalTibetanScanner(String arch, boolean backwardCompatible) throws Exception
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
archivo = arch;
|
archivo = arch;
|
||||||
// raiz = new MemorySyllableListTree(archivo);
|
// raiz = new MemorySyllableListTree(archivo);
|
||||||
// raiz = new FileSyllableListTree(archivo);
|
// raiz = new FileSyllableListTree(archivo);
|
||||||
raiz = new CachedSyllableListTree(archivo);
|
raiz = new CachedSyllableListTree(archivo, backwardCompatible);
|
||||||
floatingSil = new Vector();
|
floatingSil = new Vector();
|
||||||
resetAll();
|
resetAll();
|
||||||
}
|
}
|
||||||
|
@ -409,4 +413,9 @@ outAHere:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void destroy()
|
||||||
|
{
|
||||||
|
FileSyllableListTree.closeFiles();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -48,16 +48,29 @@ public class OnLineScannerFilter extends HttpServlet
|
||||||
ResourceBundle rb;
|
ResourceBundle rb;
|
||||||
private TibetanScanner scanner;
|
private TibetanScanner scanner;
|
||||||
private String dictionaries[];
|
private String dictionaries[];
|
||||||
|
private ScannerLogger sl;
|
||||||
|
|
||||||
public OnLineScannerFilter() throws Exception
|
public OnLineScannerFilter() //throws Exception
|
||||||
{
|
{
|
||||||
rb = ResourceBundle.getBundle(propertyFile);
|
rb = ResourceBundle.getBundle(propertyFile);
|
||||||
scanner = new LocalTibetanScanner(rb.getString(dictNameProperty));
|
sl = new ScannerLogger();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
scanner = new LocalTibetanScanner(rb.getString(dictNameProperty), false);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
sl.writeLog("Crash\tOnLineScannerFilter");
|
||||||
|
sl.writeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
dictionaries = scanner.getDictionaryDescriptions();
|
dictionaries = scanner.getDictionaryDescriptions();
|
||||||
|
sl.writeLog("Creation\tOnLineScannerFilter");
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public void doGet(HttpServletRequest request,
|
synchronized public void doGet(HttpServletRequest request,
|
||||||
HttpServletResponse response) throws IOException, ServletException
|
HttpServletResponse response) //throws IOException, ServletException
|
||||||
{
|
{
|
||||||
String answer, parrafo = null, checkboxName;
|
String answer, parrafo = null, checkboxName;
|
||||||
|
|
||||||
|
@ -66,7 +79,19 @@ public class OnLineScannerFilter extends HttpServlet
|
||||||
ThdlOptions.setUserPreference("thdl.rely.on.system.tm.fonts", true);
|
ThdlOptions.setUserPreference("thdl.rely.on.system.tm.fonts", true);
|
||||||
|
|
||||||
response.setContentType("text/html");
|
response.setContentType("text/html");
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out;
|
||||||
|
sl.setUserIP(request.getRemoteAddr());
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
out = response.getWriter();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
sl.writeLog("Crash\tOnLineScannerFilter");
|
||||||
|
sl.writeException(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BitDictionarySource ds=null;
|
BitDictionarySource ds=null;
|
||||||
boolean checkedDicts[], allUnchecked, wantsTibetan, useTHDLBanner = (request.getParameter("thdlBanner")!=null);
|
boolean checkedDicts[], allUnchecked, wantsTibetan, useTHDLBanner = (request.getParameter("thdlBanner")!=null);
|
||||||
|
@ -260,8 +285,12 @@ public class OnLineScannerFilter extends HttpServlet
|
||||||
out.println("</form>");
|
out.println("</form>");
|
||||||
|
|
||||||
if (parrafo != null)
|
if (parrafo != null)
|
||||||
|
{
|
||||||
|
sl.writeLog("Translation\tOnLineScannerFilter");
|
||||||
if (ds!=null && !ds.isEmpty())
|
if (ds!=null && !ds.isEmpty())
|
||||||
desglosar(parrafo, out, wantsTibetan);
|
desglosar(parrafo, out, wantsTibetan);
|
||||||
|
}
|
||||||
|
else sl.writeLog("Invocation\tOnLineScannerFilter");
|
||||||
|
|
||||||
out.println(TibetanScanner.copyrightHTML);
|
out.println(TibetanScanner.copyrightHTML);
|
||||||
if (useTHDLBanner) out.println("</div><!--END main-->");
|
if (useTHDLBanner) out.println("</div><!--END main-->");
|
||||||
|
@ -271,7 +300,7 @@ public class OnLineScannerFilter extends HttpServlet
|
||||||
|
|
||||||
public void doPost(HttpServletRequest request,
|
public void doPost(HttpServletRequest request,
|
||||||
HttpServletResponse response)
|
HttpServletResponse response)
|
||||||
throws IOException, ServletException
|
//throws IOException, ServletException
|
||||||
{
|
{
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
|
@ -408,4 +437,13 @@ public class OnLineScannerFilter extends HttpServlet
|
||||||
}
|
}
|
||||||
pw.println("</table>");
|
pw.println("</table>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void destroy()
|
||||||
|
{
|
||||||
|
super.destroy();
|
||||||
|
sl.setUserIP(null);
|
||||||
|
sl.writeLog("Shutdown\tOnLineScannerFilter");
|
||||||
|
scanner.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.awt.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.applet.Applet;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.datatransfer.*;
|
import java.awt.datatransfer.*;
|
||||||
import org.thdl.util.*;
|
import org.thdl.util.*;
|
||||||
|
|
|
@ -36,30 +36,47 @@ public class RemoteScannerFilter extends GenericServlet
|
||||||
{
|
{
|
||||||
private TibetanScanner scanner;
|
private TibetanScanner scanner;
|
||||||
private BitDictionarySource ds;
|
private BitDictionarySource ds;
|
||||||
|
private ScannerLogger sl;
|
||||||
|
|
||||||
public RemoteScannerFilter() throws Exception
|
public RemoteScannerFilter()
|
||||||
{
|
{
|
||||||
ResourceBundle rb = ResourceBundle.getBundle("dictionary");
|
ResourceBundle rb = ResourceBundle.getBundle("dictionary");
|
||||||
scanner = new LocalTibetanScanner(rb.getString("onlinescannerfilter.dict-file-name"));
|
sl = new ScannerLogger();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
scanner = new LocalTibetanScanner(rb.getString("onlinescannerfilter.dict-file-name"),false);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
sl.writeLog("Crash\tRemoteScannerFilter");
|
||||||
|
sl.writeException(e);
|
||||||
|
}
|
||||||
ds = scanner.getDictionarySource();
|
ds = scanner.getDictionarySource();
|
||||||
|
sl.writeLog("Creation\tRemoteScannerFilter");
|
||||||
|
|
||||||
String fileName = rb.getString("remotescannerfilter.log-file-name");
|
|
||||||
Calendar rightNow = Calendar.getInstance();
|
|
||||||
|
|
||||||
PrintStream pw = new PrintStream(new FileOutputStream(fileName, true));
|
|
||||||
pw.println("Testing: " + rightNow.toString());
|
|
||||||
pw.flush();
|
|
||||||
pw.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
|
public void service(ServletRequest req, ServletResponse res) //throws ServletException, IOException
|
||||||
{
|
{
|
||||||
BufferedReader br;
|
BufferedReader br;
|
||||||
res.setContentType ("text/plain");
|
res.setContentType ("text/plain");
|
||||||
|
sl.setUserIP(req.getRemoteAddr());
|
||||||
|
|
||||||
Token token[] = null;
|
Token token[] = null;
|
||||||
Word word = null;
|
Word word = null;
|
||||||
PrintWriter out = res.getWriter();
|
PrintWriter out;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
out = res.getWriter();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
sl.writeLog("Crash\tRemoteScannerFilter");
|
||||||
|
sl.writeException(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
String linea, dicts = req.getParameter("dicts"), dicDescrip[];
|
String linea, dicts = req.getParameter("dicts"), dicDescrip[];
|
||||||
|
|
||||||
|
@ -67,6 +84,7 @@ public class RemoteScannerFilter extends GenericServlet
|
||||||
{
|
{
|
||||||
if (dicts.equals("names"))
|
if (dicts.equals("names"))
|
||||||
{
|
{
|
||||||
|
sl.writeLog("Invocation\tRemoteScannerFilter");
|
||||||
dicDescrip = scanner.getDictionaryDescriptions();
|
dicDescrip = scanner.getDictionaryDescriptions();
|
||||||
if (dicDescrip==null)
|
if (dicDescrip==null)
|
||||||
{
|
{
|
||||||
|
@ -86,11 +104,24 @@ public class RemoteScannerFilter extends GenericServlet
|
||||||
ds.setDicts(Integer.parseInt(dicts));
|
ds.setDicts(Integer.parseInt(dicts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
br = new BufferedReader(new InputStreamReader(req.getInputStream()));
|
br = new BufferedReader(new InputStreamReader(req.getInputStream()));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
sl.writeLog("Crash\tRemoteScannerFilter");
|
||||||
|
sl.writeException(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* FIXME: sometimes getDef returns raises a NullPointerException.
|
/* FIXME: sometimes getDef returns raises a NullPointerException.
|
||||||
In the meantime, I'll just keep it from crashing
|
In the meantime, I'll just keep it from crashing
|
||||||
*/
|
*/
|
||||||
|
sl.writeLog("Translation\tRemoteScannerFilter");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
while((linea = br.readLine())!= null)
|
while((linea = br.readLine())!= null)
|
||||||
|
@ -112,29 +143,19 @@ public class RemoteScannerFilter extends GenericServlet
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ResourceBundle rb = ResourceBundle.getBundle("dictionary");
|
sl.writeLog("Crash\tRemoteScannerFilter\t" + word.getWylie());
|
||||||
String fileName = rb.getString("remotescannerfilter.log-file-name");
|
sl.writeException(e);
|
||||||
Calendar rightNow = Calendar.getInstance();
|
|
||||||
|
|
||||||
PrintStream pw = new PrintStream(new FileOutputStream(fileName, true));
|
|
||||||
pw.println("Translation tool crashed on: " + rightNow.toString());
|
|
||||||
e.printStackTrace(pw);
|
|
||||||
pw.println();
|
|
||||||
pw.println("Word that crashed: " + word.getWylie());
|
|
||||||
pw.println();
|
|
||||||
pw.println("All words:");
|
|
||||||
for (i=0; i<token.length; i++)
|
|
||||||
{
|
|
||||||
if (!(token[i] instanceof Word)) continue;
|
|
||||||
word = (Word) token[i];
|
|
||||||
out.println(word.getWylie());
|
|
||||||
}
|
|
||||||
pw.println();
|
|
||||||
pw.flush();
|
|
||||||
pw.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner.clearTokens();
|
scanner.clearTokens();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void destroy()
|
||||||
|
{
|
||||||
|
super.destroy();
|
||||||
|
sl.setUserIP(null);
|
||||||
|
sl.writeLog("Shutdown\tRemoteScannerFilter");
|
||||||
|
scanner.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -137,4 +137,7 @@ public class RemoteTibetanScanner extends TibetanScanner
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void destroy()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
83
source/org/thdl/tib/scanner/ScannerLogger.java
Normal file
83
source/org/thdl/tib/scanner/ScannerLogger.java
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
The contents of this file are subject to the AMP Open Community License
|
||||||
|
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License on the AMP web site
|
||||||
|
(http://www.tibet.iteso.mx/Guatemala/).
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||||
|
License for the specific terms governing rights and limitations under the
|
||||||
|
License.
|
||||||
|
|
||||||
|
The Initial Developer of this software is Andres Montano Pellegrini. Portions
|
||||||
|
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
|
||||||
|
Pellegrini. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s): ______________________________________.
|
||||||
|
*/
|
||||||
|
package org.thdl.tib.scanner;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/** Designed to keep a log of the transactions taking place in the
|
||||||
|
servlet version of the translation tool.
|
||||||
|
|
||||||
|
@author Andrés Montano Pellegrini
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ScannerLogger
|
||||||
|
{
|
||||||
|
private String fileName;
|
||||||
|
private String lastIP;
|
||||||
|
|
||||||
|
public ScannerLogger()
|
||||||
|
{
|
||||||
|
ResourceBundle rb = ResourceBundle.getBundle("dictionary");
|
||||||
|
fileName = rb.getString("remotescannerfilter.log-file-name");
|
||||||
|
lastIP = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrentTime()
|
||||||
|
{
|
||||||
|
Calendar rightNow = Calendar.getInstance();
|
||||||
|
return Integer.toString(rightNow.get(Calendar.YEAR)) + "\t" + Integer.toString(rightNow.get(Calendar.MONTH)) + "\t" + Integer.toString(rightNow.get(Calendar.DAY_OF_MONTH)) + "\t" + Integer.toString(rightNow.get(Calendar.HOUR_OF_DAY)) + "\t" + Integer.toString(rightNow.get(Calendar.MINUTE)) + "\t" + Integer.toString(rightNow.get(Calendar.SECOND));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserIP(String lastIP)
|
||||||
|
{
|
||||||
|
this.lastIP = lastIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized public void writeLog(String s)
|
||||||
|
{
|
||||||
|
PrintStream pw = getPrintStream();
|
||||||
|
if (lastIP!=null) pw.print(lastIP);
|
||||||
|
pw.println("\t" + getCurrentTime() + "\t" + s);
|
||||||
|
pw.flush();
|
||||||
|
pw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PrintStream getPrintStream()
|
||||||
|
{
|
||||||
|
PrintStream pw;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pw = new PrintStream(new FileOutputStream(fileName, true));
|
||||||
|
return pw;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized public void writeException(Exception e)
|
||||||
|
{
|
||||||
|
PrintStream pw = getPrintStream();
|
||||||
|
e.printStackTrace(pw);
|
||||||
|
pw.flush();
|
||||||
|
pw.close();
|
||||||
|
}
|
||||||
|
}
|
|
@ -379,4 +379,5 @@ public abstract class TibetanScanner
|
||||||
public abstract void finishUp();
|
public abstract void finishUp();
|
||||||
public abstract BitDictionarySource getDictionarySource();
|
public abstract BitDictionarySource getDictionarySource();
|
||||||
public abstract String[] getDictionaryDescriptions();
|
public abstract String[] getDictionaryDescriptions();
|
||||||
|
public abstract void destroy();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue