View Javadoc
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  
19  import java.util.Map;
20  
21  import javax.xml.parsers.DocumentBuilder;
22  
23  import org.xml.sax.EntityResolver;
24  
25  /**
26   * <p>
27   * A specialized parameters class for XML configuration.
28   * </p>
29   * <p>
30   * This parameters class defines some properties which allow customizing the parsing of XML documents. The location of
31   * the XML document to be loaded can be specified, too.
32   * </p>
33   * <p>
34   * This class is not thread-safe. It is intended that an instance is constructed and initialized by a single thread
35   * during configuration of a {@code ConfigurationBuilder}.
36   * </p>
37   *
38   * @since 2.0
39   */
40  public class XMLBuilderParametersImpl extends HierarchicalBuilderParametersImpl implements XMLBuilderProperties<XMLBuilderParametersImpl> {
41      /** The key for the entity resolver property. */
42      private static final String PROP_ENTITY_RESOLVER = "entityResolver";
43  
44      /** The key for the document builder property. */
45      private static final String PROP_DOCUMENT_BUILDER = "documentBuilder";
46  
47      /** The key for the public ID property. */
48      private static final String PROP_PUBLIC_ID = "publicID";
49  
50      /** The key for the system ID property. */
51      private static final String PROP_SYSTEM_ID = "systemID";
52  
53      /** The key for the validating property. */
54      private static final String PROP_VALIDATING = "validating";
55  
56      /** The key for the schema validation flag. */
57      private static final String PROP_SCHEMA_VALIDATION = "schemaValidation";
58  
59      @Override
60      public void inheritFrom(final Map<String, ?> source) {
61          super.inheritFrom(source);
62          copyPropertiesFrom(source, PROP_DOCUMENT_BUILDER, PROP_ENTITY_RESOLVER, PROP_SCHEMA_VALIDATION, PROP_VALIDATING);
63      }
64  
65      @Override
66      public XMLBuilderParametersImpl setDocumentBuilder(final DocumentBuilder docBuilder) {
67          storeProperty(PROP_DOCUMENT_BUILDER, docBuilder);
68          return this;
69      }
70  
71      @Override
72      public XMLBuilderParametersImpl setEntityResolver(final EntityResolver resolver) {
73          storeProperty(PROP_ENTITY_RESOLVER, resolver);
74          return this;
75      }
76  
77      /**
78       * Gets the {@code EntityResolver} stored in this parameters object. Result is <b>null</b> if no such object has been
79       * set.
80       *
81       * @return the {@code EntityResolver} or <b>null</b>
82       */
83      public EntityResolver getEntityResolver() {
84          return (EntityResolver) fetchProperty(PROP_ENTITY_RESOLVER);
85      }
86  
87      @Override
88      public XMLBuilderParametersImpl setPublicID(final String pubID) {
89          storeProperty(PROP_PUBLIC_ID, pubID);
90          return this;
91      }
92  
93      @Override
94      public XMLBuilderParametersImpl setSystemID(final String sysID) {
95          storeProperty(PROP_SYSTEM_ID, sysID);
96          return this;
97      }
98  
99      @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 }