Class AbstractSubmitValidator

java.lang.Object
org.ctan.site.services.upload.util.AbstractSubmitValidator
Direct Known Subclasses:
Submit11Service

public abstract class AbstractSubmitValidator extends Object
This is an abstract base class containing validation methods.
  • Field Details

    • licenseStore

      protected LicenseStore licenseStore
      The field licenseStore contains the license store.
  • Constructor Details

    • AbstractSubmitValidator

      protected AbstractSubmitValidator(TopicStore topicStore, LicenseStore licenseStore)
      This is the constructor for AbstractSubmitValidator.
      Parameters:
      topicStore - the topic store
      licenseStore - the license store
  • Method Details

    • extractContent

      protected byte[] extractContent(InputStream stream) throws IOException
      This method extracts the content from an archive reader.
      Parameters:
      stream - the input stream
      Returns:
      the bytes found
      Throws:
      IOException - in case of an I/O error
    • hasField

      protected String hasField(Messages messages, String key, String value, int len)
      This method is a getter which ensures a maximal size on a mandatory field.
      Parameters:
      messages - the list of messages
      key - the key to validate
      value - the new value
      len - the maximum length
      Returns:
      the value of the field or null
    • hasField

      protected String hasField(Messages messages, String key, String value, int len, boolean mandatory)
      This method is a getter which ensures a maximal size.
      Parameters:
      messages - the list of messages
      key - the key to validate
      value - the new value
      len - the maximum length
      mandatory - the indicator for mandatory fields
      Returns:
      the value of the field or null
    • hasField

      protected String hasField(Messages messages, String key, String value, int len, boolean mandatory, Function<String,String> f)
      This method is a getter which ensures a maximal size.
      Parameters:
      messages - the list of messages
      key - the key to validate
      value - the new value
      len - the maximum length
      mandatory - the indicator for mandatory fields
      f - the function to apply to the value at the end
      Returns:
      the value of the field or null
    • hasField

      protected String hasField(Messages messages, String key, String value, int len, Function<String,String> f)
      This method is a getter which ensures a maximal size on a mandatory field.
      Parameters:
      messages - the list of messages
      key - the key to validate
      value - the new value
      len - the maximum length
      f - the function to apply to the value at the end
      Returns:
      the value of the field or null
    • hasListField

      protected String[] hasListField(Messages messages, String key, String value, int len, boolean mandatory)
      This method retrieves a string and checks the length.
      Parameters:
      messages - the messages to augment
      key - the key in the parameter map
      value - the value
      len - the allowed maximal length
      mandatory - the indicator for mandatory fields
      Returns:
      the value
    • hasListField

      protected String[] hasListField(Messages messages, String key, String[] value, int len, boolean mandatory)
      This method retrieves a list of strings and checks the length.
      Parameters:
      messages - the messages to augment
      key - the name of the field
      value - the values
      len - the allowed maximal length
      mandatory - the indicator for mandatory fields
      Returns:
      the list found or null in case of an error
    • hasListField

      protected String[] hasListField(Messages messages, String key, String[] value, int len, boolean mandatory, Function<String,String> f)
      This method retrieves a list of strings and checks the length.
      Parameters:
      messages - the messages to augment
      key - the name of the field
      value - the values
      len - the allowed maximal length
      mandatory - the indicator for mandatory fields
      f - the function to apply to the value at the end
      Returns:
      the list found or null in case of an error
    • hasUrlListField

      protected String[] hasUrlListField(Messages messages, String key, String value, int len)
      The method hasUrlListField provides means to check that the field contains a list of URLs separated by comma or semicolon in a String.
      Parameters:
      messages - the messages to augment
      key - the name of the field
      value - the value
      len - the allowed maximal length
      Returns:
      the field value
    • validateArchive

      protected void validateArchive(Messages messages, String pkg, Archive archive)
      This method validateArchive takes an archive file for a package and analyses its contents. If the archive is not of a known type then am error is produced.
      Parameters:
      messages - the list of messages
      pkg - the name of the package
      archive - the uploaded archive
    • validateArchiveFiles

      protected void validateArchiveFiles(Messages messages, String pkg, Archive archive) throws IOException
      This method validateArchiveFiles checks the archive file given.
      Parameters:
      messages - the messages to be augmented
      pkg - the name of the package
      archive - the archive input stream
      Throws:
      IOException - in case of an I/O error
    • validateCtanPath

      protected String validateCtanPath(Messages messages, String path, String base)
      Apply checks to the CTAN path.
      Parameters:
      messages - the messages
      path - the path to check
      base - the base directory of tex-archive on the local file system
      Returns:
      the CTAN path
    • validateLicense

      protected String validateLicense(Messages messages, String license)
      This method checks a license against the known licenses in the database.
      Parameters:
      messages - the messages
      license - the license
      Returns:
      the licenses
    • validateTopic

      protected String validateTopic(Messages messages, String topic)
      Validate that the given topics are known. Otherwise add a message that the topic has not been found.
      Parameters:
      messages - the messages to augment with the findings
      topic - the topic to check
      Returns:
      the topic
    • validateUrl

      protected String validateUrl(Messages messages, String type, String url)
      Validate that the given URL can be retrieved. For this purpose a HEAD request is sent to the URL. In case of an unreachable URL an error message is added to the messages.
      Parameters:
      messages - the messages to augment or null to suppress the error message
      type - the type of the URL for the message
      url - the URL to be checked
      Returns:
      the url parameter