createResult(FAILURE, "Content properties are not set but the document type demands content!"));
}
}
// get the content stream
ContentStream contentStream = doc.getContentStream();
if (contentStream == null) {
if (hasContentProperties && doc.getContentStreamLength() > 0) {
addResult(results,
createResult(FAILURE, "Content properties have values but the document has no content!"));
}
if (type.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
addResult(results,
createResult(FAILURE, "The document type demands content but the document has no content!"));
}
return;
}
if (type.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
addResult(results, createResult(FAILURE, "Document type doesn't allow content but document has content!"));
}
// file name check
f = createResult(FAILURE, "Content file names don't match!");
addResult(results, assertEquals(doc.getContentStreamFileName(), contentStream.getFileName(), null, f));
if (doc.getContentStreamLength() > -1 && contentStream.getLength() > -1) {
f = createResult(FAILURE, "Content lengths don't match!");
addResult(results, assertEquals(doc.getContentStreamLength(), contentStream.getLength(), null, f));
}
// MIME type check
String docMimeType = doc.getContentStreamMimeType();
if (docMimeType != null) {
int x = docMimeType.indexOf(';');
if (x > -1) {
docMimeType = docMimeType.substring(0, x);
}
docMimeType = docMimeType.trim();
}
String contentMimeType = contentStream.getMimeType();
if (contentMimeType != null) {
int x = contentMimeType.indexOf(';');
if (x > -1) {
contentMimeType = contentMimeType.substring(0, x);
}
contentMimeType = contentMimeType.trim();
}
f = createResult(FAILURE, "Content MIME types don't match!");
addResult(results, assertEquals(docMimeType, contentMimeType, null, f));
if (contentStream.getMimeType() != null) {
if (contentMimeType.equals(docMimeType)) {
f = createResult(WARNING, "Content MIME types don't match!");
addResult(results, assertEquals(doc.getContentStreamMimeType(), contentStream.getMimeType(), null, f));
}
f = createResult(FAILURE, "Content MIME types is invalid: " + contentStream.getMimeType());
addResult(
results,
assertIsTrue(contentStream.getMimeType().length() > 2
&& contentStream.getMimeType().indexOf('/') > 0, null, f));
}
// check stream
InputStream stream = contentStream.getStream();
if (stream == null) {
addResult(results, createResult(FAILURE, "Docuemnt has no content stream!"));
return;
}
try {
long bytes = 0;
byte[] buffer = new byte[64 * 1024];
int b = stream.read(buffer);
while (b > -1) {
bytes += b;
b = stream.read(buffer);
}
stream.close();
// check content length
if (doc.getContentStreamLength() > -1) {
f = createResult(FAILURE,
"Content stream length property value doesn't match the actual content length!");
addResult(results, assertEquals(doc.getContentStreamLength(), bytes, null, f));
}
if (contentStream.getLength() > -1) {
f = createResult(FAILURE, "Content length value doesn't match the actual content length!");
addResult(results, assertEquals(contentStream.getLength(), bytes, null, f));
}
} catch (Exception e) {
addResult(results, createResult(FAILURE, "Reading content failed: " + e, e, false));
} finally {
try {