Author: leleueri
Date: Tue Sep  6 17:41:11 2011
New Revision: 1165768

URL: http://svn.apache.org/viewvc?rev=1165768&view=rev
Log:
[PDFBOX-1115] Control on Font MetaData failed

Modified:
    
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontValidator.java
    
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/FontMetaDataValidation.java
    
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java

Modified: 
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontValidator.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontValidator.java?rev=1165768&r1=1165767&r2=1165768&view=diff
==============================================================================
--- 
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontValidator.java
 (original)
+++ 
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontValidator.java
 Tue Sep  6 17:41:11 2011
@@ -125,7 +125,7 @@ public abstract class AbstractFontValida
   }
 
   public static String getSubSetPatternDelimiter() {
-    return "+";
+    return "\\+";
   }
 
   /*
@@ -157,14 +157,12 @@ public abstract class AbstractFontValida
    * @return true if the meta data is valid, false otherwise
    * @throws ValidationException when checking fails
    */
-  protected boolean checkFontFileMetaData(PDFontDescriptor fontDesc,
-      PDStream fontFile) throws ValidationException {
+  protected boolean checkFontFileMetaData(PDFontDescriptor fontDesc, PDStream 
fontFile) throws ValidationException {
     PDMetadata metadata = fontFile.getMetadata();
     if (metadata != null) {
       // --- Filters are forbidden in a XMP stream
       if (metadata.getFilters() != null && !metadata.getFilters().isEmpty()) {
-        fontContainer.addError(new ValidationError(
-            ValidationConstants.ERROR_SYNTAX_STREAM_INVALID_FILTER,
+        fontContainer.addError(new 
ValidationError(ValidationConstants.ERROR_SYNTAX_STREAM_INVALID_FILTER,
         "Filter specified in font file metadata dictionnary"));
         return false;
       }
@@ -191,7 +189,7 @@ public abstract class AbstractFontValida
         FontMetaDataValidation fontMDval = new FontMetaDataValidation();
         List<ValidationError> ve = new ArrayList<ValidationError>();
         boolean isVal = fontMDval.analyseFontName(xmpMeta, fontDesc, ve);
-        isVal = isVal && fontMDval.analyseFontName(xmpMeta, fontDesc, ve);
+        isVal = isVal & fontMDval.analyseRights(xmpMeta, fontDesc, ve);
         for (ValidationError validationError : ve) {
           fontContainer.addError(validationError);
         }

Modified: 
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/FontMetaDataValidation.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/FontMetaDataValidation.java?rev=1165768&r1=1165767&r2=1165768&view=diff
==============================================================================
--- 
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/FontMetaDataValidation.java
 (original)
+++ 
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/FontMetaDataValidation.java
 Tue Sep  6 17:41:11 2011
@@ -43,177 +43,146 @@ import org.apache.pdfbox.pdmodel.font.PD
  */
 public class FontMetaDataValidation {
 
-  public List<ValidationError> validatePDFAIdentifer(XMPMetadata metadata,
-      PDFontDescriptor fontDesc) throws ValidationException {
-    List<ValidationError> ve = new ArrayList<ValidationError>();
-
-    analyseFontName(metadata, fontDesc, ve);
-    analyseRights(metadata, fontDesc, ve);
-
-    return ve;
-  }
-
-  /**
-   * Value of the dc:title must be the same as the FontName in the font
-   * descriptor.
-   * 
-   * @param metadata
-   *          XMPMetaData of the Font File Stream
-   * @param fontDesc
-   *          The FontDescriptor dictionary
-   * @param ve
-   *          the list of validation error to update if the validation fails
-   * @throws ValidationException
-   */
-  public boolean analyseFontName(XMPMetadata metadata,
-      PDFontDescriptor fontDesc, List<ValidationError> ve)
-      throws ValidationException {
-    String fontName = fontDesc.getFontName();
-    String noSubSetName = fontName;
-    if (AbstractFontValidator.isSubSet(fontName)) {
-      noSubSetName = fontName.split(AbstractFontValidator
-          .getSubSetPatternDelimiter())[1];
-    }
-
-    DublinCoreSchema dc = metadata.getDublinCoreSchema();
-    if (dc.getTitle() != null) {
-      String defaultTitle = dc.getTitleValue("x-default");
-      if (defaultTitle != null) {
-
-        if (!defaultTitle.equals(fontName)
-            && (noSubSetName != null && !defaultTitle.equals(noSubSetName))) {
-          StringBuilder sb = new StringBuilder(80);
-          sb
-              .append("FontName")
-              .append(
-                  " present in the FontDescriptor dictionary doesn't match 
with XMP information dc:title of the Font File Stream.");
-          ve.add(new ValidationError(
-              ValidationConstants.ERROR_METADATA_MISMATCH, sb.toString()));
-          return false;
-        }
-
-        // --- default value is the right one
-        return true;
-      } else {
-        Iterator<AbstractField> it = dc.getTitle().getContainer()
-            .getAllProperties().iterator();
-        boolean empty = true;
-        while (it.hasNext()) {
-          empty = false;
-          AbstractField tmp = it.next();
-          if (tmp != null && tmp instanceof TextType) {
-            if (((TextType) tmp).getStringValue().equals(fontName)
-                || (noSubSetName != null && ((TextType) tmp).getStringValue()
-                    .equals(noSubSetName))) {
-              // value found, return
-              return true;
-            }
-          }
-        }
-
-        // title doesn't match, it is an error.
-        StringBuilder sb = new StringBuilder(80);
-        sb.append("FontName");
-        if (empty) {
-          sb
-              .append(" present in the FontDescriptor dictionary can't be 
found in XMP information the Font File Stream.");
-          ve.add(new ValidationError(
-              ValidationConstants.ERROR_METADATA_PROPERTY_MISSING, sb
-                  .toString()));
-        } else {
-          sb
-              .append(" present in the FontDescriptor dictionary doesn't match 
with XMP information dc:title of the Font File Stream.");
-          ve.add(new ValidationError(
-              ValidationConstants.ERROR_METADATA_MISMATCH, sb.toString()));
-        }
-        return false;
-      }
-    }
-
-    // ---- dc:title is required
-    ve.add(new ValidationError(
-        ValidationConstants.ERROR_METADATA_PROPERTY_MISSING,
-        "dc:title is missing from the FontFile MetaData"));
-    return false;
-  }
-
-  /**
-   * If XMP MetaData are present, they must have followings information :
-   * <UL>
-   * <li>dc:rights
-   * <li>Marked (with the value true)
-   * <li>Owner
-   * <li>UsageTerms
-   * </UL>
-   * 
-   * @param metadata
-   *          XMPMetaData of the Font File Stream
-   * @param fontDesc
-   *          The FontDescriptor dictionary
-   * @param ve
-   *          the list of validation error to update if the validation fails
-   * @throws ValidationException
-   */
-  public boolean analyseRights(XMPMetadata metadata, PDFontDescriptor fontDesc,
-      List<ValidationError> ve) throws ValidationException {
-    DublinCoreSchema dc = metadata.getDublinCoreSchema();
-    ComplexProperty copyrights = dc.getRights();
-    if (copyrights == null || copyrights.getContainer() == null
-        || copyrights.getContainer().getAllProperties().isEmpty()) {
-      ve
-          .add(new ValidationError(
-              ValidationConstants.ERROR_METADATA_PROPERTY_MISSING,
-              "CopyRights is missing from the XMP information (dc:rights) of 
the Font File Stream."));
-      return false;
-    }
-
-    XMPRightsManagementSchema rights = metadata.getXMPRightsManagementSchema();
-    BooleanType marked = rights.getMarked();
-    if (marked == null) {
-      ve
-          .add(new ValidationError(
-              ValidationConstants.ERROR_METADATA_PROPERTY_MISSING,
-              "the XMP information (xmpRights:Marked) missing for the Font 
File Stream."));
-      return false;
-    } else if (!marked.getValue()) {
-      ve
-          .add(new ValidationError(
-              ValidationConstants.ERROR_METADATA_PROPERTY_MISSING,
-              "the XMP information (xmpRights:Marked) is invalid for the Font 
File Stream."));
-      return false;
-    }
-
-    ComplexProperty usage = rights.getUsageTerms();
-    if (usage == null || usage.getContainer() == null
-        || usage.getContainer().getAllProperties().isEmpty()) {
-      ve
-          .add(new ValidationError(
-              ValidationConstants.ERROR_METADATA_PROPERTY_MISSING,
-              "Usage Terms are missing from the XMP information 
(xmpRights:UsageTerms) of the Font File Stream."));
-      return false;
-    }
-
-    List<String> owners = rights.getOwnerValue();
-    if (owners == null || owners.isEmpty()) {
-      ve.add(new ValidationError(
-              ValidationConstants.ERROR_METADATA_PROPERTY_MISSING,
-              "Owner missing from the XMP information (xmpRights:Owner) of the 
Font File Stream."));
-      return false;
-    } else {
-       boolean allEmpty = true;
-       for (String owner : owners) {
-                       if (!"".equals(owner)) {
-                               allEmpty = false;
+       public List<ValidationError> validatePDFAIdentifer(XMPMetadata metadata,
+                       PDFontDescriptor fontDesc) throws ValidationException {
+               List<ValidationError> ve = new ArrayList<ValidationError>();
+
+               analyseFontName(metadata, fontDesc, ve);
+               analyseRights(metadata, fontDesc, ve);
+
+               return ve;
+       }
+
+       /**
+        * Value of the dc:title must be the same as the FontName in the font
+        * descriptor.
+        * 
+        * @param metadata
+        *          XMPMetaData of the Font File Stream
+        * @param fontDesc
+        *          The FontDescriptor dictionary
+        * @param ve
+        *          the list of validation error to update if the validation 
fails
+        * @throws ValidationException
+        */
+       public boolean analyseFontName(XMPMetadata metadata,
+                       PDFontDescriptor fontDesc, List<ValidationError> ve)
+       throws ValidationException {
+               String fontName = fontDesc.getFontName();
+               String noSubSetName = fontName;
+               if (AbstractFontValidator.isSubSet(fontName)) {
+                       noSubSetName = fontName.split(AbstractFontValidator
+                                       .getSubSetPatternDelimiter())[1];
+               }
+
+               DublinCoreSchema dc = metadata.getDublinCoreSchema();
+               if (dc != null) {
+                       if (dc.getTitle() != null) {
+                               String defaultTitle = 
dc.getTitleValue("x-default");
+                               if (defaultTitle != null) {
+
+                                       if (!defaultTitle.equals(fontName)
+                                                       && (noSubSetName != 
null && !defaultTitle.equals(noSubSetName))) {
+                                               StringBuilder sb = new 
StringBuilder(80);
+                                               sb
+                                               .append("FontName")
+                                               .append(
+                                               " present in the FontDescriptor 
dictionary doesn't match with XMP information dc:title of the Font File 
Stream.");
+                                               ve.add(new ValidationError(
+                                                               
ValidationConstants.ERROR_METADATA_MISMATCH, sb.toString()));
+                                               return false;
+                                       }
+
+                                       // --- default value is the right one
+                                       return true;
+                               } else {
+                                       Iterator<AbstractField> it = 
dc.getTitle().getContainer()
+                                       .getAllProperties().iterator();
+                                       boolean empty = true;
+                                       while (it.hasNext()) {
+                                               empty = false;
+                                               AbstractField tmp = it.next();
+                                               if (tmp != null && tmp 
instanceof TextType) {
+                                                       if (((TextType) 
tmp).getStringValue().equals(fontName)
+                                                                       || 
(noSubSetName != null && ((TextType) tmp).getStringValue()
+                                                                               
        .equals(noSubSetName))) {
+                                                               // value found, 
return
+                                                               return true;
+                                                       }
+                                               }
+                                       }
+
+                                       // title doesn't match, it is an error.
+                                       StringBuilder sb = new 
StringBuilder(80);
+                                       sb.append("FontName");
+                                       if (empty) {
+                                               sb
+                                               .append(" present in the 
FontDescriptor dictionary can't be found in XMP information the Font File 
Stream.");
+                                               ve.add(new ValidationError(
+                                                               
ValidationConstants.ERROR_METADATA_PROPERTY_MISSING, sb
+                                                               .toString()));
+                                       } else {
+                                               sb
+                                               .append(" present in the 
FontDescriptor dictionary doesn't match with XMP information dc:title of the 
Font File Stream.");
+                                               ve.add(new ValidationError(
+                                                               
ValidationConstants.ERROR_METADATA_MISMATCH, sb.toString()));
+                                       }
+                                       return false;
+                               }
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * If XMP MetaData are present, they must have followings information :
+        * <UL>
+        * <li>dc:rights
+        * <li>Marked (with the value true)
+        * <li>Owner
+        * <li>UsageTerms
+        * </UL>
+        * 
+        * @param metadata
+        *          XMPMetaData of the Font File Stream
+        * @param fontDesc
+        *          The FontDescriptor dictionary
+        * @param ve
+        *          the list of validation error to update if the validation 
fails
+        * @throws ValidationException
+        */
+       public boolean analyseRights(XMPMetadata metadata, PDFontDescriptor 
fontDesc, List<ValidationError> ve)
+       throws ValidationException {
+
+               DublinCoreSchema dc = metadata.getDublinCoreSchema();
+               if (dc != null) {
+                       ComplexProperty copyrights = dc.getRights();
+                       if (copyrights == null || copyrights.getContainer() == 
null
+                                       || 
copyrights.getContainer().getAllProperties().isEmpty()) {
+                               ve
+                               .add(new ValidationError(
+                                               
ValidationConstants.ERROR_METADATA_PROPERTY_MISSING,
+                               "CopyRights is missing from the XMP information 
(dc:rights) of the Font File Stream."));
+                               return false;
                        }
                }
-       if (allEmpty) {
-               ve.add(new ValidationError(
-                     ValidationConstants.ERROR_METADATA_PROPERTY_MISSING,
-                     "Owner missing from the XMP information (xmpRights:Owner) 
of the Font File Stream."));
-             return false;     
-       }
-    }
 
-    return true;
-  }
+               XMPRightsManagementSchema rights = 
metadata.getXMPRightsManagementSchema();
+               if (rights != null) {
+                       BooleanType marked = rights.getMarked();
+                       if (marked != null && !marked.getValue()) {
+                               ve
+                               .add(new ValidationError(
+                                               
ValidationConstants.ERROR_METADATA_PROPERTY_MISSING,
+                               "the XMP information (xmpRights:Marked) is 
invalid for the Font File Stream."));
+                               return false;
+                       }
+
+                       /*
+                        * rights.getUsageTerms() & rights.getOwnerValue() 
should be present but it is only a 
+                        * recommendation : may be it should be useful to 
append a Warning if these entries are missing.  
+                        */
+               }
+               return true;
+       }
 }

Modified: 
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java?rev=1165768&r1=1165767&r2=1165768&view=diff
==============================================================================
--- 
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java
 (original)
+++ 
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java
 Tue Sep  6 17:41:11 2011
@@ -48,6 +48,7 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.persistence.util.COSObjectKey;
+import org.apache.pdfbox.util.StringUtil;
 
 /**
  * This helper validates the PDF file catalog
@@ -179,7 +180,7 @@ public class CatalogValidationHelper ext
       PDDocumentCatalog catalog, List<ValidationError> result)
       throws ValidationException {
     String lang = catalog.getLanguage();
-    if (lang != null && !lang.matches("[A-Za-z]{1,8}(-[A-Za-z]{1,8})*")) {
+    if (lang != null && !"".equals(lang) && 
!lang.matches("[A-Za-z]{1,8}(-[A-Za-z]{1,8})*")) {
       result.add(new ValidationError(ERROR_SYNTAX_LANG_NOT_RFC1766));
     }
   }


Reply via email to