Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cleanup): Abstract away document type #389

Merged
merged 3 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix Typo
Josh-Matsuoka authored and andrewazores committed May 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 1179619003c1ba282534f95b33b8508080303a3a
51 changes: 25 additions & 26 deletions src/main/java/io/cryostat/core/templates/RemoteTemplateService.java
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@
import io.cryostat.core.net.JFRConnection;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import org.jsoup.select.Elements;
@@ -61,31 +60,31 @@ public Optional<String> getXml(String templateName, TemplateType type)
return Optional.empty();
}
try {
return conn.getService().getServerTemplates().stream()
.map(xmlText -> Jsoup.parse(xmlText, "", Parser.xmlParser()))
.filter(
doc -> {
Elements els = doc.getElementsByTag("configuration");
if (els.isEmpty()) {
throw new MalformedXMLException(
"Document did not contain \"configuration\""
+ " element");
}
if (els.size() > 1) {
throw new MalformedXMLException(
"Document contains multiple \"configuration\""
+ " elements");
}
Element configuration = els.first();
if (!configuration.hasAttr("label")) {
throw new MalformedXMLException(
"Configuration element did not have \"label\""
+ " attribute");
}
return configuration.attr("label").equals(templateName);
})
.map(doc -> document.toString())
.findFirst();
return conn.getService().getServerTemplates().stream()
.map(xmlText -> Jsoup.parse(xmlText, "", Parser.xmlParser()))
.filter(
doc -> {
Elements els = doc.getElementsByTag("configuration");
if (els.isEmpty()) {
throw new MalformedXMLException(
"Document did not contain \"configuration\""
+ " element");
}
if (els.size() > 1) {
throw new MalformedXMLException(
"Document contains multiple \"configuration\""
+ " elements");
}
Element configuration = els.first();
if (!configuration.hasAttr("label")) {
throw new MalformedXMLException(
"Configuration element did not have \"label\""
+ " attribute");
}
return configuration.attr("label").equals(templateName);
})
.map(doc -> doc.toString())
.findFirst();
} catch (org.openjdk.jmc.flightrecorder.configuration.FlightRecorderException
| IOException
| ServiceNotAvailableException e) {