Class AbstractSubmitValidator
java.lang.Object
org.ctan.site.services.upload.util.AbstractSubmitValidator
- Direct Known Subclasses:
Submit11Service
This is an abstract base class containing validation methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected LicenseStore
The fieldlicenseStore
contains the license store. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractSubmitValidator
(TopicStore topicStore, LicenseStore licenseStore) This is the constructor forAbstractSubmitValidator
. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]
extractContent
(InputStream stream) This method extracts the content from an archive reader.protected String
This method is a getter which ensures a maximal size on a mandatory field.protected String
This method is a getter which ensures a maximal size.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.protected String
This method is a getter which ensures a maximal size on a mandatory field.protected String[]
hasListField
(Messages messages, String key, String[] value, int len, boolean mandatory) This method retrieves a list of strings and checks the length.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.protected String[]
hasListField
(Messages messages, String key, String value, int len, boolean mandatory) This method retrieves a string and checks the length.protected String[]
hasUrlListField
(Messages messages, String key, String value, int len) The methodhasUrlListField
provides means to check that the field contains a list of URLs separated by comma or semicolon in a String.protected void
validateArchive
(Messages messages, String pkg, Archive archive) This methodvalidateArchive
takes an archive file for a package and analyses its contents.protected void
validateArchiveFiles
(Messages messages, String pkg, Archive archive) This methodvalidateArchiveFiles
checks the archive file given.protected String
validateCtanPath
(Messages messages, String path, String base) Apply checks to the CTAN path.protected String
validateLicense
(Messages messages, String license) This method checks a license against the known licenses in the database.protected String
validateTopic
(Messages messages, String topic) Validate that the given topics are known.protected String
validateUrl
(Messages messages, String type, String url) Validate that the given URL can be retrieved.
-
Field Details
-
licenseStore
The fieldlicenseStore
contains the license store.
-
-
Constructor Details
-
AbstractSubmitValidator
This is the constructor forAbstractSubmitValidator
.- Parameters:
topicStore
- the topic storelicenseStore
- the license store
-
-
Method Details
-
extractContent
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
This method is a getter which ensures a maximal size on a mandatory field.- Parameters:
messages
- the list of messageskey
- the key to validatevalue
- the new valuelen
- the maximum length- Returns:
- the value of the field or
null
-
hasField
This method is a getter which ensures a maximal size.- Parameters:
messages
- the list of messageskey
- the key to validatevalue
- the new valuelen
- the maximum lengthmandatory
- 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 messageskey
- the key to validatevalue
- the new valuelen
- the maximum lengthmandatory
- the indicator for mandatory fieldsf
- 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 messageskey
- the key to validatevalue
- the new valuelen
- the maximum lengthf
- 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 augmentkey
- the key in the parameter mapvalue
- the valuelen
- the allowed maximal lengthmandatory
- 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 augmentkey
- the name of the fieldvalue
- the valueslen
- the allowed maximal lengthmandatory
- 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 augmentkey
- the name of the fieldvalue
- the valueslen
- the allowed maximal lengthmandatory
- the indicator for mandatory fieldsf
- the function to apply to the value at the end- Returns:
- the list found or
null
in case of an error
-
hasUrlListField
The methodhasUrlListField
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 augmentkey
- the name of the fieldvalue
- the valuelen
- the allowed maximal length- Returns:
- the field value
-
validateArchive
This methodvalidateArchive
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 messagespkg
- the name of the packagearchive
- the uploaded archive
-
validateArchiveFiles
protected void validateArchiveFiles(Messages messages, String pkg, Archive archive) throws IOException This methodvalidateArchiveFiles
checks the archive file given.- Parameters:
messages
- the messages to be augmentedpkg
- the name of the packagearchive
- the archive input stream- Throws:
IOException
- in case of an I/O error
-
validateCtanPath
Apply checks to the CTAN path.- Parameters:
messages
- the messagespath
- the path to checkbase
- the base directory of tex-archive on the local file system- Returns:
- the CTAN path
-
validateLicense
This method checks a license against the known licenses in the database.- Parameters:
messages
- the messageslicense
- the license- Returns:
- the licenses
-
validateTopic
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 findingstopic
- the topic to check- Returns:
- the topic
-
validateUrl
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 ornull
to suppress the error messagetype
- the type of the URL for the messageurl
- the URL to be checked- Returns:
- the url parameter
-