XMLBuilderParametersImpl.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.configuration2.builder;

  18. import java.util.Map;

  19. import javax.xml.parsers.DocumentBuilder;

  20. import org.xml.sax.EntityResolver;

  21. /**
  22.  * <p>
  23.  * A specialized parameters class for XML configuration.
  24.  * </p>
  25.  * <p>
  26.  * This parameters class defines some properties which allow customizing the parsing of XML documents. The location of
  27.  * the XML document to be loaded can be specified, too.
  28.  * </p>
  29.  * <p>
  30.  * This class is not thread-safe. It is intended that an instance is constructed and initialized by a single thread
  31.  * during configuration of a {@code ConfigurationBuilder}.
  32.  * </p>
  33.  *
  34.  * @since 2.0
  35.  */
  36. public class XMLBuilderParametersImpl extends HierarchicalBuilderParametersImpl implements XMLBuilderProperties<XMLBuilderParametersImpl> {
  37.     /** The key for the entity resolver property. */
  38.     private static final String PROP_ENTITY_RESOLVER = "entityResolver";

  39.     /** The key for the document builder property. */
  40.     private static final String PROP_DOCUMENT_BUILDER = "documentBuilder";

  41.     /** The key for the public ID property. */
  42.     private static final String PROP_PUBLIC_ID = "publicID";

  43.     /** The key for the system ID property. */
  44.     private static final String PROP_SYSTEM_ID = "systemID";

  45.     /** The key for the validating property. */
  46.     private static final String PROP_VALIDATING = "validating";

  47.     /** The key for the schema validation flag. */
  48.     private static final String PROP_SCHEMA_VALIDATION = "schemaValidation";

  49.     /**
  50.      * Gets the {@code EntityResolver} stored in this parameters object. Result is <strong>null</strong> if no such object has been
  51.      * set.
  52.      *
  53.      * @return the {@code EntityResolver} or <strong>null</strong>
  54.      */
  55.     public EntityResolver getEntityResolver() {
  56.         return (EntityResolver) fetchProperty(PROP_ENTITY_RESOLVER);
  57.     }

  58.     @Override
  59.     public void inheritFrom(final Map<String, ?> source) {
  60.         super.inheritFrom(source);
  61.         copyPropertiesFrom(source, PROP_DOCUMENT_BUILDER, PROP_ENTITY_RESOLVER, PROP_SCHEMA_VALIDATION, PROP_VALIDATING);
  62.     }

  63.     @Override
  64.     public XMLBuilderParametersImpl setDocumentBuilder(final DocumentBuilder docBuilder) {
  65.         storeProperty(PROP_DOCUMENT_BUILDER, docBuilder);
  66.         return this;
  67.     }

  68.     @Override
  69.     public XMLBuilderParametersImpl setEntityResolver(final EntityResolver resolver) {
  70.         storeProperty(PROP_ENTITY_RESOLVER, resolver);
  71.         return this;
  72.     }

  73.     @Override
  74.     public XMLBuilderParametersImpl setPublicID(final String pubID) {
  75.         storeProperty(PROP_PUBLIC_ID, pubID);
  76.         return this;
  77.     }

  78.     @Override
  79.     public XMLBuilderParametersImpl setSchemaValidation(final boolean f) {
  80.         storeProperty(PROP_SCHEMA_VALIDATION, Boolean.valueOf(f));
  81.         return this;
  82.     }

  83.     @Override
  84.     public XMLBuilderParametersImpl setSystemID(final String sysID) {
  85.         storeProperty(PROP_SYSTEM_ID, sysID);
  86.         return this;
  87.     }

  88.     @Override
  89.     public XMLBuilderParametersImpl setValidating(final boolean f) {
  90.         storeProperty(PROP_VALIDATING, Boolean.valueOf(f));
  91.         return this;
  92.     }
  93. }