Skip to content

Commit

Permalink
Rename static variable
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo authored Jul 26, 2024
1 parent 9ccc64c commit 11d5bbd
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public class DolphinPlaces implements QuickAccessService {
</bookmark>""";


private static final Validator xmlValidator;
private static final Validator XML_VALIDATOR;

static {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try (var schemaDefinition = DolphinPlaces.class.getResourceAsStream("/xbel-1.0.xsd")) {
Source schemaFile = new StreamSource(schemaDefinition);
xmlValidator = factory.newSchema(schemaFile).newValidator();
XML_VALIDATOR = factory.newSchema(schemaFile).newValidator();
} catch (IOException | SAXException e) {
throw new IllegalStateException("Failed to load included XBEL schema definition file.", e);
}
Expand All @@ -75,7 +75,7 @@ public QuickAccessService.QuickAccessEntry add(Path target, String displayName)
}
var placesContent = Files.readString(PLACES_FILE);
//validate
xmlValidator.validate(new StreamSource(new StringReader(placesContent)));
XML_VALIDATOR.validate(new StreamSource(new StringReader(placesContent)));
// modify
int insertIndex = placesContent.lastIndexOf("</xbel"); //cannot be -1 due to validation; we do not match the end tag, since betweent tag name and closing bracket can be whitespaces
try (var writer = Files.newBufferedWriter(TMP_FILE, StandardCharsets.UTF_8, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
Expand Down Expand Up @@ -121,7 +121,7 @@ public void remove() throws QuickAccessServiceException {
return; //we assume someone has removed our entry
}
//validate
xmlValidator.validate(new StreamSource(new StringReader(placesContent)));
XML_VALIDATOR.validate(new StreamSource(new StringReader(placesContent)));
//modify
int openingTagIndex = indexOfEntryOpeningTag(placesContent, idIndex);
var contentToWrite1 = placesContent.substring(0, openingTagIndex).stripTrailing();
Expand Down

0 comments on commit 11d5bbd

Please sign in to comment.