package baf.guide; import baf.util.*; import java.util.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Game extends Item { public static SortedList all = new SortedList(); public static long globalLastModified = 0; public static long lastObsolete = 0; boolean obsolete = false; public Game(String path) throws IOException { super(path); name = attributes.getProperty(":t"); if (name == null) throw new IllegalArgumentException(); sortString = name.toLowerCase(); // Chop introductory words like "the" from the sortString StringTokenizer st = new StringTokenizer(sortString); String prefix = st.nextToken(); for (int i=ignorables.length-1; i>=0; i--) if (prefix.equals(ignorables[i])) { sortString = st.nextToken("").trim(); break; } } /** Prefixes that can be ignored when sorting. */ private static final String ignorables[] = { "a", "the", "la", "die", "der"}; public long getLastModified() { return new File(filename).lastModified(); } /** Synchronizes the cache with the filesystem. */ public static synchronized void update() throws IOException { File gamedir = new File(basedir + "/games"); String games[] = gamedir.list(); long max = globalLastModified; for (int i=0; i globalLastModified) { String path = "/games/"+fname; Game newg = new Game(path); Game oldg = (Game)byPath.put(path, newg); if (oldg != null) { oldg.obsolete = true; all.remove(oldg); if (lm > lastObsolete) lastObsolete = lm; } all.add(newg); } if (lm > max) max = lm; } globalLastModified = max; } public static final Game[] search(String tag, String value) throws IOException { return Index.forTag(tag).search(value); } public void header(ServletOutputStream out) throws IOException { header(out, name, getDescription(), null, null); } public void body(ServletOutputStream out) throws IOException { out.print(""); out.print(name); out.print("
\n"); // List the authors String authors = attributes.getProperty(":a"); if (authors == null) out.print("Anonymous"); else { StringTokenizer st = new StringTokenizer(authors, "/"); Author a[] = new Author[st.countTokens()]; for (int i=0; i\n"); String rating = attributes.getProperty(":r"); if (rating == null) out.print("Not rated"); else out.print(rating); out.print("
\n"); String shareware = attributes.getProperty(":s"); if (shareware != null) { out.print(shareware); out.print("
\n"); } super.body(out); out.print("
\n"); } public String getTag() { return ":t"; } public String getDescription() { return "Review of "+name; } public void page(ServletOutputStream out) throws IOException { header(out); body(out); footer(out); } public static void indexPage(ServletOutputStream out) throws IOException { update(); header(out, "All games", "Index of all text adventures reviewed"); out.print("

Index of All Games

\n\n"); footer(out); } public static void reviewsPage(ServletOutputStream out) throws IOException { update(); header(out, "All reviews", "Reviews of text adventures"); out.print("

All Reviews

\n"); for (Enumeration e = all.elements(); e.hasMoreElements(); ) { out.print("
\n"); Game g = (Game)e.nextElement(); g.body(out); } footer(out); } }