select TIFF-hul (JHOVE API)

Chlara
2013-10-14
2014-03-03
  • Chlara

    Chlara - 2013-10-14

    Hi Gary,
    I use JHOVE as a library in my Java application. With your "JHOVE usage notes - Using the JHOVE API" it works, but now I want to select only the TIFF-hul module.
    What should I write instead of "Module module = null;"

    If it works then I will change to Version 1.11.

    Thank You
    Chlara


    My code:

        try {
            // Jhove direkt ansprechen
            JhoveBase je = new JhoveBase();
            String NAME = new String( "Jhove" );
            String RELEASE = new String( "1.5" );
            int[] DATE = new int[] { 2009, 12, 19 };
            String USAGE = new String( "no usage" );
            String RIGHTS = new String( "LGPL v2.1" );
            App app = new App( NAME, RELEASE, DATE, USAGE, RIGHTS );
            OutputHandler handler = je.getHandler( "XML" );
    
            Module module = null; // check all modules => null oder TIFF => ???
            String logLevel = null;
            je.setLogLevel( logLevel );
            String saxClass = null;
            String configFile = pathToJhoveConfig;
            je.init( configFile, saxClass );
    
            je.setEncoding( "utf-8" );
            je.setTempDirectory( pathToWorkDir + "/temp" );
            je.setBufferSize( 4096 );
            je.setChecksumFlag( false );
            je.setShowRawFlag( false );
            je.setSignatureFlag( false );
            try {
                File newReport = new File( pathToJhoveOutput,
                        valDatei.getName() + ".jhove-log.txt" );
                String outputFile = newReport.getAbsolutePath();
                String[] dirFileOrUri = { valDatei.getAbsolutePath() };
                je.dispatch( app, module, null, handler, outputFile,
                        dirFileOrUri );
                jhoveReport = newReport;
            } catch ( Exception e ) {
                e.printStackTrace();
            }
        } catch ( Exception e ) {
            e.printStackTrace();
        }
    
     
  • Gary McGath

    Gary McGath - 2013-10-14

    You should be able to do it in the configuration file, not the Java code.

    My payment-optional book, "Jhove Tips for Developers," can be helpful in figuring out setup issues. https://www.smashwords.com/books/view/270759

     
    • Chlara

      Chlara - 2014-02-26

      Hi Gary,

      With "JHOVE Tips for Developers" I can calling dispatch. But I need to get the error from an not well-formed TIFF. So change the configuration and using the dispatcher isn't the solution.

      The Tips for developers and the sourcecode tell me that process should been used.

      Now I have the problem, that the minimal example isn't sufficient for me. I receive a NullPointerException at the line "handler.setWriter( writer );". Whats wrong with my code?

      If it works then I will change to Version 1.11.

      Thank You
      Chlara

      My code:

          try {
              String NAME = new String( "Jhove" );
              String RELEASE = new String( "1.5" );
              int[] DATE = new int[] { 2009, 12, 19 };
              String USAGE = new String( "no usage" );
              String RIGHTS = new String( "LGPL v2.1" );
              App app = new App( NAME, RELEASE, DATE, USAGE, RIGHTS );
              JhoveBase je = new JhoveBase();
              OutputHandler handler = je.getHandler( "XML" );
      
              Module module = je.getModule( "TIFF" );
              String logLevel = null; 
              je.setLogLevel( logLevel );
              String saxClass = null;
              String configFile = pathToJhoveConfig;
              je.init( configFile, saxClass );
      
              je.setEncoding( "utf-8" );
              je.setTempDirectory( pathToWorkDir + "/temp" );
              je.setBufferSize( 4096 );
              je.setChecksumFlag( false );
              je.setShowRawFlag( false );
              je.setSignatureFlag( false );
              try {
                  File newReport = new File( pathToJhoveOutput,
                          valDatei.getName() + ".jhove-log.txt" );
                  newReport.getParentFile().mkdirs();
                  PrintWriter writer = null;
                  String dirFileOrUri = valDatei.getAbsolutePath();
                  try {
                      writer = new PrintWriter( newReport );
                      // Jhove Teil
                      handler.setWriter( writer );
                      handler.setBase( je );
                      module.init( "" );
                      module.setDefaultParams( new ArrayList<String>() );
                      je.process( app, module, handler, dirFileOrUri );
                  } catch ( FileNotFoundException e ) {
                      e.printStackTrace();
                  } finally {
                      if ( writer != null ) {
                          writer.close();
                      }
                  }
                  writer.close();
                  jhoveReport = newReport;
              } catch ( Exception e ) {
                  e.printStackTrace();
              }
          } catch ( Exception e ) {
              e.printStackTrace();
          }
      
       
  • Chlara

    Chlara - 2014-03-03

    Hi,

    For all developers who have the same problem… I have found the solution for validating via API a file format against a fix defined module.

    With the code below I can call the Jhove TIFF-module via API and I receive the error if the file isn’t a well-formed TIFF (instead of being told it’s a well-formed BYTESTREAM).

    It works with dispatch but you need some more module initialization like:
    Module module = new TiffModule();
    module.init( "" );
    module.setDefaultParams( new ArrayList<String>() );

    Chlara

        try {
            String NAME = new String( "Jhove" );
            String RELEASE = new String( "1.5" );
            int[] DATE = new int[] { 2009, 12, 19 };
            String USAGE = new String( "no usage" );
            String RIGHTS = new String( "LGPL v2.1" );
            App app = new App( NAME, RELEASE, DATE, USAGE, RIGHTS );
            JhoveBase je = new JhoveBase();
            OutputHandler handler = je.getHandler( "XML" );
    
            // check all modules => null oder new TiffModule ();
            Module module = new TiffModule();
            module.init( "" );
            module.setDefaultParams( new ArrayList<String>() );
    
            String logLevel = null; // null = SEVERE, WARNING, INFO, FINE, FINEST
            je.setLogLevel( logLevel );
            String saxClass = null;
            String configFile = pathToJhoveConfig;
            je.init( configFile, saxClass );
    
            je.setEncoding( "utf-8" );
            je.setTempDirectory( pathToWorkDir + "/jhove" );
            je.setBufferSize( 4096 );
            je.setChecksumFlag( false );
            je.setShowRawFlag( false );
            je.setSignatureFlag( false );
    
            try {
                File newReport = new File( pathToJhoveOutput,
                        valDatei.getName() + ".jhove-log.txt" );
                String outputFile = newReport.getAbsolutePath();
                String[] dirFileOrUri = { valDatei.getAbsolutePath() };
                je.dispatch( app, module, null, handler, outputFile,
                        dirFileOrUri );
                jhoveReport = newReport;
            } catch ( Exception e ) {
                e.printStackTrace();
            }
    
        } catch ( Exception e ) {
            e.printStackTrace();
        }
    
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks