0449b818caa9ec88f9557acaa67460bfce084382
1 package be
.nikiroo
.fanfix
.searchable
;
3 import java
.io
.IOException
;
7 import org
.jsoup
.helper
.DataUtil
;
8 import org
.jsoup
.nodes
.Document
;
10 import be
.nikiroo
.fanfix
.Instance
;
11 import be
.nikiroo
.fanfix
.data
.MetaData
;
12 import be
.nikiroo
.fanfix
.supported
.BasicSupport
;
13 import be
.nikiroo
.fanfix
.supported
.SupportType
;
16 * This class supports browsing through stories on the supported websites. It
17 * will fetch some {@link MetaData} that satisfy a search query or some tags if
22 public abstract class BasicSearchable
{
23 private SupportType type
;
24 private BasicSupport support
;
27 * Create a new {@link BasicSearchable} of the given type.
30 * the type, must not be NULL
32 public BasicSearchable(SupportType type
) {
34 support
= BasicSupport
.getSupport(getType(), null);
42 public SupportType
getType() {
52 protected void setType(SupportType type
) {
57 * The associated {@link BasicSupport}.
59 * Mostly used to download content.
63 protected BasicSupport
getSupport() {
68 * Get a list of tags that can be browsed here.
70 * @return the list of tags
73 * in case of I/O error
75 abstract public List
<SearchableTag
> getTags() throws IOException
;
78 * Fill the tag (set it 'complete') with more information from the support.
84 * in case of I/O error
86 abstract public void fillTag(SearchableTag tag
) throws IOException
;
89 * Search for the given term and return the number of pages of results of
90 * stories satisfying this search term.
93 * the term to search for
95 * @return a number of pages
98 * in case of I/O error
100 abstract public int searchPages(String search
) throws IOException
;
103 * Search for the given term and return a list of stories satisfying this
106 * Not that the returned stories will <b>NOT</b> be complete, but will only
107 * contain enough information to present them to the user and retrieve them.
109 * URL is guaranteed to be usable, LUID will always be NULL.
112 * the term to search for
114 * the page to use for result pagination, index is 1-based
116 * @return a list of stories that satisfy that search term
118 * @throws IOException
119 * in case of I/O error
121 abstract public List
<MetaData
> search(String search
, int page
)
125 * Search for the given tag and return a list of stories satisfying this
128 * Not that the returned stories will <b>NOT</b> be complete, but will only
129 * contain enough information to present them to the user and retrieve them.
131 * URL is guaranteed to be usable, LUID will always be NULL.
134 * the tag to search for
136 * the page to use for result pagination (see
137 * {@link SearchableTag#getPages()}, remember to check for -1),
140 * @return a list of stories that satisfy that search term
142 * @throws IOException
143 * in case of I/O error
145 abstract public List
<MetaData
> search(SearchableTag tag
, int page
)
149 * Load a document from its url.
154 * TRUE for more stable resources, FALSE when they often change
156 * @return the document
158 * @throws IOException
159 * in case of I/O error
161 protected Document
load(String url
, boolean stable
) throws IOException
{
162 return load(new URL(url
), stable
);
166 * Load a document from its url.
171 * TRUE for more stable resources, FALSE when they often change
173 * @return the document
175 * @throws IOException
176 * in case of I/O error
178 protected Document
load(URL url
, boolean stable
) throws IOException
{
179 return DataUtil
.load(Instance
.getCache().open(url
, support
, stable
),
180 "UTF-8", url
.toString());
184 * Return a {@link BasicSearchable} implementation supporting the given
185 * type, or NULL if it does not exist.
188 * the type, must not be NULL
190 * @return an implementation that supports it, or NULL
192 public static BasicSearchable
getSearchable(SupportType type
) {
193 BasicSearchable support
= null;
200 support
= new Fanfiction(type
);
215 support
= new MangaLel();