1 package net.mlw.fball.loader.yahoo.league;
2
3 import java.io.File;
4 import java.io.FileReader;
5 import java.io.LineNumberReader;
6 import java.util.Iterator;
7
8 import net.mlw.fball.bo.Coach;
9 import net.mlw.fball.bo.League;
10 import net.mlw.fball.bo.Player;
11 import net.mlw.fball.event.StatusEvent;
12 import net.mlw.fball.gui.events.ErrorEvent;
13 import net.mlw.util.ParsingUtils;
14
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17
18 /***
19 *
20 * @author Matthew L. Wilson
21 * @version $Revision: 1.1 $ $Date: 2004/04/01 21:51:07 $
22 */
23 public class PlayerLoader extends AbstractLeagueLoader
24 {
25 /*** Commons Logger. **/
26 private static final Log LOGGER = LogFactory.getLog(PlayerLoader.class);
27
28 /***
29 * @see java.lang.Runnable#run()
30 */
31 public void updateLeague(League league) throws Exception
32 {
33 for (Iterator iter = league.getCoaches().values().iterator(); iter.hasNext();)
34 {
35 Coach coach = (Coach) iter.next();
36 coach.getPlayers().clear();
37 }
38
39 File file = new File("/stats/yahoo/leagues/" + league.getId() + "/players.html");
40 if (file.exists())
41 {
42 int index = 0;
43 LineNumberReader reader = new LineNumberReader(new FileReader(file));
44 while (reader.ready())
45 {
46 String line = reader.readLine();
47
48 if ((index = line.indexOf("nfl/players/")) >= 0)
49 {
50 String yahooPlayerId = line.substring(index + 12, line.indexOf("\"", index));
51 String yahooCoachId = line.substring((index = line.indexOf("&mid=") + 5), line.indexOf("\"", index));
52
53 Coach coach = (Coach) league.getCoaches().get(yahooCoachId);
54 if (coach != null)
55 {
56 Player player = playerDao.findByProvider("yahoo", yahooPlayerId);
57 if (player != null)
58 {
59 coach.getPlayers().put(player.getId(), player);
60 }
61 else
62 {
63 eventListener.onEvent(
64 new StatusEvent(
65 coach.getName()
66 + ": Player ("
67 + ParsingUtils.getTdContents(line, "null", 4)
68 + ") not found: 'yahoo' - '"
69 + yahooPlayerId
70 + "'"));
71 }
72 }
73 else
74 {
75 eventListener.onEvent(new ErrorEvent("Coach not found: '" + yahooCoachId + "'"));
76 }
77 }
78 }
79 }
80 }
81
82 }
This page was automatically generated by Maven