Example #1
0
  /**
   * Parse an AXML chunk.
   *
   * @param jhove2 JHOVE2 framework
   * @param source WAVE source unit
   * @param input WAVE source input
   * @return Number of bytes consumed
   * @throws JHOVE2Exception
   * @throws IOException
   * @throws EOFException
   */
  @Override
  public long parse(JHOVE2 jhove2, Source source, Input input)
      throws EOFException, IOException, JHOVE2Exception {
    long consumed = super.parse(jhove2, source, input);

    /* The chunk contents are in XML; invoke the XML module. */
    ByteStreamSource child =
        jhove2
            .getSourceFactory()
            .getByteStreamSource(jhove2, source, input.getPosition(), this.size, ".xml");
    I8R xml = this.xmlFormat.getIdentifier();
    FormatIdentification id = new FormatIdentification(xml, Confidence.PositiveGeneric);
    child.addPresumptiveFormat(id);
    jhove2.characterize(child, input);
    consumed += this.size;

    return consumed;
  }
Example #2
0
  /**
   * Parse a WAVE chunk.
   *
   * @param jhove2 JHOVE2 framework
   * @param source WAVE source unit
   * @param input WAVE source input
   * @return Number of bytes consumed
   * @throws EOFException If End-of-File is reached reading the source unit
   * @throws IOException If an I/O exception is raised reading the source unit
   * @throws JHOVE2Exception
   */
  @Override
  public long parse(JHOVE2 jhove2, Source source, Input input)
      throws EOFException, IOException, JHOVE2Exception {
    long consumed = super.parse(jhove2, source, input);
    long start = ((MeasurableSource) source).getStartingOffset();
    int numErrors = 0;

    /* Format category */
    this.formatCategory = input.readUnsignedShort();
    FormatCategory category = FormatCategory.getFormatCategory(this.formatCategory, jhove2);
    if (category != null) {
      this.formatCategory_d = category.getCategory();
    } else {
      numErrors++;
      this.isValid = Validity.False;
      Object[] args = new Object[] {input.getPosition() - 4L - start, this.formatCategory};
      this.invalidFormatCategoryMessage =
          new Message(
              Severity.ERROR,
              Context.OBJECT,
              "org.jhove2.module.format.wave.FormatChunk.invalidFormatCategory",
              args,
              jhove2.getConfigInfo());
    }
    consumed += 2;

    /* Number of channels. */
    this.numChannels = input.readUnsignedShort();
    consumed += 2;

    /* Sampling rate. */
    this.samplingRate = input.readUnsignedInt();
    consumed += 4;

    /* Average bytes per second. */
    this.avgBytesPerSec = input.readUnsignedInt();
    consumed += 4;

    /* Data block size. */
    this.dataBlockSize = input.readUnsignedShort();
    consumed += 2;

    this.bitsPerSample = input.readUnsignedShort();
    consumed += 2;

    if (this.formatCategory != WAVE_FORMAT_PCM) {
      this.extraSize = input.readUnsignedShort();
      consumed += 2;

      if (this.formatCategory == WAVE_FORMAT_MPEG) {
        this.mpeg = new MPEGFormatHeader();
        consumed += this.mpeg.parse(jhove2, source, input);
      }
    }

    return consumed;
  }
Example #3
0
 /**
  * Inspects candidate group to determine if it comprises instance of Format
  *
  * @param jhove2 framework configured with SourceFactory
  * @return FormatIdentification for this group if it comprises instance of a Format; otherwise
  *     returns null;
  * @throws JHOVE2Exception
  */
 protected ClumpSource recognizeGroupedSource(GlobPathMatchInfoGroup fileGroup, JHOVE2 jhove2)
     throws JHOVE2Exception {
   FormatIdentification fi = null;
   ClumpSource clumpSource = null;
   if (fileGroup.getMustHaveCount() >= this.minMustHavesToIdentify) {
     fi =
         new FormatIdentification(
             this.format, GLOB_PATH_CONFIDENCE, this.getReportableIdentifier());
     if (jhove2.getSourceFactory() == null) {
       throw new JHOVE2Exception("JHOVE2 SourceFactory is null");
     }
     clumpSource = jhove2.getSourceFactory().getClumpSource(jhove2);
     clumpSource = (ClumpSource) clumpSource.addPresumptiveFormat(fi);
     for (GlobPathMatchInfo sourceInfo : fileGroup.getSourceMatchInfoList()) {
       if ((sourceInfo.isMustHave() || sourceInfo.isMayHave())
           || (this.includeUnmatchedFromGroup)) {
         Source sourceInfoSource = sourceInfo.getSource();
         sourceInfoSource = clumpSource.addChildSource(sourceInfoSource);
         sourceInfo.setSource(sourceInfoSource);
       }
     }
   }
   return clumpSource;
 }
Example #4
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.jhove2.module.format.tiff.profile.TiffProfile#validateThisProfile()
   */
  @Override
  public void validateThisProfile(JHOVE2 jhove2, TiffIFD ifd) throws JHOVE2Exception {
    /* Check required tags. */
    super.validateThisProfile(jhove2, ifd);

    /* Check required values. */

    if (!isNewSubfileTypeValid(ifd, 0)) {
      this.invalidNewSubfileTypeMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFITProfile.InvalidNewSubfileTypeMessage",
              jhove2.getConfigInfo());
    }

    if (!isCompressionValid(ifd, 1)) {
      this.isValid = Validity.False;
      Object[] args = new Object[] {1};
      this.invalidCompressionValueMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFITProfile.InvalidCompressionValueMessage",
              args,
              jhove2.getConfigInfo());
    }

    if (!isPhotometricInterpretationValid(ifd, 0)) {
      this.isValid = Validity.False;
      this.invalidPhotometricInterpretationValueMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFProfile.InvalidPhotometricInterpretationValueMessage",
              jhove2.getConfigInfo());
    }

    if (!isSamplesPerPixelValid(ifd, 1)) {
      this.isValid = Validity.False;
      Object[] args = new Object[] {1};
      this.invalidSPPValueMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFITProfile.InvalidSPPValueMessage",
              args,
              jhove2.getConfigInfo());
    }

    if (!isResolutionUnitValid(ifd, new int[] {2, 3})) {
      this.isValid = Validity.False;
      this.invalidResolutionUnitValueMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFProfile.InvalidResolutionUnitValueMessage",
              jhove2.getConfigInfo());
    }

    int[] validValues;
    /* ImageColorIndicator=1, but only if ImageColorValue is defined */
    if ((ifd.getEntries().get(TiffIFD.IMAGECOLORVALUE)) != null) validValues = new int[] {1};
    else {
      /* ImageColorIndicator=0,1,2 */
      validValues = new int[] {0, 1, 2};
    }
    if (!isImageColorIndicatorValid(ifd, validValues)) {
      this.isValid = Validity.False;
      this.invalidImageColorIndicatorMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFITProfile.InvalidImageColorIndicatorMessage",
              jhove2.getConfigInfo());
    }

    /*
     * BackgroundColorIndicator=0,1, or 2; BackgroundColorIndicator=1, but
     * only if BackgroundColorValue is defined.
     */
    if ((ifd.getEntries().get(TiffIFD.BACKGROUNDCOLORVALUE)) != null) {
      validValues = new int[] {1};
    } else {
      validValues = new int[] {0, 1, 2};
    }
    if (!isBackgroundColorIndicatorValid(ifd, validValues)) {
      this.isValid = Validity.False;
      this.invalidBackgroundColorIndicatorMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFITProfile.InvalidBackgroundColorIndicatorMessage",
              jhove2.getConfigInfo());
    }

    /* Tags which must NOT be defined */
    IFDEntry entry = null;
    if ((entry = ifd.getEntries().get(TiffIFD.DOCUMENTNAME)) != null) {
      this.isValid = Validity.False;
      Object[] args = new Object[] {entry.getName()};
      this.tagShouldNotBePresentMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFProfile.tagShouldNotBePresentMessage",
              args,
              jhove2.getConfigInfo());
    }
    if ((entry = ifd.getEntries().get(TiffIFD.MODEL)) != null) {
      this.isValid = Validity.False;
      Object[] args = new Object[] {entry.getName()};
      this.tagShouldNotBePresentMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFProfile.tagShouldNotBePresentMessage",
              args,
              jhove2.getConfigInfo());
    }
    if ((entry = ifd.getEntries().get(TiffIFD.PAGENAME)) != null) {
      this.isValid = Validity.False;
      Object[] args = new Object[] {entry.getName()};
      this.tagShouldNotBePresentMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFProfile.tagShouldNotBePresentMessage",
              args,
              jhove2.getConfigInfo());
    }
    if ((entry = ifd.getEntries().get(TiffIFD.HOSTCOMPUTER)) != null) {
      this.isValid = Validity.False;
      Object[] args = new Object[] {entry.getName()};
      this.tagShouldNotBePresentMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFProfile.tagShouldNotBePresentMessage",
              args,
              jhove2.getConfigInfo());
    }

    if ((entry = ifd.getEntries().get(TiffIFD.SITE)) != null) {
      this.isValid = Validity.False;
      Object[] args = new Object[] {entry.getName()};
      this.tagShouldNotBePresentMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFProfile.tagShouldNotBePresentMessage",
              args,
              jhove2.getConfigInfo());
    }
    if ((entry = ifd.getEntries().get(TiffIFD.COLORSEQUENCE)) != null) {
      this.isValid = Validity.False;
      Object[] args = new Object[] {entry.getName()};
      this.tagShouldNotBePresentMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFProfile.tagShouldNotBePresentMessage",
              args,
              jhove2.getConfigInfo());
    }
    if ((entry = ifd.getEntries().get(TiffIFD.IT8HEADER)) != null) {
      this.isValid = Validity.False;
      Object[] args = new Object[] {entry.getName()};
      this.tagShouldNotBePresentMessage =
          new Message(
              Severity.WARNING,
              Context.OBJECT,
              "org.jhove2.module.format.tiff.profile.TIFFProfile.tagShouldNotBePresentMessage",
              args,
              jhove2.getConfigInfo());
    }
  }