You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by gb...@apache.org on 2011/12/01 22:08:35 UTC
svn commit: r1209238 - in /pdfbox/trunk/preflight: pom.xml
src/main/java/org/apache/padaf/preflight/AbstractValidator.java
src/main/java/org/apache/padaf/preflight/PdfAValidator.java
src/main/resources/project.version
Author: gbailleul
Date: Thu Dec 1 21:08:34 2011
New Revision: 1209238
URL: http://svn.apache.org/viewvc?rev=1209238&view=rev
Log:
PDFBOX-1179: remove resource file, modify validator source, prepare filtering in pom, add getVersion method
Removed:
pdfbox/trunk/preflight/src/main/resources/project.version
Modified:
pdfbox/trunk/preflight/pom.xml
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/AbstractValidator.java
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/PdfAValidator.java
Modified: pdfbox/trunk/preflight/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/pom.xml?rev=1209238&r1=1209237&r2=1209238&view=diff
==============================================================================
--- pdfbox/trunk/preflight/pom.xml (original)
+++ pdfbox/trunk/preflight/pom.xml Thu Dec 1 21:08:34 2011
@@ -46,13 +46,16 @@
<build>
<resources>
<resource>
+ <directory>src/main/java</directory>
+ <filtering>true</filtering>
+ <targetPath>../filtered-sources/java</targetPath>
+ </resource>
+ <resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
- <includes>
- <include>project.version</include>
- </includes>
</resource>
</resources>
+ <sourceDirectory>target/filtered-sources/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/AbstractValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/AbstractValidator.java?rev=1209238&r1=1209237&r2=1209238&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/AbstractValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/AbstractValidator.java Thu Dec 1 21:08:34 2011
@@ -21,8 +21,6 @@
package org.apache.padaf.preflight;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@@ -31,168 +29,163 @@ import java.util.List;
import javax.activation.DataSource;
-import org.apache.commons.io.IOUtils;
import org.apache.padaf.preflight.ValidationResult.ValidationError;
import org.apache.padaf.preflight.helpers.AbstractValidationHelper;
-
import org.apache.padaf.preflight.javacc.ParseException;
public abstract class AbstractValidator implements PdfAValidator {
- static {
- try {
- InputStream is = AbstractValidator.class.getClassLoader().getResourceAsStream("project.version");
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- IOUtils.copy(is, bos);
- IOUtils.closeQuietly(is);
- IOUtils.closeQuietly(bos);
- fullName = "PADAF - " + new String(bos.toByteArray(),"us-ascii");
- } catch (Exception e) {
- e.printStackTrace();
- fullName = "PADAF - Unknown version";
- }
- }
-
- protected ValidatorConfig config = null;
-
- protected static String fullName;
-
-
- protected Collection<AbstractValidationHelper> priorHelpers = new ArrayList<AbstractValidationHelper>();
- protected Collection<AbstractValidationHelper> standHelpers = new ArrayList<AbstractValidationHelper>();
-
- /**
- *
- * @param cfg
- * @throws ValidationException
- */
- public AbstractValidator ( ValidatorConfig cfg ) throws ValidationException {
- config = cfg;
-
- Collection<Class<? extends AbstractValidationHelper>> ph = cfg.getPriorHelpers();
- for (Class<? extends AbstractValidationHelper> priorHlpCls : ph) {
- this.priorHelpers.add(instantiateHelper(priorHlpCls, cfg));
- }
-
- Collection<Class<? extends AbstractValidationHelper>> sh = cfg.getStandHelpers();
- for (Class<? extends AbstractValidationHelper> standHlpCls : sh) {
- this.priorHelpers.add(instantiateHelper(standHlpCls, cfg));
- }
-
- }
-
- /**
- * Instantiate a ValidationHelper using the given class.
- *
- * @param avhCls
- * @param cfg
- * @return
- * @throws ValidationException
- */
- private AbstractValidationHelper instantiateHelper(Class<? extends AbstractValidationHelper> avhCls, ValidatorConfig cfg)
- throws ValidationException {
- try {
- Constructor<? extends AbstractValidationHelper> construct = avhCls.getConstructor(ValidatorConfig.class);
- return construct.newInstance(cfg);
- } catch (NoSuchMethodException e) {
- throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(), e);
- } catch (InvocationTargetException e) {
- throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(), e);
- } catch (IllegalAccessException e) {
- throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(), e);
- } catch (InstantiationException e) {
- throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(), e);
- }
- }
-
- /**
- * Create an instance of Document Handler.
- * This method can be override if a inherited class of DocumentHandler
- * must be used.
- *
- * @param source
- * @return
- */
- protected DocumentHandler createDocumentHandler(DataSource source) {
- return new DocumentHandler(source);
- }
-
- /**
- * This method calls the validate method of the given ValidationHelper. A
- * validation exception will be thrown if the Helper throws a validation
- * exception and if the list of errors is empty.
- *
- * @param handler
- * the document handler which contains elements for the validation
- * @param helper
- * An inherited class of AbstractValidationHelper.
- * @param errors
- * A list of validation errors
- * @throws ValidationException
- */
- protected void runValidation(DocumentHandler handler,
- AbstractValidationHelper helper, List<ValidationError> errors)
- throws ValidationException {
- try {
- errors.addAll(helper.validate(handler));
- } catch (ValidationException e) {
- if (errors.size() == 0) {
- // If there are no error, the Exception is thrown because of we can't
- // know if the
- // exception is due to a validation error or to a unexpected cause.
- throw e;
- }
- }
- }
-
- /**
- * Create an instance of ValidationResult. This object contains an instance of
- * ValidationError. If the ParseException is an instance of PdfParseException,
- * the embedded validation error is initialized with the error code of the
- * exception, otherwise it is an UnknownError.
- *
- * @param e
- * @return
- */
- protected ValidationResult createErrorResult(ParseException e) {
- if (e instanceof PdfParseException) {
- if (e.getCause()==null) {
- return new ValidationResult(new ValidationError(((PdfParseException) e)
- .getErrorCode()));
-
- } else if (e.getCause().getMessage()==null) {
- return new ValidationResult(new ValidationError(((PdfParseException) e)
- .getErrorCode()));
- } else {
- return new ValidationResult(new ValidationError(((PdfParseException) e)
- .getErrorCode(),e.getCause().getMessage()));
-
- }
- }
- return createUnknownErrorResult();
- }
-
- /**
- * Create an instance of ValidationResult with a
- * ValidationError(UNKNOWN_ERROR)
- *
- * @return
- */
- protected ValidationResult createUnknownErrorResult() {
- ValidationError error = new ValidationError(
- ValidationConstants.ERROR_UNKOWN_ERROR);
- ValidationResult result = new ValidationResult(error);
- return result;
- }
-
- /* (non-Javadoc)
- * @see net.padaf.preflight.PdfAValidator#getFullName()
- */
- public String getFullName() {
- return fullName;
- }
-
-
-
-
+ protected ValidatorConfig config = null;
+
+
+ public static final String version = "${project.version}";
+
+ public static final String fullName = "PADAF - "+version;
+
+
+ protected Collection<AbstractValidationHelper> priorHelpers = new ArrayList<AbstractValidationHelper>();
+ protected Collection<AbstractValidationHelper> standHelpers = new ArrayList<AbstractValidationHelper>();
+
+ /**
+ *
+ * @param cfg
+ * @throws ValidationException
+ */
+ public AbstractValidator ( ValidatorConfig cfg ) throws ValidationException {
+ config = cfg;
+
+ Collection<Class<? extends AbstractValidationHelper>> ph = cfg.getPriorHelpers();
+ for (Class<? extends AbstractValidationHelper> priorHlpCls : ph) {
+ this.priorHelpers.add(instantiateHelper(priorHlpCls, cfg));
+ }
+
+ Collection<Class<? extends AbstractValidationHelper>> sh = cfg.getStandHelpers();
+ for (Class<? extends AbstractValidationHelper> standHlpCls : sh) {
+ this.priorHelpers.add(instantiateHelper(standHlpCls, cfg));
+ }
+
+ }
+
+ /**
+ * Instantiate a ValidationHelper using the given class.
+ *
+ * @param avhCls
+ * @param cfg
+ * @return
+ * @throws ValidationException
+ */
+ private AbstractValidationHelper instantiateHelper(Class<? extends AbstractValidationHelper> avhCls, ValidatorConfig cfg)
+ throws ValidationException {
+ try {
+ Constructor<? extends AbstractValidationHelper> construct = avhCls.getConstructor(ValidatorConfig.class);
+ return construct.newInstance(cfg);
+ } catch (NoSuchMethodException e) {
+ throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(), e);
+ } catch (InvocationTargetException e) {
+ throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(), e);
+ } catch (IllegalAccessException e) {
+ throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(), e);
+ } catch (InstantiationException e) {
+ throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Create an instance of Document Handler.
+ * This method can be override if a inherited class of DocumentHandler
+ * must be used.
+ *
+ * @param source
+ * @return
+ */
+ protected DocumentHandler createDocumentHandler(DataSource source) {
+ return new DocumentHandler(source);
+ }
+
+ /**
+ * This method calls the validate method of the given ValidationHelper. A
+ * validation exception will be thrown if the Helper throws a validation
+ * exception and if the list of errors is empty.
+ *
+ * @param handler
+ * the document handler which contains elements for the validation
+ * @param helper
+ * An inherited class of AbstractValidationHelper.
+ * @param errors
+ * A list of validation errors
+ * @throws ValidationException
+ */
+ protected void runValidation(DocumentHandler handler,
+ AbstractValidationHelper helper, List<ValidationError> errors)
+ throws ValidationException {
+ try {
+ errors.addAll(helper.validate(handler));
+ } catch (ValidationException e) {
+ if (errors.size() == 0) {
+ // If there are no error, the Exception is thrown because of we can't
+ // know if the
+ // exception is due to a validation error or to a unexpected cause.
+ throw e;
+ }
+ }
+ }
+
+ /**
+ * Create an instance of ValidationResult. This object contains an instance of
+ * ValidationError. If the ParseException is an instance of PdfParseException,
+ * the embedded validation error is initialized with the error code of the
+ * exception, otherwise it is an UnknownError.
+ *
+ * @param e
+ * @return
+ */
+ protected ValidationResult createErrorResult(ParseException e) {
+ if (e instanceof PdfParseException) {
+ if (e.getCause()==null) {
+ return new ValidationResult(new ValidationError(((PdfParseException) e)
+ .getErrorCode()));
+
+ } else if (e.getCause().getMessage()==null) {
+ return new ValidationResult(new ValidationError(((PdfParseException) e)
+ .getErrorCode()));
+ } else {
+ return new ValidationResult(new ValidationError(((PdfParseException) e)
+ .getErrorCode(),e.getCause().getMessage()));
+
+ }
+ }
+ return createUnknownErrorResult();
+ }
+
+ /**
+ * Create an instance of ValidationResult with a
+ * ValidationError(UNKNOWN_ERROR)
+ *
+ * @return
+ */
+ protected ValidationResult createUnknownErrorResult() {
+ ValidationError error = new ValidationError(
+ ValidationConstants.ERROR_UNKOWN_ERROR);
+ ValidationResult result = new ValidationResult(error);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see net.padaf.preflight.PdfAValidator#getFullName()
+ */
+ public String getFullName() {
+ return fullName;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.padaf.preflight.PdfAValidator#getVersion()
+ */
+ public String getVersion() {
+ return version;
+ }
+
+
+
+
}
\ No newline at end of file
Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/PdfAValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/PdfAValidator.java?rev=1209238&r1=1209237&r2=1209238&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/PdfAValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/PdfAValidator.java Thu Dec 1 21:08:34 2011
@@ -43,5 +43,7 @@ public interface PdfAValidator {
* Return the version qualified name of the product
*/
String getFullName ();
+
+ String getVersion ();
}