1 package net.mlw.fball.loader.yahoo;
2
3 import java.io.File;
4 import java.io.FileReader;
5 import java.io.LineNumberReader;
6 import java.net.URL;
7
8 import net.mlw.fball.bo.Team;
9 import net.mlw.fball.event.ProgressEvent;
10 import net.mlw.fball.event.StatusEvent;
11 import net.mlw.fball.loader.LoaderContextHolder;
12 import net.mlw.util.NetUtils;
13
14 /***
15 * @author Matthew L. Wilson
16 * @version $Revision: 1.6 $ $Date: 2004/04/01 21:51:07 $
17 */
18 public class TeamLoader extends LoaderContextHolder
19 {
20 /***
21 * @see java.lang.Runnable#run()
22 */
23 public void doLoad() throws Exception
24 {
25 File file = new File(getBaseDir() + "/team-list");
26
27 eventListener.onEvent(new StatusEvent("Saving: (" + file + ") <--" + location));
28 NetUtils.copyFile(new URL(location), file);
29
30 int index = 0;
31 int totalCount = 0;
32 LineNumberReader reader = new LineNumberReader(new FileReader(file));
33 while (reader.ready())
34 {
35 String line = reader.readLine();
36 if ((index = line.indexOf("/nfl/teams/")) >= 0)
37 {
38 totalCount++;
39 }
40 }
41 eventListener.onEvent(new ProgressEvent(totalCount));
42
43 int count = 0;
44 reader = new LineNumberReader(new FileReader(file));
45 while (reader.ready())
46 {
47 String line = reader.readLine();
48 if ((index = line.indexOf("/nfl/teams/")) >= 0)
49 {
50 String name = line.substring(line.indexOf(">", index) + 1, line.indexOf("<", index));
51 String shortName = line.substring(index + 11, index + 14);
52 String teamProviderId = line.substring(index + 11, index + 14);
53
54 Team team = teamDao.findByProvider("yahoo", teamProviderId);
55 if (team == null)
56 {
57 team = new Team();
58 team.addProvider("yahoo", teamProviderId);
59 }
60
61 team.setName(name);
62 team.setShortName(shortName);
63
64 eventListener.onEvent(new StatusEvent("Saving: " + team));
65 teamDao.save(team);
66 eventListener.onEvent(new ProgressEvent(totalCount, ++count));
67 }
68 }
69 }
70
71 }
This page was automatically generated by Maven