    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 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    @Override
    060    public void inheritFrom(final Map<String, ?> source) {
    061        super.inheritFrom(source);
    062        copyPropertiesFrom(source, PROP_DOCUMENT_BUILDER, PROP_ENTITY_RESOLVER, PROP_SCHEMA_VALIDATION, PROP_VALIDATING);
    063    }
    064
    065    @Override
    066    public XMLBuilderParametersImpl setDocumentBuilder(final DocumentBuilder docBuilder) {
    067        storeProperty(PROP_DOCUMENT_BUILDER, docBuilder);
    068        return this;
    069    }
    070
    071    @Override
    072    public XMLBuilderParametersImpl setEntityResolver(final EntityResolver resolver) {
    073        storeProperty(PROP_ENTITY_RESOLVER, resolver);
    074        return this;
    075    }
    076
    077    /**
    078     * Returns the {@code EntityResolver} stored in this parameters object. Result is <b>null</b> if no such object has been
    079     * set.
    080     *
    081     * @return the {@code EntityResolver} or <b>null</b>
    082     */
    083    public EntityResolver getEntityResolver() {
    084        return (EntityResolver) fetchProperty(PROP_ENTITY_RESOLVER);
    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 setSystemID(final String sysID) {
    095        storeProperty(PROP_SYSTEM_ID, sysID);
    096        return this;
    097    }
    098
    099    @Override
    100    public XMLBuilderParametersImpl setValidating(final boolean f) {
    101        storeProperty(PROP_VALIDATING, Boolean.valueOf(f));
    102        return this;
    103    }
    104
    105    @Override
    106    public XMLBuilderParametersImpl setSchemaValidation(final boolean f) {
    107        storeProperty(PROP_SCHEMA_VALIDATION, Boolean.valueOf(f));
    108        return this;
    109    }
    110}