Package edu.harvard.hul.ois.jhove

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


    _signature.add (sig);

    _bigEndian = false;
    // end of parsing prologue.
    if (! checkSignBytes(dstream,SIGNATURE)) {
      repInfo.setMessage(new ErrorMessage ("Bad PNG Header", 0));
      repInfo.setWellFormed (RepInfo.FALSE);
      return 0;
    }
    repInfo.setFormat("PNG");

    // If we got this far, take note that the signature is OK.
    repInfo.setSigMatch(_name);
    repInfo.setModule(this);
    // First chunk MUST be IHDR
    int declChunkLen = (int)(readUnsignedInt(dstream, PNG_ENDIANITY, this)
                 &0x7FFFFFFF);
    chcks.reset();

    int chunkSig = (int)(readUnsignedInt(dstream, PNG_ENDIANITY, this)&0x7FFFFFFF);
    chcks.update(int2byteArray(chunkSig));

    if (chunkSig != IHDR_HEAD_SIG ) {
      repInfo.setWellFormed(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("IHDR header not found where expected." ));
      return 0;
    }
    else {
      checkIHDR(dstream,repInfo,declChunkLen);

      if (somethingWrongP(repInfo))
        return 0;

      // not sure it's useful...
      expectingIHDR = RepInfo.FALSE;
    }

    // The IHDR is where it should be and it's fine, now let's
    // handle the other chunks.



    while (expectingIEND == RepInfo.TRUE) {
      declChunkLen = (int)(readUnsignedInt(dstream, PNG_ENDIANITY, this)
                 &0x7FFFFFFF);
      // Each chunk has its checsum;
      chcks.reset();

      chunkSig = (int)(readUnsignedInt(dstream, PNG_ENDIANITY, this)&0x7FFFFFFF);
      chcks.update(int2byteArray(chunkSig));

      switch (chunkSig) {

      case IHDR_HEAD_SIG:
        repInfo.setWellFormed(RepInfo.FALSE);
        repInfo.setMessage(new ErrorMessage("Duplicated IHDR chunk." ));
        break;

      case PLTE_HEAD_SIG:
        if (expectingPLTE == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Unexpected or duplicated PLTE chunk." ));

          break;
        }
        checkPLTE(dstream,repInfo,declChunkLen);
        expectingPLTE = RepInfo.FALSE;

        break;

      case IDAT_HEAD_SIG:
        if (expectingPLTE == RepInfo.TRUE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Expected PLTE chunk not found." ));

          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"IDAT");
        expectingIDAT = RepInfo.FALSE;
        break;

      case IEND_HEAD_SIG:
        if (expectingPLTE == RepInfo.TRUE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Expected PLTE chunk not found." ));

          break;
        }
        if (expectingIDAT == RepInfo.TRUE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("No IDAT chunk found." ));

          break;
        }
        checkChunk(dstream, repInfo, declChunkLen,"IEND");
        expectingIEND = RepInfo.FALSE;
        break;

      case cHRM_HEAD_SIG:
        if (expectingPLTE == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("cHRM chunk found after PLTE one." ));

          break;
        }
        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("cHRM chunk found after IDAT ones." ));


          break;
        }
        if (expecting_cHRM == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra cHRM chunk found." ));


          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"cHRM");
        expecting_cHRM = RepInfo.FALSE;

        break;

      case gAMA_HEAD_SIG:
        if (expectingPLTE == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("gAMA chunk found after PLTE one." ));

          break;
        }
        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("gAMA chunk found after IDAT ones." ));

          break;
        }
        if (expecting_gAMA == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra gAMA chunk found." ));

          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"gAMA");
        expecting_gAMA = RepInfo.FALSE;

        break;

      case iCCP_HEAD_SIG:

        if (expectingPLTE == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("iCCP chunk found after PLTE one." ));

          break;
        }
        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("iCCP chunk found after IDAT ones." ));

          break;
        }
        if (expecting_iCCP == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra iCCP chunk found." ));

          break;
        }
        if (expecting_sRGB == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("iCCP chunk with sRGB chunk found." ));

          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"iCCP");
        expecting_iCCP = RepInfo.FALSE;
        expecting_sRGB = RepInfo.FALSE;
        break;

      case sBIT_HEAD_SIG:
        if (expectingPLTE == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("sBIT chunk found after PLTE one." ));

          break;
        }
        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("sBIT chunk found after IDAT ones." ));

          break;
        }
        if (expecting_sBIT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra sBIT chunk found." ));

          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"sBIT");
        expecting_sBIT = RepInfo.FALSE;


        break;

      case sRGB_HEAD_SIG:
        if (expectingPLTE == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("sRGB chunk found after PLTE one." ));

          break;
        }
        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("sRGB chunk found after IDAT ones." ));

          break;
        }
        if (expecting_sRGB == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra sRGB chunk found." ));

          break;
        }
        if (expecting_iCCP == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("iCPP chunk after sRGB chunk found." ));

          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"sRGB");
        expecting_sRGB = RepInfo.FALSE;
        expecting_iCCP = RepInfo.FALSE;

        break;

      case tEXt_HEAD_SIG:

        checkChunk(dstream, repInfo, declChunkLen,"tEXT");
        break;

      case zTXt_HEAD_SIG:

        checkChunk(dstream, repInfo, declChunkLen,"zEXT");
        break;

      case iTXt_HEAD_SIG:

        checkChunk(dstream, repInfo, declChunkLen,"iEXT");
        break;

      case bKGD_HEAD_SIG:

        if (expectingPLTE == RepInfo.TRUE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("gAMA chunk found before PLTE one." ));


          break;
        }
        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("gAMA chunk found after IDAT ones." ));

          break;
        }
        if (expecting_gAMA == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra gAMA chunk found." ));

          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"bKGRD");
        expecting_gAMA = RepInfo.FALSE;
        break;

      case hIST_HEAD_SIG:

        if (expectingPLTE == RepInfo.TRUE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("hIST chunk found before PLTE one." ));

          break;
        }
        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("hIST chunk found after IDAT ones." ));

          break;
        }
        if (expecting_hIST == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra hIST chunk found." ));

          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"hIST");
        expecting_hIST = RepInfo.FALSE;
        break;

      case tRNS_HEAD_SIG:

        if (expectingPLTE == RepInfo.TRUE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("tRNS chunk found before PLTE one." ));

          break;
        }
        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("tRNS chunk found after IDAT ones." ));

          break;
        }
        if (expecting_tRNS == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra tRNS chunk found." ));

          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"tRNS");
        expecting_tRNS = RepInfo.FALSE;
        break;

      case pHYs_HEAD_SIG:

        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("pHYs chunk found after IDAT ones." ));

          break;
        }
        if (expecting_pHYs == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra pHYs chunk found." ));

          break;
        }

        checkChunk(dstream, repInfo, declChunkLen,"pHYs");
        expecting_pHYs = RepInfo.FALSE;
        break;

      case sPLT_HEAD_SIG:

        if (expectingIDAT == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("sPLT chunk found after IDAT ones." ));

          break;
        }
        checkChunk(dstream, repInfo, declChunkLen,"sPLT");

        break;

      case tIME_HEAD_SIG:
        if (expecting_tIME == RepInfo.FALSE) {
          repInfo.setWellFormed(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Extra tIME chunk found." ));

          break;
        }

        checktIME(dstream, repInfo, declChunkLen);
        expecting_tIME = RepInfo.FALSE;
        break;

      default:
        // Some strong choices. Reject undefined non ancillary chunks
        if (( chunkSig & ( PROP_ANCILLARY  ) ) == 0) {
          repInfo.setValid(RepInfo.FALSE);
          repInfo.setMessage(new ErrorMessage("Unknown non ancillary chunk found. Datastream not interpretable!" ));

          break;

        }

        sigName.delete(0, sigName.length());

        sigName.append((char)((chunkSig & 0x7F000000) >>> 24) );
        sigName.append((char)((chunkSig & 0x007F0000) >>> 16) );
        sigName.append((char)((chunkSig & 0x00007F00) >>> 8) );
        sigName.append((char)((chunkSig & 0x0000007F)) );
        // a private chunk, check the CRC
        checkChunk(dstream, repInfo, declChunkLen, sigName.toString());
        break;
      }


      if (somethingWrongP(repInfo))
        return 0;

    }


    // epilogue
    if (expectingPLTE == RepInfo.TRUE) {
      repInfo.setWellFormed(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("PLTE chunk not found (but was expected)." ));

    }


    return 0;
View Full Code Here


    int tmp = (int)(readUnsignedInt(inputStream, PNG_ENDIANITY, this)&0xFFFFFFFF);
    chcks.update(int2byteArray(tmp));

    if (tmp == 0) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Illegal 0 value for height." ));

    }

    tmp = (int)(readUnsignedInt(inputStream, PNG_ENDIANITY, this)&0xFFFFFFFF);
    chcks.update(int2byteArray(tmp));

    if (tmp == 0) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Illegal 0 value for width." ));

    }

    tmp = readUnsignedByte(inputStream, this);
    chcks.update((byte)tmp);

    int colorType = readUnsignedByte(inputStream, this);
    chcks.update((byte)colorType);

    switch (colorType) {
    case 0:
      if (tmp != 1 &&
        tmp != 2 &&
        tmp != 4 &&
        tmp != 8 &&
        tmp != 16) {
        repInfo.setValid(RepInfo.FALSE);
        repInfo.setMessage(new ErrorMessage("In IHDR, illegal value for bit depth for colour type " +

                          colorType + ": " +tmp ));

      }
      repInfo.setProfile("PNG GrayScale");

      expectingPLTE=RepInfo.FALSE;
    case 3:
      if (tmp != 1 &&
        tmp != 2 &&
        tmp != 4 &&
        tmp != 8 ) {
        repInfo.setValid(RepInfo.FALSE);
        repInfo.setMessage(new ErrorMessage("In IHDR, illegal value for bit depth for colour type " +
                          colorType + ": " +tmp ));

      }
      // We need to find a palette!
      expectingPLTE = RepInfo.TRUE;
      colorDepth = tmp;
      maxPaletteSize = 1 << tmp ;
      repInfo.setProfile("PNG Indexed");

      break;
    case 4:
      expectingPLTE=RepInfo.FALSE;
      if (tmp != 8 &&
        tmp != 16) {
        repInfo.setValid(RepInfo.FALSE);
        repInfo.setMessage(new ErrorMessage("In IHDR, valore illegale per la profondita` dei bit per il colour type " +
                          colorType + ": " +tmp ));

      }

      repInfo.setProfile("PNG GrayScale with Alpha");
      break;
    case 6:
      expectingPLTE=RepInfo.FALSE;
      expecting_tRNS=RepInfo.FALSE;
      if (tmp != 8 &&
        tmp != 16) {
        repInfo.setValid(RepInfo.FALSE);
        repInfo.setMessage(new ErrorMessage("In IHDR, valore illegale per la profondita` dei bit per il colour type " +
                          colorType + ": " +tmp ));

      }
      repInfo.setProfile("PNG Truecolor with Alpha");
      break;
    case 2:
      expectingPLTE=RepInfo.FALSE;
      expecting_tRNS=RepInfo.FALSE;
      if (tmp != 8 &&
        tmp != 16) {
        repInfo.setValid(RepInfo.FALSE);
        repInfo.setMessage(new ErrorMessage("In IHDR, valore illegale per la profondita` dei bit per il colour type " +
                          colorType + ": " +tmp ));

      }

      repInfo.setProfile("PNG Truecolor");
      break;
    default:
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("In IHDR, valore illegale per il colour type (" +
                        colorType +")"));

      break;
    }

    // Compression
    tmp = readUnsignedByte(inputStream, this);
    chcks.update((byte)tmp);

    if (tmp!=0) {
      repInfo.setMessage(new InfoMessage("Attenzione, tipo di compressine " +
                         tmp + " not conforme alla raccommandazione del W3C."));
    }


    // filtering
    tmp = readUnsignedByte(inputStream, this);
    chcks.update((byte)tmp);

    if (tmp!=0) {
      repInfo.setMessage(new InfoMessage("Attenzione, tipo di filtro " +
                         tmp + " no ancora standardizzato dal W3C."));
    }

    // interlace

    tmp = readUnsignedByte(inputStream, this);
    chcks.update((byte)tmp);

    if (tmp!=0 && tmp!=1) {
      repInfo.setMessage(new InfoMessage("Attenzione, tipo di interlacciamento " +
                         tmp + " no ancora standardizzato dal W3C."));
    }

    long crc32 = readUnsignedInt(inputStream, PNG_ENDIANITY, this);

    if (crc32 != chcks.getValue()) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Errore CRC nel chunk IHDR" ));
    }

    }
View Full Code Here

                 final int declChunkLen)
    throws IOException {

    if ((declChunkLen % 3) != 0) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Lunghezza PLTE non valida." ));
    }


    // Scan the palette
    paletteSize=0;

    for (int i = 0; i < declChunkLen; i++) {
      int tmp = readUnsignedByte(inputStream, this);
      chcks.update((byte)tmp);

      tmp = readUnsignedByte(inputStream, this);
      chcks.update((byte)tmp);

      tmp = readUnsignedByte(inputStream, this);
      chcks.update((byte)tmp);

      paletteSize++;

    }

    if (paletteSize > maxPaletteSize) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Too many palette items in PLTE chunk" ));


    }
    shortPalette = (paletteSize < maxPaletteSize);
    long crc32 = readUnsignedInt(inputStream, PNG_ENDIANITY, this);

    if (crc32 != chcks.getValue()) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("CRC Error in PLTE chunk" ));

    }
    }
View Full Code Here

    int month = readUnsignedByte(inputStream, this);
    chcks.update((byte)month);

    if (month < 1 || month > 12) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Illegal month value in tIME chunk"));

    }

    int day = readUnsignedByte(inputStream, this);
    chcks.update((byte)day);

    if (day < 1 || day > 31) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Illegal day value in tIME chunk"));

    }

    int hour = readUnsignedByte(inputStream, this);
    chcks.update((byte)hour);

    if (hour < 0 || hour > 23) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Illegal hour value in tIME chunk"));

    }

    int minute = readUnsignedByte(inputStream, this);
    chcks.update((byte)minute);

    if (minute < 0 || minute > 59) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Illegal minute value in tIME chunk"));

    }

    int second = readUnsignedByte(inputStream, this);
    chcks.update((byte)second);

    if (second < 0 || second > 60) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("Illegal second value in tIME chunk"));

    }

    long crc32 = readUnsignedInt(inputStream, PNG_ENDIANITY, this);

    if (crc32 != chcks.getValue()) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("CRC Error in tIME chunk" ));

    }

    // Some operations to deal with GregorianCalendar class, that
    // has 0 base  month numbering and doesn't like leap seconds
View Full Code Here

      declChunkLen--;

      if (c != 0) {
        // segnalare errore e scartare
        repInfo.setValid(RepInfo.FALSE);
        repInfo.setMessage(new ErrorMessage("Missing 0 byte after keyword"));

        checkChunk(inputStream, repInfo, declChunkLen, "tEXT");
        buf.append((char)c);

      }


      return;
    }

    String keyword = buf.toString();

    // so far we got a keyword and the null ( 0 ) separator, lets'
    // get the value, set a property and check that everything is
    // OK with the CRC.

    buf.delete(0, buf.length() );

    while (declChunkLen > 0) {
      c = readUnsignedByte(inputStream, this);
      chcks.update((byte)c);
      declChunkLen--;

    }

    String value = buf.toString();

    Property p = new Property(keyword,
                  PropertyType.STRING,
                  value);
    repInfo.setProperty(p);
    Booolean bol = (Booolean)keywordList.get(keyword);

    if (bol != null) {
      bol.setFlag(true);
    }

    long crc32 = readUnsignedInt(inputStream, PNG_ENDIANITY, this);

    if (crc32 != chcks.getValue()) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("CRC Error in tEXT chunk" ));

    }


    }
View Full Code Here

    }
    long crc32 = readUnsignedInt(inputStream, PNG_ENDIANITY, this);

    if (crc32 != chcks.getValue()) {
      repInfo.setValid(RepInfo.FALSE);
      repInfo.setMessage(new ErrorMessage("CRC Error in " + chunkSig +" chunk" ));

    }

    }
View Full Code Here

      ZipEntry mimeTypeZE = zipf.getEntry(MIMETYPE);

      if (mimeTypeZE == null) {
        repInfo.setValid(false);
        repInfo.setWellFormed(false);
        repInfo.setMessage(new ErrorMessage("Corrupted or invaild ODF Package: mimetype comonent is missing."));
        zipf.close();
        return 0;

      }

      ZipEntry manifestZE = zipf.getEntry(MANIFEST);
      if (manifestZE == null) {
        repInfo.setValid(false);
        repInfo.setWellFormed(false);
        repInfo.setMessage(new ErrorMessage("Corrupted or invaild ODF Package: manifest is missing."));
        zipf.close();
        return 0;

      }

      if (! setProfileMime(repInfo, zipf, mimeTypeZE)) {
        repInfo.setValid(false);
        repInfo.setWellFormed(true);
        repInfo.setMessage(new ErrorMessage("Invalid ODF Package, unexpected type: " + repInfo.getMimeType()));
        zipf.close();
        return 0;

      }
      repInfo.setSigMatch(_name);

      // Process Manifest
      String manifestFileName = dumpPart(manifestZE, zipf);
      JingDriver jd = new JingDriver();

      ByteArrayOutputStream errorStream = new ByteArrayOutputStream(1024);

      if (! jd.doValidation(getResource(SCHEMA_MANIFEST),
                  manifestFileName,
                  errorStream) ) {
        StringBuffer buf = new StringBuffer("Invalid ODF Package, manifest failed Relaxed NG validation: " );
        buf.append(errorStream.toString());
        repInfo.setValid(false);
        repInfo.setWellFormed(false);
        repInfo.setMessage(new ErrorMessage(buf.toString()));
      }

      XMLReader parser = getXmlParser();
      List elementList = new ArrayList();
      Booolean isEncrypted = new Booolean(false,"");
      ManifestHandler manifestHandler = new ManifestHandler(elementList,
                                  isEncrypted);

      parser.setContentHandler (manifestHandler);

      /*
       * Attempt to set schema awareness to avoid validation
       * errors.
       */
      try {
        parser.setFeature("http://xml.org/sax/features/validation",
                  false);
        parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
                  true);
        parser.setProperty ("http://java.sun.com/xml/jaxp/" +
                  "properties/schemaLanguage",
                  "http://www.w3.org/2001/XMLSchema");
      }
      catch (SAXException e)
      {}

      try {
        parser.parse (manifestFileName);

      } catch (SAXException excptn) {
        repInfo.setValid(false);
        repInfo.setWellFormed(false);
        repInfo.setMessage(new ErrorMessage("Mmalformed manifest : " +
                          excptn.getMessage()));
        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});

              } catch (Exception excptn) {
                StringBuffer xxx = new StringBuffer("File ");
                xxx.append(mnfe.fullPath);
                xxx.append("analysis failed. Cause: ");
                xxx.append(excptn.getMessage());
                repInfo.setMessage(new ErrorMessage(xxx.toString()));
              }


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

                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();) {
                current.addContainedRepInfo((RepInfo)iter2.next());
              }

            }



          } // End "good for processing"

        }

      } // end of the loop on the manifest.


    } catch (ZipException excptn) {
      repInfo.setValid(false);
      repInfo.setWellFormed(false);
      repInfo.setMessage(new ErrorMessage("Invalid or corrupted ODF Package: " +
                        excptn.getMessage()));
    } catch (IOException excptn) {
      repInfo.setValid(false);
      repInfo.setWellFormed(false);
      repInfo.setMessage(new ErrorMessage("Error during ODF analysis: " +
                        excptn.getMessage()));
    } catch (IllegalStateException excptn) {
      repInfo.setValid(false);
      repInfo.setWellFormed(false);
      repInfo.setMessage(new ErrorMessage("Unexpected end of stream: " +
                        excptn.getMessage()));

    }
    catch (Throwable excptn) {
      // TODO remove after debugging
View Full Code Here

TOP

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

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.