Class Profiles


  • public final class Profiles
    extends Object
    Utitlity class that provides helper methods for handling ValidationProfiles and associated classes.

    The utility methods generally fall into one of the following categories:

    • default instance creators, defaultTypeName(), used for testing or when a vanilla instance of a particular type is required.
    • from values instance creators, typeNameFromValues(...), used to create instances from their contained types.
    • XML helper methods, typeNameToXml(...), to facilitate XML serialisation to Strings, OutputStreams and Writers.
    • XML helper methods, typeNameFromXml(...), to facilitate XML deserialisation.
    Note that XML serialisation and de-serialisation is achieved through JAXB bindings.

    TODO: Defensive Checks for all parameters.

    Author:
    Carl Wilson
    • Constructor Detail

      • Profiles

        public Profiles()
    • Method Detail

      • defaultProfile

        public static ValidationProfile defaultProfile()
        Returns an immutable default instance of a ValidationProfile. This is a static single instance, i.e. Profiles.defaultProfile() == Profiles.defaultProfile() is always true.
        Returns:
        the ValidationProfile default instance
      • profileDetailsFromValues

        public static ProfileDetails profileDetailsFromValues​(String name,
                                                              String description,
                                                              String creator,
                                                              Date created)
        Returns a ProfileDetails instance initialised using the passed values.
        Parameters:
        name - a String name that identifies the profile
        description - a short, textual String description of the profile.
        creator - a String that identifies the creator of the profile
        created - a Date instance indicating when the profile was created.
        Returns:
        the ProfileDetails instance initialised from the values
      • defaultReference

        public static Reference defaultReference()
        Returns an immutable default instance of a Reference. This is a static single instance, i.e. Profiles.defaultReference() == Profiles.defaultReference() is always true.
        Returns:
        the Reference default instance
      • referenceFromValues

        public static Reference referenceFromValues​(String specification,
                                                    String clause)
        Returns a Reference instance initialised with the passed values.
        Parameters:
        specification - a String identifying the specification the Reference refers to.
        clause - a String identifying the location referred to within the specification.
        Returns:
        an appropriately initialised Reference instance
        Throws:
        IllegalArgumentException - if any of the parameters are null or the specification is empty
      • defaultRuleId

        public static RuleId defaultRuleId()
        Returns an immutable default instance of a RuleId. This is a static single instance, i.e. Profiles.defaultRuleId() == Profiles.defaultRuleId() is always true.
        Returns:
        the RuleId default instance
      • ruleIdFromValues

        public static RuleId ruleIdFromValues​(PDFAFlavour.Specification specification,
                                              String clause,
                                              int testNumber)
        Returns a RuleId instance initialised with the passed values.
        Parameters:
        specification - a PDFAFlavour.Specification instance identifying the PDF/A specification part the RuleId is derived
        clause - a String that identifies that clause within the specification that the RuleId is derived
        testNumber - an int that identifies the test number for the RuleId
        Returns:
        a RuleId instance
        Throws:
        IllegalArgumentException - if any of the parameters are null or the clause is empty
      • defaultRule

        public static Rule defaultRule()
        Returns an immutable default instance of a Rule. This is a static single instance, i.e. Profiles.defaultRule() == Profiles.defaultRule() is always true.
        Returns:
        the Rule default instance
      • defaultError

        public static ErrorDetails defaultError()
        Returns an immutable default instance of ErrorDetails. This is a static single instance, i.e. Profiles.defaultError() == Profiles.defaultError() is always true.
        Returns:
        the ErrorDetails default instance
      • ruleFromValues

        public static Rule ruleFromValues​(RuleId id,
                                          String object,
                                          String description,
                                          String test,
                                          ErrorDetails error,
                                          List<Reference> references)
        Returns a Rule instance initialised with the passed values.
        Parameters:
        id - the RuleId id for the Rule
        object - a String that identifies the Object that the rule applies to
        description - a textual description of the Rule.
        test - a JavaScript expression that is the test carried out on a model instance
        error - the ErrorDetails associated with theRule.
        references - a list of further References for this rule
        Returns:
        a Rule instance.
        Throws:
        IllegalArgumentException - if any of the parameters are null or the test, object, or description is empty
      • ruleFromValues

        public static Rule ruleFromValues​(RuleId id,
                                          String object,
                                          Boolean deferred,
                                          String description,
                                          String test,
                                          ErrorDetails error,
                                          List<Reference> references)
        Returns a Rule instance initialised with the passed values.
        Parameters:
        id - the RuleId id for the Rule
        object - a String that identifies the Object that the rule applies to
        deferred - a Boolean that identifies the deferred property of the rule
        description - a textual description of the Rule.
        test - a JavaScript expression that is the test carried out on a model instance
        error - the ErrorDetails associated with theRule.
        references - a list of further References for this rule
        Returns:
        a Rule instance.
        Throws:
        IllegalArgumentException - if any of the parameters are null or the test, object, or description is empty
      • defaultVariable

        public static Variable defaultVariable()
        Returns an immutable default instance of a Variable. This is a static single instance, i.e. Profiles.defaultVariable() == Profiles.defaultVariable() is always true.
        Returns:
        the Variable default instance
      • profileToXml

        public static String profileToXml​(ValidationProfile toConvert,
                                          boolean format,
                                          boolean fragment)
                                   throws JAXBException
        Convert a ValidationProfile instance into an XML String.
        Parameters:
        toConvert - a ValidationProfile to convert to an XML String
        prettyXml - set to Boolean.TRUE for pretty formatted XML, Boolean.FALSE for no space formatting
        Returns:
        a String xml representation of toConvert
        Throws:
        JAXBException - thrown by JAXB marshaller if there's an error converting the object
        IOException - thrown when's there's a problem closing the underlying StringWriter
        IllegalArgumentException - if toConvert is null
      • profileToXml

        public static void profileToXml​(ValidationProfile toConvert,
                                        Writer dest,
                                        boolean format,
                                        boolean fragment)
                                 throws JAXBException
        Convert a ValidationProfile instance to XML and serialise to the Writer forXMLOutput.
        Parameters:
        toConvert - a ValidationProfile to convert to an XML String
        forXmlOutput - a Writer used to write the generated XML to
        prettyXml - set to Boolean.TRUE for pretty formatted XML, Boolean.FALSE for no space formatting
        Throws:
        JAXBException - thrown by JAXB marshaller if there's an error converting the object
        IllegalArgumentException - if toConvert is null
      • directoryFromProfiles

        public static ProfileDirectory directoryFromProfiles​(Set<ValidationProfile> profiles)
        Create a ProfileDirectory from a Set of ValidationProfiles. Note that the returned directory uses each ValidationProfile's associated PDFAFlavour as a directory key. This means that only a single ValidationProfile can be associated with a particular PDFAFlavour. If the Set of Profiles passed in profiles contains multiple ValidationProfiles with the same PDFAFlavour only one will be contained in the returned ProfileDirectory. Which one is indeterminate.
        Parameters:
        profiles - a Set of ValidationProfiles used to populate the directory instance
        Returns:
        a ProfileDirectory populated with the ValidationProfiles passed in the profiles parameter
        Throws:
        IllegalArgumentException - if the profiles parameter is null or empty
      • getVeraProfileDirectory

        public static ProfileDirectory getVeraProfileDirectory()
        Returns a ProfileDirectory instance that has been pre-populated with the curated ValidationProfiles supplied with the veraPDF library.

        While the veraPDF library and associated ValidationProfiles are under development, there is no guarantee that the profiles supplied are complete and accurate. Please check the validation profiles GitHub repo to find out the current status of our ValidationProfiles.

        Returns:
        the pre-populated veraPDF ValidationProfile directory
      • getValidationProfileSchema

        public static String getValidationProfileSchema()
                                                 throws JAXBException,
                                                        IOException
        Returns the JAXB generated XML schema for the ValidationProfileImpl type.
        Returns:
        the String representation of the schema
        Throws:
        JAXBException - if there's a problem marshaling the schema
        IOException - if there's a problem outputting the result