X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=supported%2FText.java;h=ff9d264f8494b9d68ddf73fc557acc539b59044b;hb=HEAD;hp=c54b6a5d44ce0a328d63451420c6a9c00a82bd3c;hpb=371a36bd5f5d0e46038491ecfdd18653fe4d6f61;p=nikiroo-utils.git diff --git a/supported/Text.java b/supported/Text.java deleted file mode 100644 index c54b6a5..0000000 --- a/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; - } -}