diff --git a/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/schema/DomToSchemaProcessor.java b/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/schema/DomToSchemaProcessor.java index def44c8aa2d..a5d6d1fb0fe 100644 --- a/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/schema/DomToSchemaProcessor.java +++ b/infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/schema/DomToSchemaProcessor.java @@ -101,7 +101,7 @@ private XSSchemaSet parseSchema(Element schema) throws SchemaException { // Make sure that the schema parser sees all the namespace declarations DOMUtil.fixNamespaceDeclarations(schema); try { - TransformerFactory transfac = TransformerFactory.newInstance(); + TransformerFactory transfac = DOMUtil.setupTransformerFactory(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); diff --git a/infra/util/src/main/java/com/evolveum/midpoint/util/DOMUtil.java b/infra/util/src/main/java/com/evolveum/midpoint/util/DOMUtil.java index 3226772e3e5..48ad02c6a19 100644 --- a/infra/util/src/main/java/com/evolveum/midpoint/util/DOMUtil.java +++ b/infra/util/src/main/java/com/evolveum/midpoint/util/DOMUtil.java @@ -171,27 +171,7 @@ public class DOMUtil { transformerThreadLocal = ThreadLocal.withInitial(() -> { try { - //setTransformerFactoryIfPresent("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); // too many whitespaces in Java11 - //setTransformerFactoryIfPresent("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"); // too few whitespaces - - String className = "org.apache.xalan.processor.TransformerFactoryImpl"; - setTransformerFactoryIfPresent(className); // a bit slower - - ClassLoader cl = null; - try { - Class clazz = Class.forName(className); - if (clazz != null) { - cl = clazz.getClassLoader(); - } - } catch (Exception ex) { - } - - TransformerFactory transformerFactory; - if (cl != null) { - transformerFactory = TransformerFactory.newInstance(className, cl); - } else { - transformerFactory = TransformerFactory.newInstance(); - } + TransformerFactory transformerFactory = setupTransformerFactory(); //System.out.println("TF = " + transformerFactory.getClass().getName()); Transformer trans = transformerFactory.newTransformer(); @@ -205,7 +185,19 @@ public class DOMUtil { }); } + public static TransformerFactory setupTransformerFactory() { + //setTransformerFactoryIfPresent("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); // too many whitespaces in Java11 + //setTransformerFactoryIfPresent("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"); // too few whitespaces + setTransformerFactoryIfPresent("org.apache.xalan.processor.TransformerFactoryImpl"); // a bit slower + + return TransformerFactory.newInstance(); + } + private static void setTransformerFactoryIfPresent(String className) { + if (!DOMUtilSettings.isAddTransformerFactorySystemProperty()) { + return; + } + String propertyName = TransformerFactory.class.getName(); try { Class.forName(className); diff --git a/infra/util/src/main/java/com/evolveum/midpoint/util/DOMUtilSettings.java b/infra/util/src/main/java/com/evolveum/midpoint/util/DOMUtilSettings.java new file mode 100644 index 00000000000..99c8c12506d --- /dev/null +++ b/infra/util/src/main/java/com/evolveum/midpoint/util/DOMUtilSettings.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010-2019 Evolveum + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.evolveum.midpoint.util; + +/** + * Created by Viliam Repan (lazyman). + */ +public class DOMUtilSettings { + + private static boolean addTransformerFactorySystemProperty = true; + + public static boolean isAddTransformerFactorySystemProperty() { + return addTransformerFactorySystemProperty; + } + + /** + * Method used by MidPoint Studio to disable setting system property during {@link DOMUtil} initialization. + * Not used within MidPoint as the default "true" value doesn't change the initialization behaviour. + * + * @param addTransformerFactorySystemProperty + */ + public static void setAddTransformerFactorySystemProperty(boolean addTransformerFactorySystemProperty) { + DOMUtilSettings.addTransformerFactorySystemProperty = addTransformerFactorySystemProperty; + } +}