Source code
Description: source: package: org.apache.commons.configuration2.builder, class: XMLBuilderParametersImpl

    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
    042    /** The key for the entity resolver property. */
    043    private static final String PROP_ENTITY_RESOLVER = "entityResolver";
    044
    045    /** The key for the document builder property. */
    046    private static final String PROP_DOCUMENT_BUILDER = "documentBuilder";
    047
    048    /** The key for the public ID property. */
    049    private static final String PROP_PUBLIC_ID = "publicID";
    050
    051    /** The key for the system ID property. */
    052    private static final String PROP_SYSTEM_ID = "systemID";
    053
    054    /** The key for the validating property. */
    055    private static final String PROP_VALIDATING = "validating";
    056
    057    /** The key for the schema validation flag. */
    058    private static final String PROP_SCHEMA_VALIDATION = "schemaValidation";
    059
    060    /**
    061     * Gets the {@code EntityResolver} stored in this parameters object. Result is <strong>null</strong> if no such object has been
    062     * set.
    063     *
    064     * @return the {@code EntityResolver} or <strong>null</strong>
    065     */
    066    public EntityResolver getEntityResolver() {
    067        return (EntityResolver) fetchProperty(PROP_ENTITY_RESOLVER);
    068    }
    069
    070    @Override
    071    public void inheritFrom(final Map<String, ?> source) {
    072        super.inheritFrom(source);
    073        copyPropertiesFrom(source, PROP_DOCUMENT_BUILDER, PROP_ENTITY_RESOLVER, PROP_SCHEMA_VALIDATION, PROP_VALIDATING);
    074    }
    075
    076    @Override
    077    public XMLBuilderParametersImpl setDocumentBuilder(final DocumentBuilder docBuilder) {
    078        storeProperty(PROP_DOCUMENT_BUILDER, docBuilder);
    079        return this;
    080    }
    081
    082    @Override
    083    public XMLBuilderParametersImpl setEntityResolver(final EntityResolver resolver) {
    084        storeProperty(PROP_ENTITY_RESOLVER, resolver);
    085        return this;
    086    }
    087
    088    @Override
    089    public XMLBuilderParametersImpl setPublicID(final String pubID) {
    090        storeProperty(PROP_PUBLIC_ID, pubID);
    091        return this;
    092    }
    093
    094    @Override
    095    public XMLBuilderParametersImpl setSchemaValidation(final boolean f) {
    096        storeProperty(PROP_SCHEMA_VALIDATION, Boolean.valueOf(f));
    097        return this;
    098    }
    099
    100    @Override
    101    public XMLBuilderParametersImpl setSystemID(final String sysID) {
    102        storeProperty(PROP_SYSTEM_ID, sysID);
    103        return this;
    104    }
    105
    106    @Override
    107    public XMLBuilderParametersImpl setValidating(final boolean f) {
    108        storeProperty(PROP_VALIDATING, Boolean.valueOf(f));
    109        return this;
    110    }
    111}