X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FText.java;h=e082a737f2a7be9c11b9fc133bea0c96f108ae55;hb=95c926ea1d5b7c75d5bbc81c50d80f5509d28a4d;hp=c54b6a5d44ce0a328d63451420c6a9c00a82bd3c;hpb=e4e740f55b13b48f849e44c8f9a7ef5b746835c1;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/Text.java b/src/be/nikiroo/fanfix/supported/Text.java deleted file mode 100644 index c54b6a5..0000000 --- a/src/be/nikiroo/fanfix/supported/Text.java +++ /dev/null @@ -1,379 +0,0 @@ -package be.nikiroo.fanfix.supported; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; -import java.util.Scanner; - -import org.jsoup.nodes.Document; - -import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.bundles.Config; -import be.nikiroo.fanfix.data.Chapter; -import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.data.Paragraph; -import be.nikiroo.utils.Image; -import be.nikiroo.utils.ImageUtils; -import be.nikiroo.utils.Progress; -import be.nikiroo.utils.streams.MarkableFileInputStream; - -/** - * Support class for local stories encoded in textual format, with a few rules: - *
- * It must also be a file, not another kind of URL. - * - * @param url - * the {@link URL} to check - * @param info - * TRUE to require the info file, FALSE to forbid the info file - * - * @return TRUE if it is supported - */ - protected boolean supports(URL url, boolean info) { - if (!"file".equals(url.getProtocol())) { - return false; - } - - boolean infoPresent = false; - File file; - try { - file = new File(url.toURI()); - file = assureNoTxt(file); - file = new File(file.getPath() + ".info"); - } catch (URISyntaxException e) { - Instance.getInstance().getTraceHandler().error(e); - file = null; - } - - infoPresent = (file != null && file.exists()); - - return infoPresent == info; - } - - /** - * Remove the ".txt" extension if it is present. - * - * @param file - * the file to process - * - * @return the same file or a copy of it without the ".txt" extension if it - * was present - */ - protected File assureNoTxt(File file) { - if (file.getName().endsWith(".txt")) { - file = new File(file.getPath().substring(0, - file.getPath().length() - 4)); - } - - return file; - } - - /** - * Check if the given line looks like the given starting chapter in a - * supported language, and return the language if it does (or NULL if not). - * - * @param line - * the line to check - * @param number - * the specific chapter number to check for - * - * @return the language or NULL - */ - static private String detectChapter(String line, int number) { - line = line.toUpperCase(); - for (String lang : Instance.getInstance().getConfig().getList(Config.CONF_CHAPTER)) { - String chapter = Instance.getInstance().getConfig().getStringX(Config.CONF_CHAPTER, lang); - if (chapter != null && !chapter.isEmpty()) { - chapter = chapter.toUpperCase() + " "; - if (line.startsWith(chapter)) { - // We want "[CHAPTER] [number]: [name]", with ": [name]" - // optional - String test = line.substring(chapter.length()).trim(); - - String possibleNum = test.trim(); - if (possibleNum.indexOf(':') > 0) { - possibleNum = possibleNum.substring(0, - possibleNum.indexOf(':')).trim(); - } - - if (test.startsWith(Integer.toString(number))) { - test = test - .substring(Integer.toString(number).length()) - .trim(); - if (test.isEmpty() || test.startsWith(":")) { - return lang; - } - } - } - } - } - - return null; - } -}