Skip to content

Commit

Permalink
handle sonar messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rsehr committed Nov 29, 2024
1 parent cc18450 commit ba44f67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import de.intranda.goobi.plugins.checks.numbers.ValueRangeFactory;

public class TifValidationResolutionCheck implements TifValidationCheck {
public static String NAME = "resolution_check";
public static final String NAME = "resolution_check";

private static Namespace jhove = Namespace.getNamespace("jhove", "http://hul.harvard.edu/ois/xml/ns/jhove");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TifValidationSimpleXpathCheck implements TifValidationCheck {
private static XPathFactory xFactory = XPathFactory.instance();

private Set<Namespace> namespaces;
private XPathExpression xpath;
private XPathExpression<Object> xpath;
private String expectedValue;
private String errorMessage;
private Map<String, String> replaceMap;
Expand All @@ -37,11 +37,10 @@ public TifValidationSimpleXpathCheck(Set<Namespace> namespaces, String xpath, St
}

public static String validateXPath(String path) {
if (StringUtils.isNotBlank(path)) {
if (!path.matches("\\w+\\(.+\\)")) {
path = "string(" + path + ")";
}
if (StringUtils.isNotBlank(path) && !path.matches("\\w+\\(.+\\)")) {
path = "string(" + path + ")";
}

return path;
}

Expand All @@ -53,18 +52,17 @@ private void createReplaceMap() {
@Override
public boolean check(Document doc) {
Object value = xpath.evaluateFirst(doc);
if (value instanceof Element) {
value = ((Element) value).getTextTrim();
} else if (value instanceof Attribute) {
value = ((Attribute) value).getValue();
} else if (value instanceof Text) {
value = ((Text) value).getText();
if (value instanceof Element e) {
value = e.getTextTrim();
} else if (value instanceof Attribute a) {
value = a.getValue();
} else if (value instanceof Text t) {
value = t.getText();
} else if (!(value instanceof String)) {
value = value.toString();
}
this.replaceMap.put("found", (String) value);
return this.expectedValue.equals(value) || (value != null && value instanceof String && ((String) value).matches(this.expectedValue));
// return this.expectedValue.equals(value);
return this.expectedValue.equals(value) || (value instanceof String s && s.matches(this.expectedValue));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@

public class ValueRangeFactory {

public static ValueRange create(String s) throws IllegalArgumentException{
private ValueRangeFactory() {
// private constructor to hide public default constructor
}

public static ValueRange create(String s) throws IllegalArgumentException {
ValueRange range = null;
if(s.contains(",")) {
if (s.contains(",")) {
StringTokenizer tokenizer = new StringTokenizer(s, ",");
range = new ArrayValueRange();
while(tokenizer.hasMoreTokens()) {
((ArrayValueRange)range).addValue(tokenizer.nextToken());
while (tokenizer.hasMoreTokens()) {
((ArrayValueRange) range).addValue(tokenizer.nextToken());
}
} else if(s.contains("-")) {
} else if (s.contains("-")) {
int index = s.indexOf("-");
String start = s.substring(0, index);
String end = s.substring(index+1);
String end = s.substring(index + 1);
try {
double startD = Double.parseDouble(start);
double endD = Double.parseDouble(end);
range = new ContinuousArrayRange(startD, endD);
} catch(NullPointerException | NumberFormatException e) {
} catch (NullPointerException | NumberFormatException e) {
throw new IllegalArgumentException("Cannot parse " + s + " as number range");
}
} else if(StringUtils.isNumeric(s)) {
} else if (StringUtils.isNumeric(s)) {
double value = Double.parseDouble(s);
range = new SingleValueRange(value);
} else {
Expand Down

0 comments on commit ba44f67

Please sign in to comment.