Skip to content

Commit

Permalink
CSSTUDIO-2371 Improve the robustness of parsing the log ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamwolk committed Aug 28, 2024
1 parent 1dc0c6d commit 5bb341a
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,32 @@ public void changed(ObservableValue<? extends State> observable, State oldValue,
}

private class HyperLinkRedirectEventListener implements EventListener {

private Optional<Long> parseLogEntryID(String href) {
if (webClientRoot.isPresent() && openLogentryWithID.isPresent() && href.startsWith(webClientRoot.get())) {
try {
String withoutWebClientRoot = href.substring(webClientRoot.get().length());
String idString = withoutWebClientRoot.charAt(0) == '/' ? withoutWebClientRoot.substring(1) : withoutWebClientRoot;
long id = Long.parseLong(idString);
return Optional.of(id);
}
catch (Exception exception) {
return Optional.empty();
}
}
else {
return Optional.empty();
}
}

@Override
public void handleEvent(Event event) {
event.preventDefault();
HTMLAnchorElement anchorElement = (HTMLAnchorElement) event.getCurrentTarget();
String href = anchorElement.getHref();
if (webClientRoot.isPresent() && openLogentryWithID.isPresent() && href.startsWith(webClientRoot.get())) {
String withoutWebClientRoot = href.substring(webClientRoot.get().length());
String idString = withoutWebClientRoot.charAt(0) == '/' ? withoutWebClientRoot.substring(1) : withoutWebClientRoot.substring(0);
long id = Long.parseLong(idString);
Optional<Long> maybeID = parseLogEntryID(href);
if (maybeID.isPresent()) {
Long id = maybeID.get();
openLogentryWithID.get().accept(id);
} else {
try {
Expand Down

0 comments on commit 5bb341a

Please sign in to comment.