    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 *     https://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 java.util.Map;
    020
    021import javax.xml.parsers.DocumentBuilder;
    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 parsing of XML documents. The location of
    031 * the XML document to be loaded can be specified, too.
    032 * </p>
    033 * <p>
    034 * This class is not thread-safe. It is intended that an instance is constructed and initialized by a single thread
    035 * during configuration of a {@code ConfigurationBuilder}.
    036 * </p>
    037 *
    038 * @since 2.0
    039 */
    040public class XMLBuilderParametersImpl extends HierarchicalBuilderParametersImpl implements XMLBuilderProperties<XMLBuilderParametersImpl> {
    041    /** The key for the entity resolver property. */
    042    private static final String PROP_ENTITY_RESOLVER = "entityResolver";
    043
    044    /** The key for the document builder property. */
    045    private static final String PROP_DOCUMENT_BUILDER = "documentBuilder";
    046
    047    /** The key for the public ID property. */
    048    private static final String PROP_PUBLIC_ID = "publicID";
    049
    050    /** The key for the system ID property. */
    051    private static final String PROP_SYSTEM_ID = "systemID";
    052
    053    /** The key for the validating property. */
    054    private static final String PROP_VALIDATING = "validating";
    055
    056    /** The key for the schema validation flag. */
    057    private static final String PROP_SCHEMA_VALIDATION = "schemaValidation";
    058
    059    /**
    060     * Gets the {@code EntityResolver} stored in this parameters object. Result is <strong>null</strong> if no such object has been
    061     * set.
    062     *
    063     * @return the {@code EntityResolver} or <strong>null</strong>
    064     */
    065    public EntityResolver getEntityResolver() {
    066        return (EntityResolver) fetchProperty(PROP_ENTITY_RESOLVER);
    067    }
    068
    069    @Override
    070    public void inheritFrom(final Map<String, ?> source) {
    071        super.inheritFrom(source);
    072        copyPropertiesFrom(source, PROP_DOCUMENT_BUILDER, PROP_ENTITY_RESOLVER, PROP_SCHEMA_VALIDATION, PROP_VALIDATING);
    073    }
    074
    075    @Override
    076    public XMLBuilderParametersImpl setDocumentBuilder(final DocumentBuilder docBuilder) {
    077        storeProperty(PROP_DOCUMENT_BUILDER, docBuilder);
    078        return this;
    079    }
    080
    081    @Override
    082    public XMLBuilderParametersImpl setEntityResolver(final EntityResolver resolver) {
    083        storeProperty(PROP_ENTITY_RESOLVER, resolver);
    084        return this;
    085    }
    086
    087    @Override
    088    public XMLBuilderParametersImpl setPublicID(final String pubID) {
    089        storeProperty(PROP_PUBLIC_ID, pubID);
    090        return this;
    091    }
    092
    093    @Override
    094    public XMLBuilderParametersImpl setSchemaValidation(final boolean f) {
    095        storeProperty(PROP_SCHEMA_VALIDATION, Boolean.valueOf(f));
    096        return this;
    097    }
    098
    099    @Override
    100    public XMLBuilderParametersImpl setSystemID(final String sysID) {
    101        storeProperty(PROP_SYSTEM_ID, sysID);
    102        return this;
    103    }
    104
    105    @Override
    106    public XMLBuilderParametersImpl setValidating(final boolean f) {
    107        storeProperty(PROP_VALIDATING, Boolean.valueOf(f));
    108        return this;
    109    }
    110}