Compare commits
No commits in common. "21f64b71479766b2f5661d9a4c74e3df72149a39" and "95d6df60ea5e38a6c877b3b96ae242f1e7c41b12" have entirely different histories.
21f64b7147
...
95d6df60ea
3 changed files with 291 additions and 352 deletions
28
pom.xml
28
pom.xml
|
@ -9,8 +9,9 @@
|
||||||
<relativePath/>
|
<relativePath/>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
<groupId>net.kemitix</groupId>
|
||||||
<artifactId>epub-creator</artifactId>
|
<artifactId>epub-creator</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.1.0</version>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:git@github.com:kemitix/epub-creator.git</connection>
|
<connection>scm:git:git@github.com:kemitix/epub-creator.git</connection>
|
||||||
|
@ -24,51 +25,40 @@
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
|
||||||
<tiles-maven-plugin.version>2.27</tiles-maven-plugin.version>
|
<tiles-maven-plugin.version>2.20</tiles-maven-plugin.version>
|
||||||
<kemitix-tiles.version>2.8.0</kemitix-tiles.version>
|
<kemitix-tiles.version>2.8.0</kemitix-tiles.version>
|
||||||
<assertj.version>3.22.0</assertj.version>
|
|
||||||
<lombok.version>1.18.22</lombok.version>
|
|
||||||
<commons-collections.version>3.2.2</commons-collections.version>
|
|
||||||
<commons-io.version>2.11.0</commons-io.version>
|
|
||||||
<htmlcleaner.version>2.26</htmlcleaner.version>
|
|
||||||
<junit.version>4.13.2</junit.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>${junit.version}</version>
|
<version>4.13.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sourceforge.htmlcleaner</groupId>
|
<groupId>net.sourceforge.htmlcleaner</groupId>
|
||||||
<artifactId>htmlcleaner</artifactId>
|
<artifactId>htmlcleaner</artifactId>
|
||||||
<version>${htmlcleaner.version}</version>
|
<version>2.24</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>${commons-io.version}</version>
|
<version>2.8.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-collections</groupId>
|
<groupId>commons-collections</groupId>
|
||||||
<artifactId>commons-collections</artifactId>
|
<artifactId>commons-collections</artifactId>
|
||||||
<version>${commons-collections.version}</version>
|
<version>3.2.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>${lombok.version}</version>
|
<version>1.18.18</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.assertj</groupId>
|
|
||||||
<artifactId>assertj-core</artifactId>
|
|
||||||
<version>${assertj.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -36,7 +36,6 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of the OpfCreator. This follows EPUB3 standards to
|
* Default implementation of the OpfCreator. This follows EPUB3 standards to
|
||||||
|
@ -122,18 +121,7 @@ public class OpfCreatorDefault implements OpfCreator {
|
||||||
addNodeData(metaNode, "dc:identifier", book.getId());
|
addNodeData(metaNode, "dc:identifier", book.getId());
|
||||||
addNodeData(metaNode, "dc:title", book.getTitle());
|
addNodeData(metaNode, "dc:title", book.getTitle());
|
||||||
addNodeData(metaNode, "dc:language", book.getLanguage());
|
addNodeData(metaNode, "dc:language", book.getLanguage());
|
||||||
Optional<MetadataItem> customModifiedValue = metadataItems.stream()
|
addNodeData(metaNode, "meta", new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'").format(new Date()));
|
||||||
.filter(MetadataItem::hasValue)
|
|
||||||
.filter(MetadataItem::hasProperty)
|
|
||||||
.filter(item -> item.getProperty().equals("dcterms:modified"))
|
|
||||||
.findFirst();
|
|
||||||
if (customModifiedValue.isPresent()) {
|
|
||||||
MetadataItem item = customModifiedValue.get();
|
|
||||||
addNodeData(metaNode, "meta", item.getValue());
|
|
||||||
metadataItems.remove(item);
|
|
||||||
} else {
|
|
||||||
addNodeData(metaNode, "meta", new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'").format(new Date()));
|
|
||||||
}
|
|
||||||
if (book.getAuthor() != null) {
|
if (book.getAuthor() != null) {
|
||||||
TagNode creatorNode = new TagNode("dc:creator");
|
TagNode creatorNode = new TagNode("dc:creator");
|
||||||
creatorNode.addChild(new ContentNode(book.getAuthor()));
|
creatorNode.addChild(new ContentNode(book.getAuthor()));
|
||||||
|
|
|
@ -2,86 +2,47 @@ package coza.opencollab.epub.creator;
|
||||||
|
|
||||||
import coza.opencollab.epub.creator.api.MetadataItem;
|
import coza.opencollab.epub.creator.api.MetadataItem;
|
||||||
import coza.opencollab.epub.creator.model.EpubBook;
|
import coza.opencollab.epub.creator.model.EpubBook;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import lombok.val;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.assertj.core.api.WithAssertions;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
import junit.framework.Assert;
|
||||||
import java.util.Scanner;
|
import org.apache.commons.io.IOUtils;
|
||||||
import java.util.zip.ZipFile;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @author OpenCollab
|
* @author OpenCollab
|
||||||
*/
|
*/
|
||||||
public class EpubCreatorTest implements WithAssertions {
|
public class EpubCreatorTest {
|
||||||
|
|
||||||
String author = "Samuel Holtzkampf";
|
|
||||||
String modified = "modified-date-and-time";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bookHasAuthor() {
|
public void testEpubCreate() {
|
||||||
//when
|
try (FileOutputStream file = new FileOutputStream(new File("test.epub"))) {
|
||||||
val book = createEpubBook();
|
EpubBook book = new EpubBook("en", "Samuel .-__Id1", "Samuel Test Book", "Samuel Holtzkampf");
|
||||||
//then
|
|
||||||
assertThat(book.getAuthor()).isEqualTo(author);
|
|
||||||
|
|
||||||
}
|
MetadataItem.Builder builder = MetadataItem.builder();
|
||||||
|
book.addMetadata(builder.name("dc:creator").value("Bob Smith"));
|
||||||
|
book.addMetadata(builder.name("meta")
|
||||||
|
.property("role").refines("#editor-id")
|
||||||
|
.value("Editor"));
|
||||||
|
|
||||||
@Test
|
book.addContent(this.getClass().getResourceAsStream("/epub30-overview.xhtml"),
|
||||||
public void hasSetModifiedValue() {
|
"application/xhtml+xml", "xhtml/epub30-overview.xhtml", true, true).setId("Overview");
|
||||||
//given
|
book.addContent(this.getClass().getResourceAsStream("/idpflogo_web_125.jpg"),
|
||||||
//TODO use a proper temp file
|
"image/jpeg", "img/idpflogo_web_125.jpg", false, false);
|
||||||
val file = new File("test.epub");
|
book.addContent(this.getClass().getResourceAsStream("/epub-spec.css"),
|
||||||
writeBookToFile(createEpubBook(), file);
|
"text/css", "css/epub-spec.css", false, false);
|
||||||
//when
|
book.addTextContent("TestHtml", "xhtml/samuelTest2.xhtml", "Samuel test one two four!!!!!\nTesting two").setToc(true);
|
||||||
String bookOpf = unzipFileEntry(file, "content/book.opf");
|
book.addTextContent("TestHtml", "xhtml/samuelTest.xhtml", "Samuel test one two three\nTesting two").setToc(true);
|
||||||
//then
|
book.addCoverImage(IOUtils.toByteArray(this.getClass().getResourceAsStream("/P1010832.jpg")),
|
||||||
assertThat(bookOpf).containsOnlyOnce("<meta property=\"dcterms:modified\">");
|
"image/jpeg", "images/P1010832.jpg");
|
||||||
assertThat(bookOpf).contains(String.format("<meta property=\"dcterms:modified\">%s</meta>", modified));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
private String unzipFileEntry(File file, String name) {
|
book.writeToStream(file);
|
||||||
val zipFile = new ZipFile(file);
|
// TODO : real tests to see if document correct, this is just to test that creation is succesfull
|
||||||
val entry = zipFile.getEntry(name);
|
Assert.assertEquals("test", "test");
|
||||||
val inputStream = zipFile.getInputStream(entry);
|
} catch (Exception ex) {
|
||||||
try (Scanner scanner = new Scanner(inputStream)) {
|
System.out.println(ex);
|
||||||
return scanner.useDelimiter("\\A").next();
|
Assert.assertEquals("test", "test1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
private void writeBookToFile(EpubBook book, File file) {
|
|
||||||
try (OutputStream outputStream = new FileOutputStream(file)) {
|
|
||||||
book.writeToStream(outputStream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
private EpubBook createEpubBook() {
|
|
||||||
EpubBook book = new EpubBook("en", "Samuel .-__Id1", "Samuel Test Book", author);
|
|
||||||
|
|
||||||
MetadataItem.Builder builder = MetadataItem.builder();
|
|
||||||
book.addMetadata(builder.name("dc:creator").value("Bob Smith"));
|
|
||||||
book.addMetadata(builder.name("meta")
|
|
||||||
.property("role").refines("#editor-id")
|
|
||||||
.value("Editor"));
|
|
||||||
book.addMetadata((builder.name("meta").property("dcterms:modified").value(modified)));
|
|
||||||
|
|
||||||
book.addContent(this.getClass().getResourceAsStream("/epub30-overview.xhtml"),
|
|
||||||
"application/xhtml+xml", "xhtml/epub30-overview.xhtml", true, true).setId("Overview");
|
|
||||||
book.addContent(this.getClass().getResourceAsStream("/idpflogo_web_125.jpg"),
|
|
||||||
"image/jpeg", "img/idpflogo_web_125.jpg", false, false);
|
|
||||||
book.addContent(this.getClass().getResourceAsStream("/epub-spec.css"),
|
|
||||||
"text/css", "css/epub-spec.css", false, false);
|
|
||||||
book.addTextContent("TestHtml", "xhtml/samuelTest2.xhtml", "Samuel test one two four!!!!!\nTesting two").setToc(true);
|
|
||||||
book.addTextContent("TestHtml", "xhtml/samuelTest.xhtml", "Samuel test one two three\nTesting two").setToc(true);
|
|
||||||
book.addCoverImage(IOUtils.toByteArray(this.getClass().getResourceAsStream("/P1010832.jpg")),
|
|
||||||
"image/jpeg", "images/P1010832.jpg");
|
|
||||||
return book;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue