+ private static final Logger LOG = LoggerFactory.getLogger(StructuredDataToXmlProvider.class);
+ private static final TransformerFactory FACTORY = TransformerFactory.newInstance();
+ private static final ThreadLocal<Transformer> TRANSFORMER = new ThreadLocal<Transformer>() {
+ @Override
+ protected Transformer initialValue() {
+ final Transformer ret;
+ try {
+ ret = FACTORY.newTransformer();
+ } catch (TransformerConfigurationException e) {
+ LOG.error("Failed to instantiate XML transformer", e);
+ throw new IllegalStateException("XML encoding currently unavailable", e);
+ }
+
+ ret.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
+ ret.setOutputProperty(OutputKeys.METHOD, "xml");
+ ret.setOutputProperty(OutputKeys.INDENT, "yes");
+ ret.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+ ret.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+
+ return ret;
+ }
+ };