epubcheck icon indicating copy to clipboard operation
epubcheck copied to clipboard

Support all commandline flags in the public java epubcheck interface

Open Jbprod opened this issue 10 years ago • 5 comments

Hi all,

I'm a developer and I'm currently writing an application in Java which would allow to write and manage epub more easily. It is hosted at Github (name : Sopherim) and would be free and open source.

I wanted also to give the user the ability to validate epub. I've already used epubcheck in command line or with the java sources, but my need is particular : I wanted to know how to do to validate an unpacked (or expanded) folder in java.

I know how to do this in command line (mode exp), I know also how to validate an epub file in java, but I don't know how to validate an unpacked folder in java.

Do you know how to do ?

Thank you.

Jbprod avatar Mar 25 '14 09:03 Jbprod

Have a look at the wiki page https://github.com/IDPF/epubcheck/wiki/Library

There's described how you use the epubcheck public interface.

However, this interface doesn't support the expanded check option yet and I failed to implement this when developing pagina EPUB-Checker.

However, I just "implemented" my own method of checking unpacked epubs: I build the EPUB first before checking it with normal epubcheck interface as describes above.

This is part of my code with some extra checks and messages around which you won't need...

if(file.isDirectory()) {

    File expectedMimetype = new File(file.getPath() + File.separator + "mimetype");
    File expectedMetaInf = new File(file.getPath() + File.separator + "META-INF");

    if(expectedMimetype.exists() && expectedMimetype.isFile()
        && expectedMetaInf.exists() && expectedMetaInf.isDirectory()) {

        // create EPUB archive from source folder
        // second argument is "save" flag (true/false) but it isn't needed here...
        Archive epub = new Archive(file.getPath(), paginaEPUBChecker.modeExp_keepArchive);
        epub.createArchive();

        // validate with your own "validate()" implementation or the epubcheck public interface
        paginaEPUBChecker.validate();

    } else {

        mainGUI.setBorderStateError();
        mainGUI.txtarea_results.setText(__("This folder doesn't seem to contain any valid EPUB structure") + ": " + file.getName() + "/");
        mainGUI.txtarea_results.append("\n\n" + __("There should be at least a folder named 'META-INF' and the 'mimetype' file..."));
    }
}

However, we should try to support the commandline arguments and flags also in the java interface. I'm going to change the title of this issue...

tofi86 avatar Mar 26 '14 17:03 tofi86

Thank you. I agree with you. There should be a support for the commandline arguments and flags in the Java interface. It would be great.

I know how to validate a epub file with the public interface. But in my software, when I'm editing the epub, I store temporarly the unpacked folder in a temp directory. What I want to do is to validate this temporary folder without being obliged to package first the epub...

I hope it will be possible one day...

Jbprod avatar Mar 27 '14 11:03 Jbprod

I finally found how to do. Everything is in the class Checker.java. We have just to take some minutes to see how it works and to implement it ourself. But everything is in this class...

Jbprod avatar Mar 28 '14 15:03 Jbprod

Yes, sure, everything is in the Checker class. But there's no public interface for this class! E.g., there's no setter for the variable expanded which we would need when implementing the EpubCheck interface...

tofi86 avatar Mar 30 '14 22:03 tofi86

Yes, you're right, but defining this public interface is quite easy. We can define it ourselves

Jbprod avatar Mar 31 '14 14:03 Jbprod