if (requireExistingNotCompressedObj && ((offsetOrObjstmObNr == null)))
{
addValidationError(new ValidationError(ERROR_SYNTAX_MISSING_OFFSET,
"Object must be defined and must not be compressed object: " + objKey.getNumber() + ":"
+ objKey.getGeneration()));
throw new SyntaxValidationException("Object must be defined and must not be compressed object: "
+ objKey.getNumber() + ":" + objKey.getGeneration(), validationResult);
}
if (offsetOrObjstmObNr == null)
{
// not defined object -> NULL object (Spec. 1.7, chap. 3.2.9)
pdfObject.setObject(COSNull.NULL);
}
else if (offsetOrObjstmObNr == 0)
{
addValidationError(new ValidationError(ERROR_SYNTAX_INVALID_OFFSET, "Object {" + objKey.getNumber()
+ ":" + objKey.getGeneration() + "} has an offset of 0"));
}
else if (offsetOrObjstmObNr > 0)
{
// offset of indirect object in file
// ---- go to object start
setPdfSource(offsetOrObjstmObNr);
// ---- we must have an indirect object
long readObjNr = 0;
int readObjGen = 0;
long offset = pdfSource.getOffset();
String line = readLine();
Pattern pattern = Pattern.compile("(\\d+)\\s(\\d+)\\sobj");
Matcher matcher = pattern.matcher(line);
if (matcher.matches())
{
readObjNr = Integer.parseInt(matcher.group(1));
readObjGen = Integer.parseInt(matcher.group(2));
}
else
{
addValidationError(new ValidationError(ERROR_SYNTAX_OBJ_DELIMITER, "Single space expected [offset="+offset+"; key="+offsetOrObjstmObNr.toString()+"; line="+line+"; object="+pdfObject.toString()+"]"));
// reset pdfSource cursor to read object information
pdfSource.seek(offset);
readObjNr = readObjectNumber();
readObjGen = readGenerationNumber();
skipSpaces(); // skip spaces between Object Generation number and the 'obj' keyword
for (char c : OBJ_MARKER)
{
if (pdfSource.read() != c)
{
addValidationError(new ValidationError(ERROR_SYNTAX_OBJ_DELIMITER, "Expected pattern '"
+ new String(OBJ_MARKER) + " but missed at character '" + c + "'"));
throw new SyntaxValidationException("Expected pattern '" + new String(OBJ_MARKER)
+ " but missed at character '" + c + "'", validationResult);
}
}
}