summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java17
1 files changed, 13 insertions, 4 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java b/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java
index b3402d6607..3030d702c2 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java
@@ -50,7 +50,9 @@ import org.xml.sax.SAXException;
public class XmlFileUtils {
private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ private static final TransformerFactory transformerFactory = TransformerFactory.newInstance();
private static boolean isNewDocumentBuilderFactoryInstance = true;
+ private static boolean isNewTransformerFactoryInstance = true;
private static final Pattern XPATH_PROPERTY_REGEX =
Pattern.compile("\\[@(\\S{1,100})=['\\\"](\\S{1,100})['\\\"]\\]");
@@ -109,10 +111,7 @@ public class XmlFileUtils {
&& !root.getTagName().equals(YangUtils.DATA_ROOT_NODE_TAG_NAME)) {
final Document documentWithRootNode = addDataRootNode(root, rootNodeTagName, namespace, rootNodeProperty);
documentWithRootNode.setXmlStandalone(true);
- final TransformerFactory transformerFactory = TransformerFactory.newInstance();
- transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
- transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
- final Transformer transformer = transformerFactory.newTransformer();
+ final Transformer transformer = getTransformerFactory().newTransformer();
final StringWriter stringWriter = new StringWriter();
transformer.transform(new DOMSource(documentWithRootNode), new StreamResult(stringWriter));
return stringWriter.toString();
@@ -171,4 +170,14 @@ public class XmlFileUtils {
return documentBuilderFactory;
}
+
+ private static TransformerFactory getTransformerFactory() {
+ if (isNewTransformerFactoryInstance) {
+ transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
+ isNewTransformerFactoryInstance = false;
+ }
+
+ return transformerFactory;
+ }
}