From 727108fef9dcc661d45fa69ebf8b76f5128a2b6f Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 9 Apr 2019 17:37:33 +0200 Subject: [PATCH] separate support name and BasicSupport --- .../fanfix/supported/BasicSupport.java | 10 +--- src/be/nikiroo/fanfix/supported/Cbz.java | 5 -- src/be/nikiroo/fanfix/supported/E621.java | 9 +--- src/be/nikiroo/fanfix/supported/EHentai.java | 9 +--- src/be/nikiroo/fanfix/supported/Epub.java | 7 +-- .../nikiroo/fanfix/supported/Fanfiction.java | 9 +--- .../nikiroo/fanfix/supported/Fimfiction.java | 9 +--- .../fanfix/supported/FimfictionApi.java | 9 +--- src/be/nikiroo/fanfix/supported/Html.java | 5 -- src/be/nikiroo/fanfix/supported/InfoText.java | 5 -- src/be/nikiroo/fanfix/supported/MangaFox.java | 9 +--- src/be/nikiroo/fanfix/supported/MangaLel.java | 9 +--- .../nikiroo/fanfix/supported/SupportType.java | 54 +++++++++++++------ src/be/nikiroo/fanfix/supported/Text.java | 7 +-- src/be/nikiroo/fanfix/supported/YiffStar.java | 10 +--- 15 files changed, 58 insertions(+), 108 deletions(-) diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport.java b/src/be/nikiroo/fanfix/supported/BasicSupport.java index 4337626..0b0e66c 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport.java @@ -38,13 +38,6 @@ public abstract class BasicSupport { private SupportType type; private URL currentReferer; // with only one 'r', as in 'HTTP'... - /** - * The name of this support class. - * - * @return the name - */ - protected abstract String getSourceName(); - /** * Check if the given resource is supported by this {@link BasicSupport}. * @@ -444,7 +437,8 @@ public abstract class BasicSupport { * the type * @param url * the {@link URL} to support (can be NULL to get an - * "abstract support") + * "abstract support"; if not NULL, will be used as the source + * URL) * * @return an implementation that supports it, or NULL */ diff --git a/src/be/nikiroo/fanfix/supported/Cbz.java b/src/be/nikiroo/fanfix/supported/Cbz.java index 062adf0..e1a766e 100644 --- a/src/be/nikiroo/fanfix/supported/Cbz.java +++ b/src/be/nikiroo/fanfix/supported/Cbz.java @@ -36,11 +36,6 @@ class Cbz extends Epub { return url.toString().toLowerCase().endsWith(".cbz"); } - @Override - public String getSourceName() { - return "cbz"; - } - @Override protected String getDataPrefix() { return ""; diff --git a/src/be/nikiroo/fanfix/supported/E621.java b/src/be/nikiroo/fanfix/supported/E621.java index 36b9dad..dfa9e5e 100644 --- a/src/be/nikiroo/fanfix/supported/E621.java +++ b/src/be/nikiroo/fanfix/supported/E621.java @@ -33,11 +33,6 @@ import be.nikiroo.utils.StringUtils; * @author niki */ class E621 extends BasicSupport_Deprecated { - @Override - public String getSourceName() { - return "e621.net"; - } - @Override protected MetaData getMeta(URL source, InputStream in) throws IOException { MetaData meta = new MetaData(); @@ -46,9 +41,9 @@ class E621 extends BasicSupport_Deprecated { meta.setAuthor(getAuthor(source, reset(in))); meta.setDate(""); meta.setTags(getTags(source, reset(in), false)); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(source.toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(source.toString()); meta.setLuid(""); meta.setLang("en"); diff --git a/src/be/nikiroo/fanfix/supported/EHentai.java b/src/be/nikiroo/fanfix/supported/EHentai.java index 9ed4e89..67585cd 100644 --- a/src/be/nikiroo/fanfix/supported/EHentai.java +++ b/src/be/nikiroo/fanfix/supported/EHentai.java @@ -26,11 +26,6 @@ import be.nikiroo.utils.StringUtils; * @author niki */ class EHentai extends BasicSupport_Deprecated { - @Override - public String getSourceName() { - return "e-hentai.org"; - } - @Override protected MetaData getMeta(URL source, InputStream in) throws IOException { MetaData meta = new MetaData(); @@ -39,9 +34,9 @@ class EHentai extends BasicSupport_Deprecated { meta.setAuthor(getAuthor(reset(in))); meta.setDate(getDate(reset(in))); meta.setTags(getTags(reset(in))); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(source.toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(source.toString()); meta.setLuid(""); meta.setLang(getLang(reset(in))); diff --git a/src/be/nikiroo/fanfix/supported/Epub.java b/src/be/nikiroo/fanfix/supported/Epub.java index e5261d3..c71ba17 100644 --- a/src/be/nikiroo/fanfix/supported/Epub.java +++ b/src/be/nikiroo/fanfix/supported/Epub.java @@ -34,11 +34,6 @@ class Epub extends InfoText { private URL fakeSource; private InputStream fakeIn; - @Override - public String getSourceName() { - return "epub"; - } - public File getSourceFileOriginal() { return super.getSourceFile(); } @@ -198,7 +193,7 @@ class Epub extends InfoText { meta = new MetaData(); meta.setLang("en"); meta.setTags(new ArrayList()); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUuid(url); meta.setUrl(url); meta.setTitle(title); diff --git a/src/be/nikiroo/fanfix/supported/Fanfiction.java b/src/be/nikiroo/fanfix/supported/Fanfiction.java index 9b749bc..7bdd4ff 100644 --- a/src/be/nikiroo/fanfix/supported/Fanfiction.java +++ b/src/be/nikiroo/fanfix/supported/Fanfiction.java @@ -32,11 +32,6 @@ class Fanfiction extends BasicSupport_Deprecated { return true; } - @Override - public String getSourceName() { - return "Fanfiction.net"; - } - @Override protected MetaData getMeta(URL source, InputStream in) throws IOException { MetaData meta = new MetaData(); @@ -45,9 +40,9 @@ class Fanfiction extends BasicSupport_Deprecated { meta.setAuthor(getAuthor(reset(in))); meta.setDate(getDate(reset(in))); meta.setTags(getTags(reset(in))); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(source.toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(source.toString()); meta.setLuid(""); meta.setLang("en"); // TODO! diff --git a/src/be/nikiroo/fanfix/supported/Fimfiction.java b/src/be/nikiroo/fanfix/supported/Fimfiction.java index 792f66b..e96ac4f 100644 --- a/src/be/nikiroo/fanfix/supported/Fimfiction.java +++ b/src/be/nikiroo/fanfix/supported/Fimfiction.java @@ -30,11 +30,6 @@ class Fimfiction extends BasicSupport_Deprecated { return true; } - @Override - public String getSourceName() { - return "FimFiction.net"; - } - @Override protected MetaData getMeta(URL source, InputStream in) throws IOException { MetaData meta = new MetaData(); @@ -43,9 +38,9 @@ class Fimfiction extends BasicSupport_Deprecated { meta.setAuthor(getAuthor(reset(in))); meta.setDate(getDate(reset(in))); meta.setTags(getTags(reset(in))); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(source.toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(source.toString()); meta.setLuid(""); meta.setLang("en"); diff --git a/src/be/nikiroo/fanfix/supported/FimfictionApi.java b/src/be/nikiroo/fanfix/supported/FimfictionApi.java index a99986f..887f5f9 100644 --- a/src/be/nikiroo/fanfix/supported/FimfictionApi.java +++ b/src/be/nikiroo/fanfix/supported/FimfictionApi.java @@ -84,11 +84,6 @@ class FimfictionApi extends BasicSupport { return true; } - @Override - public String getSourceName() { - return "FimFiction.net"; - } - /** * Extract the full JSON data we will later use to build the {@link Story}. * @@ -137,9 +132,9 @@ class FimfictionApi extends BasicSupport { meta.setAuthor(getKeyJson(json, 0, "type", "user", "name")); meta.setDate(getKeyJson(json, 0, "type", "story", "date_published")); meta.setTags(getTags()); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(getSource().toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(getSource().toString()); meta.setLuid(""); meta.setLang("en"); diff --git a/src/be/nikiroo/fanfix/supported/Html.java b/src/be/nikiroo/fanfix/supported/Html.java index 5fe2839..c27dd32 100644 --- a/src/be/nikiroo/fanfix/supported/Html.java +++ b/src/be/nikiroo/fanfix/supported/Html.java @@ -14,11 +14,6 @@ import be.nikiroo.fanfix.Instance; * @author niki */ class Html extends InfoText { - @Override - public String getSourceName() { - return "html"; - } - @Override protected boolean supports(URL url) { try { diff --git a/src/be/nikiroo/fanfix/supported/InfoText.java b/src/be/nikiroo/fanfix/supported/InfoText.java index 37f447a..42e2c13 100644 --- a/src/be/nikiroo/fanfix/supported/InfoText.java +++ b/src/be/nikiroo/fanfix/supported/InfoText.java @@ -16,11 +16,6 @@ import be.nikiroo.fanfix.data.MetaData; * @author niki */ class InfoText extends Text { - @Override - public String getSourceName() { - return "info-text"; - } - protected File getInfoFile() { return new File(assureNoTxt(getSourceFile()).getPath() + ".info"); } diff --git a/src/be/nikiroo/fanfix/supported/MangaFox.java b/src/be/nikiroo/fanfix/supported/MangaFox.java index bd5816a..5dee0d6 100644 --- a/src/be/nikiroo/fanfix/supported/MangaFox.java +++ b/src/be/nikiroo/fanfix/supported/MangaFox.java @@ -28,11 +28,6 @@ class MangaFox extends BasicSupport { return true; } - @Override - public String getSourceName() { - return "MangaFox.me"; - } - @Override protected MetaData getMeta() throws IOException { MetaData meta = new MetaData(); @@ -63,9 +58,9 @@ class MangaFox extends BasicSupport { meta.setDate(StringUtils.unhtml(table.get(0).text()).trim()); meta.setTags(explode(table.get(3).text())); } - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(getSource().toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(getSource().toString()); meta.setLuid(""); meta.setLang("en"); diff --git a/src/be/nikiroo/fanfix/supported/MangaLel.java b/src/be/nikiroo/fanfix/supported/MangaLel.java index 0351622..d42e743 100644 --- a/src/be/nikiroo/fanfix/supported/MangaLel.java +++ b/src/be/nikiroo/fanfix/supported/MangaLel.java @@ -26,11 +26,6 @@ class MangaLel extends BasicSupport { return true; } - @Override - public String getSourceName() { - return "MangaLel.com"; - } - @Override protected MetaData getMeta() throws IOException { MetaData meta = new MetaData(); @@ -41,9 +36,9 @@ class MangaLel extends BasicSupport { meta.setAuthor(authorDateTag[0]); meta.setDate(authorDateTag[1]); meta.setTags(explode(authorDateTag[2])); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(getSource().toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(getSource().toString()); meta.setLuid(""); meta.setLang("fr"); diff --git a/src/be/nikiroo/fanfix/supported/SupportType.java b/src/be/nikiroo/fanfix/supported/SupportType.java index 7ded392..37c03bf 100644 --- a/src/be/nikiroo/fanfix/supported/SupportType.java +++ b/src/be/nikiroo/fanfix/supported/SupportType.java @@ -35,8 +35,44 @@ public enum SupportType { HTML; /** - * A description of this support type (more information than the - * {@link BasicSupport#getSourceName()}). + * The name of this support type (a short version). + * + * @return the name + */ + public String getSourceName() { + switch (this) { + case CBZ: + return "cbz"; + case E621: + return "e621.net"; + case E_HENTAI: + return "e-hentai.org"; + case EPUB: + return "epub"; + case FANFICTION: + return "Fanfiction.net"; + case FIMFICTION: + return "FimFiction.net"; + case HTML: + return "html"; + case INFO_TEXT: + return "info-text"; + case MANGA_LEL: + return "MangaLel.com"; + case MANGAFOX: + return "MangaFox.me"; + case TEXT: + return "text"; + case YIFFSTAR: + return "YiffStar"; + } + + return ""; + } + + /** + * A description of this support type (more information than + * {@link SupportType#getSourceName()}). * * @return the description */ @@ -51,20 +87,6 @@ public enum SupportType { return desc; } - /** - * The name of this support type (a short version). - * - * @return the name - */ - public String getSourceName() { - BasicSupport support = BasicSupport.getSupport(this, null); - if (support != null) { - return support.getSourceName(); - } - - return null; - } - @Override public String toString() { return super.toString().toLowerCase(); diff --git a/src/be/nikiroo/fanfix/supported/Text.java b/src/be/nikiroo/fanfix/supported/Text.java index cba23bf..3518f20 100644 --- a/src/be/nikiroo/fanfix/supported/Text.java +++ b/src/be/nikiroo/fanfix/supported/Text.java @@ -67,11 +67,6 @@ class Text extends BasicSupport { return false; } - @Override - public String getSourceName() { - return "text"; - } - @Override protected Document loadDocument(URL source) throws IOException { try { @@ -92,7 +87,7 @@ class Text extends BasicSupport { meta.setAuthor(getAuthor()); meta.setDate(getDate()); meta.setTags(new ArrayList()); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(getSourceFile().toURI().toURL().toString()); meta.setPublisher(""); meta.setUuid(getSourceFile().toString()); diff --git a/src/be/nikiroo/fanfix/supported/YiffStar.java b/src/be/nikiroo/fanfix/supported/YiffStar.java index 92d44fe..a17253a 100644 --- a/src/be/nikiroo/fanfix/supported/YiffStar.java +++ b/src/be/nikiroo/fanfix/supported/YiffStar.java @@ -26,12 +26,6 @@ import be.nikiroo.utils.StringUtils; * @author niki */ class YiffStar extends BasicSupport_Deprecated { - - @Override - public String getSourceName() { - return "YiffStar"; - } - @Override protected MetaData getMeta(URL source, InputStream in) throws IOException { MetaData meta = new MetaData(); @@ -40,9 +34,9 @@ class YiffStar extends BasicSupport_Deprecated { meta.setAuthor(getAuthor(reset(in))); meta.setDate(""); meta.setTags(getTags(reset(in))); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(source.toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(source.toString()); meta.setLuid(""); meta.setLang("en"); -- 2.27.0