001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.configuration2.builder;
018
019import javax.xml.parsers.DocumentBuilder;
020
021import java.util.Map;
022
023import org.xml.sax.EntityResolver;
024
025/**
026 * <p>
027 * A specialized parameters class for XML configuration.
028 * </p>
029 * <p>
030 * This parameters class defines some properties which allow customizing the
031 * parsing of XML documents. The location of the XML document to be loaded can
032 * be specified, too.
033 * </p>
034 * <p>
035 * This class is not thread-safe. It is intended that an instance is constructed
036 * and initialized by a single thread during configuration of a
037 * {@code ConfigurationBuilder}.
038 * </p>
039 *
040 * @version $Id: XMLBuilderParametersImpl.java 1842194 2018-09-27 22:24:23Z ggregory $
041 * @since 2.0
042 */
043public class XMLBuilderParametersImpl extends HierarchicalBuilderParametersImpl
044        implements XMLBuilderProperties<XMLBuilderParametersImpl>
045{
046    /** The key for the entity resolver property. */
047    private static final String PROP_ENTITY_RESOLVER = "entityResolver";
048
049    /** The key for the document builder property. */
050    private static final String PROP_DOCUMENT_BUILDER = "documentBuilder";
051
052    /** The key for the public ID property. */
053    private static final String PROP_PUBLIC_ID = "publicID";
054
055    /** The key for the system ID property. */
056    private static final String PROP_SYSTEM_ID = "systemID";
057
058    /** The key for the validating property. */
059    private static final String PROP_VALIDATING = "validating";
060
061    /** The key for the schema validation flag. */
062    private static final String PROP_SCHEMA_VALIDATION = "schemaValidation";
063
064    @Override
065    public void inheritFrom(final Map<String, ?> source)
066    {
067        super.inheritFrom(source);
068        copyPropertiesFrom(source, PROP_DOCUMENT_BUILDER, PROP_ENTITY_RESOLVER,
069                PROP_SCHEMA_VALIDATION, PROP_VALIDATING);
070    }
071
072    @Override
073    public XMLBuilderParametersImpl setDocumentBuilder(
074            final DocumentBuilder docBuilder)
075    {
076        storeProperty(PROP_DOCUMENT_BUILDER, docBuilder);
077        return this;
078    }
079
080    @Override
081    public XMLBuilderParametersImpl setEntityResolver(final EntityResolver resolver)
082    {
083        storeProperty(PROP_ENTITY_RESOLVER, resolver);
084        return this;
085    }
086
087    /**
088     * Returns the {@code EntityResolver} stored in this parameters object.
089     * Result is <b>null</b> if no such object has been set.
090     *
091     * @return the {@code EntityResolver} or <b>null</b>
092     */
093    public EntityResolver getEntityResolver()
094    {
095        return (EntityResolver) fetchProperty(PROP_ENTITY_RESOLVER);
096    }
097
098    @Override
099    public XMLBuilderParametersImpl setPublicID(final String pubID)
100    {
101        storeProperty(PROP_PUBLIC_ID, pubID);
102        return this;
103    }
104
105    @Override
106    public XMLBuilderParametersImpl setSystemID(final String sysID)
107    {
108        storeProperty(PROP_SYSTEM_ID, sysID);
109        return this;
110    }
111
112    @Override
113    public XMLBuilderParametersImpl setValidating(final boolean f)
114    {
115        storeProperty(PROP_VALIDATING, Boolean.valueOf(f));
116        return this;
117    }
118
119    @Override
120    public XMLBuilderParametersImpl setSchemaValidation(final boolean f)
121    {
122        storeProperty(PROP_SCHEMA_VALIDATION, Boolean.valueOf(f));
123        return this;
124    }
125}