You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2013/11/17 12:53:41 UTC
svn commit: r1542711 [2/2] - in /pdfbox/branches/1.8: ./
fontbox/src/main/java/org/apache/fontbox/cmap/
jempbox/src/main/java/org/apache/jempbox/xmp/
pdfbox/src/main/java/org/apache/pdfbox/cos/
pdfbox/src/main/java/org/apache/pdfbox/pdfparser/ pdfbox/s...
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java?rev=1542711&r1=1542710&r2=1542711&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java Sun Nov 17 11:53:40 2013
@@ -22,8 +22,10 @@ import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDocument;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSString;
import org.apache.pdfbox.encryption.ARCFour;
@@ -41,7 +43,6 @@ import org.apache.pdfbox.pdmodel.PDDocum
* @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
* @author Benoit Guillon (benoit.guillon@snv.jussieu.fr)
*
- * @version $Revision: 1.5 $
*/
public class StandardSecurityHandler extends SecurityHandler
@@ -64,7 +65,7 @@ public class StandardSecurityHandler ext
/**
* Protection policy class for this handler.
*/
- public static final Class PROTECTION_POLICY_CLASS = StandardProtectionPolicy.class;
+ public static final Class<?> PROTECTION_POLICY_CLASS = StandardProtectionPolicy.class;
/**
* Standard padding for encryption.
@@ -124,14 +125,15 @@ public class StandardSecurityHandler ext
*/
private int computeRevisionNumber()
{
- if(version == 2
- && !policy.getPermissions().canFillInForm()
- && !policy.getPermissions().canExtractForAccessibility()
- && !policy.getPermissions().canPrintDegraded() )
+ if(version < 2 && !policy.getPermissions().hasAnyRevision3PermissionSet())
{
return 2;
}
- return 3;
+ if ( version == 2 || version == 3 || policy.getPermissions().hasAnyRevision3PermissionSet())
+ {
+ return 3;
+ }
+ return 4;
}
/**
@@ -170,7 +172,7 @@ public class StandardSecurityHandler ext
* @throws CryptographyException If there is an error with decryption.
*/
public void prepareForDecryption(PDEncryptionDictionary encDictionary, COSArray documentIDArray,
- DecryptionMaterial decryptionMaterial)
+ DecryptionMaterial decryptionMaterial)
throws CryptographyException, IOException
{
if(!(decryptionMaterial instanceof StandardDecryptionMaterial))
@@ -270,8 +272,8 @@ public class StandardSecurityHandler ext
if (stdCryptFilterDictionary != null)
{
COSName cryptFilterMethod = stdCryptFilterDictionary.getCryptFilterMethod();
-
- if (cryptFilterMethod != null) {
+ if (cryptFilterMethod != null)
+ {
setAES("AESV2".equalsIgnoreCase(cryptFilterMethod.getName()));
}
}
@@ -380,6 +382,7 @@ public class StandardSecurityHandler ext
* @param id The document id.
* @param encRevision The encryption algorithm revision.
* @param length The encryption key length.
+ * @param encryptMetadata The encryption metadata
*
* @return True If the ownerPassword param is the owner password.
*
@@ -461,26 +464,7 @@ public class StandardSecurityHandler ext
}
else if( encRevision == 3 || encRevision == 4)
{
- /**
- byte[] iterationKey = new byte[ rc4Key.length ];
- byte[] dataToEncrypt = o;
- for( int i=19; i>=0; i-- )
- {
- System.arraycopy( rc4Key, 0, iterationKey, 0, rc4Key.length );
- for( int j=0; j< iterationKey.length; j++ )
- {
- iterationKey[j] = (byte)(iterationKey[j] ^ (byte)i);
- }
- rc4.setKey( iterationKey );
- rc4.write( dataToEncrypt, result );
- dataToEncrypt = result.toByteArray();
- result.reset();
- }
- result.write( dataToEncrypt, 0, dataToEncrypt.length );
- */
byte[] iterationKey = new byte[ rc4Key.length ];
-
-
byte[] otemp = new byte[ o.length ]; //sm
System.arraycopy( o, 0, otemp, 0, o.length ); //sm
rc4.write( o, result);//sm
@@ -498,10 +482,7 @@ public class StandardSecurityHandler ext
otemp = result.toByteArray(); //sm
}
}
-
-
return result.toByteArray();
-
}
catch( NoSuchAlgorithmException e )
{
@@ -518,6 +499,7 @@ public class StandardSecurityHandler ext
* @param id The document id.
* @param encRevision The revision of the encryption algorithm.
* @param length The length of the encryption key.
+ * @param encryptMetadata The encryption metadata
*
* @return The encrypted key bytes.
*
@@ -606,6 +588,7 @@ public class StandardSecurityHandler ext
* @param id The document id.
* @param encRevision The revision of the encryption.
* @param length The length of the encryption key.
+ * @param encryptMetadata The encryption metadata
*
* @return The user password.
*
@@ -790,6 +773,7 @@ public class StandardSecurityHandler ext
* @param id The document id used for encryption.
* @param encRevision The revision of the encryption algorithm.
* @param length The length of the encryption key.
+ * @param encryptMetadata The encryption metadata
*
* @return true If the plaintext password is the user password.
*
@@ -814,7 +798,7 @@ public class StandardSecurityHandler ext
if( encRevision == 2 )
{
//STEP 2
- matches = arraysEqual( u, computedValue );
+ matches = Arrays.equals(u, computedValue);
}
else if( encRevision == 3 || encRevision == 4 )
{
@@ -838,6 +822,7 @@ public class StandardSecurityHandler ext
* @param id The document id used for encryption.
* @param encRevision The revision of the encryption algorithm.
* @param length The length of the encryption key.
+ * @param encryptMetadata The encryption metadata
*
* @return true If the plaintext password is the user password.
*
@@ -869,6 +854,7 @@ public class StandardSecurityHandler ext
* @param id The document id.
* @param encRevision The encryption algorithm revision.
* @param length The encryption key length.
+ * @param encryptMetadata The encryption metadata
*
* @return True If the ownerPassword param is the owner password.
*
@@ -892,29 +878,19 @@ public class StandardSecurityHandler ext
private static final boolean arraysEqual( byte[] first, byte[] second, int count )
{
- boolean equal = first.length >= count && second.length >= count;
- for( int i=0; i<count && equal; i++ )
+ // both arrays have to have a minimum length of count
+ if (first.length < count || second.length < count)
{
- equal = first[i] == second[i];
+ return false;
}
- return equal;
- }
-
- /**
- * This will compare two byte[] for equality.
- *
- * @param first The first byte array.
- * @param second The second byte array.
- *
- * @return true If the arrays contain the exact same data.
- */
- private static final boolean arraysEqual( byte[] first, byte[] second )
- {
- boolean equal = first.length == second.length;
- for( int i=0; i<first.length && equal; i++ )
+ for( int i=0; i<count; i++ )
{
- equal = first[i] == second[i];
+ if( first[i] != second[i])
+ {
+ return false;
+ }
}
- return equal;
+ return true;
}
+
}
Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConfiguration.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConfiguration.java?rev=1542711&r1=1542710&r2=1542711&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConfiguration.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConfiguration.java Sun Nov 17 11:53:40 2013
@@ -193,9 +193,21 @@ public class PreflightConfiguration
public void replaceProcess(String processName, Class<? extends ValidationProcess> process)
{
- this.processes.put(processName, process);
+ if (process == null)
+ {
+ removeProcess(processName);
+ }
+ else
+ {
+ this.processes.put(processName, process);
+ }
}
+ public void removeProcess(String processName)
+ {
+ this.processes.remove(processName);
+ }
+
public Collection<String> getPageValidationProcessNames()
{
return this.innerProcesses.keySet();
@@ -203,9 +215,19 @@ public class PreflightConfiguration
public void replacePageProcess(String processName, Class<? extends ValidationProcess> process)
{
- this.innerProcesses.put(processName, process);
+ if (process == null) {
+ removePageProcess(processName);
+ }
+ else {
+ this.innerProcesses.put(processName, process);
+ }
}
+ public void removePageProcess(String processName)
+ {
+ this.innerProcesses.remove(processName);
+ }
+
public boolean isErrorOnMissingProcess()
{
return errorOnMissingProcess;
Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java?rev=1542711&r1=1542710&r2=1542711&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java Sun Nov 17 11:53:40 2013
@@ -414,8 +414,14 @@ public interface PreflightConstants
* The stream uses a filter which isn't defined in the PDF Reference document.
*/
String ERROR_SYNTAX_STREAM_UNDEFINED_FILTER = "1.2.12";
-
- String ERROR_SYNTAX_NOCATALOG = "1.2.13";
+ /**
+ * The stream can't be processed
+ */
+ String ERROR_SYNTAX_STREAM_DAMAGED = "1.2.13";
+ /**
+ * There are no catalog dictionary in the PDF File
+ */
+ String ERROR_SYNTAX_NOCATALOG = "1.2.14";
/**
* Common error about the cross ref table
*/
@@ -473,6 +479,7 @@ public interface PreflightConstants
* Main error code for graphical problems
*/
String ERROR_GRAPHIC_MAIN = "2";
+
String ERROR_GRAPHIC_INVALID = "2.1";
/**
* BBox Entry of a Form XObject is missing or isn't an Array
@@ -504,6 +511,10 @@ public interface PreflightConstants
String ERROR_GRAPHIC_TOO_MANY_GRAPHIC_STATES = "2.1.8";
+ String ERROR_GRAPHIC_MISSING_OBJECT = "2.1.9";
+
+ String ERROR_GRAPHIC_XOBJECT_INVALID_TYPE = "2.1.10";
+
/**
* Main error code for graphical transparency problems
*/
@@ -573,6 +584,10 @@ public interface PreflightConstants
* ICC Based color space used in the PDF file is invalid
*/
String ERROR_GRAPHIC_INVALID_COLOR_SPACE_ICCBASED = "2.4.11";
+ /**
+ * Validation asked on a missing ColorSpace
+ */
+ String ERROR_GRAPHIC_MISSING_COLOR_SPACE_ICCBASED = "2.4.12";
// -----------------------------------------------------------
// ---- FONT ERRORS 3.x...
// -----------------------------------------------------------
@@ -637,6 +652,10 @@ public interface PreflightConstants
*/
String ERROR_FONTS_ENCODING_IO = "3.1.13";
/**
+ * The font type is unknown
+ */
+ String ERROR_FONTS_UNKNOWN_FONT_TYPE = "3.1.14";
+ /**
* The embedded font is damaged
*/
String ERROR_FONTS_DAMAGED = "3.2";
@@ -711,7 +730,10 @@ public interface PreflightConstants
* The AP dictionary of the annotation contains forbidden/invalid entries (only the N entry is authorized)
*/
String ERROR_ANNOT_MISSING_AP_N_CONTENT = "5.1.2";
-
+ /**
+ * An annotation validation is required but there are no element to validate
+ */
+ String ERROR_ANNOT_MISSING_ANNOTATION_DICTIONARY = "5.1.3";
/**
* Common forbidden field error in annotation dictionary
*/
@@ -783,6 +805,10 @@ public interface PreflightConstants
*/
String ERROR_ACTION_HIDE_H_INVALID = "6.1.4";
/**
+ * An action validation is required but there are no element to validate
+ */
+ String ERROR_ACTION_MISSING_ACTION_DICTIONARY = "6.1.5";
+ /**
* Common forbidden action error
*/
String ERROR_ACTION_FORBIDDEN_ACTIONS = "6.2";
@@ -915,4 +941,17 @@ public interface PreflightConstants
*/
String ERROR_METADATA_CATEGORY_PROPERTY_INVALID = "7.5.1";
+ /**
+ * the infor dictionary is corrupt or value can't be read
+ */
+ String ERROR_METADATA_DICT_INFO_CORRUPT = "7.12";
+ /**
+ * Error about PDF processing : that is not necessary a specific PDF/A validation error
+ * but a PDF specification requirement that isn't respected.
+ */
+ String ERROR_PDF_PROCESSING = "8";
+ /**
+ * A Mandatory element is missing
+ */
+ String ERROR_PDF_PROCESSING_MISSING = "8.1";
}
Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java?rev=1542711&r1=1542710&r2=1542711&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java Sun Nov 17 11:53:40 2013
@@ -78,7 +78,7 @@ public class ValidationResult
* Create a Validation Result object. This constructor force the isValid to false and add all the given errors to
* the list or ValidationErrors.
*
- * @param error
+ * @param errors
* if error is null, no error is added to the list.
*/
public ValidationResult(List<ValidationError> errors)
@@ -334,5 +334,29 @@ public class ValidationResult
this.isWarning = isWarning;
}
+ @Override
+ public int hashCode() {
+ return errorCode.hashCode();
+ }
+
+ public boolean equals (Object o) {
+ if (o instanceof ValidationError) {
+ ValidationError ve = (ValidationError)o;
+ // check errorCode
+ if (errorCode==null && ve.errorCode!=null) {
+ return false;
+ } else if (!errorCode.equals(ve.errorCode)) {
+ return false;
+ } else if (!details.equals(ve.details)) {
+ return false;
+ }
+ // check warning
+ return isWarning==ve.isWarning;
+
+ } else {
+ return false;
+ }
+ }
+
}
}
Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java?rev=1542711&r1=1542710&r2=1542711&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java Sun Nov 17 11:53:40 2013
@@ -21,12 +21,30 @@
package org.apache.pdfbox.preflight;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.activation.DataSource;
import javax.activation.FileDataSource;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import org.apache.commons.io.IOUtils;
import org.apache.pdfbox.Version;
import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
import org.apache.pdfbox.preflight.exception.SyntaxValidationException;
import org.apache.pdfbox.preflight.parser.PreflightParser;
+import org.apache.pdfbox.preflight.parser.XmlResultParser;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* This class is a simple main class used to check the validity of a pdf file.
@@ -43,13 +61,95 @@ public class Validator_A1b
{
if (args.length == 0)
{
- System.out.println("Usage : java org.apache.pdfbox.preflight.Validator_A1b <file path>");
- System.out.println("Version : " + Version.getVersion());
+ usage();
System.exit(1);
}
+ // is output xml ?
+ int posFile = 0;
+ boolean outputXml = "xml".equals(args[posFile]);
+ posFile += outputXml?1:0;
+ // list
+ boolean isGroup = "group".equals(args[posFile]);
+ posFile += isGroup?1:0;
+ // list
+ boolean isBatch = "batch".equals(args[posFile]);
+ posFile += isBatch?1:0;
+
+ if (isGroup||isBatch) {
+ // prepare the list
+ List<File> ftp = listFiles(args[posFile]);
+ int status = 0;
+ if (!outputXml) {
+ // simple list of files
+ for (File file2 : ftp)
+ {
+ status |= runSimple(new FileDataSource(file2));
+ }
+ System.exit(status);
+ } else {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+ XmlResultParser xrp = new XmlResultParser();
+ if (isGroup) {
+ Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ Element root = document.createElement("preflights");
+ document.appendChild(root);
+ root.setAttribute("count", String.format("%d", ftp.size()));
+ for (File file : ftp)
+ {
+ Element result = xrp.validate(document,new FileDataSource(file));
+ root.appendChild(result);
+ }
+ transformer.transform(new DOMSource(document), new StreamResult(new File(args[posFile]+".preflight.xml")));
+ } else {
+ // isBatch
+ for (File file : ftp)
+ {
+ Element result = xrp.validate(new FileDataSource(file));
+ Document document = result.getOwnerDocument();
+ document.appendChild(result);
+ transformer.transform(new DOMSource(document), new StreamResult(new File(file.getAbsolutePath()+".preflight.xml")));
+ }
+ }
+ }
+
+
+
+ } else {
+ // only one file
+ FileDataSource fd = new FileDataSource(args[posFile]);
+ if (!outputXml) {
+ // simple validation
+ System.exit(runSimple(fd));
+ } else {
+ // generate xml output
+ XmlResultParser xrp = new XmlResultParser();
+ Element result = xrp.validate(fd);
+ Document document = result.getOwnerDocument();
+ document.appendChild(result);
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+ transformer.transform(new DOMSource(document), new StreamResult(System.out));
+ }
+ }
+
+ }
+
+ private static void usage () {
+ System.out.println("Usage : java org.apache.pdfbox.preflight.Validator_A1b [xml] [mode] <file path>");
+ System.out.println();
+ System.out.println(" * xml : if set, generate xml output");
+ System.out.println(" * mode : if set, <file path> must be a file containing PDF to parse, can have 2 values");
+ System.out.println(" batch : for each file of the list and xml file is generated");
+ System.out.println(" group : generate an xml result for all the file of the list.");
+ System.out.println("Version : " + Version.getVersion());
+ }
+
+ private static int runSimple (DataSource fd) throws Exception {
ValidationResult result = null;
- FileDataSource fd = new FileDataSource(args[0]);
PreflightParser parser = new PreflightParser(fd);
try
{
@@ -66,18 +166,36 @@ public class Validator_A1b
if (result.isValid())
{
- System.out.println("The file " + args[0] + " is a valid PDF/A-1b file");
- System.exit(0);
+ System.out.println("The file " + fd.getName() + " is a valid PDF/A-1b file");
+ System.out.println();
+ return 0;
}
else
{
- System.out.println("The file" + args[0] + " is not valid, error(s) :");
+ System.out.println("The file" + fd.getName() + " is not valid, error(s) :");
for (ValidationError error : result.getErrorsList())
{
System.out.println(error.getErrorCode() + " : " + error.getDetails());
}
-
- System.exit(-1);
+ System.out.println();
+ return -1;
+ }
+
+ }
+
+
+ private static List<File> listFiles (String path) throws IOException {
+ List<File> files = new ArrayList<File>();
+ File f = new File(path);
+ FileReader fr = new FileReader(f);
+ BufferedReader buf = new BufferedReader(fr);
+ while (buf.ready()) {
+ File fn = new File(buf.readLine());
+ if (fn.exists()) {
+ files.add(fn);
+ } // else warn ?
}
+ IOUtils.closeQuietly(buf);
+ return files;
}
}
Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java?rev=1542711&r1=1542710&r2=1542711&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java Sun Nov 17 11:53:40 2013
@@ -254,7 +254,7 @@ public class Type0FontValidator extends
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
"Some elements in the CMap dictionary are missing or invalid"));
}
- else if (!(wmValue == wmode && cmnValue.equals(cmapName)))
+ else if (!(wmValue == wmode && cmapName.equals(cmnValue)))
{
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
"CMapName or WMode is inconsistent"));
Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java?rev=1542711&r1=1542710&r2=1542711&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java Sun Nov 17 11:53:40 2013
@@ -341,7 +341,7 @@ public class SynchronizedMetaDataValidat
protected void analyzeCreationDateProperty(PDDocumentInformation dico, XMPBasicSchema xmp, List<ValidationError> ve)
throws ValidationException
{
- Calendar creationDate;
+ Calendar creationDate = null;
try
{
creationDate = dico.getCreationDate();
@@ -349,7 +349,7 @@ public class SynchronizedMetaDataValidat
catch (IOException e)
{
// If there is an error while converting this property to a date
- throw formatAccessException("Document Information", "CreationDate", e);
+ ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_DICT_INFO_CORRUPT, "Document Information 'CreationDate' can't be read : " + e.getMessage()));
}
if (creationDate != null)
{
@@ -424,7 +424,7 @@ public class SynchronizedMetaDataValidat
catch (IOException e)
{
// If there is an error while converting this property to a date
- throw formatAccessException("Document Information", "ModifyDate", e);
+ ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_DICT_INFO_CORRUPT, "Document Information 'ModifyDate' can't be read : " + e.getMessage()));
}
}
@@ -508,24 +508,6 @@ public class SynchronizedMetaDataValidat
}
/**
- * Return an exception formatted on IOException when accessing metadata
- *
- * @param type
- * type of property (Document Info or XMP)
- * @param target
- * the name of the metadata
- * @param cause
- * the raised IOException
- * @return the generated exception
- */
- protected ValidationException formatAccessException(String type, String target, Throwable cause)
- {
- StringBuilder sb = new StringBuilder(80);
- sb.append("Cannot treat ").append(type).append(" ").append(target).append(" property");
- return new ValidationException(sb.toString(), cause);
- }
-
- /**
* Return an exception formatted on IOException when accessing on metadata schema
*
* @param target
Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java?rev=1542711&r1=1542710&r2=1542711&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java Sun Nov 17 11:53:40 2013
@@ -694,10 +694,12 @@ public class PreflightParser extends Non
{
addValidationError(new ValidationError(ERROR_SYNTAX_OBJ_DELIMITER, "Single space expected"));
+
// reset pdfSource cursor to read object information
pdfSource.seek(offset);
readObjNr = readInt();
readObjGen = readInt();
+ skipSpaces(); // skip spaces between Object Generation number and the 'obj' keyword
for (char c : OBJ_MARKER)
{
if (pdfSource.read() != c)
Copied: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java (from r1469999, pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java)
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java?p2=pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java&p1=pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java&r1=1469999&r2=1542711&rev=1542711&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java Sun Nov 17 11:53:40 2013
@@ -1,9 +1,29 @@
+/*****************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
package org.apache.pdfbox.preflight.parser;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -28,7 +48,9 @@ public class XmlResultParser
Document rdocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
return validate(rdocument,source);
} catch (ParserConfigurationException e) {
- throw new IOException("Failed to init document builder", e);
+ IOException ioe = new IOException("Failed to init document builder");
+ ioe.initCause(e);
+ throw ioe;
}
}
@@ -71,58 +93,54 @@ public class XmlResultParser
} else {
Element preflight = generateResponseSkeleton(rdocument, source.getName(), after-before);
// valid ?
- Element valid = rdocument.createElement("isValid");
- valid.setAttribute("type", pdfType);
- valid.setTextContent("false");
- preflight.appendChild(valid);
- // errors list
- List<ValidationError> cleaned = cleanErrorList(result.getErrorsList());
- Element errors = rdocument.createElement("errors");
- errors.setAttribute("count", String.format("%d", cleaned.size()));
- preflight.appendChild(errors);
- Map<ValidationError, Integer> errorsByType = new HashMap<ValidationError, Integer>();
- for (ValidationError validationError : cleaned)
- {
- Integer count = errorsByType.get(validationError);
- if (count==null) {
- errorsByType.put(validationError, 1);
- } else {
- errorsByType.put(validationError, count++);
- }
- }
-
- for (Map.Entry<ValidationError,Integer> entry : errorsByType.entrySet())
- {
- Element error = rdocument.createElement("error");
- error.setAttribute("count", String.format("%d",entry.getValue().intValue()));
- Element code = rdocument.createElement("code");
- code.setTextContent(entry.getKey().getErrorCode());
- error.appendChild(code);
- Element detail = rdocument.createElement("details");
- detail.setTextContent(entry.getKey().getDetails());
- error.appendChild(detail);
- errors.appendChild(error);
- }
+ createResponseWithError(rdocument, pdfType, result, preflight);
return preflight;
}
}
- private List<ValidationError> cleanErrorList (List<ValidationError> errors) {
- List<ValidationError> cleaned = new ArrayList<ValidationResult.ValidationError>(errors.size());
- List<String> already = new ArrayList<String>(errors.size());
- for (ValidationError validationError : errors)
+ protected void createResponseWithError(Document rdocument, String pdfType, ValidationResult result, Element preflight) {
+ Element valid = rdocument.createElement("isValid");
+ valid.setAttribute("type", pdfType);
+ valid.setTextContent("false");
+ preflight.appendChild(valid);
+ // errors list
+ Element errors = rdocument.createElement("errors");
+ Map<ValidationError, Integer> cleaned = cleanErrorList(result.getErrorsList());
+ preflight.appendChild(errors);
+ int totalCount = 0;
+ for (Map.Entry<ValidationError,Integer> entry : cleaned.entrySet())
{
- if (!already.contains(validationError.getErrorCode())) {
- // first time
- cleaned.add(validationError);
- already.add(validationError.getErrorCode());
- } // else already found
+ Element error = rdocument.createElement("error");
+ int count = entry.getValue().intValue();
+ error.setAttribute("count", String.format("%d",count));
+ totalCount += count;
+ Element code = rdocument.createElement("code");
+ code.setTextContent(entry.getKey().getErrorCode());
+ error.appendChild(code);
+ Element detail = rdocument.createElement("details");
+ detail.setTextContent(entry.getKey().getDetails());
+ error.appendChild(detail);
+ errors.appendChild(error);
+ }
+ errors.setAttribute("count", String.format("%d", totalCount));
+ }
+
+ private Map<ValidationError,Integer> cleanErrorList (List<ValidationError> errors) {
+ Map<ValidationError,Integer> cleaned = new HashMap<ValidationError, Integer>(errors.size());
+ for (ValidationError ve: errors) {
+ Integer found = cleaned.get(ve);
+ if (found!=null) {
+ cleaned.put(ve,found+1);
+ } else {
+ cleaned.put(ve,1);
+ }
+
}
- return cleaned;
+ return cleaned;
}
- private Element generateFailureResponse (Document rdocument, String name,long duration, String pdfType, Exception e) {
+ protected Element generateFailureResponse (Document rdocument, String name,long duration, String pdfType, Exception e) {
Element preflight = generateResponseSkeleton(rdocument, name, duration);
// valid ?
Element valid = rdocument.createElement("isValid");
@@ -145,7 +163,7 @@ public class XmlResultParser
return preflight;
}
- private Element generateResponseSkeleton (Document rdocument, String name, long duration) {
+ protected Element generateResponseSkeleton (Document rdocument, String name, long duration) {
Element preflight = rdocument.createElement("preflight");
preflight.setAttribute("name", name);
// duration
Modified: pdfbox/branches/1.8/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java?rev=1542711&r1=1542710&r2=1542711&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java (original)
+++ pdfbox/branches/1.8/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java Sun Nov 17 11:53:40 2013
@@ -436,19 +436,6 @@ public class TestSynchronizedMetadataVal
}
}
-
- /**
- * Check if FormatAccessException Generator is ok
- *
- * @throws Exception
- */
- @Test
- public void checkformatAccessException() throws Exception
- {
- Throwable cause = new Throwable();
- Assert.assertSame(cause, sync.formatAccessException("test", "test", cause).getCause());
- }
-
/**
* Check if SchemaAccessException Generator is ok
*