Package org.idpf.epub.testsuite

Source Code of org.idpf.epub.testsuite.ZipBuilder

package org.idpf.epub.testsuite;

import java.io.File;
import java.security.InvalidParameterException;

import com.adobe.epubcheck.api.EpubCheck;
import com.adobe.epubcheck.api.Report;
import com.adobe.epubcheck.util.Archive;
import com.adobe.epubcheck.util.DefaultReportImpl;
import com.adobe.epubcheck.util.Messages;

public class ZipBuilder extends Builder {
   
  public ZipBuilder(String[] args) throws Exception {
    super(args);
  }
 
  /**
   * Iterates over all expanded epub dirs under parent, validates
   * and if valid moves a zip ocf to the build dir.
   */
  @Override
   boolean run(File parent) {
    if(!parent.exists() || !parent.isDirectory())
      throw new InvalidParameterException(parent.getAbsolutePath());
       
    boolean hadError = false;
    for(File epubDir : parent.listFiles(dirFilter)) {
      Archive epub = new Archive(epubDir.getAbsolutePath(), false);
      epub.createArchive();
      Report report = new DefaultReportImpl(epub.getEpubName());
      EpubCheck check = new EpubCheck(epub.getEpubFile(), report);
      if (check.validate()) {
        System.out.println(Messages.NO_ERRORS__OR_WARNINGS);
        String name = epub.getEpubName();
        name = name.replace(".epub", "-"+now+".epub");
        epub.getEpubFile().renameTo(new File(buildDir,name));
      } else {
        hadError = true;
        System.err.println(Messages.THERE_WERE_ERRORS);
      }
    }
    return hadError;
  }
     
  public static void main(String[] args) throws Exception {   
    ZipBuilder zb = new ZipBuilder(args);
    zb.run(new File(zb.contentDir, "30"));
  }
 
}
TOP

Related Classes of org.idpf.epub.testsuite.ZipBuilder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.