tests: fix NPE, add BasicSupportUtilities tests
[nikiroo-utils.git] / src / be / nikiroo / fanfix / supported / Fanfiction.java
index b80156d471a818e02728ce92eff640ead174d210..0dcd7903e077d2bb6afa268247e04ea39a04722a 100644 (file)
@@ -5,6 +5,7 @@ import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
+import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -25,17 +26,12 @@ import be.nikiroo.utils.StringUtils;
  * 
  * @author niki
  */
-class Fanfiction extends BasicSupport {
+class Fanfiction extends BasicSupport_Deprecated {
        @Override
        protected boolean isHtml() {
                return true;
        }
 
-       @Override
-       public String getSourceName() {
-               return "Fanfiction.net";
-       }
-
        @Override
        protected MetaData getMeta(URL source, InputStream in) throws IOException {
                MetaData meta = new MetaData();
@@ -44,12 +40,12 @@ class Fanfiction extends BasicSupport {
                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");
+               meta.setLang("en"); // TODO!
                meta.setSubject(getSubject(reset(in)));
                meta.setType(getType().toString());
                meta.setImageDocument(false);
@@ -122,7 +118,7 @@ class Fanfiction extends BasicSupport {
                        }
                }
 
-               return null;
+               return "";
        }
 
        private String getAuthor(InputStream in) {
@@ -142,7 +138,7 @@ class Fanfiction extends BasicSupport {
                        }
                }
 
-               return fixAuthor(author);
+               return bsHelper.fixAuthor(author);
        }
 
        private String getDate(InputStream in) {
@@ -244,24 +240,8 @@ class Fanfiction extends BasicSupport {
                                                }
 
                                                try {
-                                                       final String chapName = name.trim();
-                                                       final URL chapURL = new URL(base + i + suffix);
-                                                       urls.add(new Entry<String, URL>() {
-                                                               @Override
-                                                               public URL setValue(URL value) {
-                                                                       return null;
-                                                               }
-
-                                                               @Override
-                                                               public URL getValue() {
-                                                                       return chapURL;
-                                                               }
-
-                                                               @Override
-                                                               public String getKey() {
-                                                                       return chapName;
-                                                               }
-                                                       });
+                                                       urls.add(new AbstractMap.SimpleEntry<String, URL>(
+                                                                       name.trim(), new URL(base + i + suffix)));
                                                } catch (MalformedURLException e) {
                                                        Instance.getTraceHandler()
                                                                        .error(new IOException(
@@ -324,10 +304,10 @@ class Fanfiction extends BasicSupport {
                                        int pos = line.indexOf("<hr");
                                        if (pos >= 0) {
                                                boolean chaptered = false;
-                                               for (String lang : Instance.getConfig()
-                                                               .getString(Config.CHAPTER).split(",")) {
+                                               for (String lang : Instance.getConfig().getList(
+                                                               Config.CONF_CHAPTER)) {
                                                        String chapterWord = Instance.getConfig()
-                                                                       .getStringX(Config.CHAPTER, lang);
+                                                                       .getStringX(Config.CONF_CHAPTER, lang);
                                                        int posChap = line.indexOf(chapterWord + " ");
                                                        if (posChap < pos) {
                                                                chaptered = true;