Skip to content

Commit

Permalink
Javadoc and try-with-catch for parser
Browse files Browse the repository at this point in the history
  • Loading branch information
lahsivjar committed Nov 8, 2024
1 parent 70b12de commit 82800a7
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,24 @@ public static LifecyclePolicy loadPolicy(
}
}

/**
* Parses lifecycle policy based on the provided content type without doing any variable substitution.
* It is caller's responsibility to do any variable substitution if required.
*/
public static LifecyclePolicy parsePolicy(
String rawPolicy,
String name,
NamedXContentRegistry xContentRegistry,
XContentType contentType
) throws IOException {
XContentParser parser = contentType.xContent()
.createParser(XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry), rawPolicy);
LifecyclePolicy policy = LifecyclePolicy.parse(parser, name);
policy.validate();
return policy;
try (
XContentParser parser = contentType.xContent()
.createParser(XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry), rawPolicy)
) {
LifecyclePolicy policy = LifecyclePolicy.parse(parser, name);
policy.validate();
return policy;
}
}

private static String replaceVariables(String template, Map<String, String> variables) {
Expand Down

0 comments on commit 82800a7

Please sign in to comment.