001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 /*
019 * $Id: OutputPropertyUtils.java 468654 2006-10-28 07:09:23Z minchau $
020 */
021 package org.apache.xml.serializer;
022
023 import java.util.Properties;
024
025 /**
026 * This class contains some static methods that act as helpers when parsing a
027 * Java Property object.
028 *
029 * This class is not a public API.
030 * It is only public because it is used outside of this package.
031 *
032 * @see java.util.Properties
033 * @xsl.usage internal
034 */
035 public final class OutputPropertyUtils
036 {
037 /**
038 * Searches for the boolean property with the specified key in the property list.
039 * If the key is not found in this property list, the default property list,
040 * and its defaults, recursively, are then checked. The method returns
041 * <code>false</code> if the property is not found, or if the value is other
042 * than "yes".
043 *
044 * @param key the property key.
045 * @param props the list of properties that will be searched.
046 * @return the value in this property list as a boolean value, or false
047 * if null or not "yes".
048 */
049 public static boolean getBooleanProperty(String key, Properties props)
050 {
051
052 String s = props.getProperty(key);
053
054 if (null == s || !s.equals("yes"))
055 return false;
056 else
057 return true;
058 }
059
060 /**
061 * Searches for the int property with the specified key in the property list.
062 * If the key is not found in this property list, the default property list,
063 * and its defaults, recursively, are then checked. The method returns
064 * <code>false</code> if the property is not found, or if the value is other
065 * than "yes".
066 *
067 * @param key the property key.
068 * @param props the list of properties that will be searched.
069 * @return the value in this property list as a int value, or 0
070 * if null or not a number.
071 */
072 public static int getIntProperty(String key, Properties props)
073 {
074
075 String s = props.getProperty(key);
076
077 if (null == s)
078 return 0;
079 else
080 return Integer.parseInt(s);
081 }
082
083 }