1 package be
.nikiroo
.fanfix
.reader
;
3 import java
.io
.IOException
;
6 import be
.nikiroo
.fanfix
.Instance
;
7 import be
.nikiroo
.fanfix
.Library
;
8 import be
.nikiroo
.fanfix
.data
.Story
;
9 import be
.nikiroo
.fanfix
.supported
.BasicSupport
;
10 import be
.nikiroo
.fanfix
.supported
.BasicSupport
.SupportType
;
13 * Command line {@link Story} reader.
15 * Will output stories to the console.
19 public abstract class BasicReader
{
20 public enum ReaderType
{
21 /** Simple reader that outputs everything on the console */
23 /** Reader that starts local programs to handle the stories */
27 private static ReaderType defaultType
;
29 private ReaderType type
;
32 // TODO: default type from config
36 * The type of this reader.
40 public ReaderType
getType() {
45 * The type of this reader.
50 protected BasicReader
setType(ReaderType type
) {
56 * Return the current {@link Story}.
58 * @return the {@link Story}
60 public Story
getStory() {
65 * Create a new {@link BasicReader} for a {@link Story} in the
69 * the {@link Story} ID
71 * in case of I/O error
73 public void setStory(String luid
) throws IOException
{
74 story
= Instance
.getLibrary().getStory(luid
);
76 throw new IOException("Cannot retrieve story from library: " + luid
);
81 * Create a new {@link BasicReader} for an external {@link Story}.
84 * the {@link Story} {@link URL}
86 * in case of I/O error
88 public void setStory(URL source
) throws IOException
{
89 BasicSupport support
= BasicSupport
.getSupport(source
);
90 if (support
== null) {
91 throw new IOException("URL not supported: " + source
.toString());
94 story
= support
.process(source
);
96 throw new IOException(
97 "Cannot retrieve story from external source: "
104 * Start the {@link Story} Reading.
106 * @throws IOException
107 * in case of I/O error or if the {@link Story} was not
110 public abstract void read() throws IOException
;
113 * Read the selected chapter (starting at 1).
118 public abstract void read(int chapter
);
121 * Start the reader in browse mode for the given type (or pass NULL for all
125 * the type of {@link Story} to take into account, or NULL for
128 public abstract void start(SupportType type
);
131 * Return a new {@link BasicReader} ready for use.
133 * @return a {@link BasicReader}
135 public static BasicReader
getReader() {
136 switch (defaultType
) {
138 // return new LocalReader().setType(ReaderType.LOCAL);
140 return new CliReader().setType(ReaderType
.CLI
);
147 * The default {@link ReaderType} used when calling
148 * {@link BasicReader#getReader()}.
150 * @return the default type
152 public static ReaderType
getDefaultReaderType() {
157 * The default {@link ReaderType} used when calling
158 * {@link BasicReader#getReader()}.
161 * the new default type
163 public static void setDefaultReaderType(ReaderType defaultType
) {
164 BasicReader
.defaultType
= defaultType
;