Avoid package cycle through dedicated ResourcePropertiesPersister
See gh-25151
This commit is contained in:
parent
8eedd9d5cc
commit
56c661829b
|
|
@ -35,8 +35,8 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
|||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.core.io.support.ResourcePropertiesPersister;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.DefaultPropertiesPersister;
|
||||
import org.springframework.util.PropertiesPersister;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
|
|||
@Nullable
|
||||
private String defaultParentBean;
|
||||
|
||||
private PropertiesPersister propertiesPersister = new DefaultPropertiesPersister();
|
||||
private PropertiesPersister propertiesPersister = ResourcePropertiesPersister.INSTANCE;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -187,12 +187,12 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
|
|||
|
||||
/**
|
||||
* Set the PropertiesPersister to use for parsing properties files.
|
||||
* The default is DefaultPropertiesPersister.
|
||||
* @see org.springframework.util.DefaultPropertiesPersister
|
||||
* The default is ResourcePropertiesPersister.
|
||||
* @see ResourcePropertiesPersister#INSTANCE
|
||||
*/
|
||||
public void setPropertiesPersister(@Nullable PropertiesPersister propertiesPersister) {
|
||||
this.propertiesPersister =
|
||||
(propertiesPersister != null ? propertiesPersister : new DefaultPropertiesPersister());
|
||||
(propertiesPersister != null ? propertiesPersister : ResourcePropertiesPersister.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -33,8 +33,8 @@ import org.springframework.context.ResourceLoaderAware;
|
|||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.io.support.ResourcePropertiesPersister;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.DefaultPropertiesPersister;
|
||||
import org.springframework.util.PropertiesPersister;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ import org.springframework.util.StringUtils;
|
|||
* @see #setFileEncodings
|
||||
* @see #setPropertiesPersister
|
||||
* @see #setResourceLoader
|
||||
* @see org.springframework.util.DefaultPropertiesPersister
|
||||
* @see ResourcePropertiesPersister
|
||||
* @see org.springframework.core.io.DefaultResourceLoader
|
||||
* @see ResourceBundleMessageSource
|
||||
* @see java.util.ResourceBundle
|
||||
|
|
@ -98,7 +98,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
|
|||
|
||||
private boolean concurrentRefresh = true;
|
||||
|
||||
private PropertiesPersister propertiesPersister = new DefaultPropertiesPersister();
|
||||
private PropertiesPersister propertiesPersister = ResourcePropertiesPersister.INSTANCE;
|
||||
|
||||
private ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
|
||||
|
|
@ -143,12 +143,12 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
|
|||
|
||||
/**
|
||||
* Set the PropertiesPersister to use for parsing properties files.
|
||||
* <p>The default is a DefaultPropertiesPersister.
|
||||
* @see org.springframework.util.DefaultPropertiesPersister
|
||||
* <p>The default is ResourcePropertiesPersister.
|
||||
* @see ResourcePropertiesPersister#INSTANCE
|
||||
*/
|
||||
public void setPropertiesPersister(@Nullable PropertiesPersister propertiesPersister) {
|
||||
this.propertiesPersister =
|
||||
(propertiesPersister != null ? propertiesPersister : new DefaultPropertiesPersister());
|
||||
(propertiesPersister != null ? propertiesPersister : ResourcePropertiesPersister.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -27,7 +27,6 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.DefaultPropertiesPersister;
|
||||
import org.springframework.util.PropertiesPersister;
|
||||
|
||||
/**
|
||||
|
|
@ -56,7 +55,7 @@ public abstract class PropertiesLoaderSupport {
|
|||
@Nullable
|
||||
private String fileEncoding;
|
||||
|
||||
private PropertiesPersister propertiesPersister = new DefaultPropertiesPersister();
|
||||
private PropertiesPersister propertiesPersister = ResourcePropertiesPersister.INSTANCE;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -130,12 +129,12 @@ public abstract class PropertiesLoaderSupport {
|
|||
|
||||
/**
|
||||
* Set the PropertiesPersister to use for parsing properties files.
|
||||
* The default is DefaultPropertiesPersister.
|
||||
* @see org.springframework.util.DefaultPropertiesPersister
|
||||
* The default is ResourcePropertiesPersister.
|
||||
* @see ResourcePropertiesPersister#INSTANCE
|
||||
*/
|
||||
public void setPropertiesPersister(@Nullable PropertiesPersister propertiesPersister) {
|
||||
this.propertiesPersister =
|
||||
(propertiesPersister != null ? propertiesPersister : new DefaultPropertiesPersister());
|
||||
(propertiesPersister != null ? propertiesPersister : ResourcePropertiesPersister.INSTANCE);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import org.springframework.core.io.Resource;
|
|||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.DefaultPropertiesPersister;
|
||||
import org.springframework.util.PropertiesPersister;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
|
|
@ -79,7 +78,7 @@ public abstract class PropertiesLoaderUtils {
|
|||
public static void fillProperties(Properties props, EncodedResource resource)
|
||||
throws IOException {
|
||||
|
||||
fillProperties(props, resource, new DefaultPropertiesPersister());
|
||||
fillProperties(props, resource, ResourcePropertiesPersister.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 org.springframework.core.io.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.core.SpringProperties;
|
||||
import org.springframework.util.DefaultPropertiesPersister;
|
||||
|
||||
/**
|
||||
* Spring-aware subclass of the plain {@link DefaultPropertiesPersister},
|
||||
* adding a conditional check for disabled XML support through the shared
|
||||
* "spring.xml.ignore" property.
|
||||
*
|
||||
* <p>This is the standard implementation used in Spring's resource support.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.3
|
||||
*/
|
||||
public class ResourcePropertiesPersister extends DefaultPropertiesPersister {
|
||||
|
||||
/**
|
||||
* A convenient constant for a default {@code ResourcePropertiesPersister} instance,
|
||||
* as used in Spring's common resource support.
|
||||
* @since 5.3
|
||||
*/
|
||||
public static final ResourcePropertiesPersister INSTANCE = new ResourcePropertiesPersister();
|
||||
|
||||
/**
|
||||
* Boolean flag controlled by a {@code spring.xml.ignore} system property that instructs Spring to
|
||||
* ignore XML, i.e. to not initialize the XML-related infrastructure.
|
||||
* <p>The default is "false".
|
||||
*/
|
||||
private static final boolean shouldIgnoreXml = SpringProperties.getFlag("spring.xml.ignore");
|
||||
|
||||
|
||||
@Override
|
||||
public void loadFromXml(Properties props, InputStream is) throws IOException {
|
||||
if (shouldIgnoreXml) {
|
||||
throw new UnsupportedOperationException("XML support disabled");
|
||||
}
|
||||
super.loadFromXml(props, is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeToXml(Properties props, OutputStream os, String header) throws IOException {
|
||||
if (shouldIgnoreXml) {
|
||||
throw new UnsupportedOperationException("XML support disabled");
|
||||
}
|
||||
super.storeToXml(props, os, header);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeToXml(Properties props, OutputStream os, String header, String encoding) throws IOException {
|
||||
if (shouldIgnoreXml) {
|
||||
throw new UnsupportedOperationException("XML support disabled");
|
||||
}
|
||||
super.storeToXml(props, os, header, encoding);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -23,8 +23,6 @@ import java.io.Reader;
|
|||
import java.io.Writer;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.core.SpringProperties;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link PropertiesPersister} interface.
|
||||
* Follows the native parsing of {@code java.util.Properties}.
|
||||
|
|
@ -48,22 +46,14 @@ import org.springframework.core.SpringProperties;
|
|||
* "defaultEncoding" and "fileEncodings" properties).
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sebastien Deleuze
|
||||
* @since 10.03.2004
|
||||
* @see java.util.Properties
|
||||
* @see java.util.Properties#load
|
||||
* @see java.util.Properties#store
|
||||
* @see org.springframework.core.io.support.ResourcePropertiesPersister
|
||||
*/
|
||||
public class DefaultPropertiesPersister implements PropertiesPersister {
|
||||
|
||||
/**
|
||||
* Boolean flag controlled by a {@code spring.xml.ignore} system property that instructs Spring to
|
||||
* ignore XML, i.e. to not initialize the XML-related infrastructure.
|
||||
* <p>The default is "false".
|
||||
*/
|
||||
private static final boolean shouldIgnoreXml = SpringProperties.getFlag("spring.xml.ignore");
|
||||
|
||||
|
||||
@Override
|
||||
public void load(Properties props, InputStream is) throws IOException {
|
||||
props.load(is);
|
||||
|
|
@ -86,25 +76,16 @@ public class DefaultPropertiesPersister implements PropertiesPersister {
|
|||
|
||||
@Override
|
||||
public void loadFromXml(Properties props, InputStream is) throws IOException {
|
||||
if (shouldIgnoreXml) {
|
||||
throw new UnsupportedOperationException("XML support disabled");
|
||||
}
|
||||
props.loadFromXML(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeToXml(Properties props, OutputStream os, String header) throws IOException {
|
||||
if (shouldIgnoreXml) {
|
||||
throw new UnsupportedOperationException("XML support disabled");
|
||||
}
|
||||
props.storeToXML(os, header);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeToXml(Properties props, OutputStream os, String header, String encoding) throws IOException {
|
||||
if (shouldIgnoreXml) {
|
||||
throw new UnsupportedOperationException("XML support disabled");
|
||||
}
|
||||
props.storeToXML(os, header, encoding);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -35,6 +35,7 @@ import java.util.Properties;
|
|||
* @author Juergen Hoeller
|
||||
* @since 10.03.2004
|
||||
* @see DefaultPropertiesPersister
|
||||
* @see org.springframework.core.io.support.ResourcePropertiesPersister
|
||||
* @see java.util.Properties
|
||||
*/
|
||||
public interface PropertiesPersister {
|
||||
|
|
|
|||
Loading…
Reference in New Issue