We already have a TransformerFactory, no need to create a new one,
which speeds up processing. Also change the thrown exception to
IllegalStateException, as we do not really expect this to fail.
Change-Id: I6710893ec7324a7cba26b13e8d7cdb9c2414167e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
public static String toString(final Element xml) {
try {
public static String toString(final Element xml) {
try {
- final Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ final Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
final StreamResult result = new StreamResult(new StringWriter());
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
final StreamResult result = new StreamResult(new StringWriter());
transformer.transform(source, result);
return result.getWriter().toString();
transformer.transform(source, result);
return result.getWriter().toString();
- } catch (IllegalArgumentException | TransformerFactoryConfigurationError | TransformerException e) {
- throw new RuntimeException("Unable to serialize xml element " + xml, e);
+ } catch (IllegalArgumentException | TransformerException e) {
+ throw new IllegalStateException("Unable to serialize xml element " + xml, e);