Package edu.harvard.hul.ois.jhove

Examples of edu.harvard.hul.ois.jhove.JhoveBase


    try {
      //Initialize Jhove 
      File config = new File(Fits.FITS_XML+"jhove"+File.separator+"jhove.conf");
      //= new File((this.getClass().getResource("jhove.conf")).toURI());
      jhoveConf = config.getPath();
          jhove = new JhoveBase ();
          jhove.init (jhoveConf, "org.apache.xerces.parsers.SAXParser");
          jhove.setChecksumFlag(false)
        jhove.setSignatureFlag(false);
        jhove.setShowRawFlag(false);
          xh = new XmlHandler();
View Full Code Here


        zipf.close();
        return 0;

      }
      // Process components
      JhoveBase jhoveBase;
      try {

        jhoveBase = new JhoveBase();
        jhoveBase.init(_je.getConfigFile(),
                 _je.getSaxClass());

      } catch (JhoveException excptn) {

        repInfo.setValid(false);
        repInfo.setWellFormed(false);
        repInfo.setMessage(new ErrorMessage("Can't instance engine to analyze package parts. Cause : " +
                          excptn.getMessage()));
        zipf.close();
        return 0;
      }

      for (Iterator iter = elementList.iterator(); iter.hasNext();) {
        ManifestEntry mnfe = (ManifestEntry) iter.next();

        /*
         * If the size field is set then the data is
         * encrypted, therefore we can't process it. If the
         * type equals application/binary (not a IANA
         * registered one!) then the data is skipped as
         * application specific.
         */
        if (mnfe.size != 0) {
          StringBuffer tmp = new StringBuffer("Warning, part ");
          tmp.append(mnfe.fullPath);
          tmp.append(" is encrypted, validation skipped.");
          repInfo.setMessage(new InfoMessage(tmp.toString()));
        }
        else if (mimeTypeMap.get(mnfe.mediaType) != null &&
             ! mnfe.fullPath.equals(SKIP_ROOT)) {
          String subDocName;
          int idxof = mnfe.fullPath.indexOf("/");
          if (idxof<1) {

            subDocName= mnfe.fullPath.substring(0, idxof);

          }
          else {

            subDocName = mnfe.fullPath;

          }

          RepInfo subDoc = new RepInfo(subDocName);
          subDoc.setModule(this);
          subDoc.setFormat("ODF");
          subDoc.setProfile((String)mimeTypeMap.get(mnfe.mediaType));
          subDoc.setMimeType(mnfe.mediaType);
          subDoc.setValid(true);
          subDoc.setWellFormed(true);
          subDoc.setConsistent(true);
          repInfo.putEmbeddedRepInfo(subDocName, subDoc);
        }
        else if ( mnfe.mediaType.equals("") ||
              mnfe.mediaType.equals(SKIP_TYPE) ||
              mnfe.mediaType.startsWith(SKIP_APP)) {

        }
        else {
          ZipEntry part = zipf.getEntry(mnfe.fullPath);
          if (part==null) {
            // Manifest holds information of "virtual"
            // file entries, like Configurations2 (a directory)
            break;
          }

          // good for processing
          if (! part.isDirectory() &&
            part.getSize() > 0) {
            String partFileName = dumpPart(part, zipf);

            if (mnfe.mediaType.equals(XRNG_TYPE)) {
              if (! jd.doValidation(getResource(SCHEMA_OPENDOCUMENT),
                          partFileName,
                          errorStream)) {

                NullHandler nullHandler = new NullHandler();

                try {
                  jhoveBase.dispatch(_app,
                             null,
                             null,
                             nullHandler,
                             null,
                             new String[] {partFileName});

                  String partDocName;
                  int idxofp = mnfe.fullPath.indexOf("/");
                  if (idxofp<1) {

                    partDocName = mnfe.fullPath;

                  }
                  else {

                    partDocName= mnfe.fullPath.substring(0, idxofp-1);

                  }

                  RepInfo current = repInfo.getEmbeddedRepInfo(partDocName);
                  if (current==null) {
                    current=repInfo;
                  }


                  for (Iterator iter2 = nullHandler.getRepInfos(); iter2.hasNext();) {
                    if ( ((RepInfo)iter2.next()).getWellFormed() != RepInfo.TRUE) {
                      repInfo.setValid(false);
                    }
                  }

                  if (repInfo.getValid() == RepInfo.TRUE && ! alreadyNonPreservable) {
                    alreadyNonPreservable=true;
                    repInfo.setProfile((String)mimeTypeMap.get(repInfo.getMimeType()));
                  }
                  else {
                    StringBuffer buf = new StringBuffer("Invalid ODF Package, component ");
                    buf.append(mnfe.fullPath);
                    buf.append(" failed both Relaxed NG and normal XML validation therefore" );
                    buf.append(" is not well formed.");
                    repInfo.setValid(false);
                    repInfo.setMessage(new ErrorMessage(buf.toString()));
                  }



                } catch (Exception excptn) {
                  StringBuffer buf = new StringBuffer("Invalid ODF Package, component ");
                  buf.append(mnfe.fullPath);
                  buf.append(" failed both Relaxed NG and normal XML validation " );
                  buf.append(" due this error: ");
                  buf.append(excptn.getMessage());
                  repInfo.setValid(false);
                  repInfo.setMessage(new ErrorMessage(buf.toString()));
                }
              }
              if (mnfe.fullPath.equals(META_FILE)) {
                MetaHandler metaHandler = new MetaHandler(repInfo);

                parser.setContentHandler (metaHandler);

                try {
                  parser.parse (partFileName);

                } catch (SAXException excptn) {
                  repInfo.setValid(false);
                  repInfo.setMessage(new ErrorMessage("malformed meta.xml: " +
                                    excptn.getMessage()));
                }

              }
            }
            else if (mnfe.mediaType.startsWith(IMG_TYPE)) {
              // For the files in the Picture directory
              NullHandler nullHandler = new NullHandler();

              try {
                jhoveBase.dispatch(_app,
                           null,
                           null,
                           nullHandler,
                           null,
                           new String[] {partFileName});
View Full Code Here

       
            App app = new App("", "", myDate, "", "");
            String configFile = loadConfigFile();
            String saxClass = JhoveBase.getSaxClassFromProperties();
           
            JhoveBase jhove = new JhoveBase();
            jhove.setLogLevel("SEVERE");

            jhove.init(configFile, saxClass);
            jhove.setEncoding("utf-8");
            jhove.setTempDirectory(OS.getTmpPath());
           

            // load all module
            Module module = null;

            XmlHandler aboutHandler = new XmlHandler();
            OutputStream out = newOutputStream(new StringBuffer());
            aboutHandler.setWriter(new PrintWriter(out));
            String s = new File(filePathName).toURI().toString();
            String[] dirFileOrUri = new String[] { s };

            // execute jhove
            jhove.dispatch(app, module, aboutHandler, aboutHandler, outputFile,
                    dirFileOrUri);
        } catch (Exception e) {
            log.error("could not execute jhove: "+e.getMessage(),e);
        }
    }
View Full Code Here

     *         identification
     */
    private List<URI> identifyOneBinary(final File temporary) {
        try {
            /* And use the JHOVE API to identify it: */
            JhoveBase base = new JhoveBase();
            base.setEncoding(ENCODING);
            Calendar calendar = Calendar.getInstance();
            int[] date = new int[] { calendar.get(Calendar.YEAR),
                    calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH) };
            App app = new App(PLANETS, PLANETS, date, PLANETS, PLANETS);
            base.init(config() + CONFIG_FILE, null);
            /* For JHOVE's output, we create another temporary file: */
            File output = File.createTempFile(OUTPUT, null);
            output.deleteOnExit();
            base.dispatch(app, null, null, new TextHandler(), output
                    .getAbsolutePath(), new String[] { temporary
                    .getAbsolutePath() });
            /* And finally we create our result object with the PRONOM ID: */
            return result(base);
        } catch (JhoveException e) {
View Full Code Here

TOP

Related Classes of edu.harvard.hul.ois.jhove.JhoveBase

Copyright © 2018 www.massapicom. 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.