ebc509611856b0a6f6d699a64c7a96592a68428a
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 a list of stories satisfying this
92 * Not that the returned stories will <b>NOT</b> be complete, but will only
93 * contain enough information to present them to the user and retrieve them.
95 * URL is guaranteed to be usable, LUID will always be NULL.
98 * the term to search for
100 * @return a list of stories that satisfy that search term
102 * @throws IOException
103 * in case of I/O error
105 abstract public List
<MetaData
> search(String search
) throws IOException
;
108 * Search for the given tag and return a list of stories satisfying this
111 * Not that the returned stories will <b>NOT</b> be complete, but will only
112 * contain enough information to present them to the user and retrieve them.
114 * URL is guaranteed to be usable, LUID will always be NULL.
117 * the tag to search for
119 * the page to use for result pagination (see
120 * {@link SearchableTag#getPages()}, remember to check for -1),
123 * @return a list of stories that satisfy that search term
125 * @throws IOException
126 * in case of I/O error
128 abstract public List
<MetaData
> search(SearchableTag tag
, int page
)
132 * Load a document from its url.
137 * TRUE for more stable resources, FALSE when they often change
139 * @return the document
141 * @throws IOException
142 * in case of I/O error
144 protected Document
load(String url
, boolean stable
) throws IOException
{
145 return load(new URL(url
), stable
);
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(URL url
, boolean stable
) throws IOException
{
162 return DataUtil
.load(Instance
.getCache().open(url
, support
, stable
),
163 "UTF-8", url
.toString());
167 * Return a {@link BasicSearchable} implementation supporting the given
168 * type, or NULL if it does not exist.
171 * the type, must not be NULL
173 * @return an implementation that supports it, or NULL
175 public static BasicSearchable
getSearchable(SupportType type
) {
176 BasicSearchable support
= null;
183 support
= new Fanfiction(type
);