1 package org.paneris.bibliomania;
2
3 import java.util.Vector;
4
5 import org.melati.Melati;
6 import org.melati.poem.PoemThread;
7 import org.melati.poem.util.EnumUtils;
8 import org.melati.util.ThrowingPrintWriter;
9 import org.melati.util.UnexpectedExceptionException;
10 import org.webmacro.WebMacroException;
11 import org.webmacro.servlet.WebContext;
12
13 public class FixTextID extends BibliomaniaServlet {
14
15
16
17
18 private static final long serialVersionUID = 1L;
19
20 protected String bibliomaniaHandle(Melati melati, WebContext context)
21 throws WebMacroException {
22
23 ThrowingPrintWriter p;
24
25 try {
26 context.getResponse().setContentType("text/plain");
27 p = new ThrowingPrintWriter(context.getResponse().getWriter(),
28 "servlet output");
29 }
30 catch (Exception e) {
31 throw new UnexpectedExceptionException(e);
32 }
33
34 Integer diag = null;
35 long what = 0;
36
37 try {
38 ChapterTable chapters =
39 ((BibliomaniaDatabase)melati.getDatabase()).getChapterTable();
40
41 Vector all = EnumUtils.vectorOf(chapters.selection("textid is null"));
42
43 for (int i = 0; i < all.size(); ++i) {
44 if (i % 200 == 0) {
45 PoemThread.commit();
46 p.println("Done " + i);
47 p.flush();
48 }
49
50 Chapter chapter = (Chapter)all.elementAt(i);
51 diag = chapter.troid();
52 chapter.setTextid(what = chapter.ftiTextID());
53 }
54
55 PoemThread.commit();
56
57 p.println("Finished successfully");
58 }
59 catch (Exception e) {
60 p.println("\nAt record " + diag + " " + what + " (" + Long.toString(what, 2) + "):\n");
61 e.printStackTrace(p);
62 }
63
64 return null;
65 }
66 }