separate support name and BasicSupport
authorNiki Roo <niki@nikiroo.be>
Tue, 9 Apr 2019 15:37:33 +0000 (17:37 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 9 Apr 2019 15:37:33 +0000 (17:37 +0200)
15 files changed:
src/be/nikiroo/fanfix/supported/BasicSupport.java
src/be/nikiroo/fanfix/supported/Cbz.java
src/be/nikiroo/fanfix/supported/E621.java
src/be/nikiroo/fanfix/supported/EHentai.java
src/be/nikiroo/fanfix/supported/Epub.java
src/be/nikiroo/fanfix/supported/Fanfiction.java
src/be/nikiroo/fanfix/supported/Fimfiction.java
src/be/nikiroo/fanfix/supported/FimfictionApi.java
src/be/nikiroo/fanfix/supported/Html.java
src/be/nikiroo/fanfix/supported/InfoText.java
src/be/nikiroo/fanfix/supported/MangaFox.java
src/be/nikiroo/fanfix/supported/MangaLel.java
src/be/nikiroo/fanfix/supported/SupportType.java
src/be/nikiroo/fanfix/supported/Text.java
src/be/nikiroo/fanfix/supported/YiffStar.java

index 4337626c7fe60d96914eb9658df2b827823de539..0b0e66c401cff6532efe281c79c1aed7f385f4ce 100644 (file)
@@ -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
         */
index 062adf0fac71550a8946257f9123e2d178ba7d98..e1a766e32defd0a1945e3aeba53c0622b7e487a2 100644 (file)
@@ -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 "";
index 36b9dad3c9bf3520053e938539a9db149e134695..dfa9e5ed6a60e4694fc8494dcf196b4328259ee6 100644 (file)
@@ -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");
index 9ed4e89e60996c6683876e543803ca55581117ad..67585cd477f90a257acd94c9d28c67bac07575f7 100644 (file)
@@ -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)));
index e5261d36b7a9e291ebfd16b303f22cf51d9b35db..c71ba1785ea9db20e6d10bc5b5a72f6612057d53 100644 (file)
@@ -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<String>());
-                               meta.setSource(getSourceName());
+                               meta.setSource(getType().getSourceName());
                                meta.setUuid(url);
                                meta.setUrl(url);
                                meta.setTitle(title);
index 9b749bc6753e1efc92c2ffb48d1d6a83f1981b1e..7bdd4ffb9ca5c74f6548069328fae900be05b2e0 100644 (file)
@@ -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!
index 792f66baf11e1423287d4138b07c8f2fca95ef51..e96ac4f5766eb601886e3b6574c27044fb33b81a 100644 (file)
@@ -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");
index a99986f27e1f4e50aa88b1b0de27cbd9bd833cc8..887f5f9c121397a4b8e90d7023c8d1ffac073f9b 100644 (file)
@@ -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");
index 5fe28397e66936698a73dec7c64787bc08a43730..c27dd32f181651186446bbe597c09b6f6b7d8c5b 100644 (file)
@@ -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 {
index 37f447aeb721a970fe14e6933a73dd396b1823d4..42e2c13b6f75a1e32afa10f560361c1670ea9572 100644 (file)
@@ -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");
        }
index bd5816a63641c57e0fdb6ba7f7aa0f2e86e652bb..5dee0d6a9f95cd2bf4e420dbf9cec38bca3322fa 100644 (file)
@@ -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");
index 0351622e8ef66b66d6563c6a0920e3f4f8a8edb2..d42e74318ddaa4b75f16d34a6f5f424735a12f4c 100644 (file)
@@ -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");
index 7ded3926625ccf1382989a627b39734cfa8fda9e..37c03bffbd3f8b15c2ba837583185187b09f923e 100644 (file)
@@ -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();
index cba23bf8c2f1815d2eddba3ff611ed1951b9e4b6..3518f20f6fce30b9c3751eaaf867c60568919d07 100644 (file)
@@ -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<String>());
-               meta.setSource(getSourceName());
+               meta.setSource(getType().getSourceName());
                meta.setUrl(getSourceFile().toURI().toURL().toString());
                meta.setPublisher("");
                meta.setUuid(getSourceFile().toString());
index 92d44fe9beaa9f997c6d1375af2f4c332b0ee496..a17253a5762b4199a0f2997361da63f92dd009f1 100644 (file)
@@ -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");