25c388a8e268aa1bde8a26f84c4d10a2721be070
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 protected 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 * @return a list of stories that satisfy that search term
121 * @throws IOException
122 * in case of I/O error
124 abstract public List
<MetaData
> search(SearchableTag tag
) throws IOException
;
127 * Load a document from its url.
131 * @return the document
133 * @throws IOException
134 * in case of I/O error
136 protected Document
load(String url
) throws IOException
{
137 return load(new URL(url
));
141 * Load a document from its url.
145 * @return the document
147 * @throws IOException
148 * in case of I/O error
150 protected Document
load(URL url
) throws IOException
{
151 return DataUtil
.load(Instance
.getCache().open(url
, support
, false),
152 "UTF-8", url
.toString());
156 * Return a {@link BasicSearchable} implementation supporting the given
157 * type, or NULL if it does not exist.
160 * the type, must not be NULL
162 * @return an implementation that supports it, or NULL
164 public static BasicSearchable
getSearchable(SupportType type
) {
165 BasicSearchable support
= null;
172 support
= new Fanfiction(type
);