mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
This commit is contained in:
parent
9c98d6470d
commit
7a8635eba2
4 changed files with 77 additions and 17 deletions
|
|
@ -1,7 +1,10 @@
|
|||
package de.kosit.validationtool.cmd;
|
||||
|
||||
import static org.apache.commons.io.FilenameUtils.isExtension;
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import lombok.Getter;
|
||||
|
|
@ -18,27 +21,25 @@ public class DefaultNamingStrategy implements NamingStrategy {
|
|||
|
||||
private String prefix;
|
||||
|
||||
private String postfix = "report";
|
||||
private String postfix;
|
||||
|
||||
@Override
|
||||
public String createName(final String base) {
|
||||
if (StringUtils.isEmpty(base)) {
|
||||
public String createName(final String name) {
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
throw new IllegalArgumentException("Can not generate name based on null input");
|
||||
}
|
||||
final int index = base.lastIndexOf('.');
|
||||
final String base = isExtension(name.toLowerCase(), "xml") ? FilenameUtils.getBaseName(name) : name;
|
||||
final StringBuilder result = new StringBuilder();
|
||||
if (isNotEmpty(this.prefix)) {
|
||||
result.append(this.prefix).append("-");
|
||||
}
|
||||
result.append(base, 0, index > 0 ? index : base.length());
|
||||
result.append(base);
|
||||
if (isNotEmpty(this.postfix)) {
|
||||
result.append("-").append(this.postfix);
|
||||
} else if (isEmpty(this.prefix)) {
|
||||
result.append("-").append("report");
|
||||
}
|
||||
if (index > 0) {
|
||||
result.append(base.substring(index));
|
||||
} else {
|
||||
result.append(".xml");
|
||||
}
|
||||
result.append(".xml");
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ package de.kosit.validationtool.impl.tasks;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
|
@ -113,11 +113,7 @@ public interface CheckAction {
|
|||
*/
|
||||
public String getName() {
|
||||
final String fileName = getInput().getName().replaceAll(".*/|.*\\\\", "");
|
||||
final Matcher matcher = Pattern.compile("(.*)\\..+").matcher(fileName);
|
||||
if (matcher.matches()) {
|
||||
return matcher.group(1);
|
||||
}
|
||||
return fileName;
|
||||
return FilenameUtils.getBaseName(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue