meta.setTitle(getTitle());
meta.setAuthor(getAuthor());
- meta.setDate(getDate());
+ meta.setDate(bsHelper.formatDate(getDate()));
meta.setTags(new ArrayList<String>());
meta.setSource(getType().getSourceName());
meta.setUrl(getSourceFile().toURI().toURL().toString());
meta.setType(getType().toString());
meta.setImageDocument(false);
meta.setCover(getCover(getSourceFile()));
-
+
return meta;
}
private String getLang() {
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
scan.next(); // Title
}
private String getTitle() {
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
return scan.next();
}
private String getAuthor() {
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
scan.next();
}
private String getDate() {
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
scan.next();
return content;
}
- private Image getCover(File sourceFile) {
+ protected Image getCover(File sourceFile) {
String path = sourceFile.getName();
for (String ext : new String[] { ".txt", ".text", ".story" }) {
protected List<Entry<String, URL>> getChapters(Progress pg)
throws IOException {
List<Entry<String, URL>> chaps = new ArrayList<Entry<String, URL>>();
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
- boolean prevLineEmpty = false;
+ String line = "first is not empty";
while (scan.hasNext()) {
- String line = scan.next();
+ boolean prevLineEmpty = line.trim().isEmpty();
+ line = scan.next();
if (prevLineEmpty && detectChapter(line, chaps.size() + 1) != null) {
String chapName = Integer.toString(chaps.size() + 1);
int pos = line.indexOf(':');
chapName, //
getSourceFile().toURI().toURL()));
}
-
- prevLineEmpty = line.trim().isEmpty();
}
-
+
return chaps;
}
protected String getChapterContent(URL source, int number, Progress pg)
throws IOException {
StringBuilder builder = new StringBuilder();
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
- boolean inChap = false;
+ scan.next(); // title
+ scan.next(); // author
+ scan.next(); // date or empty
+ Boolean inChap = null;
+ String line = "";
while (scan.hasNext()) {
- String line = scan.next();
- if (!inChap && detectChapter(line, number) != null) {
+ if (number == 0 && !line.trim().isEmpty()) {
+ // We found pre-chapter content, we are checking for
+ // Chapter 0 (fake chapter) --> keep the content
+ if (inChap == null)
+ inChap = true;
+ }
+ line = scan.next();
+ if ((inChap == null || !inChap) && detectChapter(line, number) != null) {
inChap = true;
} else if (detectChapter(line, number + 1) != null) {
break;
- } else if (inChap) {
+ } else if (inChap != null && inChap) {
builder.append(line);
builder.append("\n");
}
}
/**
- * Remove the ".txt" extension if it is present.
+ * Remove the ".txt" (or ".text") extension if it is present.
*
* @param file
* the file to process
* was present
*/
protected File assureNoTxt(File file) {
- if (file.getName().endsWith(".txt")) {
- file = new File(file.getPath().substring(0,
- file.getPath().length() - 4));
+ for (String ext : new String[] { ".txt", ".text" }) {
+ if (file.getName().endsWith(ext)) {
+ file = new File(file.getPath().substring(0,
+ file.getPath().length() - ext.length()));
+ }
}
return file;