From 4f5e0ef49e90030d6b9b53a0d94d984e64493223 Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Tue, 7 Mar 2023 14:28:33 +1100 Subject: [PATCH] WW-5293 Split XmlConfigurationProvider into XmlDocConfigurationProvider Part 1 --- .../providers/XmlConfigurationProvider.java | 47 +--------- .../XmlDocConfigurationProvider.java | 91 +++++++++++++++++++ 2 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java index 45cdbe69b..088935a34 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java @@ -21,11 +21,9 @@ package com.opensymphony.xwork2.config.providers; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.FileManager; import com.opensymphony.xwork2.FileManagerFactory; -import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.config.BeanSelectionProvider; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationException; -import com.opensymphony.xwork2.config.ConfigurationProvider; import com.opensymphony.xwork2.config.ConfigurationUtil; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig; @@ -96,25 +94,15 @@ import static org.apache.commons.lang3.StringUtils.trimToNull; * @author Neo * @version $Revision$ */ -public abstract class XmlConfigurationProvider implements ConfigurationProvider { +public class XmlConfigurationProvider extends XmlDocConfigurationProvider { private static final Logger LOG = LogManager.getLogger(XmlConfigurationProvider.class); private final String configFileName; private final Set loadedFileUrls = new HashSet<>(); - private final Map declaredPackages = new HashMap<>(); - - protected List documents; private Set includedFileNames; - private ObjectFactory objectFactory; - - private Map dtdMappings = new HashMap<>(); - private Configuration configuration; - - private boolean throwExceptionOnDuplicateBeans = true; private FileManager fileManager; - private ValueSubstitutor valueSubstitutor; public XmlConfigurationProvider() { this("struts.xml"); @@ -132,47 +120,18 @@ public abstract class XmlConfigurationProvider implements ConfigurationProvider this(filename); } - public void setThrowExceptionOnDuplicateBeans(boolean val) { - this.throwExceptionOnDuplicateBeans = val; - } - - public void setDtdMappings(Map mappings) { - this.dtdMappings = Collections.unmodifiableMap(mappings); - } - - @Inject - public void setObjectFactory(ObjectFactory objectFactory) { - this.objectFactory = objectFactory; - } - @Inject public void setFileManagerFactory(FileManagerFactory fileManagerFactory) { this.fileManager = fileManagerFactory.getFileManager(); } - @Inject(required = false) - public void setValueSubstitutor(ValueSubstitutor valueSubstitutor) { - this.valueSubstitutor = valueSubstitutor; - } - - /** - * Returns an unmodifiable map of DTD mappings - * - * @return map of DTD mappings - */ - public Map getDtdMappings() { - return dtdMappings; - } - + @Override public void init(Configuration configuration) { - this.configuration = configuration; + super.init(configuration); this.includedFileNames = configuration.getLoadedFileNames(); loadDocuments(configFileName); } - public void destroy() { - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java new file mode 100644 index 000000000..13ab914c0 --- /dev/null +++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.opensymphony.xwork2.config.providers; + +import com.opensymphony.xwork2.ObjectFactory; +import com.opensymphony.xwork2.config.Configuration; +import com.opensymphony.xwork2.config.ConfigurationProvider; +import com.opensymphony.xwork2.inject.Inject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public abstract class XmlDocConfigurationProvider implements ConfigurationProvider { + + private static final Logger LOG = LogManager.getLogger(XmlConfigurationProvider.class); + + protected final Map declaredPackages = new HashMap<>(); + + protected List documents; + protected ObjectFactory objectFactory; + + protected Map dtdMappings = new HashMap<>(); + protected Configuration configuration; + + protected boolean throwExceptionOnDuplicateBeans = true; + + protected ValueSubstitutor valueSubstitutor; + + public XmlDocConfigurationProvider(Document... documents) { + this.documents = Arrays.asList(documents); + } + + @Inject + public void setObjectFactory(ObjectFactory objectFactory) { + this.objectFactory = objectFactory; + } + + @Inject(required = false) + public void setValueSubstitutor(ValueSubstitutor valueSubstitutor) { + this.valueSubstitutor = valueSubstitutor; + } + + public void setThrowExceptionOnDuplicateBeans(boolean val) { + this.throwExceptionOnDuplicateBeans = val; + } + + public void setDtdMappings(Map mappings) { + this.dtdMappings = Collections.unmodifiableMap(mappings); + } + + /** + * Returns an unmodifiable map of DTD mappings + * + * @return map of DTD mappings + */ + public Map getDtdMappings() { + return dtdMappings; + } + + @Override + public void init(Configuration configuration) { + this.configuration = configuration; + } + + @Override + public void destroy() { + } +}