--list was causing problems + move reader
[fanfix.git] / src / be / nikiroo / fanfix / reader / FanfixReader.java
CommitLineData
89cb07a6
NR
1package be.nikiroo.fanfix.reader;
2
3import java.io.IOException;
4import java.net.URL;
5
6import be.nikiroo.fanfix.Instance;
7import be.nikiroo.fanfix.Library;
8import be.nikiroo.fanfix.data.Story;
9import be.nikiroo.fanfix.supported.BasicSupport;
10import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
11
12/**
13 * Command line {@link Story} reader.
14 * <p>
15 * Will output stories to the console.
16 *
17 * @author niki
18 */
19public abstract class FanfixReader {
20 private Story story;
21
22 /**
23 * Return the current {@link Story}.
24 *
25 * @return the {@link Story}
26 */
27 public Story getStory() {
28 return story;
29 }
30
31 /**
32 * Create a new {@link FanfixReader} for a {@link Story} in the
33 * {@link Library} .
34 *
35 * @param luid
36 * the {@link Story} ID
37 * @throws IOException
38 * in case of I/O error
39 */
40 public void setStory(String luid) throws IOException {
41 story = Instance.getLibrary().getStory(luid);
42 if (story == null) {
43 throw new IOException("Cannot retrieve story from library: " + luid);
44 }
45 }
46
47 /**
48 * Create a new {@link FanfixReader} for an external {@link Story}.
49 *
50 * @param source
51 * the {@link Story} {@link URL}
52 * @throws IOException
53 * in case of I/O error
54 */
55 public void setStory(URL source) throws IOException {
56 BasicSupport support = BasicSupport.getSupport(source);
57 if (support == null) {
58 throw new IOException("URL not supported: " + source.toString());
59 }
60
61 story = support.process(source);
62 if (story == null) {
63 throw new IOException(
64 "Cannot retrieve story from external source: "
65 + source.toString());
66
67 }
68 }
69
70 /**
71 * Start the {@link Story} Reading.
72 *
73 * @throws IOException
74 * in case of I/O error or if the {@link Story} was not
75 * previously set
76 */
77 public abstract void read() throws IOException;
78
79 /**
80 * Read the selected chapter (starting at 1).
81 *
82 * @param chapter
83 * the chapter
84 */
85 public abstract void read(int chapter);
86
87 /**
88 * Start the reader in browse mode for the given type (or pass NULL for all
89 * types).
90 *
91 * @param type
92 * the type of {@link Story} to take into account, or NULL for
93 * all
94 */
95 public abstract void start(SupportType type);
96}