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 2011/07/24 16:02:33 UTC
svn commit: r1150373 [3/12] - in /pdfbox/trunk/preflight: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/padaf/ src/main/java/org/apache/padaf/preflight/
src/main/java/org/apache/padaf/preflight/a...
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/InvalidAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/InvalidAction.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/InvalidAction.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/InvalidAction.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.actions;
+
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
+
+/**
+ * ActionManager for InvalidAction. An invalid action is an action which isn't
+ * authorized in a PDF/A file but should be valid in a standard PDF file.
+ */
+public class InvalidAction extends AbstractActionManager {
+ private String actionName = null;
+
+ /**
+ *
+ * @param amFact
+ * Instance of ActionManagerFactory used to create ActionManager to
+ * check Next actions.
+ * @param adict
+ * the COSDictionary of the action wrapped by this class.
+ * @param cDoc
+ * the COSDocument from which the action comes from.
+ * @param aaKey
+ * The name of the key which identify the action in a additional
+ * action dictionary.
+ * @param name
+ * the action type
+ */
+ public InvalidAction(ActionManagerFactory amFact, COSDictionary adict,
+ COSDocument cDoc, String aaKey, String name) {
+ super(amFact, adict, cDoc, aaKey);
+ this.actionName = name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.awl.edoc.pdfa.validation.actions.AbstractActionManager#valid(java.util
+ * .List)
+ */
+ @Override
+ protected boolean innerValid(List<ValidationError> error) {
+ error.add(new ValidationError(ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN, "The action "
+ + actionName + " is forbidden"));
+ return false;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/InvalidAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/NamedAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/NamedAction.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/NamedAction.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/NamedAction.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.actions;
+
+import static org.apache.padaf.preflight.ValidationConstants.ACTION_DICTIONARY_KEY_N;
+import static org.apache.padaf.preflight.ValidationConstants.ACTION_DICTIONARY_VALUE_ATYPE_NAMED_FIRST;
+import static org.apache.padaf.preflight.ValidationConstants.ACTION_DICTIONARY_VALUE_ATYPE_NAMED_LAST;
+import static org.apache.padaf.preflight.ValidationConstants.ACTION_DICTIONARY_VALUE_ATYPE_NAMED_NEXT;
+import static org.apache.padaf.preflight.ValidationConstants.ACTION_DICTIONARY_VALUE_ATYPE_NAMED_PREV;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_NAMED;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ACTION_MISING_KEY;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSName;
+
+/**
+ * ActionManager for the Named action. Named action is valid if N entry is
+ * present with one of the four values :
+ * <UL>
+ * <li>NextPage
+ * <li>PrevPage
+ * <li>FirstPage
+ * <li>LastPage
+ * </UL>
+ */
+public class NamedAction extends AbstractActionManager {
+
+ /**
+ * @param amFact
+ * Instance of ActionManagerFactory used to create ActionManager to
+ * check Next actions.
+ * @param adict
+ * the COSDictionary of the action wrapped by this class.
+ * @param cDoc
+ * the COSDocument from which the action comes from.
+ * @param aaKey
+ * The name of the key which identify the action in a additional
+ * action dictionary.
+ */
+ public NamedAction(ActionManagerFactory amFact, COSDictionary adict,
+ COSDocument doc, String aaKey) {
+ super(amFact, adict, doc, aaKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.awl.edoc.pdfa.validation.actions.AbstractActionManager#valid(java.util
+ * .List)
+ */
+ @Override
+ protected boolean innerValid(List<ValidationError> error) {
+ String n = this.actionDictionnary.getNameAsString(COSName
+ .getPDFName(ACTION_DICTIONARY_KEY_N));
+
+ // ---- N entry is mandatory
+ if (n == null || "".equals(n)) {
+ error.add(new ValidationError(ERROR_ACTION_MISING_KEY,
+ "N entry is mandatory for the NamedActions"));
+ return false;
+ }
+
+ // ---- Only Predefine name actions are authorized
+ if (!(ACTION_DICTIONARY_VALUE_ATYPE_NAMED_FIRST.equals(n)
+ || ACTION_DICTIONARY_VALUE_ATYPE_NAMED_LAST.equals(n)
+ || ACTION_DICTIONARY_VALUE_ATYPE_NAMED_NEXT.equals(n) || ACTION_DICTIONARY_VALUE_ATYPE_NAMED_PREV
+ .equals(n))) {
+ error.add(new ValidationError(ERROR_ACTION_FORBIDDEN_ACTIONS_NAMED, n + " isn't authorized as named action"));
+ return false;
+ }
+
+ return true;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/NamedAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/SubmitAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/SubmitAction.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/SubmitAction.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/SubmitAction.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.actions;
+
+import static org.apache.padaf.preflight.ValidationConstants.ACTION_DICTIONARY_KEY_F;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ACTION_MISING_KEY;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSName;
+
+/**
+ * ActionManager for the Submit action SubmitAction is valid if the F entry is
+ * present.
+ */
+public class SubmitAction extends AbstractActionManager {
+
+ /**
+ * @param amFact
+ * Instance of ActionManagerFactory used to create ActionManager to
+ * check Next actions.
+ * @param adict
+ * the COSDictionary of the action wrapped by this class.
+ * @param cDoc
+ * the COSDocument from which the action comes from.
+ * @param aaKey
+ * The name of the key which identify the action in a additional
+ * action dictionary.
+ */
+ public SubmitAction(ActionManagerFactory amFact, COSDictionary adict,
+ COSDocument doc, String aaKey) {
+ super(amFact, adict, doc, aaKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.awl.edoc.pdfa.validation.actions.AbstractActionManager#valid(java.util
+ * .List)
+ */
+ @Override
+ protected boolean innerValid(List<ValidationError> error) {
+ COSBase f = this.actionDictionnary.getItem(COSName
+ .getPDFName(ACTION_DICTIONARY_KEY_F));
+ if (f == null) {
+ error.add(new ValidationError(ERROR_ACTION_MISING_KEY,
+ "F entry is mandatory for the SubmitActions"));
+ return false;
+ }
+ return true;
+ }
+
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/SubmitAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/ThreadAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/ThreadAction.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/ThreadAction.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/ThreadAction.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.actions;
+
+import static org.apache.padaf.preflight.ValidationConstants.ACTION_DICTIONARY_KEY_D;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ACTION_INVALID_TYPE;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ACTION_MISING_KEY;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.padaf.preflight.utils.COSUtils;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSName;
+
+/**
+ * ActionManager for the Thread action ThreadAction is valid if the D entry is
+ * present.
+ */
+public class ThreadAction extends AbstractActionManager {
+
+ /**
+ * @param amFact
+ * Instance of ActionManagerFactory used to create ActionManager to
+ * check Next actions.
+ * @param adict
+ * the COSDictionary of the action wrapped by this class.
+ * @param cDoc
+ * the COSDocument from which the action comes from.
+ * @param aaKey
+ * The name of the key which identify the action in a additional
+ * action dictionary.
+ */
+ public ThreadAction(ActionManagerFactory amFact, COSDictionary adict,
+ COSDocument doc, String aaKey) {
+ super(amFact, adict, doc, aaKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.awl.edoc.pdfa.validation.actions.AbstractActionManager#valid(java.util
+ * .List)
+ */
+ @Override
+ protected boolean innerValid(List<ValidationError> error) {
+ COSBase d = this.actionDictionnary.getItem(COSName
+ .getPDFName(ACTION_DICTIONARY_KEY_D));
+
+ // ---- D entry is mandatory
+ if (d == null) {
+ error.add(new ValidationError(ERROR_ACTION_MISING_KEY,
+ "D entry is mandatory for the ThreadAction"));
+ return false;
+ }
+
+ if (!(COSUtils.isInteger(d, cDoc) || COSUtils.isString(d, cDoc) || COSUtils
+ .isDictionary(d, cDoc))) {
+ error.add(new ValidationError(ERROR_ACTION_INVALID_TYPE, "D entry type is invalid"));
+ return false;
+ }
+
+ return true;
+ }
+
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/ThreadAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UndefAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UndefAction.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UndefAction.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UndefAction.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.actions;
+
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_UNDEF;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
+
+/**
+ * ActionManager for Undefined Actions. An undefined action is an action which isn't
+ * declared in the PDF Reference Third Edition. This kind of actions are forbidden to
+ * avoid wrong result due to new features which can't be consistent with the PDF/A-1 format
+ */
+public class UndefAction extends AbstractActionManager {
+ private String actionName = null;
+
+ /**
+ *
+ * @param amFact
+ * Instance of ActionManagerFactory used to create ActionManager to
+ * check Next actions.
+ * @param adict
+ * the COSDictionary of the action wrapped by this class.
+ * @param cDoc
+ * the COSDocument from which the action comes from.
+ * @param aaKey
+ * The name of the key which identify the action in a additional
+ * action dictionary.
+ * @param name
+ * the action type
+ */
+ public UndefAction(ActionManagerFactory amFact, COSDictionary adict,
+ COSDocument cDoc, String aaKey, String name) {
+ super(amFact, adict, cDoc, aaKey);
+ this.actionName = name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.awl.edoc.pdfa.validation.actions.AbstractActionManager#valid(java.util
+ * .List)
+ */
+ @Override
+ protected boolean innerValid(List<ValidationError> error) {
+ error.add(new ValidationError(ERROR_ACTION_FORBIDDEN_ACTIONS_UNDEF, "The action "
+ + actionName + " is undefined"));
+ return false;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UndefAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UriAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UriAction.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UriAction.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UriAction.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,85 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.actions;
+
+import static org.apache.padaf.preflight.ValidationConstants.ACTION_DICTIONARY_KEY_URI;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ACTION_INVALID_TYPE;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ACTION_MISING_KEY;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.padaf.preflight.utils.COSUtils;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSName;
+
+/**
+ * ActionManager for the URI action URI action is valid if the URI entry is
+ * present as a String.
+ */
+public class UriAction extends AbstractActionManager {
+
+ /**
+ * @param amFact
+ * Instance of ActionManagerFactory used to create ActionManager to
+ * check Next actions.
+ * @param adict
+ * the COSDictionary of the action wrapped by this class.
+ * @param cDoc
+ * the COSDocument from which the action comes from.
+ * @param aaKey
+ * The name of the key which identify the action in a additional
+ * action dictionary.
+ */
+ public UriAction(ActionManagerFactory amFact, COSDictionary adict,
+ COSDocument doc, String aaKey) {
+ super(amFact, adict, doc, aaKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.awl.edoc.pdfa.validation.actions.AbstractActionManager#valid(java.util
+ * .List)
+ */
+ @Override
+ protected boolean innerValid(List<ValidationError> error) {
+ COSBase uri = this.actionDictionnary.getItem(COSName
+ .getPDFName(ACTION_DICTIONARY_KEY_URI));
+ if (uri == null) {
+ error.add(new ValidationError(ERROR_ACTION_MISING_KEY,
+ "URI entry is mandatory for the UriAction"));
+ return false;
+ }
+
+ if (!COSUtils.isString(uri, cDoc)) {
+ error.add(new ValidationError(ERROR_ACTION_INVALID_TYPE, "URI entry should be a string"));
+ return false;
+ }
+
+ return true;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/actions/UriAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidator.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,374 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_CA;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_D;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_N;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_R;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_SYNTAX_DICT_INVALID;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.padaf.preflight.actions.AbstractActionManager;
+import org.apache.padaf.preflight.actions.ActionManagerFactory;
+import org.apache.padaf.preflight.graphics.ICCProfileWrapper;
+import org.apache.padaf.preflight.utils.COSUtils;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
+
+public abstract class AnnotationValidator {
+
+ protected AnnotationValidatorFactory annotFact = null;
+ protected ActionManagerFactory actionFact = null;
+ protected COSDocument cosDoc = null;
+
+ protected DocumentHandler handler = null;
+ /**
+ * COSDictionary of the annotation
+ */
+ protected COSDictionary annotDictionary = null;
+ /**
+ * Instance of PDAnnotation built using the annotDictionary
+ */
+ protected PDAnnotation pdAnnot = null;
+
+ public AnnotationValidator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super();
+ this.handler = handler;
+ this.cosDoc = handler.getDocument().getDocument();
+ this.annotDictionary = annotDictionary;
+ }
+
+ /**
+ * Checks if flags of the annotation are authorized.
+ * <UL>
+ * <li>Print flag must be 1
+ * <li>NoView flag must be 0
+ * <li>Hidden flag must be 0
+ * <li>Invisible flag must be 0
+ * </UL>
+ * If one of these flags is invalid, the errors list is updated with the
+ * ERROR_ANNOT_FORBIDDEN_FLAG ValidationError code.
+ *
+ * @param errors
+ * list of errors which is updated if validation fails
+ * @return false if a flag is invalid, true otherwise.
+ */
+ protected boolean checkFlags(List<ValidationError> errors) {
+ boolean result = this.pdAnnot.isPrinted();
+ result = result && !this.pdAnnot.isHidden();
+ result = result && !this.pdAnnot.isInvisible();
+ result = result && !this.pdAnnot.isNoView();
+ if (!result) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_FORBIDDEN_FLAG, "Flags of " + pdAnnot.getSubtype() + " annotation are invalid"));
+ }
+
+ return result;
+ }
+
+ /**
+ * Check if the CA value is 1.0. Return true if the CA element is missing or
+ * if the value is 1.0. Return false otherwise and update the given list of
+ * errors.
+ *
+ * @param errors
+ * list of errors which is updated if validation fails
+ * @return
+ */
+ protected boolean checkCA(List<ValidationError> errors) {
+ COSBase ca = this.pdAnnot.getDictionary().getItem(
+ COSName.getPDFName(ANNOT_DICTIONARY_KEY_CA));
+ if (ca != null) {
+ float caf = this.pdAnnot.getDictionary().getFloat(
+ COSName.getPDFName(ANNOT_DICTIONARY_KEY_CA));
+ if (caf != 1.0f) { // ---- Only 1.0 is authorized as value
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_INVALID_CA, "CA entry is invalid. Expected 1.0 / Read " + caf));
+ return false;
+ }
+ } //else optional field, ok
+ return true;
+ }
+
+ /**
+ * Return true if the C field is present in the Annotation dictionary and if
+ * the RGB profile is used in the DestOutputProfile of the OutputIntent
+ * dictionary.
+ *
+ * @param errors
+ * list of errors which is updated if no RGB profile is found when
+ * the C element is present
+ * @return
+ */
+ protected boolean checkColors(List<ValidationError> errors) {
+ if (this.pdAnnot.getColour() != null) {
+ if (!searchRGBProfile()) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_FORBIDDEN_COLOR,"Annotation uses a Color profile which isn't the same than the profile contained by the OutputIntent"));
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Search the RGB Profile in OutputIntents dictionaries
+ *
+ * @return true if a rgb profile is found, false otherwise.
+ */
+ protected boolean searchRGBProfile() {
+ ICCProfileWrapper iccpw = this.handler.getIccProfileWrapper();
+ if (iccpw != null) {
+ return iccpw.isRGBColorSpace();
+ }
+ return false;
+ }
+
+ /**
+ * This method checks the AP entry of the Annotation Dictionary. If the AP key
+ * is missing, this method returns true. If the AP key exists, only the N
+ * entry is authorized and must be a Stream which define the appearance of the
+ * annotation. (Currently, only the type of the N entry is checked because of
+ * the Appearance stream is a Form XObject, so it will be checked by the
+ * Graphics Helper)
+ *
+ * If the AP content isn't valid, this method return false and updates the
+ * errors list.
+ *
+ * @param errors
+ * list of errors which is updated if validation fails
+ * @return
+ */
+ protected boolean checkAP(List<ValidationError> errors) {
+ PDAppearanceDictionary ap = this.pdAnnot.getAppearance();
+ if (ap != null) {
+ COSDictionary apDict = ap.getDictionary();
+ // ---- Only N entry is authorized
+ if (apDict.getItem(COSName.getPDFName(ANNOT_DICTIONARY_KEY_D)) != null
+ || apDict.getItem(
+ COSName.getPDFName(ANNOT_DICTIONARY_KEY_R)) != null) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_INVALID_AP_CONTENT,
+ "Only the N Appearance is authorized"));
+ return false;
+ } else if (apDict.getItem(
+ COSName.getPDFName(ANNOT_DICTIONARY_KEY_N)) == null) {
+ // ---- N entry is required
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_MISSING_AP_N_CONTENT,
+ "The N Appearance must be present"));
+ return false;
+ } else {
+ // ---- the N entry must be a Stream (Dictionaries are forbidden)
+ COSBase apn = apDict.getItem(
+ COSName.getPDFName(ANNOT_DICTIONARY_KEY_N));
+ if (!COSUtils.isStream(apn, this.cosDoc)) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_INVALID_AP_CONTENT,
+ "The N Appearance must be a Stream"));
+ return false;
+ }
+ }
+ } //else ok, nothing to check,this field is optional
+ return true;
+ }
+
+ /**
+ * Extract a list of ActionManager from the Annotation dictionary and valid
+ * them. If an action is invalid, the errors list is updated and the method
+ * returns false. Otherwise, the method returns true and the errors list
+ * doesn't change.
+ *
+ * @param errors
+ * list of errors which is updated if validation fails
+ * @return
+ * @throws ValidationException
+ */
+ protected boolean checkActions(List<ValidationError> errors)
+ throws ValidationException {
+
+ if ( actionFact == null) {
+ return false;
+ }
+
+ List<AbstractActionManager> la = actionFact.getActions(annotDictionary, cosDoc);
+ for (AbstractActionManager aMng : la) {
+ if (!aMng.valid(errors)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * This method validates the Popup entry. This entry shall contain an other
+ * Annotation. This annotation is validated with the right
+ * AnnotationValidator.
+ *
+ * @param errors
+ * @return
+ * @throws ValidationException
+ */
+ protected boolean checkPopup(List<ValidationError> errors)
+ throws ValidationException {
+ COSBase cosPopup = this.annotDictionary.getItem(COSName
+ .getPDFName(ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP));
+ if (cosPopup != null) {
+ COSDictionary popupDict = COSUtils.getAsDictionary(cosPopup, this.cosDoc);
+ if (popupDict == null) {
+ errors
+ .add(new ValidationError(
+ ERROR_SYNTAX_DICT_INVALID,
+ "An Annotation has a Popup entry, but the value is missing or isn't a dictionary"));
+ return false;
+ }
+ AnnotationValidator popupVal = this.annotFact.getAnnotationValidator(popupDict, handler,
+ errors);
+ return popupVal.validate(errors);
+ }
+ return true;
+ }
+
+ /**
+ * Execute validation of the Annotation dictionary.
+ *
+ * @param errors
+ * list of errors which is updated if validation fails
+ * @return true if validation succeed, false otherwise.
+ * @throws ValidationException
+ */
+ public boolean validate(List<ValidationError> errors)
+ throws ValidationException {
+ boolean isValide = checkMandatoryFields(errors);
+ isValide = isValide && checkFlags(errors);
+ isValide = isValide && checkColors(errors);
+ isValide = isValide && checkAP(errors);
+ isValide = isValide && checkCA(errors);
+ isValide = isValide && checkActions(errors);
+ isValide = isValide && checkPopup(errors);
+ return isValide;
+ }
+
+ /**
+ * Checks if all mandatory fields of an annotation are present. If some fields
+ * are missing, the method returns false and the errors list is updated.
+ *
+ * @param errors
+ * list of errors which is updated if validation fails
+ * @return true if validation succeed, false otherwise.
+ */
+ protected abstract boolean checkMandatoryFields(List<ValidationError> errors);
+
+ /**
+ * Initialize the annotFact attribute of this object.
+ * This method must be called by the Factory at the creation of this object.
+ * Only the Factory should call this method.
+ *
+ * @param fact
+ */
+ public final void setFactory (AnnotationValidatorFactory fact) {
+ this.annotFact = fact;
+ }
+
+// /**
+// * Return an instance of AnnotationValidator if the annotation subtype is
+// * authorized for a PDF/A. Otherwise, returns null and the given list is
+// * updated with the right error code.
+// *
+// * If the subtype isn't mentioned in the PDF/A specification and if it doesn't
+// * exist in the PDF Reference 1.4, it will be considered as an invalid
+// * annotation. Here is the list of Annotations which appear after the PDF 1.4
+// * :
+// * <UL>
+// * <li>Polygon (1.5)
+// * <li>Polyline (1.5)
+// * <li>Caret (1.5)
+// * <li>Screen (1.5)
+// * <li>Watermark (1.6)
+// * <li>3D (1.6)
+// * </UL>
+// *
+// * @param annotDic
+// * @param handler
+// * @param errors
+// * @return
+// */
+// public static AnnotationValidator getAnnotationValidator(
+// COSDictionary annotDic, DocumentHandler handler,
+// List<ValidationError> errors) {
+// AnnotationValidator av = null;
+//
+// String subtype = annotDic.getNameAsString(COSName
+// .getPDFName(DICTIONARY_KEY_SUBTYPE));
+// if (subtype == null || "".equals(subtype)) {
+// errors.add(new ValidationError(ERROR_ANNOT_MISSING_SUBTYPE));
+// } else {
+// if (ANNOT_DICTIONARY_VALUE_SUBTYPE_TEXT.equals(subtype)) {
+// av = new TextAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_LINK.equals(subtype)) {
+// av = new LinkAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_FREETEXT.equals(subtype)) {
+// av = new FreeTextAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_LINE.equals(subtype)) {
+// av = new LineAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUARE.equals(subtype)
+// || ANNOT_DICTIONARY_VALUE_SUBTYPE_CIRCLE.equals(subtype)) {
+// av = new SquareCircleAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_HIGHLIGHT.equals(subtype)
+// || ANNOT_DICTIONARY_VALUE_SUBTYPE_UNDERLINE.equals(subtype)
+// || ANNOT_DICTIONARY_VALUE_SUBTYPE_STRIKEOUT.equals(subtype)
+// || ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUILGGLY.equals(subtype)) {
+// av = new MarkupAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_STAMP.equals(subtype)) {
+// av = new RubberStampAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_INK.equals(subtype)) {
+// av = new InkAnnotationValdiator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP.equals(subtype)) {
+// av = new PopupAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_WIDGET.equals(subtype)) {
+// av = new WidgetAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_PRINTERMARK.equals(subtype)) {
+// av = new PrintMarkAnnotationValidator(handler, annotDic);
+// } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_TRAPNET.equals(subtype)) {
+// av = new TrapNetAnnotationValidator(handler, annotDic);
+// } else {
+// errors.add(new ValidationError(ERROR_ANNOT_FORBIDDEN_SUBTYPE,
+// "The subtype isn't authorized : " + subtype));
+// }
+// }
+// return av;
+// }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidatorFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidatorFactory.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidatorFactory.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidatorFactory.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.padaf.preflight.actions.ActionManagerFactory;
+import org.apache.pdfbox.cos.COSDictionary;
+
+public abstract class AnnotationValidatorFactory {
+ protected ActionManagerFactory actionFact = null;
+
+ public final void setActionFact(ActionManagerFactory _actionFact) {
+ this.actionFact = _actionFact;
+ }
+
+ /**
+ * Return an instance of AnnotationValidator.
+ * <B>WARNING</B> this method must call the setFactory of each instance of AnnotationValidator.
+ *
+ * @param annotDic
+ * @param handler
+ * @param errors
+ * @return
+ */
+ public final AnnotationValidator getAnnotationValidator(COSDictionary annotDic,
+ DocumentHandler handler,
+ List<ValidationError> errors) {
+ AnnotationValidator av = instantiateAnnotationValidator(annotDic, handler, errors);
+ if (av != null) {
+ av.actionFact = actionFact;
+ }
+ return av;
+ }
+
+ public abstract AnnotationValidator instantiateAnnotationValidator(COSDictionary annotDic,
+ DocumentHandler handler,
+ List<ValidationError> errors);
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/AnnotationValidatorFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/FreeTextAnnotationValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/FreeTextAnnotationValidator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/FreeTextAnnotationValidator.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/FreeTextAnnotationValidator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_CONTENTS;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_DA;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_F;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_RECT;
+import static org.apache.padaf.preflight.ValidationConstants.DICTIONARY_KEY_SUBTYPE;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup;
+
+/**
+ * Validation class for the FreeTextAnnotation
+ */
+public class FreeTextAnnotationValidator extends AnnotationValidator {
+ /**
+ * PDFBox object which wraps the Annotation dictionary
+ */
+ protected PDAnnotationTextMarkup pdFreeText = null;
+
+ public FreeTextAnnotationValidator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super(handler, annotDictionary);
+ this.pdFreeText = new PDAnnotationTextMarkup(annotDictionary);
+ this.pdAnnot = this.pdFreeText;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.awl.edoc.pdfa.validation.annotation.AnnotationValidator#
+ * checkMandatoryFields(java.util.List)
+ */
+ protected boolean checkMandatoryFields(List<ValidationError> errors) {
+ boolean subtype = false;
+ boolean da = false;
+ boolean f = false;
+ boolean rect = false;
+ boolean contents = false;
+
+ for (Object key : this.annotDictionary.keySet()) {
+ if (!(key instanceof COSName)) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
+ "Invalid key in The Annotation dictionary"));
+ return false;
+ }
+
+ String cosName = ((COSName) key).getName();
+ if (cosName.equals(DICTIONARY_KEY_SUBTYPE)) {
+ subtype = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_DA)) {
+ da = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_RECT)) {
+ rect = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_F)) {
+ f = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_CONTENTS)) {
+ contents = true;
+ }
+ }
+
+ /*
+ * ---- After PDF 1.4, all additional entries in this annotation are
+ * optional and they seem to be compatible with the PDF/A specification.
+ */
+ boolean result = (subtype && rect && f && da && contents);
+ if (!result) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_MISSING_FIELDS,"A mandatory field for the " + this.pdAnnot.getSubtype() + " annotation is missing"));
+ }
+ return result;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/FreeTextAnnotationValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/InkAnnotationValdiator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/InkAnnotationValdiator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/InkAnnotationValdiator.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/InkAnnotationValdiator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,103 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_CONTENTS;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_F;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_INKLIST;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_RECT;
+import static org.apache.padaf.preflight.ValidationConstants.DICTIONARY_KEY_SUBTYPE;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown;
+
+/**
+ * Validation class for the InkAnnotation
+ */
+public class InkAnnotationValdiator extends AnnotationValidator {
+ /**
+ * PDFBox which wraps the annotation dictionary
+ */
+ protected PDAnnotationUnknown pdUnk = null;
+
+ public InkAnnotationValdiator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super(handler, annotDictionary);
+ this.pdUnk = new PDAnnotationUnknown(annotDictionary);
+ this.pdAnnot = this.pdUnk;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.awl.edoc.pdfa.validation.annotation.AnnotationValidator#
+ * checkMandatoryFields(java.util.List)
+ */
+ protected boolean checkMandatoryFields(List<ValidationError> errors) {
+ boolean subtype = false;
+ boolean rect = false;
+ boolean f = false;
+ boolean contents = false;
+ boolean inkList = false;
+
+ for (Object key : this.annotDictionary.keySet()) {
+ if (!(key instanceof COSName)) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
+ "Invalid key in The Annotation dictionary"));
+ return false;
+ }
+
+ String cosName = ((COSName) key).getName();
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_RECT)) {
+ rect = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_INKLIST)) {
+ inkList = true;
+ }
+ if (cosName.equals(DICTIONARY_KEY_SUBTYPE)) {
+ subtype = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_F)) {
+ f = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_CONTENTS)) {
+ contents = true;
+ }
+ }
+
+ boolean result = (subtype && rect && f && contents && inkList);
+ if (!result) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_MISSING_FIELDS));
+ }
+ return result;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/InkAnnotationValdiator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LineAnnotationValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LineAnnotationValidator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LineAnnotationValidator.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LineAnnotationValidator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,137 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_F;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_L;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_RECT;
+import static org.apache.padaf.preflight.ValidationConstants.DICTIONARY_KEY_SUBTYPE;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLine;
+
+/**
+ * Validation class for the LineAnnotation
+ */
+public class LineAnnotationValidator extends AnnotationValidator {
+ /**
+ * PDFBox object which wraps the annotation dictionary
+ */
+ protected PDAnnotationLine pdLine = null;
+
+ public LineAnnotationValidator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super(handler, annotDictionary);
+ this.pdLine = new PDAnnotationLine(annotDictionary);
+ this.pdAnnot = this.pdLine;
+ }
+
+ /**
+ * In addition of the AnnotationValidator.validate() method, this method
+ * executes the the checkIColors method.
+ *
+ * @see org.apache.padaf.preflight.annotation.AnnotationValidator#validate(java.util.List)
+ */
+ @Override
+ public boolean validate(List<ValidationError> errors)
+ throws ValidationException {
+ boolean isValide = super.validate(errors);
+ isValide = isValide && checkIColors(errors);
+ return isValide;
+ }
+
+ /**
+ * Return true if the IC field is present in the Annotation dictionary and if
+ * the RGB profile is used in the DestOutputProfile of the OutputIntent
+ * dictionary.
+ *
+ * @param errors
+ * list of errors with is updated if no RGB profile is found when the
+ * IC element is present
+ * @return
+ */
+ protected boolean checkIColors(List<ValidationError> errors) {
+ if (this.pdLine.getInteriorColour() != null) {
+ if (!searchRGBProfile()) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_FORBIDDEN_COLOR,"Annotation uses a Color profile which isn't the same than the profile contained by the OutputIntent"));
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.awl.edoc.pdfa.validation.annotation.AnnotationValidator#
+ * checkMandatoryFields(java.util.List)
+ */
+ protected boolean checkMandatoryFields(List<ValidationError> errors) {
+ boolean subtype = false;
+ boolean l = false;
+ boolean f = false;
+ boolean rect = false;
+
+ for (Object key : this.annotDictionary.keySet()) {
+ if (!(key instanceof COSName)) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
+ "Invalid key in The Annotation dictionary"));
+ return false;
+ }
+
+ String cosName = ((COSName) key).getName();
+ if (cosName.equals(DICTIONARY_KEY_SUBTYPE)) {
+ subtype = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_L)) {
+ l = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_RECT)) {
+ rect = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_F)) {
+ f = true;
+ }
+ }
+ /*
+ * ---- After PDF 1.4, all additional entries in this annotation are
+ * optional and they seem to be compatible with the PDF/A specification.
+ */
+ boolean result = (subtype && rect && f && l);
+ if (!result) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_MISSING_FIELDS));
+ }
+ return result;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LineAnnotationValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LinkAnnotationValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LinkAnnotationValidator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LinkAnnotationValidator.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LinkAnnotationValidator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,138 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_F;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_RECT;
+import static org.apache.padaf.preflight.ValidationConstants.DICTIONARY_KEY_SUBTYPE;
+
+import java.io.IOException;
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
+
+/**
+ * Validation class for the LinkAnnotation
+ */
+public class LinkAnnotationValidator extends AnnotationValidator {
+ /**
+ * PDFBox object which wraps the annotation dictionary
+ */
+ protected PDAnnotationLink pdLink = null;
+
+ public LinkAnnotationValidator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super(handler, annotDictionary);
+ this.pdLink = new PDAnnotationLink(annotDictionary);
+ this.pdAnnot = this.pdLink;
+ }
+
+ /**
+ * In addition of the AnnotationValidator.validate() method, this method
+ * executes the the checkDest method.
+ *
+ * @see org.apache.padaf.preflight.annotation.AnnotationValidator#validate(java.util.List)
+ */
+ @Override
+ public boolean validate(List<ValidationError> errors)
+ throws ValidationException {
+ boolean isValide = super.validate(errors);
+ isValide = isValide && checkDest(errors);
+ return isValide;
+ }
+
+ /**
+ * Check if the Dest element is authorized according to the A entry
+ *
+ * @param errors
+ * @return
+ */
+ protected boolean checkDest(List<ValidationError> errors) {
+ try {
+ PDDestination dest = this.pdLink.getDestination();
+ if (dest != null) {
+ // ---- check the if an A entry is present.
+ if (this.pdLink.getAction() != null) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_FORBIDDEN_DEST,
+ "Dest can't be used due to A element"));
+ return false;
+ }
+ }
+ } catch (IOException e) {
+ errors
+ .add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_INVALID_DEST,
+ "Dest can't be checked"));
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.awl.edoc.pdfa.validation.annotation.AnnotationValidator#
+ * checkMandatoryFields(java.util.List)
+ */
+ protected boolean checkMandatoryFields(List<ValidationError> errors) {
+ boolean subtype = false;
+ boolean rect = false;
+ boolean f = false;
+
+ for (Object key : this.annotDictionary.keySet()) {
+ if (!(key instanceof COSName)) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
+ "Invalid key in The Annotation dictionary"));
+ return false;
+ }
+
+ String cosName = ((COSName) key).getName();
+ if (cosName.equals(DICTIONARY_KEY_SUBTYPE)) {
+ subtype = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_RECT)) {
+ rect = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_F)) {
+ f = true;
+ }
+ }
+
+ boolean result = (subtype && rect && f);
+ if (!result) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_MISSING_FIELDS));
+ }
+ return result;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/LinkAnnotationValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/MarkupAnnotationValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/MarkupAnnotationValidator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/MarkupAnnotationValidator.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/MarkupAnnotationValidator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,103 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_CONTENTS;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_F;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_QUADPOINTS;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_RECT;
+import static org.apache.padaf.preflight.ValidationConstants.DICTIONARY_KEY_SUBTYPE;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup;
+
+/**
+ * Validation class for the MarkupAnnotation
+ */
+public class MarkupAnnotationValidator extends AnnotationValidator {
+ /**
+ * PDFBox object which wraps the annotation dictionary
+ */
+ protected PDAnnotationTextMarkup pdMarkup = null;
+
+ public MarkupAnnotationValidator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super(handler, annotDictionary);
+ this.pdMarkup = new PDAnnotationTextMarkup(annotDictionary);
+ this.pdAnnot = this.pdMarkup;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.awl.edoc.pdfa.validation.annotation.AnnotationValidator#
+ * checkMandatoryFields(java.util.List)
+ */
+ protected boolean checkMandatoryFields(List<ValidationError> errors) {
+ boolean subtype = false;
+ boolean rect = false;
+ boolean f = false;
+ boolean contents = false;
+ boolean qp = false;
+
+ for (Object key : this.annotDictionary.keySet()) {
+ if (!(key instanceof COSName)) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
+ "Invalid key in The Annotation dictionary"));
+ return false;
+ }
+
+ String cosName = ((COSName) key).getName();
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_RECT)) {
+ rect = true;
+ }
+ if (cosName.equals(DICTIONARY_KEY_SUBTYPE)) {
+ subtype = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_F)) {
+ f = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_CONTENTS)) {
+ contents = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_QUADPOINTS)) {
+ qp = true;
+ }
+ }
+
+ boolean result = (subtype && rect && f && contents && qp);
+ if (!result) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_MISSING_FIELDS));
+ }
+ return result;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/MarkupAnnotationValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PDFAbAnnotationFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PDFAbAnnotationFactory.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PDFAbAnnotationFactory.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PDFAbAnnotationFactory.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,132 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_CIRCLE;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_FREETEXT;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_HIGHLIGHT;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_INK;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_LINE;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_LINK;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_PRINTERMARK;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUARE;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUILGGLY;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_STAMP;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_STRIKEOUT;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_TEXT;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_TRAPNET;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_UNDERLINE;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_WIDGET;
+import static org.apache.padaf.preflight.ValidationConstants.DICTIONARY_KEY_SUBTYPE;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ANNOT_FORBIDDEN_SUBTYPE;
+import static org.apache.padaf.preflight.ValidationConstants.ERROR_ANNOT_MISSING_SUBTYPE;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+
+/**
+ * Factory to instantiate AnnotationValidator for a PDF/A-1b valdiation.
+ *
+ */
+public class PDFAbAnnotationFactory extends AnnotationValidatorFactory {
+
+ /**
+ * Return an instance of AnnotationValidator if the annotation subtype is
+ * authorized for a PDF/A. Otherwise, returns null and the given list is
+ * updated with the right error code.
+ *
+ * If the subtype isn't mentioned in the PDF/A specification and if it doesn't
+ * exist in the PDF Reference 1.4, it will be considered as an invalid
+ * annotation. Here is the list of Annotations which appear after the PDF 1.4
+ * :
+ * <UL>
+ * <li>Polygon (1.5)
+ * <li>Polyline (1.5)
+ * <li>Caret (1.5)
+ * <li>Screen (1.5)
+ * <li>Watermark (1.6)
+ * <li>3D (1.6)
+ * </UL>
+ *
+ * @param annotDic
+ * @param handler
+ * @param errors
+ * @return
+ */
+ @Override
+ public AnnotationValidator instantiateAnnotationValidator(COSDictionary annotDic,
+ DocumentHandler handler, List<ValidationError> errors) {
+ AnnotationValidator av = null;
+
+ String subtype = annotDic.getNameAsString(COSName.getPDFName(DICTIONARY_KEY_SUBTYPE));
+
+ if (subtype == null || "".equals(subtype)) {
+ errors.add(new ValidationError(ERROR_ANNOT_MISSING_SUBTYPE));
+ } else {
+ if (ANNOT_DICTIONARY_VALUE_SUBTYPE_TEXT.equals(subtype)) {
+ av = new TextAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_LINK.equals(subtype)) {
+ av = new LinkAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_FREETEXT.equals(subtype)) {
+ av = new FreeTextAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_LINE.equals(subtype)) {
+ av = new LineAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUARE.equals(subtype)
+ || ANNOT_DICTIONARY_VALUE_SUBTYPE_CIRCLE.equals(subtype)) {
+ av = new SquareCircleAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_HIGHLIGHT.equals(subtype)
+ || ANNOT_DICTIONARY_VALUE_SUBTYPE_UNDERLINE.equals(subtype)
+ || ANNOT_DICTIONARY_VALUE_SUBTYPE_STRIKEOUT.equals(subtype)
+ || ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUILGGLY.equals(subtype)) {
+ av = new MarkupAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_STAMP.equals(subtype)) {
+ av = new RubberStampAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_INK.equals(subtype)) {
+ av = new InkAnnotationValdiator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP.equals(subtype)) {
+ av = new PopupAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_WIDGET.equals(subtype)) {
+ av = new WidgetAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_PRINTERMARK.equals(subtype)) {
+ av = new PrintMarkAnnotationValidator(handler, annotDic);
+ } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_TRAPNET.equals(subtype)) {
+ av = new TrapNetAnnotationValidator(handler, annotDic);
+ } else {
+ errors.add(new ValidationError(ERROR_ANNOT_FORBIDDEN_SUBTYPE,
+ "The subtype isn't authorized : " + subtype));
+ }
+ }
+
+ if ( av != null ) {
+ // initialize the factory if the Validator has been created
+ av.setFactory(this);
+ }
+
+ return av;
+ }
+}
\ No newline at end of file
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PDFAbAnnotationFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PopupAnnotationValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PopupAnnotationValidator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PopupAnnotationValidator.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PopupAnnotationValidator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_F;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_RECT;
+import static org.apache.padaf.preflight.ValidationConstants.DICTIONARY_KEY_SUBTYPE;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationPopup;
+
+/**
+ * Validation class for the PopupAnnotation
+ */
+public class PopupAnnotationValidator extends AnnotationValidator {
+ /**
+ * PDFBox object which wraps the annotation dictionary
+ */
+ protected PDAnnotationPopup pdPopup = null;
+
+ public PopupAnnotationValidator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super(handler, annotDictionary);
+ this.pdPopup = new PDAnnotationPopup(annotDictionary);
+ this.pdAnnot = this.pdPopup;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.awl.edoc.pdfa.validation.annotation.AnnotationValidator#
+ * checkMandatoryFields(java.util.List)
+ */
+ protected boolean checkMandatoryFields(List<ValidationError> errors) {
+ boolean subtype = false;
+ boolean rect = false;
+ boolean f = false;
+
+ for (Object key : this.annotDictionary.keySet()) {
+ if (!(key instanceof COSName)) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
+ "Invalid key in The Annotation dictionary"));
+ return false;
+ }
+
+ String cosName = ((COSName) key).getName();
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_RECT)) {
+ rect = true;
+ }
+ if (cosName.equals(DICTIONARY_KEY_SUBTYPE)) {
+ subtype = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_F)) {
+ f = true;
+ }
+ }
+
+ boolean result = (subtype && rect && f);
+ if (!result) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_MISSING_FIELDS));
+ }
+ return result;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PopupAnnotationValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PrintMarkAnnotationValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PrintMarkAnnotationValidator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PrintMarkAnnotationValidator.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PrintMarkAnnotationValidator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_F;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_RECT;
+import static org.apache.padaf.preflight.ValidationConstants.DICTIONARY_KEY_SUBTYPE;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown;
+
+/**
+ * Validation class for the PopupAnnotation
+ */
+public class PrintMarkAnnotationValidator extends AnnotationValidator {
+ /**
+ * PDFBox object which wraps the annotation dictionary
+ */
+ protected PDAnnotationUnknown pdUnk = null;
+
+ public PrintMarkAnnotationValidator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super(handler, annotDictionary);
+ this.pdUnk = new PDAnnotationUnknown(annotDictionary);
+ this.pdAnnot = this.pdUnk;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.awl.edoc.pdfa.validation.annotation.AnnotationValidator#
+ * checkMandatoryFields(java.util.List)
+ */
+ protected boolean checkMandatoryFields(List<ValidationError> errors) {
+ boolean subtype = false;
+ boolean rect = false;
+ boolean f = false;
+
+ for (Object key : this.annotDictionary.keySet()) {
+ if (!(key instanceof COSName)) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
+ "Invalid key in The Annotation dictionary"));
+ return false;
+ }
+
+ String cosName = ((COSName) key).getName();
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_RECT)) {
+ rect = true;
+ }
+ if (cosName.equals(DICTIONARY_KEY_SUBTYPE)) {
+ subtype = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_F)) {
+ f = true;
+ }
+ }
+
+ boolean result = (subtype && rect && f);
+ if (!result) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_MISSING_FIELDS));
+ }
+ return result;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/PrintMarkAnnotationValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/RubberStampAnnotationValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/RubberStampAnnotationValidator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/RubberStampAnnotationValidator.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/RubberStampAnnotationValidator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotation;
+
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_CONTENTS;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_F;
+import static org.apache.padaf.preflight.ValidationConstants.ANNOT_DICTIONARY_KEY_RECT;
+import static org.apache.padaf.preflight.ValidationConstants.DICTIONARY_KEY_SUBTYPE;
+
+import java.util.List;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp;
+
+/**
+ * Validation class for the BudderStampAnnotation
+ */
+public class RubberStampAnnotationValidator extends AnnotationValidator {
+ /**
+ * PDFBox class which wraps the annotaiton dictionary
+ */
+ protected PDAnnotationRubberStamp pdRStamp = null;
+
+ public RubberStampAnnotationValidator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super(handler, annotDictionary);
+ this.pdRStamp = new PDAnnotationRubberStamp(annotDictionary);
+ this.pdAnnot = this.pdRStamp;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.awl.edoc.pdfa.validation.annotation.AnnotationValidator#
+ * checkMandatoryFields(java.util.List)
+ */
+ protected boolean checkMandatoryFields(List<ValidationError> errors) {
+ boolean subtype = false;
+ boolean rect = false;
+ boolean f = false;
+ boolean contents = false;
+
+ for (Object key : this.annotDictionary.keySet()) {
+ if (!(key instanceof COSName)) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
+ "Invalid key in The Annotation dictionary"));
+ return false;
+ }
+
+ String cosName = ((COSName) key).getName();
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_RECT)) {
+ rect = true;
+ }
+ if (cosName.equals(DICTIONARY_KEY_SUBTYPE)) {
+ subtype = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_F)) {
+ f = true;
+ }
+ if (cosName.equals(ANNOT_DICTIONARY_KEY_CONTENTS)) {
+ contents = true;
+ }
+ }
+
+ boolean result = (subtype && rect && f && contents);
+ if (!result) {
+ errors.add(new ValidationResult.ValidationError(
+ ValidationConstants.ERROR_ANNOT_MISSING_FIELDS));
+ }
+ return result;
+ }
+
+}
Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/annotation/RubberStampAnnotationValidator.java
------------------------------------------------------------------------------
svn:eol-style = native