Renamed convertToAllowedCharacters() to convertDiacriticsAndReservedXmlCharacters(), removed side effect that containsOnlyAllowedCharacters() converts diacritics and XML characters and added default implementation convertDiacriticsAndReservedXmlCharactersAndCheckIfContainsOnlyAllowedCharacters()

This commit is contained in:
dankito 2020-05-14 14:48:56 +02:00
parent f89e2855d2
commit deb7f3ad36
4 changed files with 13 additions and 9 deletions

View File

@ -5,8 +5,14 @@ interface ISepaMessageCreator {
fun createXmlFile(filename: String, replacementStrings: Map<String, String>): String
fun convertDiacriticsAndReservedXmlCharactersAndCheckIfContainsOnlyAllowedCharacters(stringToTest: String): Boolean {
val convertedString = convertDiacriticsAndReservedXmlCharacters(stringToTest)
return containsOnlyAllowedCharacters(convertedString)
}
fun containsOnlyAllowedCharacters(stringToTest: String): Boolean
fun convertToAllowedCharacters(input: String): String
fun convertDiacriticsAndReservedXmlCharacters(input: String): String
}

View File

@ -26,14 +26,14 @@ open class SepaBankTransferBase(
debitorBic,
mapOf(
SepaMessageCreator.NumberOfTransactionsKey to "1", // TODO: may someday support more then one transaction per file
"DebitorName" to messageCreator.convertToAllowedCharacters(debitor.name),
"DebitorName" to messageCreator.convertDiacriticsAndReservedXmlCharacters(debitor.name),
"DebitorIban" to account.iban!!,
"DebitorBic" to debitorBic,
"CreditorName" to messageCreator.convertToAllowedCharacters(data.creditorName),
"CreditorName" to messageCreator.convertDiacriticsAndReservedXmlCharacters(data.creditorName),
"CreditorIban" to data.creditorIban.replace(" ", ""),
"CreditorBic" to data.creditorBic.replace(" ", ""),
"Amount" to data.amount.toString(), // TODO: check if ',' or '.' should be used as decimal separator
"Usage" to if (data.usage.isEmpty()) " " else messageCreator.convertToAllowedCharacters(data.usage),
"Usage" to if (data.usage.isEmpty()) " " else messageCreator.convertDiacriticsAndReservedXmlCharacters(data.usage),
"RequestedExecutionDate" to RequestedExecutionDateValueForNotScheduledTransfers
),
messageCreator

View File

@ -39,12 +39,10 @@ open class SepaMessageCreator : ISepaMessageCreator {
override fun containsOnlyAllowedCharacters(stringToTest: String): Boolean {
val convertedString = convertToAllowedCharacters(stringToTest)
return AllowedSepaCharactersPattern.matcher(convertedString).matches()
return AllowedSepaCharactersPattern.matcher(stringToTest).matches()
}
override fun convertToAllowedCharacters(input: String): String {
override fun convertDiacriticsAndReservedXmlCharacters(input: String): String {
// TODO: add other replacement strings
return input
.replace("\"", "&quot;")

View File

@ -82,7 +82,7 @@ open class InputValidator {
}
open fun convertToAllowedSepaCharacters(string: String): String {
return sepaMessageCreator.convertToAllowedCharacters(string)
return sepaMessageCreator.convertDiacriticsAndReservedXmlCharacters(string)
}