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.web; 18 19 import java.util.Collection; 20 21 import org.apache.commons.configuration2.AbstractConfiguration; 22 23 /** 24 * <p> 25 * An abstract base class for all web configurations. 26 * </p> 27 * <p> 28 * This class implements common functionality used by all web based configurations. E.g. some methods are not supported 29 * by configurations of this type, so they throw a {@code UnsupportedOperationException} exception. 30 * </p> 31 * 32 * @since 1.2 33 */ 34 abstract class BaseWebConfiguration extends AbstractConfiguration { 35 /** 36 * Checks if this configuration is empty. This implementation makes use of the {@code getKeys()} method (which must be 37 * defined by concrete sub classes) to find out whether properties exist. 38 * 39 * @return a flag whether this configuration is empty 40 */ 41 @Override 42 protected boolean isEmptyInternal() { 43 return !getKeysInternal().hasNext(); 44 } 45 46 /** 47 * Checks whether the specified key is stored in this configuration. 48 * 49 * @param key the key 50 * @return a flag whether this key exists in this configuration 51 */ 52 @Override 53 protected boolean containsKeyInternal(final String key) { 54 return getPropertyInternal(key) != null; 55 } 56 57 /** 58 * Removes the property with the given key. <strong>This operation is not supported and will throw an 59 * UnsupportedOperationException.</strong> 60 * 61 * @param key the key of the property to be removed 62 * @throws UnsupportedOperationException because this operation is not allowed 63 */ 64 @Override 65 protected void clearPropertyDirect(final String key) { 66 throw new UnsupportedOperationException("Read only configuration"); 67 } 68 69 /** 70 * Adds a property to this configuration. <strong>This operation is not supported and will throw an 71 * UnsupportedOperationException.</strong> 72 * 73 * @param key the key of the property 74 * @param obj the value to be added 75 * @throws UnsupportedOperationException because this operation is not allowed 76 */ 77 @Override 78 protected void addPropertyDirect(final String key, final Object obj) { 79 throw new UnsupportedOperationException("Read only configuration"); 80 } 81 82 /** 83 * Takes care of list delimiters in property values. This method checks if delimiter parsing is enabled and the passed 84 * in value contains a delimiter character. If this is the case, a split operation is performed. 85 * 86 * @param value the property value to be examined 87 * @return the processed value 88 */ 89 protected Object handleDelimiters(Object value) { 90 if (value instanceof String) { 91 final Collection<String> values = getListDelimiterHandler().split((String) value, true); 92 value = values.size() > 1 ? values : values.iterator().next(); 93 } 94 95 return value; 96 } 97 }